@defisaver/automation-sdk 3.1.10 → 3.1.14-spark-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/automation/private/StrategiesAutomation.d.ts +5 -3
- package/cjs/automation/private/StrategiesAutomation.js +27 -10
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +352 -11
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +1 -1
- package/cjs/services/ethereumService.js +21 -14
- package/cjs/services/ethereumService.test.js +3 -0
- package/cjs/services/strategiesService.js +329 -54
- package/cjs/services/strategiesService.test.js +1 -0
- package/cjs/services/strategySubService.d.ts +24 -5
- package/cjs/services/strategySubService.js +116 -10
- package/cjs/services/strategySubService.test.js +1049 -173
- package/cjs/services/subDataService.d.ts +361 -88
- package/cjs/services/subDataService.js +799 -249
- package/cjs/services/subDataService.test.js +1287 -142
- package/cjs/services/triggerService.d.ts +100 -9
- package/cjs/services/triggerService.js +188 -19
- package/cjs/services/triggerService.test.js +437 -46
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/services/utils.test.js +0 -77
- package/cjs/types/enums.d.ts +88 -12
- package/cjs/types/enums.js +78 -2
- package/cjs/types/index.d.ts +59 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -3
- package/esm/automation/private/StrategiesAutomation.js +27 -10
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +351 -10
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/services/ethereumService.js +21 -14
- package/esm/services/ethereumService.test.js +3 -0
- package/esm/services/strategiesService.js +330 -55
- package/esm/services/strategiesService.test.js +1 -0
- package/esm/services/strategySubService.d.ts +24 -5
- package/esm/services/strategySubService.js +115 -9
- package/esm/services/strategySubService.test.js +1052 -176
- package/esm/services/subDataService.d.ts +361 -88
- package/esm/services/subDataService.js +799 -249
- package/esm/services/subDataService.test.js +1288 -143
- package/esm/services/triggerService.d.ts +100 -9
- package/esm/services/triggerService.js +187 -18
- package/esm/services/triggerService.test.js +438 -47
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/services/utils.test.js +1 -52
- package/esm/types/enums.d.ts +88 -12
- package/esm/types/enums.js +78 -2
- package/esm/types/index.d.ts +59 -1
- package/package.json +4 -5
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +38 -15
- package/src/constants/index.ts +353 -11
- package/src/index.ts +4 -2
- package/src/services/ethereumService.test.ts +3 -0
- package/src/services/ethereumService.ts +23 -16
- package/src/services/strategiesService.test.ts +1 -0
- package/src/services/strategiesService.ts +387 -72
- package/src/services/strategySubService.test.ts +1330 -316
- package/src/services/strategySubService.ts +365 -12
- package/src/services/subDataService.test.ts +1413 -170
- package/src/services/subDataService.ts +1148 -431
- package/src/services/triggerService.test.ts +482 -52
- package/src/services/triggerService.ts +272 -27
- package/src/services/utils.test.ts +0 -59
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +78 -2
- package/src/types/index.ts +74 -1
- package/umd/index.js +0 -34219
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import Dec from 'decimal.js';
|
|
3
3
|
import { otherAddresses } from '@defisaver/sdk';
|
|
4
|
-
import { getAssetInfo } from '@defisaver/tokens';
|
|
4
|
+
import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
5
5
|
import * as web3Utils from 'web3-utils';
|
|
6
6
|
|
|
7
|
-
import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
|
|
7
|
+
import { Bundles, ChainId, CloseToAssetType, OrderType, RatioState, Strategies } from '../types/enums';
|
|
8
8
|
import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from '../types';
|
|
9
9
|
|
|
10
10
|
import '../configuration';
|
|
@@ -18,8 +18,11 @@ import {
|
|
|
18
18
|
compoundV3Encode,
|
|
19
19
|
morphoAaveV2Encode,
|
|
20
20
|
exchangeEncode,
|
|
21
|
+
crvUSDEncode,
|
|
22
|
+
compoundV3L2Encode,
|
|
23
|
+
morphoBlueEncode,
|
|
21
24
|
sparkEncode,
|
|
22
|
-
|
|
25
|
+
aaveV4Encode,
|
|
23
26
|
} from './strategySubService';
|
|
24
27
|
|
|
25
28
|
describe('Feature: strategySubService.ts', () => {
|
|
@@ -169,6 +172,61 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
169
172
|
});
|
|
170
173
|
});
|
|
171
174
|
});
|
|
175
|
+
|
|
176
|
+
describe('leverageManagementWithoutSubProxy()', () => {
|
|
177
|
+
const examples: Array<[
|
|
178
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
179
|
+
[
|
|
180
|
+
vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState,
|
|
181
|
+
isBoost: boolean, daiAddr?: EthereumAddress,
|
|
182
|
+
]
|
|
183
|
+
]> = [
|
|
184
|
+
// Repay scenario (isBoost=false, RatioState.UNDER)
|
|
185
|
+
[
|
|
186
|
+
[
|
|
187
|
+
Bundles.MainnetIds.MAKER_REPAY,
|
|
188
|
+
true,
|
|
189
|
+
['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
|
|
190
|
+
[
|
|
191
|
+
'0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
|
|
192
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
193
|
+
],
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
222, // vaultId
|
|
197
|
+
140, // triggerRatio
|
|
198
|
+
180, // targetRatio
|
|
199
|
+
RatioState.UNDER, // ratioState
|
|
200
|
+
false, // isBoost
|
|
201
|
+
]
|
|
202
|
+
],
|
|
203
|
+
// Boost scenario (isBoost=true, RatioState.OVER)
|
|
204
|
+
[
|
|
205
|
+
[
|
|
206
|
+
Bundles.MainnetIds.MAKER_BOOST,
|
|
207
|
+
true,
|
|
208
|
+
['0x000000000000000000000000000000000000000000000000000000000000014d00000000000000000000000000000000000000000000000026db992a3b1800000000000000000000000000000000000000000000000000000000000000000000'],
|
|
209
|
+
[
|
|
210
|
+
'0x000000000000000000000000000000000000000000000000000000000000014d', '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
211
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
212
|
+
],
|
|
213
|
+
],
|
|
214
|
+
[
|
|
215
|
+
333, // vaultId
|
|
216
|
+
280, // triggerRatio
|
|
217
|
+
250, // targetRatio
|
|
218
|
+
RatioState.OVER, // ratioState
|
|
219
|
+
true, // isBoost
|
|
220
|
+
]
|
|
221
|
+
],
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
examples.forEach(([expected, actual]) => {
|
|
225
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
226
|
+
expect(makerEncode.leverageManagementWithoutSubProxy(...actual)).to.eql(expected);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
172
230
|
});
|
|
173
231
|
|
|
174
232
|
describe('When testing strategySubService.liquityEncode', () => {
|
|
@@ -618,264 +676,1155 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
618
676
|
});
|
|
619
677
|
});
|
|
620
678
|
});
|
|
621
|
-
});
|
|
622
679
|
|
|
623
|
-
|
|
624
|
-
describe('leverageManagement()', () => {
|
|
680
|
+
describe('leverageManagementOnPriceGeneric()', () => {
|
|
625
681
|
const examples: Array<[
|
|
626
|
-
[
|
|
627
|
-
[
|
|
682
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
683
|
+
[
|
|
684
|
+
strategyOrBundleId: number,
|
|
685
|
+
price: number,
|
|
686
|
+
ratioState: RatioState,
|
|
687
|
+
collAsset: EthereumAddress,
|
|
688
|
+
collAssetId: number,
|
|
689
|
+
debtAsset: EthereumAddress,
|
|
690
|
+
debtAssetId: number,
|
|
691
|
+
marketAddr: EthereumAddress,
|
|
692
|
+
targetRatio: number,
|
|
693
|
+
user: EthereumAddress
|
|
694
|
+
]
|
|
628
695
|
]> = [
|
|
629
696
|
[
|
|
630
|
-
[
|
|
631
|
-
|
|
697
|
+
[
|
|
698
|
+
Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
|
|
699
|
+
true,
|
|
700
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
|
|
701
|
+
[
|
|
702
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
703
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
704
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
705
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
706
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
707
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
708
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
709
|
+
],
|
|
710
|
+
],
|
|
711
|
+
[
|
|
712
|
+
Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
|
|
713
|
+
1670,
|
|
714
|
+
RatioState.UNDER,
|
|
715
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
716
|
+
0,
|
|
717
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
718
|
+
1,
|
|
719
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
720
|
+
200,
|
|
721
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
722
|
+
]
|
|
632
723
|
],
|
|
633
724
|
[
|
|
634
|
-
[
|
|
635
|
-
|
|
725
|
+
[
|
|
726
|
+
Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
|
|
727
|
+
true,
|
|
728
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
|
|
729
|
+
[
|
|
730
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
731
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
732
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
733
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
734
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
735
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
736
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
737
|
+
],
|
|
738
|
+
],
|
|
739
|
+
[
|
|
740
|
+
Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
|
|
741
|
+
0.5,
|
|
742
|
+
RatioState.OVER,
|
|
743
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
744
|
+
2,
|
|
745
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
746
|
+
1,
|
|
747
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
748
|
+
200,
|
|
749
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
750
|
+
]
|
|
636
751
|
],
|
|
637
752
|
];
|
|
638
753
|
|
|
639
754
|
examples.forEach(([expected, actual]) => {
|
|
640
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
641
|
-
expect(
|
|
755
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
756
|
+
expect(aaveV3Encode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
|
|
642
757
|
});
|
|
643
758
|
});
|
|
644
759
|
});
|
|
645
|
-
});
|
|
646
760
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
761
|
+
describe('closeOnPriceGeneric()', () => {
|
|
762
|
+
const examples: Array<[
|
|
763
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
764
|
+
[
|
|
765
|
+
strategyOrBundleId: number,
|
|
766
|
+
collAsset: EthereumAddress,
|
|
767
|
+
collAssetId: number,
|
|
768
|
+
debtAsset: EthereumAddress,
|
|
769
|
+
debtAssetId: number,
|
|
770
|
+
marketAddr: EthereumAddress,
|
|
771
|
+
user: EthereumAddress,
|
|
772
|
+
stopLossPrice: number,
|
|
773
|
+
stopLossType: CloseToAssetType,
|
|
774
|
+
takeProfitPrice: number,
|
|
775
|
+
takeProfitType: CloseToAssetType
|
|
776
|
+
]
|
|
777
|
+
]> = [
|
|
778
|
+
// Stop loss only (to debt)
|
|
650
779
|
[
|
|
651
780
|
[
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
781
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
782
|
+
true,
|
|
783
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
|
|
784
|
+
[
|
|
785
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
786
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
787
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
788
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
789
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
790
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
791
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
792
|
+
],
|
|
659
793
|
],
|
|
660
794
|
[
|
|
661
|
-
|
|
795
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
796
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
797
|
+
0,
|
|
662
798
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
663
|
-
|
|
664
|
-
|
|
799
|
+
1,
|
|
800
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
801
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
802
|
+
1500, // stopLossPrice
|
|
803
|
+
CloseToAssetType.DEBT, // stopLossType
|
|
804
|
+
0, // takeProfitPrice
|
|
805
|
+
CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
|
|
665
806
|
]
|
|
666
807
|
],
|
|
808
|
+
// Take profit only (to collateral)
|
|
667
809
|
[
|
|
668
810
|
[
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
811
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
812
|
+
true,
|
|
813
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
814
|
+
[
|
|
815
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
816
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
817
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
818
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
819
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
820
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
821
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
822
|
+
],
|
|
676
823
|
],
|
|
677
824
|
[
|
|
678
|
-
|
|
825
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
679
826
|
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
680
|
-
|
|
681
|
-
|
|
827
|
+
0,
|
|
828
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
829
|
+
1,
|
|
830
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
831
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
832
|
+
0, // stopLossPrice
|
|
833
|
+
CloseToAssetType.DEBT, // stopLossType (not used since price is 0)
|
|
834
|
+
5000, // takeProfitPrice
|
|
835
|
+
CloseToAssetType.COLLATERAL, // takeProfitType
|
|
682
836
|
]
|
|
683
837
|
],
|
|
684
|
-
|
|
685
|
-
examples.forEach(([expected, actual]) => {
|
|
686
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
687
|
-
expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
688
|
-
});
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
694
|
-
describe('leverageManagement()', () => {
|
|
695
|
-
const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
|
|
696
|
-
[
|
|
697
|
-
[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],
|
|
698
|
-
[160, 220, 180, 190, true]
|
|
699
|
-
],
|
|
700
|
-
[
|
|
701
|
-
[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],
|
|
702
|
-
[160, 200, 180, 190, false]
|
|
703
|
-
],
|
|
704
|
-
];
|
|
705
|
-
|
|
706
|
-
examples.forEach(([expected, actual]) => {
|
|
707
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
708
|
-
expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
709
|
-
});
|
|
710
|
-
});
|
|
711
|
-
});
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
describe('When testing strategySubService.exchangeEncode', () => {
|
|
715
|
-
describe('dca()', () => {
|
|
716
|
-
const examples: Array<[
|
|
717
|
-
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
718
|
-
[fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId],
|
|
719
|
-
]> = [
|
|
838
|
+
// Both stop loss and take profit with useOnBehalf
|
|
720
839
|
[
|
|
721
840
|
[
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
841
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
842
|
+
true,
|
|
843
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
725
844
|
[
|
|
726
|
-
'
|
|
727
|
-
'
|
|
845
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
846
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
847
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
848
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
849
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
850
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
851
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
728
852
|
],
|
|
729
853
|
],
|
|
730
|
-
[
|
|
854
|
+
[
|
|
855
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
856
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
857
|
+
2,
|
|
858
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
859
|
+
1,
|
|
860
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
861
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
862
|
+
1500, // stopLossPrice
|
|
863
|
+
CloseToAssetType.COLLATERAL, // stopLossType
|
|
864
|
+
4000, // takeProfitPrice
|
|
865
|
+
CloseToAssetType.COLLATERAL, // takeProfitType
|
|
866
|
+
]
|
|
731
867
|
],
|
|
868
|
+
// Stop loss only (to collateral) - CloseStrategyType.STOP_LOSS_IN_COLLATERAL
|
|
732
869
|
[
|
|
733
870
|
[
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
871
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
872
|
+
true,
|
|
873
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
|
|
737
874
|
[
|
|
738
|
-
'
|
|
739
|
-
'
|
|
875
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
876
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
877
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
878
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
879
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
880
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
881
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
740
882
|
],
|
|
741
883
|
],
|
|
742
|
-
[
|
|
884
|
+
[
|
|
885
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
886
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
887
|
+
0,
|
|
888
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
889
|
+
1,
|
|
890
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
891
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
892
|
+
1500, // stopLossPrice
|
|
893
|
+
CloseToAssetType.COLLATERAL, // stopLossType
|
|
894
|
+
0, // takeProfitPrice
|
|
895
|
+
CloseToAssetType.DEBT, // takeProfitType (not used since price is 0)
|
|
896
|
+
]
|
|
743
897
|
],
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
examples.forEach(([expected, actual]) => {
|
|
747
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
748
|
-
expect(exchangeEncode.dca(...actual)).to.eql(expected);
|
|
749
|
-
});
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
|
|
753
|
-
describe('limitOrder()', () => {
|
|
754
|
-
const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
|
|
898
|
+
// Take profit only (to debt) - CloseStrategyType.TAKE_PROFIT_IN_DEBT
|
|
755
899
|
[
|
|
756
900
|
[
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
901
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
902
|
+
true,
|
|
903
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
904
|
+
[
|
|
905
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
906
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
907
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
908
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
909
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
910
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
911
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
912
|
+
],
|
|
763
913
|
],
|
|
764
914
|
[
|
|
915
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
765
916
|
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
766
|
-
|
|
767
|
-
'
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
917
|
+
0,
|
|
918
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
919
|
+
1,
|
|
920
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
921
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
922
|
+
0, // stopLossPrice
|
|
923
|
+
CloseToAssetType.COLLATERAL, // stopLossType (not used since price is 0)
|
|
924
|
+
5000, // takeProfitPrice
|
|
925
|
+
CloseToAssetType.DEBT, // takeProfitType
|
|
771
926
|
]
|
|
772
927
|
],
|
|
928
|
+
// Take profit in collateral and stop loss in debt - CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
|
|
773
929
|
[
|
|
774
930
|
[
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
931
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
932
|
+
true,
|
|
933
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
934
|
+
[
|
|
935
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
936
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
937
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
938
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
939
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
940
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
941
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
942
|
+
],
|
|
781
943
|
],
|
|
782
944
|
[
|
|
783
|
-
|
|
784
|
-
web3Utils.toChecksumAddress(getAssetInfo('
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
945
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
946
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
947
|
+
2,
|
|
948
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
949
|
+
1,
|
|
950
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
951
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
952
|
+
1500, // stopLossPrice
|
|
953
|
+
CloseToAssetType.DEBT, // stopLossType
|
|
954
|
+
4000, // takeProfitPrice
|
|
955
|
+
CloseToAssetType.COLLATERAL, // takeProfitType
|
|
789
956
|
]
|
|
790
957
|
],
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
958
|
+
// Both stop loss and take profit in debt - CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
|
|
959
|
+
[
|
|
960
|
+
[
|
|
961
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
962
|
+
true,
|
|
963
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
964
|
+
[
|
|
965
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
966
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
967
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
968
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
969
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
970
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
971
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
972
|
+
],
|
|
973
|
+
],
|
|
974
|
+
[
|
|
975
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
976
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
977
|
+
0,
|
|
978
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
979
|
+
1,
|
|
980
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
981
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
982
|
+
1500, // stopLossPrice
|
|
983
|
+
CloseToAssetType.DEBT, // stopLossType
|
|
984
|
+
4000, // takeProfitPrice
|
|
985
|
+
CloseToAssetType.DEBT, // takeProfitType
|
|
986
|
+
]
|
|
987
|
+
],
|
|
988
|
+
// Take profit in debt and stop loss in collateral - CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
|
|
989
|
+
[
|
|
990
|
+
[
|
|
991
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
992
|
+
true,
|
|
993
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
994
|
+
[
|
|
995
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
996
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
997
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
998
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
999
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
1000
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
1001
|
+
'0x0000000000000000000000009876543210987654321098765432109876543210',
|
|
1002
|
+
],
|
|
1003
|
+
],
|
|
1004
|
+
[
|
|
1005
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
1006
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1007
|
+
0,
|
|
1008
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1009
|
+
1,
|
|
1010
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1011
|
+
web3Utils.toChecksumAddress('0x9876543210987654321098765432109876543210'),
|
|
1012
|
+
1500, // stopLossPrice
|
|
1013
|
+
CloseToAssetType.COLLATERAL, // stopLossType
|
|
1014
|
+
4000, // takeProfitPrice
|
|
1015
|
+
CloseToAssetType.DEBT, // takeProfitType
|
|
1016
|
+
]
|
|
1017
|
+
],
|
|
1018
|
+
];
|
|
1019
|
+
|
|
1020
|
+
examples.forEach(([expected, actual]) => {
|
|
1021
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1022
|
+
expect(aaveV3Encode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1023
|
+
});
|
|
1024
|
+
});
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
describe('collateralSwitch()', () => {
|
|
1028
|
+
const examples: Array<[
|
|
1029
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1030
|
+
[
|
|
1031
|
+
strategyOrBundleId: number,
|
|
1032
|
+
fromAsset: EthereumAddress,
|
|
1033
|
+
fromAssetId: number,
|
|
1034
|
+
toAsset: EthereumAddress,
|
|
1035
|
+
toAssetId: number,
|
|
1036
|
+
marketAddr: EthereumAddress,
|
|
1037
|
+
amountToSwitch: string,
|
|
1038
|
+
baseTokenAddress: EthereumAddress,
|
|
1039
|
+
quoteTokenAddress: EthereumAddress,
|
|
1040
|
+
price: number,
|
|
1041
|
+
state: RatioState,
|
|
1042
|
+
]
|
|
1043
|
+
]> = [
|
|
1044
|
+
// WETH -> USDC, price 100000, state UNDER
|
|
1045
|
+
[
|
|
1046
|
+
[
|
|
1047
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1048
|
+
false,
|
|
1049
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1050
|
+
[
|
|
1051
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1052
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1053
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1054
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1055
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1056
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1057
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1058
|
+
],
|
|
1059
|
+
],
|
|
1060
|
+
[
|
|
1061
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1062
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1063
|
+
0,
|
|
1064
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1065
|
+
1,
|
|
1066
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1067
|
+
'10000000000000000000', // 10 WETH
|
|
1068
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1069
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1070
|
+
100000,
|
|
1071
|
+
RatioState.UNDER,
|
|
1072
|
+
]
|
|
1073
|
+
],
|
|
1074
|
+
// USDC -> WETH, price 0.00001, state OVER
|
|
1075
|
+
[
|
|
1076
|
+
[
|
|
1077
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1078
|
+
false,
|
|
1079
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000'],
|
|
1080
|
+
[
|
|
1081
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1082
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1083
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1084
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1085
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1086
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
1087
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1088
|
+
],
|
|
1089
|
+
],
|
|
1090
|
+
[
|
|
1091
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1092
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1093
|
+
1,
|
|
1094
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1095
|
+
0,
|
|
1096
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1097
|
+
MAXUINT, // MaxUint256
|
|
1098
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1099
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1100
|
+
0.00001,
|
|
1101
|
+
RatioState.OVER,
|
|
1102
|
+
]
|
|
1103
|
+
],
|
|
1104
|
+
// WETH -> WBTC, price 1, state UNDER
|
|
1105
|
+
[
|
|
1106
|
+
[
|
|
1107
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1108
|
+
false,
|
|
1109
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1110
|
+
[
|
|
1111
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1112
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1113
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1114
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1115
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1116
|
+
'0x0000000000000000000000000000000000000000000000004563918244f40000',
|
|
1117
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1118
|
+
],
|
|
1119
|
+
],
|
|
1120
|
+
[
|
|
1121
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1122
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1123
|
+
0,
|
|
1124
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1125
|
+
2,
|
|
1126
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1127
|
+
'5000000000000000000', // 5 WETH
|
|
1128
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1129
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1130
|
+
1,
|
|
1131
|
+
RatioState.UNDER,
|
|
1132
|
+
]
|
|
1133
|
+
],
|
|
1134
|
+
];
|
|
1135
|
+
|
|
1136
|
+
examples.forEach(([expected, actual]) => {
|
|
1137
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1138
|
+
expect(aaveV3Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1139
|
+
});
|
|
1140
|
+
});
|
|
1141
|
+
});
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1144
|
+
describe('When testing strategySubService.compoundV2Encode', () => {
|
|
1145
|
+
describe('leverageManagement()', () => {
|
|
1146
|
+
const examples: Array<[
|
|
1147
|
+
[string, string, string, string, boolean],
|
|
1148
|
+
[triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
|
|
1149
|
+
]> = [
|
|
1150
|
+
[
|
|
1151
|
+
[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],
|
|
1152
|
+
[160, 220, 180, 190, true]
|
|
1153
|
+
],
|
|
1154
|
+
[
|
|
1155
|
+
[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],
|
|
1156
|
+
[160, 200, 180, 190, false]
|
|
1157
|
+
],
|
|
1158
|
+
];
|
|
1159
|
+
|
|
1160
|
+
examples.forEach(([expected, actual]) => {
|
|
1161
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1162
|
+
expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1163
|
+
});
|
|
1164
|
+
});
|
|
1165
|
+
});
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
1169
|
+
describe('leverageManagement()', () => {
|
|
1170
|
+
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]]> = [
|
|
1171
|
+
[
|
|
1172
|
+
[
|
|
1173
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1174
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1175
|
+
new Dec(160).mul(1e16).toString(),
|
|
1176
|
+
new Dec(220).mul(1e16).toString(),
|
|
1177
|
+
new Dec(180).mul(1e16).toString(),
|
|
1178
|
+
new Dec(190).mul(1e16).toString(),
|
|
1179
|
+
true, false,
|
|
1180
|
+
],
|
|
1181
|
+
[
|
|
1182
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1183
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1184
|
+
160, 220, 180, 190,
|
|
1185
|
+
true, false,
|
|
1186
|
+
]
|
|
1187
|
+
],
|
|
1188
|
+
[
|
|
1189
|
+
[
|
|
1190
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1191
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1192
|
+
new Dec(160).mul(1e16).toString(),
|
|
1193
|
+
new Dec(210).mul(1e16).toString(),
|
|
1194
|
+
new Dec(180).mul(1e16).toString(),
|
|
1195
|
+
new Dec(190).mul(1e16).toString(),
|
|
1196
|
+
false, true,
|
|
1197
|
+
],
|
|
1198
|
+
[
|
|
1199
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
1200
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1201
|
+
160, 210, 180, 190,
|
|
1202
|
+
false, true,
|
|
1203
|
+
]
|
|
1204
|
+
],
|
|
1205
|
+
];
|
|
1206
|
+
examples.forEach(([expected, actual]) => {
|
|
1207
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1208
|
+
expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1209
|
+
});
|
|
1210
|
+
});
|
|
1211
|
+
});
|
|
1212
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1213
|
+
const examples: Array<[
|
|
1214
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1215
|
+
[strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, price: number, priceState: RatioState, ratioState: RatioState, user: EthereumAddress]
|
|
1216
|
+
]> = [
|
|
1217
|
+
[
|
|
1218
|
+
[
|
|
1219
|
+
Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
1220
|
+
true,
|
|
1221
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f07775030000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1222
|
+
[
|
|
1223
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
1224
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1225
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1226
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1227
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1228
|
+
'0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
|
|
1229
|
+
],
|
|
1230
|
+
],
|
|
1231
|
+
[
|
|
1232
|
+
Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
1233
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1234
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1235
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1236
|
+
200,
|
|
1237
|
+
2000,
|
|
1238
|
+
RatioState.UNDER,
|
|
1239
|
+
RatioState.UNDER,
|
|
1240
|
+
web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1241
|
+
],
|
|
1242
|
+
],
|
|
1243
|
+
[
|
|
1244
|
+
[
|
|
1245
|
+
Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
1246
|
+
true,
|
|
1247
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f077750300000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1248
|
+
[
|
|
1249
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
1250
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1251
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1252
|
+
'0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
|
|
1253
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1254
|
+
'0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
|
|
1255
|
+
],
|
|
1256
|
+
],
|
|
1257
|
+
[
|
|
1258
|
+
Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
1259
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1260
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1261
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1262
|
+
190,
|
|
1263
|
+
3000,
|
|
1264
|
+
RatioState.OVER,
|
|
1265
|
+
RatioState.OVER,
|
|
1266
|
+
web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1267
|
+
],
|
|
1268
|
+
]
|
|
1269
|
+
];
|
|
1270
|
+
examples.forEach(([expected, actual]) => {
|
|
1271
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1272
|
+
expect(compoundV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1273
|
+
});
|
|
1274
|
+
});
|
|
1275
|
+
});
|
|
1276
|
+
describe('closeOnPrice()', () => {
|
|
1277
|
+
const examples: Array<[
|
|
1278
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1279
|
+
[strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, stopLossPrice: number, stopLossType: CloseToAssetType, takeProfitPrice: number, takeProfitType: CloseToAssetType, user: EthereumAddress]
|
|
1280
|
+
]> = [
|
|
1281
|
+
[
|
|
1282
|
+
[
|
|
1283
|
+
Bundles.MainnetIds.COMP_V3_SW_CLOSE,
|
|
1284
|
+
true,
|
|
1285
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1286
|
+
[
|
|
1287
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
1288
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1289
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1290
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1291
|
+
'0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
|
|
1292
|
+
],
|
|
1293
|
+
],
|
|
1294
|
+
[
|
|
1295
|
+
Bundles.MainnetIds.COMP_V3_SW_CLOSE,
|
|
1296
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1297
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1298
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1299
|
+
1500,
|
|
1300
|
+
CloseToAssetType.DEBT,
|
|
1301
|
+
4000,
|
|
1302
|
+
CloseToAssetType.DEBT,
|
|
1303
|
+
web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1304
|
+
],
|
|
1305
|
+
],
|
|
1306
|
+
[
|
|
1307
|
+
[
|
|
1308
|
+
Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
|
|
1309
|
+
true,
|
|
1310
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1311
|
+
[
|
|
1312
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
1313
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1314
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1315
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1316
|
+
'0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
|
|
1317
|
+
],
|
|
1318
|
+
],
|
|
1319
|
+
[
|
|
1320
|
+
Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
|
|
1321
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1322
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1323
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1324
|
+
0,
|
|
1325
|
+
CloseToAssetType.DEBT,
|
|
1326
|
+
5000,
|
|
1327
|
+
CloseToAssetType.COLLATERAL,
|
|
1328
|
+
web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1329
|
+
],
|
|
1330
|
+
]
|
|
1331
|
+
];
|
|
1332
|
+
examples.forEach(([expected, actual]) => {
|
|
1333
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1334
|
+
expect(compoundV3Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
1335
|
+
});
|
|
1336
|
+
});
|
|
1337
|
+
});
|
|
1338
|
+
});
|
|
1339
|
+
|
|
1340
|
+
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
1341
|
+
describe('leverageManagement()', () => {
|
|
1342
|
+
const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
|
|
1343
|
+
[
|
|
1344
|
+
[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],
|
|
1345
|
+
[160, 220, 180, 190, true]
|
|
1346
|
+
],
|
|
1347
|
+
[
|
|
1348
|
+
[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],
|
|
1349
|
+
[160, 200, 180, 190, false]
|
|
1350
|
+
],
|
|
1351
|
+
];
|
|
1352
|
+
|
|
1353
|
+
examples.forEach(([expected, actual]) => {
|
|
1354
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1355
|
+
expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1356
|
+
});
|
|
1357
|
+
});
|
|
1358
|
+
});
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
describe('When testing strategySubService.exchangeEncode', () => {
|
|
1362
|
+
describe('dca()', () => {
|
|
1363
|
+
const examples: Array<[
|
|
1364
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1365
|
+
[fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId],
|
|
1366
|
+
]> = [
|
|
1367
|
+
[
|
|
1368
|
+
[
|
|
1369
|
+
Strategies.ArbitrumIds.EXCHANGE_DCA,
|
|
1370
|
+
false,
|
|
1371
|
+
['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
|
|
1372
|
+
[
|
|
1373
|
+
'0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
|
|
1374
|
+
'0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
|
|
1375
|
+
],
|
|
1376
|
+
],
|
|
1377
|
+
[getAssetInfo('DAI', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, ChainId.Arbitrum]
|
|
1378
|
+
],
|
|
1379
|
+
[
|
|
1380
|
+
[
|
|
1381
|
+
Strategies.MainnetIds.EXCHANGE_DCA,
|
|
1382
|
+
false,
|
|
1383
|
+
['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
|
|
1384
|
+
[
|
|
1385
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
|
|
1386
|
+
'0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
|
|
1387
|
+
],
|
|
1388
|
+
],
|
|
1389
|
+
[getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
|
|
1390
|
+
],
|
|
1391
|
+
];
|
|
1392
|
+
|
|
1393
|
+
examples.forEach(([expected, actual]) => {
|
|
1394
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1395
|
+
expect(exchangeEncode.dca(...actual)).to.eql(expected);
|
|
1396
|
+
});
|
|
1397
|
+
});
|
|
1398
|
+
});
|
|
1399
|
+
|
|
1400
|
+
describe('limitOrder()', () => {
|
|
1401
|
+
const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
|
|
1402
|
+
[
|
|
1403
|
+
[
|
|
1404
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1405
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1406
|
+
'2131',
|
|
1407
|
+
'0.53123',
|
|
1408
|
+
'1696590921159',
|
|
1409
|
+
`${OrderType.STOP_LOSS}`
|
|
1410
|
+
],
|
|
1411
|
+
[
|
|
1412
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1413
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1414
|
+
'2131',
|
|
1415
|
+
'0.53123',
|
|
1416
|
+
1696590921159,
|
|
1417
|
+
OrderType.STOP_LOSS
|
|
1418
|
+
]
|
|
1419
|
+
],
|
|
1420
|
+
[
|
|
1421
|
+
[
|
|
1422
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1423
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1424
|
+
'2131',
|
|
1425
|
+
'0.43123',
|
|
1426
|
+
'1646590921159',
|
|
1427
|
+
`${OrderType.TAKE_PROFIT}`
|
|
1428
|
+
],
|
|
1429
|
+
[
|
|
1430
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1431
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1432
|
+
'2131',
|
|
1433
|
+
'0.43123',
|
|
1434
|
+
1646590921159,
|
|
1435
|
+
OrderType.TAKE_PROFIT
|
|
1436
|
+
]
|
|
1437
|
+
],
|
|
1438
|
+
];
|
|
1439
|
+
|
|
1440
|
+
examples.forEach(([expected, actual]) => {
|
|
1441
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1442
|
+
expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
|
|
1443
|
+
});
|
|
1444
|
+
});
|
|
1445
|
+
});
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
describe('When testing strategySubService.crvUSDEncode', () => {
|
|
1449
|
+
describe('leverageManagement()', () => {
|
|
1450
|
+
const examples: Array<[
|
|
1451
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1452
|
+
[owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress],
|
|
1453
|
+
]> = [
|
|
1454
|
+
[
|
|
1455
|
+
[
|
|
1456
|
+
Bundles.MainnetIds.CRVUSD_REPAY,
|
|
1457
|
+
true,
|
|
1458
|
+
[
|
|
1459
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
|
|
1460
|
+
],
|
|
1461
|
+
[
|
|
1462
|
+
'0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
|
|
1463
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1464
|
+
'0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
|
|
1465
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1466
|
+
'0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
|
|
1467
|
+
],
|
|
1468
|
+
],
|
|
1469
|
+
[
|
|
1470
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1471
|
+
web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
|
|
1472
|
+
RatioState.UNDER,
|
|
1473
|
+
190,
|
|
1474
|
+
140,
|
|
1475
|
+
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1476
|
+
'0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
|
|
1477
|
+
]
|
|
1478
|
+
],
|
|
1479
|
+
[
|
|
1480
|
+
[
|
|
1481
|
+
Bundles.MainnetIds.CRVUSD_BOOST,
|
|
1482
|
+
true,
|
|
1483
|
+
[
|
|
1484
|
+
'0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
|
|
1485
|
+
],
|
|
1486
|
+
[
|
|
1487
|
+
'0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
|
|
1488
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1489
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1490
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1491
|
+
'0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
|
|
1492
|
+
],
|
|
1493
|
+
],
|
|
1494
|
+
[
|
|
1495
|
+
web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
|
|
1496
|
+
web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
|
|
1497
|
+
RatioState.OVER,
|
|
1498
|
+
160,
|
|
1499
|
+
200,
|
|
1500
|
+
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1501
|
+
'0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
|
|
1502
|
+
]
|
|
1503
|
+
],
|
|
1504
|
+
];
|
|
1505
|
+
|
|
1506
|
+
examples.forEach(([expected, actual]) => {
|
|
1507
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1508
|
+
expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1509
|
+
});
|
|
1510
|
+
});
|
|
1511
|
+
});
|
|
1512
|
+
describe('payback()', () => {
|
|
1513
|
+
const examples: Array<[
|
|
1514
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1515
|
+
[owner: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number],
|
|
1516
|
+
]> = [
|
|
1517
|
+
[
|
|
1518
|
+
[
|
|
1519
|
+
Strategies.MainnetIds.CURVEUSD_PAYBACK,
|
|
1520
|
+
false,
|
|
1521
|
+
[
|
|
1522
|
+
'0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000',
|
|
1523
|
+
],
|
|
1524
|
+
[
|
|
1525
|
+
'0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
|
|
1526
|
+
'0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
|
|
1527
|
+
'0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
|
|
1528
|
+
'0x00000000000000000000000000000000000000000000043c33c1937564800000',
|
|
1529
|
+
'0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
|
|
1530
|
+
],
|
|
1531
|
+
],
|
|
1532
|
+
[
|
|
1533
|
+
web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
|
|
1534
|
+
web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
|
|
1535
|
+
web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
|
|
1536
|
+
'20000',
|
|
1537
|
+
'0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
|
|
1538
|
+
web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
|
|
1539
|
+
20,
|
|
1540
|
+
]
|
|
1541
|
+
]
|
|
1542
|
+
];
|
|
1543
|
+
|
|
1544
|
+
examples.forEach(([expected, actual]) => {
|
|
1545
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1546
|
+
expect(crvUSDEncode.payback(...actual)).to.eql(expected);
|
|
1547
|
+
});
|
|
797
1548
|
});
|
|
798
1549
|
});
|
|
799
1550
|
});
|
|
800
1551
|
|
|
801
|
-
describe('When testing strategySubService.
|
|
1552
|
+
describe('When testing strategySubService.morphoBlueEncode', () => {
|
|
802
1553
|
describe('leverageManagement()', () => {
|
|
803
1554
|
const examples: Array<[
|
|
804
|
-
|
|
805
|
-
[
|
|
1555
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1556
|
+
[
|
|
1557
|
+
marketId: string,
|
|
1558
|
+
loanToken: EthereumAddress,
|
|
1559
|
+
collToken: EthereumAddress,
|
|
1560
|
+
oracle: EthereumAddress,
|
|
1561
|
+
irm: EthereumAddress,
|
|
1562
|
+
lltv: string,
|
|
1563
|
+
ratioState: RatioState,
|
|
1564
|
+
targetRatio: number,
|
|
1565
|
+
triggerRatio: number,
|
|
1566
|
+
user: EthereumAddress,
|
|
1567
|
+
isEoa: boolean,
|
|
1568
|
+
network: ChainId
|
|
1569
|
+
],
|
|
806
1570
|
]> = [
|
|
807
1571
|
[
|
|
808
|
-
|
|
809
|
-
|
|
1572
|
+
[
|
|
1573
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY,
|
|
1574
|
+
true,
|
|
1575
|
+
[
|
|
1576
|
+
'0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
|
|
1577
|
+
],
|
|
1578
|
+
[
|
|
1579
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1580
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1581
|
+
'0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
|
|
1582
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1583
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1584
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1585
|
+
'0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
|
|
1586
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1587
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1588
|
+
],
|
|
1589
|
+
],
|
|
1590
|
+
[
|
|
1591
|
+
'0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
|
|
1592
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1593
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1594
|
+
web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
|
|
1595
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1596
|
+
'945000000000000000',
|
|
1597
|
+
RatioState.UNDER,
|
|
1598
|
+
140,
|
|
1599
|
+
120,
|
|
1600
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1601
|
+
false,
|
|
1602
|
+
ChainId.Ethereum,
|
|
1603
|
+
]
|
|
810
1604
|
],
|
|
811
1605
|
[
|
|
812
|
-
|
|
813
|
-
|
|
1606
|
+
[
|
|
1607
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST,
|
|
1608
|
+
true,
|
|
1609
|
+
[
|
|
1610
|
+
'0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
|
|
1611
|
+
],
|
|
1612
|
+
[
|
|
1613
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1614
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1615
|
+
'0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
|
|
1616
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1617
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1618
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1619
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1620
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1621
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1622
|
+
],
|
|
1623
|
+
],
|
|
1624
|
+
[
|
|
1625
|
+
'0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
|
|
1626
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1627
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1628
|
+
web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
|
|
1629
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1630
|
+
'945000000000000000',
|
|
1631
|
+
RatioState.OVER,
|
|
1632
|
+
160,
|
|
1633
|
+
200,
|
|
1634
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1635
|
+
false,
|
|
1636
|
+
ChainId.Ethereum,
|
|
1637
|
+
]
|
|
814
1638
|
],
|
|
815
1639
|
];
|
|
816
1640
|
|
|
817
1641
|
examples.forEach(([expected, actual]) => {
|
|
818
1642
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
819
|
-
expect(
|
|
1643
|
+
expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
|
|
820
1644
|
});
|
|
821
1645
|
});
|
|
822
1646
|
});
|
|
823
1647
|
|
|
824
|
-
describe('
|
|
1648
|
+
describe('closeOnPrice()', () => {
|
|
825
1649
|
const examples: Array<[
|
|
826
1650
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
827
1651
|
[
|
|
828
1652
|
strategyOrBundleId: number,
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
1653
|
+
loanToken: EthereumAddress,
|
|
1654
|
+
collToken: EthereumAddress,
|
|
1655
|
+
oracle: EthereumAddress,
|
|
1656
|
+
irm: EthereumAddress,
|
|
1657
|
+
lltv: string,
|
|
1658
|
+
user: EthereumAddress,
|
|
1659
|
+
stopLossPrice: number,
|
|
1660
|
+
stopLossType: CloseToAssetType,
|
|
1661
|
+
takeProfitPrice: number,
|
|
1662
|
+
takeProfitType: CloseToAssetType,
|
|
836
1663
|
]
|
|
837
1664
|
]> = [
|
|
838
1665
|
[
|
|
839
1666
|
[
|
|
840
|
-
Bundles.MainnetIds.
|
|
1667
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
841
1668
|
true,
|
|
842
|
-
|
|
1669
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
843
1670
|
[
|
|
844
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
845
|
-
'
|
|
1671
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1672
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1673
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
846
1674
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1675
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1676
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1677
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1678
|
+
],
|
|
1679
|
+
],
|
|
1680
|
+
[
|
|
1681
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1682
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1683
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1684
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1685
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1686
|
+
'945000000000000000',
|
|
1687
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1688
|
+
1500,
|
|
1689
|
+
CloseToAssetType.DEBT,
|
|
1690
|
+
4000,
|
|
1691
|
+
CloseToAssetType.COLLATERAL
|
|
1692
|
+
]
|
|
1693
|
+
],
|
|
1694
|
+
];
|
|
1695
|
+
|
|
1696
|
+
examples.forEach(([expected, actual]) => {
|
|
1697
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1698
|
+
expect(morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
|
|
1699
|
+
});
|
|
1700
|
+
});
|
|
1701
|
+
});
|
|
1702
|
+
});
|
|
1703
|
+
|
|
1704
|
+
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
1705
|
+
describe('leverageManagement()', () => {
|
|
1706
|
+
const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean, boolean]]> = [
|
|
1707
|
+
[
|
|
1708
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1709
|
+
[
|
|
1710
|
+
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1711
|
+
web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1712
|
+
160, 220, 180, 190,
|
|
1713
|
+
true,
|
|
1714
|
+
false,
|
|
1715
|
+
],
|
|
1716
|
+
],
|
|
1717
|
+
[
|
|
1718
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1719
|
+
[
|
|
1720
|
+
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1721
|
+
web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1722
|
+
160, 220, 180, 110,
|
|
1723
|
+
false,
|
|
1724
|
+
false,
|
|
1725
|
+
],
|
|
1726
|
+
],
|
|
1727
|
+
];
|
|
1728
|
+
examples.forEach(([expected, actual]) => {
|
|
1729
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1730
|
+
expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1731
|
+
});
|
|
1732
|
+
});
|
|
1733
|
+
});
|
|
1734
|
+
});
|
|
1735
|
+
|
|
1736
|
+
describe('When testing strategySubService.sparkEncode', () => {
|
|
1737
|
+
describe('leverageManagement()', () => {
|
|
1738
|
+
const examples: Array<[string, [number, number, number, number, boolean]]> = [
|
|
1739
|
+
[
|
|
1740
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1741
|
+
[140,240,210,190,true]
|
|
1742
|
+
],
|
|
1743
|
+
[
|
|
1744
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1745
|
+
[137, 184, 289, 246, false]
|
|
1746
|
+
]
|
|
1747
|
+
];
|
|
1748
|
+
|
|
1749
|
+
examples.forEach(([expected, actual]) => {
|
|
1750
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1751
|
+
expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1752
|
+
});
|
|
1753
|
+
});
|
|
1754
|
+
});
|
|
1755
|
+
|
|
1756
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1757
|
+
const examples: Array<[[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1758
|
+
[
|
|
1759
|
+
strategyOrBundleId: number,
|
|
1760
|
+
isBundle: boolean,
|
|
1761
|
+
triggerData: { baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState },
|
|
1762
|
+
subData: { collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number }
|
|
1763
|
+
]]> = [
|
|
1764
|
+
[
|
|
1765
|
+
[
|
|
1766
|
+
Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
|
|
1767
|
+
true,
|
|
1768
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1769
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1770
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1771
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1772
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1773
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1774
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1775
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
847
1776
|
],
|
|
848
1777
|
],
|
|
849
1778
|
[
|
|
850
|
-
|
|
1779
|
+
59,
|
|
851
1780
|
true,
|
|
852
1781
|
{
|
|
853
|
-
|
|
1782
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1783
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1784
|
+
price: 2500,
|
|
1785
|
+
ratioState: RatioState.UNDER,
|
|
854
1786
|
},
|
|
855
1787
|
{
|
|
856
|
-
collAsset: getAssetInfo('WETH'
|
|
1788
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1789
|
+
collAssetId: 0,
|
|
1790
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1791
|
+
debtAssetId: 1,
|
|
1792
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1793
|
+
targetRatio: 200,
|
|
857
1794
|
},
|
|
858
1795
|
]
|
|
859
1796
|
],
|
|
860
1797
|
[
|
|
861
1798
|
[
|
|
862
|
-
Bundles.MainnetIds.
|
|
1799
|
+
Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
|
|
863
1800
|
true,
|
|
864
|
-
['
|
|
1801
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
865
1802
|
[
|
|
866
|
-
'
|
|
867
|
-
'
|
|
1803
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1804
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1805
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1806
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1807
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1808
|
+
'0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
868
1809
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
869
|
-
]
|
|
1810
|
+
]
|
|
870
1811
|
],
|
|
871
1812
|
[
|
|
872
|
-
|
|
1813
|
+
60,
|
|
873
1814
|
true,
|
|
874
1815
|
{
|
|
875
|
-
|
|
1816
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1817
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1818
|
+
price: 45000,
|
|
1819
|
+
ratioState: RatioState.OVER,
|
|
876
1820
|
},
|
|
877
1821
|
{
|
|
878
|
-
collAsset: getAssetInfo('
|
|
1822
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1823
|
+
collAssetId: 2,
|
|
1824
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1825
|
+
debtAssetId: 4,
|
|
1826
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1827
|
+
targetRatio: 250,
|
|
879
1828
|
},
|
|
880
1829
|
]
|
|
881
1830
|
]
|
|
@@ -883,240 +1832,305 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
883
1832
|
|
|
884
1833
|
examples.forEach(([expected, actual]) => {
|
|
885
1834
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
886
|
-
expect(sparkEncode.
|
|
1835
|
+
expect(sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
887
1836
|
});
|
|
888
1837
|
});
|
|
889
1838
|
});
|
|
890
|
-
});
|
|
891
1839
|
|
|
892
|
-
|
|
893
|
-
describe('leverageManagement()', () => {
|
|
1840
|
+
describe('closeOnPrice()', () => {
|
|
894
1841
|
const examples: Array<[
|
|
895
1842
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
896
|
-
[
|
|
897
|
-
|
|
1843
|
+
[
|
|
1844
|
+
strategyOrBundleId: number,
|
|
1845
|
+
collAsset: EthereumAddress,
|
|
1846
|
+
collAssetId: number,
|
|
1847
|
+
debtAsset: EthereumAddress,
|
|
1848
|
+
debtAssetId: number,
|
|
1849
|
+
marketAddr: EthereumAddress,
|
|
1850
|
+
user: EthereumAddress,
|
|
1851
|
+
stopLossPrice: number,
|
|
1852
|
+
stopLossType: CloseToAssetType,
|
|
1853
|
+
takeProfitPrice: number,
|
|
1854
|
+
takeProfitType: CloseToAssetType,
|
|
1855
|
+
]
|
|
1856
|
+
] > =
|
|
1857
|
+
[
|
|
898
1858
|
[
|
|
899
1859
|
[
|
|
900
|
-
Bundles.MainnetIds.
|
|
1860
|
+
Bundles.MainnetIds.SPARK_CLOSE,
|
|
901
1861
|
true,
|
|
1862
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
|
|
902
1863
|
[
|
|
903
|
-
'
|
|
904
|
-
|
|
1864
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1865
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1866
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1867
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1868
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1869
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1870
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1871
|
+
]
|
|
1872
|
+
],
|
|
1873
|
+
[
|
|
1874
|
+
57,
|
|
1875
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1876
|
+
2,
|
|
1877
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1878
|
+
4,
|
|
1879
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1880
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1881
|
+
40000,
|
|
1882
|
+
CloseToAssetType.DEBT,
|
|
1883
|
+
60000,
|
|
1884
|
+
CloseToAssetType.COLLATERAL,
|
|
1885
|
+
]
|
|
1886
|
+
],
|
|
1887
|
+
]
|
|
1888
|
+
|
|
1889
|
+
examples.forEach(([expected, actual]) => {
|
|
1890
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1891
|
+
expect(sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1892
|
+
});
|
|
1893
|
+
});
|
|
1894
|
+
});
|
|
1895
|
+
|
|
1896
|
+
describe('collateralSwitch()', () => {
|
|
1897
|
+
const examples: Array<[
|
|
1898
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1899
|
+
[
|
|
1900
|
+
strategyOrBundleId: number,
|
|
1901
|
+
fromAsset: EthereumAddress,
|
|
1902
|
+
fromAssetId: number,
|
|
1903
|
+
toAsset: EthereumAddress,
|
|
1904
|
+
toAssetId: number,
|
|
1905
|
+
marketAddr: EthereumAddress,
|
|
1906
|
+
amountToSwitch: string,
|
|
1907
|
+
baseTokenAddress: EthereumAddress,
|
|
1908
|
+
quoteTokenAddress: EthereumAddress,
|
|
1909
|
+
price: number,
|
|
1910
|
+
state: RatioState,
|
|
1911
|
+
]
|
|
1912
|
+
]> = [
|
|
1913
|
+
// WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
|
|
1914
|
+
[
|
|
1915
|
+
[
|
|
1916
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1917
|
+
false,
|
|
1918
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
|
|
905
1919
|
[
|
|
906
|
-
'0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
|
|
907
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
908
|
-
'0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
|
|
909
1920
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
910
|
-
'
|
|
1921
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1922
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
1923
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
1924
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1925
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1926
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
911
1927
|
],
|
|
912
1928
|
],
|
|
913
1929
|
[
|
|
914
|
-
|
|
915
|
-
web3Utils.toChecksumAddress('
|
|
1930
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1931
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1932
|
+
0,
|
|
1933
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1934
|
+
7,
|
|
1935
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1936
|
+
'10000000000000000000', // 10 WETH
|
|
1937
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1938
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1939
|
+
0.025,
|
|
916
1940
|
RatioState.UNDER,
|
|
917
|
-
190,
|
|
918
|
-
140,
|
|
919
|
-
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
920
|
-
'0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
|
|
921
1941
|
]
|
|
922
1942
|
],
|
|
1943
|
+
// cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
|
|
923
1944
|
[
|
|
924
1945
|
[
|
|
925
|
-
|
|
926
|
-
|
|
1946
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1947
|
+
false,
|
|
1948
|
+
['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
|
|
927
1949
|
[
|
|
928
|
-
'
|
|
1950
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
1951
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
1952
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1953
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1954
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1955
|
+
'0x0000000000000000000000000000000000000000000000000000000005f5e100',
|
|
1956
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
929
1957
|
],
|
|
1958
|
+
],
|
|
1959
|
+
[
|
|
1960
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1961
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1962
|
+
7,
|
|
1963
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1964
|
+
0,
|
|
1965
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1966
|
+
'100000000', // 1 cbBTC (8 decimals)
|
|
1967
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1968
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1969
|
+
25,
|
|
1970
|
+
RatioState.UNDER,
|
|
1971
|
+
]
|
|
1972
|
+
],
|
|
1973
|
+
// cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
|
|
1974
|
+
[
|
|
1975
|
+
[
|
|
1976
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1977
|
+
false,
|
|
1978
|
+
['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
|
|
930
1979
|
[
|
|
931
|
-
'
|
|
932
|
-
'
|
|
933
|
-
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1980
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
1981
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
934
1982
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
935
|
-
'
|
|
1983
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1984
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1985
|
+
'0x0000000000000000000000000000000000000000000000000000000005f5e100',
|
|
1986
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
936
1987
|
],
|
|
937
1988
|
],
|
|
938
1989
|
[
|
|
939
|
-
|
|
940
|
-
web3Utils.toChecksumAddress('
|
|
1990
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1991
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1992
|
+
7,
|
|
1993
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1994
|
+
0,
|
|
1995
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1996
|
+
'100000000', // 1 cbBTC (8 decimals)
|
|
1997
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1998
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1999
|
+
40,
|
|
941
2000
|
RatioState.OVER,
|
|
942
|
-
160,
|
|
943
|
-
200,
|
|
944
|
-
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
945
|
-
'0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
|
|
946
2001
|
]
|
|
947
2002
|
],
|
|
948
2003
|
];
|
|
949
2004
|
|
|
950
2005
|
examples.forEach(([expected, actual]) => {
|
|
951
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
952
|
-
expect(
|
|
2006
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2007
|
+
expect(sparkEncode.collateralSwitch(...actual)).to.eql(expected);
|
|
953
2008
|
});
|
|
954
2009
|
});
|
|
955
2010
|
});
|
|
956
|
-
|
|
2011
|
+
});
|
|
2012
|
+
|
|
2013
|
+
describe('When testing strategySubService.aaveV4Encode', () => {
|
|
2014
|
+
describe('leverageManagement()', () => {
|
|
957
2015
|
const examples: Array<[
|
|
958
2016
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
959
|
-
[
|
|
2017
|
+
[
|
|
2018
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number
|
|
2019
|
+
]
|
|
960
2020
|
]> = [
|
|
961
2021
|
[
|
|
2022
|
+
[1,true,["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x0000000000000000000000000000000000000000000000000000000000000001","0x00000000000000000000000000000000000000000000000014d1120d7b160000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
962
2023
|
[
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
'0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
|
|
970
|
-
'0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
|
|
971
|
-
'0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
|
|
972
|
-
'0x00000000000000000000000000000000000000000000043c33c1937564800000',
|
|
973
|
-
'0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
|
|
974
|
-
],
|
|
975
|
-
],
|
|
976
|
-
[
|
|
977
|
-
web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
|
|
978
|
-
web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
|
|
979
|
-
web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
|
|
980
|
-
'20000',
|
|
981
|
-
'0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
|
|
982
|
-
web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
|
|
983
|
-
20,
|
|
2024
|
+
1,
|
|
2025
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2026
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
2027
|
+
RatioState.UNDER,
|
|
2028
|
+
150,
|
|
2029
|
+
120,
|
|
984
2030
|
]
|
|
985
2031
|
]
|
|
986
2032
|
];
|
|
987
2033
|
|
|
988
2034
|
examples.forEach(([expected, actual]) => {
|
|
989
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
990
|
-
expect(
|
|
2035
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2036
|
+
expect(aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
|
|
991
2037
|
});
|
|
992
2038
|
});
|
|
993
2039
|
});
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
describe('leverageManagement()', () => {
|
|
2040
|
+
|
|
2041
|
+
describe('leverageManagementOnPrice()', () => {
|
|
997
2042
|
const examples: Array<[
|
|
998
2043
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
999
2044
|
[
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
collToken: EthereumAddress,
|
|
1003
|
-
oracle: EthereumAddress,
|
|
1004
|
-
irm: EthereumAddress,
|
|
1005
|
-
lltv: string,
|
|
1006
|
-
ratioState: RatioState,
|
|
1007
|
-
targetRatio: number,
|
|
1008
|
-
triggerRatio: number,
|
|
1009
|
-
user: EthereumAddress,
|
|
1010
|
-
isEoa: boolean,
|
|
1011
|
-
network: ChainId
|
|
1012
|
-
],
|
|
2045
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState
|
|
2046
|
+
]
|
|
1013
2047
|
]> = [
|
|
1014
2048
|
[
|
|
2049
|
+
[2,true,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000000000000000000000000000016345785d8a00000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1015
2050
|
[
|
|
1016
|
-
|
|
1017
|
-
true,
|
|
1018
|
-
[
|
|
1019
|
-
'0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
|
|
1020
|
-
],
|
|
1021
|
-
[
|
|
1022
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1023
|
-
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1024
|
-
'0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
|
|
1025
|
-
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1026
|
-
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1027
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1028
|
-
'0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
|
|
1029
|
-
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1030
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1031
|
-
],
|
|
1032
|
-
],
|
|
1033
|
-
[
|
|
1034
|
-
'0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
|
|
1035
|
-
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1036
|
-
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1037
|
-
web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
|
|
1038
|
-
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1039
|
-
'945000000000000000',
|
|
1040
|
-
RatioState.UNDER,
|
|
1041
|
-
140,
|
|
1042
|
-
120,
|
|
2051
|
+
2,
|
|
1043
2052
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1044
|
-
|
|
1045
|
-
|
|
2053
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
2054
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
2055
|
+
10,
|
|
2056
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
2057
|
+
20,
|
|
2058
|
+
160,
|
|
2059
|
+
'1500',
|
|
2060
|
+
RatioState.OVER, // priceState - goes to trigger
|
|
2061
|
+
RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1046
2062
|
]
|
|
1047
|
-
]
|
|
2063
|
+
]
|
|
2064
|
+
];
|
|
2065
|
+
|
|
2066
|
+
examples.forEach(([expected, actual]) => {
|
|
2067
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2068
|
+
expect(aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
2069
|
+
});
|
|
2070
|
+
});
|
|
2071
|
+
});
|
|
2072
|
+
|
|
2073
|
+
describe('closeOnPrice()', () => {
|
|
2074
|
+
const examples: Array<[
|
|
2075
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1048
2076
|
[
|
|
2077
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice: string, stopLossType: CloseToAssetType, takeProfitPrice: string, takeProfitType: CloseToAssetType
|
|
2078
|
+
]
|
|
2079
|
+
]> = [
|
|
2080
|
+
[
|
|
2081
|
+
[3,true,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000000000000000003","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1049
2082
|
[
|
|
1050
|
-
|
|
1051
|
-
true,
|
|
1052
|
-
[
|
|
1053
|
-
'0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
|
|
1054
|
-
],
|
|
1055
|
-
[
|
|
1056
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1057
|
-
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1058
|
-
'0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
|
|
1059
|
-
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1060
|
-
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1061
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1062
|
-
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1063
|
-
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1064
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1065
|
-
],
|
|
1066
|
-
],
|
|
1067
|
-
[
|
|
1068
|
-
'0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
|
|
1069
|
-
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1070
|
-
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1071
|
-
web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
|
|
1072
|
-
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1073
|
-
'945000000000000000',
|
|
1074
|
-
RatioState.OVER,
|
|
1075
|
-
160,
|
|
1076
|
-
200,
|
|
2083
|
+
3,
|
|
1077
2084
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1078
|
-
|
|
1079
|
-
|
|
2085
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
2086
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
2087
|
+
10,
|
|
2088
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
2089
|
+
20,
|
|
2090
|
+
'1400',
|
|
2091
|
+
CloseToAssetType.DEBT,
|
|
2092
|
+
'0',
|
|
2093
|
+
CloseToAssetType.COLLATERAL
|
|
1080
2094
|
]
|
|
1081
|
-
]
|
|
2095
|
+
]
|
|
1082
2096
|
];
|
|
1083
2097
|
|
|
1084
2098
|
examples.forEach(([expected, actual]) => {
|
|
1085
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1086
|
-
expect(
|
|
2099
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2100
|
+
expect(aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
1087
2101
|
});
|
|
1088
2102
|
});
|
|
1089
2103
|
});
|
|
1090
|
-
});
|
|
1091
2104
|
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
2105
|
+
describe('collateralSwitch()', () => {
|
|
2106
|
+
const examples: Array<[
|
|
2107
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1095
2108
|
[
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
1100
|
-
160, 220, 180, 190,
|
|
1101
|
-
true
|
|
1102
|
-
],
|
|
1103
|
-
],
|
|
2109
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState
|
|
2110
|
+
]
|
|
2111
|
+
]> = [
|
|
1104
2112
|
[
|
|
1105
|
-
|
|
2113
|
+
[4,false,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000de0b6b3a7640000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1106
2114
|
[
|
|
1107
|
-
|
|
1108
|
-
web3Utils.toChecksumAddress('
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
2115
|
+
4,
|
|
2116
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2117
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
2118
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
2119
|
+
10,
|
|
2120
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
2121
|
+
20,
|
|
2122
|
+
'1000000000000000000',
|
|
2123
|
+
'1500',
|
|
2124
|
+
RatioState.UNDER,
|
|
2125
|
+
]
|
|
2126
|
+
]
|
|
1113
2127
|
];
|
|
2128
|
+
|
|
1114
2129
|
examples.forEach(([expected, actual]) => {
|
|
1115
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1116
|
-
expect(
|
|
2130
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2131
|
+
expect(aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1117
2132
|
});
|
|
1118
2133
|
});
|
|
1119
2134
|
});
|
|
1120
2135
|
});
|
|
1121
|
-
|
|
1122
2136
|
});
|