@defisaver/automation-sdk 3.2.2 → 3.2.3
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/.babelrc +3 -3
- package/.editorconfig +9 -9
- package/.env.dev +4 -4
- package/.eslintignore +6 -6
- package/.eslintrc.js +39 -39
- package/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +46 -46
- package/cjs/abis/Erc20.json +223 -223
- package/cjs/abis/SubStorage.json +21 -21
- package/cjs/abis/UniMulticall.json +17 -17
- package/cjs/abis/index.d.ts +9 -9
- package/cjs/abis/index.js +30 -30
- package/cjs/abis/legacy_AaveV2Subscriptions.json +8 -8
- package/cjs/abis/legacy_AuthCheck.json +8 -8
- package/cjs/abis/legacy_CompoundV2Subscriptions.json +9 -9
- package/cjs/abis/legacy_MakerSubscriptions.json +9 -9
- package/cjs/automation/private/Automation.d.ts +12 -12
- package/cjs/automation/private/Automation.js +42 -42
- package/cjs/automation/private/LegacyAutomation.d.ts +25 -25
- package/cjs/automation/private/LegacyAutomation.js +118 -118
- package/cjs/automation/private/LegacyProtocol.d.ts +22 -22
- package/cjs/automation/private/LegacyProtocol.js +41 -41
- package/cjs/automation/private/LegacyProtocol.test.d.ts +1 -1
- package/cjs/automation/private/LegacyProtocol.test.js +25 -25
- package/cjs/automation/private/Protocol.d.ts +22 -22
- package/cjs/automation/private/Protocol.js +41 -41
- package/cjs/automation/private/Protocol.test.d.ts +1 -1
- package/cjs/automation/private/Protocol.test.js +25 -25
- package/cjs/automation/private/StrategiesAutomation.d.ts +33 -33
- package/cjs/automation/private/StrategiesAutomation.js +189 -189
- package/cjs/automation/private/StrategiesAutomation.test.d.ts +1 -1
- package/cjs/automation/private/StrategiesAutomation.test.js +671 -671
- package/cjs/automation/public/ArbitrumStrategies.d.ts +5 -5
- package/cjs/automation/public/ArbitrumStrategies.js +13 -13
- package/cjs/automation/public/BaseStrategies.d.ts +5 -5
- package/cjs/automation/public/BaseStrategies.js +13 -13
- package/cjs/automation/public/EthereumStrategies.d.ts +5 -5
- package/cjs/automation/public/EthereumStrategies.js +13 -13
- package/cjs/automation/public/OptimismStrategies.d.ts +5 -5
- package/cjs/automation/public/OptimismStrategies.js +13 -13
- package/cjs/automation/public/Strategies.test.d.ts +1 -1
- package/cjs/automation/public/Strategies.test.js +61 -61
- package/cjs/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
- package/cjs/automation/public/legacy/LegacyAaveAutomation.js +20 -20
- package/cjs/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
- package/cjs/automation/public/legacy/LegacyCompoundAutomation.js +20 -20
- package/cjs/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
- package/cjs/automation/public/legacy/LegacyMakerAutomation.js +20 -20
- package/cjs/configuration.d.ts +1 -1
- package/cjs/configuration.js +12 -12
- package/cjs/constants/index.d.ts +28 -28
- package/cjs/constants/index.js +564 -564
- package/cjs/index.d.ts +23 -23
- package/cjs/index.js +65 -65
- package/cjs/services/contractService.d.ts +12 -12
- package/cjs/services/contractService.js +54 -54
- package/cjs/services/ethereumService.d.ts +7 -7
- package/cjs/services/ethereumService.js +49 -49
- package/cjs/services/ethereumService.test.d.ts +1 -1
- package/cjs/services/ethereumService.test.js +242 -242
- package/cjs/services/strategiesService.d.ts +2 -2
- package/cjs/services/strategiesService.js +898 -898
- package/cjs/services/strategiesService.test.d.ts +1 -1
- package/cjs/services/strategiesService.test.js +110 -110
- package/cjs/services/strategySubService.d.ts +110 -110
- package/cjs/services/strategySubService.js +308 -308
- package/cjs/services/strategySubService.test.d.ts +1 -1
- package/cjs/services/strategySubService.test.js +936 -936
- package/cjs/services/subDataService.d.ts +254 -254
- package/cjs/services/subDataService.js +669 -669
- package/cjs/services/subDataService.test.d.ts +1 -1
- package/cjs/services/subDataService.test.js +1282 -1282
- package/cjs/services/triggerService.d.ts +234 -234
- package/cjs/services/triggerService.js +447 -447
- package/cjs/services/triggerService.test.d.ts +1 -1
- package/cjs/services/triggerService.test.js +926 -926
- package/cjs/services/utils.d.ts +30 -30
- package/cjs/services/utils.js +182 -182
- package/cjs/services/utils.test.d.ts +1 -1
- package/cjs/services/utils.test.js +376 -376
- package/cjs/types/contracts/generated/Erc20.d.ts +53 -53
- package/cjs/types/contracts/generated/Erc20.js +5 -5
- package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
- package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.js +5 -5
- package/cjs/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
- package/cjs/types/contracts/generated/Legacy_AuthCheck.js +5 -5
- package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
- package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +5 -5
- package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
- package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.js +5 -5
- package/cjs/types/contracts/generated/SubStorage.d.ts +114 -114
- package/cjs/types/contracts/generated/SubStorage.js +5 -5
- package/cjs/types/contracts/generated/UniMulticall.d.ts +55 -55
- package/cjs/types/contracts/generated/UniMulticall.js +5 -5
- package/cjs/types/contracts/generated/index.d.ts +7 -7
- package/cjs/types/contracts/generated/index.js +2 -2
- package/cjs/types/contracts/generated/types.d.ts +54 -54
- package/cjs/types/contracts/generated/types.js +2 -2
- package/cjs/types/enums.d.ts +226 -226
- package/cjs/types/enums.js +252 -252
- package/cjs/types/index.d.ts +248 -248
- package/cjs/types/index.js +2 -2
- package/esm/abis/Erc20.json +223 -223
- package/esm/abis/SubStorage.json +21 -21
- package/esm/abis/UniMulticall.json +17 -17
- package/esm/abis/index.d.ts +9 -9
- package/esm/abis/index.js +18 -18
- package/esm/abis/legacy_AaveV2Subscriptions.json +8 -8
- package/esm/abis/legacy_AuthCheck.json +8 -8
- package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -9
- package/esm/abis/legacy_MakerSubscriptions.json +9 -9
- package/esm/automation/private/Automation.d.ts +12 -12
- package/esm/automation/private/Automation.js +39 -39
- package/esm/automation/private/LegacyAutomation.d.ts +25 -25
- package/esm/automation/private/LegacyAutomation.js +112 -112
- package/esm/automation/private/LegacyProtocol.d.ts +22 -22
- package/esm/automation/private/LegacyProtocol.js +38 -38
- package/esm/automation/private/LegacyProtocol.test.d.ts +1 -1
- package/esm/automation/private/LegacyProtocol.test.js +20 -20
- package/esm/automation/private/Protocol.d.ts +22 -22
- package/esm/automation/private/Protocol.js +38 -38
- package/esm/automation/private/Protocol.test.d.ts +1 -1
- package/esm/automation/private/Protocol.test.js +20 -20
- package/esm/automation/private/StrategiesAutomation.d.ts +33 -33
- package/esm/automation/private/StrategiesAutomation.js +183 -183
- package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
- package/esm/automation/private/StrategiesAutomation.test.js +666 -666
- package/esm/automation/public/ArbitrumStrategies.d.ts +5 -5
- package/esm/automation/public/ArbitrumStrategies.js +7 -7
- package/esm/automation/public/BaseStrategies.d.ts +5 -5
- package/esm/automation/public/BaseStrategies.js +7 -7
- package/esm/automation/public/EthereumStrategies.d.ts +5 -5
- package/esm/automation/public/EthereumStrategies.js +7 -7
- package/esm/automation/public/OptimismStrategies.d.ts +5 -5
- package/esm/automation/public/OptimismStrategies.js +7 -7
- package/esm/automation/public/Strategies.test.d.ts +1 -1
- package/esm/automation/public/Strategies.test.js +56 -56
- package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
- package/esm/automation/public/legacy/LegacyAaveAutomation.js +14 -14
- package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
- package/esm/automation/public/legacy/LegacyCompoundAutomation.js +14 -14
- package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
- package/esm/automation/public/legacy/LegacyMakerAutomation.js +14 -14
- package/esm/configuration.d.ts +1 -1
- package/esm/configuration.js +7 -7
- package/esm/constants/index.d.ts +28 -28
- package/esm/constants/index.js +558 -558
- package/esm/index.d.ts +23 -23
- package/esm/index.js +23 -23
- package/esm/services/contractService.d.ts +12 -12
- package/esm/services/contractService.js +45 -45
- package/esm/services/ethereumService.d.ts +7 -7
- package/esm/services/ethereumService.js +41 -41
- package/esm/services/ethereumService.test.d.ts +1 -1
- package/esm/services/ethereumService.test.js +237 -237
- package/esm/services/strategiesService.d.ts +2 -2
- package/esm/services/strategiesService.js +868 -868
- package/esm/services/strategiesService.test.d.ts +1 -1
- package/esm/services/strategiesService.test.js +108 -108
- package/esm/services/strategySubService.d.ts +110 -110
- package/esm/services/strategySubService.js +279 -279
- package/esm/services/strategySubService.test.d.ts +1 -1
- package/esm/services/strategySubService.test.js +908 -908
- package/esm/services/subDataService.d.ts +254 -254
- package/esm/services/subDataService.js +663 -663
- package/esm/services/subDataService.test.d.ts +1 -1
- package/esm/services/subDataService.test.js +1254 -1254
- package/esm/services/triggerService.d.ts +234 -234
- package/esm/services/triggerService.js +418 -418
- package/esm/services/triggerService.test.d.ts +1 -1
- package/esm/services/triggerService.test.js +901 -901
- package/esm/services/utils.d.ts +30 -30
- package/esm/services/utils.js +131 -131
- package/esm/services/utils.test.d.ts +1 -1
- package/esm/services/utils.test.js +348 -348
- package/esm/types/contracts/generated/Erc20.d.ts +53 -53
- package/esm/types/contracts/generated/Erc20.js +4 -4
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +4 -4
- package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
- package/esm/types/contracts/generated/Legacy_AuthCheck.js +4 -4
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +4 -4
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +4 -4
- package/esm/types/contracts/generated/SubStorage.d.ts +114 -114
- package/esm/types/contracts/generated/SubStorage.js +4 -4
- package/esm/types/contracts/generated/UniMulticall.d.ts +55 -55
- package/esm/types/contracts/generated/UniMulticall.js +4 -4
- package/esm/types/contracts/generated/index.d.ts +7 -7
- package/esm/types/contracts/generated/index.js +1 -1
- package/esm/types/contracts/generated/types.d.ts +54 -54
- package/esm/types/contracts/generated/types.js +1 -1
- package/esm/types/enums.d.ts +226 -226
- package/esm/types/enums.js +249 -249
- package/esm/types/index.d.ts +248 -248
- package/esm/types/index.js +1 -1
- package/package.json +60 -60
- package/scripts/generateContractTypes.js +39 -39
- package/src/abis/Erc20.json +222 -222
- package/src/abis/SubStorage.json +21 -21
- package/src/abis/UniMulticall.json +17 -17
- package/src/abis/index.ts +28 -28
- package/src/abis/legacy_AaveV2Subscriptions.json +7 -7
- package/src/abis/legacy_AuthCheck.json +7 -7
- package/src/abis/legacy_CompoundV2Subscriptions.json +8 -8
- package/src/abis/legacy_MakerSubscriptions.json +8 -8
- package/src/automation/private/Automation.ts +44 -44
- package/src/automation/private/LegacyAutomation.ts +135 -135
- package/src/automation/private/LegacyProtocol.test.ts +23 -23
- package/src/automation/private/LegacyProtocol.ts +51 -51
- package/src/automation/private/Protocol.test.ts +23 -23
- package/src/automation/private/Protocol.ts +51 -51
- package/src/automation/private/StrategiesAutomation.test.ts +663 -663
- package/src/automation/private/StrategiesAutomation.ts +254 -254
- package/src/automation/public/ArbitrumStrategies.ts +10 -10
- package/src/automation/public/BaseStrategies.ts +10 -10
- package/src/automation/public/EthereumStrategies.ts +10 -10
- package/src/automation/public/OptimismStrategies.ts +10 -10
- package/src/automation/public/Strategies.test.ts +49 -49
- package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -20
- package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -20
- package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -20
- package/src/configuration.ts +8 -8
- package/src/constants/index.ts +593 -593
- package/src/index.ts +39 -39
- package/src/services/contractService.ts +77 -77
- package/src/services/ethereumService.test.ts +257 -257
- package/src/services/ethereumService.ts +69 -69
- package/src/services/strategiesService.test.ts +105 -105
- package/src/services/strategiesService.ts +1158 -1158
- package/src/services/strategySubService.test.ts +1122 -1122
- package/src/services/strategySubService.ts +634 -634
- package/src/services/subDataService.test.ts +1387 -1387
- package/src/services/subDataService.ts +914 -914
- package/src/services/triggerService.test.ts +1004 -1004
- package/src/services/triggerService.ts +573 -573
- package/src/services/utils.test.ts +430 -430
- package/src/services/utils.ts +162 -162
- package/src/types/enums.ts +246 -246
- package/src/types/index.ts +312 -312
- package/tsconfig.esm.json +8 -8
- package/tsconfig.json +22 -22
- package/.env +0 -4
|
@@ -1,669 +1,669 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
7
|
-
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
|
-
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
9
|
-
const web3_utils_1 = require("web3-utils");
|
|
10
|
-
const tokens_1 = require("@defisaver/tokens");
|
|
11
|
-
const sdk_1 = require("@defisaver/sdk");
|
|
12
|
-
const enums_1 = require("../types/enums");
|
|
13
|
-
const constants_1 = require("../constants");
|
|
14
|
-
const utils_1 = require("./utils");
|
|
15
|
-
exports.makerRepayFromSavingsSubData = {
|
|
16
|
-
encode(vaultId, targetRatioPercentage, chainId, daiAddr, mcdCdpManagerAddr) {
|
|
17
|
-
const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
|
|
18
|
-
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
19
|
-
const _mcdCdpManagerAddr = mcdCdpManagerAddr || (0, sdk_1.otherAddresses)(chainId).McdCdpManager;
|
|
20
|
-
const vaultIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', vaultId.toString());
|
|
21
|
-
const targetRatioWei = (0, utils_1.ratioPercentageToWei)(targetRatioPercentage);
|
|
22
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', targetRatioWei);
|
|
23
|
-
const daiAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _daiAddr);
|
|
24
|
-
const mcdManagerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _mcdCdpManagerAddr);
|
|
25
|
-
return [vaultIdEncoded, targetRatioEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
26
|
-
},
|
|
27
|
-
decode(subData) {
|
|
28
|
-
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
29
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
30
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
31
|
-
const daiAddr = web3_eth_abi_1.default.decodeParameter('address', subData[2]).toString();
|
|
32
|
-
const mcdManagerAddr = web3_eth_abi_1.default.decodeParameter('address', subData[3]).toString();
|
|
33
|
-
return {
|
|
34
|
-
vaultId, targetRatio, daiAddr, mcdManagerAddr,
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
exports.liquityRepayFromSavingsSubData = {
|
|
39
|
-
decode(subData) {
|
|
40
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
41
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
42
|
-
return { targetRatio };
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
exports.makerCloseSubData = {
|
|
46
|
-
encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr) {
|
|
47
|
-
const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
|
|
48
|
-
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
49
|
-
const _mcdCdpManagerAddr = mcdCdpManagerAddr || (0, sdk_1.otherAddresses)(chainId).McdCdpManager;
|
|
50
|
-
const vaultIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', vaultId.toString());
|
|
51
|
-
const daiAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _daiAddr);
|
|
52
|
-
const mcdManagerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _mcdCdpManagerAddr);
|
|
53
|
-
if ((0, utils_1.compareAddresses)(closeToAssetAddr, _daiAddr)) {
|
|
54
|
-
// Close to DAI strategy
|
|
55
|
-
return [vaultIdEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
56
|
-
}
|
|
57
|
-
// Close to collateral strategy
|
|
58
|
-
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', closeToAssetAddr);
|
|
59
|
-
return [vaultIdEncoded, collAddrEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
60
|
-
},
|
|
61
|
-
decode(subData) {
|
|
62
|
-
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
63
|
-
// if closing to collateral, asset addr will be 2nd param out of 4
|
|
64
|
-
// if closing to DAI, will return 2nd param out of 3, which will be DAI addr
|
|
65
|
-
const closeToAssetAddr = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
66
|
-
return {
|
|
67
|
-
vaultId, closeToAssetAddr,
|
|
68
|
-
};
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
exports.makerLeverageManagementSubData = {
|
|
72
|
-
decode: (subData) => {
|
|
73
|
-
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
74
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
75
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
76
|
-
return { vaultId, targetRatio };
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
exports.liquityLeverageManagementSubData = {
|
|
80
|
-
decode: (subData) => {
|
|
81
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
82
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
83
|
-
return { targetRatio };
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
exports.liquityCloseSubData = {
|
|
87
|
-
encode(closeToAssetAddr, chainId = enums_1.ChainId.Ethereum, collAddr, debtAddr) {
|
|
88
|
-
const _collAddr = collAddr || (0, tokens_1.getAssetInfo)('WETH', chainId).address;
|
|
89
|
-
const _debtAddr = debtAddr || (0, tokens_1.getAssetInfo)('LUSD', chainId).address;
|
|
90
|
-
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _collAddr);
|
|
91
|
-
const debtAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _debtAddr);
|
|
92
|
-
// if (compareAddresses(closeToAssetAddr, _debtAddr)) { // Closing to debt strategy was not implemented, but it should be in the future
|
|
93
|
-
// // close to LUSD strategy
|
|
94
|
-
// return [debtAddrEncoded, collAddrEncoded];
|
|
95
|
-
// }
|
|
96
|
-
// close to collateral strategy
|
|
97
|
-
return [collAddrEncoded, debtAddrEncoded];
|
|
98
|
-
},
|
|
99
|
-
decode(subData) {
|
|
100
|
-
const closeToAssetAddr = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
101
|
-
const debtAddr = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
102
|
-
return { closeToAssetAddr, debtAddr };
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
exports.aaveV2LeverageManagementSubData = {
|
|
106
|
-
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
107
|
-
return [
|
|
108
|
-
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
109
|
-
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
110
|
-
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
111
|
-
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
112
|
-
// @ts-ignore // TODO
|
|
113
|
-
boostEnabled,
|
|
114
|
-
];
|
|
115
|
-
},
|
|
116
|
-
decode(subData) {
|
|
117
|
-
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
118
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
119
|
-
return { targetRatio };
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
exports.aaveV3LeverageManagementSubData = {
|
|
123
|
-
decode(subData) {
|
|
124
|
-
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
125
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
126
|
-
return { targetRatio };
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
exports.aaveV3QuotePriceSubData = {
|
|
130
|
-
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
131
|
-
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
132
|
-
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
133
|
-
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
134
|
-
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
135
|
-
const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
|
|
136
|
-
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
137
|
-
},
|
|
138
|
-
decode(subData) {
|
|
139
|
-
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
140
|
-
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
141
|
-
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
142
|
-
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
143
|
-
return {
|
|
144
|
-
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
145
|
-
};
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
exports.compoundV2LeverageManagementSubData = {
|
|
149
|
-
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
150
|
-
return [
|
|
151
|
-
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
152
|
-
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
153
|
-
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
154
|
-
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
155
|
-
// @ts-ignore // TODO
|
|
156
|
-
boostEnabled,
|
|
157
|
-
];
|
|
158
|
-
},
|
|
159
|
-
decode(subData) {
|
|
160
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
161
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
162
|
-
return { targetRatio };
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
exports.compoundV3LeverageManagementSubData = {
|
|
166
|
-
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
167
|
-
return [
|
|
168
|
-
market,
|
|
169
|
-
baseToken,
|
|
170
|
-
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
171
|
-
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
172
|
-
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
173
|
-
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
174
|
-
// @ts-ignore // TODO
|
|
175
|
-
boostEnabled, isEOA,
|
|
176
|
-
];
|
|
177
|
-
},
|
|
178
|
-
decode(subData) {
|
|
179
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
180
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
181
|
-
return { targetRatio };
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
exports.compoundV3L2LeverageManagementSubData = {
|
|
185
|
-
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
186
|
-
let subInput = '0x';
|
|
187
|
-
subInput = subInput.concat(market.slice(2));
|
|
188
|
-
subInput = subInput.concat(baseToken.slice(2));
|
|
189
|
-
subInput = subInput.concat(new decimal_js_1.default(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
190
|
-
.padStart(32, '0'));
|
|
191
|
-
subInput = subInput.concat(new decimal_js_1.default(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
192
|
-
.padStart(32, '0'));
|
|
193
|
-
subInput = subInput.concat(new decimal_js_1.default(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
194
|
-
.padStart(32, '0'));
|
|
195
|
-
subInput = subInput.concat(new decimal_js_1.default(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
196
|
-
.padStart(32, '0'));
|
|
197
|
-
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
198
|
-
return subInput;
|
|
199
|
-
},
|
|
200
|
-
decode(subData) {
|
|
201
|
-
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
202
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
203
|
-
return { targetRatio };
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
exports.morphoAaveV2LeverageManagementSubData = {
|
|
207
|
-
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
208
|
-
return [
|
|
209
|
-
(0, utils_1.ratioPercentageToWei)(triggerRepayRatio),
|
|
210
|
-
(0, utils_1.ratioPercentageToWei)(triggerBoostRatio),
|
|
211
|
-
(0, utils_1.ratioPercentageToWei)(targetBoostRatio),
|
|
212
|
-
(0, utils_1.ratioPercentageToWei)(targetRepayRatio),
|
|
213
|
-
// @ts-ignore
|
|
214
|
-
boostEnabled,
|
|
215
|
-
];
|
|
216
|
-
},
|
|
217
|
-
decode(subData) {
|
|
218
|
-
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint128', subData[1]);
|
|
219
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
220
|
-
return { targetRatio };
|
|
221
|
-
},
|
|
222
|
-
};
|
|
223
|
-
exports.cBondsRebondSubData = {
|
|
224
|
-
encode(bondId) {
|
|
225
|
-
const bondIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', bondId);
|
|
226
|
-
return [bondIdEncoded];
|
|
227
|
-
},
|
|
228
|
-
decode(subData) {
|
|
229
|
-
const bondId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
230
|
-
return { bondId };
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
exports.liquityPaybackUsingChickenBondSubData = {
|
|
234
|
-
/**
|
|
235
|
-
* @param sourceId bondId or subId
|
|
236
|
-
* @param sourceType 0 for bond, 1 for subId
|
|
237
|
-
* @param chainId
|
|
238
|
-
*/
|
|
239
|
-
encode: (sourceId, sourceType, chainId = enums_1.ChainId.Ethereum) => {
|
|
240
|
-
const sourceIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceId);
|
|
241
|
-
const sourceTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceType);
|
|
242
|
-
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('LUSD', chainId).address);
|
|
243
|
-
const bLusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('bLUSD', chainId).address);
|
|
244
|
-
return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
|
|
245
|
-
},
|
|
246
|
-
decode: (subData) => {
|
|
247
|
-
const sourceId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
248
|
-
const sourceType = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
249
|
-
return { sourceId, sourceType };
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
exports.exchangeDcaSubData = {
|
|
253
|
-
encode: (fromToken, toToken, amount, interval) => {
|
|
254
|
-
const sellTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', fromToken);
|
|
255
|
-
const buyTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', toToken);
|
|
256
|
-
const amountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', amount);
|
|
257
|
-
const intervalEncoded = web3_eth_abi_1.default.encodeParameter('uint256', interval);
|
|
258
|
-
return [sellTokenEncoded, buyTokenEncoded, amountEncoded, intervalEncoded];
|
|
259
|
-
},
|
|
260
|
-
decode: (subData, chainId) => {
|
|
261
|
-
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
262
|
-
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
263
|
-
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
264
|
-
const interval = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]).toString();
|
|
265
|
-
return {
|
|
266
|
-
fromToken,
|
|
267
|
-
toToken,
|
|
268
|
-
amount,
|
|
269
|
-
interval,
|
|
270
|
-
};
|
|
271
|
-
},
|
|
272
|
-
};
|
|
273
|
-
exports.exchangeLimitOrderSubData = {
|
|
274
|
-
encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
|
|
275
|
-
return [
|
|
276
|
-
fromToken,
|
|
277
|
-
toToken,
|
|
278
|
-
amount,
|
|
279
|
-
targetPrice,
|
|
280
|
-
new decimal_js_1.default(goodUntil).toString(),
|
|
281
|
-
new decimal_js_1.default(orderType).toString(),
|
|
282
|
-
];
|
|
283
|
-
},
|
|
284
|
-
decode: (subData, chainId) => {
|
|
285
|
-
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
286
|
-
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
287
|
-
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
288
|
-
return { fromToken, toToken, amount };
|
|
289
|
-
},
|
|
290
|
-
};
|
|
291
|
-
exports.sparkLeverageManagementSubData = {
|
|
292
|
-
decode(subData) {
|
|
293
|
-
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
294
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
295
|
-
return { targetRatio };
|
|
296
|
-
},
|
|
297
|
-
};
|
|
298
|
-
exports.sparkQuotePriceSubData = {
|
|
299
|
-
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
300
|
-
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
301
|
-
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
302
|
-
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
303
|
-
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
304
|
-
const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
|
|
305
|
-
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
306
|
-
},
|
|
307
|
-
decode(subData) {
|
|
308
|
-
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
309
|
-
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
310
|
-
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
311
|
-
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
312
|
-
return {
|
|
313
|
-
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
314
|
-
};
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
exports.liquityDsrPaybackSubData = {
|
|
318
|
-
encode: (targetRatio) => {
|
|
319
|
-
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
320
|
-
const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
|
|
321
|
-
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
322
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
323
|
-
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
324
|
-
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
|
|
325
|
-
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, lusdAddressEncoded];
|
|
326
|
-
},
|
|
327
|
-
decode: (subData) => {
|
|
328
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
329
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
330
|
-
return { targetRatio };
|
|
331
|
-
},
|
|
332
|
-
};
|
|
333
|
-
exports.liquityDsrSupplySubData = {
|
|
334
|
-
encode: (targetRatio) => {
|
|
335
|
-
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
336
|
-
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
337
|
-
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
338
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
339
|
-
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
340
|
-
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
341
|
-
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, wethAddressEncoded];
|
|
342
|
-
},
|
|
343
|
-
decode: (subData) => {
|
|
344
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
345
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
346
|
-
return { targetRatio };
|
|
347
|
-
},
|
|
348
|
-
};
|
|
349
|
-
exports.liquityDebtInFrontRepaySubData = {
|
|
350
|
-
encode: (targetRatioIncrease) => {
|
|
351
|
-
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
352
|
-
const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
|
|
353
|
-
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
354
|
-
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
|
|
355
|
-
const targetRatioIncreaseEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatioIncrease));
|
|
356
|
-
const withdrawIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 1); // withdraw - 1
|
|
357
|
-
const paybackIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 0); // payback - 0
|
|
358
|
-
return [wethAddressEncoded, lusdAddressEncoded, targetRatioIncreaseEncoded, withdrawIdEncoded, paybackIdEncoded];
|
|
359
|
-
},
|
|
360
|
-
decode: (subData) => {
|
|
361
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
|
|
362
|
-
const targetRatioIncrease = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
363
|
-
return { targetRatioIncrease };
|
|
364
|
-
},
|
|
365
|
-
};
|
|
366
|
-
exports.crvUSDLeverageManagementSubData = {
|
|
367
|
-
encode: (controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr) => {
|
|
368
|
-
const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
|
|
369
|
-
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
370
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
371
|
-
const collTokenAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collTokenAddr);
|
|
372
|
-
const crvUSDAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', crvUSDAddr);
|
|
373
|
-
return [controllerAddrEncoded, ratioStateEncoded, targetRatioEncoded, collTokenAddrEncoded, crvUSDAddrEncoded];
|
|
374
|
-
},
|
|
375
|
-
decode: (subData) => {
|
|
376
|
-
const controller = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
377
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
|
|
378
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
379
|
-
return { controller, targetRatio };
|
|
380
|
-
},
|
|
381
|
-
};
|
|
382
|
-
exports.crvUSDPaybackSubData = {
|
|
383
|
-
encode: (controllerAddr, addressToPullTokensFrom, positionOwner, paybackAmount, crvUSDAddr) => {
|
|
384
|
-
const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
|
|
385
|
-
const addressToPullTokensFromEncoded = web3_eth_abi_1.default.encodeParameter('address', addressToPullTokensFrom);
|
|
386
|
-
const positionOwnerEncoded = web3_eth_abi_1.default.encodeParameter('address', positionOwner);
|
|
387
|
-
const paybackAmountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, web3_utils_1.toWei)(paybackAmount, 'ether'));
|
|
388
|
-
const crvUSDAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', crvUSDAddr);
|
|
389
|
-
return [
|
|
390
|
-
controllerAddrEncoded,
|
|
391
|
-
addressToPullTokensFromEncoded,
|
|
392
|
-
positionOwnerEncoded,
|
|
393
|
-
paybackAmountEncoded,
|
|
394
|
-
crvUSDAddrEncoded,
|
|
395
|
-
];
|
|
396
|
-
},
|
|
397
|
-
decode: (subData) => {
|
|
398
|
-
const controller = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
399
|
-
const addressToPullTokensFrom = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
400
|
-
const positionOwner = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
401
|
-
const weiPaybackAmount = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
402
|
-
const paybackAmount = (0, web3_utils_1.fromWei)(weiPaybackAmount, 'ether');
|
|
403
|
-
return {
|
|
404
|
-
controller,
|
|
405
|
-
addressToPullTokensFrom,
|
|
406
|
-
positionOwner,
|
|
407
|
-
paybackAmount,
|
|
408
|
-
};
|
|
409
|
-
},
|
|
410
|
-
};
|
|
411
|
-
exports.morphoBlueLeverageManagementSubData = {
|
|
412
|
-
encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
|
|
413
|
-
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
414
|
-
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
415
|
-
const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
|
|
416
|
-
const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
|
|
417
|
-
const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
|
|
418
|
-
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
419
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
420
|
-
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
421
|
-
const isEOAEncoded = web3_eth_abi_1.default.encodeParameter('bool', isEOA);
|
|
422
|
-
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
|
|
423
|
-
},
|
|
424
|
-
decode: (subData) => {
|
|
425
|
-
const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
426
|
-
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
427
|
-
const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
428
|
-
const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
429
|
-
const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
430
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[6]);
|
|
431
|
-
const user = web3_eth_abi_1.default.decodeParameter('address', subData[7]);
|
|
432
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
433
|
-
return {
|
|
434
|
-
loanToken,
|
|
435
|
-
collToken,
|
|
436
|
-
oracle,
|
|
437
|
-
irm,
|
|
438
|
-
lltv,
|
|
439
|
-
user,
|
|
440
|
-
targetRatio,
|
|
441
|
-
};
|
|
442
|
-
},
|
|
443
|
-
};
|
|
444
|
-
exports.aaveV3LeverageManagementOnPriceSubData = {
|
|
445
|
-
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
|
|
446
|
-
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
447
|
-
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
448
|
-
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
449
|
-
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
450
|
-
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
451
|
-
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
452
|
-
const useOnBehalfEncoded = web3_eth_abi_1.default.encodeParameter('bool', false);
|
|
453
|
-
return [
|
|
454
|
-
encodedColl,
|
|
455
|
-
encodedCollId,
|
|
456
|
-
encodedDebt,
|
|
457
|
-
encodedDebtId,
|
|
458
|
-
encodedMarket,
|
|
459
|
-
encodedTargetRatio,
|
|
460
|
-
useOnBehalfEncoded,
|
|
461
|
-
];
|
|
462
|
-
},
|
|
463
|
-
decode(subData) {
|
|
464
|
-
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
465
|
-
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
466
|
-
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
467
|
-
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
468
|
-
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
469
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
470
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
471
|
-
return {
|
|
472
|
-
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
473
|
-
};
|
|
474
|
-
},
|
|
475
|
-
};
|
|
476
|
-
exports.liquityV2LeverageManagementSubData = {
|
|
477
|
-
encode: (market, troveId, collToken, boldToken, ratioState, targetRatio) => {
|
|
478
|
-
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
479
|
-
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
480
|
-
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
481
|
-
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
482
|
-
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
483
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
484
|
-
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
485
|
-
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
486
|
-
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
487
|
-
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
488
|
-
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
489
|
-
return [
|
|
490
|
-
marketEncoded,
|
|
491
|
-
troveIdEncoded,
|
|
492
|
-
collTokenEncoded,
|
|
493
|
-
boldTokenEncoded,
|
|
494
|
-
ratioStateEncoded,
|
|
495
|
-
targetRatioEncoded,
|
|
496
|
-
collActionTypeEncoded,
|
|
497
|
-
debtActionTypeEncoded,
|
|
498
|
-
];
|
|
499
|
-
},
|
|
500
|
-
decode: (subData) => {
|
|
501
|
-
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
502
|
-
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
503
|
-
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
504
|
-
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
505
|
-
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
506
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
507
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
508
|
-
return {
|
|
509
|
-
market, troveId, collToken, boldToken, ratioState, targetRatio,
|
|
510
|
-
};
|
|
511
|
-
},
|
|
512
|
-
};
|
|
513
|
-
exports.liquityV2CloseSubData = {
|
|
514
|
-
encode(market, troveId, collToken, boldToken, closeType) {
|
|
515
|
-
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
516
|
-
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
517
|
-
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
518
|
-
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
519
|
-
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
520
|
-
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
521
|
-
const gasCompensation = new decimal_js_1.default('0.0375').mul(1e18).toString();
|
|
522
|
-
const gasCompensationEncoded = web3_eth_abi_1.default.encodeParameter('uint256', gasCompensation);
|
|
523
|
-
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
524
|
-
return [
|
|
525
|
-
marketEncoded,
|
|
526
|
-
troveIdEncoded,
|
|
527
|
-
collAddrEncoded,
|
|
528
|
-
boldTokenEncoded,
|
|
529
|
-
wethAddressEncoded,
|
|
530
|
-
gasCompensationEncoded,
|
|
531
|
-
closeTypeEncoded,
|
|
532
|
-
];
|
|
533
|
-
},
|
|
534
|
-
decode(subData) {
|
|
535
|
-
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
536
|
-
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
537
|
-
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
538
|
-
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
539
|
-
// skip wethAddress and gasCompensation
|
|
540
|
-
const closeType = web3_eth_abi_1.default.decodeParameter('uint8', subData[6]);
|
|
541
|
-
return {
|
|
542
|
-
market, troveId, collToken, boldToken, closeType,
|
|
543
|
-
};
|
|
544
|
-
},
|
|
545
|
-
};
|
|
546
|
-
exports.liquityV2LeverageManagementOnPriceSubData = {
|
|
547
|
-
encode(market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice) {
|
|
548
|
-
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
549
|
-
const encodedTroveId = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
550
|
-
const encodedCollToken = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
551
|
-
const encodedBoldToken = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
552
|
-
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
553
|
-
const collActionType = isRepayOnPrice ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
554
|
-
const debtActionType = isRepayOnPrice ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
555
|
-
const encodedCollActionType = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
556
|
-
const encodedDebtActionType = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
557
|
-
return [
|
|
558
|
-
encodedMarket,
|
|
559
|
-
encodedTroveId,
|
|
560
|
-
encodedCollToken,
|
|
561
|
-
encodedBoldToken,
|
|
562
|
-
encodedTargetRatio,
|
|
563
|
-
encodedCollActionType,
|
|
564
|
-
encodedDebtActionType,
|
|
565
|
-
];
|
|
566
|
-
},
|
|
567
|
-
decode(subData) {
|
|
568
|
-
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
569
|
-
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
570
|
-
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
571
|
-
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
572
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
573
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
574
|
-
return {
|
|
575
|
-
market, troveId, collToken, boldToken, targetRatio,
|
|
576
|
-
};
|
|
577
|
-
},
|
|
578
|
-
};
|
|
579
|
-
exports.morphoBlueLeverageManagementOnPriceSubData = {
|
|
580
|
-
encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
|
|
581
|
-
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
582
|
-
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
583
|
-
const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
|
|
584
|
-
const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
|
|
585
|
-
const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
|
|
586
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
587
|
-
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
588
|
-
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, targetRatioEncoded, userEncoded];
|
|
589
|
-
},
|
|
590
|
-
decode(subData) {
|
|
591
|
-
const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
592
|
-
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
593
|
-
const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
594
|
-
const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
595
|
-
const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
596
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
597
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
598
|
-
const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
599
|
-
return {
|
|
600
|
-
loanToken,
|
|
601
|
-
collToken,
|
|
602
|
-
oracle,
|
|
603
|
-
irm,
|
|
604
|
-
lltv,
|
|
605
|
-
targetRatio,
|
|
606
|
-
user,
|
|
607
|
-
};
|
|
608
|
-
},
|
|
609
|
-
};
|
|
610
|
-
exports.liquityV2PaybackSubData = {
|
|
611
|
-
encode: (market, troveId, boldToken, targetRatio, ratioState) => {
|
|
612
|
-
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
613
|
-
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
614
|
-
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
615
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
616
|
-
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
617
|
-
return [
|
|
618
|
-
marketEncoded,
|
|
619
|
-
troveIdEncoded,
|
|
620
|
-
boldTokenEncoded,
|
|
621
|
-
targetRatioEncoded,
|
|
622
|
-
ratioStateEncoded,
|
|
623
|
-
];
|
|
624
|
-
},
|
|
625
|
-
decode: (subData) => {
|
|
626
|
-
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
627
|
-
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
628
|
-
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
629
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
630
|
-
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
631
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
632
|
-
return {
|
|
633
|
-
market, troveId, boldToken, ratioState, targetRatio,
|
|
634
|
-
};
|
|
635
|
-
},
|
|
636
|
-
};
|
|
637
|
-
exports.fluidLeverageManagementSubData = {
|
|
638
|
-
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
639
|
-
const nftIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', nftId);
|
|
640
|
-
const vaultEncoded = web3_eth_abi_1.default.encodeParameter('address', vault);
|
|
641
|
-
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
642
|
-
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
643
|
-
const wrapEthEncoded = web3_eth_abi_1.default.encodeParameter('bool', true);
|
|
644
|
-
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
645
|
-
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
646
|
-
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
647
|
-
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
648
|
-
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
649
|
-
return [
|
|
650
|
-
nftIdEncoded,
|
|
651
|
-
vaultEncoded,
|
|
652
|
-
ratioStateEncoded,
|
|
653
|
-
targetRatioEncoded,
|
|
654
|
-
wrapEthEncoded,
|
|
655
|
-
collActionTypeEncoded,
|
|
656
|
-
debtActionTypeEncoded,
|
|
657
|
-
];
|
|
658
|
-
},
|
|
659
|
-
decode: (subData) => {
|
|
660
|
-
const nftId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
661
|
-
const vault = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
662
|
-
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
|
|
663
|
-
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
664
|
-
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
665
|
-
return {
|
|
666
|
-
nftId, vault, ratioState, targetRatio,
|
|
667
|
-
};
|
|
668
|
-
},
|
|
669
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fluidLeverageManagementSubData = exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
|
+
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
9
|
+
const web3_utils_1 = require("web3-utils");
|
|
10
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
11
|
+
const sdk_1 = require("@defisaver/sdk");
|
|
12
|
+
const enums_1 = require("../types/enums");
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
exports.makerRepayFromSavingsSubData = {
|
|
16
|
+
encode(vaultId, targetRatioPercentage, chainId, daiAddr, mcdCdpManagerAddr) {
|
|
17
|
+
const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
|
|
18
|
+
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
19
|
+
const _mcdCdpManagerAddr = mcdCdpManagerAddr || (0, sdk_1.otherAddresses)(chainId).McdCdpManager;
|
|
20
|
+
const vaultIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', vaultId.toString());
|
|
21
|
+
const targetRatioWei = (0, utils_1.ratioPercentageToWei)(targetRatioPercentage);
|
|
22
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', targetRatioWei);
|
|
23
|
+
const daiAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _daiAddr);
|
|
24
|
+
const mcdManagerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _mcdCdpManagerAddr);
|
|
25
|
+
return [vaultIdEncoded, targetRatioEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
26
|
+
},
|
|
27
|
+
decode(subData) {
|
|
28
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
29
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
30
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
31
|
+
const daiAddr = web3_eth_abi_1.default.decodeParameter('address', subData[2]).toString();
|
|
32
|
+
const mcdManagerAddr = web3_eth_abi_1.default.decodeParameter('address', subData[3]).toString();
|
|
33
|
+
return {
|
|
34
|
+
vaultId, targetRatio, daiAddr, mcdManagerAddr,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
exports.liquityRepayFromSavingsSubData = {
|
|
39
|
+
decode(subData) {
|
|
40
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
41
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
42
|
+
return { targetRatio };
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
exports.makerCloseSubData = {
|
|
46
|
+
encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr) {
|
|
47
|
+
const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
|
|
48
|
+
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
49
|
+
const _mcdCdpManagerAddr = mcdCdpManagerAddr || (0, sdk_1.otherAddresses)(chainId).McdCdpManager;
|
|
50
|
+
const vaultIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', vaultId.toString());
|
|
51
|
+
const daiAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _daiAddr);
|
|
52
|
+
const mcdManagerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _mcdCdpManagerAddr);
|
|
53
|
+
if ((0, utils_1.compareAddresses)(closeToAssetAddr, _daiAddr)) {
|
|
54
|
+
// Close to DAI strategy
|
|
55
|
+
return [vaultIdEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
56
|
+
}
|
|
57
|
+
// Close to collateral strategy
|
|
58
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', closeToAssetAddr);
|
|
59
|
+
return [vaultIdEncoded, collAddrEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
60
|
+
},
|
|
61
|
+
decode(subData) {
|
|
62
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
63
|
+
// if closing to collateral, asset addr will be 2nd param out of 4
|
|
64
|
+
// if closing to DAI, will return 2nd param out of 3, which will be DAI addr
|
|
65
|
+
const closeToAssetAddr = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
66
|
+
return {
|
|
67
|
+
vaultId, closeToAssetAddr,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
exports.makerLeverageManagementSubData = {
|
|
72
|
+
decode: (subData) => {
|
|
73
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
74
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
75
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
76
|
+
return { vaultId, targetRatio };
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
exports.liquityLeverageManagementSubData = {
|
|
80
|
+
decode: (subData) => {
|
|
81
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
82
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
83
|
+
return { targetRatio };
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
exports.liquityCloseSubData = {
|
|
87
|
+
encode(closeToAssetAddr, chainId = enums_1.ChainId.Ethereum, collAddr, debtAddr) {
|
|
88
|
+
const _collAddr = collAddr || (0, tokens_1.getAssetInfo)('WETH', chainId).address;
|
|
89
|
+
const _debtAddr = debtAddr || (0, tokens_1.getAssetInfo)('LUSD', chainId).address;
|
|
90
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _collAddr);
|
|
91
|
+
const debtAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _debtAddr);
|
|
92
|
+
// if (compareAddresses(closeToAssetAddr, _debtAddr)) { // Closing to debt strategy was not implemented, but it should be in the future
|
|
93
|
+
// // close to LUSD strategy
|
|
94
|
+
// return [debtAddrEncoded, collAddrEncoded];
|
|
95
|
+
// }
|
|
96
|
+
// close to collateral strategy
|
|
97
|
+
return [collAddrEncoded, debtAddrEncoded];
|
|
98
|
+
},
|
|
99
|
+
decode(subData) {
|
|
100
|
+
const closeToAssetAddr = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
101
|
+
const debtAddr = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
102
|
+
return { closeToAssetAddr, debtAddr };
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
exports.aaveV2LeverageManagementSubData = {
|
|
106
|
+
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
107
|
+
return [
|
|
108
|
+
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
109
|
+
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
110
|
+
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
111
|
+
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
112
|
+
// @ts-ignore // TODO
|
|
113
|
+
boostEnabled,
|
|
114
|
+
];
|
|
115
|
+
},
|
|
116
|
+
decode(subData) {
|
|
117
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
118
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
119
|
+
return { targetRatio };
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
exports.aaveV3LeverageManagementSubData = {
|
|
123
|
+
decode(subData) {
|
|
124
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
125
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
126
|
+
return { targetRatio };
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
exports.aaveV3QuotePriceSubData = {
|
|
130
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
131
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
132
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
133
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
134
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
135
|
+
const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
|
|
136
|
+
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
137
|
+
},
|
|
138
|
+
decode(subData) {
|
|
139
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
140
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
141
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
142
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
143
|
+
return {
|
|
144
|
+
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
exports.compoundV2LeverageManagementSubData = {
|
|
149
|
+
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
150
|
+
return [
|
|
151
|
+
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
152
|
+
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
153
|
+
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
154
|
+
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
155
|
+
// @ts-ignore // TODO
|
|
156
|
+
boostEnabled,
|
|
157
|
+
];
|
|
158
|
+
},
|
|
159
|
+
decode(subData) {
|
|
160
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
161
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
162
|
+
return { targetRatio };
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
exports.compoundV3LeverageManagementSubData = {
|
|
166
|
+
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
167
|
+
return [
|
|
168
|
+
market,
|
|
169
|
+
baseToken,
|
|
170
|
+
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
171
|
+
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
172
|
+
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
173
|
+
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
174
|
+
// @ts-ignore // TODO
|
|
175
|
+
boostEnabled, isEOA,
|
|
176
|
+
];
|
|
177
|
+
},
|
|
178
|
+
decode(subData) {
|
|
179
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
180
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
181
|
+
return { targetRatio };
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
exports.compoundV3L2LeverageManagementSubData = {
|
|
185
|
+
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
186
|
+
let subInput = '0x';
|
|
187
|
+
subInput = subInput.concat(market.slice(2));
|
|
188
|
+
subInput = subInput.concat(baseToken.slice(2));
|
|
189
|
+
subInput = subInput.concat(new decimal_js_1.default(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
190
|
+
.padStart(32, '0'));
|
|
191
|
+
subInput = subInput.concat(new decimal_js_1.default(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
192
|
+
.padStart(32, '0'));
|
|
193
|
+
subInput = subInput.concat(new decimal_js_1.default(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
194
|
+
.padStart(32, '0'));
|
|
195
|
+
subInput = subInput.concat(new decimal_js_1.default(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
196
|
+
.padStart(32, '0'));
|
|
197
|
+
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
198
|
+
return subInput;
|
|
199
|
+
},
|
|
200
|
+
decode(subData) {
|
|
201
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
202
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
203
|
+
return { targetRatio };
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
exports.morphoAaveV2LeverageManagementSubData = {
|
|
207
|
+
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
208
|
+
return [
|
|
209
|
+
(0, utils_1.ratioPercentageToWei)(triggerRepayRatio),
|
|
210
|
+
(0, utils_1.ratioPercentageToWei)(triggerBoostRatio),
|
|
211
|
+
(0, utils_1.ratioPercentageToWei)(targetBoostRatio),
|
|
212
|
+
(0, utils_1.ratioPercentageToWei)(targetRepayRatio),
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
boostEnabled,
|
|
215
|
+
];
|
|
216
|
+
},
|
|
217
|
+
decode(subData) {
|
|
218
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint128', subData[1]);
|
|
219
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
220
|
+
return { targetRatio };
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
exports.cBondsRebondSubData = {
|
|
224
|
+
encode(bondId) {
|
|
225
|
+
const bondIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', bondId);
|
|
226
|
+
return [bondIdEncoded];
|
|
227
|
+
},
|
|
228
|
+
decode(subData) {
|
|
229
|
+
const bondId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
230
|
+
return { bondId };
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
exports.liquityPaybackUsingChickenBondSubData = {
|
|
234
|
+
/**
|
|
235
|
+
* @param sourceId bondId or subId
|
|
236
|
+
* @param sourceType 0 for bond, 1 for subId
|
|
237
|
+
* @param chainId
|
|
238
|
+
*/
|
|
239
|
+
encode: (sourceId, sourceType, chainId = enums_1.ChainId.Ethereum) => {
|
|
240
|
+
const sourceIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceId);
|
|
241
|
+
const sourceTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceType);
|
|
242
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('LUSD', chainId).address);
|
|
243
|
+
const bLusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('bLUSD', chainId).address);
|
|
244
|
+
return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
|
|
245
|
+
},
|
|
246
|
+
decode: (subData) => {
|
|
247
|
+
const sourceId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
248
|
+
const sourceType = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
249
|
+
return { sourceId, sourceType };
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
exports.exchangeDcaSubData = {
|
|
253
|
+
encode: (fromToken, toToken, amount, interval) => {
|
|
254
|
+
const sellTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', fromToken);
|
|
255
|
+
const buyTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', toToken);
|
|
256
|
+
const amountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', amount);
|
|
257
|
+
const intervalEncoded = web3_eth_abi_1.default.encodeParameter('uint256', interval);
|
|
258
|
+
return [sellTokenEncoded, buyTokenEncoded, amountEncoded, intervalEncoded];
|
|
259
|
+
},
|
|
260
|
+
decode: (subData, chainId) => {
|
|
261
|
+
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
262
|
+
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
263
|
+
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
264
|
+
const interval = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]).toString();
|
|
265
|
+
return {
|
|
266
|
+
fromToken,
|
|
267
|
+
toToken,
|
|
268
|
+
amount,
|
|
269
|
+
interval,
|
|
270
|
+
};
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
exports.exchangeLimitOrderSubData = {
|
|
274
|
+
encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
|
|
275
|
+
return [
|
|
276
|
+
fromToken,
|
|
277
|
+
toToken,
|
|
278
|
+
amount,
|
|
279
|
+
targetPrice,
|
|
280
|
+
new decimal_js_1.default(goodUntil).toString(),
|
|
281
|
+
new decimal_js_1.default(orderType).toString(),
|
|
282
|
+
];
|
|
283
|
+
},
|
|
284
|
+
decode: (subData, chainId) => {
|
|
285
|
+
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
286
|
+
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
287
|
+
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
288
|
+
return { fromToken, toToken, amount };
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
exports.sparkLeverageManagementSubData = {
|
|
292
|
+
decode(subData) {
|
|
293
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
294
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
295
|
+
return { targetRatio };
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
exports.sparkQuotePriceSubData = {
|
|
299
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
300
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
301
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
302
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
303
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
304
|
+
const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
|
|
305
|
+
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
306
|
+
},
|
|
307
|
+
decode(subData) {
|
|
308
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
309
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
310
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
311
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
312
|
+
return {
|
|
313
|
+
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
exports.liquityDsrPaybackSubData = {
|
|
318
|
+
encode: (targetRatio) => {
|
|
319
|
+
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
320
|
+
const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
|
|
321
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
322
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
323
|
+
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
324
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
|
|
325
|
+
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, lusdAddressEncoded];
|
|
326
|
+
},
|
|
327
|
+
decode: (subData) => {
|
|
328
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
329
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
330
|
+
return { targetRatio };
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
exports.liquityDsrSupplySubData = {
|
|
334
|
+
encode: (targetRatio) => {
|
|
335
|
+
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
336
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
337
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
338
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
339
|
+
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
340
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
341
|
+
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, wethAddressEncoded];
|
|
342
|
+
},
|
|
343
|
+
decode: (subData) => {
|
|
344
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
345
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
346
|
+
return { targetRatio };
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
exports.liquityDebtInFrontRepaySubData = {
|
|
350
|
+
encode: (targetRatioIncrease) => {
|
|
351
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
352
|
+
const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
|
|
353
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
354
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
|
|
355
|
+
const targetRatioIncreaseEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatioIncrease));
|
|
356
|
+
const withdrawIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 1); // withdraw - 1
|
|
357
|
+
const paybackIdEncoded = web3_eth_abi_1.default.encodeParameter('uint8', 0); // payback - 0
|
|
358
|
+
return [wethAddressEncoded, lusdAddressEncoded, targetRatioIncreaseEncoded, withdrawIdEncoded, paybackIdEncoded];
|
|
359
|
+
},
|
|
360
|
+
decode: (subData) => {
|
|
361
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
|
|
362
|
+
const targetRatioIncrease = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
363
|
+
return { targetRatioIncrease };
|
|
364
|
+
},
|
|
365
|
+
};
|
|
366
|
+
exports.crvUSDLeverageManagementSubData = {
|
|
367
|
+
encode: (controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr) => {
|
|
368
|
+
const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
|
|
369
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
370
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
371
|
+
const collTokenAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collTokenAddr);
|
|
372
|
+
const crvUSDAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', crvUSDAddr);
|
|
373
|
+
return [controllerAddrEncoded, ratioStateEncoded, targetRatioEncoded, collTokenAddrEncoded, crvUSDAddrEncoded];
|
|
374
|
+
},
|
|
375
|
+
decode: (subData) => {
|
|
376
|
+
const controller = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
377
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
|
|
378
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
379
|
+
return { controller, targetRatio };
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
exports.crvUSDPaybackSubData = {
|
|
383
|
+
encode: (controllerAddr, addressToPullTokensFrom, positionOwner, paybackAmount, crvUSDAddr) => {
|
|
384
|
+
const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
|
|
385
|
+
const addressToPullTokensFromEncoded = web3_eth_abi_1.default.encodeParameter('address', addressToPullTokensFrom);
|
|
386
|
+
const positionOwnerEncoded = web3_eth_abi_1.default.encodeParameter('address', positionOwner);
|
|
387
|
+
const paybackAmountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, web3_utils_1.toWei)(paybackAmount, 'ether'));
|
|
388
|
+
const crvUSDAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', crvUSDAddr);
|
|
389
|
+
return [
|
|
390
|
+
controllerAddrEncoded,
|
|
391
|
+
addressToPullTokensFromEncoded,
|
|
392
|
+
positionOwnerEncoded,
|
|
393
|
+
paybackAmountEncoded,
|
|
394
|
+
crvUSDAddrEncoded,
|
|
395
|
+
];
|
|
396
|
+
},
|
|
397
|
+
decode: (subData) => {
|
|
398
|
+
const controller = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
399
|
+
const addressToPullTokensFrom = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
400
|
+
const positionOwner = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
401
|
+
const weiPaybackAmount = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
402
|
+
const paybackAmount = (0, web3_utils_1.fromWei)(weiPaybackAmount, 'ether');
|
|
403
|
+
return {
|
|
404
|
+
controller,
|
|
405
|
+
addressToPullTokensFrom,
|
|
406
|
+
positionOwner,
|
|
407
|
+
paybackAmount,
|
|
408
|
+
};
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
exports.morphoBlueLeverageManagementSubData = {
|
|
412
|
+
encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
|
|
413
|
+
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
414
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
415
|
+
const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
|
|
416
|
+
const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
|
|
417
|
+
const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
|
|
418
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
419
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
420
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
421
|
+
const isEOAEncoded = web3_eth_abi_1.default.encodeParameter('bool', isEOA);
|
|
422
|
+
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
|
|
423
|
+
},
|
|
424
|
+
decode: (subData) => {
|
|
425
|
+
const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
426
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
427
|
+
const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
428
|
+
const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
429
|
+
const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
430
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[6]);
|
|
431
|
+
const user = web3_eth_abi_1.default.decodeParameter('address', subData[7]);
|
|
432
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
433
|
+
return {
|
|
434
|
+
loanToken,
|
|
435
|
+
collToken,
|
|
436
|
+
oracle,
|
|
437
|
+
irm,
|
|
438
|
+
lltv,
|
|
439
|
+
user,
|
|
440
|
+
targetRatio,
|
|
441
|
+
};
|
|
442
|
+
},
|
|
443
|
+
};
|
|
444
|
+
exports.aaveV3LeverageManagementOnPriceSubData = {
|
|
445
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
|
|
446
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
447
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
448
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
449
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
450
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
|
|
451
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
452
|
+
const useOnBehalfEncoded = web3_eth_abi_1.default.encodeParameter('bool', false);
|
|
453
|
+
return [
|
|
454
|
+
encodedColl,
|
|
455
|
+
encodedCollId,
|
|
456
|
+
encodedDebt,
|
|
457
|
+
encodedDebtId,
|
|
458
|
+
encodedMarket,
|
|
459
|
+
encodedTargetRatio,
|
|
460
|
+
useOnBehalfEncoded,
|
|
461
|
+
];
|
|
462
|
+
},
|
|
463
|
+
decode(subData) {
|
|
464
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
465
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
466
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
467
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
468
|
+
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
469
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
470
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
471
|
+
return {
|
|
472
|
+
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
473
|
+
};
|
|
474
|
+
},
|
|
475
|
+
};
|
|
476
|
+
exports.liquityV2LeverageManagementSubData = {
|
|
477
|
+
encode: (market, troveId, collToken, boldToken, ratioState, targetRatio) => {
|
|
478
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
479
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
480
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
481
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
482
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
483
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
484
|
+
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
485
|
+
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
486
|
+
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
487
|
+
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
488
|
+
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
489
|
+
return [
|
|
490
|
+
marketEncoded,
|
|
491
|
+
troveIdEncoded,
|
|
492
|
+
collTokenEncoded,
|
|
493
|
+
boldTokenEncoded,
|
|
494
|
+
ratioStateEncoded,
|
|
495
|
+
targetRatioEncoded,
|
|
496
|
+
collActionTypeEncoded,
|
|
497
|
+
debtActionTypeEncoded,
|
|
498
|
+
];
|
|
499
|
+
},
|
|
500
|
+
decode: (subData) => {
|
|
501
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
502
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
503
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
504
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
505
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
506
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
507
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
508
|
+
return {
|
|
509
|
+
market, troveId, collToken, boldToken, ratioState, targetRatio,
|
|
510
|
+
};
|
|
511
|
+
},
|
|
512
|
+
};
|
|
513
|
+
exports.liquityV2CloseSubData = {
|
|
514
|
+
encode(market, troveId, collToken, boldToken, closeType) {
|
|
515
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
516
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
517
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
518
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
519
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
520
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
521
|
+
const gasCompensation = new decimal_js_1.default('0.0375').mul(1e18).toString();
|
|
522
|
+
const gasCompensationEncoded = web3_eth_abi_1.default.encodeParameter('uint256', gasCompensation);
|
|
523
|
+
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
524
|
+
return [
|
|
525
|
+
marketEncoded,
|
|
526
|
+
troveIdEncoded,
|
|
527
|
+
collAddrEncoded,
|
|
528
|
+
boldTokenEncoded,
|
|
529
|
+
wethAddressEncoded,
|
|
530
|
+
gasCompensationEncoded,
|
|
531
|
+
closeTypeEncoded,
|
|
532
|
+
];
|
|
533
|
+
},
|
|
534
|
+
decode(subData) {
|
|
535
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
536
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
537
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
538
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
539
|
+
// skip wethAddress and gasCompensation
|
|
540
|
+
const closeType = web3_eth_abi_1.default.decodeParameter('uint8', subData[6]);
|
|
541
|
+
return {
|
|
542
|
+
market, troveId, collToken, boldToken, closeType,
|
|
543
|
+
};
|
|
544
|
+
},
|
|
545
|
+
};
|
|
546
|
+
exports.liquityV2LeverageManagementOnPriceSubData = {
|
|
547
|
+
encode(market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice) {
|
|
548
|
+
const encodedMarket = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
549
|
+
const encodedTroveId = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
550
|
+
const encodedCollToken = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
551
|
+
const encodedBoldToken = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
552
|
+
const encodedTargetRatio = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
553
|
+
const collActionType = isRepayOnPrice ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
554
|
+
const debtActionType = isRepayOnPrice ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
555
|
+
const encodedCollActionType = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
556
|
+
const encodedDebtActionType = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
557
|
+
return [
|
|
558
|
+
encodedMarket,
|
|
559
|
+
encodedTroveId,
|
|
560
|
+
encodedCollToken,
|
|
561
|
+
encodedBoldToken,
|
|
562
|
+
encodedTargetRatio,
|
|
563
|
+
encodedCollActionType,
|
|
564
|
+
encodedDebtActionType,
|
|
565
|
+
];
|
|
566
|
+
},
|
|
567
|
+
decode(subData) {
|
|
568
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
569
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
570
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
571
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
572
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
573
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
574
|
+
return {
|
|
575
|
+
market, troveId, collToken, boldToken, targetRatio,
|
|
576
|
+
};
|
|
577
|
+
},
|
|
578
|
+
};
|
|
579
|
+
exports.morphoBlueLeverageManagementOnPriceSubData = {
|
|
580
|
+
encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
|
|
581
|
+
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
582
|
+
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
583
|
+
const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
|
|
584
|
+
const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
|
|
585
|
+
const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
|
|
586
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
587
|
+
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
588
|
+
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, targetRatioEncoded, userEncoded];
|
|
589
|
+
},
|
|
590
|
+
decode(subData) {
|
|
591
|
+
const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
592
|
+
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
593
|
+
const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
594
|
+
const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
595
|
+
const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
596
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
597
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
598
|
+
const user = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
599
|
+
return {
|
|
600
|
+
loanToken,
|
|
601
|
+
collToken,
|
|
602
|
+
oracle,
|
|
603
|
+
irm,
|
|
604
|
+
lltv,
|
|
605
|
+
targetRatio,
|
|
606
|
+
user,
|
|
607
|
+
};
|
|
608
|
+
},
|
|
609
|
+
};
|
|
610
|
+
exports.liquityV2PaybackSubData = {
|
|
611
|
+
encode: (market, troveId, boldToken, targetRatio, ratioState) => {
|
|
612
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
613
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
614
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
615
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
616
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
617
|
+
return [
|
|
618
|
+
marketEncoded,
|
|
619
|
+
troveIdEncoded,
|
|
620
|
+
boldTokenEncoded,
|
|
621
|
+
targetRatioEncoded,
|
|
622
|
+
ratioStateEncoded,
|
|
623
|
+
];
|
|
624
|
+
},
|
|
625
|
+
decode: (subData) => {
|
|
626
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
627
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
628
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
629
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
630
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
631
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
632
|
+
return {
|
|
633
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
634
|
+
};
|
|
635
|
+
},
|
|
636
|
+
};
|
|
637
|
+
exports.fluidLeverageManagementSubData = {
|
|
638
|
+
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
639
|
+
const nftIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', nftId);
|
|
640
|
+
const vaultEncoded = web3_eth_abi_1.default.encodeParameter('address', vault);
|
|
641
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
642
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
643
|
+
const wrapEthEncoded = web3_eth_abi_1.default.encodeParameter('bool', true);
|
|
644
|
+
const isRepay = ratioState === enums_1.RatioState.UNDER;
|
|
645
|
+
const collActionType = isRepay ? enums_1.CollActionType.WITHDRAW : enums_1.CollActionType.SUPPLY;
|
|
646
|
+
const debtActionType = isRepay ? enums_1.DebtActionType.PAYBACK : enums_1.DebtActionType.BORROW;
|
|
647
|
+
const collActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', collActionType);
|
|
648
|
+
const debtActionTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', debtActionType);
|
|
649
|
+
return [
|
|
650
|
+
nftIdEncoded,
|
|
651
|
+
vaultEncoded,
|
|
652
|
+
ratioStateEncoded,
|
|
653
|
+
targetRatioEncoded,
|
|
654
|
+
wrapEthEncoded,
|
|
655
|
+
collActionTypeEncoded,
|
|
656
|
+
debtActionTypeEncoded,
|
|
657
|
+
];
|
|
658
|
+
},
|
|
659
|
+
decode: (subData) => {
|
|
660
|
+
const nftId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
661
|
+
const vault = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
662
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[2]);
|
|
663
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
664
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
665
|
+
return {
|
|
666
|
+
nftId, vault, ratioState, targetRatio,
|
|
667
|
+
};
|
|
668
|
+
},
|
|
669
|
+
};
|