@defisaver/automation-sdk 2.1.1 → 2.1.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 +5 -1
- package/esm/constants/index.js +10 -0
- package/esm/services/strategiesService.js +36 -0
- package/esm/services/strategySubService.d.ts +3 -0
- package/esm/services/strategySubService.js +11 -1
- package/esm/services/strategySubService.test.js +62 -1
- package/esm/services/subDataService.d.ts +8 -1
- package/esm/services/subDataService.js +17 -1
- package/esm/services/subDataService.test.js +54 -0
- package/esm/services/triggerService.d.ts +9 -0
- package/esm/services/triggerService.js +16 -1
- package/esm/services/triggerService.test.js +36 -0
- package/esm/types/enums.d.ts +5 -2
- package/esm/types/enums.js +3 -0
- package/esm/types/index.d.ts +5 -1
- package/package.json +2 -2
- package/src/automation/private/StrategiesAutomation.ts +9 -1
- package/src/constants/index.ts +10 -0
- package/src/services/strategiesService.ts +41 -0
- package/src/services/strategySubService.test.ts +67 -1
- package/src/services/strategySubService.ts +21 -0
- package/src/services/subDataService.test.ts +66 -4
- package/src/services/subDataService.ts +24 -0
- package/src/services/triggerService.test.ts +37 -0
- package/src/services/triggerService.ts +24 -0
- package/src/types/enums.ts +3 -0
- package/src/types/index.ts +6 -1
- package/umd/index.js +574 -333
|
@@ -413,3 +413,24 @@ export const sparkEncode = {
|
|
|
413
413
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
414
414
|
},
|
|
415
415
|
};
|
|
416
|
+
|
|
417
|
+
export const crvUSDEncode = {
|
|
418
|
+
leverageManagement(
|
|
419
|
+
owner: EthereumAddress,
|
|
420
|
+
controllerAddr: EthereumAddress,
|
|
421
|
+
ratioState: RatioState,
|
|
422
|
+
targetRatio: number,
|
|
423
|
+
triggerRatio: number,
|
|
424
|
+
collTokenAddr: EthereumAddress,
|
|
425
|
+
crvUSDAddr: EthereumAddress,
|
|
426
|
+
) {
|
|
427
|
+
const subData = subDataService.crvUSDLeverageManagementSubData.encode(controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr);
|
|
428
|
+
const triggerData = triggerService.crvUSDRatioTrigger.encode(owner, controllerAddr, triggerRatio, ratioState);
|
|
429
|
+
|
|
430
|
+
// over is boost, under is repay
|
|
431
|
+
const strategyOrBundleId = ratioState === RatioState.OVER ? Bundles.MainnetIds.CRVUSD_BOOST : Bundles.MainnetIds.CRVUSD_REPAY;
|
|
432
|
+
const isBundle = true;
|
|
433
|
+
|
|
434
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
435
|
+
},
|
|
436
|
+
};
|
|
@@ -3,7 +3,7 @@ import { expect } from 'chai';
|
|
|
3
3
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
4
4
|
import * as web3Utils from 'web3-utils';
|
|
5
5
|
|
|
6
|
-
import { ChainId, OrderType } from '../types/enums';
|
|
6
|
+
import { ChainId, OrderType, RatioState } from '../types/enums';
|
|
7
7
|
import type { EthereumAddress, SubData } from '../types';
|
|
8
8
|
|
|
9
9
|
import {
|
|
@@ -13,8 +13,12 @@ import {
|
|
|
13
13
|
cBondsRebondSubData,
|
|
14
14
|
compoundV2LeverageManagementSubData,
|
|
15
15
|
compoundV3LeverageManagementSubData,
|
|
16
|
-
exchangeDcaSubData,
|
|
17
|
-
|
|
16
|
+
exchangeDcaSubData,
|
|
17
|
+
exchangeLimitOrderSubData,
|
|
18
|
+
liquityCloseSubData,
|
|
19
|
+
liquityDebtInFrontRepaySubData,
|
|
20
|
+
liquityDsrPaybackSubData,
|
|
21
|
+
liquityDsrSupplySubData,
|
|
18
22
|
liquityLeverageManagementSubData,
|
|
19
23
|
liquityPaybackUsingChickenBondSubData,
|
|
20
24
|
liquityRepayFromSavingsSubData,
|
|
@@ -24,7 +28,7 @@ import {
|
|
|
24
28
|
morphoAaveV2LeverageManagementSubData,
|
|
25
29
|
sparkLeverageManagementSubData,
|
|
26
30
|
sparkQuotePriceSubData,
|
|
27
|
-
|
|
31
|
+
crvUSDLeverageManagementSubData,
|
|
28
32
|
} from './subDataService';
|
|
29
33
|
|
|
30
34
|
describe('Feature: subDataService.ts', () => {
|
|
@@ -1059,5 +1063,63 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1059
1063
|
});
|
|
1060
1064
|
});
|
|
1061
1065
|
});
|
|
1066
|
+
describe('When testing subDataService.crvUSDLeverageManagementSubData', () => {
|
|
1067
|
+
describe('encode()', () => {
|
|
1068
|
+
const examples: Array<[SubData, [controller: EthereumAddress, ratioState: RatioState, targetRatio: number, collToken: EthereumAddress, crvUSD: EthereumAddress]]> = [
|
|
1069
|
+
[
|
|
1070
|
+
[
|
|
1071
|
+
"0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635",
|
|
1072
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
1073
|
+
"0x00000000000000000000000000000000000000000000000010a741a462780000",
|
|
1074
|
+
"0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
1075
|
+
"0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e",
|
|
1076
|
+
],
|
|
1077
|
+
["0xa920de414ea4ab66b97da1bfe9e6eca7d4219635", RatioState.UNDER, 120, "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E"],
|
|
1078
|
+
],
|
|
1079
|
+
[
|
|
1080
|
+
[
|
|
1081
|
+
"0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635",
|
|
1082
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
1083
|
+
"0x00000000000000000000000000000000000000000000000018fae27693b40000",
|
|
1084
|
+
"0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
1085
|
+
"0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e",
|
|
1086
|
+
],
|
|
1087
|
+
["0xa920de414ea4ab66b97da1bfe9e6eca7d4219635", RatioState.OVER, 180, "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E"]
|
|
1088
|
+
],
|
|
1089
|
+
];
|
|
1090
|
+
examples.forEach(([expected, actual]) => {
|
|
1091
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1092
|
+
expect(crvUSDLeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
1093
|
+
});
|
|
1094
|
+
});
|
|
1095
|
+
});
|
|
1096
|
+
describe('decode()', () => {
|
|
1097
|
+
const examples: Array<[{
|
|
1098
|
+
controller: EthereumAddress,
|
|
1099
|
+
targetRatio: number,
|
|
1100
|
+
}, SubData]> = [
|
|
1101
|
+
[
|
|
1102
|
+
{
|
|
1103
|
+
controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
|
|
1104
|
+
targetRatio: 120,
|
|
1105
|
+
},
|
|
1106
|
+
["0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000010a741a462780000", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e",],
|
|
1107
|
+
],
|
|
1108
|
+
[
|
|
1109
|
+
{
|
|
1110
|
+
controller: "0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635",
|
|
1111
|
+
targetRatio: 180,
|
|
1112
|
+
},
|
|
1113
|
+
["0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000018fae27693b40000", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e",],
|
|
1114
|
+
],
|
|
1115
|
+
];
|
|
1116
|
+
|
|
1117
|
+
examples.forEach(([expected, actual]) => {
|
|
1118
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1119
|
+
expect(crvUSDLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
1120
|
+
});
|
|
1121
|
+
});
|
|
1122
|
+
});
|
|
1123
|
+
});
|
|
1062
1124
|
|
|
1063
1125
|
});
|
|
@@ -452,3 +452,27 @@ export const liquityDebtInFrontRepaySubData = {
|
|
|
452
452
|
return { targetRatioIncrease };
|
|
453
453
|
},
|
|
454
454
|
};
|
|
455
|
+
|
|
456
|
+
export const crvUSDLeverageManagementSubData = {
|
|
457
|
+
encode: (
|
|
458
|
+
controllerAddr: EthereumAddress,
|
|
459
|
+
ratioState: RatioState,
|
|
460
|
+
targetRatio: number,
|
|
461
|
+
collTokenAddr: EthereumAddress,
|
|
462
|
+
crvUSDAddr: EthereumAddress,
|
|
463
|
+
) => {
|
|
464
|
+
const controllerAddrEncoded = AbiCoder.encodeParameter('address', controllerAddr);
|
|
465
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
466
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
467
|
+
const collTokenAddrEncoded = AbiCoder.encodeParameter('address', collTokenAddr);
|
|
468
|
+
const crvUSDAddrEncoded = AbiCoder.encodeParameter('address', crvUSDAddr);
|
|
469
|
+
return [controllerAddrEncoded, ratioStateEncoded, targetRatioEncoded, collTokenAddrEncoded, crvUSDAddrEncoded];
|
|
470
|
+
},
|
|
471
|
+
decode: (subData: SubData) => {
|
|
472
|
+
const controller = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
473
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[2]) as any as string;
|
|
474
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
475
|
+
|
|
476
|
+
return { controller, targetRatio };
|
|
477
|
+
},
|
|
478
|
+
};
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
sparkRatioTrigger,
|
|
26
26
|
trailingStopTrigger,
|
|
27
27
|
liquityDebtInFrontWithLimitTrigger,
|
|
28
|
+
crvUSDRatioTrigger,
|
|
28
29
|
} from './triggerService';
|
|
29
30
|
|
|
30
31
|
describe('Feature: triggerService.ts', () => {
|
|
@@ -893,5 +894,41 @@ describe('Feature: triggerService.ts', () => {
|
|
|
893
894
|
});
|
|
894
895
|
});
|
|
895
896
|
});
|
|
897
|
+
describe('When testing triggerService.crvUSDRatioTrigger', () => {
|
|
898
|
+
describe('encode()', () => {
|
|
899
|
+
const examples: Array<[[string], [owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
|
|
900
|
+
[
|
|
901
|
+
['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
|
|
902
|
+
[web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 120, RatioState.UNDER]
|
|
903
|
+
],
|
|
904
|
+
[
|
|
905
|
+
['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
|
|
906
|
+
[web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 200, RatioState.OVER]
|
|
907
|
+
],
|
|
908
|
+
];
|
|
909
|
+
examples.forEach(([expected, actual]) => {
|
|
910
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
911
|
+
expect(crvUSDRatioTrigger.encode(...actual)).to.eql(expected);
|
|
912
|
+
});
|
|
913
|
+
});
|
|
914
|
+
});
|
|
915
|
+
describe('decode()', () => {
|
|
916
|
+
const examples: Array<[{ owner: EthereumAddress, controller: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
|
|
917
|
+
[
|
|
918
|
+
{ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 120, ratioState: RatioState.UNDER },
|
|
919
|
+
['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
|
|
920
|
+
],
|
|
921
|
+
[
|
|
922
|
+
{ owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 200, ratioState: RatioState.OVER },
|
|
923
|
+
['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
|
|
924
|
+
],
|
|
925
|
+
];
|
|
896
926
|
|
|
927
|
+
examples.forEach(([expected, actual]) => {
|
|
928
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
929
|
+
expect(crvUSDRatioTrigger.decode(actual)).to.eql(expected);
|
|
930
|
+
});
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
});
|
|
897
934
|
});
|
|
@@ -380,3 +380,27 @@ export const curveUsdSoftLiquidationTrigger = {
|
|
|
380
380
|
};
|
|
381
381
|
},
|
|
382
382
|
};
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
export const crvUSDRatioTrigger = {
|
|
386
|
+
encode(
|
|
387
|
+
owner: EthereumAddress,
|
|
388
|
+
controller: EthereumAddress,
|
|
389
|
+
ratioPercentage: number,
|
|
390
|
+
ratioState: RatioState,
|
|
391
|
+
) {
|
|
392
|
+
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
393
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, controller, ratioWei, ratioState])];
|
|
394
|
+
},
|
|
395
|
+
decode(
|
|
396
|
+
triggerData: TriggerData,
|
|
397
|
+
) {
|
|
398
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
399
|
+
return {
|
|
400
|
+
owner: decodedData[0] as EthereumAddress,
|
|
401
|
+
controller: decodedData[1] as EthereumAddress,
|
|
402
|
+
ratio: weiToRatioPercentage(decodedData[2] as string),
|
|
403
|
+
ratioState: Number(decodedData[3]),
|
|
404
|
+
};
|
|
405
|
+
},
|
|
406
|
+
};
|
package/src/types/enums.ts
CHANGED
|
@@ -39,6 +39,7 @@ export namespace ProtocolIdentifiers {
|
|
|
39
39
|
MorphoAaveV2 = 'Morpho-Aave__V2',
|
|
40
40
|
Exchange = 'Exchange',
|
|
41
41
|
Spark = 'Spark',
|
|
42
|
+
CrvUSD = 'CurveUSD',
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export enum LegacyAutomation {
|
|
@@ -138,6 +139,8 @@ export namespace Bundles {
|
|
|
138
139
|
AAVE_V2_BOOST = 23,
|
|
139
140
|
COMP_V2_REPAY = 20,
|
|
140
141
|
COMP_V2_BOOST = 21,
|
|
142
|
+
CRVUSD_REPAY = 26,
|
|
143
|
+
CRVUSD_BOOST = 27,
|
|
141
144
|
}
|
|
142
145
|
|
|
143
146
|
export enum OptimismIds {
|
package/src/types/index.ts
CHANGED
|
@@ -167,9 +167,14 @@ export declare namespace Position {
|
|
|
167
167
|
debtInFrontMin: string,
|
|
168
168
|
targetRepayRatioIncrease: number,
|
|
169
169
|
}
|
|
170
|
+
|
|
171
|
+
interface LeverageManagementCrvUSD extends Base {
|
|
172
|
+
subHashBoost?: string,
|
|
173
|
+
subHashRepay?: string,
|
|
174
|
+
}
|
|
170
175
|
}
|
|
171
176
|
|
|
172
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay;
|
|
177
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD;
|
|
173
178
|
|
|
174
179
|
export interface Automated {
|
|
175
180
|
chainId: ChainId,
|