@defisaver/automation-sdk 3.0.2-dev → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/automation/private/StrategiesAutomation.js +3 -1
- package/esm/constants/index.js +5 -0
- package/esm/services/strategiesService.js +14 -2
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +7 -0
- package/esm/services/strategySubService.test.js +34 -0
- package/esm/services/subDataService.d.ts +9 -0
- package/esm/services/subDataService.js +31 -1
- package/esm/services/subDataService.test.js +45 -0
- package/esm/services/triggerService.d.ts +8 -0
- package/esm/services/triggerService.js +15 -1
- package/esm/services/triggerService.test.js +28 -0
- package/esm/types/enums.d.ts +3 -1
- package/esm/types/enums.js +2 -0
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.ts +3 -1
- package/src/constants/index.ts +5 -0
- package/src/services/ethereumService.ts +1 -1
- package/src/services/strategiesService.ts +22 -2
- package/src/services/strategySubService.test.ts +38 -0
- package/src/services/strategySubService.ts +17 -0
- package/src/services/subDataService.test.ts +53 -1
- package/src/services/subDataService.ts +38 -0
- package/src/services/triggerService.test.ts +30 -0
- package/src/services/triggerService.ts +21 -1
- package/src/types/enums.ts +2 -0
- package/umd/index.js +128 -56
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import AbiCoder from 'web3-eth-abi';
|
|
3
|
+
import { fromWei, toWei } from 'web3-utils';
|
|
4
|
+
|
|
3
5
|
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
4
6
|
import { otherAddresses } from '@defisaver/sdk';
|
|
5
7
|
|
|
@@ -511,6 +513,42 @@ export const crvUSDLeverageManagementSubData = {
|
|
|
511
513
|
},
|
|
512
514
|
};
|
|
513
515
|
|
|
516
|
+
export const crvUSDPaybackSubData = {
|
|
517
|
+
encode: (
|
|
518
|
+
controllerAddr: EthereumAddress,
|
|
519
|
+
addressToPullTokensFrom: EthereumAddress,
|
|
520
|
+
positionOwner: EthereumAddress,
|
|
521
|
+
paybackAmount: string,
|
|
522
|
+
crvUSDAddr: EthereumAddress,
|
|
523
|
+
) => {
|
|
524
|
+
const controllerAddrEncoded = AbiCoder.encodeParameter('address', controllerAddr);
|
|
525
|
+
const addressToPullTokensFromEncoded = AbiCoder.encodeParameter('address', addressToPullTokensFrom);
|
|
526
|
+
const positionOwnerEncoded = AbiCoder.encodeParameter('address', positionOwner);
|
|
527
|
+
const paybackAmountEncoded = AbiCoder.encodeParameter('uint256', toWei(paybackAmount, 'ether'));
|
|
528
|
+
const crvUSDAddrEncoded = AbiCoder.encodeParameter('address', crvUSDAddr);
|
|
529
|
+
return [
|
|
530
|
+
controllerAddrEncoded,
|
|
531
|
+
addressToPullTokensFromEncoded,
|
|
532
|
+
positionOwnerEncoded,
|
|
533
|
+
paybackAmountEncoded,
|
|
534
|
+
crvUSDAddrEncoded,
|
|
535
|
+
];
|
|
536
|
+
},
|
|
537
|
+
decode: (subData: SubData) => {
|
|
538
|
+
const controller = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
539
|
+
const addressToPullTokensFrom = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
|
|
540
|
+
const positionOwner = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
|
|
541
|
+
const weiPaybackAmount = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
|
|
542
|
+
const paybackAmount = fromWei(weiPaybackAmount, 'ether');
|
|
543
|
+
return {
|
|
544
|
+
controller,
|
|
545
|
+
addressToPullTokensFrom,
|
|
546
|
+
positionOwner,
|
|
547
|
+
paybackAmount,
|
|
548
|
+
};
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
|
|
514
552
|
export const morphoBlueLeverageManagementSubData = {
|
|
515
553
|
encode: (
|
|
516
554
|
loanToken: EthereumAddress,
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
liquityDebtInFrontWithLimitTrigger,
|
|
29
29
|
crvUSDRatioTrigger,
|
|
30
30
|
morphoBlueRatioTrigger,
|
|
31
|
+
crvUsdHealthRatioTrigger,
|
|
31
32
|
} from './triggerService';
|
|
32
33
|
|
|
33
34
|
describe('Feature: triggerService.ts', () => {
|
|
@@ -934,6 +935,35 @@ describe('Feature: triggerService.ts', () => {
|
|
|
934
935
|
});
|
|
935
936
|
});
|
|
936
937
|
|
|
938
|
+
describe('When testing triggerService.crvUsdHealthRatioTrigger', () => {
|
|
939
|
+
describe('encode()', () => {
|
|
940
|
+
const examples: Array<[[string], [owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number]]> = [
|
|
941
|
+
[
|
|
942
|
+
['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
|
|
943
|
+
[web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 20]
|
|
944
|
+
]
|
|
945
|
+
];
|
|
946
|
+
examples.forEach(([expected, actual]) => {
|
|
947
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
948
|
+
expect(crvUsdHealthRatioTrigger.encode(...actual)).to.eql(expected);
|
|
949
|
+
});
|
|
950
|
+
});
|
|
951
|
+
});
|
|
952
|
+
describe('decode()', () => {
|
|
953
|
+
const examples: Array<[{ owner: EthereumAddress, controller: EthereumAddress, ratio: number }, TriggerData]> = [
|
|
954
|
+
[
|
|
955
|
+
{ owner: web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 20 },
|
|
956
|
+
['0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000'],
|
|
957
|
+
],
|
|
958
|
+
];
|
|
959
|
+
examples.forEach(([expected, actual]) => {
|
|
960
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
961
|
+
expect(crvUsdHealthRatioTrigger.decode(actual)).to.eql(expected);
|
|
962
|
+
});
|
|
963
|
+
});
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
|
|
937
967
|
describe('When testing triggerService.morphoBlueRatioTrigger', () => {
|
|
938
968
|
describe('encode()', () => {
|
|
939
969
|
const examples: Array<[[string], [marketId: string, owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
|
|
@@ -381,7 +381,6 @@ export const curveUsdSoftLiquidationTrigger = {
|
|
|
381
381
|
},
|
|
382
382
|
};
|
|
383
383
|
|
|
384
|
-
|
|
385
384
|
export const crvUSDRatioTrigger = {
|
|
386
385
|
encode(
|
|
387
386
|
owner: EthereumAddress,
|
|
@@ -405,6 +404,27 @@ export const crvUSDRatioTrigger = {
|
|
|
405
404
|
},
|
|
406
405
|
};
|
|
407
406
|
|
|
407
|
+
export const crvUsdHealthRatioTrigger = {
|
|
408
|
+
encode(
|
|
409
|
+
owner: EthereumAddress,
|
|
410
|
+
controller: EthereumAddress,
|
|
411
|
+
ratioPercentage: number,
|
|
412
|
+
) {
|
|
413
|
+
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
414
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256'], [owner, controller, ratioWei])];
|
|
415
|
+
},
|
|
416
|
+
decode(
|
|
417
|
+
triggerData: TriggerData,
|
|
418
|
+
) {
|
|
419
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256'], triggerData[0]);
|
|
420
|
+
return {
|
|
421
|
+
owner: decodedData[0] as EthereumAddress,
|
|
422
|
+
controller: decodedData[1] as EthereumAddress,
|
|
423
|
+
ratio: weiToRatioPercentage(decodedData[2] as string),
|
|
424
|
+
};
|
|
425
|
+
},
|
|
426
|
+
};
|
|
427
|
+
|
|
408
428
|
export const morphoBlueRatioTrigger = {
|
|
409
429
|
encode(
|
|
410
430
|
marketId: string, // bytes32
|
package/src/types/enums.ts
CHANGED
|
@@ -65,6 +65,7 @@ export namespace Strategies {
|
|
|
65
65
|
LIQUITY_DSR_PAYBACK = 69,
|
|
66
66
|
LIQUITY_DSR_SUPPLY = 70,
|
|
67
67
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
68
|
+
CURVEUSD_PAYBACK = 92,
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
export enum OptimismIds {
|
|
@@ -94,6 +95,7 @@ export namespace Strategies {
|
|
|
94
95
|
TrailingStopToColl = 'trailing-stop-to-collateral',
|
|
95
96
|
TrailingStopToDebt = 'trailing-stop-to-debt',
|
|
96
97
|
Rebond = 'rebond',
|
|
98
|
+
Payback = 'payback',
|
|
97
99
|
BondProtection = 'bond-protection',
|
|
98
100
|
Dca = 'dca',
|
|
99
101
|
LimitOrder = 'limit-order',
|