@defisaver/automation-sdk 3.3.22 → 3.3.23

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.
@@ -549,6 +549,114 @@ 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
+
552
660
  describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
553
661
  describe('encode()', () => {
554
662
  const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean]]> = [
@@ -735,6 +735,56 @@ export const aaveV3CollateralSwitchSubData = {
735
735
  };
736
736
  },
737
737
  };
738
+ export const aaveV3DebtSwitchSubData = {
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('uint8', fromAssetId);
750
+ const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
751
+ const encodedToAssetId = AbiCoder.encodeParameter('uint8', 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('uint8', subData[1]));
777
+ const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
778
+ const toAssetId = Number(AbiCoder.decodeParameter('uint8', 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
+ };
738
788
  export const aaveV3QuotePriceSubData = {
739
789
  encode(
740
790
  collAsset: EthereumAddress,
@@ -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
  }