@defisaver/automation-sdk 3.3.16-dev-13082-morpho-eoa-dev → 3.3.16-liq-prot-dev
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 +117 -42
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +5 -2
- package/cjs/services/strategiesService.js +157 -12
- package/cjs/services/strategySubService.d.ts +18 -21
- package/cjs/services/strategySubService.js +78 -74
- package/cjs/services/strategySubService.test.js +3 -149
- package/cjs/services/subDataService.d.ts +70 -20
- package/cjs/services/subDataService.js +23 -79
- package/cjs/services/subDataService.test.js +17 -202
- package/cjs/services/utils.d.ts +2 -1
- package/cjs/services/utils.js +14 -1
- package/cjs/types/enums.d.ts +36 -17
- package/cjs/types/enums.js +30 -11
- package/esm/constants/index.js +117 -42
- package/esm/index.d.ts +2 -2
- package/esm/index.js +5 -2
- package/esm/services/strategiesService.js +157 -12
- package/esm/services/strategySubService.d.ts +18 -21
- package/esm/services/strategySubService.js +78 -73
- package/esm/services/strategySubService.test.js +4 -147
- package/esm/services/subDataService.d.ts +70 -20
- package/esm/services/subDataService.js +21 -77
- package/esm/services/subDataService.test.js +18 -200
- package/esm/services/utils.d.ts +2 -1
- package/esm/services/utils.js +13 -1
- package/esm/types/enums.d.ts +36 -17
- package/esm/types/enums.js +30 -11
- package/package.json +1 -1
- package/src/constants/index.ts +119 -43
- package/src/index.ts +22 -6
- package/src/services/strategiesService.ts +221 -12
- package/src/services/strategySubService.test.ts +3 -191
- package/src/services/strategySubService.ts +173 -121
- package/src/services/subDataService.test.ts +18 -214
- package/src/services/subDataService.ts +42 -106
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +15 -1
- package/src/types/enums.ts +30 -13
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
1
|
import { expect } from 'chai';
|
|
3
2
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
4
3
|
import * as web3Utils from 'web3-utils';
|
|
5
4
|
import { MAXUINT } from '@defisaver/tokens';
|
|
6
5
|
|
|
7
|
-
import { ChainId, CloseStrategyType,
|
|
6
|
+
import { ChainId, CloseStrategyType, RatioState } from '../types/enums';
|
|
8
7
|
import type { EthereumAddress, SubData } from '../types';
|
|
9
8
|
|
|
10
9
|
import '../configuration';
|
|
@@ -133,7 +132,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
133
132
|
});
|
|
134
133
|
});
|
|
135
134
|
|
|
136
|
-
describe('When testing subDataService.
|
|
135
|
+
describe('When testing subDataService.legacyMakerLeverageManagementSubData', () => {
|
|
137
136
|
describe('decode()', () => {
|
|
138
137
|
const examples: Array<[{ vaultId: number, targetRatio: number }, SubData]> = [
|
|
139
138
|
[
|
|
@@ -147,13 +146,13 @@ describe('Feature: subDataService.ts', () => {
|
|
|
147
146
|
|
|
148
147
|
examples.forEach(([expected, actual]) => {
|
|
149
148
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
150
|
-
expect(subDataService.
|
|
149
|
+
expect(subDataService.legacyMakerLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
151
150
|
});
|
|
152
151
|
});
|
|
153
152
|
});
|
|
154
153
|
});
|
|
155
154
|
|
|
156
|
-
describe('When testing subDataService.
|
|
155
|
+
describe('When testing subDataService.makerLeverageManagementSubData', () => {
|
|
157
156
|
describe('encode()', () => {
|
|
158
157
|
const examples: Array<[SubData, [vaultId: number, targetRatio: number, daiAddr?: EthereumAddress]]> = [
|
|
159
158
|
[
|
|
@@ -174,7 +173,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
174
173
|
|
|
175
174
|
examples.forEach(([expected, actual]) => {
|
|
176
175
|
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
177
|
-
expect(subDataService.
|
|
176
|
+
expect(subDataService.makerLeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
178
177
|
});
|
|
179
178
|
});
|
|
180
179
|
});
|
|
@@ -207,13 +206,13 @@ describe('Feature: subDataService.ts', () => {
|
|
|
207
206
|
|
|
208
207
|
examples.forEach(([expected, actual]) => {
|
|
209
208
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
210
|
-
expect(subDataService.
|
|
209
|
+
expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
211
210
|
});
|
|
212
211
|
});
|
|
213
212
|
});
|
|
214
213
|
});
|
|
215
214
|
|
|
216
|
-
describe('When testing subDataService.
|
|
215
|
+
describe('When testing subDataService.legacyLiquityLeverageManagementSubData', () => {
|
|
217
216
|
describe('decode()', () => {
|
|
218
217
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
219
218
|
[
|
|
@@ -227,7 +226,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
227
226
|
|
|
228
227
|
examples.forEach(([expected, actual]) => {
|
|
229
228
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
230
|
-
expect(subDataService.
|
|
229
|
+
expect(subDataService.legacyLiquityLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
231
230
|
});
|
|
232
231
|
});
|
|
233
232
|
});
|
|
@@ -287,26 +286,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
287
286
|
});
|
|
288
287
|
});
|
|
289
288
|
|
|
290
|
-
describe('When testing subDataService.
|
|
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
|
-
|
|
289
|
+
describe('When testing subDataService.legacyAaveV2LeverageManagementSubData', () => {
|
|
310
290
|
describe('decode()', () => {
|
|
311
291
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
312
292
|
[
|
|
@@ -321,13 +301,13 @@ describe('Feature: subDataService.ts', () => {
|
|
|
321
301
|
|
|
322
302
|
examples.forEach(([expected, actual]) => {
|
|
323
303
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
324
|
-
expect(subDataService.
|
|
304
|
+
expect(subDataService.legacyAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
325
305
|
});
|
|
326
306
|
});
|
|
327
307
|
});
|
|
328
308
|
});
|
|
329
309
|
|
|
330
|
-
describe('When testing subDataService.
|
|
310
|
+
describe('When testing subDataService.legacyAaveV3LeverageManagementSubData', () => {
|
|
331
311
|
describe('decode()', () => {
|
|
332
312
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
333
313
|
[
|
|
@@ -342,7 +322,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
342
322
|
|
|
343
323
|
examples.forEach(([expected, actual]) => {
|
|
344
324
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
345
|
-
expect(subDataService.
|
|
325
|
+
expect(subDataService.legacyAaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
346
326
|
});
|
|
347
327
|
});
|
|
348
328
|
});
|
|
@@ -694,26 +674,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
694
674
|
});
|
|
695
675
|
});
|
|
696
676
|
|
|
697
|
-
describe('When testing subDataService.
|
|
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
|
-
|
|
677
|
+
describe('When testing subDataService.legacyCompoundV2LeverageManagementSubData', () => {
|
|
717
678
|
describe('decode()', () => {
|
|
718
679
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
719
680
|
[
|
|
@@ -728,104 +689,13 @@ describe('Feature: subDataService.ts', () => {
|
|
|
728
689
|
|
|
729
690
|
examples.forEach(([expected, actual]) => {
|
|
730
691
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
731
|
-
expect(subDataService.
|
|
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);
|
|
692
|
+
expect(subDataService.legacyCompoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
804
693
|
});
|
|
805
694
|
});
|
|
806
695
|
});
|
|
807
696
|
});
|
|
808
697
|
|
|
809
698
|
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
|
-
|
|
829
699
|
describe('decode()', () => {
|
|
830
700
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
831
701
|
[
|
|
@@ -847,25 +717,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
847
717
|
});
|
|
848
718
|
|
|
849
719
|
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
|
-
|
|
869
720
|
describe('decode()', () => {
|
|
870
721
|
const examples: Array<[{ bondId: string }, SubData]> = [
|
|
871
722
|
[
|
|
@@ -1016,54 +867,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1016
867
|
});
|
|
1017
868
|
});
|
|
1018
869
|
|
|
1019
|
-
describe('When testing subDataService.
|
|
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
|
-
|
|
870
|
+
describe('When testing subDataService.legacyExchangeLimitOrderSubData', () => {
|
|
1067
871
|
describe('decode()', () => {
|
|
1068
872
|
const examples: Array<[{ fromToken: EthereumAddress, toToken: EthereumAddress, amount: string }, [SubData, ChainId]]> = [
|
|
1069
873
|
[
|
|
@@ -1098,13 +902,13 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1098
902
|
|
|
1099
903
|
examples.forEach(([expected, actual]) => {
|
|
1100
904
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1101
|
-
expect(subDataService.
|
|
905
|
+
expect(subDataService.legacyExchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
|
|
1102
906
|
});
|
|
1103
907
|
});
|
|
1104
908
|
});
|
|
1105
909
|
});
|
|
1106
910
|
|
|
1107
|
-
describe('When testing subDataService.
|
|
911
|
+
describe('When testing subDataService.legacySparkLeverageManagementSubData', () => {
|
|
1108
912
|
describe('decode()', () => {
|
|
1109
913
|
const examples: Array<[{ targetRatio: number }, SubData]> = [
|
|
1110
914
|
[
|
|
@@ -1119,7 +923,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1119
923
|
|
|
1120
924
|
examples.forEach(([expected, actual]) => {
|
|
1121
925
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1122
|
-
expect(subDataService.
|
|
926
|
+
expect(subDataService.legacySparkLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
1123
927
|
});
|
|
1124
928
|
});
|
|
1125
929
|
});
|
|
@@ -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
|
|
9
|
+
import type { CloseStrategyType } from '../types/enums';
|
|
10
10
|
import {
|
|
11
11
|
ChainId, CollActionType, DebtActionType, RatioState,
|
|
12
12
|
} from '../types/enums';
|
|
@@ -24,22 +24,6 @@ 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
|
-
},
|
|
43
27
|
decode(subData: SubData): { targetRatio: number } {
|
|
44
28
|
const ratioWei = AbiCoder.decodeParameter('uint128', subData[1]) as any as string;
|
|
45
29
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -48,10 +32,6 @@ export const morphoAaveV2LeverageManagementSubData = {
|
|
|
48
32
|
},
|
|
49
33
|
};
|
|
50
34
|
export const cBondsRebondSubData = {
|
|
51
|
-
encode(bondId: number | string): SubData {
|
|
52
|
-
const bondIdEncoded = AbiCoder.encodeParameter('uint256', bondId);
|
|
53
|
-
return [bondIdEncoded];
|
|
54
|
-
},
|
|
55
35
|
decode(subData: SubData): { bondId: string } {
|
|
56
36
|
const bondId = AbiCoder.decodeParameter('uint256', subData[1])!.toString();
|
|
57
37
|
return { bondId };
|
|
@@ -156,7 +136,7 @@ export const makerCloseSubData = {
|
|
|
156
136
|
};
|
|
157
137
|
},
|
|
158
138
|
};
|
|
159
|
-
export const
|
|
139
|
+
export const legacyMakerLeverageManagementSubData = {
|
|
160
140
|
decode: (subData:SubData) => {
|
|
161
141
|
const vaultId = +AbiCoder.decodeParameter('uint256', subData[0])!.toString();
|
|
162
142
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
@@ -164,7 +144,8 @@ export const makerLeverageManagementSubData = {
|
|
|
164
144
|
return { vaultId, targetRatio };
|
|
165
145
|
},
|
|
166
146
|
};
|
|
167
|
-
|
|
147
|
+
|
|
148
|
+
export const makerLeverageManagementSubData = {
|
|
168
149
|
encode(
|
|
169
150
|
vaultId: number,
|
|
170
151
|
targetRatio: number,
|
|
@@ -184,6 +165,9 @@ export const makerLeverageManagementWithoutSubProxy = {
|
|
|
184
165
|
},
|
|
185
166
|
};
|
|
186
167
|
|
|
168
|
+
export const makerLiquidationProtectionSubData = makerLeverageManagementSubData;
|
|
169
|
+
|
|
170
|
+
|
|
187
171
|
/**
|
|
188
172
|
__ __ ______ __ __ __ .___________.____ ____ ____ ____ __
|
|
189
173
|
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
|
|
@@ -200,14 +184,14 @@ export const liquityRepayFromSavingsSubData = {
|
|
|
200
184
|
return { targetRatio };
|
|
201
185
|
},
|
|
202
186
|
};
|
|
203
|
-
export const
|
|
187
|
+
export const legacyLiquityLeverageManagementSubData = {
|
|
204
188
|
decode: (subData:SubData) => {
|
|
205
189
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
206
190
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
207
191
|
return { targetRatio };
|
|
208
192
|
},
|
|
209
193
|
};
|
|
210
|
-
export const
|
|
194
|
+
export const liquityLeverageManagementSubData = {
|
|
211
195
|
encode(
|
|
212
196
|
targetRatio: number,
|
|
213
197
|
ratioState: RatioState,
|
|
@@ -510,23 +494,7 @@ export const liquityV2PaybackSubData = {
|
|
|
510
494
|
/ _____ \ / _____ \ \ / | |____ \ / / /_
|
|
511
495
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____|
|
|
512
496
|
*/
|
|
513
|
-
export const
|
|
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
|
-
},
|
|
497
|
+
export const legacyAaveV2LeverageManagementSubData = {
|
|
530
498
|
decode(subData: SubData): { targetRatio: number } {
|
|
531
499
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
532
500
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -534,7 +502,7 @@ export const aaveV2LeverageManagementSubData = {
|
|
|
534
502
|
return { targetRatio };
|
|
535
503
|
},
|
|
536
504
|
};
|
|
537
|
-
export const
|
|
505
|
+
export const aaveV2LeverageManagementSubData = {
|
|
538
506
|
encode(
|
|
539
507
|
market: EthereumAddress,
|
|
540
508
|
targetRatio: number,
|
|
@@ -570,7 +538,7 @@ export const aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
|
570
538
|
/ _____ \ / _____ \ \ / | |____ \ / ___) |
|
|
571
539
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____/
|
|
572
540
|
*/
|
|
573
|
-
export const
|
|
541
|
+
export const legacyAaveV3LeverageManagementSubData = {
|
|
574
542
|
decode(subData: SubData): { targetRatio: number } {
|
|
575
543
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
576
544
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -578,7 +546,8 @@ export const aaveV3LeverageManagementSubData = {
|
|
|
578
546
|
return { targetRatio };
|
|
579
547
|
},
|
|
580
548
|
};
|
|
581
|
-
|
|
549
|
+
|
|
550
|
+
export const aaveV3LeverageManagementSubData = {
|
|
582
551
|
encode(
|
|
583
552
|
targetRatio: number,
|
|
584
553
|
ratioState: RatioState,
|
|
@@ -605,6 +574,9 @@ export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
605
574
|
return { targetRatio, ratioState };
|
|
606
575
|
},
|
|
607
576
|
};
|
|
577
|
+
|
|
578
|
+
export const aaveV3LiquidationProtectionSubData = aaveV3LeverageManagementSubData;
|
|
579
|
+
|
|
608
580
|
export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
609
581
|
encode(
|
|
610
582
|
collAsset: EthereumAddress,
|
|
@@ -851,6 +823,7 @@ export const aaveV3LeverageManagementOnPriceSubData = {
|
|
|
851
823
|
/ _____ \ / _____ \ \ / | |____ \ / | |
|
|
852
824
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
|
|
853
825
|
*/
|
|
826
|
+
|
|
854
827
|
export const aaveV4LeverageManagementSubData = {
|
|
855
828
|
encode: (
|
|
856
829
|
spoke: EthereumAddress,
|
|
@@ -882,6 +855,9 @@ export const aaveV4LeverageManagementSubData = {
|
|
|
882
855
|
};
|
|
883
856
|
},
|
|
884
857
|
};
|
|
858
|
+
|
|
859
|
+
export const aaveV4LiquidationProtectionSubData = aaveV4LeverageManagementSubData;
|
|
860
|
+
|
|
885
861
|
export const aaveV4LeverageManagementOnPriceSubData = {
|
|
886
862
|
encode: (
|
|
887
863
|
spoke: EthereumAddress,
|
|
@@ -1024,23 +1000,7 @@ export const aaveV4CollateralSwitchSubData = {
|
|
|
1024
1000
|
| `----.| `--' | | | | | | | \ / / /_
|
|
1025
1001
|
\______| \______/ |__| |__| | _| \__/ |____|
|
|
1026
1002
|
*/
|
|
1027
|
-
export const
|
|
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
|
-
},
|
|
1003
|
+
export const legacyCompoundV2LeverageManagementSubData = {
|
|
1044
1004
|
decode(subData: SubData): { targetRatio: number } {
|
|
1045
1005
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
1046
1006
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
@@ -1048,7 +1008,7 @@ export const compoundV2LeverageManagementSubData = {
|
|
|
1048
1008
|
return { targetRatio };
|
|
1049
1009
|
},
|
|
1050
1010
|
};
|
|
1051
|
-
export const
|
|
1011
|
+
export const compoundV2LeverageManagementSubData = {
|
|
1052
1012
|
encode(
|
|
1053
1013
|
targetRatio: number,
|
|
1054
1014
|
ratioState: RatioState,
|
|
@@ -1081,36 +1041,8 @@ export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
|
1081
1041
|
| `----.| `--' | | | | | | | \ / ___) |
|
|
1082
1042
|
\______| \______/ |__| |__| | _| \__/ |____/
|
|
1083
1043
|
*/
|
|
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
1044
|
|
|
1110
|
-
|
|
1111
|
-
},
|
|
1112
|
-
};
|
|
1113
|
-
export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
1045
|
+
export const compoundV3LeverageManagementSubData = {
|
|
1114
1046
|
encode(
|
|
1115
1047
|
market: EthereumAddress,
|
|
1116
1048
|
baseToken: EthereumAddress,
|
|
@@ -1134,6 +1066,9 @@ export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
1134
1066
|
};
|
|
1135
1067
|
},
|
|
1136
1068
|
};
|
|
1069
|
+
|
|
1070
|
+
export const compoundV3LiquidationProtectionSubData = compoundV3LeverageManagementSubData;
|
|
1071
|
+
|
|
1137
1072
|
export const compoundV3LeverageManagementOnPriceSubData = {
|
|
1138
1073
|
encode(
|
|
1139
1074
|
market: EthereumAddress,
|
|
@@ -1251,17 +1186,7 @@ export const exchangeDcaSubData = {
|
|
|
1251
1186
|
};
|
|
1252
1187
|
},
|
|
1253
1188
|
};
|
|
1254
|
-
export const
|
|
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
|
-
},
|
|
1189
|
+
export const legacyExchangeLimitOrderSubData = {
|
|
1265
1190
|
decode: (subData: SubData, chainId: ChainId) => {
|
|
1266
1191
|
const fromToken = AbiCoder.decodeParameter('address', subData[0])!.toString();
|
|
1267
1192
|
const toToken = AbiCoder.decodeParameter('address', subData[1])!.toString();
|
|
@@ -1269,7 +1194,7 @@ export const exchangeLimitOrderSubData = {
|
|
|
1269
1194
|
return { fromToken, toToken, amount };
|
|
1270
1195
|
},
|
|
1271
1196
|
};
|
|
1272
|
-
export const
|
|
1197
|
+
export const exchangeLimitOrderSubData = {
|
|
1273
1198
|
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string): SubData {
|
|
1274
1199
|
return [
|
|
1275
1200
|
AbiCoder.encodeParameter('address', fromToken),
|
|
@@ -1293,7 +1218,7 @@ export const exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
|
1293
1218
|
.----) | | | / _____ \ | |\ \----.| . \
|
|
1294
1219
|
|_______/ | _| /__/ \__\ | _| `._____||__|\__\
|
|
1295
1220
|
*/
|
|
1296
|
-
export const
|
|
1221
|
+
export const legacySparkLeverageManagementSubData = {
|
|
1297
1222
|
decode(subData: SubData): { targetRatio: number } {
|
|
1298
1223
|
const ratioWei = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
|
|
1299
1224
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -1301,7 +1226,8 @@ export const sparkLeverageManagementSubData = {
|
|
|
1301
1226
|
return { targetRatio };
|
|
1302
1227
|
},
|
|
1303
1228
|
};
|
|
1304
|
-
|
|
1229
|
+
|
|
1230
|
+
export const sparkLeverageManagementSubData = {
|
|
1305
1231
|
encode(
|
|
1306
1232
|
targetRatio: number,
|
|
1307
1233
|
ratioState: RatioState,
|
|
@@ -1320,6 +1246,10 @@ export const sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
|
1320
1246
|
return { targetRatio, ratioState };
|
|
1321
1247
|
},
|
|
1322
1248
|
};
|
|
1249
|
+
|
|
1250
|
+
export const sparkLiquidationProtectionSubData = sparkLeverageManagementSubData;
|
|
1251
|
+
|
|
1252
|
+
|
|
1323
1253
|
export const sparkCloseGenericSubData = {
|
|
1324
1254
|
encode(
|
|
1325
1255
|
collAsset: EthereumAddress,
|
|
@@ -1534,6 +1464,7 @@ export const crvUSDPaybackSubData = {
|
|
|
1534
1464
|
| | | | | `--' | | |\ \----.| | | | | | | `--' |
|
|
1535
1465
|
|__| |__| \______/ | _| `._____|| _| |__| |__| \______/
|
|
1536
1466
|
*/
|
|
1467
|
+
|
|
1537
1468
|
export const morphoBlueLeverageManagementSubData = {
|
|
1538
1469
|
encode: (
|
|
1539
1470
|
loanToken: EthereumAddress,
|
|
@@ -1578,6 +1509,9 @@ export const morphoBlueLeverageManagementSubData = {
|
|
|
1578
1509
|
};
|
|
1579
1510
|
},
|
|
1580
1511
|
};
|
|
1512
|
+
|
|
1513
|
+
export const morphoBlueLiquidationProtectionSubData = morphoBlueLeverageManagementSubData;
|
|
1514
|
+
|
|
1581
1515
|
export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
1582
1516
|
encode(
|
|
1583
1517
|
loanToken: EthereumAddress,
|
|
@@ -1708,3 +1642,5 @@ export const fluidLeverageManagementSubData = {
|
|
|
1708
1642
|
};
|
|
1709
1643
|
},
|
|
1710
1644
|
};
|
|
1645
|
+
|
|
1646
|
+
export const fluidLiquidationProtectionSubData = fluidLeverageManagementSubData;
|