@defisaver/automation-sdk 3.3.15-liq-prot-1-dev → 3.3.15-liq-prot-3-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/index.d.ts +1 -2
- package/cjs/index.js +0 -1
- package/cjs/services/strategiesService.js +10 -10
- package/cjs/services/strategySubService.d.ts +9 -15
- package/cjs/services/strategySubService.js +20 -30
- package/cjs/services/strategySubService.test.js +2 -40
- package/cjs/services/subDataService.d.ts +18 -23
- package/cjs/services/subDataService.js +23 -225
- package/cjs/services/subDataService.test.js +17 -134
- package/cjs/services/utils.d.ts +0 -1
- package/cjs/services/utils.js +1 -21
- package/cjs/services/utils.test.js +0 -25
- package/cjs/types/enums.d.ts +1 -1
- package/cjs/types/enums.js +1 -1
- package/esm/index.d.ts +1 -2
- package/esm/index.js +1 -2
- package/esm/services/strategiesService.js +10 -10
- package/esm/services/strategySubService.d.ts +9 -15
- package/esm/services/strategySubService.js +19 -29
- package/esm/services/strategySubService.test.js +3 -38
- package/esm/services/subDataService.d.ts +18 -23
- package/esm/services/subDataService.js +22 -224
- package/esm/services/subDataService.test.js +18 -132
- package/esm/services/utils.d.ts +0 -1
- package/esm/services/utils.js +0 -19
- package/esm/services/utils.test.js +2 -27
- package/esm/types/enums.d.ts +1 -1
- package/esm/types/enums.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/services/strategiesService.ts +10 -10
- package/src/services/strategySubService.test.ts +2 -46
- package/src/services/strategySubService.ts +19 -36
- package/src/services/subDataService.test.ts +18 -142
- package/src/services/subDataService.ts +23 -294
- package/src/services/utils.test.ts +0 -31
- package/src/services/utils.ts +0 -17
- package/src/types/enums.ts +1 -1
|
@@ -1,9 +1,8 @@
|
|
|
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
|
-
import { ChainId, CloseStrategyType,
|
|
5
|
+
import { ChainId, CloseStrategyType, RatioState } from '../types/enums';
|
|
7
6
|
import '../configuration';
|
|
8
7
|
import * as subDataService from './subDataService';
|
|
9
8
|
describe('Feature: subDataService.ts', () => {
|
|
@@ -118,7 +117,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
118
117
|
});
|
|
119
118
|
});
|
|
120
119
|
});
|
|
121
|
-
describe('When testing subDataService.
|
|
120
|
+
describe('When testing subDataService.legacyMakerLeverageManagementSubData', () => {
|
|
122
121
|
describe('decode()', () => {
|
|
123
122
|
const examples = [
|
|
124
123
|
[
|
|
@@ -131,12 +130,12 @@ describe('Feature: subDataService.ts', () => {
|
|
|
131
130
|
];
|
|
132
131
|
examples.forEach(([expected, actual]) => {
|
|
133
132
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
134
|
-
expect(subDataService.
|
|
133
|
+
expect(subDataService.legacyMakerLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
135
134
|
});
|
|
136
135
|
});
|
|
137
136
|
});
|
|
138
137
|
});
|
|
139
|
-
describe('When testing subDataService.
|
|
138
|
+
describe('When testing subDataService.makerLeverageManagementSubData', () => {
|
|
140
139
|
describe('encode()', () => {
|
|
141
140
|
const examples = [
|
|
142
141
|
[
|
|
@@ -156,7 +155,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
156
155
|
];
|
|
157
156
|
examples.forEach(([expected, actual]) => {
|
|
158
157
|
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
159
|
-
expect(subDataService.
|
|
158
|
+
expect(subDataService.makerLeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
160
159
|
});
|
|
161
160
|
});
|
|
162
161
|
});
|
|
@@ -187,12 +186,12 @@ describe('Feature: subDataService.ts', () => {
|
|
|
187
186
|
];
|
|
188
187
|
examples.forEach(([expected, actual]) => {
|
|
189
188
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
190
|
-
expect(subDataService.
|
|
189
|
+
expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
191
190
|
});
|
|
192
191
|
});
|
|
193
192
|
});
|
|
194
193
|
});
|
|
195
|
-
describe('When testing subDataService.
|
|
194
|
+
describe('When testing subDataService.legacyLiquityLeverageManagementSubData', () => {
|
|
196
195
|
describe('decode()', () => {
|
|
197
196
|
const examples = [
|
|
198
197
|
[
|
|
@@ -205,7 +204,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
205
204
|
];
|
|
206
205
|
examples.forEach(([expected, actual]) => {
|
|
207
206
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
208
|
-
expect(subDataService.
|
|
207
|
+
expect(subDataService.legacyLiquityLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
209
208
|
});
|
|
210
209
|
});
|
|
211
210
|
});
|
|
@@ -260,24 +259,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
260
259
|
});
|
|
261
260
|
});
|
|
262
261
|
});
|
|
263
|
-
describe('When testing subDataService.
|
|
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
|
-
});
|
|
262
|
+
describe('When testing subDataService.legacyAaveV2LeverageManagementSubData', () => {
|
|
281
263
|
describe('decode()', () => {
|
|
282
264
|
const examples = [
|
|
283
265
|
[
|
|
@@ -291,12 +273,12 @@ describe('Feature: subDataService.ts', () => {
|
|
|
291
273
|
];
|
|
292
274
|
examples.forEach(([expected, actual]) => {
|
|
293
275
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
294
|
-
expect(subDataService.
|
|
276
|
+
expect(subDataService.legacyAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
295
277
|
});
|
|
296
278
|
});
|
|
297
279
|
});
|
|
298
280
|
});
|
|
299
|
-
describe('When testing subDataService.
|
|
281
|
+
describe('When testing subDataService.legacyAaveV3LeverageManagementSubData', () => {
|
|
300
282
|
describe('decode()', () => {
|
|
301
283
|
const examples = [
|
|
302
284
|
[
|
|
@@ -310,7 +292,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
310
292
|
];
|
|
311
293
|
examples.forEach(([expected, actual]) => {
|
|
312
294
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
313
|
-
expect(subDataService.
|
|
295
|
+
expect(subDataService.legacyAaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
314
296
|
});
|
|
315
297
|
});
|
|
316
298
|
});
|
|
@@ -649,24 +631,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
649
631
|
});
|
|
650
632
|
});
|
|
651
633
|
});
|
|
652
|
-
describe('When testing subDataService.
|
|
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
|
-
});
|
|
634
|
+
describe('When testing subDataService.legacyCompoundV2LeverageManagementSubData', () => {
|
|
670
635
|
describe('decode()', () => {
|
|
671
636
|
const examples = [
|
|
672
637
|
[
|
|
@@ -680,29 +645,12 @@ describe('Feature: subDataService.ts', () => {
|
|
|
680
645
|
];
|
|
681
646
|
examples.forEach(([expected, actual]) => {
|
|
682
647
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
683
|
-
expect(subDataService.
|
|
648
|
+
expect(subDataService.legacyCompoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
684
649
|
});
|
|
685
650
|
});
|
|
686
651
|
});
|
|
687
652
|
});
|
|
688
653
|
describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
|
|
689
|
-
describe('encode()', () => {
|
|
690
|
-
const examples = [
|
|
691
|
-
[
|
|
692
|
-
[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],
|
|
693
|
-
[160, 220, 180, 190, true]
|
|
694
|
-
],
|
|
695
|
-
[
|
|
696
|
-
[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],
|
|
697
|
-
[160, 200, 180, 190, false]
|
|
698
|
-
],
|
|
699
|
-
];
|
|
700
|
-
examples.forEach(([expected, actual]) => {
|
|
701
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
702
|
-
expect(subDataService.morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
703
|
-
});
|
|
704
|
-
});
|
|
705
|
-
});
|
|
706
654
|
describe('decode()', () => {
|
|
707
655
|
const examples = [
|
|
708
656
|
[
|
|
@@ -722,23 +670,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
722
670
|
});
|
|
723
671
|
});
|
|
724
672
|
describe('When testing subDataService.cBondsRebondSubData', () => {
|
|
725
|
-
describe('encode()', () => {
|
|
726
|
-
const examples = [
|
|
727
|
-
[
|
|
728
|
-
['0x00000000000000000000000000000000000000000000000000000000000000c8'],
|
|
729
|
-
[200]
|
|
730
|
-
],
|
|
731
|
-
[
|
|
732
|
-
['0x000000000000000000000000000000000000000000000000000000000000a119'],
|
|
733
|
-
[41241]
|
|
734
|
-
],
|
|
735
|
-
];
|
|
736
|
-
examples.forEach(([expected, actual]) => {
|
|
737
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
738
|
-
expect(subDataService.cBondsRebondSubData.encode(...actual)).to.eql(expected);
|
|
739
|
-
});
|
|
740
|
-
});
|
|
741
|
-
});
|
|
742
673
|
describe('decode()', () => {
|
|
743
674
|
const examples = [
|
|
744
675
|
[
|
|
@@ -879,52 +810,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
879
810
|
});
|
|
880
811
|
});
|
|
881
812
|
});
|
|
882
|
-
describe('When testing subDataService.
|
|
883
|
-
describe('encode()', () => {
|
|
884
|
-
const examples = [
|
|
885
|
-
[
|
|
886
|
-
[
|
|
887
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
888
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
889
|
-
'2131',
|
|
890
|
-
'0.53123',
|
|
891
|
-
'1696590921159',
|
|
892
|
-
`${OrderType.STOP_LOSS}`
|
|
893
|
-
],
|
|
894
|
-
[
|
|
895
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
896
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
897
|
-
'2131',
|
|
898
|
-
'0.53123',
|
|
899
|
-
1696590921159,
|
|
900
|
-
OrderType.STOP_LOSS
|
|
901
|
-
]
|
|
902
|
-
],
|
|
903
|
-
[
|
|
904
|
-
[
|
|
905
|
-
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
906
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
907
|
-
'2131',
|
|
908
|
-
'0.43123',
|
|
909
|
-
'1646590921159',
|
|
910
|
-
`${OrderType.TAKE_PROFIT}`
|
|
911
|
-
],
|
|
912
|
-
[
|
|
913
|
-
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
914
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
915
|
-
'2131',
|
|
916
|
-
'0.43123',
|
|
917
|
-
1646590921159,
|
|
918
|
-
OrderType.TAKE_PROFIT
|
|
919
|
-
]
|
|
920
|
-
],
|
|
921
|
-
];
|
|
922
|
-
examples.forEach(([expected, actual]) => {
|
|
923
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
924
|
-
expect(subDataService.exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
|
|
925
|
-
});
|
|
926
|
-
});
|
|
927
|
-
});
|
|
813
|
+
describe('When testing subDataService.legacyExchangeLimitOrderSubData', () => {
|
|
928
814
|
describe('decode()', () => {
|
|
929
815
|
const examples = [
|
|
930
816
|
[
|
|
@@ -958,12 +844,12 @@ describe('Feature: subDataService.ts', () => {
|
|
|
958
844
|
];
|
|
959
845
|
examples.forEach(([expected, actual]) => {
|
|
960
846
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
961
|
-
expect(subDataService.
|
|
847
|
+
expect(subDataService.legacyExchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
|
|
962
848
|
});
|
|
963
849
|
});
|
|
964
850
|
});
|
|
965
851
|
});
|
|
966
|
-
describe('When testing subDataService.
|
|
852
|
+
describe('When testing subDataService.legacySparkLeverageManagementSubData', () => {
|
|
967
853
|
describe('decode()', () => {
|
|
968
854
|
const examples = [
|
|
969
855
|
[
|
|
@@ -977,7 +863,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
977
863
|
];
|
|
978
864
|
examples.forEach(([expected, actual]) => {
|
|
979
865
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
980
|
-
expect(subDataService.
|
|
866
|
+
expect(subDataService.legacySparkLeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
981
867
|
});
|
|
982
868
|
});
|
|
983
869
|
});
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -29,4 +29,3 @@ export declare function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStr
|
|
|
29
29
|
takeProfitType: CloseToAssetType | undefined;
|
|
30
30
|
};
|
|
31
31
|
export declare function getBundleIdsByNetwork(network: ChainId): typeof Bundles.MainnetIds | typeof Bundles.ArbitrumIds | typeof Bundles.BaseIds;
|
|
32
|
-
export declare function getCompoundV3LeverageManagementBundleId(network: ChainId, isEOA: boolean, isBoost: boolean): number;
|
package/esm/services/utils.js
CHANGED
|
@@ -149,22 +149,3 @@ export function getBundleIdsByNetwork(network) {
|
|
|
149
149
|
throw new Error(`Unsupported network ${network}`);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
-
// Mainnet uses the V2 bundle ids; L2s use the original bundle ids.
|
|
153
|
-
export function getCompoundV3LeverageManagementBundleId(network, isEOA, isBoost) {
|
|
154
|
-
switch (Number(network)) {
|
|
155
|
-
case ChainId.Ethereum:
|
|
156
|
-
if (isEOA)
|
|
157
|
-
return isBoost ? Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE;
|
|
158
|
-
return isBoost ? Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE;
|
|
159
|
-
case ChainId.Base:
|
|
160
|
-
if (isEOA)
|
|
161
|
-
return isBoost ? Bundles.BaseIds.COMP_V3_EOA_BOOST : Bundles.BaseIds.COMP_V3_EOA_REPAY;
|
|
162
|
-
return isBoost ? Bundles.BaseIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.BaseIds.COMP_V3_SW_REPAY_BUNDLE;
|
|
163
|
-
case ChainId.Arbitrum:
|
|
164
|
-
if (isEOA)
|
|
165
|
-
return isBoost ? Bundles.ArbitrumIds.COMP_V3_EOA_BOOST : Bundles.ArbitrumIds.COMP_V3_EOA_REPAY;
|
|
166
|
-
return isBoost ? Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE;
|
|
167
|
-
default:
|
|
168
|
-
throw new Error(`Compound V3 leverage management is not supported on network ${network}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
|
-
import {
|
|
3
|
+
import { ChainId, ProtocolIdentifiers, RatioState } from '../types/enums';
|
|
4
4
|
import '../configuration';
|
|
5
|
-
import { addToArrayIf, addToObjectIf, compareAddresses, encodeSubId, ethToWeth,
|
|
5
|
+
import { addToArrayIf, addToObjectIf, compareAddresses, encodeSubId, ethToWeth, getRatioStateInfoForAaveCloseStrategy, isAddress, isDefined, isEmptyBytes, isRatioStateOver, isRatioStateUnder, isUndefined, ratioPercentageToWei, requireAddress, requireAddresses, weiToRatioPercentage, wethToEth, wethToEthByAddress, getPositionId, } from './utils';
|
|
6
6
|
describe('Feature: utils.ts', () => {
|
|
7
7
|
describe('When testing utils.isDefined()', () => {
|
|
8
8
|
const examples = [
|
|
@@ -294,29 +294,4 @@ describe('Feature: utils.ts', () => {
|
|
|
294
294
|
});
|
|
295
295
|
});
|
|
296
296
|
});
|
|
297
|
-
describe('When testing utils.getCompoundV3LeverageManagementBundleId()', () => {
|
|
298
|
-
// Mainnet uses the V2 bundle ids; L2s use the original bundle ids.
|
|
299
|
-
const examples = [
|
|
300
|
-
[Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE, [ChainId.Ethereum, false, false]],
|
|
301
|
-
[Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE, [ChainId.Ethereum, false, true]],
|
|
302
|
-
[Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE, [ChainId.Ethereum, true, false]],
|
|
303
|
-
[Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE, [ChainId.Ethereum, true, true]],
|
|
304
|
-
[Bundles.BaseIds.COMP_V3_SW_REPAY_BUNDLE, [ChainId.Base, false, false]],
|
|
305
|
-
[Bundles.BaseIds.COMP_V3_SW_BOOST_BUNDLE, [ChainId.Base, false, true]],
|
|
306
|
-
[Bundles.BaseIds.COMP_V3_EOA_REPAY, [ChainId.Base, true, false]],
|
|
307
|
-
[Bundles.BaseIds.COMP_V3_EOA_BOOST, [ChainId.Base, true, true]],
|
|
308
|
-
[Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE, [ChainId.Arbitrum, false, false]],
|
|
309
|
-
[Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE, [ChainId.Arbitrum, false, true]],
|
|
310
|
-
[Bundles.ArbitrumIds.COMP_V3_EOA_REPAY, [ChainId.Arbitrum, true, false]],
|
|
311
|
-
[Bundles.ArbitrumIds.COMP_V3_EOA_BOOST, [ChainId.Arbitrum, true, true]],
|
|
312
|
-
];
|
|
313
|
-
examples.forEach(([expected, actual]) => {
|
|
314
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
315
|
-
expect(getCompoundV3LeverageManagementBundleId(...actual)).to.equal(expected);
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
it(`Given ${ChainId.Optimism} (unsupported) should throw an error`, () => {
|
|
319
|
-
expect(() => getCompoundV3LeverageManagementBundleId(ChainId.Optimism, false, false)).to.throw(Error);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
297
|
});
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -140,7 +140,7 @@ export declare namespace Strategies {
|
|
|
140
140
|
CollateralSwitch = "collateral-switch",
|
|
141
141
|
EoaCollateralSwitch = "eoa-collateral-switch",
|
|
142
142
|
LiquidationProtection = "liquidation-protection",
|
|
143
|
-
EoaLiquidationProtection = "
|
|
143
|
+
EoaLiquidationProtection = "liquidation-protection-eoa"
|
|
144
144
|
}
|
|
145
145
|
enum IdOverrides {
|
|
146
146
|
TakeProfit = "take-profit",
|
package/esm/types/enums.js
CHANGED
|
@@ -157,7 +157,7 @@ export var Strategies;
|
|
|
157
157
|
Identifiers["CollateralSwitch"] = "collateral-switch";
|
|
158
158
|
Identifiers["EoaCollateralSwitch"] = "eoa-collateral-switch";
|
|
159
159
|
Identifiers["LiquidationProtection"] = "liquidation-protection";
|
|
160
|
-
Identifiers["EoaLiquidationProtection"] = "
|
|
160
|
+
Identifiers["EoaLiquidationProtection"] = "liquidation-protection-eoa";
|
|
161
161
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
162
162
|
let IdOverrides;
|
|
163
163
|
(function (IdOverrides) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -28,14 +28,12 @@ import {
|
|
|
28
28
|
compareSubHashes,
|
|
29
29
|
encodeSubId,
|
|
30
30
|
getCloseStrategyType,
|
|
31
|
-
getCompoundV3LeverageManagementBundleId,
|
|
32
31
|
} from './services/utils';
|
|
33
32
|
|
|
34
33
|
const utils = {
|
|
35
34
|
compareSubHashes,
|
|
36
35
|
encodeSubId,
|
|
37
36
|
getCloseStrategyType,
|
|
38
|
-
getCompoundV3LeverageManagementBundleId,
|
|
39
37
|
getRatioStateInfoForAaveCloseStrategy,
|
|
40
38
|
};
|
|
41
39
|
|
|
@@ -106,7 +106,7 @@ function parseMakerLeverageManagement(position: Position.Automated, parseData: P
|
|
|
106
106
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
107
107
|
|
|
108
108
|
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
109
|
-
const subData = subDataService.
|
|
109
|
+
const subData = subDataService.legacyMakerLeverageManagementSubData.decode(subStruct.subData);
|
|
110
110
|
|
|
111
111
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
112
112
|
_position.strategyData.decoded.subData = subData;
|
|
@@ -223,7 +223,7 @@ function parseAaveV2LeverageManagement(position: Position.Automated, parseData:
|
|
|
223
223
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
224
224
|
|
|
225
225
|
const triggerData = triggerService.aaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
226
|
-
const subData = subDataService.
|
|
226
|
+
const subData = subDataService.legacyAaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
227
227
|
|
|
228
228
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
229
229
|
_position.strategyData.decoded.subData = subData;
|
|
@@ -267,9 +267,9 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
267
267
|
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
268
268
|
let subData;
|
|
269
269
|
if (isEOA) {
|
|
270
|
-
subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.decode(subStruct.subData);
|
|
271
|
-
} else {
|
|
272
270
|
subData = subDataService.aaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
271
|
+
} else {
|
|
272
|
+
subData = subDataService.legacyAaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
@@ -670,7 +670,7 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
670
670
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
671
671
|
|
|
672
672
|
const triggerData = triggerService.compoundV2RatioTrigger.decode(subStruct.triggerData);
|
|
673
|
-
const subData = subDataService.
|
|
673
|
+
const subData = subDataService.legacyCompoundV2LeverageManagementSubData.decode(subStruct.subData);
|
|
674
674
|
|
|
675
675
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
676
676
|
_position.strategyData.decoded.subData = subData;
|
|
@@ -712,7 +712,7 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
712
712
|
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
713
713
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
714
714
|
|
|
715
|
-
const subDataDecoder = subDataService.
|
|
715
|
+
const subDataDecoder = subDataService.compoundV3LeverageManagementSubData;
|
|
716
716
|
|
|
717
717
|
const triggerData = triggerService.compoundV3RatioTrigger.decode(subStruct.triggerData);
|
|
718
718
|
const subData = subDataDecoder.decode(subStruct.subData);
|
|
@@ -758,7 +758,7 @@ function parseCompoundV3LiquidationProtection(position: Position.Automated, pars
|
|
|
758
758
|
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
759
759
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
760
760
|
|
|
761
|
-
const subDataDecoder = subDataService.
|
|
761
|
+
const subDataDecoder = subDataService.compoundV3LiquidationProtectionSubData;
|
|
762
762
|
|
|
763
763
|
const triggerData = triggerService.compoundV3RatioTrigger.decode(subStruct.triggerData);
|
|
764
764
|
const subData = subDataDecoder.decode(subStruct.subData);
|
|
@@ -888,7 +888,7 @@ function parseExchangeLimitOrder(position: Position.Automated, parseData: ParseD
|
|
|
888
888
|
|
|
889
889
|
const { subStruct } = parseData.subscriptionEventData;
|
|
890
890
|
|
|
891
|
-
_position.strategyData.decoded.subData = subDataService.
|
|
891
|
+
_position.strategyData.decoded.subData = subDataService.legacyExchangeLimitOrderSubData.decode(subStruct.subData, chainId);
|
|
892
892
|
const fromTokenDecimals = getAssetInfoByAddress(_position.strategyData.decoded.subData.fromToken, chainId).decimals;
|
|
893
893
|
const toTokenDecimals = getAssetInfoByAddress(_position.strategyData.decoded.subData.toToken, chainId).decimals;
|
|
894
894
|
_position.strategyData.decoded.triggerData = triggerService.exchangeOffchainPriceTrigger.decode(subStruct.triggerData, fromTokenDecimals, toTokenDecimals);
|
|
@@ -905,7 +905,7 @@ function parseLiquityLeverageManagement(position: Position.Automated, parseData:
|
|
|
905
905
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
906
906
|
|
|
907
907
|
const triggerData = triggerService.liquityRatioTrigger.decode(subStruct.triggerData);
|
|
908
|
-
const subData = subDataService.
|
|
908
|
+
const subData = subDataService.legacyLiquityLeverageManagementSubData.decode(subStruct.subData);
|
|
909
909
|
|
|
910
910
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
911
911
|
_position.strategyData.decoded.subData = subData;
|
|
@@ -989,7 +989,7 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
989
989
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
990
990
|
|
|
991
991
|
const triggerData = triggerService.sparkRatioTrigger.decode(subStruct.triggerData);
|
|
992
|
-
const subData = subDataService.
|
|
992
|
+
const subData = subDataService.legacySparkLeverageManagementSubData.decode(subStruct.subData);
|
|
993
993
|
|
|
994
994
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
995
995
|
_position.strategyData.decoded.subData = subData;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import Dec from 'decimal.js';
|
|
3
2
|
import { otherAddresses } from '@defisaver/sdk';
|
|
4
3
|
import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
5
4
|
import * as web3Utils from 'web3-utils';
|
|
@@ -9,12 +8,10 @@ import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from
|
|
|
9
8
|
|
|
10
9
|
import '../configuration';
|
|
11
10
|
import {
|
|
12
|
-
chickenBondsEncode,
|
|
13
11
|
liquityEncode,
|
|
14
12
|
makerEncode,
|
|
15
13
|
aaveV3Encode,
|
|
16
14
|
compoundV3Encode,
|
|
17
|
-
morphoAaveV2Encode,
|
|
18
15
|
exchangeEncode,
|
|
19
16
|
crvUSDEncode,
|
|
20
17
|
morphoBlueEncode,
|
|
@@ -137,7 +134,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
137
134
|
});
|
|
138
135
|
});
|
|
139
136
|
|
|
140
|
-
describe('
|
|
137
|
+
describe('leverageManagement()', () => {
|
|
141
138
|
const examples: Array<[
|
|
142
139
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
143
140
|
[
|
|
@@ -187,7 +184,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
187
184
|
|
|
188
185
|
examples.forEach(([expected, actual]) => {
|
|
189
186
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
190
|
-
expect(makerEncode.
|
|
187
|
+
expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
|
|
191
188
|
});
|
|
192
189
|
});
|
|
193
190
|
});
|
|
@@ -348,26 +345,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
348
345
|
});
|
|
349
346
|
});
|
|
350
347
|
|
|
351
|
-
describe('When testing strategySubService.chickenBondsEncode', () => {
|
|
352
|
-
describe('rebond()', () => {
|
|
353
|
-
const examples: Array<[
|
|
354
|
-
SubData,
|
|
355
|
-
[bondId: number],
|
|
356
|
-
]> = [
|
|
357
|
-
[
|
|
358
|
-
['0x00000000000000000000000000000000000000000000000000000000000005e3'],
|
|
359
|
-
[1507]
|
|
360
|
-
]
|
|
361
|
-
];
|
|
362
|
-
|
|
363
|
-
examples.forEach(([expected, actual]) => {
|
|
364
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
365
|
-
expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
348
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
372
349
|
describe('closeToAsset()', () => {
|
|
373
350
|
const examples: Array<[
|
|
@@ -1156,27 +1133,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1156
1133
|
});
|
|
1157
1134
|
});
|
|
1158
1135
|
|
|
1159
|
-
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
1160
|
-
describe('leverageManagement()', () => {
|
|
1161
|
-
const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
|
|
1162
|
-
[
|
|
1163
|
-
[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],
|
|
1164
|
-
[160, 220, 180, 190, true]
|
|
1165
|
-
],
|
|
1166
|
-
[
|
|
1167
|
-
[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],
|
|
1168
|
-
[160, 200, 180, 190, false]
|
|
1169
|
-
],
|
|
1170
|
-
];
|
|
1171
|
-
|
|
1172
|
-
examples.forEach(([expected, actual]) => {
|
|
1173
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1174
|
-
expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1175
|
-
});
|
|
1176
|
-
});
|
|
1177
|
-
});
|
|
1178
|
-
});
|
|
1179
|
-
|
|
1180
1136
|
describe('When testing strategySubService.exchangeEncode', () => {
|
|
1181
1137
|
describe('dca()', () => {
|
|
1182
1138
|
const examples: Array<[
|