@defisaver/automation-sdk 3.3.20 → 3.3.21-coll-switch-generic-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 +40 -0
- package/cjs/services/strategiesService.js +21 -1
- package/cjs/services/strategiesService.test.js +94 -0
- package/cjs/services/strategySubService.d.ts +2 -0
- package/cjs/services/strategySubService.js +12 -0
- package/cjs/services/strategySubService.test.js +107 -0
- package/cjs/services/subDataService.d.ts +24 -0
- package/cjs/services/subDataService.js +66 -2
- package/cjs/services/subDataService.test.js +139 -0
- package/cjs/types/enums.d.ts +14 -4
- package/cjs/types/enums.js +10 -0
- package/esm/constants/index.js +40 -0
- package/esm/services/strategiesService.js +21 -1
- package/esm/services/strategiesService.test.js +95 -1
- package/esm/services/strategySubService.d.ts +2 -0
- package/esm/services/strategySubService.js +12 -0
- package/esm/services/strategySubService.test.js +107 -0
- package/esm/services/subDataService.d.ts +24 -0
- package/esm/services/subDataService.js +64 -0
- package/esm/services/subDataService.test.js +139 -0
- package/esm/types/enums.d.ts +14 -4
- package/esm/types/enums.js +10 -0
- package/package.json +1 -1
- package/src/constants/index.ts +40 -0
- package/src/services/strategiesService.test.ts +106 -1
- package/src/services/strategiesService.ts +23 -1
- package/src/services/strategySubService.test.ts +131 -0
- package/src/services/strategySubService.ts +46 -0
- package/src/services/subDataService.test.ts +149 -0
- package/src/services/subDataService.ts +101 -0
- package/src/types/enums.ts +10 -0
|
@@ -549,6 +549,155 @@ 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
|
+
|
|
552
701
|
describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
|
|
553
702
|
describe('encode()', () => {
|
|
554
703
|
const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean]]> = [
|
|
@@ -735,6 +735,107 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
735
735
|
};
|
|
736
736
|
},
|
|
737
737
|
};
|
|
738
|
+
export const aaveV3GenericFLCollateralSwitchSubData = {
|
|
739
|
+
encode(
|
|
740
|
+
fromAsset: EthereumAddress,
|
|
741
|
+
fromAssetId: number,
|
|
742
|
+
toAsset: EthereumAddress,
|
|
743
|
+
toAssetId: number,
|
|
744
|
+
marketAddr: EthereumAddress,
|
|
745
|
+
amountToSwitch: string,
|
|
746
|
+
user: EthereumAddress,
|
|
747
|
+
): SubData {
|
|
748
|
+
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
749
|
+
const encodedFromAssetId = AbiCoder.encodeParameter('uint16', fromAssetId);
|
|
750
|
+
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
751
|
+
const encodedToAssetId = AbiCoder.encodeParameter('uint16', toAssetId);
|
|
752
|
+
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
753
|
+
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
754
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
755
|
+
|
|
756
|
+
return [
|
|
757
|
+
encodedFromAsset,
|
|
758
|
+
encodedFromAssetId,
|
|
759
|
+
encodedToAsset,
|
|
760
|
+
encodedToAssetId,
|
|
761
|
+
encodedMarketAddr,
|
|
762
|
+
encodedAmountToSwitch,
|
|
763
|
+
encodedUser,
|
|
764
|
+
];
|
|
765
|
+
},
|
|
766
|
+
decode(subData: SubData): {
|
|
767
|
+
fromAsset: EthereumAddress,
|
|
768
|
+
fromAssetId: number,
|
|
769
|
+
toAsset: EthereumAddress,
|
|
770
|
+
toAssetId: number,
|
|
771
|
+
marketAddr: EthereumAddress,
|
|
772
|
+
amountToSwitch: string,
|
|
773
|
+
user: EthereumAddress,
|
|
774
|
+
} {
|
|
775
|
+
const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
776
|
+
const fromAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
|
|
777
|
+
const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
778
|
+
const toAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
|
|
779
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
780
|
+
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
781
|
+
const user = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
782
|
+
|
|
783
|
+
return {
|
|
784
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
785
|
+
};
|
|
786
|
+
},
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
export const aaveV3DebtSwitchSubData = {
|
|
790
|
+
encode(
|
|
791
|
+
fromAsset: EthereumAddress,
|
|
792
|
+
fromAssetId: number,
|
|
793
|
+
toAsset: EthereumAddress,
|
|
794
|
+
toAssetId: number,
|
|
795
|
+
marketAddr: EthereumAddress,
|
|
796
|
+
amountToSwitch: string,
|
|
797
|
+
user: EthereumAddress,
|
|
798
|
+
): SubData {
|
|
799
|
+
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
800
|
+
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
801
|
+
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
802
|
+
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
803
|
+
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
804
|
+
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
805
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
806
|
+
|
|
807
|
+
return [
|
|
808
|
+
encodedFromAsset,
|
|
809
|
+
encodedFromAssetId,
|
|
810
|
+
encodedToAsset,
|
|
811
|
+
encodedToAssetId,
|
|
812
|
+
encodedMarketAddr,
|
|
813
|
+
encodedAmountToSwitch,
|
|
814
|
+
encodedUser,
|
|
815
|
+
];
|
|
816
|
+
},
|
|
817
|
+
decode(subData: SubData): {
|
|
818
|
+
fromAsset: EthereumAddress,
|
|
819
|
+
fromAssetId: number,
|
|
820
|
+
toAsset: EthereumAddress,
|
|
821
|
+
toAssetId: number,
|
|
822
|
+
marketAddr: EthereumAddress,
|
|
823
|
+
amountToSwitch: string,
|
|
824
|
+
user: EthereumAddress,
|
|
825
|
+
} {
|
|
826
|
+
const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
827
|
+
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
828
|
+
const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
829
|
+
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
830
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
831
|
+
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
832
|
+
const user = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
833
|
+
|
|
834
|
+
return {
|
|
835
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
836
|
+
};
|
|
837
|
+
},
|
|
838
|
+
};
|
|
738
839
|
export const aaveV3QuotePriceSubData = {
|
|
739
840
|
encode(
|
|
740
841
|
collAsset: EthereumAddress,
|
package/src/types/enums.ts
CHANGED
|
@@ -102,24 +102,32 @@ 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,
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
export enum OptimismIds {
|
|
108
110
|
EXCHANGE_DCA = 8,
|
|
109
111
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
110
112
|
AAVE_V3_COLLATERAL_SWITCH = 24,
|
|
113
|
+
AAVE_V3_DEBT_SWITCH = 25,
|
|
114
|
+
AAVE_V3_DEBT_SWITCH_EOA = 26,
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
export enum BaseIds {
|
|
114
118
|
EXCHANGE_DCA = 8,
|
|
115
119
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
116
120
|
AAVE_V3_COLLATERAL_SWITCH = 56,
|
|
121
|
+
AAVE_V3_DEBT_SWITCH = 61,
|
|
122
|
+
AAVE_V3_DEBT_SWITCH_EOA = 62,
|
|
117
123
|
}
|
|
118
124
|
|
|
119
125
|
export enum ArbitrumIds {
|
|
120
126
|
EXCHANGE_DCA = 8,
|
|
121
127
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
122
128
|
AAVE_V3_COLLATERAL_SWITCH = 50,
|
|
129
|
+
AAVE_V3_DEBT_SWITCH = 55,
|
|
130
|
+
AAVE_V3_DEBT_SWITCH_EOA = 56,
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
export enum Identifiers {
|
|
@@ -154,6 +162,8 @@ export namespace Strategies {
|
|
|
154
162
|
EoaRepayOnPrice = 'eoa-repay-on-price',
|
|
155
163
|
CollateralSwitch = 'collateral-switch',
|
|
156
164
|
EoaCollateralSwitch = 'eoa-collateral-switch',
|
|
165
|
+
DebtSwitch = 'debt-switch',
|
|
166
|
+
EoaDebtSwitch = 'eoa-debt-switch',
|
|
157
167
|
LiquidationProtection = 'liquidation-protection',
|
|
158
168
|
EoaLiquidationProtection = 'liquidation-protection-eoa',
|
|
159
169
|
}
|