@defisaver/automation-sdk 3.3.21-coll-switch-generic-dev → 3.3.21-instant-twap-close-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/constants/index.js +10 -40
- package/cjs/services/strategiesService.js +21 -16
- package/cjs/services/strategiesService.test.js +62 -94
- package/cjs/services/strategySubService.d.ts +1 -2
- package/cjs/services/strategySubService.js +7 -12
- package/cjs/services/strategySubService.test.js +111 -107
- package/cjs/services/subDataService.d.ts +12 -22
- package/cjs/services/subDataService.js +35 -61
- package/cjs/services/subDataService.test.js +70 -139
- package/cjs/types/enums.d.ts +9 -15
- package/cjs/types/enums.js +4 -10
- package/esm/constants/index.js +10 -40
- package/esm/services/strategiesService.js +21 -16
- package/esm/services/strategiesService.test.js +63 -95
- package/esm/services/strategySubService.d.ts +1 -2
- package/esm/services/strategySubService.js +7 -12
- package/esm/services/strategySubService.test.js +111 -107
- package/esm/services/subDataService.d.ts +12 -22
- package/esm/services/subDataService.js +33 -59
- package/esm/services/subDataService.test.js +70 -139
- package/esm/types/enums.d.ts +9 -15
- package/esm/types/enums.js +4 -10
- package/package.json +1 -1
- package/src/constants/index.ts +10 -40
- package/src/services/strategiesService.test.ts +78 -106
- package/src/services/strategiesService.ts +27 -16
- package/src/services/strategySubService.test.ts +125 -126
- package/src/services/strategySubService.ts +18 -38
- package/src/services/subDataService.test.ts +98 -149
- package/src/services/subDataService.ts +48 -88
- package/src/types/enums.ts +4 -10
|
@@ -424,52 +424,33 @@ export const aaveV3Encode = {
|
|
|
424
424
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
425
425
|
},
|
|
426
426
|
|
|
427
|
-
|
|
428
|
-
strategyOrBundleId: number,
|
|
429
|
-
fromAsset: EthereumAddress,
|
|
430
|
-
fromAssetId: number,
|
|
431
|
-
toAsset: EthereumAddress,
|
|
432
|
-
toAssetId: number,
|
|
433
|
-
marketAddr: EthereumAddress,
|
|
434
|
-
amountToSwitch: string,
|
|
435
|
-
baseTokenAddress: EthereumAddress,
|
|
436
|
-
quoteTokenAddress: EthereumAddress,
|
|
437
|
-
price: number,
|
|
438
|
-
state: RatioState,
|
|
439
|
-
) {
|
|
440
|
-
const isBundle = false;
|
|
441
|
-
|
|
442
|
-
const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
443
|
-
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
444
|
-
|
|
445
|
-
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
446
|
-
},
|
|
447
|
-
|
|
448
|
-
collateralSwitchGeneric(
|
|
427
|
+
instantCloseOnPriceGeneric(
|
|
449
428
|
strategyOrBundleId: number,
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
429
|
+
collAsset: EthereumAddress,
|
|
430
|
+
collAssetId: number,
|
|
431
|
+
debtAsset: EthereumAddress,
|
|
432
|
+
debtAssetId: number,
|
|
454
433
|
marketAddr: EthereumAddress,
|
|
455
|
-
amountToSwitch: string,
|
|
456
434
|
user: EthereumAddress,
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
435
|
+
tsi: string,
|
|
436
|
+
slippage: string,
|
|
437
|
+
stopLossPrice: number = 0,
|
|
438
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
439
|
+
takeProfitPrice: number = 0,
|
|
440
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
461
441
|
) {
|
|
462
|
-
const isBundle =
|
|
442
|
+
const isBundle = true;
|
|
443
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
463
444
|
|
|
464
|
-
const subDataEncoded = subDataService.
|
|
465
|
-
|
|
445
|
+
const subDataEncoded = subDataService.aaveV3InstantCloseGenericSubData.encode(
|
|
446
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage,
|
|
466
447
|
);
|
|
467
|
-
const triggerDataEncoded = triggerService.
|
|
448
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
468
449
|
|
|
469
450
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
470
451
|
},
|
|
471
452
|
|
|
472
|
-
|
|
453
|
+
collateralSwitch(
|
|
473
454
|
strategyOrBundleId: number,
|
|
474
455
|
fromAsset: EthereumAddress,
|
|
475
456
|
fromAssetId: number,
|
|
@@ -477,7 +458,6 @@ export const aaveV3Encode = {
|
|
|
477
458
|
toAssetId: number,
|
|
478
459
|
marketAddr: EthereumAddress,
|
|
479
460
|
amountToSwitch: string,
|
|
480
|
-
user: EthereumAddress,
|
|
481
461
|
baseTokenAddress: EthereumAddress,
|
|
482
462
|
quoteTokenAddress: EthereumAddress,
|
|
483
463
|
price: number,
|
|
@@ -485,7 +465,7 @@ export const aaveV3Encode = {
|
|
|
485
465
|
) {
|
|
486
466
|
const isBundle = false;
|
|
487
467
|
|
|
488
|
-
const subDataEncoded = subDataService.
|
|
468
|
+
const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
489
469
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
490
470
|
|
|
491
471
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
@@ -549,155 +549,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
549
549
|
});
|
|
550
550
|
});
|
|
551
551
|
|
|
552
|
-
describe('When testing subDataService.aaveV3DebtSwitchSubData', () => {
|
|
553
|
-
describe('encode()', () => {
|
|
554
|
-
const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress]]> = [
|
|
555
|
-
// USDC -> DAI
|
|
556
|
-
[
|
|
557
|
-
[
|
|
558
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
559
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
560
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
561
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
562
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
563
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
564
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
565
|
-
],
|
|
566
|
-
[
|
|
567
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
568
|
-
1,
|
|
569
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
570
|
-
3,
|
|
571
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
572
|
-
'10000000000000000000', // 10 tokens
|
|
573
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
574
|
-
]
|
|
575
|
-
],
|
|
576
|
-
// DAI -> USDC (MaxUint256)
|
|
577
|
-
[
|
|
578
|
-
[
|
|
579
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
580
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
581
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
582
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
583
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
584
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
585
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
586
|
-
],
|
|
587
|
-
[
|
|
588
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
589
|
-
3,
|
|
590
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
591
|
-
1,
|
|
592
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
593
|
-
MAXUINT, // MaxUint256
|
|
594
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
595
|
-
]
|
|
596
|
-
],
|
|
597
|
-
];
|
|
598
|
-
|
|
599
|
-
examples.forEach(([expected, actual]) => {
|
|
600
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
601
|
-
expect(subDataService.aaveV3DebtSwitchSubData.encode(...actual)).to.eql(expected);
|
|
602
|
-
});
|
|
603
|
-
});
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
describe('decode()', () => {
|
|
607
|
-
const examples: Array<[{ fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress }, SubData]> = [
|
|
608
|
-
// USDC -> DAI
|
|
609
|
-
[
|
|
610
|
-
{
|
|
611
|
-
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
612
|
-
fromAssetId: 1,
|
|
613
|
-
toAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
614
|
-
toAssetId: 3,
|
|
615
|
-
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
616
|
-
amountToSwitch: '10000000000000000000',
|
|
617
|
-
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
618
|
-
},
|
|
619
|
-
[
|
|
620
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
621
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
622
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
623
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
624
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
625
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
626
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
627
|
-
],
|
|
628
|
-
],
|
|
629
|
-
// DAI -> USDC (MaxUint256)
|
|
630
|
-
[
|
|
631
|
-
{
|
|
632
|
-
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
633
|
-
fromAssetId: 3,
|
|
634
|
-
toAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
635
|
-
toAssetId: 1,
|
|
636
|
-
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
637
|
-
amountToSwitch: MAXUINT,
|
|
638
|
-
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
639
|
-
},
|
|
640
|
-
[
|
|
641
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
642
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
643
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
644
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
645
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
646
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
647
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
648
|
-
],
|
|
649
|
-
],
|
|
650
|
-
];
|
|
651
|
-
|
|
652
|
-
examples.forEach(([expected, actual]) => {
|
|
653
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
654
|
-
expect(subDataService.aaveV3DebtSwitchSubData.decode(actual)).to.eql(expected);
|
|
655
|
-
});
|
|
656
|
-
});
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
describe('When testing subDataService.aaveV3GenericFLCollateralSwitchSubData', () => {
|
|
661
|
-
const fromAsset = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
|
|
662
|
-
const toAsset = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
|
|
663
|
-
const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
664
|
-
const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
|
|
665
|
-
const examples = [
|
|
666
|
-
['10000000000000000000', '0x0000000000000000000000000000000000000000000000008ac7230489e80000'],
|
|
667
|
-
[MAXUINT, '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
|
|
668
|
-
];
|
|
669
|
-
|
|
670
|
-
examples.forEach(([amountToSwitch, encodedAmount]) => {
|
|
671
|
-
const subData: SubData = [
|
|
672
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
673
|
-
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
674
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
675
|
-
'0x000000000000000000000000000000000000000000000000000000000000ffff',
|
|
676
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
677
|
-
encodedAmount,
|
|
678
|
-
'0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
|
|
679
|
-
];
|
|
680
|
-
|
|
681
|
-
it(`encode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
|
|
682
|
-
expect(subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(
|
|
683
|
-
fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user,
|
|
684
|
-
)).to.eql(subData);
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
it(`decode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
|
|
688
|
-
expect(subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subData)).to.eql({
|
|
689
|
-
fromAsset,
|
|
690
|
-
fromAssetId: 256,
|
|
691
|
-
toAsset,
|
|
692
|
-
toAssetId: 65535,
|
|
693
|
-
marketAddr,
|
|
694
|
-
amountToSwitch,
|
|
695
|
-
user,
|
|
696
|
-
});
|
|
697
|
-
});
|
|
698
|
-
});
|
|
699
|
-
});
|
|
700
|
-
|
|
701
552
|
describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
|
|
702
553
|
describe('encode()', () => {
|
|
703
554
|
const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean]]> = [
|
|
@@ -2644,6 +2495,104 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2644
2495
|
});
|
|
2645
2496
|
});
|
|
2646
2497
|
});
|
|
2498
|
+
|
|
2499
|
+
describe("When testing subDataService.aaveV3InstantCloseGenericSubData", () => {
|
|
2500
|
+
const WETH = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
|
|
2501
|
+
const USDC = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
|
|
2502
|
+
const MARKET = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
2503
|
+
const USER = web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890');
|
|
2504
|
+
|
|
2505
|
+
const examples: Array<
|
|
2506
|
+
[
|
|
2507
|
+
string[],
|
|
2508
|
+
[
|
|
2509
|
+
collAsset: EthereumAddress,
|
|
2510
|
+
collAssetId: number,
|
|
2511
|
+
debtAsset: EthereumAddress,
|
|
2512
|
+
debtAssetId: number,
|
|
2513
|
+
closeType: CloseStrategyType,
|
|
2514
|
+
marketAddr: EthereumAddress,
|
|
2515
|
+
user: EthereumAddress,
|
|
2516
|
+
tsi: string,
|
|
2517
|
+
slippage: string
|
|
2518
|
+
]
|
|
2519
|
+
]
|
|
2520
|
+
> = [
|
|
2521
|
+
// TAKE_PROFIT_IN_COLLATERAL, zero tsi and slippage
|
|
2522
|
+
[
|
|
2523
|
+
[
|
|
2524
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2525
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2526
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2527
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2528
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2529
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2530
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2531
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2532
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2533
|
+
],
|
|
2534
|
+
[WETH, 0, USDC, 1, CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL, MARKET, USER, '0', '0'],
|
|
2535
|
+
],
|
|
2536
|
+
// STOP_LOSS_IN_DEBT
|
|
2537
|
+
[
|
|
2538
|
+
[
|
|
2539
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2540
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2541
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2542
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2543
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
2544
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2545
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2546
|
+
'0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
|
2547
|
+
'0x000000000000000000000000000000000000000000000000002386f26fc10000',
|
|
2548
|
+
],
|
|
2549
|
+
[WETH, 0, USDC, 1, CloseStrategyType.STOP_LOSS_IN_DEBT, MARKET, USER, '1000000000000000000', '10000000000000000'],
|
|
2550
|
+
],
|
|
2551
|
+
// TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, asset ids above uint8 range
|
|
2552
|
+
[
|
|
2553
|
+
[
|
|
2554
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2555
|
+
'0x000000000000000000000000000000000000000000000000000000000000012c',
|
|
2556
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2557
|
+
'0x0000000000000000000000000000000000000000000000000000000000000190',
|
|
2558
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
2559
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2560
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2561
|
+
'0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
|
|
2562
|
+
'0x0000000000000000000000000000000000000000000000000011c37937e08000',
|
|
2563
|
+
],
|
|
2564
|
+
[WETH, 300, USDC, 400, CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, MARKET, USER, '50000000000000000', '5000000000000000'],
|
|
2565
|
+
],
|
|
2566
|
+
];
|
|
2567
|
+
|
|
2568
|
+
describe("encode()", () => {
|
|
2569
|
+
examples.forEach(([expected, actual]) => {
|
|
2570
|
+
it(`Given ${JSON.stringify(
|
|
2571
|
+
actual
|
|
2572
|
+
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2573
|
+
expect(
|
|
2574
|
+
subDataService.aaveV3InstantCloseGenericSubData.encode(...actual)
|
|
2575
|
+
).to.eql(expected);
|
|
2576
|
+
});
|
|
2577
|
+
});
|
|
2578
|
+
});
|
|
2579
|
+
|
|
2580
|
+
describe("decode()", () => {
|
|
2581
|
+
examples.forEach(([encoded, [collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage]]) => {
|
|
2582
|
+
const expected = {
|
|
2583
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner: user, tsi, slippage,
|
|
2584
|
+
};
|
|
2585
|
+
|
|
2586
|
+
it(`Given ${JSON.stringify(
|
|
2587
|
+
encoded
|
|
2588
|
+
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2589
|
+
expect(
|
|
2590
|
+
subDataService.aaveV3InstantCloseGenericSubData.decode(encoded)
|
|
2591
|
+
).to.eql(expected);
|
|
2592
|
+
});
|
|
2593
|
+
});
|
|
2594
|
+
});
|
|
2595
|
+
});
|
|
2647
2596
|
describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
|
|
2648
2597
|
describe('encode()', () => {
|
|
2649
2598
|
const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number]] > =
|
|
@@ -687,106 +687,68 @@ export const aaveV3CloseGenericSubData = {
|
|
|
687
687
|
};
|
|
688
688
|
},
|
|
689
689
|
};
|
|
690
|
-
export const
|
|
690
|
+
export const aaveV3InstantCloseGenericSubData = {
|
|
691
691
|
encode(
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
amountToSwitch: string,
|
|
698
|
-
useOnBehalf: boolean = false,
|
|
699
|
-
): SubData {
|
|
700
|
-
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
701
|
-
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
702
|
-
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
703
|
-
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
704
|
-
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
705
|
-
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
706
|
-
const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
|
|
707
|
-
|
|
708
|
-
return [
|
|
709
|
-
encodedFromAsset,
|
|
710
|
-
encodedFromAssetId,
|
|
711
|
-
encodedToAsset,
|
|
712
|
-
encodedToAssetId,
|
|
713
|
-
encodedMarketAddr,
|
|
714
|
-
encodedAmountToSwitch,
|
|
715
|
-
encodedUseOnBehalf,
|
|
716
|
-
];
|
|
717
|
-
},
|
|
718
|
-
decode(subData: SubData): {
|
|
719
|
-
fromAsset: EthereumAddress,
|
|
720
|
-
fromAssetId: number,
|
|
721
|
-
toAsset: EthereumAddress,
|
|
722
|
-
toAssetId: number,
|
|
723
|
-
marketAddr: EthereumAddress,
|
|
724
|
-
amountToSwitch: string,
|
|
725
|
-
} {
|
|
726
|
-
const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
727
|
-
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
728
|
-
const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
729
|
-
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
730
|
-
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
731
|
-
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
732
|
-
|
|
733
|
-
return {
|
|
734
|
-
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
|
|
735
|
-
};
|
|
736
|
-
},
|
|
737
|
-
};
|
|
738
|
-
export const aaveV3GenericFLCollateralSwitchSubData = {
|
|
739
|
-
encode(
|
|
740
|
-
fromAsset: EthereumAddress,
|
|
741
|
-
fromAssetId: number,
|
|
742
|
-
toAsset: EthereumAddress,
|
|
743
|
-
toAssetId: number,
|
|
692
|
+
collAsset: EthereumAddress,
|
|
693
|
+
collAssetId: number,
|
|
694
|
+
debtAsset: EthereumAddress,
|
|
695
|
+
debtAssetId: number,
|
|
696
|
+
closeType: CloseStrategyType,
|
|
744
697
|
marketAddr: EthereumAddress,
|
|
745
|
-
amountToSwitch: string,
|
|
746
698
|
user: EthereumAddress,
|
|
699
|
+
tsi: string,
|
|
700
|
+
slippage: string,
|
|
747
701
|
): SubData {
|
|
748
|
-
const
|
|
749
|
-
const
|
|
750
|
-
const
|
|
751
|
-
const
|
|
752
|
-
const
|
|
753
|
-
const
|
|
702
|
+
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
703
|
+
const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
|
|
704
|
+
const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
|
|
705
|
+
const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
|
|
706
|
+
const encodedCloseType = AbiCoder.encodeParameter('uint8', closeType);
|
|
707
|
+
const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
|
|
754
708
|
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
709
|
+
const encodedTsi = AbiCoder.encodeParameter('uint256', tsi);
|
|
710
|
+
const encodedSlippage = AbiCoder.encodeParameter('uint256', slippage);
|
|
755
711
|
|
|
756
712
|
return [
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
713
|
+
encodedColl,
|
|
714
|
+
encodedCollId,
|
|
715
|
+
encodedDebt,
|
|
716
|
+
encodedDebtId,
|
|
717
|
+
encodedCloseType,
|
|
718
|
+
encodedMarket,
|
|
763
719
|
encodedUser,
|
|
720
|
+
encodedTsi,
|
|
721
|
+
encodedSlippage,
|
|
764
722
|
];
|
|
765
723
|
},
|
|
724
|
+
|
|
766
725
|
decode(subData: SubData): {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
726
|
+
collAsset: EthereumAddress,
|
|
727
|
+
collAssetId: number,
|
|
728
|
+
debtAsset: EthereumAddress,
|
|
729
|
+
debtAssetId: number,
|
|
730
|
+
closeType: CloseStrategyType,
|
|
771
731
|
marketAddr: EthereumAddress,
|
|
772
|
-
|
|
773
|
-
|
|
732
|
+
owner: EthereumAddress,
|
|
733
|
+
tsi: string,
|
|
734
|
+
slippage: string,
|
|
774
735
|
} {
|
|
775
|
-
const
|
|
776
|
-
const
|
|
777
|
-
const
|
|
778
|
-
const
|
|
779
|
-
const
|
|
780
|
-
const
|
|
781
|
-
const
|
|
736
|
+
const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
737
|
+
const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
|
|
738
|
+
const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
739
|
+
const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
|
|
740
|
+
const closeType = Number(AbiCoder.decodeParameter('uint8', subData[4])) as CloseStrategyType;
|
|
741
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[5]) as unknown as EthereumAddress;
|
|
742
|
+
const owner = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
743
|
+
const tsi = AbiCoder.decodeParameter('uint256', subData[7]) as unknown as string;
|
|
744
|
+
const slippage = AbiCoder.decodeParameter('uint256', subData[8]) as unknown as string;
|
|
782
745
|
|
|
783
746
|
return {
|
|
784
|
-
|
|
747
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner, tsi, slippage,
|
|
785
748
|
};
|
|
786
749
|
},
|
|
787
750
|
};
|
|
788
|
-
|
|
789
|
-
export const aaveV3DebtSwitchSubData = {
|
|
751
|
+
export const aaveV3CollateralSwitchSubData = {
|
|
790
752
|
encode(
|
|
791
753
|
fromAsset: EthereumAddress,
|
|
792
754
|
fromAssetId: number,
|
|
@@ -794,7 +756,7 @@ export const aaveV3DebtSwitchSubData = {
|
|
|
794
756
|
toAssetId: number,
|
|
795
757
|
marketAddr: EthereumAddress,
|
|
796
758
|
amountToSwitch: string,
|
|
797
|
-
|
|
759
|
+
useOnBehalf: boolean = false,
|
|
798
760
|
): SubData {
|
|
799
761
|
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
800
762
|
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
@@ -802,7 +764,7 @@ export const aaveV3DebtSwitchSubData = {
|
|
|
802
764
|
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
803
765
|
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
804
766
|
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
805
|
-
const
|
|
767
|
+
const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
|
|
806
768
|
|
|
807
769
|
return [
|
|
808
770
|
encodedFromAsset,
|
|
@@ -811,7 +773,7 @@ export const aaveV3DebtSwitchSubData = {
|
|
|
811
773
|
encodedToAssetId,
|
|
812
774
|
encodedMarketAddr,
|
|
813
775
|
encodedAmountToSwitch,
|
|
814
|
-
|
|
776
|
+
encodedUseOnBehalf,
|
|
815
777
|
];
|
|
816
778
|
},
|
|
817
779
|
decode(subData: SubData): {
|
|
@@ -821,7 +783,6 @@ export const aaveV3DebtSwitchSubData = {
|
|
|
821
783
|
toAssetId: number,
|
|
822
784
|
marketAddr: EthereumAddress,
|
|
823
785
|
amountToSwitch: string,
|
|
824
|
-
user: EthereumAddress,
|
|
825
786
|
} {
|
|
826
787
|
const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
827
788
|
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
@@ -829,10 +790,9 @@ export const aaveV3DebtSwitchSubData = {
|
|
|
829
790
|
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
830
791
|
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
831
792
|
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
832
|
-
const user = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
833
793
|
|
|
834
794
|
return {
|
|
835
|
-
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
|
|
795
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
|
|
836
796
|
};
|
|
837
797
|
},
|
|
838
798
|
};
|
package/src/types/enums.ts
CHANGED
|
@@ -102,32 +102,24 @@ export namespace Strategies {
|
|
|
102
102
|
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
103
103
|
SPARK_COLLATERAL_SWITCH = 156,
|
|
104
104
|
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
|
|
105
|
-
AAVE_V3_DEBT_SWITCH = 168,
|
|
106
|
-
AAVE_V3_DEBT_SWITCH_EOA = 169,
|
|
107
105
|
}
|
|
108
106
|
|
|
109
107
|
export enum OptimismIds {
|
|
110
108
|
EXCHANGE_DCA = 8,
|
|
111
109
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
112
110
|
AAVE_V3_COLLATERAL_SWITCH = 24,
|
|
113
|
-
AAVE_V3_DEBT_SWITCH = 25,
|
|
114
|
-
AAVE_V3_DEBT_SWITCH_EOA = 26,
|
|
115
111
|
}
|
|
116
112
|
|
|
117
113
|
export enum BaseIds {
|
|
118
114
|
EXCHANGE_DCA = 8,
|
|
119
115
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
120
116
|
AAVE_V3_COLLATERAL_SWITCH = 56,
|
|
121
|
-
AAVE_V3_DEBT_SWITCH = 61,
|
|
122
|
-
AAVE_V3_DEBT_SWITCH_EOA = 62,
|
|
123
117
|
}
|
|
124
118
|
|
|
125
119
|
export enum ArbitrumIds {
|
|
126
120
|
EXCHANGE_DCA = 8,
|
|
127
121
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
128
122
|
AAVE_V3_COLLATERAL_SWITCH = 50,
|
|
129
|
-
AAVE_V3_DEBT_SWITCH = 55,
|
|
130
|
-
AAVE_V3_DEBT_SWITCH_EOA = 56,
|
|
131
123
|
}
|
|
132
124
|
|
|
133
125
|
export enum Identifiers {
|
|
@@ -146,6 +138,8 @@ export namespace Strategies {
|
|
|
146
138
|
CloseOnPriceToColl = 'close-on-price-to-collateral',
|
|
147
139
|
CloseOnPrice = 'close-on-price',
|
|
148
140
|
EoaCloseOnPrice = 'eoa-close-on-price',
|
|
141
|
+
InstantCloseOnPrice = 'instant-close-on-price',
|
|
142
|
+
EoaInstantCloseOnPrice = 'eoa-instant-close-on-price',
|
|
149
143
|
TrailingStopToColl = 'trailing-stop-to-collateral',
|
|
150
144
|
TrailingStopToDebt = 'trailing-stop-to-debt',
|
|
151
145
|
Rebond = 'rebond',
|
|
@@ -162,8 +156,6 @@ export namespace Strategies {
|
|
|
162
156
|
EoaRepayOnPrice = 'eoa-repay-on-price',
|
|
163
157
|
CollateralSwitch = 'collateral-switch',
|
|
164
158
|
EoaCollateralSwitch = 'eoa-collateral-switch',
|
|
165
|
-
DebtSwitch = 'debt-switch',
|
|
166
|
-
EoaDebtSwitch = 'eoa-debt-switch',
|
|
167
159
|
LiquidationProtection = 'liquidation-protection',
|
|
168
160
|
EoaLiquidationProtection = 'liquidation-protection-eoa',
|
|
169
161
|
}
|
|
@@ -276,6 +268,8 @@ export namespace Bundles {
|
|
|
276
268
|
SPARK_EOA_BOOST_ON_PRICE = 91,
|
|
277
269
|
SPARK_EOA_CLOSE = 92,
|
|
278
270
|
SPARK_EOA_LIQUIDATION_PROTECTION = 93,
|
|
271
|
+
AAVE_V3_SW_INSTANT_CLOSE = 94,
|
|
272
|
+
AAVE_V3_EOA_INSTANT_CLOSE = 95,
|
|
279
273
|
}
|
|
280
274
|
|
|
281
275
|
export enum OptimismIds {
|