@defisaver/automation-sdk 3.3.4 → 3.3.5
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 +20 -0
- package/cjs/services/strategiesService.js +11 -0
- package/cjs/services/strategySubService.d.ts +1 -0
- package/cjs/services/strategySubService.js +6 -0
- package/cjs/services/strategySubService.test.js +99 -0
- package/cjs/services/subDataService.d.ts +11 -0
- package/cjs/services/subDataService.js +32 -1
- package/cjs/services/subDataService.test.js +142 -0
- package/cjs/types/enums.d.ts +10 -5
- package/cjs/types/enums.js +5 -0
- package/esm/constants/index.js +20 -0
- package/esm/services/strategiesService.js +11 -0
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +6 -0
- package/esm/services/strategySubService.test.js +100 -1
- package/esm/services/subDataService.d.ts +11 -0
- package/esm/services/subDataService.js +31 -0
- package/esm/services/subDataService.test.js +142 -0
- package/esm/types/enums.d.ts +10 -5
- package/esm/types/enums.js +5 -0
- package/package.json +1 -1
- package/src/constants/index.ts +20 -0
- package/src/services/strategiesService.ts +13 -0
- package/src/services/strategySubService.test.ts +117 -1
- package/src/services/strategySubService.ts +21 -0
- package/src/services/subDataService.test.ts +146 -0
- package/src/services/subDataService.ts +49 -0
- package/src/types/enums.ts +5 -0
package/cjs/constants/index.js
CHANGED
|
@@ -101,6 +101,11 @@ exports.MAINNET_STRATEGIES_INFO = {
|
|
|
101
101
|
strategyId: enums_1.Strategies.Identifiers.Payback,
|
|
102
102
|
protocol: exports.PROTOCOLS.LiquityV2,
|
|
103
103
|
},
|
|
104
|
+
[enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH]: {
|
|
105
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
106
|
+
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
107
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
108
|
+
},
|
|
104
109
|
};
|
|
105
110
|
exports.OPTIMISM_STRATEGIES_INFO = {
|
|
106
111
|
[enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -113,6 +118,11 @@ exports.OPTIMISM_STRATEGIES_INFO = {
|
|
|
113
118
|
strategyId: enums_1.Strategies.Identifiers.LimitOrder,
|
|
114
119
|
protocol: exports.PROTOCOLS.Exchange,
|
|
115
120
|
},
|
|
121
|
+
[enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH]: {
|
|
122
|
+
strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
123
|
+
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
124
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
125
|
+
},
|
|
116
126
|
};
|
|
117
127
|
exports.BASE_STRATEGIES_INFO = {
|
|
118
128
|
[enums_1.Strategies.BaseIds.EXCHANGE_DCA]: {
|
|
@@ -125,6 +135,11 @@ exports.BASE_STRATEGIES_INFO = {
|
|
|
125
135
|
strategyId: enums_1.Strategies.Identifiers.LimitOrder,
|
|
126
136
|
protocol: exports.PROTOCOLS.Exchange,
|
|
127
137
|
},
|
|
138
|
+
[enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH]: {
|
|
139
|
+
strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
140
|
+
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
141
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
142
|
+
},
|
|
128
143
|
};
|
|
129
144
|
exports.ARBITRUM_STRATEGIES_INFO = {
|
|
130
145
|
[enums_1.Strategies.ArbitrumIds.EXCHANGE_DCA]: {
|
|
@@ -137,6 +152,11 @@ exports.ARBITRUM_STRATEGIES_INFO = {
|
|
|
137
152
|
strategyId: enums_1.Strategies.Identifiers.LimitOrder,
|
|
138
153
|
protocol: exports.PROTOCOLS.Exchange,
|
|
139
154
|
},
|
|
155
|
+
[enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH]: {
|
|
156
|
+
strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
157
|
+
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
158
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
159
|
+
},
|
|
140
160
|
};
|
|
141
161
|
exports.STRATEGIES_INFO = {
|
|
142
162
|
[enums_1.ChainId.Ethereum]: exports.MAINNET_STRATEGIES_INFO,
|
|
@@ -307,6 +307,16 @@ function parseAaveV3CloseOnPrice(position, parseData) {
|
|
|
307
307
|
}
|
|
308
308
|
return _position;
|
|
309
309
|
}
|
|
310
|
+
function parseAaveV3CollateralSwitch(position, parseData) {
|
|
311
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
312
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
313
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
314
|
+
const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
315
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
316
|
+
_position.strategyData.decoded.subData = subData;
|
|
317
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
318
|
+
return _position;
|
|
319
|
+
}
|
|
310
320
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
311
321
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
312
322
|
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
@@ -904,6 +914,7 @@ const parsingMethodsMapping = {
|
|
|
904
914
|
[enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
905
915
|
[enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
906
916
|
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
917
|
+
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
907
918
|
},
|
|
908
919
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
909
920
|
[enums_1.Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
@@ -63,6 +63,7 @@ export declare const aaveV3Encode: {
|
|
|
63
63
|
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, isGeneric?: boolean): (number | boolean | string[])[];
|
|
64
64
|
leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
|
|
65
65
|
closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
66
|
+
collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
66
67
|
};
|
|
67
68
|
export declare const compoundV2Encode: {
|
|
68
69
|
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string[];
|
|
@@ -194,6 +194,12 @@ exports.aaveV3Encode = {
|
|
|
194
194
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
195
195
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
196
196
|
},
|
|
197
|
+
collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
|
|
198
|
+
const isBundle = false;
|
|
199
|
+
const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
200
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
201
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
202
|
+
},
|
|
197
203
|
};
|
|
198
204
|
exports.compoundV2Encode = {
|
|
199
205
|
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
@@ -808,6 +808,105 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
808
808
|
});
|
|
809
809
|
});
|
|
810
810
|
});
|
|
811
|
+
describe('collateralSwitch()', () => {
|
|
812
|
+
const examples = [
|
|
813
|
+
// WETH -> USDC, price 100000, state UNDER
|
|
814
|
+
[
|
|
815
|
+
[
|
|
816
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
817
|
+
false,
|
|
818
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
819
|
+
[
|
|
820
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
821
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
822
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
823
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
824
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
825
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
826
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
827
|
+
],
|
|
828
|
+
],
|
|
829
|
+
[
|
|
830
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
831
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
832
|
+
0,
|
|
833
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
834
|
+
1,
|
|
835
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
836
|
+
'10000000000000000000',
|
|
837
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
838
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
839
|
+
100000,
|
|
840
|
+
enums_1.RatioState.UNDER,
|
|
841
|
+
]
|
|
842
|
+
],
|
|
843
|
+
// USDC -> WETH, price 0.00001, state OVER
|
|
844
|
+
[
|
|
845
|
+
[
|
|
846
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
847
|
+
false,
|
|
848
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000'],
|
|
849
|
+
[
|
|
850
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
851
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
852
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
853
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
854
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
855
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
856
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
857
|
+
],
|
|
858
|
+
],
|
|
859
|
+
[
|
|
860
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
861
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
862
|
+
1,
|
|
863
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
864
|
+
0,
|
|
865
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
866
|
+
tokens_1.MAXUINT,
|
|
867
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
868
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
869
|
+
0.00001,
|
|
870
|
+
enums_1.RatioState.OVER,
|
|
871
|
+
]
|
|
872
|
+
],
|
|
873
|
+
// WETH -> WBTC, price 1, state UNDER
|
|
874
|
+
[
|
|
875
|
+
[
|
|
876
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
877
|
+
false,
|
|
878
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000001'],
|
|
879
|
+
[
|
|
880
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
881
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
882
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
883
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
884
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
885
|
+
'0x0000000000000000000000000000000000000000000000004563918244f40000',
|
|
886
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
887
|
+
],
|
|
888
|
+
],
|
|
889
|
+
[
|
|
890
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
891
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
892
|
+
0,
|
|
893
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
894
|
+
2,
|
|
895
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
896
|
+
'5000000000000000000',
|
|
897
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
898
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
899
|
+
1,
|
|
900
|
+
enums_1.RatioState.UNDER,
|
|
901
|
+
]
|
|
902
|
+
],
|
|
903
|
+
];
|
|
904
|
+
examples.forEach(([expected, actual]) => {
|
|
905
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
906
|
+
(0, chai_1.expect)(strategySubService_1.aaveV3Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
907
|
+
});
|
|
908
|
+
});
|
|
909
|
+
});
|
|
811
910
|
});
|
|
812
911
|
describe('When testing strategySubService.compoundV2Encode', () => {
|
|
813
912
|
describe('leverageManagement()', () => {
|
|
@@ -82,6 +82,17 @@ export declare const aaveV3CloseGenericSubData: {
|
|
|
82
82
|
owner: EthereumAddress;
|
|
83
83
|
};
|
|
84
84
|
};
|
|
85
|
+
export declare const aaveV3CollateralSwitchSubData: {
|
|
86
|
+
encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
|
|
87
|
+
decode(subData: string[]): {
|
|
88
|
+
fromAsset: EthereumAddress;
|
|
89
|
+
fromAssetId: number;
|
|
90
|
+
toAsset: EthereumAddress;
|
|
91
|
+
toAssetId: number;
|
|
92
|
+
marketAddr: EthereumAddress;
|
|
93
|
+
amountToSwitch: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
85
96
|
export declare const aaveV3QuotePriceSubData: {
|
|
86
97
|
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress): string[];
|
|
87
98
|
decode(subData: string[]): {
|
|
@@ -3,7 +3,7 @@ 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.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
6
|
+
exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
9
9
|
const web3_utils_1 = require("web3-utils");
|
|
@@ -216,6 +216,37 @@ exports.aaveV3CloseGenericSubData = {
|
|
|
216
216
|
};
|
|
217
217
|
},
|
|
218
218
|
};
|
|
219
|
+
exports.aaveV3CollateralSwitchSubData = {
|
|
220
|
+
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
|
|
221
|
+
const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
|
|
222
|
+
const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
|
|
223
|
+
const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
|
|
224
|
+
const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
|
|
225
|
+
const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
226
|
+
const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
|
|
227
|
+
const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', useOnBehalf);
|
|
228
|
+
return [
|
|
229
|
+
encodedFromAsset,
|
|
230
|
+
encodedFromAssetId,
|
|
231
|
+
encodedToAsset,
|
|
232
|
+
encodedToAssetId,
|
|
233
|
+
encodedMarketAddr,
|
|
234
|
+
encodedAmountToSwitch,
|
|
235
|
+
encodedUseOnBehalf,
|
|
236
|
+
];
|
|
237
|
+
},
|
|
238
|
+
decode(subData) {
|
|
239
|
+
const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
240
|
+
const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
241
|
+
const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
242
|
+
const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
243
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
244
|
+
const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
245
|
+
return {
|
|
246
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
|
|
247
|
+
};
|
|
248
|
+
},
|
|
249
|
+
};
|
|
219
250
|
exports.aaveV3QuotePriceSubData = {
|
|
220
251
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
221
252
|
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
@@ -30,6 +30,7 @@ const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
|
30
30
|
const chai_1 = require("chai");
|
|
31
31
|
const tokens_1 = require("@defisaver/tokens");
|
|
32
32
|
const web3Utils = __importStar(require("web3-utils"));
|
|
33
|
+
const tokens_2 = require("@defisaver/tokens");
|
|
33
34
|
const enums_1 = require("../types/enums");
|
|
34
35
|
require("../configuration");
|
|
35
36
|
const subDataService = __importStar(require("./subDataService"));
|
|
@@ -358,6 +359,147 @@ describe('Feature: subDataService.ts', () => {
|
|
|
358
359
|
});
|
|
359
360
|
});
|
|
360
361
|
});
|
|
362
|
+
describe('When testing subDataService.aaveV3CollateralSwitchSubData', () => {
|
|
363
|
+
describe('encode()', () => {
|
|
364
|
+
const examples = [
|
|
365
|
+
// WETH -> USDC
|
|
366
|
+
[
|
|
367
|
+
[
|
|
368
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
369
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
370
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
371
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
372
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
373
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
374
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
375
|
+
],
|
|
376
|
+
[
|
|
377
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
378
|
+
0,
|
|
379
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
380
|
+
1,
|
|
381
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
382
|
+
'10000000000000000000',
|
|
383
|
+
false,
|
|
384
|
+
]
|
|
385
|
+
],
|
|
386
|
+
// USDC -> WETH (MaxUint256)
|
|
387
|
+
[
|
|
388
|
+
[
|
|
389
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
390
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
391
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
392
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
393
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
394
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
395
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
396
|
+
],
|
|
397
|
+
[
|
|
398
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
399
|
+
1,
|
|
400
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
401
|
+
0,
|
|
402
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
403
|
+
tokens_2.MAXUINT, // MaxUint256
|
|
404
|
+
]
|
|
405
|
+
],
|
|
406
|
+
// WETH -> WBTC
|
|
407
|
+
[
|
|
408
|
+
[
|
|
409
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
410
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
411
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
412
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
413
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
414
|
+
'0x0000000000000000000000000000000000000000000000004563918244f40000',
|
|
415
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
416
|
+
],
|
|
417
|
+
[
|
|
418
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
419
|
+
0,
|
|
420
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
421
|
+
2,
|
|
422
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
423
|
+
'5000000000000000000', // 5 WETH
|
|
424
|
+
]
|
|
425
|
+
],
|
|
426
|
+
];
|
|
427
|
+
examples.forEach(([expected, actual]) => {
|
|
428
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
429
|
+
(0, chai_1.expect)(subDataService.aaveV3CollateralSwitchSubData.encode(...actual)).to.eql(expected);
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
describe('decode()', () => {
|
|
434
|
+
const examples = [
|
|
435
|
+
// WETH -> USDC
|
|
436
|
+
[
|
|
437
|
+
{
|
|
438
|
+
fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
439
|
+
fromAssetId: 0,
|
|
440
|
+
toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
441
|
+
toAssetId: 1,
|
|
442
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
443
|
+
amountToSwitch: '10000000000000000000',
|
|
444
|
+
},
|
|
445
|
+
[
|
|
446
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
447
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
448
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
449
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
450
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
451
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
452
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
453
|
+
],
|
|
454
|
+
],
|
|
455
|
+
// USDC -> WETH (MaxUint256)
|
|
456
|
+
[
|
|
457
|
+
{
|
|
458
|
+
fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
459
|
+
fromAssetId: 1,
|
|
460
|
+
toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
461
|
+
toAssetId: 0,
|
|
462
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
463
|
+
amountToSwitch: tokens_2.MAXUINT,
|
|
464
|
+
},
|
|
465
|
+
[
|
|
466
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
467
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
468
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
469
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
470
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
471
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
472
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
473
|
+
],
|
|
474
|
+
],
|
|
475
|
+
// WETH -> WBTC
|
|
476
|
+
[
|
|
477
|
+
{
|
|
478
|
+
fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
479
|
+
fromAssetId: 0,
|
|
480
|
+
toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
481
|
+
toAssetId: 2,
|
|
482
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
483
|
+
amountToSwitch: '5000000000000000000',
|
|
484
|
+
},
|
|
485
|
+
[
|
|
486
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
487
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
488
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
489
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
490
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
491
|
+
'0x0000000000000000000000000000000000000000000000004563918244f40000',
|
|
492
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
493
|
+
],
|
|
494
|
+
],
|
|
495
|
+
];
|
|
496
|
+
examples.forEach(([expected, actual]) => {
|
|
497
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
498
|
+
(0, chai_1.expect)(subDataService.aaveV3CollateralSwitchSubData.decode(actual)).to.eql(expected);
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
});
|
|
361
503
|
describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
|
|
362
504
|
describe('encode()', () => {
|
|
363
505
|
const examples = [
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -85,19 +85,23 @@ export declare namespace Strategies {
|
|
|
85
85
|
LIQUITY_DSR_SUPPLY = 70,
|
|
86
86
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
87
87
|
CURVEUSD_PAYBACK = 92,
|
|
88
|
-
LIQUITY_V2_PAYBACK = 113
|
|
88
|
+
LIQUITY_V2_PAYBACK = 113,
|
|
89
|
+
AAVE_V3_COLLATERAL_SWITCH = 135
|
|
89
90
|
}
|
|
90
91
|
enum OptimismIds {
|
|
91
92
|
EXCHANGE_DCA = 8,
|
|
92
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
93
|
+
EXCHANGE_LIMIT_ORDER = 9,
|
|
94
|
+
AAVE_V3_COLLATERAL_SWITCH = 24
|
|
93
95
|
}
|
|
94
96
|
enum BaseIds {
|
|
95
97
|
EXCHANGE_DCA = 8,
|
|
96
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
98
|
+
EXCHANGE_LIMIT_ORDER = 9,
|
|
99
|
+
AAVE_V3_COLLATERAL_SWITCH = 56
|
|
97
100
|
}
|
|
98
101
|
enum ArbitrumIds {
|
|
99
102
|
EXCHANGE_DCA = 8,
|
|
100
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
103
|
+
EXCHANGE_LIMIT_ORDER = 9,
|
|
104
|
+
AAVE_V3_COLLATERAL_SWITCH = 50
|
|
101
105
|
}
|
|
102
106
|
enum Identifiers {
|
|
103
107
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
|
@@ -128,7 +132,8 @@ export declare namespace Strategies {
|
|
|
128
132
|
BoostOnPrice = "boost-on-price",
|
|
129
133
|
RepayOnPrice = "repay-on-price",
|
|
130
134
|
EoaBoostOnPrice = "eoa-boost-on-price",
|
|
131
|
-
EoaRepayOnPrice = "eoa-repay-on-price"
|
|
135
|
+
EoaRepayOnPrice = "eoa-repay-on-price",
|
|
136
|
+
CollateralSwitch = "collateral-switch"
|
|
132
137
|
}
|
|
133
138
|
enum IdOverrides {
|
|
134
139
|
TakeProfit = "take-profit",
|
package/cjs/types/enums.js
CHANGED
|
@@ -102,21 +102,25 @@ var Strategies;
|
|
|
102
102
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
103
103
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
104
104
|
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
105
|
+
MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
105
106
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
106
107
|
let OptimismIds;
|
|
107
108
|
(function (OptimismIds) {
|
|
108
109
|
OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
109
110
|
OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
111
|
+
OptimismIds[OptimismIds["AAVE_V3_COLLATERAL_SWITCH"] = 24] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
110
112
|
})(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
|
|
111
113
|
let BaseIds;
|
|
112
114
|
(function (BaseIds) {
|
|
113
115
|
BaseIds[BaseIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
114
116
|
BaseIds[BaseIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
117
|
+
BaseIds[BaseIds["AAVE_V3_COLLATERAL_SWITCH"] = 56] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
115
118
|
})(BaseIds = Strategies.BaseIds || (Strategies.BaseIds = {}));
|
|
116
119
|
let ArbitrumIds;
|
|
117
120
|
(function (ArbitrumIds) {
|
|
118
121
|
ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
119
122
|
ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
123
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_COLLATERAL_SWITCH"] = 50] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
120
124
|
})(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
|
|
121
125
|
let Identifiers;
|
|
122
126
|
(function (Identifiers) {
|
|
@@ -149,6 +153,7 @@ var Strategies;
|
|
|
149
153
|
Identifiers["RepayOnPrice"] = "repay-on-price";
|
|
150
154
|
Identifiers["EoaBoostOnPrice"] = "eoa-boost-on-price";
|
|
151
155
|
Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
|
|
156
|
+
Identifiers["CollateralSwitch"] = "collateral-switch";
|
|
152
157
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
153
158
|
let IdOverrides;
|
|
154
159
|
(function (IdOverrides) {
|
package/esm/constants/index.js
CHANGED
|
@@ -95,6 +95,11 @@ export const MAINNET_STRATEGIES_INFO = {
|
|
|
95
95
|
strategyId: Strategies.Identifiers.Payback,
|
|
96
96
|
protocol: PROTOCOLS.LiquityV2,
|
|
97
97
|
},
|
|
98
|
+
[Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH]: {
|
|
99
|
+
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
100
|
+
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
101
|
+
protocol: PROTOCOLS.AaveV3,
|
|
102
|
+
},
|
|
98
103
|
};
|
|
99
104
|
export const OPTIMISM_STRATEGIES_INFO = {
|
|
100
105
|
[Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -107,6 +112,11 @@ export const OPTIMISM_STRATEGIES_INFO = {
|
|
|
107
112
|
strategyId: Strategies.Identifiers.LimitOrder,
|
|
108
113
|
protocol: PROTOCOLS.Exchange,
|
|
109
114
|
},
|
|
115
|
+
[Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH]: {
|
|
116
|
+
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
117
|
+
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
118
|
+
protocol: PROTOCOLS.AaveV3,
|
|
119
|
+
},
|
|
110
120
|
};
|
|
111
121
|
export const BASE_STRATEGIES_INFO = {
|
|
112
122
|
[Strategies.BaseIds.EXCHANGE_DCA]: {
|
|
@@ -119,6 +129,11 @@ export const BASE_STRATEGIES_INFO = {
|
|
|
119
129
|
strategyId: Strategies.Identifiers.LimitOrder,
|
|
120
130
|
protocol: PROTOCOLS.Exchange,
|
|
121
131
|
},
|
|
132
|
+
[Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH]: {
|
|
133
|
+
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
134
|
+
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
135
|
+
protocol: PROTOCOLS.AaveV3,
|
|
136
|
+
},
|
|
122
137
|
};
|
|
123
138
|
export const ARBITRUM_STRATEGIES_INFO = {
|
|
124
139
|
[Strategies.ArbitrumIds.EXCHANGE_DCA]: {
|
|
@@ -131,6 +146,11 @@ export const ARBITRUM_STRATEGIES_INFO = {
|
|
|
131
146
|
strategyId: Strategies.Identifiers.LimitOrder,
|
|
132
147
|
protocol: PROTOCOLS.Exchange,
|
|
133
148
|
},
|
|
149
|
+
[Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH]: {
|
|
150
|
+
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
151
|
+
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
152
|
+
protocol: PROTOCOLS.AaveV3,
|
|
153
|
+
},
|
|
134
154
|
};
|
|
135
155
|
export const STRATEGIES_INFO = {
|
|
136
156
|
[ChainId.Ethereum]: MAINNET_STRATEGIES_INFO,
|
|
@@ -278,6 +278,16 @@ function parseAaveV3CloseOnPrice(position, parseData) {
|
|
|
278
278
|
}
|
|
279
279
|
return _position;
|
|
280
280
|
}
|
|
281
|
+
function parseAaveV3CollateralSwitch(position, parseData) {
|
|
282
|
+
const _position = cloneDeep(position);
|
|
283
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
284
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
285
|
+
const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
286
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
287
|
+
_position.strategyData.decoded.subData = subData;
|
|
288
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
289
|
+
return _position;
|
|
290
|
+
}
|
|
281
291
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
282
292
|
const _position = cloneDeep(position);
|
|
283
293
|
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
@@ -875,6 +885,7 @@ const parsingMethodsMapping = {
|
|
|
875
885
|
[Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
876
886
|
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
877
887
|
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
888
|
+
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
878
889
|
},
|
|
879
890
|
[ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
880
891
|
[Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
@@ -63,6 +63,7 @@ export declare const aaveV3Encode: {
|
|
|
63
63
|
leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, isGeneric?: boolean): (number | boolean | string[])[];
|
|
64
64
|
leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
|
|
65
65
|
closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
66
|
+
collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
66
67
|
};
|
|
67
68
|
export declare const compoundV2Encode: {
|
|
68
69
|
leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string[];
|
|
@@ -165,6 +165,12 @@ export const aaveV3Encode = {
|
|
|
165
165
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
166
166
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
167
167
|
},
|
|
168
|
+
collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
|
|
169
|
+
const isBundle = false;
|
|
170
|
+
const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
171
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
172
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
173
|
+
},
|
|
168
174
|
};
|
|
169
175
|
export const compoundV2Encode = {
|
|
170
176
|
leverageManagement(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|