@defisaver/automation-sdk 3.3.15-liq-prot-3-dev → 3.3.16-dev-13082-morpho-eoa-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 +51 -111
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +2 -5
- package/cjs/services/strategiesService.js +13 -157
- package/cjs/services/strategySubService.d.ts +21 -18
- package/cjs/services/strategySubService.js +74 -78
- package/cjs/services/strategySubService.test.js +216 -3
- package/cjs/services/subDataService.d.ts +20 -70
- package/cjs/services/subDataService.js +79 -23
- package/cjs/services/subDataService.test.js +302 -17
- package/cjs/services/triggerService.test.js +60 -0
- package/cjs/services/utils.d.ts +1 -2
- package/cjs/services/utils.js +1 -14
- package/cjs/types/enums.d.ts +17 -33
- package/cjs/types/enums.js +14 -30
- package/esm/constants/index.js +51 -111
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -5
- package/esm/services/strategiesService.js +13 -157
- package/esm/services/strategySubService.d.ts +21 -18
- package/esm/services/strategySubService.js +73 -78
- package/esm/services/strategySubService.test.js +214 -4
- package/esm/services/subDataService.d.ts +20 -70
- package/esm/services/subDataService.js +77 -21
- package/esm/services/subDataService.test.js +300 -18
- package/esm/services/triggerService.test.js +61 -1
- package/esm/services/utils.d.ts +1 -2
- package/esm/services/utils.js +1 -13
- package/esm/types/enums.d.ts +17 -33
- package/esm/types/enums.js +14 -30
- package/package.json +1 -1
- package/src/constants/index.ts +52 -113
- package/src/index.ts +6 -22
- package/src/services/strategiesService.ts +13 -221
- package/src/services/strategySubService.test.ts +275 -3
- package/src/services/strategySubService.ts +121 -173
- package/src/services/subDataService.test.ts +324 -18
- package/src/services/subDataService.ts +106 -42
- package/src/services/triggerService.test.ts +69 -0
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +1 -15
- package/src/types/enums.ts +16 -30
|
@@ -1,8 +1,9 @@
|
|
|
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
|
-
import { ChainId, CloseStrategyType, RatioState } from '../types/enums';
|
|
6
|
+
import { ChainId, CloseStrategyType, OrderType, RatioState } from '../types/enums';
|
|
6
7
|
import '../configuration';
|
|
7
8
|
import * as subDataService from './subDataService';
|
|
8
9
|
describe('Feature: subDataService.ts', () => {
|
|
@@ -117,7 +118,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
117
118
|
});
|
|
118
119
|
});
|
|
119
120
|
});
|
|
120
|
-
describe('When testing subDataService.
|
|
121
|
+
describe('When testing subDataService.makerLeverageManagementSubData', () => {
|
|
121
122
|
describe('decode()', () => {
|
|
122
123
|
const examples = [
|
|
123
124
|
[
|
|
@@ -130,12 +131,12 @@ describe('Feature: subDataService.ts', () => {
|
|
|
130
131
|
];
|
|
131
132
|
examples.forEach(([expected, actual]) => {
|
|
132
133
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
133
|
-
expect(subDataService.
|
|
134
|
+
expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
134
135
|
});
|
|
135
136
|
});
|
|
136
137
|
});
|
|
137
138
|
});
|
|
138
|
-
describe('When testing subDataService.
|
|
139
|
+
describe('When testing subDataService.makerLeverageManagementWithoutSubProxy', () => {
|
|
139
140
|
describe('encode()', () => {
|
|
140
141
|
const examples = [
|
|
141
142
|
[
|
|
@@ -155,7 +156,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
155
156
|
];
|
|
156
157
|
examples.forEach(([expected, actual]) => {
|
|
157
158
|
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
158
|
-
expect(subDataService.
|
|
159
|
+
expect(subDataService.makerLeverageManagementWithoutSubProxy.encode(...actual)).to.eql(expected);
|
|
159
160
|
});
|
|
160
161
|
});
|
|
161
162
|
});
|
|
@@ -186,12 +187,12 @@ describe('Feature: subDataService.ts', () => {
|
|
|
186
187
|
];
|
|
187
188
|
examples.forEach(([expected, actual]) => {
|
|
188
189
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
189
|
-
expect(subDataService.
|
|
190
|
+
expect(subDataService.makerLeverageManagementWithoutSubProxy.decode(actual)).to.eql(expected);
|
|
190
191
|
});
|
|
191
192
|
});
|
|
192
193
|
});
|
|
193
194
|
});
|
|
194
|
-
describe('When testing subDataService.
|
|
195
|
+
describe('When testing subDataService.liquityLeverageManagementSubData', () => {
|
|
195
196
|
describe('decode()', () => {
|
|
196
197
|
const examples = [
|
|
197
198
|
[
|
|
@@ -204,7 +205,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
204
205
|
];
|
|
205
206
|
examples.forEach(([expected, actual]) => {
|
|
206
207
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
207
|
-
expect(subDataService.
|
|
208
|
+
expect(subDataService.liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
208
209
|
});
|
|
209
210
|
});
|
|
210
211
|
});
|
|
@@ -259,7 +260,24 @@ describe('Feature: subDataService.ts', () => {
|
|
|
259
260
|
});
|
|
260
261
|
});
|
|
261
262
|
});
|
|
262
|
-
describe('When testing subDataService.
|
|
263
|
+
describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
|
|
264
|
+
describe('encode()', () => {
|
|
265
|
+
const examples = [
|
|
266
|
+
[
|
|
267
|
+
[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],
|
|
268
|
+
[160, 220, 180, 190, true]
|
|
269
|
+
],
|
|
270
|
+
[
|
|
271
|
+
[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],
|
|
272
|
+
[160, 200, 180, 190, false]
|
|
273
|
+
],
|
|
274
|
+
];
|
|
275
|
+
examples.forEach(([expected, actual]) => {
|
|
276
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
277
|
+
expect(subDataService.aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
});
|
|
263
281
|
describe('decode()', () => {
|
|
264
282
|
const examples = [
|
|
265
283
|
[
|
|
@@ -273,12 +291,12 @@ describe('Feature: subDataService.ts', () => {
|
|
|
273
291
|
];
|
|
274
292
|
examples.forEach(([expected, actual]) => {
|
|
275
293
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
276
|
-
expect(subDataService.
|
|
294
|
+
expect(subDataService.aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
277
295
|
});
|
|
278
296
|
});
|
|
279
297
|
});
|
|
280
298
|
});
|
|
281
|
-
describe('When testing subDataService.
|
|
299
|
+
describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
|
|
282
300
|
describe('decode()', () => {
|
|
283
301
|
const examples = [
|
|
284
302
|
[
|
|
@@ -292,7 +310,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
292
310
|
];
|
|
293
311
|
examples.forEach(([expected, actual]) => {
|
|
294
312
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
295
|
-
expect(subDataService.
|
|
313
|
+
expect(subDataService.aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
296
314
|
});
|
|
297
315
|
});
|
|
298
316
|
});
|
|
@@ -631,7 +649,24 @@ describe('Feature: subDataService.ts', () => {
|
|
|
631
649
|
});
|
|
632
650
|
});
|
|
633
651
|
});
|
|
634
|
-
describe('When testing subDataService.
|
|
652
|
+
describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
|
|
653
|
+
describe('encode()', () => {
|
|
654
|
+
const examples = [
|
|
655
|
+
[
|
|
656
|
+
[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],
|
|
657
|
+
[160, 220, 180, 190, true]
|
|
658
|
+
],
|
|
659
|
+
[
|
|
660
|
+
[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],
|
|
661
|
+
[160, 200, 180, 190, false]
|
|
662
|
+
],
|
|
663
|
+
];
|
|
664
|
+
examples.forEach(([expected, actual]) => {
|
|
665
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
666
|
+
expect(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
667
|
+
});
|
|
668
|
+
});
|
|
669
|
+
});
|
|
635
670
|
describe('decode()', () => {
|
|
636
671
|
const examples = [
|
|
637
672
|
[
|
|
@@ -645,12 +680,97 @@ describe('Feature: subDataService.ts', () => {
|
|
|
645
680
|
];
|
|
646
681
|
examples.forEach(([expected, actual]) => {
|
|
647
682
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
648
|
-
expect(subDataService.
|
|
683
|
+
expect(subDataService.compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
|
|
689
|
+
describe('encode()', () => {
|
|
690
|
+
const examples = [
|
|
691
|
+
[
|
|
692
|
+
[
|
|
693
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
694
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
695
|
+
new Dec(160).mul(1e16).toString(),
|
|
696
|
+
new Dec(220).mul(1e16).toString(),
|
|
697
|
+
new Dec(180).mul(1e16).toString(),
|
|
698
|
+
new Dec(190).mul(1e16).toString(),
|
|
699
|
+
true, false,
|
|
700
|
+
],
|
|
701
|
+
[
|
|
702
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
703
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
704
|
+
160, 220, 180, 190,
|
|
705
|
+
true, false,
|
|
706
|
+
]
|
|
707
|
+
],
|
|
708
|
+
[
|
|
709
|
+
[
|
|
710
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
711
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
712
|
+
new Dec(160).mul(1e16).toString(),
|
|
713
|
+
new Dec(210).mul(1e16).toString(),
|
|
714
|
+
new Dec(180).mul(1e16).toString(),
|
|
715
|
+
new Dec(190).mul(1e16).toString(),
|
|
716
|
+
false, true,
|
|
717
|
+
],
|
|
718
|
+
[
|
|
719
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
720
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
721
|
+
160, 210, 180, 190,
|
|
722
|
+
false, true,
|
|
723
|
+
]
|
|
724
|
+
],
|
|
725
|
+
];
|
|
726
|
+
examples.forEach(([expected, actual]) => {
|
|
727
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
728
|
+
expect(subDataService.compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
describe('decode()', () => {
|
|
733
|
+
const examples = [
|
|
734
|
+
[
|
|
735
|
+
{ targetRatio: 123 },
|
|
736
|
+
[
|
|
737
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
738
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
|
|
739
|
+
],
|
|
740
|
+
],
|
|
741
|
+
[
|
|
742
|
+
{ targetRatio: 200 },
|
|
743
|
+
[
|
|
744
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
745
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
746
|
+
],
|
|
747
|
+
],
|
|
748
|
+
];
|
|
749
|
+
examples.forEach(([expected, actual]) => {
|
|
750
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
751
|
+
expect(subDataService.compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
649
752
|
});
|
|
650
753
|
});
|
|
651
754
|
});
|
|
652
755
|
});
|
|
653
756
|
describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
|
|
757
|
+
describe('encode()', () => {
|
|
758
|
+
const examples = [
|
|
759
|
+
[
|
|
760
|
+
[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],
|
|
761
|
+
[160, 220, 180, 190, true]
|
|
762
|
+
],
|
|
763
|
+
[
|
|
764
|
+
[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],
|
|
765
|
+
[160, 200, 180, 190, false]
|
|
766
|
+
],
|
|
767
|
+
];
|
|
768
|
+
examples.forEach(([expected, actual]) => {
|
|
769
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
770
|
+
expect(subDataService.morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
});
|
|
654
774
|
describe('decode()', () => {
|
|
655
775
|
const examples = [
|
|
656
776
|
[
|
|
@@ -670,6 +790,23 @@ describe('Feature: subDataService.ts', () => {
|
|
|
670
790
|
});
|
|
671
791
|
});
|
|
672
792
|
describe('When testing subDataService.cBondsRebondSubData', () => {
|
|
793
|
+
describe('encode()', () => {
|
|
794
|
+
const examples = [
|
|
795
|
+
[
|
|
796
|
+
['0x00000000000000000000000000000000000000000000000000000000000000c8'],
|
|
797
|
+
[200]
|
|
798
|
+
],
|
|
799
|
+
[
|
|
800
|
+
['0x000000000000000000000000000000000000000000000000000000000000a119'],
|
|
801
|
+
[41241]
|
|
802
|
+
],
|
|
803
|
+
];
|
|
804
|
+
examples.forEach(([expected, actual]) => {
|
|
805
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
806
|
+
expect(subDataService.cBondsRebondSubData.encode(...actual)).to.eql(expected);
|
|
807
|
+
});
|
|
808
|
+
});
|
|
809
|
+
});
|
|
673
810
|
describe('decode()', () => {
|
|
674
811
|
const examples = [
|
|
675
812
|
[
|
|
@@ -810,7 +947,52 @@ describe('Feature: subDataService.ts', () => {
|
|
|
810
947
|
});
|
|
811
948
|
});
|
|
812
949
|
});
|
|
813
|
-
describe('When testing subDataService.
|
|
950
|
+
describe('When testing subDataService.exchangeLimitOrderSubData', () => {
|
|
951
|
+
describe('encode()', () => {
|
|
952
|
+
const examples = [
|
|
953
|
+
[
|
|
954
|
+
[
|
|
955
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
956
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
957
|
+
'2131',
|
|
958
|
+
'0.53123',
|
|
959
|
+
'1696590921159',
|
|
960
|
+
`${OrderType.STOP_LOSS}`
|
|
961
|
+
],
|
|
962
|
+
[
|
|
963
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
964
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
965
|
+
'2131',
|
|
966
|
+
'0.53123',
|
|
967
|
+
1696590921159,
|
|
968
|
+
OrderType.STOP_LOSS
|
|
969
|
+
]
|
|
970
|
+
],
|
|
971
|
+
[
|
|
972
|
+
[
|
|
973
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
974
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
975
|
+
'2131',
|
|
976
|
+
'0.43123',
|
|
977
|
+
'1646590921159',
|
|
978
|
+
`${OrderType.TAKE_PROFIT}`
|
|
979
|
+
],
|
|
980
|
+
[
|
|
981
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
982
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
983
|
+
'2131',
|
|
984
|
+
'0.43123',
|
|
985
|
+
1646590921159,
|
|
986
|
+
OrderType.TAKE_PROFIT
|
|
987
|
+
]
|
|
988
|
+
],
|
|
989
|
+
];
|
|
990
|
+
examples.forEach(([expected, actual]) => {
|
|
991
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
992
|
+
expect(subDataService.exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
|
|
993
|
+
});
|
|
994
|
+
});
|
|
995
|
+
});
|
|
814
996
|
describe('decode()', () => {
|
|
815
997
|
const examples = [
|
|
816
998
|
[
|
|
@@ -844,12 +1026,12 @@ describe('Feature: subDataService.ts', () => {
|
|
|
844
1026
|
];
|
|
845
1027
|
examples.forEach(([expected, actual]) => {
|
|
846
1028
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
847
|
-
expect(subDataService.
|
|
1029
|
+
expect(subDataService.exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
|
|
848
1030
|
});
|
|
849
1031
|
});
|
|
850
1032
|
});
|
|
851
1033
|
});
|
|
852
|
-
describe('When testing subDataService.
|
|
1034
|
+
describe('When testing subDataService.sparkLeverageManagementSubData', () => {
|
|
853
1035
|
describe('decode()', () => {
|
|
854
1036
|
const examples = [
|
|
855
1037
|
[
|
|
@@ -863,7 +1045,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
863
1045
|
];
|
|
864
1046
|
examples.forEach(([expected, actual]) => {
|
|
865
1047
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
866
|
-
expect(subDataService.
|
|
1048
|
+
expect(subDataService.sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
867
1049
|
});
|
|
868
1050
|
});
|
|
869
1051
|
});
|
|
@@ -1269,6 +1451,106 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1269
1451
|
});
|
|
1270
1452
|
});
|
|
1271
1453
|
});
|
|
1454
|
+
describe('When testing subDataService.morphoBlueLeverageManagementOnPriceSubData', () => {
|
|
1455
|
+
describe('encode()', () => {
|
|
1456
|
+
const examples = [
|
|
1457
|
+
[
|
|
1458
|
+
[
|
|
1459
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1460
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1461
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1462
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1463
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1464
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1465
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1466
|
+
],
|
|
1467
|
+
[
|
|
1468
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1469
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1470
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1471
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1472
|
+
'945000000000000000',
|
|
1473
|
+
200,
|
|
1474
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1475
|
+
],
|
|
1476
|
+
],
|
|
1477
|
+
[
|
|
1478
|
+
[
|
|
1479
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1480
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1481
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1482
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1483
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1484
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1485
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1486
|
+
],
|
|
1487
|
+
[
|
|
1488
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1489
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1490
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1491
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1492
|
+
'945000000000000000',
|
|
1493
|
+
160,
|
|
1494
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1495
|
+
],
|
|
1496
|
+
],
|
|
1497
|
+
];
|
|
1498
|
+
examples.forEach(([expected, actual]) => {
|
|
1499
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1500
|
+
expect(subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
1501
|
+
});
|
|
1502
|
+
});
|
|
1503
|
+
});
|
|
1504
|
+
describe('decode()', () => {
|
|
1505
|
+
const examples = [
|
|
1506
|
+
[
|
|
1507
|
+
{
|
|
1508
|
+
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1509
|
+
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1510
|
+
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1511
|
+
irm: '0x0000000000000000000000000000000000000000',
|
|
1512
|
+
lltv: '945000000000000000',
|
|
1513
|
+
targetRatio: 200,
|
|
1514
|
+
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1515
|
+
},
|
|
1516
|
+
[
|
|
1517
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1518
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1519
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1520
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1521
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1522
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1523
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1524
|
+
],
|
|
1525
|
+
],
|
|
1526
|
+
[
|
|
1527
|
+
{
|
|
1528
|
+
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1529
|
+
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1530
|
+
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1531
|
+
irm: '0x0000000000000000000000000000000000000000',
|
|
1532
|
+
lltv: '945000000000000000',
|
|
1533
|
+
targetRatio: 160,
|
|
1534
|
+
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1535
|
+
},
|
|
1536
|
+
[
|
|
1537
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1538
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1539
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1540
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1541
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1542
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1543
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1544
|
+
],
|
|
1545
|
+
],
|
|
1546
|
+
];
|
|
1547
|
+
examples.forEach(([expected, actual]) => {
|
|
1548
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1549
|
+
expect(subDataService.morphoBlueLeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
|
|
1550
|
+
});
|
|
1551
|
+
});
|
|
1552
|
+
});
|
|
1553
|
+
});
|
|
1272
1554
|
describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
|
|
1273
1555
|
describe('encode()', () => {
|
|
1274
1556
|
const examples = [
|
|
@@ -3,7 +3,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
|
3
3
|
import * as web3Utils from 'web3-utils';
|
|
4
4
|
import { ChainId, OrderType, RatioState } from '../types/enums';
|
|
5
5
|
import '../configuration';
|
|
6
|
-
import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, sparkQuotePriceTrigger, aaveV4RatioTrigger, aaveV4QuotePriceTrigger, aaveV4QuotePriceRangeTrigger, } from './triggerService';
|
|
6
|
+
import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, morphoBluePriceTrigger, sparkQuotePriceTrigger, aaveV4RatioTrigger, aaveV4QuotePriceTrigger, aaveV4QuotePriceRangeTrigger, } from './triggerService';
|
|
7
7
|
describe('Feature: triggerService.ts', () => {
|
|
8
8
|
describe('When testing triggerService.chainlinkPriceTrigger', () => {
|
|
9
9
|
describe('encode()', () => {
|
|
@@ -1159,6 +1159,66 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1159
1159
|
});
|
|
1160
1160
|
});
|
|
1161
1161
|
});
|
|
1162
|
+
describe('When testing triggerService.morphoBluePriceTrigger', () => {
|
|
1163
|
+
describe('encode()', () => {
|
|
1164
|
+
const examples = [
|
|
1165
|
+
[
|
|
1166
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1167
|
+
[
|
|
1168
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1169
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1170
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1171
|
+
2500,
|
|
1172
|
+
RatioState.UNDER,
|
|
1173
|
+
],
|
|
1174
|
+
],
|
|
1175
|
+
[
|
|
1176
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1177
|
+
[
|
|
1178
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1179
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1180
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1181
|
+
4000,
|
|
1182
|
+
RatioState.OVER,
|
|
1183
|
+
],
|
|
1184
|
+
],
|
|
1185
|
+
];
|
|
1186
|
+
examples.forEach(([expected, actual]) => {
|
|
1187
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1188
|
+
expect(morphoBluePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
});
|
|
1192
|
+
describe('decode()', () => {
|
|
1193
|
+
const examples = [
|
|
1194
|
+
[
|
|
1195
|
+
{
|
|
1196
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1197
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1198
|
+
loanToken: web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1199
|
+
price: '2500',
|
|
1200
|
+
priceState: RatioState.UNDER,
|
|
1201
|
+
},
|
|
1202
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1203
|
+
],
|
|
1204
|
+
[
|
|
1205
|
+
{
|
|
1206
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1207
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1208
|
+
loanToken: web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1209
|
+
price: '4000',
|
|
1210
|
+
priceState: RatioState.OVER,
|
|
1211
|
+
},
|
|
1212
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1213
|
+
],
|
|
1214
|
+
];
|
|
1215
|
+
examples.forEach(([expected, actual]) => {
|
|
1216
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1217
|
+
expect(morphoBluePriceTrigger.decode(actual)).to.eql(expected);
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1162
1222
|
describe('When testing triggerService.aaveV4RatioTrigger', () => {
|
|
1163
1223
|
describe('encode()', () => {
|
|
1164
1224
|
const examples = [
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EthereumAddress } from '../types';
|
|
2
|
-
import {
|
|
2
|
+
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState } from '../types/enums';
|
|
3
3
|
export declare function isDefined<T>(value: T): value is NonNullable<T>;
|
|
4
4
|
export declare function isUndefined(value: unknown): boolean;
|
|
5
5
|
export declare function compareAddresses(firstAddress: EthereumAddress, secondAddress: EthereumAddress): boolean;
|
|
@@ -28,4 +28,3 @@ export declare function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStr
|
|
|
28
28
|
stopLossType: CloseToAssetType | undefined;
|
|
29
29
|
takeProfitType: CloseToAssetType | undefined;
|
|
30
30
|
};
|
|
31
|
-
export declare function getBundleIdsByNetwork(network: ChainId): typeof Bundles.MainnetIds | typeof Bundles.ArbitrumIds | typeof Bundles.BaseIds;
|
package/esm/services/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import * as web3Utils from 'web3-utils';
|
|
3
3
|
import AbiCoder from 'web3-eth-abi';
|
|
4
4
|
import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
5
|
-
import {
|
|
5
|
+
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState, } from '../types/enums';
|
|
6
6
|
export function isDefined(value) {
|
|
7
7
|
return value !== undefined && value !== null;
|
|
8
8
|
}
|
|
@@ -137,15 +137,3 @@ export function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyTyp
|
|
|
137
137
|
throw new Error('CloseStrategyType not supported');
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
export function getBundleIdsByNetwork(network) {
|
|
141
|
-
switch (Number(network)) {
|
|
142
|
-
case ChainId.Ethereum:
|
|
143
|
-
return Bundles.MainnetIds;
|
|
144
|
-
case ChainId.Arbitrum:
|
|
145
|
-
return Bundles.ArbitrumIds;
|
|
146
|
-
case ChainId.Base:
|
|
147
|
-
return Bundles.BaseIds;
|
|
148
|
-
default:
|
|
149
|
-
throw new Error(`Unsupported network ${network}`);
|
|
150
|
-
}
|
|
151
|
-
}
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -138,9 +138,7 @@ export declare namespace Strategies {
|
|
|
138
138
|
EoaBoostOnPrice = "eoa-boost-on-price",
|
|
139
139
|
EoaRepayOnPrice = "eoa-repay-on-price",
|
|
140
140
|
CollateralSwitch = "collateral-switch",
|
|
141
|
-
EoaCollateralSwitch = "eoa-collateral-switch"
|
|
142
|
-
LiquidationProtection = "liquidation-protection",
|
|
143
|
-
EoaLiquidationProtection = "liquidation-protection-eoa"
|
|
141
|
+
EoaCollateralSwitch = "eoa-collateral-switch"
|
|
144
142
|
}
|
|
145
143
|
enum IdOverrides {
|
|
146
144
|
TakeProfit = "take-profit",
|
|
@@ -151,9 +149,7 @@ export declare namespace Strategies {
|
|
|
151
149
|
LeverageManagement = "leverage-management",
|
|
152
150
|
EoaLeverageManagement = "leverage-management-eoa",
|
|
153
151
|
LeverageManagementOnPrice = "leverage-management-on-price",
|
|
154
|
-
EoaLeverageManagementOnPrice = "leverage-management-on-price-eoa"
|
|
155
|
-
LiquidationProtection = "liquidation-protection",
|
|
156
|
-
EoaLiquidationProtection = "liquidation-protection-eoa"
|
|
152
|
+
EoaLeverageManagementOnPrice = "leverage-management-on-price-eoa"
|
|
157
153
|
}
|
|
158
154
|
}
|
|
159
155
|
export declare namespace Bundles {
|
|
@@ -229,17 +225,10 @@ export declare namespace Bundles {
|
|
|
229
225
|
AAVE_V4_EOA_REPAY_ON_PRICE = 68,
|
|
230
226
|
AAVE_V4_EOA_BOOST_ON_PRICE = 69,
|
|
231
227
|
AAVE_V4_EOA_CLOSE = 70,
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
AAVE_V4_SW_LIQUIDATION_PROTECTION = 77,
|
|
237
|
-
MORPHO_BLUE_SW_LIQUIDATION_PROTECTION = 78,
|
|
238
|
-
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 79,
|
|
239
|
-
AAVE_V4_EOA_LIQUIDATION_PROTECTION = 80,
|
|
240
|
-
MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 81,
|
|
241
|
-
COMP_V3_SW_LIQUIDATION_PROTECTION = 82,
|
|
242
|
-
COMP_V3_EOA_LIQUIDATION_PROTECTION = 83
|
|
228
|
+
MORPHO_BLUE_REPAY_ON_PRICE = 84,
|
|
229
|
+
MORPHO_BLUE_EOA_BOOST_ON_PRICE = 85,
|
|
230
|
+
MORPHO_BLUE_EOA_REPAY_ON_PRICE = 86,
|
|
231
|
+
MORPHO_BLUE_EOA_CLOSE = 87
|
|
243
232
|
}
|
|
244
233
|
enum OptimismIds {
|
|
245
234
|
AAVE_V3_REPAY = 0,
|
|
@@ -252,9 +241,7 @@ export declare namespace Bundles {
|
|
|
252
241
|
AAVE_V3_EOA_BOOST = 7,
|
|
253
242
|
AAVE_V3_EOA_REPAY_ON_PRICE = 8,
|
|
254
243
|
AAVE_V3_EOA_BOOST_ON_PRICE = 9,
|
|
255
|
-
AAVE_V3_EOA_CLOSE = 10
|
|
256
|
-
AAVE_V3_SW_LIQUIDATION_PROTECTION = 11,
|
|
257
|
-
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 12
|
|
244
|
+
AAVE_V3_EOA_CLOSE = 10
|
|
258
245
|
}
|
|
259
246
|
enum BaseIds {
|
|
260
247
|
AAVE_V3_REPAY = 0,
|
|
@@ -284,12 +271,12 @@ export declare namespace Bundles {
|
|
|
284
271
|
AAVE_V3_EOA_BOOST_ON_PRICE = 26,
|
|
285
272
|
AAVE_V3_EOA_CLOSE = 27,
|
|
286
273
|
MORPHO_BLUE_CLOSE = 28,
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
274
|
+
MORPHO_BLUE_REPAY_ON_PRICE = 36,
|
|
275
|
+
MORPHO_BLUE_EOA_REPAY = 37,
|
|
276
|
+
MORPHO_BLUE_EOA_BOOST = 38,
|
|
277
|
+
MORPHO_BLUE_EOA_BOOST_ON_PRICE = 39,
|
|
278
|
+
MORPHO_BLUE_EOA_REPAY_ON_PRICE = 40,
|
|
279
|
+
MORPHO_BLUE_EOA_CLOSE = 41
|
|
293
280
|
}
|
|
294
281
|
enum ArbitrumIds {
|
|
295
282
|
AAVE_V3_REPAY = 0,
|
|
@@ -321,12 +308,9 @@ export declare namespace Bundles {
|
|
|
321
308
|
MORPHO_BLUE_EOA_REPAY = 26,
|
|
322
309
|
MORPHO_BLUE_EOA_BOOST = 27,
|
|
323
310
|
MORPHO_BLUE_CLOSE = 28,
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
COMP_V3_EOA_LIQUIDATION_PROTECTION = 33,
|
|
329
|
-
AAVE_V3_EOA_LIQUIDATION_PROTECTION = 34,
|
|
330
|
-
MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 35
|
|
311
|
+
MORPHO_BLUE_REPAY_ON_PRICE = 36,
|
|
312
|
+
MORPHO_BLUE_EOA_BOOST_ON_PRICE = 37,
|
|
313
|
+
MORPHO_BLUE_EOA_REPAY_ON_PRICE = 38,
|
|
314
|
+
MORPHO_BLUE_EOA_CLOSE = 39
|
|
331
315
|
}
|
|
332
316
|
}
|