@defisaver/automation-sdk 3.3.20 → 3.3.21-debt-switch-dev-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 +13 -0
- package/cjs/services/strategySubService.d.ts +1 -0
- package/cjs/services/strategySubService.js +6 -0
- package/cjs/services/strategySubService.test.js +71 -0
- package/cjs/services/subDataService.d.ts +12 -0
- package/cjs/services/subDataService.js +34 -2
- package/cjs/services/subDataService.test.js +104 -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 +13 -0
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +6 -0
- package/esm/services/strategySubService.test.js +71 -0
- package/esm/services/subDataService.d.ts +12 -0
- package/esm/services/subDataService.js +32 -0
- package/esm/services/subDataService.test.js +104 -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.ts +15 -0
- package/src/services/strategySubService.test.ts +89 -0
- package/src/services/strategySubService.ts +22 -0
- package/src/services/subDataService.test.ts +108 -0
- package/src/services/subDataService.ts +50 -0
- package/src/types/enums.ts +10 -0
|
@@ -831,6 +831,77 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
831
831
|
});
|
|
832
832
|
});
|
|
833
833
|
});
|
|
834
|
+
describe('debtSwitch()', () => {
|
|
835
|
+
const examples = [
|
|
836
|
+
// USDC -> DAI, price 100000, state UNDER
|
|
837
|
+
[
|
|
838
|
+
[
|
|
839
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
840
|
+
false,
|
|
841
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
842
|
+
[
|
|
843
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
844
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
845
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
846
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
847
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
848
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
849
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
850
|
+
],
|
|
851
|
+
],
|
|
852
|
+
[
|
|
853
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
854
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
855
|
+
1,
|
|
856
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
857
|
+
3,
|
|
858
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
859
|
+
'10000000000000000000',
|
|
860
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
861
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
862
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
863
|
+
100000,
|
|
864
|
+
RatioState.UNDER,
|
|
865
|
+
]
|
|
866
|
+
],
|
|
867
|
+
// DAI -> USDC (MaxUint256), price 1, state OVER
|
|
868
|
+
[
|
|
869
|
+
[
|
|
870
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
871
|
+
false,
|
|
872
|
+
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
|
|
873
|
+
[
|
|
874
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
875
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
876
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
877
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
878
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
879
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
880
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
881
|
+
],
|
|
882
|
+
],
|
|
883
|
+
[
|
|
884
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
885
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
886
|
+
3,
|
|
887
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
888
|
+
1,
|
|
889
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
890
|
+
MAXUINT,
|
|
891
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
892
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
893
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
894
|
+
1,
|
|
895
|
+
RatioState.OVER,
|
|
896
|
+
]
|
|
897
|
+
],
|
|
898
|
+
];
|
|
899
|
+
examples.forEach(([expected, actual]) => {
|
|
900
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
901
|
+
expect(aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
|
|
902
|
+
});
|
|
903
|
+
});
|
|
904
|
+
});
|
|
834
905
|
});
|
|
835
906
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
836
907
|
describe('leverageManagementOnPrice()', () => {
|
|
@@ -259,6 +259,18 @@ export declare const aaveV3CollateralSwitchSubData: {
|
|
|
259
259
|
amountToSwitch: string;
|
|
260
260
|
};
|
|
261
261
|
};
|
|
262
|
+
export declare const aaveV3DebtSwitchSubData: {
|
|
263
|
+
encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
|
|
264
|
+
decode(subData: string[]): {
|
|
265
|
+
fromAsset: EthereumAddress;
|
|
266
|
+
fromAssetId: number;
|
|
267
|
+
toAsset: EthereumAddress;
|
|
268
|
+
toAssetId: number;
|
|
269
|
+
marketAddr: EthereumAddress;
|
|
270
|
+
amountToSwitch: string;
|
|
271
|
+
user: EthereumAddress;
|
|
272
|
+
};
|
|
273
|
+
};
|
|
262
274
|
export declare const aaveV3QuotePriceSubData: {
|
|
263
275
|
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress): string[];
|
|
264
276
|
decode(subData: string[]): {
|
|
@@ -542,6 +542,38 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
542
542
|
};
|
|
543
543
|
},
|
|
544
544
|
};
|
|
545
|
+
export const aaveV3DebtSwitchSubData = {
|
|
546
|
+
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
|
|
547
|
+
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
548
|
+
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
549
|
+
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
550
|
+
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
551
|
+
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
552
|
+
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
553
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
554
|
+
return [
|
|
555
|
+
encodedFromAsset,
|
|
556
|
+
encodedFromAssetId,
|
|
557
|
+
encodedToAsset,
|
|
558
|
+
encodedToAssetId,
|
|
559
|
+
encodedMarketAddr,
|
|
560
|
+
encodedAmountToSwitch,
|
|
561
|
+
encodedUser,
|
|
562
|
+
];
|
|
563
|
+
},
|
|
564
|
+
decode(subData) {
|
|
565
|
+
const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
|
|
566
|
+
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
567
|
+
const toAsset = AbiCoder.decodeParameter('address', subData[2]);
|
|
568
|
+
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
569
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
|
|
570
|
+
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
|
|
571
|
+
const user = AbiCoder.decodeParameter('address', subData[6]);
|
|
572
|
+
return {
|
|
573
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
574
|
+
};
|
|
575
|
+
},
|
|
576
|
+
};
|
|
545
577
|
export const aaveV3QuotePriceSubData = {
|
|
546
578
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = ZERO_ADDRESS) {
|
|
547
579
|
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
@@ -510,6 +510,110 @@ describe('Feature: subDataService.ts', () => {
|
|
|
510
510
|
});
|
|
511
511
|
});
|
|
512
512
|
});
|
|
513
|
+
describe('When testing subDataService.aaveV3DebtSwitchSubData', () => {
|
|
514
|
+
describe('encode()', () => {
|
|
515
|
+
const examples = [
|
|
516
|
+
// USDC -> DAI
|
|
517
|
+
[
|
|
518
|
+
[
|
|
519
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
520
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
521
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
522
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
523
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
524
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
525
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
526
|
+
],
|
|
527
|
+
[
|
|
528
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
529
|
+
1,
|
|
530
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
531
|
+
3,
|
|
532
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
533
|
+
'10000000000000000000',
|
|
534
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
535
|
+
]
|
|
536
|
+
],
|
|
537
|
+
// DAI -> USDC (MaxUint256)
|
|
538
|
+
[
|
|
539
|
+
[
|
|
540
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
541
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
542
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
543
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
544
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
545
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
546
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
547
|
+
],
|
|
548
|
+
[
|
|
549
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
550
|
+
3,
|
|
551
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
552
|
+
1,
|
|
553
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
554
|
+
MAXUINT,
|
|
555
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
556
|
+
]
|
|
557
|
+
],
|
|
558
|
+
];
|
|
559
|
+
examples.forEach(([expected, actual]) => {
|
|
560
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
561
|
+
expect(subDataService.aaveV3DebtSwitchSubData.encode(...actual)).to.eql(expected);
|
|
562
|
+
});
|
|
563
|
+
});
|
|
564
|
+
});
|
|
565
|
+
describe('decode()', () => {
|
|
566
|
+
const examples = [
|
|
567
|
+
// USDC -> DAI
|
|
568
|
+
[
|
|
569
|
+
{
|
|
570
|
+
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
571
|
+
fromAssetId: 1,
|
|
572
|
+
toAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
573
|
+
toAssetId: 3,
|
|
574
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
575
|
+
amountToSwitch: '10000000000000000000',
|
|
576
|
+
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
577
|
+
},
|
|
578
|
+
[
|
|
579
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
580
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
581
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
582
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
583
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
584
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
585
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
586
|
+
],
|
|
587
|
+
],
|
|
588
|
+
// DAI -> USDC (MaxUint256)
|
|
589
|
+
[
|
|
590
|
+
{
|
|
591
|
+
fromAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
592
|
+
fromAssetId: 3,
|
|
593
|
+
toAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
594
|
+
toAssetId: 1,
|
|
595
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
596
|
+
amountToSwitch: MAXUINT,
|
|
597
|
+
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
598
|
+
},
|
|
599
|
+
[
|
|
600
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
601
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
602
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
603
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
604
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
605
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
606
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
607
|
+
],
|
|
608
|
+
],
|
|
609
|
+
];
|
|
610
|
+
examples.forEach(([expected, actual]) => {
|
|
611
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
612
|
+
expect(subDataService.aaveV3DebtSwitchSubData.decode(actual)).to.eql(expected);
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
});
|
|
513
617
|
describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
|
|
514
618
|
describe('encode()', () => {
|
|
515
619
|
const examples = [
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -91,22 +91,30 @@ export declare namespace Strategies {
|
|
|
91
91
|
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
92
92
|
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
93
93
|
SPARK_COLLATERAL_SWITCH = 156,
|
|
94
|
-
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167
|
|
94
|
+
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
|
|
95
|
+
AAVE_V3_DEBT_SWITCH = 168,
|
|
96
|
+
AAVE_V3_DEBT_SWITCH_EOA = 169
|
|
95
97
|
}
|
|
96
98
|
enum OptimismIds {
|
|
97
99
|
EXCHANGE_DCA = 8,
|
|
98
100
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
99
|
-
AAVE_V3_COLLATERAL_SWITCH = 24
|
|
101
|
+
AAVE_V3_COLLATERAL_SWITCH = 24,
|
|
102
|
+
AAVE_V3_DEBT_SWITCH = 25,
|
|
103
|
+
AAVE_V3_DEBT_SWITCH_EOA = 26
|
|
100
104
|
}
|
|
101
105
|
enum BaseIds {
|
|
102
106
|
EXCHANGE_DCA = 8,
|
|
103
107
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
104
|
-
AAVE_V3_COLLATERAL_SWITCH = 56
|
|
108
|
+
AAVE_V3_COLLATERAL_SWITCH = 56,
|
|
109
|
+
AAVE_V3_DEBT_SWITCH = 61,
|
|
110
|
+
AAVE_V3_DEBT_SWITCH_EOA = 62
|
|
105
111
|
}
|
|
106
112
|
enum ArbitrumIds {
|
|
107
113
|
EXCHANGE_DCA = 8,
|
|
108
114
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
109
|
-
AAVE_V3_COLLATERAL_SWITCH = 50
|
|
115
|
+
AAVE_V3_COLLATERAL_SWITCH = 50,
|
|
116
|
+
AAVE_V3_DEBT_SWITCH = 55,
|
|
117
|
+
AAVE_V3_DEBT_SWITCH_EOA = 56
|
|
110
118
|
}
|
|
111
119
|
enum Identifiers {
|
|
112
120
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
|
@@ -140,6 +148,8 @@ export declare namespace Strategies {
|
|
|
140
148
|
EoaRepayOnPrice = "eoa-repay-on-price",
|
|
141
149
|
CollateralSwitch = "collateral-switch",
|
|
142
150
|
EoaCollateralSwitch = "eoa-collateral-switch",
|
|
151
|
+
DebtSwitch = "debt-switch",
|
|
152
|
+
EoaDebtSwitch = "eoa-debt-switch",
|
|
143
153
|
LiquidationProtection = "liquidation-protection",
|
|
144
154
|
EoaLiquidationProtection = "liquidation-protection-eoa"
|
|
145
155
|
}
|
package/esm/types/enums.js
CHANGED
|
@@ -105,24 +105,32 @@ export var Strategies;
|
|
|
105
105
|
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
|
|
106
106
|
MainnetIds[MainnetIds["SPARK_COLLATERAL_SWITCH"] = 156] = "SPARK_COLLATERAL_SWITCH";
|
|
107
107
|
MainnetIds[MainnetIds["SPARK_GENERIC_FL_COLLATERAL_SWITCH"] = 167] = "SPARK_GENERIC_FL_COLLATERAL_SWITCH";
|
|
108
|
+
MainnetIds[MainnetIds["AAVE_V3_DEBT_SWITCH"] = 168] = "AAVE_V3_DEBT_SWITCH";
|
|
109
|
+
MainnetIds[MainnetIds["AAVE_V3_DEBT_SWITCH_EOA"] = 169] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
108
110
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
109
111
|
let OptimismIds;
|
|
110
112
|
(function (OptimismIds) {
|
|
111
113
|
OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
112
114
|
OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
113
115
|
OptimismIds[OptimismIds["AAVE_V3_COLLATERAL_SWITCH"] = 24] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
116
|
+
OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH"] = 25] = "AAVE_V3_DEBT_SWITCH";
|
|
117
|
+
OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH_EOA"] = 26] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
114
118
|
})(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
|
|
115
119
|
let BaseIds;
|
|
116
120
|
(function (BaseIds) {
|
|
117
121
|
BaseIds[BaseIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
118
122
|
BaseIds[BaseIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
119
123
|
BaseIds[BaseIds["AAVE_V3_COLLATERAL_SWITCH"] = 56] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
124
|
+
BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH"] = 61] = "AAVE_V3_DEBT_SWITCH";
|
|
125
|
+
BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH_EOA"] = 62] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
120
126
|
})(BaseIds = Strategies.BaseIds || (Strategies.BaseIds = {}));
|
|
121
127
|
let ArbitrumIds;
|
|
122
128
|
(function (ArbitrumIds) {
|
|
123
129
|
ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
124
130
|
ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
125
131
|
ArbitrumIds[ArbitrumIds["AAVE_V3_COLLATERAL_SWITCH"] = 50] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
132
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH"] = 55] = "AAVE_V3_DEBT_SWITCH";
|
|
133
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH_EOA"] = 56] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
126
134
|
})(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
|
|
127
135
|
let Identifiers;
|
|
128
136
|
(function (Identifiers) {
|
|
@@ -157,6 +165,8 @@ export var Strategies;
|
|
|
157
165
|
Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
|
|
158
166
|
Identifiers["CollateralSwitch"] = "collateral-switch";
|
|
159
167
|
Identifiers["EoaCollateralSwitch"] = "eoa-collateral-switch";
|
|
168
|
+
Identifiers["DebtSwitch"] = "debt-switch";
|
|
169
|
+
Identifiers["EoaDebtSwitch"] = "eoa-debt-switch";
|
|
160
170
|
Identifiers["LiquidationProtection"] = "liquidation-protection";
|
|
161
171
|
Identifiers["EoaLiquidationProtection"] = "liquidation-protection-eoa";
|
|
162
172
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
|
@@ -145,6 +145,16 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
|
|
|
145
145
|
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
146
146
|
protocol: PROTOCOLS.Spark,
|
|
147
147
|
},
|
|
148
|
+
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH]: {
|
|
149
|
+
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
150
|
+
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
151
|
+
protocol: PROTOCOLS.AaveV3,
|
|
152
|
+
},
|
|
153
|
+
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
154
|
+
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
155
|
+
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
156
|
+
protocol: PROTOCOLS.AaveV3,
|
|
157
|
+
},
|
|
148
158
|
};
|
|
149
159
|
|
|
150
160
|
export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
|
|
@@ -163,6 +173,16 @@ export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
|
|
|
163
173
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
164
174
|
protocol: PROTOCOLS.AaveV3,
|
|
165
175
|
},
|
|
176
|
+
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
|
|
177
|
+
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
|
|
178
|
+
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
179
|
+
protocol: PROTOCOLS.AaveV3,
|
|
180
|
+
},
|
|
181
|
+
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
182
|
+
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
183
|
+
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
184
|
+
protocol: PROTOCOLS.AaveV3,
|
|
185
|
+
},
|
|
166
186
|
};
|
|
167
187
|
|
|
168
188
|
export const BASE_STRATEGIES_INFO: BaseStrategiesInfo = {
|
|
@@ -181,6 +201,16 @@ export const BASE_STRATEGIES_INFO: BaseStrategiesInfo = {
|
|
|
181
201
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
182
202
|
protocol: PROTOCOLS.AaveV3,
|
|
183
203
|
},
|
|
204
|
+
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
|
|
205
|
+
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
|
|
206
|
+
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
207
|
+
protocol: PROTOCOLS.AaveV3,
|
|
208
|
+
},
|
|
209
|
+
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
210
|
+
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
211
|
+
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
212
|
+
protocol: PROTOCOLS.AaveV3,
|
|
213
|
+
},
|
|
184
214
|
};
|
|
185
215
|
|
|
186
216
|
export const ARBITRUM_STRATEGIES_INFO: ArbitrumStrategiesInfo = {
|
|
@@ -199,6 +229,16 @@ export const ARBITRUM_STRATEGIES_INFO: ArbitrumStrategiesInfo = {
|
|
|
199
229
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
200
230
|
protocol: PROTOCOLS.AaveV3,
|
|
201
231
|
},
|
|
232
|
+
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
|
|
233
|
+
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
|
|
234
|
+
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
235
|
+
protocol: PROTOCOLS.AaveV3,
|
|
236
|
+
},
|
|
237
|
+
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
238
|
+
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
239
|
+
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
240
|
+
protocol: PROTOCOLS.AaveV3,
|
|
241
|
+
},
|
|
202
242
|
};
|
|
203
243
|
|
|
204
244
|
export const STRATEGIES_INFO: StrategiesInfo = {
|
|
@@ -445,6 +445,19 @@ function parseAaveV3CollateralSwitch(position: Position.Automated, parseData: Pa
|
|
|
445
445
|
return _position;
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
+
function parseAaveV3DebtSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
449
|
+
const _position = cloneDeep(position);
|
|
450
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
451
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
452
|
+
const subData = subDataService.aaveV3DebtSwitchSubData.decode(subStruct.subData);
|
|
453
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
454
|
+
_position.strategyData.decoded.subData = subData;
|
|
455
|
+
// TODO -> This isn't enough for ID
|
|
456
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
457
|
+
|
|
458
|
+
return _position;
|
|
459
|
+
}
|
|
460
|
+
|
|
448
461
|
function parseSparkCollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
449
462
|
const _position = cloneDeep(position);
|
|
450
463
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -1597,6 +1610,8 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1597
1610
|
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1598
1611
|
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1599
1612
|
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1613
|
+
[Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
|
|
1614
|
+
[Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
|
|
1600
1615
|
[Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1601
1616
|
[Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1602
1617
|
},
|
|
@@ -1002,6 +1002,95 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1002
1002
|
});
|
|
1003
1003
|
});
|
|
1004
1004
|
});
|
|
1005
|
+
|
|
1006
|
+
describe('debtSwitch()', () => {
|
|
1007
|
+
const examples: Array<[
|
|
1008
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1009
|
+
[
|
|
1010
|
+
strategyOrBundleId: number,
|
|
1011
|
+
fromAsset: EthereumAddress,
|
|
1012
|
+
fromAssetId: number,
|
|
1013
|
+
toAsset: EthereumAddress,
|
|
1014
|
+
toAssetId: number,
|
|
1015
|
+
marketAddr: EthereumAddress,
|
|
1016
|
+
amountToSwitch: string,
|
|
1017
|
+
user: EthereumAddress,
|
|
1018
|
+
baseTokenAddress: EthereumAddress,
|
|
1019
|
+
quoteTokenAddress: EthereumAddress,
|
|
1020
|
+
price: number,
|
|
1021
|
+
state: RatioState,
|
|
1022
|
+
]
|
|
1023
|
+
]> = [
|
|
1024
|
+
// USDC -> DAI, price 100000, state UNDER
|
|
1025
|
+
[
|
|
1026
|
+
[
|
|
1027
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1028
|
+
false,
|
|
1029
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1030
|
+
[
|
|
1031
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1032
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1033
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1034
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1035
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1036
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1037
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
1038
|
+
],
|
|
1039
|
+
],
|
|
1040
|
+
[
|
|
1041
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1042
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1043
|
+
1,
|
|
1044
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1045
|
+
3,
|
|
1046
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1047
|
+
'10000000000000000000', // 10 tokens
|
|
1048
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
1049
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1050
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1051
|
+
100000,
|
|
1052
|
+
RatioState.UNDER,
|
|
1053
|
+
]
|
|
1054
|
+
],
|
|
1055
|
+
// DAI -> USDC (MaxUint256), price 1, state OVER
|
|
1056
|
+
[
|
|
1057
|
+
[
|
|
1058
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1059
|
+
false,
|
|
1060
|
+
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1061
|
+
[
|
|
1062
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1063
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1064
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1065
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1066
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1067
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
1068
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
1069
|
+
],
|
|
1070
|
+
],
|
|
1071
|
+
[
|
|
1072
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
1073
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1074
|
+
3,
|
|
1075
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1076
|
+
1,
|
|
1077
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1078
|
+
MAXUINT, // MaxUint256
|
|
1079
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
1080
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1081
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1082
|
+
1,
|
|
1083
|
+
RatioState.OVER,
|
|
1084
|
+
]
|
|
1085
|
+
],
|
|
1086
|
+
];
|
|
1087
|
+
|
|
1088
|
+
examples.forEach(([expected, actual]) => {
|
|
1089
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1090
|
+
expect(aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
|
|
1091
|
+
});
|
|
1092
|
+
});
|
|
1093
|
+
});
|
|
1005
1094
|
});
|
|
1006
1095
|
|
|
1007
1096
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
@@ -444,6 +444,28 @@ export const aaveV3Encode = {
|
|
|
444
444
|
|
|
445
445
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
446
446
|
},
|
|
447
|
+
|
|
448
|
+
debtSwitch(
|
|
449
|
+
strategyOrBundleId: number,
|
|
450
|
+
fromAsset: EthereumAddress,
|
|
451
|
+
fromAssetId: number,
|
|
452
|
+
toAsset: EthereumAddress,
|
|
453
|
+
toAssetId: number,
|
|
454
|
+
marketAddr: EthereumAddress,
|
|
455
|
+
amountToSwitch: string,
|
|
456
|
+
user: EthereumAddress,
|
|
457
|
+
baseTokenAddress: EthereumAddress,
|
|
458
|
+
quoteTokenAddress: EthereumAddress,
|
|
459
|
+
price: number,
|
|
460
|
+
state: RatioState,
|
|
461
|
+
) {
|
|
462
|
+
const isBundle = false;
|
|
463
|
+
|
|
464
|
+
const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
|
|
465
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
466
|
+
|
|
467
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
468
|
+
},
|
|
447
469
|
};
|
|
448
470
|
|
|
449
471
|
export const compoundV2Encode = {
|