@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/constants/index.js
CHANGED
|
@@ -127,6 +127,16 @@ exports.MAINNET_STRATEGIES_INFO = {
|
|
|
127
127
|
strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
|
|
128
128
|
protocol: exports.PROTOCOLS.Spark,
|
|
129
129
|
},
|
|
130
|
+
[enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH]: {
|
|
131
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
132
|
+
strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
|
|
133
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
134
|
+
},
|
|
135
|
+
[enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
136
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
137
|
+
strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
|
|
138
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
139
|
+
},
|
|
130
140
|
};
|
|
131
141
|
exports.OPTIMISM_STRATEGIES_INFO = {
|
|
132
142
|
[enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -144,6 +154,16 @@ exports.OPTIMISM_STRATEGIES_INFO = {
|
|
|
144
154
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
145
155
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
146
156
|
},
|
|
157
|
+
[enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
|
|
158
|
+
strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
|
|
159
|
+
strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
|
|
160
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
161
|
+
},
|
|
162
|
+
[enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
163
|
+
strategyOrBundleId: enums_1.Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
164
|
+
strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
|
|
165
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
166
|
+
},
|
|
147
167
|
};
|
|
148
168
|
exports.BASE_STRATEGIES_INFO = {
|
|
149
169
|
[enums_1.Strategies.BaseIds.EXCHANGE_DCA]: {
|
|
@@ -161,6 +181,16 @@ exports.BASE_STRATEGIES_INFO = {
|
|
|
161
181
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
162
182
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
163
183
|
},
|
|
184
|
+
[enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
|
|
185
|
+
strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
|
|
186
|
+
strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
|
|
187
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
188
|
+
},
|
|
189
|
+
[enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
190
|
+
strategyOrBundleId: enums_1.Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
191
|
+
strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
|
|
192
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
193
|
+
},
|
|
164
194
|
};
|
|
165
195
|
exports.ARBITRUM_STRATEGIES_INFO = {
|
|
166
196
|
[enums_1.Strategies.ArbitrumIds.EXCHANGE_DCA]: {
|
|
@@ -178,6 +208,16 @@ exports.ARBITRUM_STRATEGIES_INFO = {
|
|
|
178
208
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
179
209
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
180
210
|
},
|
|
211
|
+
[enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
|
|
212
|
+
strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
|
|
213
|
+
strategyId: enums_1.Strategies.Identifiers.DebtSwitch,
|
|
214
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
215
|
+
},
|
|
216
|
+
[enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
217
|
+
strategyOrBundleId: enums_1.Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
218
|
+
strategyId: enums_1.Strategies.Identifiers.EoaDebtSwitch,
|
|
219
|
+
protocol: exports.PROTOCOLS.AaveV3,
|
|
220
|
+
},
|
|
181
221
|
};
|
|
182
222
|
exports.STRATEGIES_INFO = {
|
|
183
223
|
[enums_1.ChainId.Ethereum]: exports.MAINNET_STRATEGIES_INFO,
|
|
@@ -347,12 +347,29 @@ function parseAaveV3CloseOnPrice(position, parseData) {
|
|
|
347
347
|
return _position;
|
|
348
348
|
}
|
|
349
349
|
function parseAaveV3CollateralSwitch(position, parseData) {
|
|
350
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
351
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
352
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
353
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
354
|
+
const subData = isEOA
|
|
355
|
+
? subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subStruct.subData)
|
|
356
|
+
: subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
357
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
358
|
+
_position.strategyData.decoded.subData = subData;
|
|
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;
|
|
363
|
+
return _position;
|
|
364
|
+
}
|
|
365
|
+
function parseAaveV3DebtSwitch(position, parseData) {
|
|
350
366
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
351
367
|
const { subStruct } = parseData.subscriptionEventData;
|
|
352
368
|
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
353
|
-
const subData = subDataService.
|
|
369
|
+
const subData = subDataService.aaveV3DebtSwitchSubData.decode(subStruct.subData);
|
|
354
370
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
355
371
|
_position.strategyData.decoded.subData = subData;
|
|
372
|
+
// TODO -> This isn't enough for ID
|
|
356
373
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
357
374
|
return _position;
|
|
358
375
|
}
|
|
@@ -1246,6 +1263,9 @@ const parsingMethodsMapping = {
|
|
|
1246
1263
|
[enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1247
1264
|
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1248
1265
|
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1266
|
+
[enums_1.Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1267
|
+
[enums_1.Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
|
|
1268
|
+
[enums_1.Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
|
|
1249
1269
|
[enums_1.Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1250
1270
|
[enums_1.Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1251
1271
|
},
|
|
@@ -11,9 +11,103 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const chai_1 = require("chai");
|
|
13
13
|
const enums_1 = require("../types/enums");
|
|
14
|
+
const constants_1 = require("../constants");
|
|
14
15
|
require("../configuration");
|
|
15
16
|
const strategiesService_1 = require("./strategiesService");
|
|
16
17
|
describe('Feature: strategiesService.ts', () => {
|
|
18
|
+
describe('When parsing Aave V3 collateral switch subscriptions', () => {
|
|
19
|
+
const proxy = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
|
|
20
|
+
const user = '0x1234567890123456789012345678901234567890';
|
|
21
|
+
const fromAsset = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
22
|
+
const toAsset = '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf';
|
|
23
|
+
const marketAddr = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
|
|
24
|
+
const amountToSwitch = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
25
|
+
const subHash = `0x${'ab'.repeat(32)}`;
|
|
26
|
+
const triggerData = [
|
|
27
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
|
28
|
+
+ '000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf'
|
|
29
|
+
+ '0000000000000000000000000000000000000000000000000000000000989680'
|
|
30
|
+
+ '0000000000000000000000000000000000000000000000000000000000000001',
|
|
31
|
+
];
|
|
32
|
+
function getParseData(strategyId, isGeneric, chainId = enums_1.ChainId.Ethereum) {
|
|
33
|
+
const subData = [
|
|
34
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
35
|
+
isGeneric
|
|
36
|
+
? '0x0000000000000000000000000000000000000000000000000000000000000100'
|
|
37
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
38
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
39
|
+
isGeneric
|
|
40
|
+
? '0x000000000000000000000000000000000000000000000000000000000000ffff'
|
|
41
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
42
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
43
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
44
|
+
isGeneric
|
|
45
|
+
? '0x0000000000000000000000001234567890123456789012345678901234567890'
|
|
46
|
+
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
47
|
+
];
|
|
48
|
+
const subStruct = Object.assign([String(strategyId), false, triggerData, subData], { strategyOrBundleId: String(strategyId), isBundle: false, triggerData, subData });
|
|
49
|
+
return {
|
|
50
|
+
chainId,
|
|
51
|
+
blockNumber: 18015756,
|
|
52
|
+
subscriptionEventData: {
|
|
53
|
+
subId: '379', proxy, subHash, subStruct,
|
|
54
|
+
0: '379', 1: proxy, 2: subHash, 3: subStruct,
|
|
55
|
+
},
|
|
56
|
+
strategiesSubsData: {
|
|
57
|
+
userProxy: proxy, isEnabled: true, strategySubHash: subHash,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
it('decodes generic collateral switches with the user and uint16 reserve IDs', () => {
|
|
62
|
+
const strategyId = enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH;
|
|
63
|
+
const originalInfo = constants_1.MAINNET_STRATEGIES_INFO[strategyId];
|
|
64
|
+
const parseData = getParseData(strategyId, true);
|
|
65
|
+
let position;
|
|
66
|
+
constants_1.MAINNET_STRATEGIES_INFO[strategyId] = Object.assign(Object.assign({}, originalInfo), { strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch });
|
|
67
|
+
try {
|
|
68
|
+
position = (0, strategiesService_1.parseStrategiesAutomatedPosition)(parseData);
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
constants_1.MAINNET_STRATEGIES_INFO[strategyId] = originalInfo;
|
|
72
|
+
}
|
|
73
|
+
(0, chai_1.expect)(position).not.to.equal(null);
|
|
74
|
+
(0, chai_1.expect)(position.protocol.id).to.equal(enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV3);
|
|
75
|
+
(0, chai_1.expect)(position.strategy.strategyId).to.equal(enums_1.Strategies.Identifiers.EoaCollateralSwitch);
|
|
76
|
+
(0, chai_1.expect)(position.strategy.isBundle).to.equal(false);
|
|
77
|
+
(0, chai_1.expect)(position.strategyData.encoded).to.eql({
|
|
78
|
+
triggerData,
|
|
79
|
+
subData: parseData.subscriptionEventData.subStruct.subData,
|
|
80
|
+
});
|
|
81
|
+
(0, chai_1.expect)(position.strategyData.decoded.triggerData).to.eql({
|
|
82
|
+
baseTokenAddress: fromAsset,
|
|
83
|
+
quoteTokenAddress: toAsset,
|
|
84
|
+
price: '0.1',
|
|
85
|
+
ratioState: enums_1.RatioState.UNDER,
|
|
86
|
+
});
|
|
87
|
+
(0, chai_1.expect)(position.strategyData.decoded.subData).to.eql({
|
|
88
|
+
fromAsset, fromAssetId: 256, toAsset, toAssetId: 65535, marketAddr, amountToSwitch, user,
|
|
89
|
+
});
|
|
90
|
+
(0, chai_1.expect)(position.owner).to.equal(proxy.toLowerCase());
|
|
91
|
+
(0, chai_1.expect)(position.positionId).to.equal(`1-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
92
|
+
});
|
|
93
|
+
const legacyStrategies = [
|
|
94
|
+
[enums_1.ChainId.Ethereum, enums_1.Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
95
|
+
[enums_1.ChainId.Optimism, enums_1.Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
96
|
+
[enums_1.ChainId.Arbitrum, enums_1.Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
97
|
+
[enums_1.ChainId.Base, enums_1.Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH],
|
|
98
|
+
];
|
|
99
|
+
legacyStrategies.forEach(([chainId, strategyId]) => {
|
|
100
|
+
it(`continues to decode legacy collateral switches on chain ${chainId}`, () => {
|
|
101
|
+
const position = (0, strategiesService_1.parseStrategiesAutomatedPosition)(getParseData(strategyId, false, chainId));
|
|
102
|
+
(0, chai_1.expect)(position).not.to.equal(null);
|
|
103
|
+
(0, chai_1.expect)(position.strategy.strategyId).to.equal(enums_1.Strategies.Identifiers.CollateralSwitch);
|
|
104
|
+
(0, chai_1.expect)(position.strategyData.decoded.subData).to.eql({
|
|
105
|
+
fromAsset, fromAssetId: 0, toAsset, toAssetId: 7, marketAddr, amountToSwitch,
|
|
106
|
+
});
|
|
107
|
+
(0, chai_1.expect)(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
17
111
|
describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
112
|
// TODO: we should probably write this for every strategy?
|
|
19
113
|
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[])[];
|
|
@@ -196,6 +196,18 @@ 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
|
+
},
|
|
205
|
+
debtSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
|
|
206
|
+
const isBundle = false;
|
|
207
|
+
const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
|
|
208
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
209
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
210
|
+
},
|
|
199
211
|
};
|
|
200
212
|
exports.compoundV2Encode = {
|
|
201
213
|
leverageManagement(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
|
|
@@ -856,6 +856,113 @@ 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
|
+
});
|
|
895
|
+
describe('debtSwitch()', () => {
|
|
896
|
+
const examples = [
|
|
897
|
+
// USDC -> DAI, price 100000, state UNDER
|
|
898
|
+
[
|
|
899
|
+
[
|
|
900
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
901
|
+
false,
|
|
902
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
903
|
+
[
|
|
904
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
905
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
906
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
907
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
908
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
909
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
910
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
911
|
+
],
|
|
912
|
+
],
|
|
913
|
+
[
|
|
914
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
915
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
916
|
+
1,
|
|
917
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
918
|
+
3,
|
|
919
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
920
|
+
'10000000000000000000',
|
|
921
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
922
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
923
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
924
|
+
100000,
|
|
925
|
+
enums_1.RatioState.UNDER,
|
|
926
|
+
]
|
|
927
|
+
],
|
|
928
|
+
// DAI -> USDC (MaxUint256), price 1, state OVER
|
|
929
|
+
[
|
|
930
|
+
[
|
|
931
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
932
|
+
false,
|
|
933
|
+
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
|
|
934
|
+
[
|
|
935
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
936
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
937
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
938
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
939
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
940
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
941
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
942
|
+
],
|
|
943
|
+
],
|
|
944
|
+
[
|
|
945
|
+
enums_1.Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
946
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
947
|
+
3,
|
|
948
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
949
|
+
1,
|
|
950
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
951
|
+
tokens_1.MAXUINT,
|
|
952
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
953
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
954
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
955
|
+
1,
|
|
956
|
+
enums_1.RatioState.OVER,
|
|
957
|
+
]
|
|
958
|
+
],
|
|
959
|
+
];
|
|
960
|
+
examples.forEach(([expected, actual]) => {
|
|
961
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
962
|
+
(0, chai_1.expect)(strategySubService_1.aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
|
|
963
|
+
});
|
|
964
|
+
});
|
|
965
|
+
});
|
|
859
966
|
});
|
|
860
967
|
describe('When testing strategySubService.compoundV3Encode', () => {
|
|
861
968
|
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[]): {
|
|
@@ -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 = 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,70 @@ exports.aaveV3CollateralSwitchSubData = {
|
|
|
549
549
|
};
|
|
550
550
|
},
|
|
551
551
|
};
|
|
552
|
+
exports.aaveV3GenericFLCollateralSwitchSubData = {
|
|
553
|
+
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
|
|
554
|
+
const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
|
|
555
|
+
const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint16', fromAssetId);
|
|
556
|
+
const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
|
|
557
|
+
const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint16', toAssetId);
|
|
558
|
+
const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
559
|
+
const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
|
|
560
|
+
const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
561
|
+
return [
|
|
562
|
+
encodedFromAsset,
|
|
563
|
+
encodedFromAssetId,
|
|
564
|
+
encodedToAsset,
|
|
565
|
+
encodedToAssetId,
|
|
566
|
+
encodedMarketAddr,
|
|
567
|
+
encodedAmountToSwitch,
|
|
568
|
+
encodedUser,
|
|
569
|
+
];
|
|
570
|
+
},
|
|
571
|
+
decode(subData) {
|
|
572
|
+
const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
573
|
+
const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[1]));
|
|
574
|
+
const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
575
|
+
const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[3]));
|
|
576
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
577
|
+
const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
578
|
+
const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
579
|
+
return {
|
|
580
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
581
|
+
};
|
|
582
|
+
},
|
|
583
|
+
};
|
|
584
|
+
exports.aaveV3DebtSwitchSubData = {
|
|
585
|
+
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
|
|
586
|
+
const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
|
|
587
|
+
const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
|
|
588
|
+
const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
|
|
589
|
+
const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
|
|
590
|
+
const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
591
|
+
const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
|
|
592
|
+
const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
593
|
+
return [
|
|
594
|
+
encodedFromAsset,
|
|
595
|
+
encodedFromAssetId,
|
|
596
|
+
encodedToAsset,
|
|
597
|
+
encodedToAssetId,
|
|
598
|
+
encodedMarketAddr,
|
|
599
|
+
encodedAmountToSwitch,
|
|
600
|
+
encodedUser,
|
|
601
|
+
];
|
|
602
|
+
},
|
|
603
|
+
decode(subData) {
|
|
604
|
+
const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
605
|
+
const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
606
|
+
const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
607
|
+
const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
608
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
609
|
+
const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
610
|
+
const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
611
|
+
return {
|
|
612
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
613
|
+
};
|
|
614
|
+
},
|
|
615
|
+
};
|
|
552
616
|
exports.aaveV3QuotePriceSubData = {
|
|
553
617
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
554
618
|
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
@@ -535,6 +535,145 @@ describe('Feature: subDataService.ts', () => {
|
|
|
535
535
|
});
|
|
536
536
|
});
|
|
537
537
|
});
|
|
538
|
+
describe('When testing subDataService.aaveV3DebtSwitchSubData', () => {
|
|
539
|
+
describe('encode()', () => {
|
|
540
|
+
const examples = [
|
|
541
|
+
// USDC -> DAI
|
|
542
|
+
[
|
|
543
|
+
[
|
|
544
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
545
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
546
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
547
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
548
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
549
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
550
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
551
|
+
],
|
|
552
|
+
[
|
|
553
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
554
|
+
1,
|
|
555
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
556
|
+
3,
|
|
557
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
558
|
+
'10000000000000000000',
|
|
559
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
560
|
+
]
|
|
561
|
+
],
|
|
562
|
+
// DAI -> USDC (MaxUint256)
|
|
563
|
+
[
|
|
564
|
+
[
|
|
565
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
566
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
567
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
568
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
569
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
570
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
571
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
572
|
+
],
|
|
573
|
+
[
|
|
574
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
575
|
+
3,
|
|
576
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
577
|
+
1,
|
|
578
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
579
|
+
tokens_2.MAXUINT,
|
|
580
|
+
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
581
|
+
]
|
|
582
|
+
],
|
|
583
|
+
];
|
|
584
|
+
examples.forEach(([expected, actual]) => {
|
|
585
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
586
|
+
(0, chai_1.expect)(subDataService.aaveV3DebtSwitchSubData.encode(...actual)).to.eql(expected);
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
describe('decode()', () => {
|
|
591
|
+
const examples = [
|
|
592
|
+
// USDC -> DAI
|
|
593
|
+
[
|
|
594
|
+
{
|
|
595
|
+
fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
596
|
+
fromAssetId: 1,
|
|
597
|
+
toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
598
|
+
toAssetId: 3,
|
|
599
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
600
|
+
amountToSwitch: '10000000000000000000',
|
|
601
|
+
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
602
|
+
},
|
|
603
|
+
[
|
|
604
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
605
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
606
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
607
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
608
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
609
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
610
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
611
|
+
],
|
|
612
|
+
],
|
|
613
|
+
// DAI -> USDC (MaxUint256)
|
|
614
|
+
[
|
|
615
|
+
{
|
|
616
|
+
fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
617
|
+
fromAssetId: 3,
|
|
618
|
+
toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
619
|
+
toAssetId: 1,
|
|
620
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
621
|
+
amountToSwitch: tokens_2.MAXUINT,
|
|
622
|
+
user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
623
|
+
},
|
|
624
|
+
[
|
|
625
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
626
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
627
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
628
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
629
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
630
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
631
|
+
'0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
|
|
632
|
+
],
|
|
633
|
+
],
|
|
634
|
+
];
|
|
635
|
+
examples.forEach(([expected, actual]) => {
|
|
636
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
637
|
+
(0, chai_1.expect)(subDataService.aaveV3DebtSwitchSubData.decode(actual)).to.eql(expected);
|
|
638
|
+
});
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
describe('When testing subDataService.aaveV3GenericFLCollateralSwitchSubData', () => {
|
|
643
|
+
const fromAsset = web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address);
|
|
644
|
+
const toAsset = web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address);
|
|
645
|
+
const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
646
|
+
const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
|
|
647
|
+
const examples = [
|
|
648
|
+
['10000000000000000000', '0x0000000000000000000000000000000000000000000000008ac7230489e80000'],
|
|
649
|
+
[tokens_2.MAXUINT, '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
|
|
650
|
+
];
|
|
651
|
+
examples.forEach(([amountToSwitch, encodedAmount]) => {
|
|
652
|
+
const subData = [
|
|
653
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
654
|
+
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
655
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
656
|
+
'0x000000000000000000000000000000000000000000000000000000000000ffff',
|
|
657
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
658
|
+
encodedAmount,
|
|
659
|
+
'0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
|
|
660
|
+
];
|
|
661
|
+
it(`encode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
|
|
662
|
+
(0, chai_1.expect)(subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user)).to.eql(subData);
|
|
663
|
+
});
|
|
664
|
+
it(`decode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
|
|
665
|
+
(0, chai_1.expect)(subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subData)).to.eql({
|
|
666
|
+
fromAsset,
|
|
667
|
+
fromAssetId: 256,
|
|
668
|
+
toAsset,
|
|
669
|
+
toAssetId: 65535,
|
|
670
|
+
marketAddr,
|
|
671
|
+
amountToSwitch,
|
|
672
|
+
user,
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
});
|
|
538
677
|
describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
|
|
539
678
|
describe('encode()', () => {
|
|
540
679
|
const examples = [
|