@defisaver/automation-sdk 3.3.14 → 3.3.15-liq-prot-1-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/constants/index.js +130 -0
- package/cjs/index.d.ts +4 -3
- package/cjs/index.js +6 -2
- package/cjs/services/strategiesService.js +178 -17
- package/cjs/services/strategySubService.d.ts +14 -13
- package/cjs/services/strategySubService.js +79 -63
- package/cjs/services/strategySubService.test.js +0 -234
- package/cjs/services/subDataService.d.ts +92 -4
- package/cjs/services/subDataService.js +245 -35
- package/cjs/services/subDataService.test.js +0 -110
- package/cjs/services/utils.d.ts +3 -1
- package/cjs/services/utils.js +34 -1
- package/cjs/services/utils.test.js +25 -0
- package/cjs/types/enums.d.ts +36 -6
- package/cjs/types/enums.js +30 -0
- package/esm/constants/index.js +130 -0
- package/esm/index.d.ts +4 -3
- package/esm/index.js +7 -3
- package/esm/services/strategiesService.js +178 -17
- package/esm/services/strategySubService.d.ts +14 -13
- package/esm/services/strategySubService.js +79 -60
- package/esm/services/strategySubService.test.js +2 -236
- package/esm/services/subDataService.d.ts +92 -4
- package/esm/services/subDataService.js +243 -34
- package/esm/services/subDataService.test.js +0 -110
- package/esm/services/utils.d.ts +3 -1
- package/esm/services/utils.js +32 -1
- package/esm/services/utils.test.js +27 -2
- package/esm/types/enums.d.ts +36 -6
- package/esm/types/enums.js +30 -0
- package/package.json +1 -1
- package/src/constants/index.ts +132 -1
- package/src/index.ts +24 -6
- package/src/services/strategiesService.ts +242 -17
- package/src/services/strategySubService.test.ts +0 -279
- package/src/services/strategySubService.ts +209 -116
- package/src/services/subDataService.test.ts +0 -120
- package/src/services/subDataService.ts +335 -49
- package/src/services/utils.test.ts +32 -1
- package/src/services/utils.ts +32 -1
- package/src/types/enums.ts +30 -2
|
@@ -71,6 +71,14 @@ export declare const makerLeverageManagementWithoutSubProxy: {
|
|
|
71
71
|
daiAddr: string;
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
|
+
export declare const makerLiquidationProtectionSubData: {
|
|
75
|
+
encode(vaultId: number, targetRatio: number, daiAddr?: EthereumAddress): string[];
|
|
76
|
+
decode(subData: string[]): {
|
|
77
|
+
vaultId: number;
|
|
78
|
+
targetRatio: number;
|
|
79
|
+
daiAddr: string;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
74
82
|
/**
|
|
75
83
|
__ __ ______ __ __ __ .___________.____ ____ ____ ____ __
|
|
76
84
|
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
|
|
@@ -89,6 +97,13 @@ export declare const liquityLeverageManagementSubData: {
|
|
|
89
97
|
targetRatio: number;
|
|
90
98
|
};
|
|
91
99
|
};
|
|
100
|
+
export declare const liquityLeverageManagementSubDataWithoutSubProxy: {
|
|
101
|
+
encode(targetRatio: number, ratioState: RatioState): string[];
|
|
102
|
+
decode(subData: string[]): {
|
|
103
|
+
targetRatio: number;
|
|
104
|
+
ratioState: RatioState;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
92
107
|
export declare const liquityCloseSubData: {
|
|
93
108
|
encode(closeToAssetAddr: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): string[];
|
|
94
109
|
decode(subData: string[]): {
|
|
@@ -177,6 +192,14 @@ export declare const aaveV2LeverageManagementSubData: {
|
|
|
177
192
|
targetRatio: number;
|
|
178
193
|
};
|
|
179
194
|
};
|
|
195
|
+
export declare const aaveV2LeverageManagementSubDataWithoutSubProxy: {
|
|
196
|
+
encode(market: EthereumAddress, targetRatio: number, ratioState: RatioState): string[];
|
|
197
|
+
decode(subData: string[]): {
|
|
198
|
+
market: EthereumAddress;
|
|
199
|
+
targetRatio: number;
|
|
200
|
+
ratioState: RatioState;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
180
203
|
/**
|
|
181
204
|
___ ___ ____ ____ _______ ____ ____ ____
|
|
182
205
|
/ \ / \ \ \ / / | ____| \ \ / / |___ \
|
|
@@ -197,6 +220,13 @@ export declare const aaveV3LeverageManagementSubDataWithoutSubProxy: {
|
|
|
197
220
|
ratioState: RatioState;
|
|
198
221
|
};
|
|
199
222
|
};
|
|
223
|
+
export declare const aaveV3LiquidationProtectionSubData: {
|
|
224
|
+
encode(targetRatio: number, ratioState: RatioState, market: EthereumAddress, user: EthereumAddress): string[];
|
|
225
|
+
decode(subData: string[]): {
|
|
226
|
+
targetRatio: number;
|
|
227
|
+
ratioState: RatioState;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
200
230
|
export declare const aaveV3LeverageManagementOnPriceGeneric: {
|
|
201
231
|
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): string[];
|
|
202
232
|
decode(subData: string[]): {
|
|
@@ -269,6 +299,15 @@ export declare const aaveV4LeverageManagementSubData: {
|
|
|
269
299
|
targetRatio: number;
|
|
270
300
|
};
|
|
271
301
|
};
|
|
302
|
+
export declare const aaveV4LiquidationProtectionSubData: {
|
|
303
|
+
encode: (spoke: EthereumAddress, owner: EthereumAddress, ratioState: RatioState, targetRatio: number) => string[];
|
|
304
|
+
decode: (subData: string[]) => {
|
|
305
|
+
spoke: string;
|
|
306
|
+
owner: string;
|
|
307
|
+
ratioState: RatioState;
|
|
308
|
+
targetRatio: number;
|
|
309
|
+
};
|
|
310
|
+
};
|
|
272
311
|
export declare const aaveV4LeverageManagementOnPriceSubData: {
|
|
273
312
|
encode: (spoke: EthereumAddress, owner: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, ratioState: RatioState, targetRatio: number) => string[];
|
|
274
313
|
decode: (subData: string[]) => {
|
|
@@ -320,6 +359,13 @@ export declare const compoundV2LeverageManagementSubData: {
|
|
|
320
359
|
targetRatio: number;
|
|
321
360
|
};
|
|
322
361
|
};
|
|
362
|
+
export declare const compoundV2LeverageManagementSubDataWithoutSubProxy: {
|
|
363
|
+
encode(targetRatio: number, ratioState: RatioState): string[];
|
|
364
|
+
decode(subData: string[]): {
|
|
365
|
+
targetRatio: number;
|
|
366
|
+
ratioState: RatioState;
|
|
367
|
+
};
|
|
368
|
+
};
|
|
323
369
|
/**
|
|
324
370
|
______ ______ .___ ___. .______ ____ ____ ____
|
|
325
371
|
/ | / __ \ | \/ | | _ \ \ \ / / |___ \
|
|
@@ -328,16 +374,22 @@ export declare const compoundV2LeverageManagementSubData: {
|
|
|
328
374
|
| `----.| `--' | | | | | | | \ / ___) |
|
|
329
375
|
\______| \______/ |__| |__| | _| \__/ |____/
|
|
330
376
|
*/
|
|
331
|
-
export declare const
|
|
332
|
-
encode(market: EthereumAddress, baseToken: EthereumAddress,
|
|
377
|
+
export declare const compoundV3LeverageManagementSubDataWithoutSubProxy: {
|
|
378
|
+
encode(market: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, ratioState: RatioState): string[];
|
|
333
379
|
decode(subData: string[]): {
|
|
380
|
+
market: EthereumAddress;
|
|
381
|
+
baseToken: EthereumAddress;
|
|
334
382
|
targetRatio: number;
|
|
383
|
+
ratioState: RatioState;
|
|
335
384
|
};
|
|
336
385
|
};
|
|
337
|
-
export declare const
|
|
338
|
-
encode(market: EthereumAddress, baseToken: EthereumAddress,
|
|
386
|
+
export declare const compoundV3LiquidationProtectionSubDataWithoutSubProxy: {
|
|
387
|
+
encode(market: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, ratioState: RatioState): string[];
|
|
339
388
|
decode(subData: string[]): {
|
|
389
|
+
market: EthereumAddress;
|
|
390
|
+
baseToken: EthereumAddress;
|
|
340
391
|
targetRatio: number;
|
|
392
|
+
ratioState: RatioState;
|
|
341
393
|
};
|
|
342
394
|
};
|
|
343
395
|
export declare const compoundV3LeverageManagementOnPriceSubData: {
|
|
@@ -386,6 +438,14 @@ export declare const exchangeLimitOrderSubData: {
|
|
|
386
438
|
amount: string;
|
|
387
439
|
};
|
|
388
440
|
};
|
|
441
|
+
export declare const exchangeLimitOrderSubDataWithoutSubProxy: {
|
|
442
|
+
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string): string[];
|
|
443
|
+
decode: (subData: string[], chainId: ChainId) => {
|
|
444
|
+
fromToken: string;
|
|
445
|
+
toToken: string;
|
|
446
|
+
amount: string;
|
|
447
|
+
};
|
|
448
|
+
};
|
|
389
449
|
/**
|
|
390
450
|
_______..______ ___ .______ __ ___
|
|
391
451
|
/ || _ \ / \ | _ \ | |/ /
|
|
@@ -406,6 +466,13 @@ export declare const sparkLeverageManagementSubDataWithoutSubProxy: {
|
|
|
406
466
|
ratioState: RatioState;
|
|
407
467
|
};
|
|
408
468
|
};
|
|
469
|
+
export declare const sparkLiquidationProtectionSubData: {
|
|
470
|
+
encode(targetRatio: number, ratioState: RatioState): string[];
|
|
471
|
+
decode(subData: string[]): {
|
|
472
|
+
targetRatio: number;
|
|
473
|
+
ratioState: RatioState;
|
|
474
|
+
};
|
|
475
|
+
};
|
|
409
476
|
export declare const sparkCloseGenericSubData: {
|
|
410
477
|
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, closeType: CloseStrategyType, marketAddr: EthereumAddress, user: EthereumAddress): string[];
|
|
411
478
|
decode(subData: string[]): {
|
|
@@ -484,6 +551,18 @@ export declare const morphoBlueLeverageManagementSubData: {
|
|
|
484
551
|
targetRatio: number;
|
|
485
552
|
};
|
|
486
553
|
};
|
|
554
|
+
export declare const morphoBlueLiquidationProtectionSubData: {
|
|
555
|
+
encode: (loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, user: EthereumAddress, isEOA: boolean) => string[];
|
|
556
|
+
decode: (subData: string[]) => {
|
|
557
|
+
loanToken: string;
|
|
558
|
+
collToken: string;
|
|
559
|
+
oracle: string;
|
|
560
|
+
irm: string;
|
|
561
|
+
lltv: string;
|
|
562
|
+
user: string;
|
|
563
|
+
targetRatio: number;
|
|
564
|
+
};
|
|
565
|
+
};
|
|
487
566
|
export declare const morphoBlueLeverageManagementOnPriceSubData: {
|
|
488
567
|
encode(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, targetRatio: number, user: EthereumAddress): string[];
|
|
489
568
|
decode(subData: string[]): {
|
|
@@ -525,3 +604,12 @@ export declare const fluidLeverageManagementSubData: {
|
|
|
525
604
|
targetRatio: number;
|
|
526
605
|
};
|
|
527
606
|
};
|
|
607
|
+
export declare const fluidLiquidationProtectionSubData: {
|
|
608
|
+
encode: (nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number) => string[];
|
|
609
|
+
decode: (subData: string[]) => {
|
|
610
|
+
nftId: string;
|
|
611
|
+
vault: string;
|
|
612
|
+
ratioState: RatioState;
|
|
613
|
+
targetRatio: number;
|
|
614
|
+
};
|
|
615
|
+
};
|
|
@@ -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.
|
|
6
|
+
exports.crvUSDLeverageManagementSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkLiquidationProtectionSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubDataWithoutSubProxy = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3LiquidationProtectionSubDataWithoutSubProxy = exports.compoundV3LeverageManagementSubDataWithoutSubProxy = exports.compoundV2LeverageManagementSubDataWithoutSubProxy = exports.compoundV2LeverageManagementSubData = exports.aaveV4CollateralSwitchSubData = exports.aaveV4CloseSubData = exports.aaveV4LeverageManagementOnPriceSubData = exports.aaveV4LiquidationProtectionSubData = exports.aaveV4LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LiquidationProtectionSubData = 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.makerLiquidationProtectionSubData = exports.makerLeverageManagementWithoutSubProxy = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
|
|
7
|
+
exports.fluidLiquidationProtectionSubData = exports.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLiquidationProtectionSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = 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");
|
|
@@ -131,6 +132,8 @@ exports.makerLeverageManagementSubData = {
|
|
|
131
132
|
return { vaultId, targetRatio };
|
|
132
133
|
},
|
|
133
134
|
};
|
|
135
|
+
// ! Any change here will PROBABLY require a change in makerLiquidationProtectionSubData as well, since it is copy paste
|
|
136
|
+
// ! Double check before changing
|
|
134
137
|
exports.makerLeverageManagementWithoutSubProxy = {
|
|
135
138
|
encode(vaultId, targetRatio, daiAddr) {
|
|
136
139
|
const encodedVaultId = web3_eth_abi_1.default.encodeParameter('uint256', vaultId);
|
|
@@ -145,6 +148,20 @@ exports.makerLeverageManagementWithoutSubProxy = {
|
|
|
145
148
|
return { vaultId, targetRatio, daiAddr };
|
|
146
149
|
},
|
|
147
150
|
};
|
|
151
|
+
exports.makerLiquidationProtectionSubData = {
|
|
152
|
+
encode(vaultId, targetRatio, daiAddr) {
|
|
153
|
+
const encodedVaultId = web3_eth_abi_1.default.encodeParameter('uint256', vaultId);
|
|
154
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
155
|
+
const encodedDaiAddr = web3_eth_abi_1.default.encodeParameter('address', daiAddr || (0, tokens_1.getAssetInfo)('DAI', 1).address);
|
|
156
|
+
return [encodedVaultId, encodedTargetRatio, encodedDaiAddr];
|
|
157
|
+
},
|
|
158
|
+
decode(subData) {
|
|
159
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
160
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[1]));
|
|
161
|
+
const daiAddr = web3_eth_abi_1.default.decodeParameter('address', subData[2]).toString();
|
|
162
|
+
return { vaultId, targetRatio, daiAddr };
|
|
163
|
+
},
|
|
164
|
+
};
|
|
148
165
|
/**
|
|
149
166
|
__ __ ______ __ __ __ .___________.____ ____ ____ ____ __
|
|
150
167
|
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
|
|
@@ -167,6 +184,23 @@ exports.liquityLeverageManagementSubData = {
|
|
|
167
184
|
return { targetRatio };
|
|
168
185
|
},
|
|
169
186
|
};
|
|
187
|
+
exports.liquityLeverageManagementSubDataWithoutSubProxy = {
|
|
188
|
+
encode(targetRatio, ratioState) {
|
|
189
|
+
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
190
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
191
|
+
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
192
|
+
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
193
|
+
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
194
|
+
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
195
|
+
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
196
|
+
return [encodedRatioState, encodedTargetRatio, collActionTypeEncoded, debtActionTypeEncoded];
|
|
197
|
+
},
|
|
198
|
+
decode(subData) {
|
|
199
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[0]);
|
|
200
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[1]));
|
|
201
|
+
return { targetRatio, ratioState };
|
|
202
|
+
},
|
|
203
|
+
};
|
|
170
204
|
exports.liquityCloseSubData = {
|
|
171
205
|
encode(closeToAssetAddr, chainId = enums_1.ChainId.Ethereum, collAddr, debtAddr) {
|
|
172
206
|
const _collAddr = collAddr || (0, tokens_1.getAssetInfo)('WETH', chainId).address;
|
|
@@ -398,6 +432,25 @@ exports.aaveV2LeverageManagementSubData = {
|
|
|
398
432
|
return { targetRatio };
|
|
399
433
|
},
|
|
400
434
|
};
|
|
435
|
+
exports.aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
436
|
+
encode(market, targetRatio, ratioState) {
|
|
437
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
438
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
439
|
+
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
440
|
+
const isBoost = ratioState === enums_1.RatioState.OVER;
|
|
441
|
+
if (isBoost) {
|
|
442
|
+
const enableAsCollEncoded = web3_eth_abi_1.default.encodeParameter('uint256', 1);
|
|
443
|
+
return [encodedMarket, encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
444
|
+
}
|
|
445
|
+
return [encodedMarket, encodedTargetRatio, encodedRatioState];
|
|
446
|
+
},
|
|
447
|
+
decode(subData) {
|
|
448
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
449
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[1]));
|
|
450
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
|
|
451
|
+
return { market, targetRatio, ratioState };
|
|
452
|
+
},
|
|
453
|
+
};
|
|
401
454
|
/**
|
|
402
455
|
___ ___ ____ ____ _______ ____ ____ ____
|
|
403
456
|
/ \ / \ \ \ / / | ____| \ \ / / |___ \
|
|
@@ -413,6 +466,8 @@ exports.aaveV3LeverageManagementSubData = {
|
|
|
413
466
|
return { targetRatio };
|
|
414
467
|
},
|
|
415
468
|
};
|
|
469
|
+
// ! Any change here will PROBABLY require a change in aaveV3LiquidationProtectionSubData as well
|
|
470
|
+
// ! Double check before changing. Liquidation protection is using Generic encoding for both - EOA and SW
|
|
416
471
|
exports.aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
417
472
|
encode(targetRatio, ratioState, market, user, isGeneric) {
|
|
418
473
|
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
@@ -432,6 +487,20 @@ exports.aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
432
487
|
return { targetRatio, ratioState };
|
|
433
488
|
},
|
|
434
489
|
};
|
|
490
|
+
exports.aaveV3LiquidationProtectionSubData = {
|
|
491
|
+
encode(targetRatio, ratioState, market, user) {
|
|
492
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
493
|
+
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
494
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
495
|
+
const encodedUser = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
496
|
+
return [encodedTargetRatio, encodedRatioState, encodedMarket, encodedUser];
|
|
497
|
+
},
|
|
498
|
+
decode(subData) {
|
|
499
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
|
|
500
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
|
|
501
|
+
return { targetRatio, ratioState };
|
|
502
|
+
},
|
|
503
|
+
};
|
|
435
504
|
exports.aaveV3LeverageManagementOnPriceGeneric = {
|
|
436
505
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user) {
|
|
437
506
|
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
@@ -593,6 +662,8 @@ exports.aaveV3LeverageManagementOnPriceSubData = {
|
|
|
593
662
|
/ _____ \ / _____ \ \ / | |____ \ / | |
|
|
594
663
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
|
|
595
664
|
*/
|
|
665
|
+
// ! Any change here will PROBABLY require a change in aaveV4LiquidationProtectionSubData as well, since it is copy paste
|
|
666
|
+
// ! Double check before changing
|
|
596
667
|
exports.aaveV4LeverageManagementSubData = {
|
|
597
668
|
encode: (spoke, owner, ratioState, targetRatio) => {
|
|
598
669
|
const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
|
|
@@ -619,6 +690,32 @@ exports.aaveV4LeverageManagementSubData = {
|
|
|
619
690
|
};
|
|
620
691
|
},
|
|
621
692
|
};
|
|
693
|
+
exports.aaveV4LiquidationProtectionSubData = {
|
|
694
|
+
encode: (spoke, owner, ratioState, targetRatio) => {
|
|
695
|
+
const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
|
|
696
|
+
const ownerEncoded = web3_eth_abi_1.default.encodeParameter('address', owner);
|
|
697
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
698
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
699
|
+
// Add two empty slots for future addons (e.g tsi or slippage settings)
|
|
700
|
+
return [
|
|
701
|
+
spokeEncoded,
|
|
702
|
+
ownerEncoded,
|
|
703
|
+
ratioStateEncoded,
|
|
704
|
+
targetRatioEncoded,
|
|
705
|
+
constants_1.EMPTY_SLOT,
|
|
706
|
+
constants_1.EMPTY_SLOT,
|
|
707
|
+
];
|
|
708
|
+
},
|
|
709
|
+
decode: (subData) => {
|
|
710
|
+
const spoke = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
711
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
712
|
+
const ratioState = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[2]));
|
|
713
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
|
|
714
|
+
return {
|
|
715
|
+
spoke, owner, ratioState, targetRatio,
|
|
716
|
+
};
|
|
717
|
+
},
|
|
718
|
+
};
|
|
622
719
|
exports.aaveV4LeverageManagementOnPriceSubData = {
|
|
623
720
|
encode: (spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio) => {
|
|
624
721
|
const spokeEncoded = web3_eth_abi_1.default.encodeParameter('address', spoke);
|
|
@@ -752,6 +849,23 @@ exports.compoundV2LeverageManagementSubData = {
|
|
|
752
849
|
return { targetRatio };
|
|
753
850
|
},
|
|
754
851
|
};
|
|
852
|
+
exports.compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
853
|
+
encode(targetRatio, ratioState) {
|
|
854
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
855
|
+
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
856
|
+
const isBoost = ratioState === enums_1.RatioState.OVER;
|
|
857
|
+
if (isBoost) {
|
|
858
|
+
const enableAsCollEncoded = web3_eth_abi_1.default.encodeParameter('uint256', 1);
|
|
859
|
+
return [encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
860
|
+
}
|
|
861
|
+
return [encodedTargetRatio, encodedRatioState];
|
|
862
|
+
},
|
|
863
|
+
decode(subData) {
|
|
864
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
|
|
865
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
|
|
866
|
+
return { targetRatio, ratioState };
|
|
867
|
+
},
|
|
868
|
+
};
|
|
755
869
|
/**
|
|
756
870
|
______ ______ .___ ___. .______ ____ ____ ____
|
|
757
871
|
/ | / __ \ | \/ | | _ \ \ \ / / |___ \
|
|
@@ -760,46 +874,42 @@ exports.compoundV2LeverageManagementSubData = {
|
|
|
760
874
|
| `----.| `--' | | | | | | | \ / ___) |
|
|
761
875
|
\______| \______/ |__| |__| | _| \__/ |____/
|
|
762
876
|
*/
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
// @ts-ignore // TODO
|
|
773
|
-
boostEnabled, isEOA,
|
|
774
|
-
];
|
|
877
|
+
// ! Any change here will PROBABLY require a change in compoundV3LiquidationProtectionSubDataWithoutSubProxy as well, since it is copy paste
|
|
878
|
+
// ! Double check before changing
|
|
879
|
+
exports.compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
880
|
+
encode(market, baseToken, targetRatio, ratioState) {
|
|
881
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
882
|
+
const encodedBaseToken = web3_eth_abi_1.default.encodeParameter('address', baseToken);
|
|
883
|
+
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
884
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
885
|
+
return [encodedMarket, encodedBaseToken, encodedRatioState, encodedTargetRatio];
|
|
775
886
|
},
|
|
776
887
|
decode(subData) {
|
|
777
|
-
const
|
|
778
|
-
const
|
|
779
|
-
|
|
888
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
889
|
+
const baseToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
890
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
|
|
891
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
|
|
892
|
+
return {
|
|
893
|
+
market, baseToken, targetRatio, ratioState,
|
|
894
|
+
};
|
|
780
895
|
},
|
|
781
896
|
};
|
|
782
|
-
exports.
|
|
783
|
-
encode(market, baseToken,
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
subInput = subInput.concat(new decimal_js_1.default(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
790
|
-
.padStart(32, '0'));
|
|
791
|
-
subInput = subInput.concat(new decimal_js_1.default(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
792
|
-
.padStart(32, '0'));
|
|
793
|
-
subInput = subInput.concat(new decimal_js_1.default(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
794
|
-
.padStart(32, '0'));
|
|
795
|
-
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
796
|
-
subInput = subInput.concat(isEOA ? '01' : '00');
|
|
797
|
-
return subInput;
|
|
897
|
+
exports.compoundV3LiquidationProtectionSubDataWithoutSubProxy = {
|
|
898
|
+
encode(market, baseToken, targetRatio, ratioState) {
|
|
899
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
900
|
+
const encodedBaseToken = web3_eth_abi_1.default.encodeParameter('address', baseToken);
|
|
901
|
+
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
902
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
903
|
+
return [encodedMarket, encodedBaseToken, encodedRatioState, encodedTargetRatio];
|
|
798
904
|
},
|
|
799
905
|
decode(subData) {
|
|
800
|
-
const
|
|
801
|
-
const
|
|
802
|
-
|
|
906
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
907
|
+
const baseToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
908
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
|
|
909
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[3]));
|
|
910
|
+
return {
|
|
911
|
+
market, baseToken, targetRatio, ratioState,
|
|
912
|
+
};
|
|
803
913
|
},
|
|
804
914
|
};
|
|
805
915
|
exports.compoundV3LeverageManagementOnPriceSubData = {
|
|
@@ -905,6 +1015,21 @@ exports.exchangeLimitOrderSubData = {
|
|
|
905
1015
|
return { fromToken, toToken, amount };
|
|
906
1016
|
},
|
|
907
1017
|
};
|
|
1018
|
+
exports.exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
1019
|
+
encode(fromToken, toToken, amount) {
|
|
1020
|
+
return [
|
|
1021
|
+
web3_eth_abi_1.default.encodeParameter('address', fromToken),
|
|
1022
|
+
web3_eth_abi_1.default.encodeParameter('address', toToken),
|
|
1023
|
+
web3_eth_abi_1.default.encodeParameter('uint256', amount),
|
|
1024
|
+
];
|
|
1025
|
+
},
|
|
1026
|
+
decode: (subData, chainId) => {
|
|
1027
|
+
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
1028
|
+
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
1029
|
+
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
1030
|
+
return { fromToken, toToken, amount };
|
|
1031
|
+
},
|
|
1032
|
+
};
|
|
908
1033
|
/**
|
|
909
1034
|
_______..______ ___ .______ __ ___
|
|
910
1035
|
/ || _ \ / \ | _ \ | |/ /
|
|
@@ -920,6 +1045,8 @@ exports.sparkLeverageManagementSubData = {
|
|
|
920
1045
|
return { targetRatio };
|
|
921
1046
|
},
|
|
922
1047
|
};
|
|
1048
|
+
// ! Any change here will PROBABLY require a change in sparkLiquidationProtectionSubData as well, since it is copy paste
|
|
1049
|
+
// ! Double check before changing
|
|
923
1050
|
exports.sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
924
1051
|
encode(targetRatio, ratioState) {
|
|
925
1052
|
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
@@ -934,6 +1061,20 @@ exports.sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
|
934
1061
|
return { targetRatio, ratioState };
|
|
935
1062
|
},
|
|
936
1063
|
};
|
|
1064
|
+
exports.sparkLiquidationProtectionSubData = {
|
|
1065
|
+
encode(targetRatio, ratioState) {
|
|
1066
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
1067
|
+
const encodedRatioState = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
1068
|
+
const encodedUseDefaultMarket = web3_eth_abi_1.default.encodeParameter('bool', true);
|
|
1069
|
+
const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', false);
|
|
1070
|
+
return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
|
|
1071
|
+
},
|
|
1072
|
+
decode(subData) {
|
|
1073
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(web3_eth_abi_1.default.decodeParameter('uint256', subData[0]));
|
|
1074
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[1]);
|
|
1075
|
+
return { targetRatio, ratioState };
|
|
1076
|
+
},
|
|
1077
|
+
};
|
|
937
1078
|
exports.sparkCloseGenericSubData = {
|
|
938
1079
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user) {
|
|
939
1080
|
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
@@ -1082,6 +1223,8 @@ exports.crvUSDPaybackSubData = {
|
|
|
1082
1223
|
| | | | | `--' | | |\ \----.| | | | | | | `--' |
|
|
1083
1224
|
|__| |__| \______/ | _| `._____|| _| |__| |__| \______/
|
|
1084
1225
|
*/
|
|
1226
|
+
// ! Any change here will PROBABLY require a change in morphoBlueLiquidationProtectionSubData as well, since it is copy paste
|
|
1227
|
+
// ! Double check before changing
|
|
1085
1228
|
exports.morphoBlueLeverageManagementSubData = {
|
|
1086
1229
|
encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
|
|
1087
1230
|
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
@@ -1115,6 +1258,39 @@ exports.morphoBlueLeverageManagementSubData = {
|
|
|
1115
1258
|
};
|
|
1116
1259
|
},
|
|
1117
1260
|
};
|
|
1261
|
+
exports.morphoBlueLiquidationProtectionSubData = {
|
|
1262
|
+
encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
|
|
1263
|
+
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
1264
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
1265
|
+
const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
|
|
1266
|
+
const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
|
|
1267
|
+
const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
|
|
1268
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
1269
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
1270
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
1271
|
+
const isEOAEncoded = web3_eth_abi_1.default.encodeParameter('bool', isEOA);
|
|
1272
|
+
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
|
|
1273
|
+
},
|
|
1274
|
+
decode: (subData) => {
|
|
1275
|
+
const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
1276
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
1277
|
+
const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
1278
|
+
const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
1279
|
+
const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
1280
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[6]);
|
|
1281
|
+
const user = web3_eth_abi_1.default.decodeParameter('address', subData[7]);
|
|
1282
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
1283
|
+
return {
|
|
1284
|
+
loanToken,
|
|
1285
|
+
collToken,
|
|
1286
|
+
oracle,
|
|
1287
|
+
irm,
|
|
1288
|
+
lltv,
|
|
1289
|
+
user,
|
|
1290
|
+
targetRatio,
|
|
1291
|
+
};
|
|
1292
|
+
},
|
|
1293
|
+
};
|
|
1118
1294
|
exports.morphoBlueLeverageManagementOnPriceSubData = {
|
|
1119
1295
|
encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
|
|
1120
1296
|
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
@@ -1184,6 +1360,8 @@ _______ __ __ __ __ _______
|
|
|
1184
1360
|
| | | `----.| `--' | | | | '--' |
|
|
1185
1361
|
|__| |_______| \______/ |__| |_______/
|
|
1186
1362
|
*/
|
|
1363
|
+
// ! Any change here will PROBABLY require a change in fluidLeverageManagementSubData as well, since it is copy paste
|
|
1364
|
+
// ! Double check before changing
|
|
1187
1365
|
exports.fluidLeverageManagementSubData = {
|
|
1188
1366
|
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
1189
1367
|
const nftIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', nftId);
|
|
@@ -1217,3 +1395,35 @@ exports.fluidLeverageManagementSubData = {
|
|
|
1217
1395
|
};
|
|
1218
1396
|
},
|
|
1219
1397
|
};
|
|
1398
|
+
exports.fluidLiquidationProtectionSubData = {
|
|
1399
|
+
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
1400
|
+
const nftIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', nftId);
|
|
1401
|
+
const vaultEncoded = web3_eth_abi_1.default.encodeParameter('address', vault);
|
|
1402
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
1403
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
1404
|
+
const wrapEthEncoded = web3_eth_abi_1.default.encodeParameter('bool', true);
|
|
1405
|
+
const collActionType = enums_1.CollActionType.WITHDRAW;
|
|
1406
|
+
const debtActionType = enums_1.DebtActionType.PAYBACK;
|
|
1407
|
+
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
1408
|
+
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
1409
|
+
return [
|
|
1410
|
+
nftIdEncoded,
|
|
1411
|
+
vaultEncoded,
|
|
1412
|
+
ratioStateEncoded,
|
|
1413
|
+
targetRatioEncoded,
|
|
1414
|
+
wrapEthEncoded,
|
|
1415
|
+
collActionTypeEncoded,
|
|
1416
|
+
debtActionTypeEncoded,
|
|
1417
|
+
];
|
|
1418
|
+
},
|
|
1419
|
+
decode: (subData) => {
|
|
1420
|
+
const nftId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
1421
|
+
const vault = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
1422
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
|
|
1423
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
1424
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
1425
|
+
return {
|
|
1426
|
+
nftId, vault, ratioState, targetRatio,
|
|
1427
|
+
};
|
|
1428
|
+
},
|
|
1429
|
+
};
|