@defisaver/automation-sdk 3.3.20 → 3.3.21-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 +40 -0
- package/cjs/services/strategiesService.js +21 -1
- package/cjs/services/strategiesService.test.js +94 -0
- package/cjs/services/strategySubService.d.ts +2 -0
- package/cjs/services/strategySubService.js +12 -0
- package/cjs/services/strategySubService.test.js +107 -0
- package/cjs/services/subDataService.d.ts +24 -0
- package/cjs/services/subDataService.js +66 -2
- package/cjs/services/subDataService.test.js +139 -0
- package/cjs/types/enums.d.ts +14 -4
- package/cjs/types/enums.js +10 -0
- package/esm/constants/index.js +40 -0
- package/esm/services/strategiesService.js +21 -1
- package/esm/services/strategiesService.test.js +95 -1
- package/esm/services/strategySubService.d.ts +2 -0
- package/esm/services/strategySubService.js +12 -0
- package/esm/services/strategySubService.test.js +107 -0
- package/esm/services/subDataService.d.ts +24 -0
- package/esm/services/subDataService.js +64 -0
- package/esm/services/subDataService.test.js +139 -0
- package/esm/types/enums.d.ts +14 -4
- package/esm/types/enums.js +10 -0
- package/package.json +1 -1
- package/src/constants/index.ts +40 -0
- package/src/services/strategiesService.test.ts +106 -1
- package/src/services/strategiesService.ts +23 -1
- package/src/services/strategySubService.test.ts +131 -0
- package/src/services/strategySubService.ts +46 -0
- package/src/services/subDataService.test.ts +149 -0
- package/src/services/subDataService.ts +101 -0
- package/src/types/enums.ts +10 -0
package/cjs/types/enums.d.ts
CHANGED
|
@@ -91,22 +91,30 @@ export declare namespace Strategies {
|
|
|
91
91
|
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
92
92
|
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
93
93
|
SPARK_COLLATERAL_SWITCH = 156,
|
|
94
|
-
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167
|
|
94
|
+
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
|
|
95
|
+
AAVE_V3_DEBT_SWITCH = 168,
|
|
96
|
+
AAVE_V3_DEBT_SWITCH_EOA = 169
|
|
95
97
|
}
|
|
96
98
|
enum OptimismIds {
|
|
97
99
|
EXCHANGE_DCA = 8,
|
|
98
100
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
99
|
-
AAVE_V3_COLLATERAL_SWITCH = 24
|
|
101
|
+
AAVE_V3_COLLATERAL_SWITCH = 24,
|
|
102
|
+
AAVE_V3_DEBT_SWITCH = 25,
|
|
103
|
+
AAVE_V3_DEBT_SWITCH_EOA = 26
|
|
100
104
|
}
|
|
101
105
|
enum BaseIds {
|
|
102
106
|
EXCHANGE_DCA = 8,
|
|
103
107
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
104
|
-
AAVE_V3_COLLATERAL_SWITCH = 56
|
|
108
|
+
AAVE_V3_COLLATERAL_SWITCH = 56,
|
|
109
|
+
AAVE_V3_DEBT_SWITCH = 61,
|
|
110
|
+
AAVE_V3_DEBT_SWITCH_EOA = 62
|
|
105
111
|
}
|
|
106
112
|
enum ArbitrumIds {
|
|
107
113
|
EXCHANGE_DCA = 8,
|
|
108
114
|
EXCHANGE_LIMIT_ORDER = 9,
|
|
109
|
-
AAVE_V3_COLLATERAL_SWITCH = 50
|
|
115
|
+
AAVE_V3_COLLATERAL_SWITCH = 50,
|
|
116
|
+
AAVE_V3_DEBT_SWITCH = 55,
|
|
117
|
+
AAVE_V3_DEBT_SWITCH_EOA = 56
|
|
110
118
|
}
|
|
111
119
|
enum Identifiers {
|
|
112
120
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
|
@@ -140,6 +148,8 @@ export declare namespace Strategies {
|
|
|
140
148
|
EoaRepayOnPrice = "eoa-repay-on-price",
|
|
141
149
|
CollateralSwitch = "collateral-switch",
|
|
142
150
|
EoaCollateralSwitch = "eoa-collateral-switch",
|
|
151
|
+
DebtSwitch = "debt-switch",
|
|
152
|
+
EoaDebtSwitch = "eoa-debt-switch",
|
|
143
153
|
LiquidationProtection = "liquidation-protection",
|
|
144
154
|
EoaLiquidationProtection = "liquidation-protection-eoa"
|
|
145
155
|
}
|
package/cjs/types/enums.js
CHANGED
|
@@ -108,24 +108,32 @@ 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";
|
|
111
113
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
112
114
|
let OptimismIds;
|
|
113
115
|
(function (OptimismIds) {
|
|
114
116
|
OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
115
117
|
OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
116
118
|
OptimismIds[OptimismIds["AAVE_V3_COLLATERAL_SWITCH"] = 24] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
119
|
+
OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH"] = 25] = "AAVE_V3_DEBT_SWITCH";
|
|
120
|
+
OptimismIds[OptimismIds["AAVE_V3_DEBT_SWITCH_EOA"] = 26] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
117
121
|
})(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
|
|
118
122
|
let BaseIds;
|
|
119
123
|
(function (BaseIds) {
|
|
120
124
|
BaseIds[BaseIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
121
125
|
BaseIds[BaseIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
122
126
|
BaseIds[BaseIds["AAVE_V3_COLLATERAL_SWITCH"] = 56] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
127
|
+
BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH"] = 61] = "AAVE_V3_DEBT_SWITCH";
|
|
128
|
+
BaseIds[BaseIds["AAVE_V3_DEBT_SWITCH_EOA"] = 62] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
123
129
|
})(BaseIds = Strategies.BaseIds || (Strategies.BaseIds = {}));
|
|
124
130
|
let ArbitrumIds;
|
|
125
131
|
(function (ArbitrumIds) {
|
|
126
132
|
ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
127
133
|
ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
128
134
|
ArbitrumIds[ArbitrumIds["AAVE_V3_COLLATERAL_SWITCH"] = 50] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
135
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH"] = 55] = "AAVE_V3_DEBT_SWITCH";
|
|
136
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_DEBT_SWITCH_EOA"] = 56] = "AAVE_V3_DEBT_SWITCH_EOA";
|
|
129
137
|
})(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
|
|
130
138
|
let Identifiers;
|
|
131
139
|
(function (Identifiers) {
|
|
@@ -160,6 +168,8 @@ var Strategies;
|
|
|
160
168
|
Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
|
|
161
169
|
Identifiers["CollateralSwitch"] = "collateral-switch";
|
|
162
170
|
Identifiers["EoaCollateralSwitch"] = "eoa-collateral-switch";
|
|
171
|
+
Identifiers["DebtSwitch"] = "debt-switch";
|
|
172
|
+
Identifiers["EoaDebtSwitch"] = "eoa-debt-switch";
|
|
163
173
|
Identifiers["LiquidationProtection"] = "liquidation-protection";
|
|
164
174
|
Identifiers["EoaLiquidationProtection"] = "liquidation-protection-eoa";
|
|
165
175
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
package/esm/constants/index.js
CHANGED
|
@@ -121,6 +121,16 @@ export const MAINNET_STRATEGIES_INFO = {
|
|
|
121
121
|
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
122
122
|
protocol: PROTOCOLS.Spark,
|
|
123
123
|
},
|
|
124
|
+
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH]: {
|
|
125
|
+
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
126
|
+
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
127
|
+
protocol: PROTOCOLS.AaveV3,
|
|
128
|
+
},
|
|
129
|
+
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
130
|
+
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
131
|
+
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
132
|
+
protocol: PROTOCOLS.AaveV3,
|
|
133
|
+
},
|
|
124
134
|
};
|
|
125
135
|
export const OPTIMISM_STRATEGIES_INFO = {
|
|
126
136
|
[Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -138,6 +148,16 @@ export const OPTIMISM_STRATEGIES_INFO = {
|
|
|
138
148
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
139
149
|
protocol: PROTOCOLS.AaveV3,
|
|
140
150
|
},
|
|
151
|
+
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
|
|
152
|
+
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
|
|
153
|
+
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
154
|
+
protocol: PROTOCOLS.AaveV3,
|
|
155
|
+
},
|
|
156
|
+
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
157
|
+
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
158
|
+
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
159
|
+
protocol: PROTOCOLS.AaveV3,
|
|
160
|
+
},
|
|
141
161
|
};
|
|
142
162
|
export const BASE_STRATEGIES_INFO = {
|
|
143
163
|
[Strategies.BaseIds.EXCHANGE_DCA]: {
|
|
@@ -155,6 +175,16 @@ export const BASE_STRATEGIES_INFO = {
|
|
|
155
175
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
156
176
|
protocol: PROTOCOLS.AaveV3,
|
|
157
177
|
},
|
|
178
|
+
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
|
|
179
|
+
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
|
|
180
|
+
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
181
|
+
protocol: PROTOCOLS.AaveV3,
|
|
182
|
+
},
|
|
183
|
+
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
184
|
+
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
185
|
+
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
186
|
+
protocol: PROTOCOLS.AaveV3,
|
|
187
|
+
},
|
|
158
188
|
};
|
|
159
189
|
export const ARBITRUM_STRATEGIES_INFO = {
|
|
160
190
|
[Strategies.ArbitrumIds.EXCHANGE_DCA]: {
|
|
@@ -172,6 +202,16 @@ export const ARBITRUM_STRATEGIES_INFO = {
|
|
|
172
202
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
173
203
|
protocol: PROTOCOLS.AaveV3,
|
|
174
204
|
},
|
|
205
|
+
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
|
|
206
|
+
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
|
|
207
|
+
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
208
|
+
protocol: PROTOCOLS.AaveV3,
|
|
209
|
+
},
|
|
210
|
+
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
211
|
+
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
212
|
+
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
213
|
+
protocol: PROTOCOLS.AaveV3,
|
|
214
|
+
},
|
|
175
215
|
};
|
|
176
216
|
export const STRATEGIES_INFO = {
|
|
177
217
|
[ChainId.Ethereum]: MAINNET_STRATEGIES_INFO,
|
|
@@ -318,12 +318,29 @@ function parseAaveV3CloseOnPrice(position, parseData) {
|
|
|
318
318
|
return _position;
|
|
319
319
|
}
|
|
320
320
|
function parseAaveV3CollateralSwitch(position, parseData) {
|
|
321
|
+
const _position = cloneDeep(position);
|
|
322
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
323
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
324
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
325
|
+
const subData = isEOA
|
|
326
|
+
? subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subStruct.subData)
|
|
327
|
+
: subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
328
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
329
|
+
_position.strategyData.decoded.subData = subData;
|
|
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;
|
|
334
|
+
return _position;
|
|
335
|
+
}
|
|
336
|
+
function parseAaveV3DebtSwitch(position, parseData) {
|
|
321
337
|
const _position = cloneDeep(position);
|
|
322
338
|
const { subStruct } = parseData.subscriptionEventData;
|
|
323
339
|
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
324
|
-
const subData = subDataService.
|
|
340
|
+
const subData = subDataService.aaveV3DebtSwitchSubData.decode(subStruct.subData);
|
|
325
341
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
326
342
|
_position.strategyData.decoded.subData = subData;
|
|
343
|
+
// TODO -> This isn't enough for ID
|
|
327
344
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
328
345
|
return _position;
|
|
329
346
|
}
|
|
@@ -1217,6 +1234,9 @@ const parsingMethodsMapping = {
|
|
|
1217
1234
|
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1218
1235
|
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1219
1236
|
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1237
|
+
[Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1238
|
+
[Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
|
|
1239
|
+
[Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
|
|
1220
1240
|
[Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1221
1241
|
[Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1222
1242
|
},
|
|
@@ -8,10 +8,104 @@ 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
|
+
import { MAINNET_STRATEGIES_INFO } from '../constants';
|
|
12
13
|
import '../configuration';
|
|
13
14
|
import { parseStrategiesAutomatedPosition } from './strategiesService';
|
|
14
15
|
describe('Feature: strategiesService.ts', () => {
|
|
16
|
+
describe('When parsing Aave V3 collateral switch subscriptions', () => {
|
|
17
|
+
const proxy = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
|
|
18
|
+
const user = '0x1234567890123456789012345678901234567890';
|
|
19
|
+
const fromAsset = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
20
|
+
const toAsset = '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf';
|
|
21
|
+
const marketAddr = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
|
|
22
|
+
const amountToSwitch = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
23
|
+
const subHash = `0x${'ab'.repeat(32)}`;
|
|
24
|
+
const triggerData = [
|
|
25
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
|
26
|
+
+ '000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf'
|
|
27
|
+
+ '0000000000000000000000000000000000000000000000000000000000989680'
|
|
28
|
+
+ '0000000000000000000000000000000000000000000000000000000000000001',
|
|
29
|
+
];
|
|
30
|
+
function getParseData(strategyId, isGeneric, chainId = ChainId.Ethereum) {
|
|
31
|
+
const subData = [
|
|
32
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
33
|
+
isGeneric
|
|
34
|
+
? '0x0000000000000000000000000000000000000000000000000000000000000100'
|
|
35
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
36
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
37
|
+
isGeneric
|
|
38
|
+
? '0x000000000000000000000000000000000000000000000000000000000000ffff'
|
|
39
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
40
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
41
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
42
|
+
isGeneric
|
|
43
|
+
? '0x0000000000000000000000001234567890123456789012345678901234567890'
|
|
44
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
45
|
+
];
|
|
46
|
+
const subStruct = Object.assign([String(strategyId), false, triggerData, subData], { strategyOrBundleId: String(strategyId), isBundle: false, triggerData, subData });
|
|
47
|
+
return {
|
|
48
|
+
chainId,
|
|
49
|
+
blockNumber: 18015756,
|
|
50
|
+
subscriptionEventData: {
|
|
51
|
+
subId: '379', proxy, subHash, subStruct,
|
|
52
|
+
0: '379', 1: proxy, 2: subHash, 3: subStruct,
|
|
53
|
+
},
|
|
54
|
+
strategiesSubsData: {
|
|
55
|
+
userProxy: proxy, isEnabled: true, strategySubHash: subHash,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
it('decodes generic collateral switches with the user and uint16 reserve IDs', () => {
|
|
60
|
+
const strategyId = Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH;
|
|
61
|
+
const originalInfo = MAINNET_STRATEGIES_INFO[strategyId];
|
|
62
|
+
const parseData = getParseData(strategyId, true);
|
|
63
|
+
let position;
|
|
64
|
+
MAINNET_STRATEGIES_INFO[strategyId] = Object.assign(Object.assign({}, originalInfo), { strategyId: Strategies.Identifiers.EoaCollateralSwitch });
|
|
65
|
+
try {
|
|
66
|
+
position = parseStrategiesAutomatedPosition(parseData);
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
MAINNET_STRATEGIES_INFO[strategyId] = originalInfo;
|
|
70
|
+
}
|
|
71
|
+
expect(position).not.to.equal(null);
|
|
72
|
+
expect(position.protocol.id).to.equal(ProtocolIdentifiers.StrategiesAutomation.AaveV3);
|
|
73
|
+
expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.EoaCollateralSwitch);
|
|
74
|
+
expect(position.strategy.isBundle).to.equal(false);
|
|
75
|
+
expect(position.strategyData.encoded).to.eql({
|
|
76
|
+
triggerData,
|
|
77
|
+
subData: parseData.subscriptionEventData.subStruct.subData,
|
|
78
|
+
});
|
|
79
|
+
expect(position.strategyData.decoded.triggerData).to.eql({
|
|
80
|
+
baseTokenAddress: fromAsset,
|
|
81
|
+
quoteTokenAddress: toAsset,
|
|
82
|
+
price: '0.1',
|
|
83
|
+
ratioState: RatioState.UNDER,
|
|
84
|
+
});
|
|
85
|
+
expect(position.strategyData.decoded.subData).to.eql({
|
|
86
|
+
fromAsset, fromAssetId: 256, toAsset, toAssetId: 65535, marketAddr, amountToSwitch, user,
|
|
87
|
+
});
|
|
88
|
+
expect(position.owner).to.equal(proxy.toLowerCase());
|
|
89
|
+
expect(position.positionId).to.equal(`1-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
90
|
+
});
|
|
91
|
+
const legacyStrategies = [
|
|
92
|
+
[ChainId.Ethereum, Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
93
|
+
[ChainId.Optimism, Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
94
|
+
[ChainId.Arbitrum, Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
95
|
+
[ChainId.Base, 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 = parseStrategiesAutomatedPosition(getParseData(strategyId, false, chainId));
|
|
100
|
+
expect(position).not.to.equal(null);
|
|
101
|
+
expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.CollateralSwitch);
|
|
102
|
+
expect(position.strategyData.decoded.subData).to.eql({
|
|
103
|
+
fromAsset, fromAssetId: 0, toAsset, toAssetId: 7, marketAddr, amountToSwitch,
|
|
104
|
+
});
|
|
105
|
+
expect(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
15
109
|
describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
110
|
// TODO: we should probably write this for every strategy?
|
|
17
111
|
const examples = [
|
|
@@ -62,6 +62,8 @@ 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[])[];
|
|
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[])[];
|
|
65
67
|
};
|
|
66
68
|
export declare const compoundV2Encode: {
|
|
67
69
|
leverageManagement(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
@@ -170,6 +170,18 @@ export const aaveV3Encode = {
|
|
|
170
170
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
171
171
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
172
172
|
},
|
|
173
|
+
collateralSwitchGeneric(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
|
|
174
|
+
const isBundle = false;
|
|
175
|
+
const subDataEncoded = subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
|
|
176
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
177
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
178
|
+
},
|
|
179
|
+
debtSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
|
|
180
|
+
const isBundle = false;
|
|
181
|
+
const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
|
|
182
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
183
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
184
|
+
},
|
|
173
185
|
};
|
|
174
186
|
export const compoundV2Encode = {
|
|
175
187
|
leverageManagement(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
@@ -831,6 +831,113 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
831
831
|
});
|
|
832
832
|
});
|
|
833
833
|
});
|
|
834
|
+
describe('collateralSwitchGeneric()', () => {
|
|
835
|
+
const strategyId = 12345;
|
|
836
|
+
const fromAsset = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
|
|
837
|
+
const toAsset = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
|
|
838
|
+
const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
839
|
+
const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
|
|
840
|
+
const examples = [
|
|
841
|
+
[
|
|
842
|
+
RatioState.UNDER,
|
|
843
|
+
'10000000000000000000',
|
|
844
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
845
|
+
'0000000000000000000000000000000000000000000000000000000000000001',
|
|
846
|
+
],
|
|
847
|
+
[
|
|
848
|
+
RatioState.OVER,
|
|
849
|
+
MAXUINT,
|
|
850
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
851
|
+
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
852
|
+
],
|
|
853
|
+
];
|
|
854
|
+
examples.forEach(([state, amountToSwitch, encodedAmount, encodedState]) => {
|
|
855
|
+
it(`encodes a generic collateral switch with the supplied quote pair and state ${state}`, () => {
|
|
856
|
+
const expectedTrigger = `0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e8${encodedState}`;
|
|
857
|
+
const expectedSubData = [
|
|
858
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
859
|
+
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
860
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
861
|
+
'0x000000000000000000000000000000000000000000000000000000000000ffff',
|
|
862
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
863
|
+
encodedAmount,
|
|
864
|
+
'0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
|
|
865
|
+
];
|
|
866
|
+
expect(aaveV3Encode.collateralSwitchGeneric(strategyId, fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user, toAsset, fromAsset, 0.00001, state)).to.eql([strategyId, false, [expectedTrigger], expectedSubData]);
|
|
867
|
+
});
|
|
868
|
+
});
|
|
869
|
+
});
|
|
870
|
+
describe('debtSwitch()', () => {
|
|
871
|
+
const examples = [
|
|
872
|
+
// USDC -> DAI, price 100000, state UNDER
|
|
873
|
+
[
|
|
874
|
+
[
|
|
875
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
876
|
+
false,
|
|
877
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
878
|
+
[
|
|
879
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
880
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
881
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
882
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
883
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
884
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
885
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
886
|
+
],
|
|
887
|
+
],
|
|
888
|
+
[
|
|
889
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
890
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
891
|
+
1,
|
|
892
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
893
|
+
3,
|
|
894
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
895
|
+
'10000000000000000000',
|
|
896
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
897
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
898
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
899
|
+
100000,
|
|
900
|
+
RatioState.UNDER,
|
|
901
|
+
]
|
|
902
|
+
],
|
|
903
|
+
// DAI -> USDC (MaxUint256), price 1, state OVER
|
|
904
|
+
[
|
|
905
|
+
[
|
|
906
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
907
|
+
false,
|
|
908
|
+
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
|
|
909
|
+
[
|
|
910
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
911
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
912
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
913
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
914
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
915
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
916
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
917
|
+
],
|
|
918
|
+
],
|
|
919
|
+
[
|
|
920
|
+
Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
921
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
922
|
+
3,
|
|
923
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
924
|
+
1,
|
|
925
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
926
|
+
MAXUINT,
|
|
927
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
928
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
929
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
930
|
+
1,
|
|
931
|
+
RatioState.OVER,
|
|
932
|
+
]
|
|
933
|
+
],
|
|
934
|
+
];
|
|
935
|
+
examples.forEach(([expected, actual]) => {
|
|
936
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
937
|
+
expect(aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
|
|
938
|
+
});
|
|
939
|
+
});
|
|
940
|
+
});
|
|
834
941
|
});
|
|
835
942
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
836
943
|
describe('leverageManagementOnPrice()', () => {
|
|
@@ -259,6 +259,30 @@ 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
|
+
};
|
|
274
|
+
export declare const aaveV3DebtSwitchSubData: {
|
|
275
|
+
encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
|
|
276
|
+
decode(subData: string[]): {
|
|
277
|
+
fromAsset: EthereumAddress;
|
|
278
|
+
fromAssetId: number;
|
|
279
|
+
toAsset: EthereumAddress;
|
|
280
|
+
toAssetId: number;
|
|
281
|
+
marketAddr: EthereumAddress;
|
|
282
|
+
amountToSwitch: string;
|
|
283
|
+
user: EthereumAddress;
|
|
284
|
+
};
|
|
285
|
+
};
|
|
262
286
|
export declare const aaveV3QuotePriceSubData: {
|
|
263
287
|
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress): string[];
|
|
264
288
|
decode(subData: string[]): {
|
|
@@ -542,6 +542,70 @@ export const aaveV3CollateralSwitchSubData = {
|
|
|
542
542
|
};
|
|
543
543
|
},
|
|
544
544
|
};
|
|
545
|
+
export const aaveV3GenericFLCollateralSwitchSubData = {
|
|
546
|
+
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
|
|
547
|
+
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
548
|
+
const encodedFromAssetId = AbiCoder.encodeParameter('uint16', fromAssetId);
|
|
549
|
+
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
550
|
+
const encodedToAssetId = AbiCoder.encodeParameter('uint16', toAssetId);
|
|
551
|
+
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
552
|
+
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
553
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
554
|
+
return [
|
|
555
|
+
encodedFromAsset,
|
|
556
|
+
encodedFromAssetId,
|
|
557
|
+
encodedToAsset,
|
|
558
|
+
encodedToAssetId,
|
|
559
|
+
encodedMarketAddr,
|
|
560
|
+
encodedAmountToSwitch,
|
|
561
|
+
encodedUser,
|
|
562
|
+
];
|
|
563
|
+
},
|
|
564
|
+
decode(subData) {
|
|
565
|
+
const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
|
|
566
|
+
const fromAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
|
|
567
|
+
const toAsset = AbiCoder.decodeParameter('address', subData[2]);
|
|
568
|
+
const toAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
|
|
569
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
|
|
570
|
+
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
|
|
571
|
+
const user = AbiCoder.decodeParameter('address', subData[6]);
|
|
572
|
+
return {
|
|
573
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
574
|
+
};
|
|
575
|
+
},
|
|
576
|
+
};
|
|
577
|
+
export const aaveV3DebtSwitchSubData = {
|
|
578
|
+
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
|
|
579
|
+
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
580
|
+
const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
|
|
581
|
+
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
582
|
+
const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
|
|
583
|
+
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
584
|
+
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
585
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
586
|
+
return [
|
|
587
|
+
encodedFromAsset,
|
|
588
|
+
encodedFromAssetId,
|
|
589
|
+
encodedToAsset,
|
|
590
|
+
encodedToAssetId,
|
|
591
|
+
encodedMarketAddr,
|
|
592
|
+
encodedAmountToSwitch,
|
|
593
|
+
encodedUser,
|
|
594
|
+
];
|
|
595
|
+
},
|
|
596
|
+
decode(subData) {
|
|
597
|
+
const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
|
|
598
|
+
const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
599
|
+
const toAsset = AbiCoder.decodeParameter('address', subData[2]);
|
|
600
|
+
const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
601
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
|
|
602
|
+
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
|
|
603
|
+
const user = AbiCoder.decodeParameter('address', subData[6]);
|
|
604
|
+
return {
|
|
605
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
606
|
+
};
|
|
607
|
+
},
|
|
608
|
+
};
|
|
545
609
|
export const aaveV3QuotePriceSubData = {
|
|
546
610
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = ZERO_ADDRESS) {
|
|
547
611
|
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|