@defisaver/automation-sdk 3.3.21-debt-switch-dev-dev → 3.3.22-coll-switch-generic-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/constants/index.js +20 -0
- package/cjs/services/strategiesService.js +8 -1
- package/cjs/services/strategiesService.test.js +92 -0
- package/cjs/services/strategySubService.d.ts +1 -0
- package/cjs/services/strategySubService.js +6 -0
- package/cjs/services/strategySubService.test.js +36 -0
- package/cjs/services/subDataService.d.ts +12 -0
- package/cjs/services/subDataService.js +34 -2
- package/cjs/services/subDataService.test.js +35 -0
- package/cjs/types/enums.d.ts +8 -4
- package/cjs/types/enums.js +4 -0
- package/esm/constants/index.js +20 -0
- package/esm/services/strategiesService.js +8 -1
- package/esm/services/strategiesService.test.js +93 -1
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +6 -0
- package/esm/services/strategySubService.test.js +36 -0
- package/esm/services/subDataService.d.ts +12 -0
- package/esm/services/subDataService.js +32 -0
- package/esm/services/subDataService.test.js +35 -0
- package/esm/types/enums.d.ts +8 -4
- package/esm/types/enums.js +4 -0
- package/package.json +1 -1
- package/src/constants/index.ts +20 -0
- package/src/services/strategiesService.test.ts +102 -1
- package/src/services/strategiesService.ts +8 -1
- package/src/services/strategySubService.test.ts +42 -0
- package/src/services/strategySubService.ts +24 -0
- package/src/services/subDataService.test.ts +41 -0
- package/src/services/subDataService.ts +51 -0
- package/src/types/enums.ts +4 -0
package/cjs/constants/index.js
CHANGED
|
@@ -107,6 +107,11 @@ exports.MAINNET_STRATEGIES_INFO = {
|
|
|
107
107
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
108
108
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
109
109
|
},
|
|
110
|
+
[enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
|
|
111
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
|
|
112
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
|
|
113
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
114
|
+
},
|
|
110
115
|
[enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
|
|
111
116
|
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
|
|
112
117
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
@@ -154,6 +159,11 @@ exports.OPTIMISM_STRATEGIES_INFO = {
|
|
|
154
159
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
155
160
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
156
161
|
},
|
|
162
|
+
[enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
|
|
163
|
+
strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
|
|
164
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
|
|
165
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
166
|
+
},
|
|
157
167
|
[enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
|
|
158
168
|
strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
|
|
159
169
|
strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
|
|
@@ -181,6 +191,11 @@ exports.BASE_STRATEGIES_INFO = {
|
|
|
181
191
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
182
192
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
183
193
|
},
|
|
194
|
+
[enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
|
|
195
|
+
strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
|
|
196
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
|
|
197
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
198
|
+
},
|
|
184
199
|
[enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
|
|
185
200
|
strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
|
|
186
201
|
strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
|
|
@@ -208,6 +223,11 @@ exports.ARBITRUM_STRATEGIES_INFO = {
|
|
|
208
223
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
209
224
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
210
225
|
},
|
|
226
|
+
[enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA]: {
|
|
227
|
+
strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA,
|
|
228
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
|
|
229
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
230
|
+
},
|
|
211
231
|
[enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
|
|
212
232
|
strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
|
|
213
233
|
strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
|
|
@@ -349,11 +349,17 @@ function parseAaveV3CloseOnPrice(position, parseData) {
|
|
|
349
349
|
function parseAaveV3CollateralSwitch(position, parseData) {
|
|
350
350
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
351
351
|
const { subStruct } = parseData.subscriptionEventData;
|
|
352
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
352
353
|
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
353
|
-
const subData =
|
|
354
|
+
const subData = isEOA
|
|
355
|
+
? subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subStruct.subData)
|
|
356
|
+
: subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
354
357
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
355
358
|
_position.strategyData.decoded.subData = subData;
|
|
356
359
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
360
|
+
_position.strategy.strategyId = isEOA
|
|
361
|
+
? enums_1.Strategies.Identifiers.EoaCollateralSwitch
|
|
362
|
+
: enums_1.Strategies.Identifiers.CollateralSwitch;
|
|
357
363
|
return _position;
|
|
358
364
|
}
|
|
359
365
|
function parseAaveV3DebtSwitch(position, parseData) {
|
|
@@ -1257,6 +1263,7 @@ const parsingMethodsMapping = {
|
|
|
1257
1263
|
[enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1258
1264
|
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1259
1265
|
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1266
|
+
[enums_1.Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1260
1267
|
[enums_1.Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
|
|
1261
1268
|
[enums_1.Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
|
|
1262
1269
|
[enums_1.Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
@@ -14,6 +14,98 @@ const enums_1 = require("../types/enums");
|
|
|
14
14
|
require("../configuration");
|
|
15
15
|
const strategiesService_1 = require("./strategiesService");
|
|
16
16
|
describe('Feature: strategiesService.ts', () => {
|
|
17
|
+
describe('When parsing Aave V3 collateral switch subscriptions', () => {
|
|
18
|
+
const proxy = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
|
|
19
|
+
const user = '0x1234567890123456789012345678901234567890';
|
|
20
|
+
const fromAsset = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
21
|
+
const toAsset = '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf';
|
|
22
|
+
const marketAddr = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
|
|
23
|
+
const amountToSwitch = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
24
|
+
const subHash = `0x${'ab'.repeat(32)}`;
|
|
25
|
+
const triggerData = [
|
|
26
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
|
27
|
+
+ '000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf'
|
|
28
|
+
+ '0000000000000000000000000000000000000000000000000000000000989680'
|
|
29
|
+
+ '0000000000000000000000000000000000000000000000000000000000000001',
|
|
30
|
+
];
|
|
31
|
+
function getParseData(strategyId, isGeneric, chainId = enums_1.ChainId.Ethereum) {
|
|
32
|
+
const subData = [
|
|
33
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
34
|
+
isGeneric
|
|
35
|
+
? '0x0000000000000000000000000000000000000000000000000000000000000100'
|
|
36
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
37
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
38
|
+
isGeneric
|
|
39
|
+
? '0x000000000000000000000000000000000000000000000000000000000000ffff'
|
|
40
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
41
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
42
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
43
|
+
isGeneric
|
|
44
|
+
? '0x0000000000000000000000001234567890123456789012345678901234567890'
|
|
45
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
46
|
+
];
|
|
47
|
+
const subStruct = Object.assign([String(strategyId), false, triggerData, subData], { strategyOrBundleId: String(strategyId), isBundle: false, triggerData, subData });
|
|
48
|
+
return {
|
|
49
|
+
chainId,
|
|
50
|
+
blockNumber: 18015756,
|
|
51
|
+
subscriptionEventData: {
|
|
52
|
+
subId: '379', proxy, subHash, subStruct,
|
|
53
|
+
0: '379', 1: proxy, 2: subHash, 3: subStruct,
|
|
54
|
+
},
|
|
55
|
+
strategiesSubsData: {
|
|
56
|
+
userProxy: proxy, isEnabled: true, strategySubHash: subHash,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const genericStrategies = [
|
|
61
|
+
[enums_1.ChainId.Ethereum, enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
|
|
62
|
+
[enums_1.ChainId.Optimism, enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
|
|
63
|
+
[enums_1.ChainId.Arbitrum, enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
|
|
64
|
+
[enums_1.ChainId.Base, enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
|
|
65
|
+
];
|
|
66
|
+
genericStrategies.forEach(([chainId, strategyId]) => {
|
|
67
|
+
it(`decodes generic collateral switches with the user and uint16 reserve IDs on chain ${chainId}`, () => {
|
|
68
|
+
const parseData = getParseData(strategyId, true, chainId);
|
|
69
|
+
const position = (0, strategiesService_1.parseStrategiesAutomatedPosition)(parseData);
|
|
70
|
+
(0, chai_1.expect)(position).not.to.equal(null);
|
|
71
|
+
(0, chai_1.expect)(position.protocol.id).to.equal(enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV3);
|
|
72
|
+
(0, chai_1.expect)(position.strategy.strategyId).to.equal(enums_1.Strategies.Identifiers.EoaCollateralSwitch);
|
|
73
|
+
(0, chai_1.expect)(position.strategy.isBundle).to.equal(false);
|
|
74
|
+
(0, chai_1.expect)(position.strategyData.encoded).to.eql({
|
|
75
|
+
triggerData,
|
|
76
|
+
subData: parseData.subscriptionEventData.subStruct.subData,
|
|
77
|
+
});
|
|
78
|
+
(0, chai_1.expect)(position.strategyData.decoded.triggerData).to.eql({
|
|
79
|
+
baseTokenAddress: fromAsset,
|
|
80
|
+
quoteTokenAddress: toAsset,
|
|
81
|
+
price: '0.1',
|
|
82
|
+
ratioState: enums_1.RatioState.UNDER,
|
|
83
|
+
});
|
|
84
|
+
(0, chai_1.expect)(position.strategyData.decoded.subData).to.eql({
|
|
85
|
+
fromAsset, fromAssetId: 256, toAsset, toAssetId: 65535, marketAddr, amountToSwitch, user,
|
|
86
|
+
});
|
|
87
|
+
(0, chai_1.expect)(position.owner).to.equal(proxy.toLowerCase());
|
|
88
|
+
(0, chai_1.expect)(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
const legacyStrategies = [
|
|
92
|
+
[enums_1.ChainId.Ethereum, enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
93
|
+
[enums_1.ChainId.Optimism, enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
94
|
+
[enums_1.ChainId.Arbitrum, enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
95
|
+
[enums_1.ChainId.Base, enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
96
|
+
];
|
|
97
|
+
legacyStrategies.forEach(([chainId, strategyId]) => {
|
|
98
|
+
it(`continues to decode legacy collateral switches on chain ${chainId}`, () => {
|
|
99
|
+
const position = (0, strategiesService_1.parseStrategiesAutomatedPosition)(getParseData(strategyId, false, chainId));
|
|
100
|
+
(0, chai_1.expect)(position).not.to.equal(null);
|
|
101
|
+
(0, chai_1.expect)(position.strategy.strategyId).to.equal(enums_1.Strategies.Identifiers.CollateralSwitch);
|
|
102
|
+
(0, chai_1.expect)(position.strategyData.decoded.subData).to.eql({
|
|
103
|
+
fromAsset, fromAssetId: 0, toAsset, toAssetId: 7, marketAddr, amountToSwitch,
|
|
104
|
+
});
|
|
105
|
+
(0, chai_1.expect)(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
17
109
|
describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
110
|
// TODO: we should probably write this for every strategy?
|
|
19
111
|
const examples = [
|
|
@@ -62,6 +62,7 @@ export declare const aaveV3Encode: {
|
|
|
62
62
|
leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
|
|
63
63
|
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[])[];
|
|
64
64
|
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[])[];
|
|
65
|
+
collateralSwitchGeneric(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
65
66
|
debtSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
66
67
|
};
|
|
67
68
|
export declare const compoundV2Encode: {
|
|
@@ -196,6 +196,12 @@ exports.aaveV3Encode = {
|
|
|
196
196
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
197
197
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
198
198
|
},
|
|
199
|
+
collateralSwitchGeneric(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
|
|
200
|
+
const isBundle = false;
|
|
201
|
+
const subDataEncoded = subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
|
|
202
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
203
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
204
|
+
},
|
|
199
205
|
debtSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
|
|
200
206
|
const isBundle = false;
|
|
201
207
|
const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
|
|
@@ -856,6 +856,42 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
856
856
|
});
|
|
857
857
|
});
|
|
858
858
|
});
|
|
859
|
+
describe('collateralSwitchGeneric()', () => {
|
|
860
|
+
const strategyId = 12345;
|
|
861
|
+
const fromAsset = web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address);
|
|
862
|
+
const toAsset = web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address);
|
|
863
|
+
const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
864
|
+
const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
|
|
865
|
+
const examples = [
|
|
866
|
+
[
|
|
867
|
+
enums_1.RatioState.UNDER,
|
|
868
|
+
'10000000000000000000',
|
|
869
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
870
|
+
'0000000000000000000000000000000000000000000000000000000000000001',
|
|
871
|
+
],
|
|
872
|
+
[
|
|
873
|
+
enums_1.RatioState.OVER,
|
|
874
|
+
tokens_1.MAXUINT,
|
|
875
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
876
|
+
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
877
|
+
],
|
|
878
|
+
];
|
|
879
|
+
examples.forEach(([state, amountToSwitch, encodedAmount, encodedState]) => {
|
|
880
|
+
it(`encodes a generic collateral switch with the supplied quote pair and state ${state}`, () => {
|
|
881
|
+
const expectedTrigger = `0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e8${encodedState}`;
|
|
882
|
+
const expectedSubData = [
|
|
883
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
884
|
+
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
885
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
886
|
+
'0x000000000000000000000000000000000000000000000000000000000000ffff',
|
|
887
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
888
|
+
encodedAmount,
|
|
889
|
+
'0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
|
|
890
|
+
];
|
|
891
|
+
(0, chai_1.expect)(strategySubService_1.aaveV3Encode.collateralSwitchGeneric(strategyId, fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user, toAsset, fromAsset, 0.00001, state)).to.eql([strategyId, false, [expectedTrigger], expectedSubData]);
|
|
892
|
+
});
|
|
893
|
+
});
|
|
894
|
+
});
|
|
859
895
|
describe('debtSwitch()', () => {
|
|
860
896
|
const examples = [
|
|
861
897
|
// USDC -> DAI, price 100000, state UNDER
|
|
@@ -259,6 +259,18 @@ export declare const aaveV3CollateralSwitchSubData: {
|
|
|
259
259
|
amountToSwitch: string;
|
|
260
260
|
};
|
|
261
261
|
};
|
|
262
|
+
export declare const aaveV3GenericFLCollateralSwitchSubData: {
|
|
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 aaveV3DebtSwitchSubData: {
|
|
263
275
|
encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
|
|
264
276
|
decode(subData: string[]): {
|
|
@@ -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.
|
|
7
|
-
exports.fluidLiquidationProtectionSubData = exports.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLiquidationProtectionSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkGenericFLCollateralSwitchSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceGenericSubData = exports.sparkLeverageManagementOnPriceSubData = void 0;
|
|
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.aaveV3DebtSwitchSubData = exports.aaveV3GenericFLCollateralSwitchSubData = 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 = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = 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,6 +549,38 @@ 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
|
+
};
|
|
552
584
|
exports.aaveV3DebtSwitchSubData = {
|
|
553
585
|
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
|
|
554
586
|
const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
|
|
@@ -639,6 +639,41 @@ describe('Feature: subDataService.ts', () => {
|
|
|
639
639
|
});
|
|
640
640
|
});
|
|
641
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
|
+
});
|
|
642
677
|
describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
|
|
643
678
|
describe('encode()', () => {
|
|
644
679
|
const examples = [
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -93,28 +93,32 @@ export declare namespace Strategies {
|
|
|
93
93
|
SPARK_COLLATERAL_SWITCH = 156,
|
|
94
94
|
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
|
|
95
95
|
AAVE_V3_DEBT_SWITCH = 168,
|
|
96
|
-
AAVE_V3_DEBT_SWITCH_EOA = 169
|
|
96
|
+
AAVE_V3_DEBT_SWITCH_EOA = 169,
|
|
97
|
+
AAVE_V3_COLLATERAL_SWITCH_EOA = 170
|
|
97
98
|
}
|
|
98
99
|
enum OptimismIds {
|
|
99
100
|
EXCHANGE_DCA = 8,
|
|
100
101
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
101
102
|
AAVE_V3_COLLATERAL_SWITCH = 24,
|
|
102
103
|
AAVE_V3_DEBT_SWITCH = 25,
|
|
103
|
-
AAVE_V3_DEBT_SWITCH_EOA = 26
|
|
104
|
+
AAVE_V3_DEBT_SWITCH_EOA = 26,
|
|
105
|
+
AAVE_V3_COLLATERAL_SWITCH_EOA = 27
|
|
104
106
|
}
|
|
105
107
|
enum BaseIds {
|
|
106
108
|
EXCHANGE_DCA = 8,
|
|
107
109
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
108
110
|
AAVE_V3_COLLATERAL_SWITCH = 56,
|
|
109
111
|
AAVE_V3_DEBT_SWITCH = 61,
|
|
110
|
-
AAVE_V3_DEBT_SWITCH_EOA = 62
|
|
112
|
+
AAVE_V3_DEBT_SWITCH_EOA = 62,
|
|
113
|
+
AAVE_V3_COLLATERAL_SWITCH_EOA = 63
|
|
111
114
|
}
|
|
112
115
|
enum ArbitrumIds {
|
|
113
116
|
EXCHANGE_DCA = 8,
|
|
114
117
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
115
118
|
AAVE_V3_COLLATERAL_SWITCH = 50,
|
|
116
119
|
AAVE_V3_DEBT_SWITCH = 55,
|
|
117
|
-
AAVE_V3_DEBT_SWITCH_EOA = 56
|
|
120
|
+
AAVE_V3_DEBT_SWITCH_EOA = 56,
|
|
121
|
+
AAVE_V3_COLLATERAL_SWITCH_EOA = 57
|
|
118
122
|
}
|
|
119
123
|
enum Identifiers {
|
|
120
124
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
package/cjs/types/enums.js
CHANGED
|
@@ -110,6 +110,7 @@ var Strategies;
|
|
|
110
110
|
MainnetIds[MainnetIds["SPARK_GENERIC_FL_COLLATERAL_SWITCH"] = 167] = "SPARK_GENERIC_FL_COLLATERAL_SWITCH";
|
|
111
111
|
MainnetIds[MainnetIds["AAVE_V3_DEBT_SWITCH"] = 168] = "AAVE_V3_DEBT_SWITCH";
|
|
112
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";
|
|
113
114
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
114
115
|
let OptimismIds;
|
|
115
116
|
(function (OptimismIds) {
|
|
@@ -118,6 +119,7 @@ var Strategies;
|
|
|
118
119
|
OptimismIds[OptimismIds["AAVE_V3_COLLATERAL_SWITCH"] = 24] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
119
120
|
OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH"] = 25] = "AAVE_V3_DEBT_SWITCH";
|
|
120
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";
|
|
121
123
|
})(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
|
|
122
124
|
let BaseIds;
|
|
123
125
|
(function (BaseIds) {
|
|
@@ -126,6 +128,7 @@ var Strategies;
|
|
|
126
128
|
BaseIds[BaseIds["AAVE_V3_COLLATERAL_SWITCH"] = 56] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
127
129
|
BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH"] = 61] = "AAVE_V3_DEBT_SWITCH";
|
|
128
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";
|
|
129
132
|
})(BaseIds = Strategies.BaseIds || (Strategies.BaseIds = {}));
|
|
130
133
|
let ArbitrumIds;
|
|
131
134
|
(function (ArbitrumIds) {
|
|
@@ -134,6 +137,7 @@ var Strategies;
|
|
|
134
137
|
ArbitrumIds[ArbitrumIds["AAVE_V3_COLLATERAL_SWITCH"] = 50] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
135
138
|
ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH"] = 55] = "AAVE_V3_DEBT_SWITCH";
|
|
136
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";
|
|
137
141
|
})(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
|
|
138
142
|
let Identifiers;
|
|
139
143
|
(function (Identifiers) {
|
package/esm/constants/index.js
CHANGED
|
@@ -101,6 +101,11 @@ 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
|
+
},
|
|
104
109
|
[Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
|
|
105
110
|
strategyOrBundleId: Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
|
|
106
111
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
@@ -148,6 +153,11 @@ export const OPTIMISM_STRATEGIES_INFO = {
|
|
|
148
153
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
149
154
|
protocol: PROTOCOLS.AaveV3,
|
|
150
155
|
},
|
|
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
|
+
},
|
|
151
161
|
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
|
|
152
162
|
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
|
|
153
163
|
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
@@ -175,6 +185,11 @@ export const BASE_STRATEGIES_INFO = {
|
|
|
175
185
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
176
186
|
protocol: PROTOCOLS.AaveV3,
|
|
177
187
|
},
|
|
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
|
+
},
|
|
178
193
|
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
|
|
179
194
|
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
|
|
180
195
|
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
@@ -202,6 +217,11 @@ export const ARBITRUM_STRATEGIES_INFO = {
|
|
|
202
217
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
203
218
|
protocol: PROTOCOLS.AaveV3,
|
|
204
219
|
},
|
|
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
|
+
},
|
|
205
225
|
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
|
|
206
226
|
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
|
|
207
227
|
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
@@ -320,11 +320,17 @@ function parseAaveV3CloseOnPrice(position, parseData) {
|
|
|
320
320
|
function parseAaveV3CollateralSwitch(position, parseData) {
|
|
321
321
|
const _position = cloneDeep(position);
|
|
322
322
|
const { subStruct } = parseData.subscriptionEventData;
|
|
323
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
323
324
|
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
324
|
-
const subData =
|
|
325
|
+
const subData = isEOA
|
|
326
|
+
? subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subStruct.subData)
|
|
327
|
+
: subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
325
328
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
326
329
|
_position.strategyData.decoded.subData = subData;
|
|
327
330
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
331
|
+
_position.strategy.strategyId = isEOA
|
|
332
|
+
? Strategies.Identifiers.EoaCollateralSwitch
|
|
333
|
+
: Strategies.Identifiers.CollateralSwitch;
|
|
328
334
|
return _position;
|
|
329
335
|
}
|
|
330
336
|
function parseAaveV3DebtSwitch(position, parseData) {
|
|
@@ -1228,6 +1234,7 @@ const parsingMethodsMapping = {
|
|
|
1228
1234
|
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1229
1235
|
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1230
1236
|
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1237
|
+
[Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1231
1238
|
[Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
|
|
1232
1239
|
[Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
|
|
1233
1240
|
[Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
@@ -8,10 +8,102 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { expect } from 'chai';
|
|
11
|
-
import { ProtocolIdentifiers, Strategies } from '../types/enums';
|
|
11
|
+
import { ChainId, ProtocolIdentifiers, RatioState, Strategies } from '../types/enums';
|
|
12
12
|
import '../configuration';
|
|
13
13
|
import { parseStrategiesAutomatedPosition } from './strategiesService';
|
|
14
14
|
describe('Feature: strategiesService.ts', () => {
|
|
15
|
+
describe('When parsing Aave V3 collateral switch subscriptions', () => {
|
|
16
|
+
const proxy = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
|
|
17
|
+
const user = '0x1234567890123456789012345678901234567890';
|
|
18
|
+
const fromAsset = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
19
|
+
const toAsset = '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf';
|
|
20
|
+
const marketAddr = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
|
|
21
|
+
const amountToSwitch = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
22
|
+
const subHash = `0x${'ab'.repeat(32)}`;
|
|
23
|
+
const triggerData = [
|
|
24
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
|
25
|
+
+ '000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf'
|
|
26
|
+
+ '0000000000000000000000000000000000000000000000000000000000989680'
|
|
27
|
+
+ '0000000000000000000000000000000000000000000000000000000000000001',
|
|
28
|
+
];
|
|
29
|
+
function getParseData(strategyId, isGeneric, chainId = ChainId.Ethereum) {
|
|
30
|
+
const subData = [
|
|
31
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
32
|
+
isGeneric
|
|
33
|
+
? '0x0000000000000000000000000000000000000000000000000000000000000100'
|
|
34
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
35
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
36
|
+
isGeneric
|
|
37
|
+
? '0x000000000000000000000000000000000000000000000000000000000000ffff'
|
|
38
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
39
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
40
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
41
|
+
isGeneric
|
|
42
|
+
? '0x0000000000000000000000001234567890123456789012345678901234567890'
|
|
43
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
44
|
+
];
|
|
45
|
+
const subStruct = Object.assign([String(strategyId), false, triggerData, subData], { strategyOrBundleId: String(strategyId), isBundle: false, triggerData, subData });
|
|
46
|
+
return {
|
|
47
|
+
chainId,
|
|
48
|
+
blockNumber: 18015756,
|
|
49
|
+
subscriptionEventData: {
|
|
50
|
+
subId: '379', proxy, subHash, subStruct,
|
|
51
|
+
0: '379', 1: proxy, 2: subHash, 3: subStruct,
|
|
52
|
+
},
|
|
53
|
+
strategiesSubsData: {
|
|
54
|
+
userProxy: proxy, isEnabled: true, strategySubHash: subHash,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const genericStrategies = [
|
|
59
|
+
[ChainId.Ethereum, Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
|
|
60
|
+
[ChainId.Optimism, Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
|
|
61
|
+
[ChainId.Arbitrum, Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
|
|
62
|
+
[ChainId.Base, Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
|
|
63
|
+
];
|
|
64
|
+
genericStrategies.forEach(([chainId, strategyId]) => {
|
|
65
|
+
it(`decodes generic collateral switches with the user and uint16 reserve IDs on chain ${chainId}`, () => {
|
|
66
|
+
const parseData = getParseData(strategyId, true, chainId);
|
|
67
|
+
const position = parseStrategiesAutomatedPosition(parseData);
|
|
68
|
+
expect(position).not.to.equal(null);
|
|
69
|
+
expect(position.protocol.id).to.equal(ProtocolIdentifiers.StrategiesAutomation.AaveV3);
|
|
70
|
+
expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.EoaCollateralSwitch);
|
|
71
|
+
expect(position.strategy.isBundle).to.equal(false);
|
|
72
|
+
expect(position.strategyData.encoded).to.eql({
|
|
73
|
+
triggerData,
|
|
74
|
+
subData: parseData.subscriptionEventData.subStruct.subData,
|
|
75
|
+
});
|
|
76
|
+
expect(position.strategyData.decoded.triggerData).to.eql({
|
|
77
|
+
baseTokenAddress: fromAsset,
|
|
78
|
+
quoteTokenAddress: toAsset,
|
|
79
|
+
price: '0.1',
|
|
80
|
+
ratioState: RatioState.UNDER,
|
|
81
|
+
});
|
|
82
|
+
expect(position.strategyData.decoded.subData).to.eql({
|
|
83
|
+
fromAsset, fromAssetId: 256, toAsset, toAssetId: 65535, marketAddr, amountToSwitch, user,
|
|
84
|
+
});
|
|
85
|
+
expect(position.owner).to.equal(proxy.toLowerCase());
|
|
86
|
+
expect(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
const legacyStrategies = [
|
|
90
|
+
[ChainId.Ethereum, Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
91
|
+
[ChainId.Optimism, Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
92
|
+
[ChainId.Arbitrum, Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
93
|
+
[ChainId.Base, Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
94
|
+
];
|
|
95
|
+
legacyStrategies.forEach(([chainId, strategyId]) => {
|
|
96
|
+
it(`continues to decode legacy collateral switches on chain ${chainId}`, () => {
|
|
97
|
+
const position = parseStrategiesAutomatedPosition(getParseData(strategyId, false, chainId));
|
|
98
|
+
expect(position).not.to.equal(null);
|
|
99
|
+
expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.CollateralSwitch);
|
|
100
|
+
expect(position.strategyData.decoded.subData).to.eql({
|
|
101
|
+
fromAsset, fromAssetId: 0, toAsset, toAssetId: 7, marketAddr, amountToSwitch,
|
|
102
|
+
});
|
|
103
|
+
expect(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
15
107
|
describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
108
|
// TODO: we should probably write this for every strategy?
|
|
17
109
|
const examples = [
|
|
@@ -62,6 +62,7 @@ export declare const aaveV3Encode: {
|
|
|
62
62
|
leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
|
|
63
63
|
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[])[];
|
|
64
64
|
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[])[];
|
|
65
|
+
collateralSwitchGeneric(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
65
66
|
debtSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
|
|
66
67
|
};
|
|
67
68
|
export declare const compoundV2Encode: {
|