@defisaver/automation-sdk 3.3.16-liq-prot-dev → 3.3.17
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/cjs/constants/index.js +42 -117
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +2 -5
- package/cjs/services/strategiesService.js +21 -160
- package/cjs/services/strategySubService.d.ts +21 -18
- package/cjs/services/strategySubService.js +74 -78
- package/cjs/services/strategySubService.test.js +149 -3
- package/cjs/services/subDataService.d.ts +20 -70
- package/cjs/services/subDataService.js +79 -23
- package/cjs/services/subDataService.test.js +202 -17
- package/cjs/services/utils.d.ts +1 -2
- package/cjs/services/utils.js +1 -14
- package/cjs/types/enums.d.ts +17 -36
- package/cjs/types/enums.js +11 -30
- package/esm/constants/index.js +42 -117
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -5
- package/esm/services/strategiesService.js +21 -160
- package/esm/services/strategySubService.d.ts +21 -18
- package/esm/services/strategySubService.js +73 -78
- package/esm/services/strategySubService.test.js +147 -4
- package/esm/services/subDataService.d.ts +20 -70
- package/esm/services/subDataService.js +77 -21
- package/esm/services/subDataService.test.js +200 -18
- package/esm/services/utils.d.ts +1 -2
- package/esm/services/utils.js +1 -13
- package/esm/types/enums.d.ts +17 -36
- package/esm/types/enums.js +11 -30
- package/package.json +1 -1
- package/src/constants/index.ts +43 -119
- package/src/index.ts +6 -22
- package/src/services/strategiesService.ts +23 -225
- package/src/services/strategySubService.test.ts +191 -3
- package/src/services/strategySubService.ts +121 -173
- package/src/services/subDataService.test.ts +214 -18
- package/src/services/subDataService.ts +106 -42
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +1 -15
- package/src/types/enums.ts +13 -30
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
1
2
|
import { expect } from 'chai';
|
|
2
3
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
4
|
import * as web3Utils from 'web3-utils';
|
|
4
5
|
import { MAXUINT } from '@defisaver/tokens';
|
|
5
6
|
|
|
6
|
-
import { ChainId, CloseStrategyType, RatioState } from '../types/enums';
|
|
7
|
+
import { ChainId, CloseStrategyType, OrderType, RatioState } from '../types/enums';
|
|
7
8
|
import type { EthereumAddress, SubData } from '../types';
|
|
8
9
|
|
|
9
10
|
import '../configuration';
|
|
@@ -132,7 +133,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
132
133
|
});
|
|
133
134
|
});
|
|
134
135
|
|
|
135
|
-
describe('When testing subDataService.
|
|
136
|
+
describe('When testing subDataService.makerLeverageManagementSubData', () => {
|
|
136
137
|
describe('decode()', () => {
|
|
137
138
|
const examples: Array<[{ vaultId: number, targetRatio: number }, SubData]> = [
|
|
138
139
|
[
|
|
@@ -146,13 +147,13 @@ describe('Feature: subDataService.ts', () => {
|
|
|
146
147
|
|
|
147
148
|
examples.forEach(([expected, actual]) => {
|
|
148
149
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
149
|
-
expect(subDataService.
|
|
150
|
+
expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
150
151
|
});
|
|
151
152
|
});
|
|
152
153
|
});
|
|
153
154
|
});
|
|
154
155
|
|
|
155
|
-
describe('When testing subDataService.
|
|
156
|
+
describe('When testing subDataService.makerLeverageManagementWithoutSubProxy', () => {
|
|
156
157
|
describe('encode()', () => {
|
|
157
158
|
const examples: Array<[SubData, [vaultId: number, targetRatio: number, daiAddr?: EthereumAddress]]> = [
|
|
158
159
|
[
|
|
@@ -173,7 +174,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
173
174
|
|
|
174
175
|
examples.forEach(([expected, actual]) => {
|
|
175
176
|
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
176
|
-
expect(subDataService.
|
|
177
|
+
expect(subDataService.makerLeverageManagementWithoutSubProxy.encode(...actual)).to.eql(expected);
|
|
177
178
|
});
|
|
178
179
|
});
|
|
179
180
|
});
|
|
@@ -206,13 +207,13 @@ describe('Feature: subDataService.ts', () => {
|
|
|
206
207
|
|
|
207
208
|
examples.forEach(([expected, actual]) => {
|
|
208
209
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
209
|
-
expect(subDataService.
|
|
210
|
+
expect(subDataService.makerLeverageManagementWithoutSubProxy.decode(actual)).to.eql(expected);
|
|
210
211
|
});
|
|
211
212
|
});
|
|
212
213
|
});
|
|
213
214
|
});
|
|
214
215
|
|
|
215
|
-
describe('When testing subDataService.
|
|
216
|
+
describe('When testing subDataService.liquityLeverageManagementSubData', () => {
|
|
216
217
|
describe('decode()', () => {
|
|
217
218
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
218
219
|
[
|
|
@@ -226,7 +227,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
226
227
|
|
|
227
228
|
examples.forEach(([expected, actual]) => {
|
|
228
229
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
229
|
-
expect(subDataService.
|
|
230
|
+
expect(subDataService.liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
230
231
|
});
|
|
231
232
|
});
|
|
232
233
|
});
|
|
@@ -286,7 +287,26 @@ describe('Feature: subDataService.ts', () => {
|
|
|
286
287
|
});
|
|
287
288
|
});
|
|
288
289
|
|
|
289
|
-
describe('When testing subDataService.
|
|
290
|
+
describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
|
|
291
|
+
describe('encode()', () => {
|
|
292
|
+
const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
|
|
293
|
+
[
|
|
294
|
+
[new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
|
|
295
|
+
[160, 220, 180, 190, true]
|
|
296
|
+
],
|
|
297
|
+
[
|
|
298
|
+
[new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
|
|
299
|
+
[160, 200, 180, 190, false]
|
|
300
|
+
],
|
|
301
|
+
];
|
|
302
|
+
|
|
303
|
+
examples.forEach(([expected, actual]) => {
|
|
304
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
305
|
+
expect(subDataService.aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
290
310
|
describe('decode()', () => {
|
|
291
311
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
292
312
|
[
|
|
@@ -301,13 +321,13 @@ describe('Feature: subDataService.ts', () => {
|
|
|
301
321
|
|
|
302
322
|
examples.forEach(([expected, actual]) => {
|
|
303
323
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
304
|
-
expect(subDataService.
|
|
324
|
+
expect(subDataService.aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
305
325
|
});
|
|
306
326
|
});
|
|
307
327
|
});
|
|
308
328
|
});
|
|
309
329
|
|
|
310
|
-
describe('When testing subDataService.
|
|
330
|
+
describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
|
|
311
331
|
describe('decode()', () => {
|
|
312
332
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
313
333
|
[
|
|
@@ -322,7 +342,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
322
342
|
|
|
323
343
|
examples.forEach(([expected, actual]) => {
|
|
324
344
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
325
|
-
expect(subDataService.
|
|
345
|
+
expect(subDataService.aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
326
346
|
});
|
|
327
347
|
});
|
|
328
348
|
});
|
|
@@ -674,7 +694,26 @@ describe('Feature: subDataService.ts', () => {
|
|
|
674
694
|
});
|
|
675
695
|
});
|
|
676
696
|
|
|
677
|
-
describe('When testing subDataService.
|
|
697
|
+
describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
|
|
698
|
+
describe('encode()', () => {
|
|
699
|
+
const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
|
|
700
|
+
[
|
|
701
|
+
[new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
|
|
702
|
+
[160, 220, 180, 190, true]
|
|
703
|
+
],
|
|
704
|
+
[
|
|
705
|
+
[new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
|
|
706
|
+
[160, 200, 180, 190, false]
|
|
707
|
+
],
|
|
708
|
+
];
|
|
709
|
+
|
|
710
|
+
examples.forEach(([expected, actual]) => {
|
|
711
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
712
|
+
expect(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
713
|
+
});
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
|
|
678
717
|
describe('decode()', () => {
|
|
679
718
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
680
719
|
[
|
|
@@ -689,13 +728,104 @@ describe('Feature: subDataService.ts', () => {
|
|
|
689
728
|
|
|
690
729
|
examples.forEach(([expected, actual]) => {
|
|
691
730
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
692
|
-
expect(subDataService.
|
|
731
|
+
expect(subDataService.compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
|
|
738
|
+
describe('encode()', () => {
|
|
739
|
+
const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string, boolean, boolean], [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean]]> = [
|
|
740
|
+
[
|
|
741
|
+
[
|
|
742
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
743
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
744
|
+
new Dec(160).mul(1e16).toString(),
|
|
745
|
+
new Dec(220).mul(1e16).toString(),
|
|
746
|
+
new Dec(180).mul(1e16).toString(),
|
|
747
|
+
new Dec(190).mul(1e16).toString(),
|
|
748
|
+
true, false,
|
|
749
|
+
],
|
|
750
|
+
[
|
|
751
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
752
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
753
|
+
160, 220, 180, 190,
|
|
754
|
+
true, false,
|
|
755
|
+
]
|
|
756
|
+
],
|
|
757
|
+
[
|
|
758
|
+
[
|
|
759
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
760
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
761
|
+
new Dec(160).mul(1e16).toString(),
|
|
762
|
+
new Dec(210).mul(1e16).toString(),
|
|
763
|
+
new Dec(180).mul(1e16).toString(),
|
|
764
|
+
new Dec(190).mul(1e16).toString(),
|
|
765
|
+
false, true,
|
|
766
|
+
],
|
|
767
|
+
[
|
|
768
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
769
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
770
|
+
160, 210, 180, 190,
|
|
771
|
+
false, true,
|
|
772
|
+
]
|
|
773
|
+
],
|
|
774
|
+
];
|
|
775
|
+
|
|
776
|
+
examples.forEach(([expected, actual]) => {
|
|
777
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
778
|
+
expect(subDataService.compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
779
|
+
});
|
|
780
|
+
});
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
describe('decode()', () => {
|
|
784
|
+
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
785
|
+
[
|
|
786
|
+
{ targetRatio: 123 },
|
|
787
|
+
[
|
|
788
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
789
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
|
|
790
|
+
],
|
|
791
|
+
],
|
|
792
|
+
[
|
|
793
|
+
{ targetRatio: 200 },
|
|
794
|
+
[
|
|
795
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
796
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
797
|
+
],
|
|
798
|
+
],
|
|
799
|
+
];
|
|
800
|
+
|
|
801
|
+
examples.forEach(([expected, actual]) => {
|
|
802
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
803
|
+
expect(subDataService.compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
693
804
|
});
|
|
694
805
|
});
|
|
695
806
|
});
|
|
696
807
|
});
|
|
697
808
|
|
|
698
809
|
describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
|
|
810
|
+
describe('encode()', () => {
|
|
811
|
+
const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
|
|
812
|
+
[
|
|
813
|
+
[new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
|
|
814
|
+
[160, 220, 180, 190, true]
|
|
815
|
+
],
|
|
816
|
+
[
|
|
817
|
+
[new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
|
|
818
|
+
[160, 200, 180, 190, false]
|
|
819
|
+
],
|
|
820
|
+
];
|
|
821
|
+
|
|
822
|
+
examples.forEach(([expected, actual]) => {
|
|
823
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
824
|
+
expect(subDataService.morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
825
|
+
});
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
|
|
699
829
|
describe('decode()', () => {
|
|
700
830
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
701
831
|
[
|
|
@@ -717,6 +847,25 @@ describe('Feature: subDataService.ts', () => {
|
|
|
717
847
|
});
|
|
718
848
|
|
|
719
849
|
describe('When testing subDataService.cBondsRebondSubData', () => {
|
|
850
|
+
describe('encode()', () => {
|
|
851
|
+
const examples: Array<[SubData, [bondId: number | string]]> = [
|
|
852
|
+
[
|
|
853
|
+
['0x00000000000000000000000000000000000000000000000000000000000000c8'],
|
|
854
|
+
[200]
|
|
855
|
+
],
|
|
856
|
+
[
|
|
857
|
+
['0x000000000000000000000000000000000000000000000000000000000000a119'],
|
|
858
|
+
[41241]
|
|
859
|
+
],
|
|
860
|
+
];
|
|
861
|
+
|
|
862
|
+
examples.forEach(([expected, actual]) => {
|
|
863
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
864
|
+
expect(subDataService.cBondsRebondSubData.encode(...actual)).to.eql(expected);
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
});
|
|
868
|
+
|
|
720
869
|
describe('decode()', () => {
|
|
721
870
|
const examples: Array<[{ bondId: string }, SubData]> = [
|
|
722
871
|
[
|
|
@@ -867,7 +1016,54 @@ describe('Feature: subDataService.ts', () => {
|
|
|
867
1016
|
});
|
|
868
1017
|
});
|
|
869
1018
|
|
|
870
|
-
describe('When testing subDataService.
|
|
1019
|
+
describe('When testing subDataService.exchangeLimitOrderSubData', () => {
|
|
1020
|
+
describe('encode()', () => {
|
|
1021
|
+
const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
|
|
1022
|
+
[
|
|
1023
|
+
[
|
|
1024
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1025
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1026
|
+
'2131',
|
|
1027
|
+
'0.53123',
|
|
1028
|
+
'1696590921159',
|
|
1029
|
+
`${OrderType.STOP_LOSS}`
|
|
1030
|
+
],
|
|
1031
|
+
[
|
|
1032
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1033
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1034
|
+
'2131',
|
|
1035
|
+
'0.53123',
|
|
1036
|
+
1696590921159,
|
|
1037
|
+
OrderType.STOP_LOSS
|
|
1038
|
+
]
|
|
1039
|
+
],
|
|
1040
|
+
[
|
|
1041
|
+
[
|
|
1042
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1043
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1044
|
+
'2131',
|
|
1045
|
+
'0.43123',
|
|
1046
|
+
'1646590921159',
|
|
1047
|
+
`${OrderType.TAKE_PROFIT}`
|
|
1048
|
+
],
|
|
1049
|
+
[
|
|
1050
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1051
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1052
|
+
'2131',
|
|
1053
|
+
'0.43123',
|
|
1054
|
+
1646590921159,
|
|
1055
|
+
OrderType.TAKE_PROFIT
|
|
1056
|
+
]
|
|
1057
|
+
],
|
|
1058
|
+
];
|
|
1059
|
+
|
|
1060
|
+
examples.forEach(([expected, actual]) => {
|
|
1061
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1062
|
+
expect(subDataService.exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
|
|
871
1067
|
describe('decode()', () => {
|
|
872
1068
|
const examples: Array<[{ fromToken: EthereumAddress, toToken: EthereumAddress, amount: string }, [SubData, ChainId]]> = [
|
|
873
1069
|
[
|
|
@@ -902,13 +1098,13 @@ describe('Feature: subDataService.ts', () => {
|
|
|
902
1098
|
|
|
903
1099
|
examples.forEach(([expected, actual]) => {
|
|
904
1100
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
905
|
-
expect(subDataService.
|
|
1101
|
+
expect(subDataService.exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
|
|
906
1102
|
});
|
|
907
1103
|
});
|
|
908
1104
|
});
|
|
909
1105
|
});
|
|
910
1106
|
|
|
911
|
-
describe('When testing subDataService.
|
|
1107
|
+
describe('When testing subDataService.sparkLeverageManagementSubData', () => {
|
|
912
1108
|
describe('decode()', () => {
|
|
913
1109
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
914
1110
|
[
|
|
@@ -923,7 +1119,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
923
1119
|
|
|
924
1120
|
examples.forEach(([expected, actual]) => {
|
|
925
1121
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
926
|
-
expect(subDataService.
|
|
1122
|
+
expect(subDataService.sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
927
1123
|
});
|
|
928
1124
|
});
|
|
929
1125
|
});
|
|
@@ -6,7 +6,7 @@ import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisave
|
|
|
6
6
|
import { otherAddresses } from '@defisaver/sdk';
|
|
7
7
|
|
|
8
8
|
import type { SubData, EthereumAddress } from '../types';
|
|
9
|
-
import type { CloseStrategyType } from '../types/enums';
|
|
9
|
+
import type { CloseStrategyType, OrderType } from '../types/enums';
|
|
10
10
|
import {
|
|
11
11
|
ChainId, CollActionType, DebtActionType, RatioState,
|
|
12
12
|
} from '../types/enums';
|
|
@@ -24,6 +24,22 @@ import { compareAddresses, ratioPercentageToWei, weiToRatioPercentage } from './
|
|
|
24
24
|
|_______/ |_______|| _| | _| `._____||_______| \______/__/ \__\ |__| |_______||_______/
|
|
25
25
|
*/
|
|
26
26
|
export const morphoAaveV2LeverageManagementSubData = {
|
|
27
|
+
encode(
|
|
28
|
+
triggerRepayRatio: number,
|
|
29
|
+
triggerBoostRatio: number,
|
|
30
|
+
targetBoostRatio: number,
|
|
31
|
+
targetRepayRatio: number,
|
|
32
|
+
boostEnabled: boolean,
|
|
33
|
+
): SubData {
|
|
34
|
+
return [
|
|
35
|
+
ratioPercentageToWei(triggerRepayRatio),
|
|
36
|
+
ratioPercentageToWei(triggerBoostRatio),
|
|
37
|
+
ratioPercentageToWei(targetBoostRatio),
|
|
38
|
+
ratioPercentageToWei(targetRepayRatio),
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
boostEnabled,
|
|
41
|
+
];
|
|
42
|
+
},
|
|
27
43
|
decode(subData: SubData): { targetRatio: number } {
|
|
28
44
|
const ratioWei = AbiCoder.decodeParameter('uint128', subData[1]) as any as string;
|
|
29
45
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -32,6 +48,10 @@ export const morphoAaveV2LeverageManagementSubData = {
|
|
|
32
48
|
},
|
|
33
49
|
};
|
|
34
50
|
export const cBondsRebondSubData = {
|
|
51
|
+
encode(bondId: number | string): SubData {
|
|
52
|
+
const bondIdEncoded = AbiCoder.encodeParameter('uint256', bondId);
|
|
53
|
+
return [bondIdEncoded];
|
|
54
|
+
},
|
|
35
55
|
decode(subData: SubData): { bondId: string } {
|
|
36
56
|
const bondId = AbiCoder.decodeParameter('uint256', subData[1])!.toString();
|
|
37
57
|
return { bondId };
|
|
@@ -136,7 +156,7 @@ export const makerCloseSubData = {
|
|
|
136
156
|
};
|
|
137
157
|
},
|
|
138
158
|
};
|
|
139
|
-
export const
|
|
159
|
+
export const makerLeverageManagementSubData = {
|
|
140
160
|
decode: (subData:SubData) => {
|
|
141
161
|
const vaultId = +AbiCoder.decodeParameter('uint256', subData[0])!.toString();
|
|
142
162
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
@@ -144,8 +164,7 @@ export const legacyMakerLeverageManagementSubData = {
|
|
|
144
164
|
return { vaultId, targetRatio };
|
|
145
165
|
},
|
|
146
166
|
};
|
|
147
|
-
|
|
148
|
-
export const makerLeverageManagementSubData = {
|
|
167
|
+
export const makerLeverageManagementWithoutSubProxy = {
|
|
149
168
|
encode(
|
|
150
169
|
vaultId: number,
|
|
151
170
|
targetRatio: number,
|
|
@@ -165,9 +184,6 @@ export const makerLeverageManagementSubData = {
|
|
|
165
184
|
},
|
|
166
185
|
};
|
|
167
186
|
|
|
168
|
-
export const makerLiquidationProtectionSubData = makerLeverageManagementSubData;
|
|
169
|
-
|
|
170
|
-
|
|
171
187
|
/**
|
|
172
188
|
__ __ ______ __ __ __ .___________.____ ____ ____ ____ __
|
|
173
189
|
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
|
|
@@ -184,14 +200,14 @@ export const liquityRepayFromSavingsSubData = {
|
|
|
184
200
|
return { targetRatio };
|
|
185
201
|
},
|
|
186
202
|
};
|
|
187
|
-
export const
|
|
203
|
+
export const liquityLeverageManagementSubData = {
|
|
188
204
|
decode: (subData:SubData) => {
|
|
189
205
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
190
206
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
191
207
|
return { targetRatio };
|
|
192
208
|
},
|
|
193
209
|
};
|
|
194
|
-
export const
|
|
210
|
+
export const liquityLeverageManagementSubDataWithoutSubProxy = {
|
|
195
211
|
encode(
|
|
196
212
|
targetRatio: number,
|
|
197
213
|
ratioState: RatioState,
|
|
@@ -494,7 +510,23 @@ export const liquityV2PaybackSubData = {
|
|
|
494
510
|
/ _____ \ / _____ \ \ / | |____ \ / / /_
|
|
495
511
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____|
|
|
496
512
|
*/
|
|
497
|
-
export const
|
|
513
|
+
export const aaveV2LeverageManagementSubData = {
|
|
514
|
+
encode(
|
|
515
|
+
triggerRepayRatio: number,
|
|
516
|
+
triggerBoostRatio: number,
|
|
517
|
+
targetBoostRatio: number,
|
|
518
|
+
targetRepayRatio: number,
|
|
519
|
+
boostEnabled: boolean,
|
|
520
|
+
): SubData {
|
|
521
|
+
return [
|
|
522
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
523
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
524
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
525
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
526
|
+
// @ts-ignore // TODO
|
|
527
|
+
boostEnabled,
|
|
528
|
+
];
|
|
529
|
+
},
|
|
498
530
|
decode(subData: SubData): { targetRatio: number } {
|
|
499
531
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
500
532
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -502,7 +534,7 @@ export const legacyAaveV2LeverageManagementSubData = {
|
|
|
502
534
|
return { targetRatio };
|
|
503
535
|
},
|
|
504
536
|
};
|
|
505
|
-
export const
|
|
537
|
+
export const aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
506
538
|
encode(
|
|
507
539
|
market: EthereumAddress,
|
|
508
540
|
targetRatio: number,
|
|
@@ -538,7 +570,7 @@ export const aaveV2LeverageManagementSubData = {
|
|
|
538
570
|
/ _____ \ / _____ \ \ / | |____ \ / ___) |
|
|
539
571
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____/
|
|
540
572
|
*/
|
|
541
|
-
export const
|
|
573
|
+
export const aaveV3LeverageManagementSubData = {
|
|
542
574
|
decode(subData: SubData): { targetRatio: number } {
|
|
543
575
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
544
576
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -546,8 +578,7 @@ export const legacyAaveV3LeverageManagementSubData = {
|
|
|
546
578
|
return { targetRatio };
|
|
547
579
|
},
|
|
548
580
|
};
|
|
549
|
-
|
|
550
|
-
export const aaveV3LeverageManagementSubData = {
|
|
581
|
+
export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
551
582
|
encode(
|
|
552
583
|
targetRatio: number,
|
|
553
584
|
ratioState: RatioState,
|
|
@@ -574,9 +605,6 @@ export const aaveV3LeverageManagementSubData = {
|
|
|
574
605
|
return { targetRatio, ratioState };
|
|
575
606
|
},
|
|
576
607
|
};
|
|
577
|
-
|
|
578
|
-
export const aaveV3LiquidationProtectionSubData = aaveV3LeverageManagementSubData;
|
|
579
|
-
|
|
580
608
|
export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
581
609
|
encode(
|
|
582
610
|
collAsset: EthereumAddress,
|
|
@@ -823,7 +851,6 @@ export const aaveV3LeverageManagementOnPriceSubData = {
|
|
|
823
851
|
/ _____ \ / _____ \ \ / | |____ \ / | |
|
|
824
852
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
|
|
825
853
|
*/
|
|
826
|
-
|
|
827
854
|
export const aaveV4LeverageManagementSubData = {
|
|
828
855
|
encode: (
|
|
829
856
|
spoke: EthereumAddress,
|
|
@@ -855,9 +882,6 @@ export const aaveV4LeverageManagementSubData = {
|
|
|
855
882
|
};
|
|
856
883
|
},
|
|
857
884
|
};
|
|
858
|
-
|
|
859
|
-
export const aaveV4LiquidationProtectionSubData = aaveV4LeverageManagementSubData;
|
|
860
|
-
|
|
861
885
|
export const aaveV4LeverageManagementOnPriceSubData = {
|
|
862
886
|
encode: (
|
|
863
887
|
spoke: EthereumAddress,
|
|
@@ -1000,7 +1024,23 @@ export const aaveV4CollateralSwitchSubData = {
|
|
|
1000
1024
|
| `----.| `--' | | | | | | | \ / / /_
|
|
1001
1025
|
\______| \______/ |__| |__| | _| \__/ |____|
|
|
1002
1026
|
*/
|
|
1003
|
-
export const
|
|
1027
|
+
export const compoundV2LeverageManagementSubData = {
|
|
1028
|
+
encode(
|
|
1029
|
+
triggerRepayRatio: number,
|
|
1030
|
+
triggerBoostRatio: number,
|
|
1031
|
+
targetBoostRatio: number,
|
|
1032
|
+
targetRepayRatio: number,
|
|
1033
|
+
boostEnabled: boolean,
|
|
1034
|
+
): SubData {
|
|
1035
|
+
return [
|
|
1036
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
1037
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
1038
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
1039
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
1040
|
+
// @ts-ignore // TODO
|
|
1041
|
+
boostEnabled,
|
|
1042
|
+
];
|
|
1043
|
+
},
|
|
1004
1044
|
decode(subData: SubData): { targetRatio: number } {
|
|
1005
1045
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
1006
1046
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
@@ -1008,7 +1048,7 @@ export const legacyCompoundV2LeverageManagementSubData = {
|
|
|
1008
1048
|
return { targetRatio };
|
|
1009
1049
|
},
|
|
1010
1050
|
};
|
|
1011
|
-
export const
|
|
1051
|
+
export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
1012
1052
|
encode(
|
|
1013
1053
|
targetRatio: number,
|
|
1014
1054
|
ratioState: RatioState,
|
|
@@ -1041,8 +1081,36 @@ export const compoundV2LeverageManagementSubData = {
|
|
|
1041
1081
|
| `----.| `--' | | | | | | | \ / ___) |
|
|
1042
1082
|
\______| \______/ |__| |__| | _| \__/ |____/
|
|
1043
1083
|
*/
|
|
1044
|
-
|
|
1045
1084
|
export const compoundV3LeverageManagementSubData = {
|
|
1085
|
+
encode(
|
|
1086
|
+
market: EthereumAddress,
|
|
1087
|
+
baseToken: EthereumAddress,
|
|
1088
|
+
triggerRepayRatio: number,
|
|
1089
|
+
triggerBoostRatio: number,
|
|
1090
|
+
targetBoostRatio: number,
|
|
1091
|
+
targetRepayRatio: number,
|
|
1092
|
+
boostEnabled: boolean,
|
|
1093
|
+
isEOA: boolean,
|
|
1094
|
+
): SubData {
|
|
1095
|
+
return [
|
|
1096
|
+
market,
|
|
1097
|
+
baseToken,
|
|
1098
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
1099
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
1100
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
1101
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
1102
|
+
// @ts-ignore // TODO
|
|
1103
|
+
boostEnabled, isEOA,
|
|
1104
|
+
];
|
|
1105
|
+
},
|
|
1106
|
+
decode(subData: SubData): { targetRatio: number } {
|
|
1107
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
|
|
1108
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1109
|
+
|
|
1110
|
+
return { targetRatio };
|
|
1111
|
+
},
|
|
1112
|
+
};
|
|
1113
|
+
export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
1046
1114
|
encode(
|
|
1047
1115
|
market: EthereumAddress,
|
|
1048
1116
|
baseToken: EthereumAddress,
|
|
@@ -1066,9 +1134,6 @@ export const compoundV3LeverageManagementSubData = {
|
|
|
1066
1134
|
};
|
|
1067
1135
|
},
|
|
1068
1136
|
};
|
|
1069
|
-
|
|
1070
|
-
export const compoundV3LiquidationProtectionSubData = compoundV3LeverageManagementSubData;
|
|
1071
|
-
|
|
1072
1137
|
export const compoundV3LeverageManagementOnPriceSubData = {
|
|
1073
1138
|
encode(
|
|
1074
1139
|
market: EthereumAddress,
|
|
@@ -1186,7 +1251,17 @@ export const exchangeDcaSubData = {
|
|
|
1186
1251
|
};
|
|
1187
1252
|
},
|
|
1188
1253
|
};
|
|
1189
|
-
export const
|
|
1254
|
+
export const exchangeLimitOrderSubData = {
|
|
1255
|
+
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType) : SubData {
|
|
1256
|
+
return [
|
|
1257
|
+
fromToken,
|
|
1258
|
+
toToken,
|
|
1259
|
+
amount,
|
|
1260
|
+
targetPrice,
|
|
1261
|
+
new Dec(goodUntil).toString(),
|
|
1262
|
+
new Dec(orderType).toString(),
|
|
1263
|
+
];
|
|
1264
|
+
},
|
|
1190
1265
|
decode: (subData: SubData, chainId: ChainId) => {
|
|
1191
1266
|
const fromToken = AbiCoder.decodeParameter('address', subData[0])!.toString();
|
|
1192
1267
|
const toToken = AbiCoder.decodeParameter('address', subData[1])!.toString();
|
|
@@ -1194,7 +1269,7 @@ export const legacyExchangeLimitOrderSubData = {
|
|
|
1194
1269
|
return { fromToken, toToken, amount };
|
|
1195
1270
|
},
|
|
1196
1271
|
};
|
|
1197
|
-
export const
|
|
1272
|
+
export const exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
1198
1273
|
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string): SubData {
|
|
1199
1274
|
return [
|
|
1200
1275
|
AbiCoder.encodeParameter('address', fromToken),
|
|
@@ -1218,7 +1293,7 @@ export const exchangeLimitOrderSubData = {
|
|
|
1218
1293
|
.----) | | | / _____ \ | |\ \----.| . \
|
|
1219
1294
|
|_______/ | _| /__/ \__\ | _| `._____||__|\__\
|
|
1220
1295
|
*/
|
|
1221
|
-
export const
|
|
1296
|
+
export const sparkLeverageManagementSubData = {
|
|
1222
1297
|
decode(subData: SubData): { targetRatio: number } {
|
|
1223
1298
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
1224
1299
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -1226,8 +1301,7 @@ export const legacySparkLeverageManagementSubData = {
|
|
|
1226
1301
|
return { targetRatio };
|
|
1227
1302
|
},
|
|
1228
1303
|
};
|
|
1229
|
-
|
|
1230
|
-
export const sparkLeverageManagementSubData = {
|
|
1304
|
+
export const sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
1231
1305
|
encode(
|
|
1232
1306
|
targetRatio: number,
|
|
1233
1307
|
ratioState: RatioState,
|
|
@@ -1246,10 +1320,6 @@ export const sparkLeverageManagementSubData = {
|
|
|
1246
1320
|
return { targetRatio, ratioState };
|
|
1247
1321
|
},
|
|
1248
1322
|
};
|
|
1249
|
-
|
|
1250
|
-
export const sparkLiquidationProtectionSubData = sparkLeverageManagementSubData;
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
1323
|
export const sparkCloseGenericSubData = {
|
|
1254
1324
|
encode(
|
|
1255
1325
|
collAsset: EthereumAddress,
|
|
@@ -1464,7 +1534,6 @@ export const crvUSDPaybackSubData = {
|
|
|
1464
1534
|
| | | | | `--' | | |\ \----.| | | | | | | `--' |
|
|
1465
1535
|
|__| |__| \______/ | _| `._____|| _| |__| |__| \______/
|
|
1466
1536
|
*/
|
|
1467
|
-
|
|
1468
1537
|
export const morphoBlueLeverageManagementSubData = {
|
|
1469
1538
|
encode: (
|
|
1470
1539
|
loanToken: EthereumAddress,
|
|
@@ -1509,9 +1578,6 @@ export const morphoBlueLeverageManagementSubData = {
|
|
|
1509
1578
|
};
|
|
1510
1579
|
},
|
|
1511
1580
|
};
|
|
1512
|
-
|
|
1513
|
-
export const morphoBlueLiquidationProtectionSubData = morphoBlueLeverageManagementSubData;
|
|
1514
|
-
|
|
1515
1581
|
export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
1516
1582
|
encode(
|
|
1517
1583
|
loanToken: EthereumAddress,
|
|
@@ -1642,5 +1708,3 @@ export const fluidLeverageManagementSubData = {
|
|
|
1642
1708
|
};
|
|
1643
1709
|
},
|
|
1644
1710
|
};
|
|
1645
|
-
|
|
1646
|
-
export const fluidLiquidationProtectionSubData = fluidLeverageManagementSubData;
|