@defisaver/automation-sdk 3.1.3 → 3.2.0
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 +5 -0
- 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 +190 -181
- 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 -0
- package/cjs/automation/public/Strategies.test.js +61 -0
- 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 +494 -489
- 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 +724 -723
- package/cjs/services/strategiesService.test.d.ts +1 -1
- package/cjs/services/strategiesService.test.js +110 -110
- package/cjs/services/strategySubService.d.ts +100 -100
- package/cjs/services/strategySubService.js +267 -267
- package/cjs/services/strategySubService.test.d.ts +1 -1
- package/cjs/services/strategySubService.test.js +936 -936
- package/cjs/services/subDataService.d.ts +192 -192
- package/cjs/services/subDataService.js +475 -475
- package/cjs/services/subDataService.test.d.ts +1 -1
- package/cjs/services/subDataService.test.js +1282 -1282
- package/cjs/services/triggerService.d.ts +191 -191
- package/cjs/services/triggerService.js +367 -367
- package/cjs/services/triggerService.test.d.ts +1 -1
- package/cjs/services/triggerService.test.js +926 -926
- package/cjs/services/utils.d.ts +25 -25
- package/cjs/services/utils.js +131 -131
- 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 +110 -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 +186 -184
- package/cjs/types/enums.js +208 -206
- package/cjs/types/index.d.ts +224 -224
- 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 +184 -175
- 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 -0
- package/esm/automation/public/Strategies.test.js +56 -0
- 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 +488 -483
- 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 +697 -696
- package/esm/services/strategiesService.test.d.ts +1 -1
- package/esm/services/strategiesService.test.js +108 -108
- package/esm/services/strategySubService.d.ts +100 -100
- package/esm/services/strategySubService.js +238 -238
- package/esm/services/strategySubService.test.d.ts +1 -1
- package/esm/services/strategySubService.test.js +908 -908
- package/esm/services/subDataService.d.ts +192 -192
- package/esm/services/subDataService.js +469 -469
- package/esm/services/subDataService.test.d.ts +1 -1
- package/esm/services/subDataService.test.js +1254 -1254
- package/esm/services/triggerService.d.ts +191 -191
- package/esm/services/triggerService.js +338 -338
- package/esm/services/triggerService.test.d.ts +1 -1
- package/esm/services/triggerService.test.js +901 -901
- package/esm/services/utils.d.ts +25 -25
- package/esm/services/utils.js +82 -82
- 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 +110 -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 +186 -184
- package/esm/types/enums.js +205 -203
- package/esm/types/index.d.ts +224 -224
- package/esm/types/index.js +1 -1
- package/package.json +62 -61
- 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 -242
- 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 -0
- 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 +523 -507
- 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 +935 -934
- package/src/services/strategySubService.test.ts +1122 -1122
- package/src/services/strategySubService.ts +524 -524
- package/src/services/subDataService.test.ts +1387 -1387
- package/src/services/subDataService.ts +645 -645
- package/src/services/triggerService.test.ts +1004 -1004
- package/src/services/triggerService.ts +449 -449
- package/src/services/utils.test.ts +430 -430
- package/src/services/utils.ts +103 -103
- package/src/types/enums.ts +202 -200
- package/src/types/index.ts +279 -279
- package/tsconfig.esm.json +8 -8
- package/tsconfig.json +22 -22
- package/umd/index.js +0 -34103
|
@@ -1,475 +1,475 @@
|
|
|
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.
|
|
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.
|
|
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
|
-
};
|
|
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.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
|
+
};
|