@defisaver/automation-sdk 3.3.11 → 3.3.12-strategies-refactor-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.
Files changed (54) hide show
  1. package/cjs/automation/private/StrategiesAutomation.d.ts +2 -0
  2. package/cjs/automation/private/StrategiesAutomation.js +10 -1
  3. package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
  4. package/cjs/constants/index.d.ts +1 -0
  5. package/cjs/constants/index.js +62 -1
  6. package/cjs/services/strategiesService.js +104 -0
  7. package/cjs/services/strategySubService.d.ts +11 -0
  8. package/cjs/services/strategySubService.js +61 -1
  9. package/cjs/services/strategySubService.test.js +96 -0
  10. package/cjs/services/subDataService.d.ts +333 -137
  11. package/cjs/services/subDataService.js +853 -537
  12. package/cjs/services/subDataService.test.js +157 -0
  13. package/cjs/services/triggerService.d.ts +29 -0
  14. package/cjs/services/triggerService.js +53 -1
  15. package/cjs/services/triggerService.test.js +84 -0
  16. package/cjs/services/utils.d.ts +1 -1
  17. package/cjs/services/utils.js +10 -2
  18. package/cjs/types/enums.d.ts +17 -3
  19. package/cjs/types/enums.js +14 -0
  20. package/cjs/types/index.d.ts +22 -1
  21. package/esm/automation/private/StrategiesAutomation.d.ts +2 -0
  22. package/esm/automation/private/StrategiesAutomation.js +10 -1
  23. package/esm/automation/private/StrategiesAutomation.test.js +25 -0
  24. package/esm/constants/index.d.ts +1 -0
  25. package/esm/constants/index.js +61 -0
  26. package/esm/services/strategiesService.js +105 -1
  27. package/esm/services/strategySubService.d.ts +11 -0
  28. package/esm/services/strategySubService.js +60 -0
  29. package/esm/services/strategySubService.test.js +97 -1
  30. package/esm/services/subDataService.d.ts +333 -137
  31. package/esm/services/subDataService.js +852 -537
  32. package/esm/services/subDataService.test.js +157 -0
  33. package/esm/services/triggerService.d.ts +29 -0
  34. package/esm/services/triggerService.js +52 -0
  35. package/esm/services/triggerService.test.js +85 -1
  36. package/esm/services/utils.d.ts +1 -1
  37. package/esm/services/utils.js +10 -2
  38. package/esm/types/enums.d.ts +17 -3
  39. package/esm/types/enums.js +14 -0
  40. package/esm/types/index.d.ts +22 -1
  41. package/package.json +2 -2
  42. package/src/automation/private/StrategiesAutomation.test.ts +40 -0
  43. package/src/automation/private/StrategiesAutomation.ts +11 -0
  44. package/src/constants/index.ts +62 -0
  45. package/src/services/strategiesService.ts +119 -1
  46. package/src/services/strategySubService.test.ts +124 -0
  47. package/src/services/strategySubService.ts +196 -0
  48. package/src/services/subDataService.test.ts +172 -0
  49. package/src/services/subDataService.ts +1100 -764
  50. package/src/services/triggerService.test.ts +97 -0
  51. package/src/services/triggerService.ts +74 -1
  52. package/src/services/utils.ts +15 -4
  53. package/src/types/enums.ts +14 -0
  54. package/src/types/index.ts +26 -0
@@ -3,7 +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.sparkLeverageManagementOnPriceSubData = exports.morphoBlueCloseOnPriceSubData = exports.sparkCloseGenericSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementWithoutSubProxy = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
6
+ exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubDataWithoutSubProxy = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubDataWithoutSubProxy = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubDataWithoutSubProxy = 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.aaveV2LeverageManagementSubDataWithoutSubProxy = exports.aaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubDataWithoutSubProxy = exports.liquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLeverageManagementWithoutSubProxy = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
7
+ exports.fluidLeverageManagementSubData = void 0;
7
8
  const decimal_js_1 = __importDefault(require("decimal.js"));
8
9
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
9
10
  const web3_utils_1 = require("web3-utils");
@@ -12,6 +13,68 @@ const sdk_1 = require("@defisaver/sdk");
12
13
  const enums_1 = require("../types/enums");
13
14
  const constants_1 = require("../constants");
14
15
  const utils_1 = require("./utils");
16
+ /**
17
+ _______ _______ .______ .______ _______ ______ ___ .___________. _______ _______
18
+ | \ | ____|| _ \ | _ \ | ____| / | / \ | || ____|| \
19
+ | .--. || |__ | |_) | | |_) | | |__ | ,----' / ^ \ `---| |----`| |__ | .--. |
20
+ | | | || __| | ___/ | / | __| | | / /_\ \ | | | __| | | | |
21
+ | '--' || |____ | | | |\ \----.| |____ | `----./ _____ \ | | | |____ | '--' |
22
+ |_______/ |_______|| _| | _| `._____||_______| \______/__/ \__\ |__| |_______||_______/
23
+ */
24
+ exports.morphoAaveV2LeverageManagementSubData = {
25
+ encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
26
+ return [
27
+ (0, utils_1.ratioPercentageToWei)(triggerRepayRatio),
28
+ (0, utils_1.ratioPercentageToWei)(triggerBoostRatio),
29
+ (0, utils_1.ratioPercentageToWei)(targetBoostRatio),
30
+ (0, utils_1.ratioPercentageToWei)(targetRepayRatio),
31
+ // @ts-ignore
32
+ boostEnabled,
33
+ ];
34
+ },
35
+ decode(subData) {
36
+ const ratioWei = web3_eth_abi_1.default.decodeParameter('uint128', subData[1]);
37
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
38
+ return { targetRatio };
39
+ },
40
+ };
41
+ exports.cBondsRebondSubData = {
42
+ encode(bondId) {
43
+ const bondIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', bondId);
44
+ return [bondIdEncoded];
45
+ },
46
+ decode(subData) {
47
+ const bondId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
48
+ return { bondId };
49
+ },
50
+ };
51
+ exports.liquityPaybackUsingChickenBondSubData = {
52
+ /**
53
+ * @param sourceId bondId or subId
54
+ * @param sourceType 0 for bond, 1 for subId
55
+ * @param chainId
56
+ */
57
+ encode: (sourceId, sourceType, chainId = enums_1.ChainId.Ethereum) => {
58
+ const sourceIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceId);
59
+ const sourceTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceType);
60
+ const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('LUSD', chainId).address);
61
+ const bLusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('bLUSD', chainId).address);
62
+ return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
63
+ },
64
+ decode: (subData) => {
65
+ const sourceId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
66
+ const sourceType = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
67
+ return { sourceId, sourceType };
68
+ },
69
+ };
70
+ /**
71
+ .___ ___. ___ __ ___ _______ .______
72
+ | \/ | / \ | |/ / | ____|| _ \
73
+ | \ / | / ^ \ | ' / | |__ | |_) |
74
+ | |\/| | / /_\ \ | < | __| | /
75
+ | | | | / _____ \ | . \ | |____ | |\ \----.
76
+ |__| |__| /__/ \__\ |__|\__\ |_______|| _| `._____|
77
+ */
15
78
  exports.makerRepayFromSavingsSubData = {
16
79
  encode(vaultId, targetRatioPercentage, chainId, daiAddr, mcdCdpManagerAddr) {
17
80
  const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
@@ -35,13 +98,6 @@ exports.makerRepayFromSavingsSubData = {
35
98
  };
36
99
  },
37
100
  };
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
101
  exports.makerCloseSubData = {
46
102
  encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr) {
47
103
  const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
@@ -90,6 +146,21 @@ exports.makerLeverageManagementWithoutSubProxy = {
90
146
  return { vaultId, targetRatio, daiAddr };
91
147
  },
92
148
  };
149
+ /**
150
+ __ __ ______ __ __ __ .___________.____ ____ ____ ____ __
151
+ | | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
152
+ | | | | | | | | | | | | | | `---| |----` \ \/ / \ \/ / | |
153
+ | | | | | | | | | | | | | | | | \_ _/ \ / | |
154
+ | `----.| | | `--' '--.| `--' | | | | | | | \ / | |
155
+ |_______||__| \_____\_____\\______/ |__| |__| |__| \__/ |_|
156
+ */
157
+ exports.liquityRepayFromSavingsSubData = {
158
+ decode(subData) {
159
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
160
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
161
+ return { targetRatio };
162
+ },
163
+ };
93
164
  exports.liquityLeverageManagementSubData = {
94
165
  decode: (subData) => {
95
166
  const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
@@ -97,6 +168,18 @@ exports.liquityLeverageManagementSubData = {
97
168
  return { targetRatio };
98
169
  },
99
170
  };
171
+ exports.liquityLeverageManagementSubDataWithoutSubProxy = {
172
+ encode(targetRatio, ratioState) {
173
+ const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
174
+ const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
175
+ return [encodedTargetRatio, encodedRatioState];
176
+ },
177
+ decode(subData) {
178
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
179
+ const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
180
+ return { targetRatio, ratioState };
181
+ },
182
+ };
100
183
  exports.liquityCloseSubData = {
101
184
  encode(closeToAssetAddr, chainId = enums_1.ChainId.Ethereum, collAddr, debtAddr) {
102
185
  const _collAddr = collAddr || (0, tokens_1.getAssetInfo)('WETH', chainId).address;
@@ -116,171 +199,202 @@ exports.liquityCloseSubData = {
116
199
  return { closeToAssetAddr, debtAddr };
117
200
  },
118
201
  };
119
- exports.aaveV2LeverageManagementSubData = {
120
- encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
121
- return [
122
- new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
123
- new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
124
- new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
125
- new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
126
- // @ts-ignore // TODO
127
- boostEnabled,
128
- ];
202
+ exports.liquityDsrPaybackSubData = {
203
+ encode: (targetRatio) => {
204
+ const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
205
+ const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
206
+ const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
207
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
208
+ const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
209
+ const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
210
+ return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, lusdAddressEncoded];
129
211
  },
130
- decode(subData) {
131
- const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
132
- const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
212
+ decode: (subData) => {
213
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
214
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
133
215
  return { targetRatio };
134
216
  },
135
217
  };
136
- exports.aaveV3LeverageManagementSubData = {
137
- decode(subData) {
138
- const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
139
- const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
218
+ exports.liquityDsrSupplySubData = {
219
+ encode: (targetRatio) => {
220
+ const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
221
+ const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
222
+ const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
223
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
224
+ const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
225
+ const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
226
+ return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, wethAddressEncoded];
227
+ },
228
+ decode: (subData) => {
229
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
230
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
140
231
  return { targetRatio };
141
232
  },
142
233
  };
143
- exports.aaveV3LeverageManagementSubDataWithoutSubProxy = {
144
- encode(targetRatio, ratioState, market, user, isGeneric) {
145
- const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
146
- const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
147
- if (isGeneric) {
148
- const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
149
- const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
150
- return [encodedTargetRatio, encodedRatioState, encodedMarket, encodedUser];
151
- }
152
- const encodedUseDefaultMarket = web3_eth_abi_1.default.encodeParameter('bool', true);
153
- const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', false);
154
- return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
234
+ exports.liquityDebtInFrontRepaySubData = {
235
+ encode: (targetRatioIncrease) => {
236
+ const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
237
+ const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
238
+ const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
239
+ const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
240
+ const targetRatioIncreaseEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatioIncrease));
241
+ const withdrawIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 1); // withdraw - 1
242
+ const paybackIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 0); // payback - 0
243
+ return [wethAddressEncoded, lusdAddressEncoded, targetRatioIncreaseEncoded, withdrawIdEncoded, paybackIdEncoded];
155
244
  },
156
- decode(subData) {
157
- const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
158
- const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
159
- return { targetRatio, ratioState };
245
+ decode: (subData) => {
246
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
247
+ const targetRatioIncrease = (0, utils_1.weiToRatioPercentage)(weiRatio);
248
+ return { targetRatioIncrease };
160
249
  },
161
250
  };
162
- exports.aaveV3LeverageManagementOnPriceGeneric = {
163
- encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user) {
164
- const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
165
- const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
166
- const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
167
- const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
168
- const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
169
- const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
170
- const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
251
+ /**
252
+ * __ __ ______ __ __ __ .___________.____ ____ ____ ____ ___
253
+ | | | | / __ \ | | | | | | | |\ \ / / \ \ / / |__ \
254
+ | | | | | | | | | | | | | | `---| |----` \ \/ / \ \/ / ) |
255
+ | | | | | | | | | | | | | | | | \_ _/ \ / / /
256
+ | `----.| | | `--' '--.| `--' | | | | | | | \ / / /_
257
+ |_______||__| \_____\_____\\______/ |__| |__| |__| \__/ |____|
258
+ */
259
+ exports.liquityV2LeverageManagementSubData = {
260
+ encode: (market, troveId, collToken, boldToken, ratioState, targetRatio) => {
261
+ const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
262
+ const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
263
+ const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
264
+ const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
265
+ const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
266
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
267
+ const isRepay = ratioState === enums_1.RatioState.UNDER;
268
+ const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
269
+ const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
270
+ const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
271
+ const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
171
272
  return [
172
- encodedColl,
173
- encodedCollId,
174
- encodedDebt,
175
- encodedDebtId,
176
- encodedMarket,
177
- encodedTargetRatio,
178
- userEncoded,
273
+ marketEncoded,
274
+ troveIdEncoded,
275
+ collTokenEncoded,
276
+ boldTokenEncoded,
277
+ ratioStateEncoded,
278
+ targetRatioEncoded,
279
+ collActionTypeEncoded,
280
+ debtActionTypeEncoded,
179
281
  ];
180
282
  },
181
- decode(subData) {
182
- const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
183
- const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
184
- const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
185
- const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
186
- const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
283
+ decode: (subData) => {
284
+ const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
285
+ const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
286
+ const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
287
+ const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
288
+ const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
187
289
  const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
188
290
  const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
189
- const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
190
291
  return {
191
- collAsset,
192
- collAssetId,
193
- debtAsset,
194
- debtAssetId,
195
- marketAddr,
196
- targetRatio,
197
- owner,
292
+ market, troveId, collToken, boldToken, ratioState, targetRatio,
198
293
  };
199
294
  },
200
295
  };
201
- exports.aaveV3CloseGenericSubData = {
202
- encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user) {
203
- const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
204
- const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
205
- const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
206
- const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
207
- const encodedCloseType = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
208
- const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
209
- const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
296
+ exports.liquityV2CloseSubData = {
297
+ encode(market, troveId, collToken, boldToken, closeType) {
298
+ const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
299
+ const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
300
+ const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
301
+ const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
302
+ const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
303
+ const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
304
+ const gasCompensation = new decimal_js_1.default('0.0375').mul(1e18).toString();
305
+ const gasCompensationEncoded = web3_eth_abi_1.default.encodeParameter('uint256', gasCompensation);
306
+ const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
210
307
  return [
211
- encodedColl,
212
- encodedCollId,
213
- encodedDebt,
214
- encodedDebtId,
215
- encodedCloseType,
216
- encodedMarket,
217
- userEncoded,
308
+ marketEncoded,
309
+ troveIdEncoded,
310
+ collAddrEncoded,
311
+ boldTokenEncoded,
312
+ wethAddressEncoded,
313
+ gasCompensationEncoded,
314
+ closeTypeEncoded,
218
315
  ];
219
316
  },
220
317
  decode(subData) {
221
- const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
222
- const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
223
- const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
224
- const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
225
- const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[4]));
226
- const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
227
- const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
318
+ const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
319
+ const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
320
+ const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
321
+ const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
322
+ // skip wethAddress and gasCompensation
323
+ const closeType = web3_eth_abi_1.default.decodeParameter('uint8', subData[6]);
228
324
  return {
229
- collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
325
+ market, troveId, collToken, boldToken, closeType,
230
326
  };
231
327
  },
232
328
  };
233
- exports.aaveV3CollateralSwitchSubData = {
234
- encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
235
- const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
236
- const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
237
- const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
238
- const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
239
- const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
240
- const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
241
- const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', useOnBehalf);
329
+ exports.liquityV2LeverageManagementOnPriceSubData = {
330
+ encode(market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice) {
331
+ const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
332
+ const encodedTroveId = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
333
+ const encodedCollToken = web3_eth_abi_1.default.encodeParameter('address', collToken);
334
+ const encodedBoldToken = web3_eth_abi_1.default.encodeParameter('address', boldToken);
335
+ const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
336
+ const collActionType = isRepayOnPrice ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
337
+ const debtActionType = isRepayOnPrice ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
338
+ const encodedCollActionType = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
339
+ const encodedDebtActionType = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
242
340
  return [
243
- encodedFromAsset,
244
- encodedFromAssetId,
245
- encodedToAsset,
246
- encodedToAssetId,
247
- encodedMarketAddr,
248
- encodedAmountToSwitch,
249
- encodedUseOnBehalf,
341
+ encodedMarket,
342
+ encodedTroveId,
343
+ encodedCollToken,
344
+ encodedBoldToken,
345
+ encodedTargetRatio,
346
+ encodedCollActionType,
347
+ encodedDebtActionType,
250
348
  ];
251
349
  },
252
350
  decode(subData) {
253
- const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
254
- const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
255
- const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
256
- const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
257
- const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
258
- const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
351
+ const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
352
+ const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
353
+ const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
354
+ const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
355
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
356
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
259
357
  return {
260
- fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
358
+ market, troveId, collToken, boldToken, targetRatio,
261
359
  };
262
360
  },
263
361
  };
264
- exports.aaveV3QuotePriceSubData = {
265
- encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
266
- const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
267
- const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
268
- const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
269
- const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
270
- const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
271
- return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
362
+ exports.liquityV2PaybackSubData = {
363
+ encode: (market, troveId, boldToken, targetRatio, ratioState) => {
364
+ const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
365
+ const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
366
+ const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
367
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
368
+ const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
369
+ return [
370
+ marketEncoded,
371
+ troveIdEncoded,
372
+ boldTokenEncoded,
373
+ targetRatioEncoded,
374
+ ratioStateEncoded,
375
+ ];
272
376
  },
273
- decode(subData) {
274
- const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
275
- const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
276
- const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
277
- const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
377
+ decode: (subData) => {
378
+ const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
379
+ const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
380
+ const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
381
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
382
+ const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
383
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
278
384
  return {
279
- collAsset, collAssetId, debtAsset, debtAssetId,
385
+ market, troveId, boldToken, ratioState, targetRatio,
280
386
  };
281
387
  },
282
388
  };
283
- exports.compoundV2LeverageManagementSubData = {
389
+ /**
390
+ ___ ___ ____ ____ _______ ____ ____ ___
391
+ / \ / \ \ \ / / | ____| \ \ / / |__ \
392
+ / ^ \ / ^ \ \ \/ / | |__ \ \/ / ) |
393
+ / /_\ \ / /_\ \ \ / | __| \ / / /
394
+ / _____ \ / _____ \ \ / | |____ \ / / /_
395
+ /__/ \__\ /__/ \__\ \__/ |_______| \__/ |____|
396
+ */
397
+ exports.aaveV2LeverageManagementSubData = {
284
398
  encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
285
399
  return [
286
400
  new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
@@ -292,149 +406,47 @@ exports.compoundV2LeverageManagementSubData = {
292
406
  ];
293
407
  },
294
408
  decode(subData) {
295
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
296
- const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
297
- return { targetRatio };
298
- },
299
- };
300
- exports.compoundV3LeverageManagementSubData = {
301
- encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
302
- return [
303
- market,
304
- baseToken,
305
- new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
306
- new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
307
- new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
308
- new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
309
- // @ts-ignore // TODO
310
- boostEnabled, isEOA,
311
- ];
312
- },
313
- decode(subData) {
314
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
315
- const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
316
- return { targetRatio };
317
- },
318
- };
319
- exports.compoundV3L2LeverageManagementSubData = {
320
- encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
321
- let subInput = '0x';
322
- subInput = subInput.concat(market.slice(2));
323
- subInput = subInput.concat(baseToken.slice(2));
324
- subInput = subInput.concat(new decimal_js_1.default(triggerRepayRatio).mul(1e16).toHex().slice(2)
325
- .padStart(32, '0'));
326
- subInput = subInput.concat(new decimal_js_1.default(triggerBoostRatio).mul(1e16).toHex().slice(2)
327
- .padStart(32, '0'));
328
- subInput = subInput.concat(new decimal_js_1.default(targetBoostRatio).mul(1e16).toHex().slice(2)
329
- .padStart(32, '0'));
330
- subInput = subInput.concat(new decimal_js_1.default(targetRepayRatio).mul(1e16).toHex().slice(2)
331
- .padStart(32, '0'));
332
- subInput = subInput.concat(boostEnabled ? '01' : '00');
333
- subInput = subInput.concat(isEOA ? '01' : '00');
334
- return subInput;
335
- },
336
- decode(subData) {
337
- const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
338
- const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
339
- return { targetRatio };
340
- },
341
- };
342
- exports.morphoAaveV2LeverageManagementSubData = {
343
- encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
344
- return [
345
- (0, utils_1.ratioPercentageToWei)(triggerRepayRatio),
346
- (0, utils_1.ratioPercentageToWei)(triggerBoostRatio),
347
- (0, utils_1.ratioPercentageToWei)(targetBoostRatio),
348
- (0, utils_1.ratioPercentageToWei)(targetRepayRatio),
349
- // @ts-ignore
350
- boostEnabled,
351
- ];
352
- },
353
- decode(subData) {
354
- const ratioWei = web3_eth_abi_1.default.decodeParameter('uint128', subData[1]);
409
+ const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
355
410
  const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
356
411
  return { targetRatio };
357
412
  },
358
413
  };
359
- exports.cBondsRebondSubData = {
360
- encode(bondId) {
361
- const bondIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', bondId);
362
- return [bondIdEncoded];
414
+ exports.aaveV2LeverageManagementSubDataWithoutSubProxy = {
415
+ encode(targetRatio, ratioState) {
416
+ const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
417
+ const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
418
+ return [encodedTargetRatio, encodedRatioState];
363
419
  },
364
420
  decode(subData) {
365
- const bondId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
366
- return { bondId };
367
- },
368
- };
369
- exports.liquityPaybackUsingChickenBondSubData = {
370
- /**
371
- * @param sourceId bondId or subId
372
- * @param sourceType 0 for bond, 1 for subId
373
- * @param chainId
374
- */
375
- encode: (sourceId, sourceType, chainId = enums_1.ChainId.Ethereum) => {
376
- const sourceIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceId);
377
- const sourceTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceType);
378
- const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('LUSD', chainId).address);
379
- const bLusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('bLUSD', chainId).address);
380
- return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
381
- },
382
- decode: (subData) => {
383
- const sourceId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
384
- const sourceType = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
385
- return { sourceId, sourceType };
386
- },
387
- };
388
- exports.exchangeDcaSubData = {
389
- encode: (fromToken, toToken, amount, interval) => {
390
- const sellTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', fromToken);
391
- const buyTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', toToken);
392
- const amountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', amount);
393
- const intervalEncoded = web3_eth_abi_1.default.encodeParameter('uint256', interval);
394
- return [sellTokenEncoded, buyTokenEncoded, amountEncoded, intervalEncoded];
395
- },
396
- decode: (subData, chainId) => {
397
- const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
398
- const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
399
- const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
400
- const interval = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]).toString();
401
- return {
402
- fromToken,
403
- toToken,
404
- amount,
405
- interval,
406
- };
407
- },
408
- };
409
- exports.exchangeLimitOrderSubData = {
410
- encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
411
- return [
412
- fromToken,
413
- toToken,
414
- amount,
415
- targetPrice,
416
- new decimal_js_1.default(goodUntil).toString(),
417
- new decimal_js_1.default(orderType).toString(),
418
- ];
419
- },
420
- decode: (subData, chainId) => {
421
- const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
422
- const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
423
- const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
424
- return { fromToken, toToken, amount };
421
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
422
+ const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
423
+ return { targetRatio, ratioState };
425
424
  },
426
425
  };
427
- exports.sparkLeverageManagementSubData = {
426
+ /**
427
+ ___ ___ ____ ____ _______ ____ ____ ____
428
+ / \ / \ \ \ / / | ____| \ \ / / |___ \
429
+ / ^ \ / ^ \ \ \/ / | |__ \ \/ / __) |
430
+ / /_\ \ / /_\ \ \ / | __| \ / |__ <
431
+ / _____ \ / _____ \ \ / | |____ \ / ___) |
432
+ /__/ \__\ /__/ \__\ \__/ |_______| \__/ |____/
433
+ */
434
+ exports.aaveV3LeverageManagementSubData = {
428
435
  decode(subData) {
429
436
  const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
430
437
  const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
431
438
  return { targetRatio };
432
439
  },
433
440
  };
434
- exports.sparkLeverageManagementSubDataWithoutSubProxy = {
435
- encode(targetRatio, ratioState) {
441
+ exports.aaveV3LeverageManagementSubDataWithoutSubProxy = {
442
+ encode(targetRatio, ratioState, market, user, isGeneric) {
436
443
  const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
437
444
  const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
445
+ if (isGeneric) {
446
+ const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
447
+ const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
448
+ return [encodedTargetRatio, encodedRatioState, encodedMarket, encodedUser];
449
+ }
438
450
  const encodedUseDefaultMarket = web3_eth_abi_1.default.encodeParameter('bool', true);
439
451
  const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', false);
440
452
  return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
@@ -445,130 +457,124 @@ exports.sparkLeverageManagementSubDataWithoutSubProxy = {
445
457
  return { targetRatio, ratioState };
446
458
  },
447
459
  };
448
- exports.liquityDsrPaybackSubData = {
449
- encode: (targetRatio) => {
450
- const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
451
- const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
452
- const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
453
- const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
454
- const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
455
- const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
456
- return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, lusdAddressEncoded];
457
- },
458
- decode: (subData) => {
459
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
460
- const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
461
- return { targetRatio };
462
- },
463
- };
464
- exports.liquityDsrSupplySubData = {
465
- encode: (targetRatio) => {
466
- const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
467
- const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
468
- const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
469
- const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
470
- const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
471
- const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
472
- return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, wethAddressEncoded];
473
- },
474
- decode: (subData) => {
475
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
476
- const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
477
- return { targetRatio };
478
- },
479
- };
480
- exports.liquityDebtInFrontRepaySubData = {
481
- encode: (targetRatioIncrease) => {
482
- const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
483
- const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
484
- const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
485
- const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
486
- const targetRatioIncreaseEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatioIncrease));
487
- const withdrawIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 1); // withdraw - 1
488
- const paybackIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 0); // payback - 0
489
- return [wethAddressEncoded, lusdAddressEncoded, targetRatioIncreaseEncoded, withdrawIdEncoded, paybackIdEncoded];
490
- },
491
- decode: (subData) => {
492
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
493
- const targetRatioIncrease = (0, utils_1.weiToRatioPercentage)(weiRatio);
494
- return { targetRatioIncrease };
495
- },
496
- };
497
- exports.crvUSDLeverageManagementSubData = {
498
- encode: (controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr) => {
499
- const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
500
- const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
501
- const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
502
- const collTokenAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collTokenAddr);
503
- const crvUSDAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', crvUSDAddr);
504
- return [controllerAddrEncoded, ratioStateEncoded, targetRatioEncoded, collTokenAddrEncoded, crvUSDAddrEncoded];
460
+ exports.aaveV3LeverageManagementOnPriceGeneric = {
461
+ encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user) {
462
+ const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
463
+ const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
464
+ const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
465
+ const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
466
+ const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
467
+ const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
468
+ const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
469
+ return [
470
+ encodedColl,
471
+ encodedCollId,
472
+ encodedDebt,
473
+ encodedDebtId,
474
+ encodedMarket,
475
+ encodedTargetRatio,
476
+ userEncoded,
477
+ ];
505
478
  },
506
- decode: (subData) => {
507
- const controller = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
508
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
479
+ decode(subData) {
480
+ const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
481
+ const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
482
+ const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
483
+ const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
484
+ const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
485
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
509
486
  const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
510
- return { controller, targetRatio };
487
+ const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
488
+ return {
489
+ collAsset,
490
+ collAssetId,
491
+ debtAsset,
492
+ debtAssetId,
493
+ marketAddr,
494
+ targetRatio,
495
+ owner,
496
+ };
511
497
  },
512
498
  };
513
- exports.crvUSDPaybackSubData = {
514
- encode: (controllerAddr, addressToPullTokensFrom, positionOwner, paybackAmount, crvUSDAddr) => {
515
- const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
516
- const addressToPullTokensFromEncoded = web3_eth_abi_1.default.encodeParameter('address', addressToPullTokensFrom);
517
- const positionOwnerEncoded = web3_eth_abi_1.default.encodeParameter('address', positionOwner);
518
- const paybackAmountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, web3_utils_1.toWei)(paybackAmount, 'ether'));
519
- const crvUSDAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', crvUSDAddr);
499
+ exports.aaveV3CloseGenericSubData = {
500
+ encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user) {
501
+ const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
502
+ const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
503
+ const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
504
+ const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
505
+ const encodedCloseType = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
506
+ const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
507
+ const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
520
508
  return [
521
- controllerAddrEncoded,
522
- addressToPullTokensFromEncoded,
523
- positionOwnerEncoded,
524
- paybackAmountEncoded,
525
- crvUSDAddrEncoded,
509
+ encodedColl,
510
+ encodedCollId,
511
+ encodedDebt,
512
+ encodedDebtId,
513
+ encodedCloseType,
514
+ encodedMarket,
515
+ userEncoded,
526
516
  ];
527
517
  },
528
- decode: (subData) => {
529
- const controller = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
530
- const addressToPullTokensFrom = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
531
- const positionOwner = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
532
- const weiPaybackAmount = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
533
- const paybackAmount = (0, web3_utils_1.fromWei)(weiPaybackAmount, 'ether');
518
+ decode(subData) {
519
+ const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
520
+ const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
521
+ const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
522
+ const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
523
+ const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[4]));
524
+ const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
525
+ const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
534
526
  return {
535
- controller,
536
- addressToPullTokensFrom,
537
- positionOwner,
538
- paybackAmount,
527
+ collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
539
528
  };
540
529
  },
541
530
  };
542
- exports.morphoBlueLeverageManagementSubData = {
543
- encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
544
- const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
545
- const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
546
- const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
547
- const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
548
- const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
549
- const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
550
- const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
551
- const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
552
- const isEOAEncoded = web3_eth_abi_1.default.encodeParameter('bool', isEOA);
553
- return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
531
+ exports.aaveV3CollateralSwitchSubData = {
532
+ encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
533
+ const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
534
+ const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
535
+ const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
536
+ const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
537
+ const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
538
+ const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
539
+ const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', useOnBehalf);
540
+ return [
541
+ encodedFromAsset,
542
+ encodedFromAssetId,
543
+ encodedToAsset,
544
+ encodedToAssetId,
545
+ encodedMarketAddr,
546
+ encodedAmountToSwitch,
547
+ encodedUseOnBehalf,
548
+ ];
549
+ },
550
+ decode(subData) {
551
+ const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
552
+ const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
553
+ const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
554
+ const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
555
+ const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
556
+ const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
557
+ return {
558
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
559
+ };
554
560
  },
555
- decode: (subData) => {
556
- const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
557
- const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
558
- const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
559
- const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
560
- const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
561
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[6]);
562
- const user = web3_eth_abi_1.default.decodeParameter('address', subData[7]);
563
- const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
561
+ };
562
+ exports.aaveV3QuotePriceSubData = {
563
+ encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
564
+ const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
565
+ const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
566
+ const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
567
+ const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
568
+ const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
569
+ return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
570
+ },
571
+ decode(subData) {
572
+ const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
573
+ const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
574
+ const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
575
+ const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
564
576
  return {
565
- loanToken,
566
- collToken,
567
- oracle,
568
- irm,
569
- lltv,
570
- user,
571
- targetRatio,
577
+ collAsset, collAssetId, debtAsset, debtAssetId,
572
578
  };
573
579
  },
574
580
  };
@@ -604,200 +610,253 @@ exports.aaveV3LeverageManagementOnPriceSubData = {
604
610
  };
605
611
  },
606
612
  };
607
- exports.liquityV2LeverageManagementSubData = {
608
- encode: (market, troveId, collToken, boldToken, ratioState, targetRatio) => {
609
- const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
610
- const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
611
- const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
612
- const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
613
+ /**
614
+ * ___ ___ ____ ____ _______ ____ ____ _ _
615
+ / \ / \ \ \ / / | ____| \ \ / / | || |
616
+ / ^ \ / ^ \ \ \/ / | |__ \ \/ / | || |_
617
+ / /_\ \ / /_\ \ \ / | __| \ / |__ _|
618
+ / _____ \ / _____ \ \ / | |____ \ / | |
619
+ /__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
620
+ */
621
+ exports.aaveV4LeverageManagementSubData = {
622
+ encode: (spoke, owner, ratioState, targetRatio) => {
623
+ const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
624
+ const ownerEncoded = web3_eth_abi_1.default.encodeParameter('address', owner);
613
625
  const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
614
626
  const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
615
- const isRepay = ratioState === enums_1.RatioState.UNDER;
616
- const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
617
- const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
618
- const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
619
- const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
627
+ // Add two empty slots for future addons (e.g tsi or slippage settings)
620
628
  return [
621
- marketEncoded,
622
- troveIdEncoded,
623
- collTokenEncoded,
624
- boldTokenEncoded,
629
+ spokeEncoded,
630
+ ownerEncoded,
625
631
  ratioStateEncoded,
626
632
  targetRatioEncoded,
627
- collActionTypeEncoded,
628
- debtActionTypeEncoded,
633
+ constants_1.EMPTY_SLOT,
634
+ constants_1.EMPTY_SLOT,
629
635
  ];
630
636
  },
631
637
  decode: (subData) => {
632
- const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
633
- const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
634
- const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
635
- const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
636
- const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
637
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
638
- const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
638
+ const spoke = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
639
+ const owner = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
640
+ const ratioState = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[2]));
641
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
639
642
  return {
640
- market, troveId, collToken, boldToken, ratioState, targetRatio,
643
+ spoke, owner, ratioState, targetRatio,
641
644
  };
642
645
  },
643
646
  };
644
- exports.liquityV2CloseSubData = {
645
- encode(market, troveId, collToken, boldToken, closeType) {
646
- const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
647
- const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
648
- const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
649
- const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
650
- const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
651
- const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
652
- const gasCompensation = new decimal_js_1.default('0.0375').mul(1e18).toString();
653
- const gasCompensationEncoded = web3_eth_abi_1.default.encodeParameter('uint256', gasCompensation);
654
- const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
647
+ exports.aaveV4LeverageManagementOnPriceSubData = {
648
+ encode: (spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio) => {
649
+ const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
650
+ const ownerEncoded = web3_eth_abi_1.default.encodeParameter('address', owner);
651
+ const collAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', collAsset);
652
+ const collAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', collAssetId);
653
+ const debtAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
654
+ const debtAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', debtAssetId);
655
+ const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
656
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
657
+ // Add two empty slots for future addons (e.g tsi or slippage settings)
655
658
  return [
656
- marketEncoded,
657
- troveIdEncoded,
658
- collAddrEncoded,
659
- boldTokenEncoded,
660
- wethAddressEncoded,
661
- gasCompensationEncoded,
662
- closeTypeEncoded,
659
+ spokeEncoded,
660
+ ownerEncoded,
661
+ collAssetEncoded,
662
+ collAssetIdEncoded,
663
+ debtAssetEncoded,
664
+ debtAssetIdEncoded,
665
+ ratioStateEncoded,
666
+ targetRatioEncoded,
667
+ constants_1.EMPTY_SLOT,
668
+ constants_1.EMPTY_SLOT,
663
669
  ];
664
670
  },
665
- decode(subData) {
666
- const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
667
- const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
668
- const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
669
- const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
670
- // skip wethAddress and gasCompensation
671
- const closeType = web3_eth_abi_1.default.decodeParameter('uint8', subData[6]);
671
+ decode: (subData) => {
672
+ const spoke = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
673
+ const owner = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
674
+ const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
675
+ const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
676
+ const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
677
+ const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[5]));
678
+ const ratioState = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[6]));
679
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[7]));
672
680
  return {
673
- market, troveId, collToken, boldToken, closeType,
681
+ spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio,
674
682
  };
675
683
  },
676
684
  };
677
- exports.liquityV2LeverageManagementOnPriceSubData = {
678
- encode(market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice) {
679
- const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
680
- const encodedTroveId = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
681
- const encodedCollToken = web3_eth_abi_1.default.encodeParameter('address', collToken);
682
- const encodedBoldToken = web3_eth_abi_1.default.encodeParameter('address', boldToken);
683
- const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
684
- const collActionType = isRepayOnPrice ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
685
- const debtActionType = isRepayOnPrice ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
686
- const encodedCollActionType = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
687
- const encodedDebtActionType = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
685
+ exports.aaveV4CloseSubData = {
686
+ encode: (spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType) => {
687
+ const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
688
+ const ownerEncoded = web3_eth_abi_1.default.encodeParameter('address', owner);
689
+ const collAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', collAsset);
690
+ const collAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', collAssetId);
691
+ const debtAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
692
+ const debtAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', debtAssetId);
693
+ const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
694
+ // Add two empty slots for future addons (e.g tsi or slippage settings)
688
695
  return [
689
- encodedMarket,
690
- encodedTroveId,
691
- encodedCollToken,
692
- encodedBoldToken,
693
- encodedTargetRatio,
694
- encodedCollActionType,
695
- encodedDebtActionType,
696
+ spokeEncoded,
697
+ ownerEncoded,
698
+ collAssetEncoded,
699
+ collAssetIdEncoded,
700
+ debtAssetEncoded,
701
+ debtAssetIdEncoded,
702
+ closeTypeEncoded,
703
+ constants_1.EMPTY_SLOT,
704
+ constants_1.EMPTY_SLOT,
696
705
  ];
697
706
  },
698
- decode(subData) {
699
- const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
700
- const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
701
- const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
702
- const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
703
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
704
- const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
707
+ decode: (subData) => {
708
+ const spoke = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
709
+ const owner = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
710
+ const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
711
+ const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
712
+ const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
713
+ const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[5]));
714
+ const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[6]));
705
715
  return {
706
- market, troveId, collToken, boldToken, targetRatio,
716
+ spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType,
707
717
  };
708
718
  },
709
719
  };
710
- exports.morphoBlueLeverageManagementOnPriceSubData = {
711
- encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
712
- const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
713
- const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
714
- const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
715
- const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
716
- const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
717
- const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
718
- const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
719
- return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, targetRatioEncoded, userEncoded];
720
+ exports.aaveV4CollateralSwitchSubData = {
721
+ encode: (spoke, owner, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch) => {
722
+ const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
723
+ const ownerEncoded = web3_eth_abi_1.default.encodeParameter('address', owner);
724
+ const fromAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
725
+ const fromAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', fromAssetId);
726
+ const toAssetEncoded = web3_eth_abi_1.default.encodeParameter('address', toAsset);
727
+ const toAssetIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', toAssetId);
728
+ const amountToSwitchEncoded = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
729
+ // Add two empty slots for future addons (e.g tsi or slippage settings)
730
+ return [
731
+ spokeEncoded,
732
+ ownerEncoded,
733
+ fromAssetEncoded,
734
+ fromAssetIdEncoded,
735
+ toAssetEncoded,
736
+ toAssetIdEncoded,
737
+ amountToSwitchEncoded,
738
+ constants_1.EMPTY_SLOT,
739
+ constants_1.EMPTY_SLOT,
740
+ ];
720
741
  },
721
- decode(subData) {
722
- const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
723
- const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
724
- const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
725
- const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
726
- const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
727
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
728
- const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
729
- const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
742
+ decode: (subData) => {
743
+ const spoke = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
744
+ const owner = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
745
+ const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
746
+ const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
747
+ const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
748
+ const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint256', subData[5]));
749
+ const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[6]);
730
750
  return {
731
- loanToken,
732
- collToken,
733
- oracle,
734
- irm,
735
- lltv,
736
- targetRatio,
737
- user,
751
+ spoke, owner, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch,
738
752
  };
739
753
  },
740
754
  };
741
- exports.liquityV2PaybackSubData = {
742
- encode: (market, troveId, boldToken, targetRatio, ratioState) => {
743
- const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
744
- const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
745
- const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
746
- const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
747
- const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
755
+ /**
756
+ ______ ______ .___ ___. .______ ____ ____ ___
757
+ / | / __ \ | \/ | | _ \ \ \ / / |__ \
758
+ | ,----'| | | | | \ / | | |_) | \ \/ / ) |
759
+ | | | | | | | |\/| | | ___/ \ / / /
760
+ | `----.| `--' | | | | | | | \ / / /_
761
+ \______| \______/ |__| |__| | _| \__/ |____|
762
+ */
763
+ exports.compoundV2LeverageManagementSubData = {
764
+ encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
748
765
  return [
749
- marketEncoded,
750
- troveIdEncoded,
751
- boldTokenEncoded,
752
- targetRatioEncoded,
753
- ratioStateEncoded,
766
+ new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
767
+ new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
768
+ new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
769
+ new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
770
+ // @ts-ignore // TODO
771
+ boostEnabled,
754
772
  ];
755
773
  },
756
- decode: (subData) => {
757
- const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
758
- const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
759
- const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
760
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
761
- const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
774
+ decode(subData) {
775
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
762
776
  const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
763
- return {
764
- market, troveId, boldToken, ratioState, targetRatio,
765
- };
777
+ return { targetRatio };
766
778
  },
767
779
  };
768
- exports.fluidLeverageManagementSubData = {
769
- encode: (nftId, vault, ratioState, targetRatio) => {
770
- const nftIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', nftId);
771
- const vaultEncoded = web3_eth_abi_1.default.encodeParameter('address', vault);
772
- const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
773
- const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
774
- const wrapEthEncoded = web3_eth_abi_1.default.encodeParameter('bool', true);
775
- const isRepay = ratioState === enums_1.RatioState.UNDER;
776
- const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
777
- const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
778
- const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
779
- const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
780
+ exports.compoundV2LeverageManagementSubDataWithoutSubProxy = {
781
+ encode(targetRatio, ratioState) {
782
+ const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
783
+ const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
784
+ return [encodedTargetRatio, encodedRatioState];
785
+ },
786
+ decode(subData) {
787
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
788
+ const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
789
+ return { targetRatio, ratioState };
790
+ },
791
+ };
792
+ /**
793
+ ______ ______ .___ ___. .______ ____ ____ ____
794
+ / | / __ \ | \/ | | _ \ \ \ / / |___ \
795
+ | ,----'| | | | | \ / | | |_) | \ \/ / __) |
796
+ | | | | | | | |\/| | | ___/ \ / |__ <
797
+ | `----.| `--' | | | | | | | \ / ___) |
798
+ \______| \______/ |__| |__| | _| \__/ |____/
799
+ */
800
+ exports.compoundV3LeverageManagementSubData = {
801
+ encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
780
802
  return [
781
- nftIdEncoded,
782
- vaultEncoded,
783
- ratioStateEncoded,
784
- targetRatioEncoded,
785
- wrapEthEncoded,
786
- collActionTypeEncoded,
787
- debtActionTypeEncoded,
803
+ market,
804
+ baseToken,
805
+ new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
806
+ new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
807
+ new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
808
+ new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
809
+ // @ts-ignore // TODO
810
+ boostEnabled, isEOA,
788
811
  ];
789
812
  },
790
- decode: (subData) => {
791
- const nftId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
792
- const vault = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
793
- const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
813
+ decode(subData) {
794
814
  const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
795
815
  const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
816
+ return { targetRatio };
817
+ },
818
+ };
819
+ exports.compoundV3LeverageManagementSubDataWithoutSubProxy = {
820
+ encode(market, baseToken, targetRatio, ratioState) {
821
+ const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
822
+ const encodedBaseToken = web3_eth_abi_1.default.encodeParameter('address', baseToken);
823
+ const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
824
+ const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
825
+ return [encodedMarket, encodedBaseToken, encodedTargetRatio, encodedRatioState];
826
+ },
827
+ decode(subData) {
828
+ const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
829
+ const baseToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
830
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]));
831
+ const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[3]);
796
832
  return {
797
- nftId, vault, ratioState, targetRatio,
833
+ market, baseToken, targetRatio, ratioState,
798
834
  };
799
835
  },
800
836
  };
837
+ exports.compoundV3L2LeverageManagementSubData = {
838
+ encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
839
+ let subInput = '0x';
840
+ subInput = subInput.concat(market.slice(2));
841
+ subInput = subInput.concat(baseToken.slice(2));
842
+ subInput = subInput.concat(new decimal_js_1.default(triggerRepayRatio).mul(1e16).toHex().slice(2)
843
+ .padStart(32, '0'));
844
+ subInput = subInput.concat(new decimal_js_1.default(triggerBoostRatio).mul(1e16).toHex().slice(2)
845
+ .padStart(32, '0'));
846
+ subInput = subInput.concat(new decimal_js_1.default(targetBoostRatio).mul(1e16).toHex().slice(2)
847
+ .padStart(32, '0'));
848
+ subInput = subInput.concat(new decimal_js_1.default(targetRepayRatio).mul(1e16).toHex().slice(2)
849
+ .padStart(32, '0'));
850
+ subInput = subInput.concat(boostEnabled ? '01' : '00');
851
+ subInput = subInput.concat(isEOA ? '01' : '00');
852
+ return subInput;
853
+ },
854
+ decode(subData) {
855
+ const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
856
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
857
+ return { targetRatio };
858
+ },
859
+ };
801
860
  exports.compoundV3LeverageManagementOnPriceSubData = {
802
861
  encode(market, collToken, baseToken, targetRatio, ratioState, user) {
803
862
  const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
@@ -854,6 +913,97 @@ exports.compoundV3CloseSubData = {
854
913
  };
855
914
  },
856
915
  };
916
+ /**
917
+ __________ ___ ______ __ __ ___ .__ __. _______ _______
918
+ | ____\ \ / / / || | | | / \ | \ | | / _____|| ____|
919
+ | |__ \ V / | ,----'| |__| | / ^ \ | \| | | | __ | |__
920
+ | __| > < | | | __ | / /_\ \ | . ` | | | |_ | | __|
921
+ | |____ / . \ | `----.| | | | / _____ \ | |\ | | |__| | | |____
922
+ |_______/__/ \__\ \______||__| |__| /__/ \__\ |__| \__| \______| |_______|
923
+ */
924
+ exports.exchangeDcaSubData = {
925
+ encode: (fromToken, toToken, amount, interval) => {
926
+ const sellTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', fromToken);
927
+ const buyTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', toToken);
928
+ const amountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', amount);
929
+ const intervalEncoded = web3_eth_abi_1.default.encodeParameter('uint256', interval);
930
+ return [sellTokenEncoded, buyTokenEncoded, amountEncoded, intervalEncoded];
931
+ },
932
+ decode: (subData, chainId) => {
933
+ const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
934
+ const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
935
+ const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
936
+ const interval = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]).toString();
937
+ return {
938
+ fromToken,
939
+ toToken,
940
+ amount,
941
+ interval,
942
+ };
943
+ },
944
+ };
945
+ exports.exchangeLimitOrderSubData = {
946
+ encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
947
+ return [
948
+ fromToken,
949
+ toToken,
950
+ amount,
951
+ targetPrice,
952
+ new decimal_js_1.default(goodUntil).toString(),
953
+ new decimal_js_1.default(orderType).toString(),
954
+ ];
955
+ },
956
+ decode: (subData, chainId) => {
957
+ const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
958
+ const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
959
+ const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
960
+ return { fromToken, toToken, amount };
961
+ },
962
+ };
963
+ exports.exchangeLimitOrderSubDataWithoutSubProxy = {
964
+ encode(fromToken, toToken, amount) {
965
+ return [
966
+ web3_eth_abi_1.default.encodeParameter('address', fromToken),
967
+ web3_eth_abi_1.default.encodeParameter('address', toToken),
968
+ web3_eth_abi_1.default.encodeParameter('uint256', amount),
969
+ ];
970
+ },
971
+ decode: (subData, chainId) => {
972
+ const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
973
+ const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
974
+ const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
975
+ return { fromToken, toToken, amount };
976
+ },
977
+ };
978
+ /**
979
+ _______..______ ___ .______ __ ___
980
+ / || _ \ / \ | _ \ | |/ /
981
+ | (----`| |_) | / ^ \ | |_) | | ' /
982
+ \ \ | ___/ / /_\ \ | / | <
983
+ .----) | | | / _____ \ | |\ \----.| . \
984
+ |_______/ | _| /__/ \__\ | _| `._____||__|\__\
985
+ */
986
+ exports.sparkLeverageManagementSubData = {
987
+ decode(subData) {
988
+ const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
989
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
990
+ return { targetRatio };
991
+ },
992
+ };
993
+ exports.sparkLeverageManagementSubDataWithoutSubProxy = {
994
+ encode(targetRatio, ratioState) {
995
+ const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
996
+ const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
997
+ const encodedUseDefaultMarket = web3_eth_abi_1.default.encodeParameter('bool', true);
998
+ const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', false);
999
+ return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
1000
+ },
1001
+ decode(subData) {
1002
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
1003
+ const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
1004
+ return { targetRatio, ratioState };
1005
+ },
1006
+ };
857
1007
  exports.sparkCloseGenericSubData = {
858
1008
  encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user) {
859
1009
  const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
@@ -886,6 +1036,155 @@ exports.sparkCloseGenericSubData = {
886
1036
  };
887
1037
  },
888
1038
  };
1039
+ exports.sparkLeverageManagementOnPriceSubData = {
1040
+ encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
1041
+ const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
1042
+ const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint16', collAssetId);
1043
+ const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
1044
+ const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint16', debtAssetId);
1045
+ const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
1046
+ const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
1047
+ const useOnBehalfEncoded = web3_eth_abi_1.default.encodeParameter('bool', false);
1048
+ return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedMarket, encodedTargetRatio, useOnBehalfEncoded];
1049
+ },
1050
+ decode(subData) {
1051
+ const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
1052
+ const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[1]));
1053
+ const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
1054
+ const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[3]));
1055
+ const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
1056
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
1057
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
1058
+ return {
1059
+ collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
1060
+ };
1061
+ },
1062
+ };
1063
+ /**
1064
+ ______ .______ ____ ____ __ __ _______. _______
1065
+ / || _ \ \ \ / / | | | | / || \
1066
+ | ,----'| |_) | \ \/ / | | | | | (----`| .--. |
1067
+ | | | / \ / | | | | \ \ | | | |
1068
+ | `----.| |\ \----. \ / | `--' | .----) | | '--' |
1069
+ \______|| _| `._____| \__/ \______/ |_______/ |_______/
1070
+ */
1071
+ exports.crvUSDLeverageManagementSubData = {
1072
+ encode: (controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr) => {
1073
+ const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
1074
+ const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
1075
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
1076
+ const collTokenAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collTokenAddr);
1077
+ const crvUSDAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', crvUSDAddr);
1078
+ return [controllerAddrEncoded, ratioStateEncoded, targetRatioEncoded, collTokenAddrEncoded, crvUSDAddrEncoded];
1079
+ },
1080
+ decode: (subData) => {
1081
+ const controller = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
1082
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
1083
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
1084
+ return { controller, targetRatio };
1085
+ },
1086
+ };
1087
+ exports.crvUSDPaybackSubData = {
1088
+ encode: (controllerAddr, addressToPullTokensFrom, positionOwner, paybackAmount, crvUSDAddr) => {
1089
+ const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
1090
+ const addressToPullTokensFromEncoded = web3_eth_abi_1.default.encodeParameter('address', addressToPullTokensFrom);
1091
+ const positionOwnerEncoded = web3_eth_abi_1.default.encodeParameter('address', positionOwner);
1092
+ const paybackAmountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, web3_utils_1.toWei)(paybackAmount, 'ether'));
1093
+ const crvUSDAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', crvUSDAddr);
1094
+ return [
1095
+ controllerAddrEncoded,
1096
+ addressToPullTokensFromEncoded,
1097
+ positionOwnerEncoded,
1098
+ paybackAmountEncoded,
1099
+ crvUSDAddrEncoded,
1100
+ ];
1101
+ },
1102
+ decode: (subData) => {
1103
+ const controller = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
1104
+ const addressToPullTokensFrom = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
1105
+ const positionOwner = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
1106
+ const weiPaybackAmount = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
1107
+ const paybackAmount = (0, web3_utils_1.fromWei)(weiPaybackAmount, 'ether');
1108
+ return {
1109
+ controller,
1110
+ addressToPullTokensFrom,
1111
+ positionOwner,
1112
+ paybackAmount,
1113
+ };
1114
+ },
1115
+ };
1116
+ /**
1117
+ .___ ___. ______ .______ .______ __ __ ______
1118
+ | \/ | / __ \ | _ \ | _ \ | | | | / __ \
1119
+ | \ / | | | | | | |_) | | |_) | | |__| | | | | |
1120
+ | |\/| | | | | | | / | ___/ | __ | | | | |
1121
+ | | | | | `--' | | |\ \----.| | | | | | | `--' |
1122
+ |__| |__| \______/ | _| `._____|| _| |__| |__| \______/
1123
+ */
1124
+ exports.morphoBlueLeverageManagementSubData = {
1125
+ encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
1126
+ const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
1127
+ const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
1128
+ const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
1129
+ const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
1130
+ const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
1131
+ const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
1132
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
1133
+ const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
1134
+ const isEOAEncoded = web3_eth_abi_1.default.encodeParameter('bool', isEOA);
1135
+ return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
1136
+ },
1137
+ decode: (subData) => {
1138
+ const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
1139
+ const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
1140
+ const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
1141
+ const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
1142
+ const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
1143
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[6]);
1144
+ const user = web3_eth_abi_1.default.decodeParameter('address', subData[7]);
1145
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
1146
+ return {
1147
+ loanToken,
1148
+ collToken,
1149
+ oracle,
1150
+ irm,
1151
+ lltv,
1152
+ user,
1153
+ targetRatio,
1154
+ };
1155
+ },
1156
+ };
1157
+ exports.morphoBlueLeverageManagementOnPriceSubData = {
1158
+ encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
1159
+ const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
1160
+ const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
1161
+ const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
1162
+ const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
1163
+ const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
1164
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
1165
+ const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
1166
+ return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, targetRatioEncoded, userEncoded];
1167
+ },
1168
+ decode(subData) {
1169
+ const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
1170
+ const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
1171
+ const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
1172
+ const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
1173
+ const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
1174
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
1175
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
1176
+ const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
1177
+ return {
1178
+ loanToken,
1179
+ collToken,
1180
+ oracle,
1181
+ irm,
1182
+ lltv,
1183
+ targetRatio,
1184
+ user,
1185
+ };
1186
+ },
1187
+ };
889
1188
  exports.morphoBlueCloseOnPriceSubData = {
890
1189
  encode(loanToken, collToken, oracle, irm, lltv, user, closeType) {
891
1190
  const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
@@ -916,27 +1215,44 @@ exports.morphoBlueCloseOnPriceSubData = {
916
1215
  };
917
1216
  },
918
1217
  };
919
- exports.sparkLeverageManagementOnPriceSubData = {
920
- encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
921
- const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
922
- const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint16', collAssetId);
923
- const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
924
- const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint16', debtAssetId);
925
- const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
926
- const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
927
- const useOnBehalfEncoded = web3_eth_abi_1.default.encodeParameter('bool', false);
928
- return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedMarket, encodedTargetRatio, useOnBehalfEncoded];
1218
+ /**
1219
+ _______ __ __ __ __ _______
1220
+ | ____|| | | | | | | | | \
1221
+ | |__ | | | | | | | | | .--. |
1222
+ | __| | | | | | | | | | | | |
1223
+ | | | `----.| `--' | | | | '--' |
1224
+ |__| |_______| \______/ |__| |_______/
1225
+ */
1226
+ exports.fluidLeverageManagementSubData = {
1227
+ encode: (nftId, vault, ratioState, targetRatio) => {
1228
+ const nftIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', nftId);
1229
+ const vaultEncoded = web3_eth_abi_1.default.encodeParameter('address', vault);
1230
+ const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
1231
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
1232
+ const wrapEthEncoded = web3_eth_abi_1.default.encodeParameter('bool', true);
1233
+ const isRepay = ratioState === enums_1.RatioState.UNDER;
1234
+ const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
1235
+ const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
1236
+ const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
1237
+ const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
1238
+ return [
1239
+ nftIdEncoded,
1240
+ vaultEncoded,
1241
+ ratioStateEncoded,
1242
+ targetRatioEncoded,
1243
+ wrapEthEncoded,
1244
+ collActionTypeEncoded,
1245
+ debtActionTypeEncoded,
1246
+ ];
929
1247
  },
930
- decode(subData) {
931
- const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
932
- const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[1]));
933
- const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
934
- const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint16', subData[3]));
935
- const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
936
- const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
1248
+ decode: (subData) => {
1249
+ const nftId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
1250
+ const vault = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
1251
+ const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
1252
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
937
1253
  const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
938
1254
  return {
939
- collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
1255
+ nftId, vault, ratioState, targetRatio,
940
1256
  };
941
1257
  },
942
1258
  };