@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,11 +1,11 @@
|
|
|
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
|
-
import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
|
|
6
|
+
import { Bundles, ChainId, CloseToAssetType, OrderType, RatioState, Strategies } from '../types/enums';
|
|
7
7
|
import '../configuration';
|
|
8
|
-
import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode,
|
|
8
|
+
import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, sparkEncode, aaveV4Encode, } from './strategySubService';
|
|
9
9
|
describe('Feature: strategySubService.ts', () => {
|
|
10
10
|
describe('When testing strategySubService.makerEncode', () => {
|
|
11
11
|
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
@@ -118,6 +118,53 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
|
+
describe('leverageManagementWithoutSubProxy()', () => {
|
|
122
|
+
const examples = [
|
|
123
|
+
// Repay scenario (isBoost=false, RatioState.UNDER)
|
|
124
|
+
[
|
|
125
|
+
[
|
|
126
|
+
Bundles.MainnetIds.MAKER_REPAY,
|
|
127
|
+
true,
|
|
128
|
+
['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
|
|
129
|
+
[
|
|
130
|
+
'0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
|
|
131
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
132
|
+
],
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
222,
|
|
136
|
+
140,
|
|
137
|
+
180,
|
|
138
|
+
RatioState.UNDER,
|
|
139
|
+
false, // isBoost
|
|
140
|
+
]
|
|
141
|
+
],
|
|
142
|
+
// Boost scenario (isBoost=true, RatioState.OVER)
|
|
143
|
+
[
|
|
144
|
+
[
|
|
145
|
+
Bundles.MainnetIds.MAKER_BOOST,
|
|
146
|
+
true,
|
|
147
|
+
['0x000000000000000000000000000000000000000000000000000000000000014d00000000000000000000000000000000000000000000000026db992a3b1800000000000000000000000000000000000000000000000000000000000000000000'],
|
|
148
|
+
[
|
|
149
|
+
'0x000000000000000000000000000000000000000000000000000000000000014d', '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
150
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
151
|
+
],
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
333,
|
|
155
|
+
280,
|
|
156
|
+
250,
|
|
157
|
+
RatioState.OVER,
|
|
158
|
+
true, // isBoost
|
|
159
|
+
]
|
|
160
|
+
],
|
|
161
|
+
];
|
|
162
|
+
examples.forEach(([expected, actual]) => {
|
|
163
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
164
|
+
expect(makerEncode.leverageManagementWithoutSubProxy(...actual)).to.eql(expected);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
121
168
|
});
|
|
122
169
|
describe('When testing strategySubService.liquityEncode', () => {
|
|
123
170
|
describe('closeOnPrice()', () => {
|
|
@@ -466,238 +513,699 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
466
513
|
});
|
|
467
514
|
});
|
|
468
515
|
});
|
|
469
|
-
|
|
470
|
-
describe('When testing strategySubService.compoundV2Encode', () => {
|
|
471
|
-
describe('leverageManagement()', () => {
|
|
472
|
-
const examples = [
|
|
473
|
-
[
|
|
474
|
-
[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],
|
|
475
|
-
[160, 220, 180, 190, true]
|
|
476
|
-
],
|
|
477
|
-
[
|
|
478
|
-
[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],
|
|
479
|
-
[160, 200, 180, 190, false]
|
|
480
|
-
],
|
|
481
|
-
];
|
|
482
|
-
examples.forEach(([expected, actual]) => {
|
|
483
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
484
|
-
expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
});
|
|
488
|
-
});
|
|
489
|
-
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
490
|
-
describe('leverageManagement()', () => {
|
|
516
|
+
describe('leverageManagementOnPriceGeneric()', () => {
|
|
491
517
|
const examples = [
|
|
492
518
|
[
|
|
493
519
|
[
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
520
|
+
Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
|
|
521
|
+
true,
|
|
522
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
|
|
523
|
+
[
|
|
524
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
525
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
526
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
527
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
528
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
529
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
530
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
531
|
+
],
|
|
501
532
|
],
|
|
502
533
|
[
|
|
503
|
-
|
|
534
|
+
Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
|
|
535
|
+
1670,
|
|
536
|
+
RatioState.UNDER,
|
|
537
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
538
|
+
0,
|
|
504
539
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
505
|
-
|
|
506
|
-
|
|
540
|
+
1,
|
|
541
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
542
|
+
200,
|
|
543
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
507
544
|
]
|
|
508
545
|
],
|
|
509
546
|
[
|
|
510
547
|
[
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
548
|
+
Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
|
|
549
|
+
true,
|
|
550
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
|
|
551
|
+
[
|
|
552
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
553
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
554
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
555
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
556
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
557
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
558
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
559
|
+
],
|
|
518
560
|
],
|
|
519
561
|
[
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
562
|
+
Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
|
|
563
|
+
0.5,
|
|
564
|
+
RatioState.OVER,
|
|
565
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
566
|
+
2,
|
|
567
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
568
|
+
1,
|
|
569
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
570
|
+
200,
|
|
571
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
524
572
|
]
|
|
525
573
|
],
|
|
526
574
|
];
|
|
527
575
|
examples.forEach(([expected, actual]) => {
|
|
528
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
529
|
-
expect(
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
535
|
-
describe('leverageManagement()', () => {
|
|
536
|
-
const examples = [
|
|
537
|
-
[
|
|
538
|
-
[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],
|
|
539
|
-
[160, 220, 180, 190, true]
|
|
540
|
-
],
|
|
541
|
-
[
|
|
542
|
-
[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],
|
|
543
|
-
[160, 200, 180, 190, false]
|
|
544
|
-
],
|
|
545
|
-
];
|
|
546
|
-
examples.forEach(([expected, actual]) => {
|
|
547
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
548
|
-
expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
576
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
577
|
+
expect(aaveV3Encode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
|
|
549
578
|
});
|
|
550
579
|
});
|
|
551
580
|
});
|
|
552
|
-
|
|
553
|
-
describe('When testing strategySubService.exchangeEncode', () => {
|
|
554
|
-
describe('dca()', () => {
|
|
581
|
+
describe('closeOnPriceGeneric()', () => {
|
|
555
582
|
const examples = [
|
|
583
|
+
// Stop loss only (to debt)
|
|
556
584
|
[
|
|
557
585
|
[
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
['
|
|
586
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
587
|
+
true,
|
|
588
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
|
|
561
589
|
[
|
|
562
|
-
'
|
|
563
|
-
'
|
|
590
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
591
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
592
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
593
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
594
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
595
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
596
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
564
597
|
],
|
|
565
598
|
],
|
|
566
|
-
[
|
|
599
|
+
[
|
|
600
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
601
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
602
|
+
0,
|
|
603
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
604
|
+
1,
|
|
605
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
606
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
607
|
+
1500,
|
|
608
|
+
CloseToAssetType.DEBT,
|
|
609
|
+
0,
|
|
610
|
+
CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
|
|
611
|
+
]
|
|
567
612
|
],
|
|
613
|
+
// Take profit only (to collateral)
|
|
568
614
|
[
|
|
569
615
|
[
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
['
|
|
616
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
617
|
+
true,
|
|
618
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
573
619
|
[
|
|
574
|
-
'
|
|
575
|
-
'
|
|
620
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
621
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
622
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
623
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
624
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
625
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
626
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
576
627
|
],
|
|
577
628
|
],
|
|
578
|
-
[getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
|
|
579
|
-
],
|
|
580
|
-
];
|
|
581
|
-
examples.forEach(([expected, actual]) => {
|
|
582
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
583
|
-
expect(exchangeEncode.dca(...actual)).to.eql(expected);
|
|
584
|
-
});
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
describe('limitOrder()', () => {
|
|
588
|
-
const examples = [
|
|
589
|
-
[
|
|
590
|
-
[
|
|
591
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
592
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
593
|
-
'2131',
|
|
594
|
-
'0.53123',
|
|
595
|
-
'1696590921159',
|
|
596
|
-
`${OrderType.STOP_LOSS}`
|
|
597
|
-
],
|
|
598
629
|
[
|
|
630
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
599
631
|
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
600
|
-
|
|
601
|
-
'
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
632
|
+
0,
|
|
633
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
634
|
+
1,
|
|
635
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
636
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
637
|
+
0,
|
|
638
|
+
CloseToAssetType.DEBT,
|
|
639
|
+
5000,
|
|
640
|
+
CloseToAssetType.COLLATERAL, // takeProfitType
|
|
605
641
|
]
|
|
606
642
|
],
|
|
643
|
+
// Both stop loss and take profit with useOnBehalf
|
|
607
644
|
[
|
|
608
645
|
[
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
'
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
646
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
647
|
+
true,
|
|
648
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
649
|
+
[
|
|
650
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
651
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
652
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
653
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
654
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
655
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
656
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
657
|
+
],
|
|
615
658
|
],
|
|
616
659
|
[
|
|
617
|
-
|
|
618
|
-
web3Utils.toChecksumAddress(getAssetInfo('
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
660
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
661
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
662
|
+
2,
|
|
663
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
664
|
+
1,
|
|
665
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
666
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
667
|
+
1500,
|
|
668
|
+
CloseToAssetType.COLLATERAL,
|
|
669
|
+
4000,
|
|
670
|
+
CloseToAssetType.COLLATERAL, // takeProfitType
|
|
623
671
|
]
|
|
624
672
|
],
|
|
625
|
-
|
|
626
|
-
examples.forEach(([expected, actual]) => {
|
|
627
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
628
|
-
expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
|
|
629
|
-
});
|
|
630
|
-
});
|
|
631
|
-
});
|
|
632
|
-
});
|
|
633
|
-
describe('When testing strategySubService.sparkEncode', () => {
|
|
634
|
-
describe('leverageManagement()', () => {
|
|
635
|
-
const examples = [
|
|
636
|
-
[
|
|
637
|
-
'0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
|
|
638
|
-
[160, 220, 180, 190, true]
|
|
639
|
-
],
|
|
640
|
-
[
|
|
641
|
-
'0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
|
|
642
|
-
[160, 200, 180, 190, false]
|
|
643
|
-
],
|
|
644
|
-
];
|
|
645
|
-
examples.forEach(([expected, actual]) => {
|
|
646
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
647
|
-
expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
648
|
-
});
|
|
649
|
-
});
|
|
650
|
-
});
|
|
651
|
-
describe('closeToAsset()', () => {
|
|
652
|
-
const examples = [
|
|
673
|
+
// Stop loss only (to collateral) - CloseStrategyType.STOP_LOSS_IN_COLLATERAL
|
|
653
674
|
[
|
|
654
675
|
[
|
|
655
|
-
Bundles.MainnetIds.
|
|
676
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
656
677
|
true,
|
|
657
|
-
['
|
|
678
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
|
|
658
679
|
[
|
|
659
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
660
|
-
'
|
|
680
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
681
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
682
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
683
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
684
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
685
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
661
686
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
662
687
|
],
|
|
663
688
|
],
|
|
664
689
|
[
|
|
665
|
-
Bundles.MainnetIds.
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
690
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
691
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
692
|
+
0,
|
|
693
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
694
|
+
1,
|
|
695
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
696
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
697
|
+
1500,
|
|
698
|
+
CloseToAssetType.COLLATERAL,
|
|
699
|
+
0,
|
|
700
|
+
CloseToAssetType.DEBT, // takeProfitType (not used since price is 0)
|
|
673
701
|
]
|
|
674
702
|
],
|
|
703
|
+
// Take profit only (to debt) - CloseStrategyType.TAKE_PROFIT_IN_DEBT
|
|
675
704
|
[
|
|
676
705
|
[
|
|
677
|
-
Bundles.MainnetIds.
|
|
706
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
678
707
|
true,
|
|
679
|
-
['
|
|
708
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
680
709
|
[
|
|
681
|
-
'
|
|
682
|
-
'
|
|
710
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
711
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
712
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
713
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
714
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
715
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
683
716
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
684
717
|
],
|
|
685
718
|
],
|
|
686
719
|
[
|
|
687
|
-
Bundles.MainnetIds.
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
720
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
721
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
722
|
+
0,
|
|
723
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
724
|
+
1,
|
|
725
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
726
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
727
|
+
0,
|
|
728
|
+
CloseToAssetType.COLLATERAL,
|
|
729
|
+
5000,
|
|
730
|
+
CloseToAssetType.DEBT, // takeProfitType
|
|
731
|
+
]
|
|
732
|
+
],
|
|
733
|
+
// Take profit in collateral and stop loss in debt - CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
|
|
734
|
+
[
|
|
735
|
+
[
|
|
736
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
737
|
+
true,
|
|
738
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
739
|
+
[
|
|
740
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
741
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
742
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
743
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
744
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
745
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
746
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
747
|
+
],
|
|
748
|
+
],
|
|
749
|
+
[
|
|
750
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
751
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
752
|
+
2,
|
|
753
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
754
|
+
1,
|
|
755
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
756
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
757
|
+
1500,
|
|
758
|
+
CloseToAssetType.DEBT,
|
|
759
|
+
4000,
|
|
760
|
+
CloseToAssetType.COLLATERAL, // takeProfitType
|
|
761
|
+
]
|
|
762
|
+
],
|
|
763
|
+
// Both stop loss and take profit in debt - CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
|
|
764
|
+
[
|
|
765
|
+
[
|
|
766
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
767
|
+
true,
|
|
768
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
769
|
+
[
|
|
770
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
771
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
772
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
773
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
774
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
775
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
776
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
777
|
+
],
|
|
778
|
+
],
|
|
779
|
+
[
|
|
780
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
781
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
782
|
+
0,
|
|
783
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
784
|
+
1,
|
|
785
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
786
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
787
|
+
1500,
|
|
788
|
+
CloseToAssetType.DEBT,
|
|
789
|
+
4000,
|
|
790
|
+
CloseToAssetType.DEBT, // takeProfitType
|
|
791
|
+
]
|
|
792
|
+
],
|
|
793
|
+
// Take profit in debt and stop loss in collateral - CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
|
|
794
|
+
[
|
|
795
|
+
[
|
|
796
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
797
|
+
true,
|
|
798
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
799
|
+
[
|
|
800
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
801
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
802
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
803
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
804
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
805
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
806
|
+
'0x0000000000000000000000009876543210987654321098765432109876543210',
|
|
807
|
+
],
|
|
808
|
+
],
|
|
809
|
+
[
|
|
810
|
+
Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
|
|
811
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
812
|
+
0,
|
|
813
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
814
|
+
1,
|
|
815
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
816
|
+
web3Utils.toChecksumAddress('0x9876543210987654321098765432109876543210'),
|
|
817
|
+
1500,
|
|
818
|
+
CloseToAssetType.COLLATERAL,
|
|
819
|
+
4000,
|
|
820
|
+
CloseToAssetType.DEBT, // takeProfitType
|
|
821
|
+
]
|
|
822
|
+
],
|
|
823
|
+
];
|
|
824
|
+
examples.forEach(([expected, actual]) => {
|
|
825
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
826
|
+
expect(aaveV3Encode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
});
|
|
830
|
+
describe('collateralSwitch()', () => {
|
|
831
|
+
const examples = [
|
|
832
|
+
// WETH -> USDC, price 100000, state UNDER
|
|
833
|
+
[
|
|
834
|
+
[
|
|
835
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
836
|
+
false,
|
|
837
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
838
|
+
[
|
|
839
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
840
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
841
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
842
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
843
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
844
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
845
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
846
|
+
],
|
|
847
|
+
],
|
|
848
|
+
[
|
|
849
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
850
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
851
|
+
0,
|
|
852
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
853
|
+
1,
|
|
854
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
855
|
+
'10000000000000000000',
|
|
856
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
857
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
858
|
+
100000,
|
|
859
|
+
RatioState.UNDER,
|
|
860
|
+
]
|
|
861
|
+
],
|
|
862
|
+
// USDC -> WETH, price 0.00001, state OVER
|
|
863
|
+
[
|
|
864
|
+
[
|
|
865
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
866
|
+
false,
|
|
867
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000'],
|
|
868
|
+
[
|
|
869
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
870
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
871
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
872
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
873
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
874
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
875
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
876
|
+
],
|
|
877
|
+
],
|
|
878
|
+
[
|
|
879
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
880
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
881
|
+
1,
|
|
882
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
883
|
+
0,
|
|
884
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
885
|
+
MAXUINT,
|
|
886
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
887
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
888
|
+
0.00001,
|
|
889
|
+
RatioState.OVER,
|
|
890
|
+
]
|
|
891
|
+
],
|
|
892
|
+
// WETH -> WBTC, price 1, state UNDER
|
|
893
|
+
[
|
|
894
|
+
[
|
|
895
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
896
|
+
false,
|
|
897
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000001'],
|
|
898
|
+
[
|
|
899
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
900
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
901
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
902
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
903
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
904
|
+
'0x0000000000000000000000000000000000000000000000004563918244f40000',
|
|
905
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
906
|
+
],
|
|
907
|
+
],
|
|
908
|
+
[
|
|
909
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
910
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
911
|
+
0,
|
|
912
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
913
|
+
2,
|
|
914
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
915
|
+
'5000000000000000000',
|
|
916
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
917
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
918
|
+
1,
|
|
919
|
+
RatioState.UNDER,
|
|
920
|
+
]
|
|
921
|
+
],
|
|
922
|
+
];
|
|
923
|
+
examples.forEach(([expected, actual]) => {
|
|
924
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
925
|
+
expect(aaveV3Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
});
|
|
929
|
+
});
|
|
930
|
+
describe('When testing strategySubService.compoundV2Encode', () => {
|
|
931
|
+
describe('leverageManagement()', () => {
|
|
932
|
+
const examples = [
|
|
933
|
+
[
|
|
934
|
+
[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],
|
|
935
|
+
[160, 220, 180, 190, true]
|
|
936
|
+
],
|
|
937
|
+
[
|
|
938
|
+
[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],
|
|
939
|
+
[160, 200, 180, 190, false]
|
|
940
|
+
],
|
|
941
|
+
];
|
|
942
|
+
examples.forEach(([expected, actual]) => {
|
|
943
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
944
|
+
expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
945
|
+
});
|
|
946
|
+
});
|
|
947
|
+
});
|
|
948
|
+
});
|
|
949
|
+
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
950
|
+
describe('leverageManagement()', () => {
|
|
951
|
+
const examples = [
|
|
952
|
+
[
|
|
953
|
+
[
|
|
954
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
955
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
956
|
+
new Dec(160).mul(1e16).toString(),
|
|
957
|
+
new Dec(220).mul(1e16).toString(),
|
|
958
|
+
new Dec(180).mul(1e16).toString(),
|
|
959
|
+
new Dec(190).mul(1e16).toString(),
|
|
960
|
+
true, false,
|
|
961
|
+
],
|
|
962
|
+
[
|
|
963
|
+
web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
964
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
965
|
+
160, 220, 180, 190,
|
|
966
|
+
true, false,
|
|
967
|
+
]
|
|
968
|
+
],
|
|
969
|
+
[
|
|
970
|
+
[
|
|
971
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
972
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
973
|
+
new Dec(160).mul(1e16).toString(),
|
|
974
|
+
new Dec(210).mul(1e16).toString(),
|
|
975
|
+
new Dec(180).mul(1e16).toString(),
|
|
976
|
+
new Dec(190).mul(1e16).toString(),
|
|
977
|
+
false, true,
|
|
978
|
+
],
|
|
979
|
+
[
|
|
980
|
+
web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
|
|
981
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
982
|
+
160, 210, 180, 190,
|
|
983
|
+
false, true,
|
|
984
|
+
]
|
|
985
|
+
],
|
|
986
|
+
];
|
|
987
|
+
examples.forEach(([expected, actual]) => {
|
|
988
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
989
|
+
expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
|
|
990
|
+
});
|
|
991
|
+
});
|
|
992
|
+
});
|
|
993
|
+
describe('leverageManagementOnPrice()', () => {
|
|
994
|
+
const examples = [
|
|
995
|
+
[
|
|
996
|
+
[
|
|
997
|
+
Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
998
|
+
true,
|
|
999
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f07775030000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1000
|
+
[
|
|
1001
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
1002
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1003
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1004
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1005
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1006
|
+
'0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
|
|
1007
|
+
],
|
|
1008
|
+
],
|
|
1009
|
+
[
|
|
1010
|
+
Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
|
|
1011
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1012
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1013
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1014
|
+
200,
|
|
1015
|
+
2000,
|
|
1016
|
+
RatioState.UNDER,
|
|
1017
|
+
RatioState.UNDER,
|
|
1018
|
+
web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1019
|
+
],
|
|
1020
|
+
],
|
|
1021
|
+
[
|
|
1022
|
+
[
|
|
1023
|
+
Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
1024
|
+
true,
|
|
1025
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f077750300000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1026
|
+
[
|
|
1027
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
1028
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1029
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1030
|
+
'0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
|
|
1031
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1032
|
+
'0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
|
|
1033
|
+
],
|
|
1034
|
+
],
|
|
1035
|
+
[
|
|
1036
|
+
Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
|
|
1037
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1038
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1039
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1040
|
+
190,
|
|
1041
|
+
3000,
|
|
1042
|
+
RatioState.OVER,
|
|
1043
|
+
RatioState.OVER,
|
|
1044
|
+
web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1045
|
+
],
|
|
1046
|
+
]
|
|
1047
|
+
];
|
|
1048
|
+
examples.forEach(([expected, actual]) => {
|
|
1049
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1050
|
+
expect(compoundV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1051
|
+
});
|
|
1052
|
+
});
|
|
1053
|
+
});
|
|
1054
|
+
describe('closeOnPrice()', () => {
|
|
1055
|
+
const examples = [
|
|
1056
|
+
[
|
|
1057
|
+
[
|
|
1058
|
+
Bundles.MainnetIds.COMP_V3_SW_CLOSE,
|
|
1059
|
+
true,
|
|
1060
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1061
|
+
[
|
|
1062
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
1063
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1064
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1065
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1066
|
+
'0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
|
|
1067
|
+
],
|
|
1068
|
+
],
|
|
1069
|
+
[
|
|
1070
|
+
Bundles.MainnetIds.COMP_V3_SW_CLOSE,
|
|
1071
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1072
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1073
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1074
|
+
1500,
|
|
1075
|
+
CloseToAssetType.DEBT,
|
|
1076
|
+
4000,
|
|
1077
|
+
CloseToAssetType.DEBT,
|
|
1078
|
+
web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1079
|
+
],
|
|
1080
|
+
],
|
|
1081
|
+
[
|
|
1082
|
+
[
|
|
1083
|
+
Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
|
|
1084
|
+
true,
|
|
1085
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1086
|
+
[
|
|
1087
|
+
'0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
|
|
1088
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1089
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1090
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1091
|
+
'0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
|
|
1092
|
+
],
|
|
1093
|
+
],
|
|
1094
|
+
[
|
|
1095
|
+
Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
|
|
1096
|
+
web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1097
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1098
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1099
|
+
0,
|
|
1100
|
+
CloseToAssetType.DEBT,
|
|
1101
|
+
5000,
|
|
1102
|
+
CloseToAssetType.COLLATERAL,
|
|
1103
|
+
web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1104
|
+
],
|
|
1105
|
+
]
|
|
1106
|
+
];
|
|
1107
|
+
examples.forEach(([expected, actual]) => {
|
|
1108
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1109
|
+
expect(compoundV3Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
1110
|
+
});
|
|
1111
|
+
});
|
|
1112
|
+
});
|
|
1113
|
+
});
|
|
1114
|
+
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
1115
|
+
describe('leverageManagement()', () => {
|
|
1116
|
+
const examples = [
|
|
1117
|
+
[
|
|
1118
|
+
[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],
|
|
1119
|
+
[160, 220, 180, 190, true]
|
|
1120
|
+
],
|
|
1121
|
+
[
|
|
1122
|
+
[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],
|
|
1123
|
+
[160, 200, 180, 190, false]
|
|
1124
|
+
],
|
|
1125
|
+
];
|
|
1126
|
+
examples.forEach(([expected, actual]) => {
|
|
1127
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1128
|
+
expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1129
|
+
});
|
|
1130
|
+
});
|
|
1131
|
+
});
|
|
1132
|
+
});
|
|
1133
|
+
describe('When testing strategySubService.exchangeEncode', () => {
|
|
1134
|
+
describe('dca()', () => {
|
|
1135
|
+
const examples = [
|
|
1136
|
+
[
|
|
1137
|
+
[
|
|
1138
|
+
Strategies.ArbitrumIds.EXCHANGE_DCA,
|
|
1139
|
+
false,
|
|
1140
|
+
['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
|
|
1141
|
+
[
|
|
1142
|
+
'0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
|
|
1143
|
+
'0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
|
|
1144
|
+
],
|
|
1145
|
+
],
|
|
1146
|
+
[getAssetInfo('DAI', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, ChainId.Arbitrum]
|
|
1147
|
+
],
|
|
1148
|
+
[
|
|
1149
|
+
[
|
|
1150
|
+
Strategies.MainnetIds.EXCHANGE_DCA,
|
|
1151
|
+
false,
|
|
1152
|
+
['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
|
|
1153
|
+
[
|
|
1154
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
|
|
1155
|
+
'0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
|
|
1156
|
+
],
|
|
1157
|
+
],
|
|
1158
|
+
[getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
|
|
1159
|
+
],
|
|
1160
|
+
];
|
|
1161
|
+
examples.forEach(([expected, actual]) => {
|
|
1162
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1163
|
+
expect(exchangeEncode.dca(...actual)).to.eql(expected);
|
|
1164
|
+
});
|
|
1165
|
+
});
|
|
1166
|
+
});
|
|
1167
|
+
describe('limitOrder()', () => {
|
|
1168
|
+
const examples = [
|
|
1169
|
+
[
|
|
1170
|
+
[
|
|
1171
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1172
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1173
|
+
'2131',
|
|
1174
|
+
'0.53123',
|
|
1175
|
+
'1696590921159',
|
|
1176
|
+
`${OrderType.STOP_LOSS}`
|
|
1177
|
+
],
|
|
1178
|
+
[
|
|
1179
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1180
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1181
|
+
'2131',
|
|
1182
|
+
'0.53123',
|
|
1183
|
+
1696590921159,
|
|
1184
|
+
OrderType.STOP_LOSS
|
|
695
1185
|
]
|
|
696
|
-
]
|
|
1186
|
+
],
|
|
1187
|
+
[
|
|
1188
|
+
[
|
|
1189
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1190
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1191
|
+
'2131',
|
|
1192
|
+
'0.43123',
|
|
1193
|
+
'1646590921159',
|
|
1194
|
+
`${OrderType.TAKE_PROFIT}`
|
|
1195
|
+
],
|
|
1196
|
+
[
|
|
1197
|
+
web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
|
|
1198
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1199
|
+
'2131',
|
|
1200
|
+
'0.43123',
|
|
1201
|
+
1646590921159,
|
|
1202
|
+
OrderType.TAKE_PROFIT
|
|
1203
|
+
]
|
|
1204
|
+
],
|
|
697
1205
|
];
|
|
698
1206
|
examples.forEach(([expected, actual]) => {
|
|
699
1207
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
700
|
-
expect(
|
|
1208
|
+
expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
|
|
701
1209
|
});
|
|
702
1210
|
});
|
|
703
1211
|
});
|
|
@@ -875,26 +1383,66 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
875
1383
|
});
|
|
876
1384
|
});
|
|
877
1385
|
});
|
|
1386
|
+
describe('closeOnPrice()', () => {
|
|
1387
|
+
const examples = [
|
|
1388
|
+
[
|
|
1389
|
+
[
|
|
1390
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1391
|
+
true,
|
|
1392
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1393
|
+
[
|
|
1394
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1395
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1396
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1397
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1398
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1399
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1400
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1401
|
+
],
|
|
1402
|
+
],
|
|
1403
|
+
[
|
|
1404
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1405
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1406
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1407
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1408
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1409
|
+
'945000000000000000',
|
|
1410
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1411
|
+
1500,
|
|
1412
|
+
CloseToAssetType.DEBT,
|
|
1413
|
+
4000,
|
|
1414
|
+
CloseToAssetType.COLLATERAL
|
|
1415
|
+
]
|
|
1416
|
+
],
|
|
1417
|
+
];
|
|
1418
|
+
examples.forEach(([expected, actual]) => {
|
|
1419
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1420
|
+
expect(morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
|
|
1421
|
+
});
|
|
1422
|
+
});
|
|
1423
|
+
});
|
|
878
1424
|
});
|
|
879
1425
|
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
880
1426
|
describe('leverageManagement()', () => {
|
|
881
1427
|
const examples = [
|
|
882
1428
|
[
|
|
883
|
-
'
|
|
1429
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
884
1430
|
[
|
|
885
1431
|
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
886
1432
|
web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
887
1433
|
160, 220, 180, 190,
|
|
888
|
-
true
|
|
1434
|
+
true,
|
|
1435
|
+
false,
|
|
889
1436
|
],
|
|
890
1437
|
],
|
|
891
1438
|
[
|
|
892
|
-
'
|
|
1439
|
+
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
893
1440
|
[
|
|
894
1441
|
web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
895
1442
|
web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
|
|
896
1443
|
160, 220, 180, 110,
|
|
897
|
-
false
|
|
1444
|
+
false,
|
|
1445
|
+
false,
|
|
898
1446
|
],
|
|
899
1447
|
],
|
|
900
1448
|
];
|
|
@@ -905,4 +1453,332 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
905
1453
|
});
|
|
906
1454
|
});
|
|
907
1455
|
});
|
|
1456
|
+
describe('When testing strategySubService.sparkEncode', () => {
|
|
1457
|
+
describe('leverageManagement()', () => {
|
|
1458
|
+
const examples = [
|
|
1459
|
+
[
|
|
1460
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1461
|
+
[140, 240, 210, 190, true]
|
|
1462
|
+
],
|
|
1463
|
+
[
|
|
1464
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1465
|
+
[137, 184, 289, 246, false]
|
|
1466
|
+
]
|
|
1467
|
+
];
|
|
1468
|
+
examples.forEach(([expected, actual]) => {
|
|
1469
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1470
|
+
expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1471
|
+
});
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
1474
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1475
|
+
const examples = [
|
|
1476
|
+
[
|
|
1477
|
+
[
|
|
1478
|
+
Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
|
|
1479
|
+
true,
|
|
1480
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1481
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1482
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1483
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1484
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1485
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1486
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1487
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1488
|
+
],
|
|
1489
|
+
],
|
|
1490
|
+
[
|
|
1491
|
+
59,
|
|
1492
|
+
true,
|
|
1493
|
+
{
|
|
1494
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1495
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1496
|
+
price: 2500,
|
|
1497
|
+
ratioState: RatioState.UNDER,
|
|
1498
|
+
},
|
|
1499
|
+
{
|
|
1500
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1501
|
+
collAssetId: 0,
|
|
1502
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1503
|
+
debtAssetId: 1,
|
|
1504
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1505
|
+
targetRatio: 200,
|
|
1506
|
+
},
|
|
1507
|
+
]
|
|
1508
|
+
],
|
|
1509
|
+
[
|
|
1510
|
+
[
|
|
1511
|
+
Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
|
|
1512
|
+
true,
|
|
1513
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1514
|
+
[
|
|
1515
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1516
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1517
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1518
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1519
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1520
|
+
'0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
1521
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1522
|
+
]
|
|
1523
|
+
],
|
|
1524
|
+
[
|
|
1525
|
+
60,
|
|
1526
|
+
true,
|
|
1527
|
+
{
|
|
1528
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1529
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1530
|
+
price: 45000,
|
|
1531
|
+
ratioState: RatioState.OVER,
|
|
1532
|
+
},
|
|
1533
|
+
{
|
|
1534
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1535
|
+
collAssetId: 2,
|
|
1536
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1537
|
+
debtAssetId: 4,
|
|
1538
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1539
|
+
targetRatio: 250,
|
|
1540
|
+
},
|
|
1541
|
+
]
|
|
1542
|
+
]
|
|
1543
|
+
];
|
|
1544
|
+
examples.forEach(([expected, actual]) => {
|
|
1545
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1546
|
+
expect(sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1547
|
+
});
|
|
1548
|
+
});
|
|
1549
|
+
});
|
|
1550
|
+
describe('closeOnPrice()', () => {
|
|
1551
|
+
const examples = [
|
|
1552
|
+
[
|
|
1553
|
+
[
|
|
1554
|
+
Bundles.MainnetIds.SPARK_CLOSE,
|
|
1555
|
+
true,
|
|
1556
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
|
|
1557
|
+
[
|
|
1558
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1559
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1560
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1561
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1562
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1563
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1564
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1565
|
+
]
|
|
1566
|
+
],
|
|
1567
|
+
[
|
|
1568
|
+
57,
|
|
1569
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1570
|
+
2,
|
|
1571
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1572
|
+
4,
|
|
1573
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1574
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1575
|
+
40000,
|
|
1576
|
+
CloseToAssetType.DEBT,
|
|
1577
|
+
60000,
|
|
1578
|
+
CloseToAssetType.COLLATERAL,
|
|
1579
|
+
]
|
|
1580
|
+
],
|
|
1581
|
+
];
|
|
1582
|
+
examples.forEach(([expected, actual]) => {
|
|
1583
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1584
|
+
expect(sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1585
|
+
});
|
|
1586
|
+
});
|
|
1587
|
+
});
|
|
1588
|
+
describe('collateralSwitch()', () => {
|
|
1589
|
+
const examples = [
|
|
1590
|
+
// WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
|
|
1591
|
+
[
|
|
1592
|
+
[
|
|
1593
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1594
|
+
false,
|
|
1595
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
|
|
1596
|
+
[
|
|
1597
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1598
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1599
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
1600
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
1601
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1602
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1603
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1604
|
+
],
|
|
1605
|
+
],
|
|
1606
|
+
[
|
|
1607
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1608
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1609
|
+
0,
|
|
1610
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1611
|
+
7,
|
|
1612
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1613
|
+
'10000000000000000000',
|
|
1614
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1615
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1616
|
+
0.025,
|
|
1617
|
+
RatioState.UNDER,
|
|
1618
|
+
]
|
|
1619
|
+
],
|
|
1620
|
+
// cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
|
|
1621
|
+
[
|
|
1622
|
+
[
|
|
1623
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1624
|
+
false,
|
|
1625
|
+
['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1626
|
+
[
|
|
1627
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
1628
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
1629
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1630
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1631
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1632
|
+
'0x0000000000000000000000000000000000000000000000000000000005f5e100',
|
|
1633
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1634
|
+
],
|
|
1635
|
+
],
|
|
1636
|
+
[
|
|
1637
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1638
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1639
|
+
7,
|
|
1640
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1641
|
+
0,
|
|
1642
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1643
|
+
'100000000',
|
|
1644
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1645
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1646
|
+
25,
|
|
1647
|
+
RatioState.UNDER,
|
|
1648
|
+
]
|
|
1649
|
+
],
|
|
1650
|
+
// cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
|
|
1651
|
+
[
|
|
1652
|
+
[
|
|
1653
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1654
|
+
false,
|
|
1655
|
+
['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1656
|
+
[
|
|
1657
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
1658
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
1659
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1660
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1661
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1662
|
+
'0x0000000000000000000000000000000000000000000000000000000005f5e100',
|
|
1663
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1664
|
+
],
|
|
1665
|
+
],
|
|
1666
|
+
[
|
|
1667
|
+
Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
|
|
1668
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1669
|
+
7,
|
|
1670
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1671
|
+
0,
|
|
1672
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1673
|
+
'100000000',
|
|
1674
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
1675
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1676
|
+
40,
|
|
1677
|
+
RatioState.OVER,
|
|
1678
|
+
]
|
|
1679
|
+
],
|
|
1680
|
+
];
|
|
1681
|
+
examples.forEach(([expected, actual]) => {
|
|
1682
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1683
|
+
expect(sparkEncode.collateralSwitch(...actual)).to.eql(expected);
|
|
1684
|
+
});
|
|
1685
|
+
});
|
|
1686
|
+
});
|
|
1687
|
+
});
|
|
1688
|
+
describe('When testing strategySubService.aaveV4Encode', () => {
|
|
1689
|
+
describe('leverageManagement()', () => {
|
|
1690
|
+
const examples = [
|
|
1691
|
+
[
|
|
1692
|
+
[1, true, ["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1693
|
+
[
|
|
1694
|
+
1,
|
|
1695
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1696
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1697
|
+
RatioState.UNDER,
|
|
1698
|
+
150,
|
|
1699
|
+
120,
|
|
1700
|
+
]
|
|
1701
|
+
]
|
|
1702
|
+
];
|
|
1703
|
+
examples.forEach(([expected, actual]) => {
|
|
1704
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1705
|
+
expect(aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1706
|
+
});
|
|
1707
|
+
});
|
|
1708
|
+
});
|
|
1709
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1710
|
+
const examples = [
|
|
1711
|
+
[
|
|
1712
|
+
[2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1713
|
+
[
|
|
1714
|
+
2,
|
|
1715
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1716
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1717
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1718
|
+
10,
|
|
1719
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1720
|
+
20,
|
|
1721
|
+
160,
|
|
1722
|
+
'1500',
|
|
1723
|
+
RatioState.OVER,
|
|
1724
|
+
RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1725
|
+
]
|
|
1726
|
+
]
|
|
1727
|
+
];
|
|
1728
|
+
examples.forEach(([expected, actual]) => {
|
|
1729
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1730
|
+
expect(aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1731
|
+
});
|
|
1732
|
+
});
|
|
1733
|
+
});
|
|
1734
|
+
describe('closeOnPrice()', () => {
|
|
1735
|
+
const examples = [
|
|
1736
|
+
[
|
|
1737
|
+
[3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1738
|
+
[
|
|
1739
|
+
3,
|
|
1740
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1741
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1742
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1743
|
+
10,
|
|
1744
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1745
|
+
20,
|
|
1746
|
+
'1400',
|
|
1747
|
+
CloseToAssetType.DEBT,
|
|
1748
|
+
'0',
|
|
1749
|
+
CloseToAssetType.COLLATERAL
|
|
1750
|
+
]
|
|
1751
|
+
]
|
|
1752
|
+
];
|
|
1753
|
+
examples.forEach(([expected, actual]) => {
|
|
1754
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1755
|
+
expect(aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
1756
|
+
});
|
|
1757
|
+
});
|
|
1758
|
+
});
|
|
1759
|
+
describe('collateralSwitch()', () => {
|
|
1760
|
+
const examples = [
|
|
1761
|
+
[
|
|
1762
|
+
[4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1763
|
+
[
|
|
1764
|
+
4,
|
|
1765
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1766
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1767
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1768
|
+
10,
|
|
1769
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1770
|
+
20,
|
|
1771
|
+
'1000000000000000000',
|
|
1772
|
+
'1500',
|
|
1773
|
+
RatioState.UNDER,
|
|
1774
|
+
]
|
|
1775
|
+
]
|
|
1776
|
+
];
|
|
1777
|
+
examples.forEach(([expected, actual]) => {
|
|
1778
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1779
|
+
expect(aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1780
|
+
});
|
|
1781
|
+
});
|
|
1782
|
+
});
|
|
1783
|
+
});
|
|
908
1784
|
});
|