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