@defisaver/automation-sdk 3.1.10 → 3.1.14-spark-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/automation/private/StrategiesAutomation.d.ts +5 -3
- package/cjs/automation/private/StrategiesAutomation.js +27 -10
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +352 -11
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +1 -1
- package/cjs/services/ethereumService.js +21 -14
- package/cjs/services/ethereumService.test.js +3 -0
- package/cjs/services/strategiesService.js +329 -54
- package/cjs/services/strategiesService.test.js +1 -0
- package/cjs/services/strategySubService.d.ts +24 -5
- package/cjs/services/strategySubService.js +116 -10
- package/cjs/services/strategySubService.test.js +1049 -173
- package/cjs/services/subDataService.d.ts +361 -88
- package/cjs/services/subDataService.js +799 -249
- package/cjs/services/subDataService.test.js +1287 -142
- package/cjs/services/triggerService.d.ts +100 -9
- package/cjs/services/triggerService.js +188 -19
- package/cjs/services/triggerService.test.js +437 -46
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/services/utils.test.js +0 -77
- package/cjs/types/enums.d.ts +88 -12
- package/cjs/types/enums.js +78 -2
- package/cjs/types/index.d.ts +59 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -3
- package/esm/automation/private/StrategiesAutomation.js +27 -10
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +351 -10
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/services/ethereumService.js +21 -14
- package/esm/services/ethereumService.test.js +3 -0
- package/esm/services/strategiesService.js +330 -55
- package/esm/services/strategiesService.test.js +1 -0
- package/esm/services/strategySubService.d.ts +24 -5
- package/esm/services/strategySubService.js +115 -9
- package/esm/services/strategySubService.test.js +1052 -176
- package/esm/services/subDataService.d.ts +361 -88
- package/esm/services/subDataService.js +799 -249
- package/esm/services/subDataService.test.js +1288 -143
- package/esm/services/triggerService.d.ts +100 -9
- package/esm/services/triggerService.js +187 -18
- package/esm/services/triggerService.test.js +438 -47
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/services/utils.test.js +1 -52
- package/esm/types/enums.d.ts +88 -12
- package/esm/types/enums.js +78 -2
- package/esm/types/index.d.ts +59 -1
- package/package.json +4 -5
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +38 -15
- package/src/constants/index.ts +353 -11
- package/src/index.ts +4 -2
- package/src/services/ethereumService.test.ts +3 -0
- package/src/services/ethereumService.ts +23 -16
- package/src/services/strategiesService.test.ts +1 -0
- package/src/services/strategiesService.ts +387 -72
- package/src/services/strategySubService.test.ts +1330 -316
- package/src/services/strategySubService.ts +365 -12
- package/src/services/subDataService.test.ts +1413 -170
- package/src/services/subDataService.ts +1148 -431
- package/src/services/triggerService.test.ts +482 -52
- package/src/services/triggerService.ts +272 -27
- package/src/services/utils.test.ts +0 -59
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +78 -2
- package/src/types/index.ts +74 -1
- package/umd/index.js +0 -34219
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fluidLeverageManagementSubData = exports.
|
|
6
|
+
exports.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV4CollateralSwitchSubData = exports.aaveV4CloseSubData = exports.aaveV4LeverageManagementOnPriceSubData = exports.aaveV4LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLeverageManagementWithoutSubProxy = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
9
9
|
const web3_utils_1 = require("web3-utils");
|
|
@@ -12,6 +12,68 @@ const sdk_1 = require("@defisaver/sdk");
|
|
|
12
12
|
const enums_1 = require("../types/enums");
|
|
13
13
|
const constants_1 = require("../constants");
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
|
+
/**
|
|
16
|
+
_______ _______ .______ .______ _______ ______ ___ .___________. _______ _______
|
|
17
|
+
| \ | ____|| _ \ | _ \ | ____| / | / \ | || ____|| \
|
|
18
|
+
| .--. || |__ | |_) | | |_) | | |__ | ,----' / ^ \ `---| |----`| |__ | .--. |
|
|
19
|
+
| | | || __| | ___/ | / | __| | | / /_\ \ | | | __| | | | |
|
|
20
|
+
| '--' || |____ | | | |\ \----.| |____ | `----./ _____ \ | | | |____ | '--' |
|
|
21
|
+
|_______/ |_______|| _| | _| `._____||_______| \______/__/ \__\ |__| |_______||_______/
|
|
22
|
+
*/
|
|
23
|
+
exports.morphoAaveV2LeverageManagementSubData = {
|
|
24
|
+
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
25
|
+
return [
|
|
26
|
+
(0, utils_1.ratioPercentageToWei)(triggerRepayRatio),
|
|
27
|
+
(0, utils_1.ratioPercentageToWei)(triggerBoostRatio),
|
|
28
|
+
(0, utils_1.ratioPercentageToWei)(targetBoostRatio),
|
|
29
|
+
(0, utils_1.ratioPercentageToWei)(targetRepayRatio),
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
boostEnabled,
|
|
32
|
+
];
|
|
33
|
+
},
|
|
34
|
+
decode(subData) {
|
|
35
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint128', subData[1]);
|
|
36
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
37
|
+
return { targetRatio };
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
exports.cBondsRebondSubData = {
|
|
41
|
+
encode(bondId) {
|
|
42
|
+
const bondIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', bondId);
|
|
43
|
+
return [bondIdEncoded];
|
|
44
|
+
},
|
|
45
|
+
decode(subData) {
|
|
46
|
+
const bondId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
47
|
+
return { bondId };
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
exports.liquityPaybackUsingChickenBondSubData = {
|
|
51
|
+
/**
|
|
52
|
+
* @param sourceId bondId or subId
|
|
53
|
+
* @param sourceType 0 for bond, 1 for subId
|
|
54
|
+
* @param chainId
|
|
55
|
+
*/
|
|
56
|
+
encode: (sourceId, sourceType, chainId = enums_1.ChainId.Ethereum) => {
|
|
57
|
+
const sourceIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceId);
|
|
58
|
+
const sourceTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceType);
|
|
59
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('LUSD', chainId).address);
|
|
60
|
+
const bLusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('bLUSD', chainId).address);
|
|
61
|
+
return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
|
|
62
|
+
},
|
|
63
|
+
decode: (subData) => {
|
|
64
|
+
const sourceId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
65
|
+
const sourceType = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
66
|
+
return { sourceId, sourceType };
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
.___ ___. ___ __ ___ _______ .______
|
|
71
|
+
| \/ | / \ | |/ / | ____|| _ \
|
|
72
|
+
| \ / | / ^ \ | ' / | |__ | |_) |
|
|
73
|
+
| |\/| | / /_\ \ | < | __| | /
|
|
74
|
+
| | | | / _____ \ | . \ | |____ | |\ \----.
|
|
75
|
+
|__| |__| /__/ \__\ |__|\__\ |_______|| _| `._____|
|
|
76
|
+
*/
|
|
15
77
|
exports.makerRepayFromSavingsSubData = {
|
|
16
78
|
encode(vaultId, targetRatioPercentage, chainId, daiAddr, mcdCdpManagerAddr) {
|
|
17
79
|
const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
|
|
@@ -35,13 +97,6 @@ exports.makerRepayFromSavingsSubData = {
|
|
|
35
97
|
};
|
|
36
98
|
},
|
|
37
99
|
};
|
|
38
|
-
exports.liquityRepayFromSavingsSubData = {
|
|
39
|
-
decode(subData) {
|
|
40
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
41
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
42
|
-
return { targetRatio };
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
100
|
exports.makerCloseSubData = {
|
|
46
101
|
encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr) {
|
|
47
102
|
const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
|
|
@@ -76,6 +131,35 @@ exports.makerLeverageManagementSubData = {
|
|
|
76
131
|
return { vaultId, targetRatio };
|
|
77
132
|
},
|
|
78
133
|
};
|
|
134
|
+
exports.makerLeverageManagementWithoutSubProxy = {
|
|
135
|
+
encode(vaultId, targetRatio, daiAddr) {
|
|
136
|
+
const encodedVaultId = web3_eth_abi_1.default.encodeParameter('uint256', vaultId);
|
|
137
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
138
|
+
const encodedDaiAddr = web3_eth_abi_1.default.encodeParameter('address', daiAddr || (0, tokens_1.getAssetInfo)('DAI', 1).address);
|
|
139
|
+
return [encodedVaultId, encodedTargetRatio, encodedDaiAddr];
|
|
140
|
+
},
|
|
141
|
+
decode(subData) {
|
|
142
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
143
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[1]));
|
|
144
|
+
const daiAddr = web3_eth_abi_1.default.decodeParameter('address', subData[2]).toString();
|
|
145
|
+
return { vaultId, targetRatio, daiAddr };
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
__ __ ______ __ __ __ .___________.____ ____ ____ ____ __
|
|
150
|
+
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
|
|
151
|
+
| | | | | | | | | | | | | | `---| |----` \ \/ / \ \/ / | |
|
|
152
|
+
| | | | | | | | | | | | | | | | \_ _/ \ / | |
|
|
153
|
+
| `----.| | | `--' '--.| `--' | | | | | | | \ / | |
|
|
154
|
+
|_______||__| \_____\_____\\______/ |__| |__| |__| \__/ |_|
|
|
155
|
+
*/
|
|
156
|
+
exports.liquityRepayFromSavingsSubData = {
|
|
157
|
+
decode(subData) {
|
|
158
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
159
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
160
|
+
return { targetRatio };
|
|
161
|
+
},
|
|
162
|
+
};
|
|
79
163
|
exports.liquityLeverageManagementSubData = {
|
|
80
164
|
decode: (subData) => {
|
|
81
165
|
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
@@ -102,6 +186,201 @@ exports.liquityCloseSubData = {
|
|
|
102
186
|
return { closeToAssetAddr, debtAddr };
|
|
103
187
|
},
|
|
104
188
|
};
|
|
189
|
+
exports.liquityDsrPaybackSubData = {
|
|
190
|
+
encode: (targetRatio) => {
|
|
191
|
+
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
192
|
+
const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
|
|
193
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
194
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
195
|
+
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
196
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
|
|
197
|
+
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, lusdAddressEncoded];
|
|
198
|
+
},
|
|
199
|
+
decode: (subData) => {
|
|
200
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
201
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
202
|
+
return { targetRatio };
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
exports.liquityDsrSupplySubData = {
|
|
206
|
+
encode: (targetRatio) => {
|
|
207
|
+
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
208
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
209
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
210
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
211
|
+
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
212
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
213
|
+
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, wethAddressEncoded];
|
|
214
|
+
},
|
|
215
|
+
decode: (subData) => {
|
|
216
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
217
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
218
|
+
return { targetRatio };
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
exports.liquityDebtInFrontRepaySubData = {
|
|
222
|
+
encode: (targetRatioIncrease) => {
|
|
223
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
224
|
+
const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
|
|
225
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
226
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
|
|
227
|
+
const targetRatioIncreaseEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatioIncrease));
|
|
228
|
+
const withdrawIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 1); // withdraw - 1
|
|
229
|
+
const paybackIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 0); // payback - 0
|
|
230
|
+
return [wethAddressEncoded, lusdAddressEncoded, targetRatioIncreaseEncoded, withdrawIdEncoded, paybackIdEncoded];
|
|
231
|
+
},
|
|
232
|
+
decode: (subData) => {
|
|
233
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
|
|
234
|
+
const targetRatioIncrease = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
235
|
+
return { targetRatioIncrease };
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* __ __ ______ __ __ __ .___________.____ ____ ____ ____ ___
|
|
240
|
+
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / |__ \
|
|
241
|
+
| | | | | | | | | | | | | | `---| |----` \ \/ / \ \/ / ) |
|
|
242
|
+
| | | | | | | | | | | | | | | | \_ _/ \ / / /
|
|
243
|
+
| `----.| | | `--' '--.| `--' | | | | | | | \ / / /_
|
|
244
|
+
|_______||__| \_____\_____\\______/ |__| |__| |__| \__/ |____|
|
|
245
|
+
*/
|
|
246
|
+
exports.liquityV2LeverageManagementSubData = {
|
|
247
|
+
encode: (market, troveId, collToken, boldToken, ratioState, targetRatio) => {
|
|
248
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
249
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
250
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
251
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
252
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
253
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
254
|
+
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
255
|
+
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
256
|
+
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
257
|
+
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
258
|
+
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
259
|
+
return [
|
|
260
|
+
marketEncoded,
|
|
261
|
+
troveIdEncoded,
|
|
262
|
+
collTokenEncoded,
|
|
263
|
+
boldTokenEncoded,
|
|
264
|
+
ratioStateEncoded,
|
|
265
|
+
targetRatioEncoded,
|
|
266
|
+
collActionTypeEncoded,
|
|
267
|
+
debtActionTypeEncoded,
|
|
268
|
+
];
|
|
269
|
+
},
|
|
270
|
+
decode: (subData) => {
|
|
271
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
272
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
273
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
274
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
275
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
276
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
277
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
278
|
+
return {
|
|
279
|
+
market, troveId, collToken, boldToken, ratioState, targetRatio,
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
exports.liquityV2CloseSubData = {
|
|
284
|
+
encode(market, troveId, collToken, boldToken, closeType) {
|
|
285
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
286
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
287
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
288
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
289
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
290
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
291
|
+
const gasCompensation = new decimal_js_1.default('0.0375').mul(1e18).toString();
|
|
292
|
+
const gasCompensationEncoded = web3_eth_abi_1.default.encodeParameter('uint256', gasCompensation);
|
|
293
|
+
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
294
|
+
return [
|
|
295
|
+
marketEncoded,
|
|
296
|
+
troveIdEncoded,
|
|
297
|
+
collAddrEncoded,
|
|
298
|
+
boldTokenEncoded,
|
|
299
|
+
wethAddressEncoded,
|
|
300
|
+
gasCompensationEncoded,
|
|
301
|
+
closeTypeEncoded,
|
|
302
|
+
];
|
|
303
|
+
},
|
|
304
|
+
decode(subData) {
|
|
305
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
306
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
307
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
308
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
309
|
+
// skip wethAddress and gasCompensation
|
|
310
|
+
const closeType = web3_eth_abi_1.default.decodeParameter('uint8', subData[6]);
|
|
311
|
+
return {
|
|
312
|
+
market, troveId, collToken, boldToken, closeType,
|
|
313
|
+
};
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
exports.liquityV2LeverageManagementOnPriceSubData = {
|
|
317
|
+
encode(market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice) {
|
|
318
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
319
|
+
const encodedTroveId = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
320
|
+
const encodedCollToken = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
321
|
+
const encodedBoldToken = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
322
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
323
|
+
const collActionType = isRepayOnPrice ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
324
|
+
const debtActionType = isRepayOnPrice ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
325
|
+
const encodedCollActionType = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
326
|
+
const encodedDebtActionType = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
327
|
+
return [
|
|
328
|
+
encodedMarket,
|
|
329
|
+
encodedTroveId,
|
|
330
|
+
encodedCollToken,
|
|
331
|
+
encodedBoldToken,
|
|
332
|
+
encodedTargetRatio,
|
|
333
|
+
encodedCollActionType,
|
|
334
|
+
encodedDebtActionType,
|
|
335
|
+
];
|
|
336
|
+
},
|
|
337
|
+
decode(subData) {
|
|
338
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
339
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
340
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
341
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
342
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
343
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
344
|
+
return {
|
|
345
|
+
market, troveId, collToken, boldToken, targetRatio,
|
|
346
|
+
};
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
exports.liquityV2PaybackSubData = {
|
|
350
|
+
encode: (market, troveId, boldToken, targetRatio, ratioState) => {
|
|
351
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
352
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
353
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
354
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
355
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
356
|
+
return [
|
|
357
|
+
marketEncoded,
|
|
358
|
+
troveIdEncoded,
|
|
359
|
+
boldTokenEncoded,
|
|
360
|
+
targetRatioEncoded,
|
|
361
|
+
ratioStateEncoded,
|
|
362
|
+
];
|
|
363
|
+
},
|
|
364
|
+
decode: (subData) => {
|
|
365
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
366
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
367
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
368
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
369
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
370
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
371
|
+
return {
|
|
372
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
373
|
+
};
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
___ ___ ____ ____ _______ ____ ____ ___
|
|
378
|
+
/ \ / \ \ \ / / | ____| \ \ / / |__ \
|
|
379
|
+
/ ^ \ / ^ \ \ \/ / | |__ \ \/ / ) |
|
|
380
|
+
/ /_\ \ / /_\ \ \ / | __| \ / / /
|
|
381
|
+
/ _____ \ / _____ \ \ / | |____ \ / / /_
|
|
382
|
+
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____|
|
|
383
|
+
*/
|
|
105
384
|
exports.aaveV2LeverageManagementSubData = {
|
|
106
385
|
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
107
386
|
return [
|
|
@@ -119,6 +398,14 @@ exports.aaveV2LeverageManagementSubData = {
|
|
|
119
398
|
return { targetRatio };
|
|
120
399
|
},
|
|
121
400
|
};
|
|
401
|
+
/**
|
|
402
|
+
___ ___ ____ ____ _______ ____ ____ ____
|
|
403
|
+
/ \ / \ \ \ / / | ____| \ \ / / |___ \
|
|
404
|
+
/ ^ \ / ^ \ \ \/ / | |__ \ \/ / __) |
|
|
405
|
+
/ /_\ \ / /_\ \ \ / | __| \ / |__ <
|
|
406
|
+
/ _____ \ / _____ \ \ / | |____ \ / ___) |
|
|
407
|
+
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |____/
|
|
408
|
+
*/
|
|
122
409
|
exports.aaveV3LeverageManagementSubData = {
|
|
123
410
|
decode(subData) {
|
|
124
411
|
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
@@ -126,6 +413,127 @@ exports.aaveV3LeverageManagementSubData = {
|
|
|
126
413
|
return { targetRatio };
|
|
127
414
|
},
|
|
128
415
|
};
|
|
416
|
+
exports.aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
417
|
+
encode(targetRatio, ratioState, market, user, isGeneric) {
|
|
418
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
419
|
+
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
420
|
+
if (isGeneric) {
|
|
421
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
422
|
+
const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
423
|
+
return [encodedTargetRatio, encodedRatioState, encodedMarket, encodedUser];
|
|
424
|
+
}
|
|
425
|
+
const encodedUseDefaultMarket = web3_eth_abi_1.default.encodeParameter('bool', true);
|
|
426
|
+
const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', false);
|
|
427
|
+
return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
|
|
428
|
+
},
|
|
429
|
+
decode(subData) {
|
|
430
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
|
|
431
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
|
|
432
|
+
return { targetRatio, ratioState };
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
exports.aaveV3LeverageManagementOnPriceGeneric = {
|
|
436
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user) {
|
|
437
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
438
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
439
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
440
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
441
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
442
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
443
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
444
|
+
return [
|
|
445
|
+
encodedColl,
|
|
446
|
+
encodedCollId,
|
|
447
|
+
encodedDebt,
|
|
448
|
+
encodedDebtId,
|
|
449
|
+
encodedMarket,
|
|
450
|
+
encodedTargetRatio,
|
|
451
|
+
userEncoded,
|
|
452
|
+
];
|
|
453
|
+
},
|
|
454
|
+
decode(subData) {
|
|
455
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
456
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
457
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
458
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
459
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
460
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
461
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
462
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
463
|
+
return {
|
|
464
|
+
collAsset,
|
|
465
|
+
collAssetId,
|
|
466
|
+
debtAsset,
|
|
467
|
+
debtAssetId,
|
|
468
|
+
marketAddr,
|
|
469
|
+
targetRatio,
|
|
470
|
+
owner,
|
|
471
|
+
};
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
exports.aaveV3CloseGenericSubData = {
|
|
475
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user) {
|
|
476
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
477
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
478
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
479
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
480
|
+
const encodedCloseType = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
481
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
482
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
483
|
+
return [
|
|
484
|
+
encodedColl,
|
|
485
|
+
encodedCollId,
|
|
486
|
+
encodedDebt,
|
|
487
|
+
encodedDebtId,
|
|
488
|
+
encodedCloseType,
|
|
489
|
+
encodedMarket,
|
|
490
|
+
userEncoded,
|
|
491
|
+
];
|
|
492
|
+
},
|
|
493
|
+
decode(subData) {
|
|
494
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
495
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
496
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
497
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
498
|
+
const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[4]));
|
|
499
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
|
|
500
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
501
|
+
return {
|
|
502
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
|
|
503
|
+
};
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
exports.aaveV3CollateralSwitchSubData = {
|
|
507
|
+
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
|
|
508
|
+
const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
|
|
509
|
+
const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
|
|
510
|
+
const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
|
|
511
|
+
const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
|
|
512
|
+
const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
513
|
+
const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
|
|
514
|
+
const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', useOnBehalf);
|
|
515
|
+
return [
|
|
516
|
+
encodedFromAsset,
|
|
517
|
+
encodedFromAssetId,
|
|
518
|
+
encodedToAsset,
|
|
519
|
+
encodedToAssetId,
|
|
520
|
+
encodedMarketAddr,
|
|
521
|
+
encodedAmountToSwitch,
|
|
522
|
+
encodedUseOnBehalf,
|
|
523
|
+
];
|
|
524
|
+
},
|
|
525
|
+
decode(subData) {
|
|
526
|
+
const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
527
|
+
const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
528
|
+
const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
529
|
+
const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
530
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
531
|
+
const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
532
|
+
return {
|
|
533
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
|
|
534
|
+
};
|
|
535
|
+
},
|
|
536
|
+
};
|
|
129
537
|
exports.aaveV3QuotePriceSubData = {
|
|
130
538
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
131
539
|
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
@@ -145,6 +553,188 @@ exports.aaveV3QuotePriceSubData = {
|
|
|
145
553
|
};
|
|
146
554
|
},
|
|
147
555
|
};
|
|
556
|
+
exports.aaveV3LeverageManagementOnPriceSubData = {
|
|
557
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
|
|
558
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
559
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
560
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
561
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
562
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
563
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
564
|
+
const useOnBehalfEncoded = web3_eth_abi_1.default.encodeParameter('bool', false);
|
|
565
|
+
return [
|
|
566
|
+
encodedColl,
|
|
567
|
+
encodedCollId,
|
|
568
|
+
encodedDebt,
|
|
569
|
+
encodedDebtId,
|
|
570
|
+
encodedMarket,
|
|
571
|
+
encodedTargetRatio,
|
|
572
|
+
useOnBehalfEncoded,
|
|
573
|
+
];
|
|
574
|
+
},
|
|
575
|
+
decode(subData) {
|
|
576
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
577
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
578
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
579
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
580
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
581
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
582
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
583
|
+
return {
|
|
584
|
+
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
585
|
+
};
|
|
586
|
+
},
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* ___ ___ ____ ____ _______ ____ ____ _ _
|
|
590
|
+
/ \ / \ \ \ / / | ____| \ \ / / | || |
|
|
591
|
+
/ ^ \ / ^ \ \ \/ / | |__ \ \/ / | || |_
|
|
592
|
+
/ /_\ \ / /_\ \ \ / | __| \ / |__ _|
|
|
593
|
+
/ _____ \ / _____ \ \ / | |____ \ / | |
|
|
594
|
+
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
|
|
595
|
+
*/
|
|
596
|
+
exports.aaveV4LeverageManagementSubData = {
|
|
597
|
+
encode: (spoke, owner, ratioState, targetRatio) => {
|
|
598
|
+
const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
|
|
599
|
+
const ownerEncoded = web3_eth_abi_1.default.encodeParameter('address', owner);
|
|
600
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
601
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
602
|
+
// Add two empty slots for future addons (e.g tsi or slippage settings)
|
|
603
|
+
return [
|
|
604
|
+
spokeEncoded,
|
|
605
|
+
ownerEncoded,
|
|
606
|
+
ratioStateEncoded,
|
|
607
|
+
targetRatioEncoded,
|
|
608
|
+
constants_1.EMPTY_SLOT,
|
|
609
|
+
constants_1.EMPTY_SLOT,
|
|
610
|
+
];
|
|
611
|
+
},
|
|
612
|
+
decode: (subData) => {
|
|
613
|
+
const spoke = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
614
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
615
|
+
const ratioState = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[2]));
|
|
616
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
|
|
617
|
+
return {
|
|
618
|
+
spoke, owner, ratioState, targetRatio,
|
|
619
|
+
};
|
|
620
|
+
},
|
|
621
|
+
};
|
|
622
|
+
exports.aaveV4LeverageManagementOnPriceSubData = {
|
|
623
|
+
encode: (spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio) => {
|
|
624
|
+
const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
|
|
625
|
+
const ownerEncoded = web3_eth_abi_1.default.encodeParameter('address', owner);
|
|
626
|
+
const collAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
627
|
+
const collAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', collAssetId);
|
|
628
|
+
const debtAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
629
|
+
const debtAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', debtAssetId);
|
|
630
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
631
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
632
|
+
// Add two empty slots for future addons (e.g tsi or slippage settings)
|
|
633
|
+
return [
|
|
634
|
+
spokeEncoded,
|
|
635
|
+
ownerEncoded,
|
|
636
|
+
collAssetEncoded,
|
|
637
|
+
collAssetIdEncoded,
|
|
638
|
+
debtAssetEncoded,
|
|
639
|
+
debtAssetIdEncoded,
|
|
640
|
+
ratioStateEncoded,
|
|
641
|
+
targetRatioEncoded,
|
|
642
|
+
constants_1.EMPTY_SLOT,
|
|
643
|
+
constants_1.EMPTY_SLOT,
|
|
644
|
+
];
|
|
645
|
+
},
|
|
646
|
+
decode: (subData) => {
|
|
647
|
+
const spoke = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
648
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
649
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
650
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
|
|
651
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
652
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[5]));
|
|
653
|
+
const ratioState = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[6]));
|
|
654
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[7]));
|
|
655
|
+
return {
|
|
656
|
+
spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio,
|
|
657
|
+
};
|
|
658
|
+
},
|
|
659
|
+
};
|
|
660
|
+
exports.aaveV4CloseSubData = {
|
|
661
|
+
encode: (spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType) => {
|
|
662
|
+
const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
|
|
663
|
+
const ownerEncoded = web3_eth_abi_1.default.encodeParameter('address', owner);
|
|
664
|
+
const collAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
665
|
+
const collAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', collAssetId);
|
|
666
|
+
const debtAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
667
|
+
const debtAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', debtAssetId);
|
|
668
|
+
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
669
|
+
// Add two empty slots for future addons (e.g tsi or slippage settings)
|
|
670
|
+
return [
|
|
671
|
+
spokeEncoded,
|
|
672
|
+
ownerEncoded,
|
|
673
|
+
collAssetEncoded,
|
|
674
|
+
collAssetIdEncoded,
|
|
675
|
+
debtAssetEncoded,
|
|
676
|
+
debtAssetIdEncoded,
|
|
677
|
+
closeTypeEncoded,
|
|
678
|
+
constants_1.EMPTY_SLOT,
|
|
679
|
+
constants_1.EMPTY_SLOT,
|
|
680
|
+
];
|
|
681
|
+
},
|
|
682
|
+
decode: (subData) => {
|
|
683
|
+
const spoke = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
684
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
685
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
686
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
|
|
687
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
688
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[5]));
|
|
689
|
+
const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[6]));
|
|
690
|
+
return {
|
|
691
|
+
spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType,
|
|
692
|
+
};
|
|
693
|
+
},
|
|
694
|
+
};
|
|
695
|
+
exports.aaveV4CollateralSwitchSubData = {
|
|
696
|
+
encode: (spoke, owner, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch) => {
|
|
697
|
+
const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
|
|
698
|
+
const ownerEncoded = web3_eth_abi_1.default.encodeParameter('address', owner);
|
|
699
|
+
const fromAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
|
|
700
|
+
const fromAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', fromAssetId);
|
|
701
|
+
const toAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', toAsset);
|
|
702
|
+
const toAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', toAssetId);
|
|
703
|
+
const amountToSwitchEncoded = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
|
|
704
|
+
// Add two empty slots for future addons (e.g tsi or slippage settings)
|
|
705
|
+
return [
|
|
706
|
+
spokeEncoded,
|
|
707
|
+
ownerEncoded,
|
|
708
|
+
fromAssetEncoded,
|
|
709
|
+
fromAssetIdEncoded,
|
|
710
|
+
toAssetEncoded,
|
|
711
|
+
toAssetIdEncoded,
|
|
712
|
+
amountToSwitchEncoded,
|
|
713
|
+
constants_1.EMPTY_SLOT,
|
|
714
|
+
constants_1.EMPTY_SLOT,
|
|
715
|
+
];
|
|
716
|
+
},
|
|
717
|
+
decode: (subData) => {
|
|
718
|
+
const spoke = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
719
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
720
|
+
const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
721
|
+
const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
|
|
722
|
+
const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
723
|
+
const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[5]));
|
|
724
|
+
const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[6]);
|
|
725
|
+
return {
|
|
726
|
+
spoke, owner, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch,
|
|
727
|
+
};
|
|
728
|
+
},
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
______ ______ .___ ___. .______ ____ ____ ___
|
|
732
|
+
/ | / __ \ | \/ | | _ \ \ \ / / |__ \
|
|
733
|
+
| ,----'| | | | | \ / | | |_) | \ \/ / ) |
|
|
734
|
+
| | | | | | | |\/| | | ___/ \ / / /
|
|
735
|
+
| `----.| `--' | | | | | | | \ / / /_
|
|
736
|
+
\______| \______/ |__| |__| | _| \__/ |____|
|
|
737
|
+
*/
|
|
148
738
|
exports.compoundV2LeverageManagementSubData = {
|
|
149
739
|
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
150
740
|
return [
|
|
@@ -162,6 +752,14 @@ exports.compoundV2LeverageManagementSubData = {
|
|
|
162
752
|
return { targetRatio };
|
|
163
753
|
},
|
|
164
754
|
};
|
|
755
|
+
/**
|
|
756
|
+
______ ______ .___ ___. .______ ____ ____ ____
|
|
757
|
+
/ | / __ \ | \/ | | _ \ \ \ / / |___ \
|
|
758
|
+
| ,----'| | | | | \ / | | |_) | \ \/ / __) |
|
|
759
|
+
| | | | | | | |\/| | | ___/ \ / |__ <
|
|
760
|
+
| `----.| `--' | | | | | | | \ / ___) |
|
|
761
|
+
\______| \______/ |__| |__| | _| \__/ |____/
|
|
762
|
+
*/
|
|
165
763
|
exports.compoundV3LeverageManagementSubData = {
|
|
166
764
|
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
167
765
|
return [
|
|
@@ -182,7 +780,7 @@ exports.compoundV3LeverageManagementSubData = {
|
|
|
182
780
|
},
|
|
183
781
|
};
|
|
184
782
|
exports.compoundV3L2LeverageManagementSubData = {
|
|
185
|
-
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
783
|
+
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
186
784
|
let subInput = '0x';
|
|
187
785
|
subInput = subInput.concat(market.slice(2));
|
|
188
786
|
subInput = subInput.concat(baseToken.slice(2));
|
|
@@ -195,6 +793,7 @@ exports.compoundV3L2LeverageManagementSubData = {
|
|
|
195
793
|
subInput = subInput.concat(new decimal_js_1.default(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
196
794
|
.padStart(32, '0'));
|
|
197
795
|
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
796
|
+
subInput = subInput.concat(isEOA ? '01' : '00');
|
|
198
797
|
return subInput;
|
|
199
798
|
},
|
|
200
799
|
decode(subData) {
|
|
@@ -203,52 +802,70 @@ exports.compoundV3L2LeverageManagementSubData = {
|
|
|
203
802
|
return { targetRatio };
|
|
204
803
|
},
|
|
205
804
|
};
|
|
206
|
-
exports.
|
|
207
|
-
encode(
|
|
805
|
+
exports.compoundV3LeverageManagementOnPriceSubData = {
|
|
806
|
+
encode(market, collToken, baseToken, targetRatio, ratioState, user) {
|
|
807
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
808
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
809
|
+
const baseTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', baseToken);
|
|
810
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
811
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
812
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
208
813
|
return [
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
814
|
+
marketEncoded,
|
|
815
|
+
collTokenEncoded,
|
|
816
|
+
baseTokenEncoded,
|
|
817
|
+
targetRatioEncoded,
|
|
818
|
+
ratioStateEncoded,
|
|
819
|
+
userEncoded,
|
|
215
820
|
];
|
|
216
821
|
},
|
|
217
822
|
decode(subData) {
|
|
218
|
-
const
|
|
219
|
-
const
|
|
220
|
-
|
|
823
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
824
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
825
|
+
const baseToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
826
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
827
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
828
|
+
const ratioState = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[4]));
|
|
829
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
|
|
830
|
+
return {
|
|
831
|
+
market, collToken, baseToken, targetRatio, ratioState, owner,
|
|
832
|
+
};
|
|
221
833
|
},
|
|
222
834
|
};
|
|
223
|
-
exports.
|
|
224
|
-
encode(
|
|
225
|
-
const
|
|
226
|
-
|
|
835
|
+
exports.compoundV3CloseSubData = {
|
|
836
|
+
encode(market, collToken, baseToken, closeType, user) {
|
|
837
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
838
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
839
|
+
const baseTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', baseToken);
|
|
840
|
+
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
841
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
842
|
+
return [
|
|
843
|
+
marketEncoded,
|
|
844
|
+
collTokenEncoded,
|
|
845
|
+
baseTokenEncoded,
|
|
846
|
+
closeTypeEncoded,
|
|
847
|
+
userEncoded,
|
|
848
|
+
];
|
|
227
849
|
},
|
|
228
850
|
decode(subData) {
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
* @param chainId
|
|
238
|
-
*/
|
|
239
|
-
encode: (sourceId, sourceType, chainId = enums_1.ChainId.Ethereum) => {
|
|
240
|
-
const sourceIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceId);
|
|
241
|
-
const sourceTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceType);
|
|
242
|
-
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('LUSD', chainId).address);
|
|
243
|
-
const bLusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('bLUSD', chainId).address);
|
|
244
|
-
return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
|
|
245
|
-
},
|
|
246
|
-
decode: (subData) => {
|
|
247
|
-
const sourceId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
248
|
-
const sourceType = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
249
|
-
return { sourceId, sourceType };
|
|
851
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
852
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
853
|
+
const baseToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
854
|
+
const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
855
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
856
|
+
return {
|
|
857
|
+
market, collToken, baseToken, closeType, owner,
|
|
858
|
+
};
|
|
250
859
|
},
|
|
251
860
|
};
|
|
861
|
+
/**
|
|
862
|
+
__________ ___ ______ __ __ ___ .__ __. _______ _______
|
|
863
|
+
| ____\ \ / / / || | | | / \ | \ | | / _____|| ____|
|
|
864
|
+
| |__ \ V / | ,----'| |__| | / ^ \ | \| | | | __ | |__
|
|
865
|
+
| __| > < | | | __ | / /_\ \ | . ` | | | |_ | | __|
|
|
866
|
+
| |____ / . \ | `----.| | | | / _____ \ | |\ | | |__| | | |____
|
|
867
|
+
|_______/__/ \__\ \______||__| |__| /__/ \__\ |__| \__| \______| |_______|
|
|
868
|
+
*/
|
|
252
869
|
exports.exchangeDcaSubData = {
|
|
253
870
|
encode: (fromToken, toToken, amount, interval) => {
|
|
254
871
|
const sellTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', fromToken);
|
|
@@ -288,6 +905,14 @@ exports.exchangeLimitOrderSubData = {
|
|
|
288
905
|
return { fromToken, toToken, amount };
|
|
289
906
|
},
|
|
290
907
|
};
|
|
908
|
+
/**
|
|
909
|
+
_______..______ ___ .______ __ ___
|
|
910
|
+
/ || _ \ / \ | _ \ | |/ /
|
|
911
|
+
| (----`| |_) | / ^ \ | |_) | | ' /
|
|
912
|
+
\ \ | ___/ / /_\ \ | / | <
|
|
913
|
+
.----) | | | / _____ \ | |\ \----.| . \
|
|
914
|
+
|_______/ | _| /__/ \__\ | _| `._____||__|\__\
|
|
915
|
+
*/
|
|
291
916
|
exports.sparkLeverageManagementSubData = {
|
|
292
917
|
decode(subData) {
|
|
293
918
|
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
@@ -295,74 +920,115 @@ exports.sparkLeverageManagementSubData = {
|
|
|
295
920
|
return { targetRatio };
|
|
296
921
|
},
|
|
297
922
|
};
|
|
298
|
-
exports.
|
|
299
|
-
encode(
|
|
923
|
+
exports.sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
924
|
+
encode(targetRatio, ratioState) {
|
|
925
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
926
|
+
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
927
|
+
const encodedUseDefaultMarket = web3_eth_abi_1.default.encodeParameter('bool', true);
|
|
928
|
+
const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', false);
|
|
929
|
+
return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
|
|
930
|
+
},
|
|
931
|
+
decode(subData) {
|
|
932
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
|
|
933
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
|
|
934
|
+
return { targetRatio, ratioState };
|
|
935
|
+
},
|
|
936
|
+
};
|
|
937
|
+
exports.sparkCloseGenericSubData = {
|
|
938
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user) {
|
|
300
939
|
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
301
940
|
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
302
941
|
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
303
942
|
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
304
|
-
const
|
|
305
|
-
|
|
943
|
+
const encodedCloseType = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
944
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
945
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
946
|
+
return [
|
|
947
|
+
encodedColl,
|
|
948
|
+
encodedCollId,
|
|
949
|
+
encodedDebt,
|
|
950
|
+
encodedDebtId,
|
|
951
|
+
encodedCloseType,
|
|
952
|
+
encodedMarket,
|
|
953
|
+
userEncoded,
|
|
954
|
+
];
|
|
306
955
|
},
|
|
307
956
|
decode(subData) {
|
|
308
957
|
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
309
958
|
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
310
959
|
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
311
960
|
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
961
|
+
const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[4]));
|
|
962
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
|
|
963
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
312
964
|
return {
|
|
313
|
-
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
965
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
|
|
314
966
|
};
|
|
315
967
|
},
|
|
316
968
|
};
|
|
317
|
-
exports.
|
|
318
|
-
encode
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
const
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
decode: (subData) => {
|
|
328
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
329
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
330
|
-
return { targetRatio };
|
|
331
|
-
},
|
|
332
|
-
};
|
|
333
|
-
exports.liquityDsrSupplySubData = {
|
|
334
|
-
encode: (targetRatio) => {
|
|
335
|
-
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
336
|
-
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
337
|
-
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
338
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
339
|
-
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
340
|
-
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
341
|
-
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, wethAddressEncoded];
|
|
969
|
+
exports.sparkLeverageManagementOnPriceSubData = {
|
|
970
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
|
|
971
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
972
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint16', collAssetId);
|
|
973
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
974
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint16', debtAssetId);
|
|
975
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
976
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
977
|
+
const useOnBehalfEncoded = web3_eth_abi_1.default.encodeParameter('bool', false);
|
|
978
|
+
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedMarket, encodedTargetRatio, useOnBehalfEncoded];
|
|
342
979
|
},
|
|
343
|
-
decode
|
|
344
|
-
const
|
|
980
|
+
decode(subData) {
|
|
981
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
982
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[1]));
|
|
983
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
984
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[3]));
|
|
985
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
986
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
345
987
|
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
346
|
-
return {
|
|
988
|
+
return {
|
|
989
|
+
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
990
|
+
};
|
|
347
991
|
},
|
|
348
992
|
};
|
|
349
|
-
exports.
|
|
350
|
-
encode
|
|
351
|
-
const
|
|
352
|
-
const
|
|
353
|
-
const
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
const
|
|
357
|
-
const
|
|
358
|
-
return [
|
|
993
|
+
exports.sparkCollateralSwitchSubData = {
|
|
994
|
+
encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
|
|
995
|
+
const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
|
|
996
|
+
const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
|
|
997
|
+
const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
|
|
998
|
+
const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
|
|
999
|
+
const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
1000
|
+
const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
|
|
1001
|
+
const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', useOnBehalf);
|
|
1002
|
+
return [
|
|
1003
|
+
encodedFromAsset,
|
|
1004
|
+
encodedFromAssetId,
|
|
1005
|
+
encodedToAsset,
|
|
1006
|
+
encodedToAssetId,
|
|
1007
|
+
encodedMarketAddr,
|
|
1008
|
+
encodedAmountToSwitch,
|
|
1009
|
+
encodedUseOnBehalf,
|
|
1010
|
+
];
|
|
359
1011
|
},
|
|
360
|
-
decode
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
|
|
1012
|
+
decode(subData) {
|
|
1013
|
+
const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
1014
|
+
const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
1015
|
+
const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
1016
|
+
const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
1017
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
1018
|
+
const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
1019
|
+
return {
|
|
1020
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
|
|
1021
|
+
};
|
|
364
1022
|
},
|
|
365
1023
|
};
|
|
1024
|
+
/**
|
|
1025
|
+
______ .______ ____ ____ __ __ _______. _______
|
|
1026
|
+
/ || _ \ \ \ / / | | | | / || \
|
|
1027
|
+
| ,----'| |_) | \ \/ / | | | | | (----`| .--. |
|
|
1028
|
+
| | | / \ / | | | | \ \ | | | |
|
|
1029
|
+
| `----.| |\ \----. \ / | `--' | .----) | | '--' |
|
|
1030
|
+
\______|| _| `._____| \__/ \______/ |_______/ |_______/
|
|
1031
|
+
*/
|
|
366
1032
|
exports.crvUSDLeverageManagementSubData = {
|
|
367
1033
|
encode: (controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr) => {
|
|
368
1034
|
const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
|
|
@@ -408,6 +1074,14 @@ exports.crvUSDPaybackSubData = {
|
|
|
408
1074
|
};
|
|
409
1075
|
},
|
|
410
1076
|
};
|
|
1077
|
+
/**
|
|
1078
|
+
.___ ___. ______ .______ .______ __ __ ______
|
|
1079
|
+
| \/ | / __ \ | _ \ | _ \ | | | | / __ \
|
|
1080
|
+
| \ / | | | | | | |_) | | |_) | | |__| | | | | |
|
|
1081
|
+
| |\/| | | | | | | / | ___/ | __ | | | | |
|
|
1082
|
+
| | | | | `--' | | |\ \----.| | | | | | | `--' |
|
|
1083
|
+
|__| |__| \______/ | _| `._____|| _| |__| |__| \______/
|
|
1084
|
+
*/
|
|
411
1085
|
exports.morphoBlueLeverageManagementSubData = {
|
|
412
1086
|
encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
|
|
413
1087
|
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
@@ -441,141 +1115,6 @@ exports.morphoBlueLeverageManagementSubData = {
|
|
|
441
1115
|
};
|
|
442
1116
|
},
|
|
443
1117
|
};
|
|
444
|
-
exports.aaveV3LeverageManagementOnPriceSubData = {
|
|
445
|
-
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
|
|
446
|
-
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
447
|
-
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
448
|
-
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
449
|
-
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
450
|
-
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
451
|
-
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
452
|
-
const useOnBehalfEncoded = web3_eth_abi_1.default.encodeParameter('bool', false);
|
|
453
|
-
return [
|
|
454
|
-
encodedColl,
|
|
455
|
-
encodedCollId,
|
|
456
|
-
encodedDebt,
|
|
457
|
-
encodedDebtId,
|
|
458
|
-
encodedMarket,
|
|
459
|
-
encodedTargetRatio,
|
|
460
|
-
useOnBehalfEncoded,
|
|
461
|
-
];
|
|
462
|
-
},
|
|
463
|
-
decode(subData) {
|
|
464
|
-
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
465
|
-
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
466
|
-
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
467
|
-
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
468
|
-
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
469
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
470
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
471
|
-
return {
|
|
472
|
-
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
473
|
-
};
|
|
474
|
-
},
|
|
475
|
-
};
|
|
476
|
-
exports.liquityV2LeverageManagementSubData = {
|
|
477
|
-
encode: (market, troveId, collToken, boldToken, ratioState, targetRatio) => {
|
|
478
|
-
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
479
|
-
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
480
|
-
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
481
|
-
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
482
|
-
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
483
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
484
|
-
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
485
|
-
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
486
|
-
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
487
|
-
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
488
|
-
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
489
|
-
return [
|
|
490
|
-
marketEncoded,
|
|
491
|
-
troveIdEncoded,
|
|
492
|
-
collTokenEncoded,
|
|
493
|
-
boldTokenEncoded,
|
|
494
|
-
ratioStateEncoded,
|
|
495
|
-
targetRatioEncoded,
|
|
496
|
-
collActionTypeEncoded,
|
|
497
|
-
debtActionTypeEncoded,
|
|
498
|
-
];
|
|
499
|
-
},
|
|
500
|
-
decode: (subData) => {
|
|
501
|
-
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
502
|
-
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
503
|
-
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
504
|
-
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
505
|
-
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
506
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
507
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
508
|
-
return {
|
|
509
|
-
market, troveId, collToken, boldToken, ratioState, targetRatio,
|
|
510
|
-
};
|
|
511
|
-
},
|
|
512
|
-
};
|
|
513
|
-
exports.liquityV2CloseSubData = {
|
|
514
|
-
encode(market, troveId, collToken, boldToken, closeType) {
|
|
515
|
-
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
516
|
-
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
517
|
-
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
518
|
-
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
519
|
-
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
520
|
-
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
521
|
-
const gasCompensation = new decimal_js_1.default('0.0375').mul(1e18).toString();
|
|
522
|
-
const gasCompensationEncoded = web3_eth_abi_1.default.encodeParameter('uint256', gasCompensation);
|
|
523
|
-
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
524
|
-
return [
|
|
525
|
-
marketEncoded,
|
|
526
|
-
troveIdEncoded,
|
|
527
|
-
collAddrEncoded,
|
|
528
|
-
boldTokenEncoded,
|
|
529
|
-
wethAddressEncoded,
|
|
530
|
-
gasCompensationEncoded,
|
|
531
|
-
closeTypeEncoded,
|
|
532
|
-
];
|
|
533
|
-
},
|
|
534
|
-
decode(subData) {
|
|
535
|
-
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
536
|
-
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
537
|
-
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
538
|
-
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
539
|
-
// skip wethAddress and gasCompensation
|
|
540
|
-
const closeType = web3_eth_abi_1.default.decodeParameter('uint8', subData[6]);
|
|
541
|
-
return {
|
|
542
|
-
market, troveId, collToken, boldToken, closeType,
|
|
543
|
-
};
|
|
544
|
-
},
|
|
545
|
-
};
|
|
546
|
-
exports.liquityV2LeverageManagementOnPriceSubData = {
|
|
547
|
-
encode(market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice) {
|
|
548
|
-
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
549
|
-
const encodedTroveId = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
550
|
-
const encodedCollToken = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
551
|
-
const encodedBoldToken = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
552
|
-
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
553
|
-
const collActionType = isRepayOnPrice ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
554
|
-
const debtActionType = isRepayOnPrice ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
555
|
-
const encodedCollActionType = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
556
|
-
const encodedDebtActionType = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
557
|
-
return [
|
|
558
|
-
encodedMarket,
|
|
559
|
-
encodedTroveId,
|
|
560
|
-
encodedCollToken,
|
|
561
|
-
encodedBoldToken,
|
|
562
|
-
encodedTargetRatio,
|
|
563
|
-
encodedCollActionType,
|
|
564
|
-
encodedDebtActionType,
|
|
565
|
-
];
|
|
566
|
-
},
|
|
567
|
-
decode(subData) {
|
|
568
|
-
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
569
|
-
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
570
|
-
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
571
|
-
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
572
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
573
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
574
|
-
return {
|
|
575
|
-
market, troveId, collToken, boldToken, targetRatio,
|
|
576
|
-
};
|
|
577
|
-
},
|
|
578
|
-
};
|
|
579
1118
|
exports.morphoBlueLeverageManagementOnPriceSubData = {
|
|
580
1119
|
encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
|
|
581
1120
|
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
@@ -607,33 +1146,44 @@ exports.morphoBlueLeverageManagementOnPriceSubData = {
|
|
|
607
1146
|
};
|
|
608
1147
|
},
|
|
609
1148
|
};
|
|
610
|
-
exports.
|
|
611
|
-
encode
|
|
612
|
-
const
|
|
613
|
-
const
|
|
614
|
-
const
|
|
615
|
-
const
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
boldTokenEncoded,
|
|
621
|
-
targetRatioEncoded,
|
|
622
|
-
ratioStateEncoded,
|
|
623
|
-
];
|
|
1149
|
+
exports.morphoBlueCloseOnPriceSubData = {
|
|
1150
|
+
encode(loanToken, collToken, oracle, irm, lltv, user, closeType) {
|
|
1151
|
+
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
1152
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
1153
|
+
const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
|
|
1154
|
+
const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
|
|
1155
|
+
const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
|
|
1156
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
1157
|
+
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
1158
|
+
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, userEncoded, closeTypeEncoded];
|
|
624
1159
|
},
|
|
625
|
-
decode
|
|
626
|
-
const
|
|
627
|
-
const
|
|
628
|
-
const
|
|
629
|
-
const
|
|
630
|
-
const
|
|
631
|
-
const
|
|
1160
|
+
decode(subData) {
|
|
1161
|
+
const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
1162
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
1163
|
+
const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
1164
|
+
const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
1165
|
+
const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
1166
|
+
const user = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
|
|
1167
|
+
const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[6]));
|
|
632
1168
|
return {
|
|
633
|
-
|
|
1169
|
+
loanToken,
|
|
1170
|
+
collToken,
|
|
1171
|
+
oracle,
|
|
1172
|
+
irm,
|
|
1173
|
+
lltv,
|
|
1174
|
+
user,
|
|
1175
|
+
closeType,
|
|
634
1176
|
};
|
|
635
1177
|
},
|
|
636
1178
|
};
|
|
1179
|
+
/**
|
|
1180
|
+
_______ __ __ __ __ _______
|
|
1181
|
+
| ____|| | | | | | | | | \
|
|
1182
|
+
| |__ | | | | | | | | | .--. |
|
|
1183
|
+
| __| | | | | | | | | | | | |
|
|
1184
|
+
| | | `----.| `--' | | | | '--' |
|
|
1185
|
+
|__| |_______| \______/ |__| |_______/
|
|
1186
|
+
*/
|
|
637
1187
|
exports.fluidLeverageManagementSubData = {
|
|
638
1188
|
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
639
1189
|
const nftIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', nftId);
|