@defisaver/automation-sdk 3.3.22-coll-switch-generic-dev → 3.3.22
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 -1
- package/cjs/automation/private/StrategiesAutomation.js +12 -0
- package/cjs/automation/private/StrategiesAutomation.test.js +51 -0
- package/cjs/constants/index.js +0 -60
- package/cjs/services/apiSubscriptionsService.d.ts +7 -0
- package/cjs/services/apiSubscriptionsService.js +33 -0
- package/cjs/services/apiSubscriptionsService.test.d.ts +1 -0
- package/cjs/services/apiSubscriptionsService.test.js +67 -0
- package/cjs/services/strategiesService.js +1 -21
- package/cjs/services/strategiesService.test.js +0 -93
- package/cjs/services/strategySubService.d.ts +0 -2
- package/cjs/services/strategySubService.js +0 -12
- package/cjs/services/strategySubService.test.js +0 -107
- package/cjs/services/subDataService.d.ts +0 -24
- package/cjs/services/subDataService.js +2 -66
- package/cjs/services/subDataService.test.js +0 -139
- package/cjs/types/enums.d.ts +4 -18
- package/cjs/types/enums.js +0 -14
- package/cjs/types/index.d.ts +24 -2
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -1
- package/esm/automation/private/StrategiesAutomation.js +12 -0
- package/esm/automation/private/StrategiesAutomation.test.js +51 -0
- package/esm/constants/index.js +0 -60
- package/esm/services/apiSubscriptionsService.d.ts +7 -0
- package/esm/services/apiSubscriptionsService.js +29 -0
- package/esm/services/apiSubscriptionsService.test.d.ts +1 -0
- package/esm/services/apiSubscriptionsService.test.js +65 -0
- package/esm/services/strategiesService.js +1 -21
- package/esm/services/strategiesService.test.js +1 -94
- package/esm/services/strategySubService.d.ts +0 -2
- package/esm/services/strategySubService.js +0 -12
- package/esm/services/strategySubService.test.js +0 -107
- package/esm/services/subDataService.d.ts +0 -24
- package/esm/services/subDataService.js +0 -64
- package/esm/services/subDataService.test.js +0 -139
- package/esm/types/enums.d.ts +4 -18
- package/esm/types/enums.js +0 -14
- package/esm/types/index.d.ts +24 -2
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.test.ts +65 -1
- package/src/automation/private/StrategiesAutomation.ts +17 -0
- package/src/constants/index.ts +0 -60
- package/src/services/apiSubscriptionsService.test.ts +73 -0
- package/src/services/apiSubscriptionsService.ts +33 -0
- package/src/services/strategiesService.test.ts +1 -103
- package/src/services/strategiesService.ts +1 -23
- package/src/services/strategySubService.test.ts +0 -131
- package/src/services/strategySubService.ts +0 -46
- package/src/services/subDataService.test.ts +0 -149
- package/src/services/subDataService.ts +0 -101
- package/src/types/enums.ts +0 -14
- package/src/types/index.ts +26 -2
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sparkGenericLiquidationProtectionSubData = exports.sparkGenericLeverageManagementSubData = exports.sparkLiquidationProtectionSubData = exports.sparkLeverageManagementSubData = exports.legacySparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.legacyExchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3LiquidationProtectionSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.legacyCompoundV2LeverageManagementSubData = exports.aaveV4CollateralSwitchSubData = exports.aaveV4CloseSubData = exports.aaveV4LeverageManagementOnPriceSubData = exports.aaveV4LiquidationProtectionSubData = exports.aaveV4LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.aaveV3QuotePriceSubData = exports.
|
|
7
|
-
exports.fluidLiquidationProtectionSubData = exports.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLiquidationProtectionSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkGenericFLCollateralSwitchSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceGenericSubData =
|
|
6
|
+
exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkGenericLiquidationProtectionSubData = exports.sparkGenericLeverageManagementSubData = exports.sparkLiquidationProtectionSubData = exports.sparkLeverageManagementSubData = exports.legacySparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.legacyExchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3LiquidationProtectionSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.legacyCompoundV2LeverageManagementSubData = exports.aaveV4CollateralSwitchSubData = exports.aaveV4CloseSubData = exports.aaveV4LeverageManagementOnPriceSubData = exports.aaveV4LiquidationProtectionSubData = exports.aaveV4LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LiquidationProtectionSubData = exports.aaveV3LeverageManagementSubData = exports.legacyAaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.legacyAaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.legacyLiquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLiquidationProtectionSubData = exports.makerLeverageManagementSubData = exports.legacyMakerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
|
|
7
|
+
exports.fluidLiquidationProtectionSubData = exports.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLiquidationProtectionSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkGenericFLCollateralSwitchSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceGenericSubData = void 0;
|
|
8
8
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
9
9
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
10
10
|
const web3_utils_1 = require("web3-utils");
|
|
@@ -549,70 +549,6 @@ exports.aaveV3CollateralSwitchSubData = {
|
|
|
549
549
|
};
|
|
550
550
|
},
|
|
551
551
|
};
|
|
552
|
-
exports.aaveV3GenericFLCollateralSwitchSubData = {
|
|
553
|
-
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
|
|
554
|
-
const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
|
|
555
|
-
const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint16', fromAssetId);
|
|
556
|
-
const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
|
|
557
|
-
const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint16', toAssetId);
|
|
558
|
-
const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
559
|
-
const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
|
|
560
|
-
const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
561
|
-
return [
|
|
562
|
-
encodedFromAsset,
|
|
563
|
-
encodedFromAssetId,
|
|
564
|
-
encodedToAsset,
|
|
565
|
-
encodedToAssetId,
|
|
566
|
-
encodedMarketAddr,
|
|
567
|
-
encodedAmountToSwitch,
|
|
568
|
-
encodedUser,
|
|
569
|
-
];
|
|
570
|
-
},
|
|
571
|
-
decode(subData) {
|
|
572
|
-
const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
573
|
-
const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[1]));
|
|
574
|
-
const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
575
|
-
const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[3]));
|
|
576
|
-
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
577
|
-
const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
578
|
-
const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
579
|
-
return {
|
|
580
|
-
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
581
|
-
};
|
|
582
|
-
},
|
|
583
|
-
};
|
|
584
|
-
exports.aaveV3DebtSwitchSubData = {
|
|
585
|
-
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
|
|
586
|
-
const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
|
|
587
|
-
const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
|
|
588
|
-
const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
|
|
589
|
-
const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
|
|
590
|
-
const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
591
|
-
const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
|
|
592
|
-
const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
593
|
-
return [
|
|
594
|
-
encodedFromAsset,
|
|
595
|
-
encodedFromAssetId,
|
|
596
|
-
encodedToAsset,
|
|
597
|
-
encodedToAssetId,
|
|
598
|
-
encodedMarketAddr,
|
|
599
|
-
encodedAmountToSwitch,
|
|
600
|
-
encodedUser,
|
|
601
|
-
];
|
|
602
|
-
},
|
|
603
|
-
decode(subData) {
|
|
604
|
-
const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
605
|
-
const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
606
|
-
const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
607
|
-
const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
608
|
-
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
609
|
-
const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
610
|
-
const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
611
|
-
return {
|
|
612
|
-
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
613
|
-
};
|
|
614
|
-
},
|
|
615
|
-
};
|
|
616
552
|
exports.aaveV3QuotePriceSubData = {
|
|
617
553
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
618
554
|
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
@@ -535,145 +535,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
535
535
|
});
|
|
536
536
|
});
|
|
537
537
|
});
|
|
538
|
-
describe('When testing subDataService.aaveV3DebtSwitchSubData', () => {
|
|
539
|
-
describe('encode()', () => {
|
|
540
|
-
const examples = [
|
|
541
|
-
// USDC -> DAI
|
|
542
|
-
[
|
|
543
|
-
[
|
|
544
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
545
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
546
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
547
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
548
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
549
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
550
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
551
|
-
],
|
|
552
|
-
[
|
|
553
|
-
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
554
|
-
1,
|
|
555
|
-
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
556
|
-
3,
|
|
557
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
558
|
-
'10000000000000000000',
|
|
559
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
560
|
-
]
|
|
561
|
-
],
|
|
562
|
-
// DAI -> USDC (MaxUint256)
|
|
563
|
-
[
|
|
564
|
-
[
|
|
565
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
566
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
567
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
568
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
569
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
570
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
571
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
572
|
-
],
|
|
573
|
-
[
|
|
574
|
-
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
575
|
-
3,
|
|
576
|
-
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
577
|
-
1,
|
|
578
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
579
|
-
tokens_2.MAXUINT,
|
|
580
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
581
|
-
]
|
|
582
|
-
],
|
|
583
|
-
];
|
|
584
|
-
examples.forEach(([expected, actual]) => {
|
|
585
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
586
|
-
(0, chai_1.expect)(subDataService.aaveV3DebtSwitchSubData.encode(...actual)).to.eql(expected);
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
});
|
|
590
|
-
describe('decode()', () => {
|
|
591
|
-
const examples = [
|
|
592
|
-
// USDC -> DAI
|
|
593
|
-
[
|
|
594
|
-
{
|
|
595
|
-
fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
596
|
-
fromAssetId: 1,
|
|
597
|
-
toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
598
|
-
toAssetId: 3,
|
|
599
|
-
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
600
|
-
amountToSwitch: '10000000000000000000',
|
|
601
|
-
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
602
|
-
},
|
|
603
|
-
[
|
|
604
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
605
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
606
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
607
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
608
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
609
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
610
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
611
|
-
],
|
|
612
|
-
],
|
|
613
|
-
// DAI -> USDC (MaxUint256)
|
|
614
|
-
[
|
|
615
|
-
{
|
|
616
|
-
fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
617
|
-
fromAssetId: 3,
|
|
618
|
-
toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
619
|
-
toAssetId: 1,
|
|
620
|
-
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
621
|
-
amountToSwitch: tokens_2.MAXUINT,
|
|
622
|
-
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
623
|
-
},
|
|
624
|
-
[
|
|
625
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
626
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
627
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
628
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
629
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
630
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
631
|
-
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
632
|
-
],
|
|
633
|
-
],
|
|
634
|
-
];
|
|
635
|
-
examples.forEach(([expected, actual]) => {
|
|
636
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
637
|
-
(0, chai_1.expect)(subDataService.aaveV3DebtSwitchSubData.decode(actual)).to.eql(expected);
|
|
638
|
-
});
|
|
639
|
-
});
|
|
640
|
-
});
|
|
641
|
-
});
|
|
642
|
-
describe('When testing subDataService.aaveV3GenericFLCollateralSwitchSubData', () => {
|
|
643
|
-
const fromAsset = web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address);
|
|
644
|
-
const toAsset = web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address);
|
|
645
|
-
const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
646
|
-
const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
|
|
647
|
-
const examples = [
|
|
648
|
-
['10000000000000000000', '0x0000000000000000000000000000000000000000000000008ac7230489e80000'],
|
|
649
|
-
[tokens_2.MAXUINT, '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
|
|
650
|
-
];
|
|
651
|
-
examples.forEach(([amountToSwitch, encodedAmount]) => {
|
|
652
|
-
const subData = [
|
|
653
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
654
|
-
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
655
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
656
|
-
'0x000000000000000000000000000000000000000000000000000000000000ffff',
|
|
657
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
658
|
-
encodedAmount,
|
|
659
|
-
'0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
|
|
660
|
-
];
|
|
661
|
-
it(`encode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
|
|
662
|
-
(0, chai_1.expect)(subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user)).to.eql(subData);
|
|
663
|
-
});
|
|
664
|
-
it(`decode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
|
|
665
|
-
(0, chai_1.expect)(subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subData)).to.eql({
|
|
666
|
-
fromAsset,
|
|
667
|
-
fromAssetId: 256,
|
|
668
|
-
toAsset,
|
|
669
|
-
toAssetId: 65535,
|
|
670
|
-
marketAddr,
|
|
671
|
-
amountToSwitch,
|
|
672
|
-
user,
|
|
673
|
-
});
|
|
674
|
-
});
|
|
675
|
-
});
|
|
676
|
-
});
|
|
677
538
|
describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
|
|
678
539
|
describe('encode()', () => {
|
|
679
540
|
const examples = [
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -91,34 +91,22 @@ 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
|
|
95
|
-
AAVE_V3_DEBT_SWITCH = 168,
|
|
96
|
-
AAVE_V3_DEBT_SWITCH_EOA = 169,
|
|
97
|
-
AAVE_V3_COLLATERAL_SWITCH_EOA = 170
|
|
94
|
+
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167
|
|
98
95
|
}
|
|
99
96
|
enum OptimismIds {
|
|
100
97
|
EXCHANGE_DCA = 8,
|
|
101
98
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
102
|
-
AAVE_V3_COLLATERAL_SWITCH = 24
|
|
103
|
-
AAVE_V3_DEBT_SWITCH = 25,
|
|
104
|
-
AAVE_V3_DEBT_SWITCH_EOA = 26,
|
|
105
|
-
AAVE_V3_COLLATERAL_SWITCH_EOA = 27
|
|
99
|
+
AAVE_V3_COLLATERAL_SWITCH = 24
|
|
106
100
|
}
|
|
107
101
|
enum BaseIds {
|
|
108
102
|
EXCHANGE_DCA = 8,
|
|
109
103
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
110
|
-
AAVE_V3_COLLATERAL_SWITCH = 56
|
|
111
|
-
AAVE_V3_DEBT_SWITCH = 61,
|
|
112
|
-
AAVE_V3_DEBT_SWITCH_EOA = 62,
|
|
113
|
-
AAVE_V3_COLLATERAL_SWITCH_EOA = 63
|
|
104
|
+
AAVE_V3_COLLATERAL_SWITCH = 56
|
|
114
105
|
}
|
|
115
106
|
enum ArbitrumIds {
|
|
116
107
|
EXCHANGE_DCA = 8,
|
|
117
108
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
118
|
-
AAVE_V3_COLLATERAL_SWITCH = 50
|
|
119
|
-
AAVE_V3_DEBT_SWITCH = 55,
|
|
120
|
-
AAVE_V3_DEBT_SWITCH_EOA = 56,
|
|
121
|
-
AAVE_V3_COLLATERAL_SWITCH_EOA = 57
|
|
109
|
+
AAVE_V3_COLLATERAL_SWITCH = 50
|
|
122
110
|
}
|
|
123
111
|
enum Identifiers {
|
|
124
112
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
|
@@ -152,8 +140,6 @@ export declare namespace Strategies {
|
|
|
152
140
|
EoaRepayOnPrice = "eoa-repay-on-price",
|
|
153
141
|
CollateralSwitch = "collateral-switch",
|
|
154
142
|
EoaCollateralSwitch = "eoa-collateral-switch",
|
|
155
|
-
DebtSwitch = "debt-switch",
|
|
156
|
-
EoaDebtSwitch = "eoa-debt-switch",
|
|
157
143
|
LiquidationProtection = "liquidation-protection",
|
|
158
144
|
EoaLiquidationProtection = "liquidation-protection-eoa"
|
|
159
145
|
}
|
package/cjs/types/enums.js
CHANGED
|
@@ -108,36 +108,24 @@ var Strategies;
|
|
|
108
108
|
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
|
|
109
109
|
MainnetIds[MainnetIds["SPARK_COLLATERAL_SWITCH"] = 156] = "SPARK_COLLATERAL_SWITCH";
|
|
110
110
|
MainnetIds[MainnetIds["SPARK_GENERIC_FL_COLLATERAL_SWITCH"] = 167] = "SPARK_GENERIC_FL_COLLATERAL_SWITCH";
|
|
111
|
-
MainnetIds[MainnetIds["AAVE_V3_DEBT_SWITCH"] = 168] = "AAVE_V3_DEBT_SWITCH";
|
|
112
|
-
MainnetIds[MainnetIds["AAVE_V3_DEBT_SWITCH_EOA"] = 169] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
113
|
-
MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH_EOA"] = 170] = "AAVE_V3_COLLATERAL_SWITCH_EOA";
|
|
114
111
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
115
112
|
let OptimismIds;
|
|
116
113
|
(function (OptimismIds) {
|
|
117
114
|
OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
118
115
|
OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
119
116
|
OptimismIds[OptimismIds["AAVE_V3_COLLATERAL_SWITCH"] = 24] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
120
|
-
OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH"] = 25] = "AAVE_V3_DEBT_SWITCH";
|
|
121
|
-
OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH_EOA"] = 26] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
122
|
-
OptimismIds[OptimismIds["AAVE_V3_COLLATERAL_SWITCH_EOA"] = 27] = "AAVE_V3_COLLATERAL_SWITCH_EOA";
|
|
123
117
|
})(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
|
|
124
118
|
let BaseIds;
|
|
125
119
|
(function (BaseIds) {
|
|
126
120
|
BaseIds[BaseIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
127
121
|
BaseIds[BaseIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
128
122
|
BaseIds[BaseIds["AAVE_V3_COLLATERAL_SWITCH"] = 56] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
129
|
-
BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH"] = 61] = "AAVE_V3_DEBT_SWITCH";
|
|
130
|
-
BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH_EOA"] = 62] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
131
|
-
BaseIds[BaseIds["AAVE_V3_COLLATERAL_SWITCH_EOA"] = 63] = "AAVE_V3_COLLATERAL_SWITCH_EOA";
|
|
132
123
|
})(BaseIds = Strategies.BaseIds || (Strategies.BaseIds = {}));
|
|
133
124
|
let ArbitrumIds;
|
|
134
125
|
(function (ArbitrumIds) {
|
|
135
126
|
ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
136
127
|
ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
137
128
|
ArbitrumIds[ArbitrumIds["AAVE_V3_COLLATERAL_SWITCH"] = 50] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
138
|
-
ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH"] = 55] = "AAVE_V3_DEBT_SWITCH";
|
|
139
|
-
ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH_EOA"] = 56] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
140
|
-
ArbitrumIds[ArbitrumIds["AAVE_V3_COLLATERAL_SWITCH_EOA"] = 57] = "AAVE_V3_COLLATERAL_SWITCH_EOA";
|
|
141
129
|
})(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
|
|
142
130
|
let Identifiers;
|
|
143
131
|
(function (Identifiers) {
|
|
@@ -172,8 +160,6 @@ var Strategies;
|
|
|
172
160
|
Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
|
|
173
161
|
Identifiers["CollateralSwitch"] = "collateral-switch";
|
|
174
162
|
Identifiers["EoaCollateralSwitch"] = "eoa-collateral-switch";
|
|
175
|
-
Identifiers["DebtSwitch"] = "debt-switch";
|
|
176
|
-
Identifiers["EoaDebtSwitch"] = "eoa-debt-switch";
|
|
177
163
|
Identifiers["LiquidationProtection"] = "liquidation-protection";
|
|
178
164
|
Identifiers["EoaLiquidationProtection"] = "liquidation-protection-eoa";
|
|
179
165
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
package/cjs/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Web3 from 'web3';
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
3
|
import type { BaseContract, BlockType } from './contracts/generated/types';
|
|
4
|
-
import type {
|
|
4
|
+
import type { StrategyModel } from './contracts/generated/SubStorage';
|
|
5
5
|
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType } from './enums';
|
|
6
6
|
export type PlaceholderType = any;
|
|
7
7
|
export type EthereumAddress = string;
|
|
@@ -53,6 +53,21 @@ interface _SubscriptionOptions {
|
|
|
53
53
|
unexpiredOnly: boolean;
|
|
54
54
|
}
|
|
55
55
|
export type SubscriptionOptions = Partial<_SubscriptionOptions>;
|
|
56
|
+
/** Subscription record as returned by the automation API (GET /v1/subscriptions) */
|
|
57
|
+
export interface ApiSubscriptionRecord {
|
|
58
|
+
id: number;
|
|
59
|
+
wallet: EthereumAddress;
|
|
60
|
+
wallet_type: string;
|
|
61
|
+
is_enabled: boolean;
|
|
62
|
+
is_bundle: boolean;
|
|
63
|
+
strategy_or_bundle_id: number;
|
|
64
|
+
strategy_ids: number[];
|
|
65
|
+
sub_data_hash: string;
|
|
66
|
+
trigger_data: string[];
|
|
67
|
+
sub_data: string[];
|
|
68
|
+
block_number: number;
|
|
69
|
+
additional_triggers: string[] | null;
|
|
70
|
+
}
|
|
56
71
|
export declare namespace Interfaces {
|
|
57
72
|
interface ProtocolBase {
|
|
58
73
|
id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation;
|
|
@@ -291,10 +306,17 @@ export interface BundlesInfo {
|
|
|
291
306
|
[ChainId.Base]: BaseBundleInfo;
|
|
292
307
|
}
|
|
293
308
|
export type StrategyOrBundleIds = typeof Strategies.MainnetIds[keyof typeof Strategies.MainnetIds] | typeof Strategies.OptimismIds[keyof typeof Strategies.OptimismIds] | typeof Strategies.ArbitrumIds[keyof typeof Strategies.ArbitrumIds] | typeof Strategies.BaseIds[keyof typeof Strategies.BaseIds] | typeof Bundles.MainnetIds[keyof typeof Bundles.MainnetIds] | typeof Bundles.OptimismIds[keyof typeof Bundles.OptimismIds] | typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds] | typeof Bundles.BaseIds[keyof typeof Bundles.BaseIds];
|
|
309
|
+
/** Fields of the Subscribe event that parsing relies on */
|
|
310
|
+
export interface SubscriptionEventData {
|
|
311
|
+
subId: string;
|
|
312
|
+
proxy: EthereumAddress;
|
|
313
|
+
subHash: string;
|
|
314
|
+
subStruct: StrategyModel.StrategySubStructOutputStruct;
|
|
315
|
+
}
|
|
294
316
|
export interface ParseData {
|
|
295
317
|
chainId: ChainId;
|
|
296
318
|
blockNumber: BlockNumber;
|
|
297
|
-
subscriptionEventData:
|
|
319
|
+
subscriptionEventData: SubscriptionEventData;
|
|
298
320
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct;
|
|
299
321
|
}
|
|
300
322
|
type MapToProtocolVersion<T> = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type Web3 from 'web3';
|
|
2
2
|
import type { PastEventOptions } from 'web3-eth-contract';
|
|
3
|
-
import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, BlockNumber } from '../../types';
|
|
3
|
+
import type { Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, BlockNumber, ApiSubscriptionRecord } from '../../types';
|
|
4
4
|
import type { StrategyModel, Subscribe, SubStorage, UpdateData } from '../../types/contracts/generated/SubStorage';
|
|
5
5
|
import type { ChainId } from '../../types/enums';
|
|
6
6
|
import Automation from './Automation';
|
|
@@ -30,6 +30,10 @@ export default class StrategiesAutomation extends Automation {
|
|
|
30
30
|
protected mergeSubs(_subscriptions: (Position.Automated | null)[]): Position.Automated[];
|
|
31
31
|
protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
32
32
|
getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
33
|
+
/**
|
|
34
|
+
* @description Parses subscriptions returned by the automation API (GET /v1/subscriptions)
|
|
35
|
+
*/
|
|
36
|
+
parseSubscriptionsFromApi(records: ApiSubscriptionRecord[], options?: SubscriptionOptions): (Position.Automated | null)[];
|
|
33
37
|
getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
34
38
|
}
|
|
35
39
|
export {};
|
|
@@ -14,6 +14,7 @@ import { addToObjectIf, isDefined, isUndefined } from '../../services/utils';
|
|
|
14
14
|
import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
|
|
15
15
|
import { getEventsFromContract, multicall } from '../../services/ethereumService';
|
|
16
16
|
import { parseStrategiesAutomatedPosition } from '../../services/strategiesService';
|
|
17
|
+
import { parseDataFromApiSubscription } from '../../services/apiSubscriptionsService';
|
|
17
18
|
import Automation from './Automation';
|
|
18
19
|
export default class StrategiesAutomation extends Automation {
|
|
19
20
|
constructor(args) {
|
|
@@ -184,6 +185,17 @@ export default class StrategiesAutomation extends Automation {
|
|
|
184
185
|
return this._getSubscriptions(undefined, options);
|
|
185
186
|
});
|
|
186
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* @description Parses subscriptions returned by the automation API (GET /v1/subscriptions)
|
|
190
|
+
*/
|
|
191
|
+
parseSubscriptionsFromApi(records, options) {
|
|
192
|
+
const filtered = (options === null || options === void 0 ? void 0 : options.enabledOnly) ? records.filter((record) => record.is_enabled) : records;
|
|
193
|
+
let subscriptions = filtered.map((record) => this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId)));
|
|
194
|
+
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
195
|
+
subscriptions = this.mergeSubs(subscriptions);
|
|
196
|
+
}
|
|
197
|
+
return (options === null || options === void 0 ? void 0 : options.unexpiredOnly) ? this.removeExpiredSubscriptions(subscriptions) : subscriptions;
|
|
198
|
+
}
|
|
187
199
|
getSubscriptionsFor(addresses, options) {
|
|
188
200
|
return __awaiter(this, void 0, void 0, function* () {
|
|
189
201
|
return this._getSubscriptions(addresses, options);
|
|
@@ -688,4 +688,55 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
688
688
|
expect(loneBoost === null || loneBoost === void 0 ? void 0 : loneBoost.subId).to.equal(1);
|
|
689
689
|
});
|
|
690
690
|
}));
|
|
691
|
+
describe('When testing StrategiesAutomation.parseSubscriptionsFromApi', () => {
|
|
692
|
+
const strategiesAutomation = new StrategiesAutomation({
|
|
693
|
+
chainId: ChainId.Ethereum,
|
|
694
|
+
provider: Web3_1,
|
|
695
|
+
providerFork: null,
|
|
696
|
+
});
|
|
697
|
+
const owner = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
|
|
698
|
+
const subData = [
|
|
699
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
700
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
701
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
702
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
703
|
+
];
|
|
704
|
+
// Aave V3 leverage management: repay (bundle 8, ratio under) and boost (bundle 9, ratio over) for the same owner and market
|
|
705
|
+
const repay = {
|
|
706
|
+
id: 379,
|
|
707
|
+
wallet: owner,
|
|
708
|
+
wallet_type: 'safe',
|
|
709
|
+
is_enabled: true,
|
|
710
|
+
is_bundle: true,
|
|
711
|
+
strategy_or_bundle_id: 8,
|
|
712
|
+
strategy_ids: [34, 35],
|
|
713
|
+
sub_data_hash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
714
|
+
trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001'],
|
|
715
|
+
sub_data: subData,
|
|
716
|
+
block_number: 18015756,
|
|
717
|
+
additional_triggers: null,
|
|
718
|
+
};
|
|
719
|
+
const boost = Object.assign(Object.assign({}, repay), { id: 380, is_enabled: false, strategy_or_bundle_id: 9, sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111', trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'] });
|
|
720
|
+
it('Given API records should return parsed positions', () => {
|
|
721
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost]);
|
|
722
|
+
expect(positions).to.have.length(2);
|
|
723
|
+
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.subId)).to.eql([379, 380]);
|
|
724
|
+
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.isEnabled)).to.eql([true, false]);
|
|
725
|
+
});
|
|
726
|
+
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
727
|
+
var _a, _b;
|
|
728
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
729
|
+
expect(positions).to.have.length(1);
|
|
730
|
+
expect((_a = positions[0]) === null || _a === void 0 ? void 0 : _a.subIds).to.eql([379, 380]);
|
|
731
|
+
expect((_b = positions[0]) === null || _b === void 0 ? void 0 : _b.isEnabled).to.equal(true);
|
|
732
|
+
});
|
|
733
|
+
it('Given enabledOnly option should drop disabled records before parsing', () => {
|
|
734
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { enabledOnly: true });
|
|
735
|
+
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.subId)).to.eql([379]);
|
|
736
|
+
});
|
|
737
|
+
it('Given a record of an unknown strategy should return null for it', () => {
|
|
738
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([Object.assign(Object.assign({}, repay), { strategy_or_bundle_id: 9999 })]);
|
|
739
|
+
expect(positions).to.eql([null]);
|
|
740
|
+
});
|
|
741
|
+
});
|
|
691
742
|
});
|
package/esm/constants/index.js
CHANGED
|
@@ -101,11 +101,6 @@ export const MAINNET_STRATEGIES_INFO = {
|
|
|
101
101
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
102
102
|
protocol: PROTOCOLS.AaveV3,
|
|
103
103
|
},
|
|
104
|
-
[Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
|
|
105
|
-
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
|
|
106
|
-
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
107
|
-
protocol: PROTOCOLS.AaveV3,
|
|
108
|
-
},
|
|
109
104
|
[Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
|
|
110
105
|
strategyOrBundleId: Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
|
|
111
106
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
@@ -126,16 +121,6 @@ export const MAINNET_STRATEGIES_INFO = {
|
|
|
126
121
|
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
127
122
|
protocol: PROTOCOLS.Spark,
|
|
128
123
|
},
|
|
129
|
-
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH]: {
|
|
130
|
-
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
131
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
132
|
-
protocol: PROTOCOLS.AaveV3,
|
|
133
|
-
},
|
|
134
|
-
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
135
|
-
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
136
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
137
|
-
protocol: PROTOCOLS.AaveV3,
|
|
138
|
-
},
|
|
139
124
|
};
|
|
140
125
|
export const OPTIMISM_STRATEGIES_INFO = {
|
|
141
126
|
[Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -153,21 +138,6 @@ export const OPTIMISM_STRATEGIES_INFO = {
|
|
|
153
138
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
154
139
|
protocol: PROTOCOLS.AaveV3,
|
|
155
140
|
},
|
|
156
|
-
[Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
|
|
157
|
-
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
|
|
158
|
-
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
159
|
-
protocol: PROTOCOLS.AaveV3,
|
|
160
|
-
},
|
|
161
|
-
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
|
|
162
|
-
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
|
|
163
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
164
|
-
protocol: PROTOCOLS.AaveV3,
|
|
165
|
-
},
|
|
166
|
-
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
167
|
-
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
168
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
169
|
-
protocol: PROTOCOLS.AaveV3,
|
|
170
|
-
},
|
|
171
141
|
};
|
|
172
142
|
export const BASE_STRATEGIES_INFO = {
|
|
173
143
|
[Strategies.BaseIds.EXCHANGE_DCA]: {
|
|
@@ -185,21 +155,6 @@ export const BASE_STRATEGIES_INFO = {
|
|
|
185
155
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
186
156
|
protocol: PROTOCOLS.AaveV3,
|
|
187
157
|
},
|
|
188
|
-
[Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
|
|
189
|
-
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
|
|
190
|
-
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
191
|
-
protocol: PROTOCOLS.AaveV3,
|
|
192
|
-
},
|
|
193
|
-
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
|
|
194
|
-
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
|
|
195
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
196
|
-
protocol: PROTOCOLS.AaveV3,
|
|
197
|
-
},
|
|
198
|
-
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
199
|
-
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
200
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
201
|
-
protocol: PROTOCOLS.AaveV3,
|
|
202
|
-
},
|
|
203
158
|
};
|
|
204
159
|
export const ARBITRUM_STRATEGIES_INFO = {
|
|
205
160
|
[Strategies.ArbitrumIds.EXCHANGE_DCA]: {
|
|
@@ -217,21 +172,6 @@ export const ARBITRUM_STRATEGIES_INFO = {
|
|
|
217
172
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
218
173
|
protocol: PROTOCOLS.AaveV3,
|
|
219
174
|
},
|
|
220
|
-
[Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
|
|
221
|
-
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
|
|
222
|
-
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
223
|
-
protocol: PROTOCOLS.AaveV3,
|
|
224
|
-
},
|
|
225
|
-
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
|
|
226
|
-
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
|
|
227
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
228
|
-
protocol: PROTOCOLS.AaveV3,
|
|
229
|
-
},
|
|
230
|
-
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
231
|
-
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
232
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
233
|
-
protocol: PROTOCOLS.AaveV3,
|
|
234
|
-
},
|
|
235
175
|
};
|
|
236
176
|
export const STRATEGIES_INFO = {
|
|
237
177
|
[ChainId.Ethereum]: MAINNET_STRATEGIES_INFO,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiSubscriptionRecord, ParseData } from '../types';
|
|
2
|
+
import type { ChainId } from '../types/enums';
|
|
3
|
+
/**
|
|
4
|
+
* @description Maps a subscription record returned by the automation API to the data
|
|
5
|
+
* the parser expects from Subscribe events and SubStorage (trigger data is stored without 0x prefix)
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseDataFromApiSubscription(record: ApiSubscriptionRecord, chainId: ChainId): ParseData;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function addHexPrefix(value) {
|
|
2
|
+
return value.startsWith('0x') ? value : `0x${value}`;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* @description Maps a subscription record returned by the automation API to the data
|
|
6
|
+
* the parser expects from Subscribe events and SubStorage (trigger data is stored without 0x prefix)
|
|
7
|
+
*/
|
|
8
|
+
export function parseDataFromApiSubscription(record, chainId) {
|
|
9
|
+
return {
|
|
10
|
+
chainId,
|
|
11
|
+
blockNumber: record.block_number,
|
|
12
|
+
subscriptionEventData: {
|
|
13
|
+
subId: record.id.toString(),
|
|
14
|
+
proxy: record.wallet,
|
|
15
|
+
subHash: record.sub_data_hash,
|
|
16
|
+
subStruct: {
|
|
17
|
+
strategyOrBundleId: record.strategy_or_bundle_id.toString(),
|
|
18
|
+
isBundle: record.is_bundle,
|
|
19
|
+
triggerData: record.trigger_data.map(addHexPrefix),
|
|
20
|
+
subData: record.sub_data.map(addHexPrefix),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
strategiesSubsData: {
|
|
24
|
+
userProxy: record.wallet,
|
|
25
|
+
isEnabled: record.is_enabled,
|
|
26
|
+
strategySubHash: record.sub_data_hash,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../configuration';
|