@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,367 +1,367 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
|
|
30
|
-
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
|
-
const tokens_1 = require("@defisaver/tokens");
|
|
32
|
-
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
33
|
-
const web3Utils = __importStar(require("web3-utils"));
|
|
34
|
-
const utils_1 = require("./utils");
|
|
35
|
-
exports.chainlinkPriceTrigger = {
|
|
36
|
-
encode(tokenAddr, price, state) {
|
|
37
|
-
const _price = new decimal_js_1.default(price).mul(1e8).floor().toString();
|
|
38
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint8'], [tokenAddr, _price, state])];
|
|
39
|
-
},
|
|
40
|
-
decode(triggerData) {
|
|
41
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
42
|
-
return { tokenAddr: decodedData[0], price: new decimal_js_1.default(decodedData[1]).div(1e8).toString(), state: +decodedData[2] };
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
exports.trailingStopTrigger = {
|
|
46
|
-
encode(tokenAddr, percentage, roundId) {
|
|
47
|
-
const _percentage = new decimal_js_1.default(percentage).mul(1e8).toString();
|
|
48
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint80'], [tokenAddr, _percentage, roundId])];
|
|
49
|
-
},
|
|
50
|
-
decode(triggerData) {
|
|
51
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint80'], triggerData[0]);
|
|
52
|
-
const triggerPercentage = new decimal_js_1.default(decodedData[1]).div(1e8).toNumber();
|
|
53
|
-
return { tokenAddr: decodedData[0], triggerPercentage, roundId: decodedData[2] };
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
exports.makerRatioTrigger = {
|
|
57
|
-
encode(vaultId, ratioPercentage, ratioState) {
|
|
58
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
59
|
-
return [web3_eth_abi_1.default.encodeParameters(['uint256', 'uint256', 'uint8'], [vaultId, ratioWei, ratioState])];
|
|
60
|
-
},
|
|
61
|
-
decode(triggerData) {
|
|
62
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
63
|
-
return { vaultId: +decodedData[0], ratio: (0, utils_1.weiToRatioPercentage)(decodedData[1]), ratioState: +decodedData[2] };
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
exports.aaveV3RatioTrigger = {
|
|
67
|
-
encode(owner, market, ratioPercentage, ratioState) {
|
|
68
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
69
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
70
|
-
},
|
|
71
|
-
decode(triggerData) {
|
|
72
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
73
|
-
return {
|
|
74
|
-
owner: decodedData[0],
|
|
75
|
-
market: decodedData[1],
|
|
76
|
-
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
77
|
-
ratioState: Number(decodedData[3]),
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
exports.morphoAaveV2RatioTrigger = {
|
|
82
|
-
encode(owner, ratioPercentage, ratioState) {
|
|
83
|
-
const ratioWei = new decimal_js_1.default(ratioPercentage).mul(1e16).toString();
|
|
84
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint128', 'uint8'], [owner, ratioWei, ratioState])];
|
|
85
|
-
},
|
|
86
|
-
decode(triggerData) {
|
|
87
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint128', 'uint8'], triggerData[0]);
|
|
88
|
-
return {
|
|
89
|
-
owner: decodedData[0],
|
|
90
|
-
ratio: new decimal_js_1.default(decodedData[1]).div(1e16).toNumber(),
|
|
91
|
-
ratioState: Number(decodedData[2]),
|
|
92
|
-
};
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
exports.aaveV3QuotePriceTrigger = {
|
|
96
|
-
encode(baseTokenAddress, quoteTokenAddress, price, ratioState) {
|
|
97
|
-
// Price is always in 8 decimals
|
|
98
|
-
const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
|
|
99
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
|
|
100
|
-
},
|
|
101
|
-
decode(triggerData) {
|
|
102
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
103
|
-
// Price is always in 8 decimals
|
|
104
|
-
const price = new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 8)).toDP(8).toString();
|
|
105
|
-
return {
|
|
106
|
-
price,
|
|
107
|
-
baseTokenAddress: decodedData[0],
|
|
108
|
-
quoteTokenAddress: decodedData[1],
|
|
109
|
-
ratioState: +decodedData[3],
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = {
|
|
114
|
-
encode(baseTokenAddress, quoteTokenAddress, price, ratioState, maximumGasPriceInGwei) {
|
|
115
|
-
// Price is always in 8 decimals
|
|
116
|
-
const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
|
|
117
|
-
const _maximumGasPrice = maximumGasPriceInGwei
|
|
118
|
-
? new decimal_js_1.default(maximumGasPriceInGwei.toString()).mul(Math.pow(10, 9)).floor().toString() // We convert it to WEI
|
|
119
|
-
: tokens_1.MAXUINT; // If undefined than set to MAXUINT
|
|
120
|
-
return [
|
|
121
|
-
web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState]),
|
|
122
|
-
web3_eth_abi_1.default.encodeParameters(['uint256'], [_maximumGasPrice]),
|
|
123
|
-
];
|
|
124
|
-
},
|
|
125
|
-
decode(triggerData) {
|
|
126
|
-
const decodedPriceTrigger = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
127
|
-
const decodedMaximumGasPriceTrigger = web3_eth_abi_1.default.decodeParameters(['uint256'], triggerData[1]);
|
|
128
|
-
// Price is always in 8 decimals
|
|
129
|
-
const price = new decimal_js_1.default(decodedPriceTrigger[2]).div(Math.pow(10, 8)).toDP(8).toString();
|
|
130
|
-
const maximumGasPrice = new decimal_js_1.default(decodedMaximumGasPriceTrigger[0]).div(Math.pow(10, 9)).toDP(9).toString();
|
|
131
|
-
return {
|
|
132
|
-
baseTokenAddress: decodedPriceTrigger[0],
|
|
133
|
-
quoteTokenAddress: decodedPriceTrigger[1],
|
|
134
|
-
price,
|
|
135
|
-
ratioState: +decodedPriceTrigger[3],
|
|
136
|
-
maximumGasPrice,
|
|
137
|
-
};
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
exports.compoundV2RatioTrigger = {
|
|
141
|
-
encode(owner, ratioPercentage, ratioState) {
|
|
142
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
143
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint8'], [owner, ratioWei, ratioState])];
|
|
144
|
-
},
|
|
145
|
-
decode(triggerData) {
|
|
146
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
147
|
-
return {
|
|
148
|
-
owner: decodedData[0],
|
|
149
|
-
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[1]),
|
|
150
|
-
ratioState: +decodedData[2],
|
|
151
|
-
};
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
exports.liquityRatioTrigger = {
|
|
155
|
-
encode(owner, ratioPercentage, ratioState) {
|
|
156
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
157
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint8'], [owner, ratioWei, ratioState])];
|
|
158
|
-
},
|
|
159
|
-
decode(triggerData) {
|
|
160
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
161
|
-
return {
|
|
162
|
-
owner: decodedData[0],
|
|
163
|
-
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[1]),
|
|
164
|
-
ratioState: +decodedData[2],
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
exports.liquityDebtInFrontTrigger = {
|
|
169
|
-
encode(owner, debtInFrontMin) {
|
|
170
|
-
const debtInFrontMinWei = web3Utils.toWei(new decimal_js_1.default(debtInFrontMin).toString(), 'ether');
|
|
171
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256'], [owner, debtInFrontMinWei])];
|
|
172
|
-
},
|
|
173
|
-
decode(triggerData) {
|
|
174
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256'], triggerData[0]);
|
|
175
|
-
return {
|
|
176
|
-
owner: decodedData[0],
|
|
177
|
-
debtInFrontMin: new decimal_js_1.default(decodedData[1]).div(Math.pow(10, 18)).toString(),
|
|
178
|
-
};
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger;
|
|
182
|
-
exports.aaveV2RatioTrigger = {
|
|
183
|
-
encode(owner, market, ratioPercentage, ratioState) {
|
|
184
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
185
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
186
|
-
},
|
|
187
|
-
decode(triggerData) {
|
|
188
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
189
|
-
return {
|
|
190
|
-
owner: decodedData[0],
|
|
191
|
-
market: decodedData[1],
|
|
192
|
-
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
193
|
-
ratioState: +decodedData[3],
|
|
194
|
-
};
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
exports.cBondsRebondTrigger = {
|
|
198
|
-
encode(bondId) {
|
|
199
|
-
return [web3_eth_abi_1.default.encodeParameters(['uint256'], [bondId])];
|
|
200
|
-
},
|
|
201
|
-
decode(triggerData) {
|
|
202
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['uint256'], triggerData[0]);
|
|
203
|
-
return { bondId: decodedData[0] };
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
exports.compoundV3RatioTrigger = {
|
|
207
|
-
encode(owner, market, ratioPercentage, ratioState) {
|
|
208
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
209
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
210
|
-
},
|
|
211
|
-
decode(triggerData) {
|
|
212
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
213
|
-
return {
|
|
214
|
-
owner: decodedData[0],
|
|
215
|
-
market: decodedData[1],
|
|
216
|
-
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
217
|
-
ratioState: +decodedData[3],
|
|
218
|
-
};
|
|
219
|
-
},
|
|
220
|
-
};
|
|
221
|
-
exports.exchangeTimestampTrigger = {
|
|
222
|
-
encode(timestamp, interval) {
|
|
223
|
-
const timestampWei = new decimal_js_1.default(timestamp).toString();
|
|
224
|
-
const intervalWei = new decimal_js_1.default(interval).toString();
|
|
225
|
-
return [web3_eth_abi_1.default.encodeParameters(['uint256', 'uint256'], [timestampWei, intervalWei])];
|
|
226
|
-
},
|
|
227
|
-
decode(triggerData) {
|
|
228
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['uint256', 'uint256'], triggerData[0]);
|
|
229
|
-
return {
|
|
230
|
-
timestamp: Number(decodedData[0]),
|
|
231
|
-
interval: Number(decodedData[1]),
|
|
232
|
-
};
|
|
233
|
-
},
|
|
234
|
-
};
|
|
235
|
-
exports.exchangeOffchainPriceTrigger = {
|
|
236
|
-
encode(targetPrice, goodUntil, orderType, fromTokenDecimals, toTokenDecimals) {
|
|
237
|
-
const decimals = new decimal_js_1.default(toTokenDecimals).plus(18).minus(fromTokenDecimals).toNumber();
|
|
238
|
-
const price = new decimal_js_1.default(targetPrice.toString()).mul(Math.pow(10, decimals)).floor().toString();
|
|
239
|
-
return [web3_eth_abi_1.default.encodeParameters(['uint256', 'uint256', 'uint8'], [price, goodUntil, orderType])];
|
|
240
|
-
},
|
|
241
|
-
decode(triggerData, fromTokenDecimals, toTokenDecimals) {
|
|
242
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
243
|
-
const decimals = new decimal_js_1.default(toTokenDecimals).plus(18).minus(fromTokenDecimals).toString();
|
|
244
|
-
const price = new decimal_js_1.default(decodedData[0]).div(new decimal_js_1.default(10).pow(decimals)).toDP(fromTokenDecimals).toString();
|
|
245
|
-
return {
|
|
246
|
-
targetPrice: price,
|
|
247
|
-
goodUntil: +decodedData[1],
|
|
248
|
-
orderType: +decodedData[2],
|
|
249
|
-
};
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
exports.sparkRatioTrigger = {
|
|
253
|
-
encode(owner, market, ratioPercentage, ratioState) {
|
|
254
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
255
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
256
|
-
},
|
|
257
|
-
decode(triggerData) {
|
|
258
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
259
|
-
return {
|
|
260
|
-
owner: decodedData[0],
|
|
261
|
-
market: decodedData[1],
|
|
262
|
-
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
263
|
-
ratioState: Number(decodedData[3]),
|
|
264
|
-
};
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
exports.sparkQuotePriceTrigger = {
|
|
268
|
-
encode(baseTokenAddress, quoteTokenAddress, price, ratioState) {
|
|
269
|
-
// Price is always in 8 decimals
|
|
270
|
-
const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
|
|
271
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
|
|
272
|
-
},
|
|
273
|
-
decode(triggerData) {
|
|
274
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
275
|
-
// Price is always in 8 decimals
|
|
276
|
-
const price = new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 8)).toDP(8).toString();
|
|
277
|
-
return {
|
|
278
|
-
price,
|
|
279
|
-
baseTokenAddress: decodedData[0],
|
|
280
|
-
quoteTokenAddress: decodedData[1],
|
|
281
|
-
ratioState: +decodedData[3],
|
|
282
|
-
};
|
|
283
|
-
},
|
|
284
|
-
};
|
|
285
|
-
exports.curveUsdBorrowRateTrigger = {
|
|
286
|
-
encode(market, targetRate, rateState) {
|
|
287
|
-
// the form is x = (e**(rate*365*86400))-1 where x*100 is number in %
|
|
288
|
-
// we reverse engineer that so we can calculate rate = ln(y/100 + 1) / 365*86400 where y is input in %
|
|
289
|
-
const rate = new decimal_js_1.default(new decimal_js_1.default(new decimal_js_1.default(targetRate).div(100)).plus(1)).ln().div(365).div(86400)
|
|
290
|
-
.toString();
|
|
291
|
-
const rateWei = new decimal_js_1.default(rate).mul(Math.pow(10, 18)).floor().toString(); // 18 decimals
|
|
292
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint8'], [market, rateWei, rateState])];
|
|
293
|
-
},
|
|
294
|
-
decode(triggerData) {
|
|
295
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
296
|
-
const rateEth = web3Utils.fromWei(decodedData[1], 'ether');
|
|
297
|
-
// the form is x = (e**(rate*365*86400))-1 where x*100 is number in %
|
|
298
|
-
const exponentRate = new decimal_js_1.default(rateEth).mul(365).mul(86400);
|
|
299
|
-
const targetRate = new decimal_js_1.default(new decimal_js_1.default(2.718281828459).pow(exponentRate).minus(1)).mul(100)
|
|
300
|
-
.toString();
|
|
301
|
-
return {
|
|
302
|
-
market: decodedData[0],
|
|
303
|
-
targetRate,
|
|
304
|
-
rateState: +decodedData[2],
|
|
305
|
-
};
|
|
306
|
-
},
|
|
307
|
-
};
|
|
308
|
-
exports.curveUsdSoftLiquidationTrigger = {
|
|
309
|
-
encode(market, owner, percentage) {
|
|
310
|
-
// 100% = 1e18 => 1% = 1e16
|
|
311
|
-
const _percentage = new decimal_js_1.default(percentage).mul(Math.pow(10, 16)).floor().toString();
|
|
312
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256'], [market, owner, _percentage])];
|
|
313
|
-
},
|
|
314
|
-
decode(triggerData) {
|
|
315
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256'], triggerData[0]);
|
|
316
|
-
return {
|
|
317
|
-
market: decodedData[0],
|
|
318
|
-
owner: decodedData[1],
|
|
319
|
-
percentage: new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 16)).toString(),
|
|
320
|
-
};
|
|
321
|
-
},
|
|
322
|
-
};
|
|
323
|
-
exports.crvUSDRatioTrigger = {
|
|
324
|
-
encode(owner, controller, ratioPercentage, ratioState) {
|
|
325
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
326
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, controller, ratioWei, ratioState])];
|
|
327
|
-
},
|
|
328
|
-
decode(triggerData) {
|
|
329
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
330
|
-
return {
|
|
331
|
-
owner: decodedData[0],
|
|
332
|
-
controller: decodedData[1],
|
|
333
|
-
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
334
|
-
ratioState: Number(decodedData[3]),
|
|
335
|
-
};
|
|
336
|
-
},
|
|
337
|
-
};
|
|
338
|
-
exports.crvUsdHealthRatioTrigger = {
|
|
339
|
-
encode(owner, controller, ratioPercentage) {
|
|
340
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
341
|
-
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256'], [owner, controller, ratioWei])];
|
|
342
|
-
},
|
|
343
|
-
decode(triggerData) {
|
|
344
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256'], triggerData[0]);
|
|
345
|
-
return {
|
|
346
|
-
owner: decodedData[0],
|
|
347
|
-
controller: decodedData[1],
|
|
348
|
-
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
349
|
-
};
|
|
350
|
-
},
|
|
351
|
-
};
|
|
352
|
-
exports.morphoBlueRatioTrigger = {
|
|
353
|
-
encode(marketId, // bytes32
|
|
354
|
-
owner, ratioPercentage, ratioState) {
|
|
355
|
-
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
356
|
-
return [web3_eth_abi_1.default.encodeParameters(['bytes32', 'address', 'uint256', 'uint8'], [marketId, owner, ratioWei, ratioState])];
|
|
357
|
-
},
|
|
358
|
-
decode(triggerData) {
|
|
359
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['bytes32', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
360
|
-
return {
|
|
361
|
-
marketId: decodedData[0],
|
|
362
|
-
owner: decodedData[1],
|
|
363
|
-
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
364
|
-
ratioState: Number(decodedData[3]),
|
|
365
|
-
};
|
|
366
|
-
},
|
|
367
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
|
|
30
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
32
|
+
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
33
|
+
const web3Utils = __importStar(require("web3-utils"));
|
|
34
|
+
const utils_1 = require("./utils");
|
|
35
|
+
exports.chainlinkPriceTrigger = {
|
|
36
|
+
encode(tokenAddr, price, state) {
|
|
37
|
+
const _price = new decimal_js_1.default(price).mul(1e8).floor().toString();
|
|
38
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint8'], [tokenAddr, _price, state])];
|
|
39
|
+
},
|
|
40
|
+
decode(triggerData) {
|
|
41
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
42
|
+
return { tokenAddr: decodedData[0], price: new decimal_js_1.default(decodedData[1]).div(1e8).toString(), state: +decodedData[2] };
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
exports.trailingStopTrigger = {
|
|
46
|
+
encode(tokenAddr, percentage, roundId) {
|
|
47
|
+
const _percentage = new decimal_js_1.default(percentage).mul(1e8).toString();
|
|
48
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint80'], [tokenAddr, _percentage, roundId])];
|
|
49
|
+
},
|
|
50
|
+
decode(triggerData) {
|
|
51
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint80'], triggerData[0]);
|
|
52
|
+
const triggerPercentage = new decimal_js_1.default(decodedData[1]).div(1e8).toNumber();
|
|
53
|
+
return { tokenAddr: decodedData[0], triggerPercentage, roundId: decodedData[2] };
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
exports.makerRatioTrigger = {
|
|
57
|
+
encode(vaultId, ratioPercentage, ratioState) {
|
|
58
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
59
|
+
return [web3_eth_abi_1.default.encodeParameters(['uint256', 'uint256', 'uint8'], [vaultId, ratioWei, ratioState])];
|
|
60
|
+
},
|
|
61
|
+
decode(triggerData) {
|
|
62
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
63
|
+
return { vaultId: +decodedData[0], ratio: (0, utils_1.weiToRatioPercentage)(decodedData[1]), ratioState: +decodedData[2] };
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
exports.aaveV3RatioTrigger = {
|
|
67
|
+
encode(owner, market, ratioPercentage, ratioState) {
|
|
68
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
69
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
70
|
+
},
|
|
71
|
+
decode(triggerData) {
|
|
72
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
73
|
+
return {
|
|
74
|
+
owner: decodedData[0],
|
|
75
|
+
market: decodedData[1],
|
|
76
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
77
|
+
ratioState: Number(decodedData[3]),
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
exports.morphoAaveV2RatioTrigger = {
|
|
82
|
+
encode(owner, ratioPercentage, ratioState) {
|
|
83
|
+
const ratioWei = new decimal_js_1.default(ratioPercentage).mul(1e16).toString();
|
|
84
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint128', 'uint8'], [owner, ratioWei, ratioState])];
|
|
85
|
+
},
|
|
86
|
+
decode(triggerData) {
|
|
87
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint128', 'uint8'], triggerData[0]);
|
|
88
|
+
return {
|
|
89
|
+
owner: decodedData[0],
|
|
90
|
+
ratio: new decimal_js_1.default(decodedData[1]).div(1e16).toNumber(),
|
|
91
|
+
ratioState: Number(decodedData[2]),
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
exports.aaveV3QuotePriceTrigger = {
|
|
96
|
+
encode(baseTokenAddress, quoteTokenAddress, price, ratioState) {
|
|
97
|
+
// Price is always in 8 decimals
|
|
98
|
+
const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
|
|
99
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
|
|
100
|
+
},
|
|
101
|
+
decode(triggerData) {
|
|
102
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
103
|
+
// Price is always in 8 decimals
|
|
104
|
+
const price = new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 8)).toDP(8).toString();
|
|
105
|
+
return {
|
|
106
|
+
price,
|
|
107
|
+
baseTokenAddress: decodedData[0],
|
|
108
|
+
quoteTokenAddress: decodedData[1],
|
|
109
|
+
ratioState: +decodedData[3],
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = {
|
|
114
|
+
encode(baseTokenAddress, quoteTokenAddress, price, ratioState, maximumGasPriceInGwei) {
|
|
115
|
+
// Price is always in 8 decimals
|
|
116
|
+
const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
|
|
117
|
+
const _maximumGasPrice = maximumGasPriceInGwei
|
|
118
|
+
? new decimal_js_1.default(maximumGasPriceInGwei.toString()).mul(Math.pow(10, 9)).floor().toString() // We convert it to WEI
|
|
119
|
+
: tokens_1.MAXUINT; // If undefined than set to MAXUINT
|
|
120
|
+
return [
|
|
121
|
+
web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState]),
|
|
122
|
+
web3_eth_abi_1.default.encodeParameters(['uint256'], [_maximumGasPrice]),
|
|
123
|
+
];
|
|
124
|
+
},
|
|
125
|
+
decode(triggerData) {
|
|
126
|
+
const decodedPriceTrigger = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
127
|
+
const decodedMaximumGasPriceTrigger = web3_eth_abi_1.default.decodeParameters(['uint256'], triggerData[1]);
|
|
128
|
+
// Price is always in 8 decimals
|
|
129
|
+
const price = new decimal_js_1.default(decodedPriceTrigger[2]).div(Math.pow(10, 8)).toDP(8).toString();
|
|
130
|
+
const maximumGasPrice = new decimal_js_1.default(decodedMaximumGasPriceTrigger[0]).div(Math.pow(10, 9)).toDP(9).toString();
|
|
131
|
+
return {
|
|
132
|
+
baseTokenAddress: decodedPriceTrigger[0],
|
|
133
|
+
quoteTokenAddress: decodedPriceTrigger[1],
|
|
134
|
+
price,
|
|
135
|
+
ratioState: +decodedPriceTrigger[3],
|
|
136
|
+
maximumGasPrice,
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
exports.compoundV2RatioTrigger = {
|
|
141
|
+
encode(owner, ratioPercentage, ratioState) {
|
|
142
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
143
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint8'], [owner, ratioWei, ratioState])];
|
|
144
|
+
},
|
|
145
|
+
decode(triggerData) {
|
|
146
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
147
|
+
return {
|
|
148
|
+
owner: decodedData[0],
|
|
149
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[1]),
|
|
150
|
+
ratioState: +decodedData[2],
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
exports.liquityRatioTrigger = {
|
|
155
|
+
encode(owner, ratioPercentage, ratioState) {
|
|
156
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
157
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint8'], [owner, ratioWei, ratioState])];
|
|
158
|
+
},
|
|
159
|
+
decode(triggerData) {
|
|
160
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
161
|
+
return {
|
|
162
|
+
owner: decodedData[0],
|
|
163
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[1]),
|
|
164
|
+
ratioState: +decodedData[2],
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
exports.liquityDebtInFrontTrigger = {
|
|
169
|
+
encode(owner, debtInFrontMin) {
|
|
170
|
+
const debtInFrontMinWei = web3Utils.toWei(new decimal_js_1.default(debtInFrontMin).toString(), 'ether');
|
|
171
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256'], [owner, debtInFrontMinWei])];
|
|
172
|
+
},
|
|
173
|
+
decode(triggerData) {
|
|
174
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256'], triggerData[0]);
|
|
175
|
+
return {
|
|
176
|
+
owner: decodedData[0],
|
|
177
|
+
debtInFrontMin: new decimal_js_1.default(decodedData[1]).div(Math.pow(10, 18)).toString(),
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger;
|
|
182
|
+
exports.aaveV2RatioTrigger = {
|
|
183
|
+
encode(owner, market, ratioPercentage, ratioState) {
|
|
184
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
185
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
186
|
+
},
|
|
187
|
+
decode(triggerData) {
|
|
188
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
189
|
+
return {
|
|
190
|
+
owner: decodedData[0],
|
|
191
|
+
market: decodedData[1],
|
|
192
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
193
|
+
ratioState: +decodedData[3],
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
exports.cBondsRebondTrigger = {
|
|
198
|
+
encode(bondId) {
|
|
199
|
+
return [web3_eth_abi_1.default.encodeParameters(['uint256'], [bondId])];
|
|
200
|
+
},
|
|
201
|
+
decode(triggerData) {
|
|
202
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['uint256'], triggerData[0]);
|
|
203
|
+
return { bondId: decodedData[0] };
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
exports.compoundV3RatioTrigger = {
|
|
207
|
+
encode(owner, market, ratioPercentage, ratioState) {
|
|
208
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
209
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
210
|
+
},
|
|
211
|
+
decode(triggerData) {
|
|
212
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
213
|
+
return {
|
|
214
|
+
owner: decodedData[0],
|
|
215
|
+
market: decodedData[1],
|
|
216
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
217
|
+
ratioState: +decodedData[3],
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
exports.exchangeTimestampTrigger = {
|
|
222
|
+
encode(timestamp, interval) {
|
|
223
|
+
const timestampWei = new decimal_js_1.default(timestamp).toString();
|
|
224
|
+
const intervalWei = new decimal_js_1.default(interval).toString();
|
|
225
|
+
return [web3_eth_abi_1.default.encodeParameters(['uint256', 'uint256'], [timestampWei, intervalWei])];
|
|
226
|
+
},
|
|
227
|
+
decode(triggerData) {
|
|
228
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['uint256', 'uint256'], triggerData[0]);
|
|
229
|
+
return {
|
|
230
|
+
timestamp: Number(decodedData[0]),
|
|
231
|
+
interval: Number(decodedData[1]),
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
exports.exchangeOffchainPriceTrigger = {
|
|
236
|
+
encode(targetPrice, goodUntil, orderType, fromTokenDecimals, toTokenDecimals) {
|
|
237
|
+
const decimals = new decimal_js_1.default(toTokenDecimals).plus(18).minus(fromTokenDecimals).toNumber();
|
|
238
|
+
const price = new decimal_js_1.default(targetPrice.toString()).mul(Math.pow(10, decimals)).floor().toString();
|
|
239
|
+
return [web3_eth_abi_1.default.encodeParameters(['uint256', 'uint256', 'uint8'], [price, goodUntil, orderType])];
|
|
240
|
+
},
|
|
241
|
+
decode(triggerData, fromTokenDecimals, toTokenDecimals) {
|
|
242
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
243
|
+
const decimals = new decimal_js_1.default(toTokenDecimals).plus(18).minus(fromTokenDecimals).toString();
|
|
244
|
+
const price = new decimal_js_1.default(decodedData[0]).div(new decimal_js_1.default(10).pow(decimals)).toDP(fromTokenDecimals).toString();
|
|
245
|
+
return {
|
|
246
|
+
targetPrice: price,
|
|
247
|
+
goodUntil: +decodedData[1],
|
|
248
|
+
orderType: +decodedData[2],
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
exports.sparkRatioTrigger = {
|
|
253
|
+
encode(owner, market, ratioPercentage, ratioState) {
|
|
254
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
255
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
256
|
+
},
|
|
257
|
+
decode(triggerData) {
|
|
258
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
259
|
+
return {
|
|
260
|
+
owner: decodedData[0],
|
|
261
|
+
market: decodedData[1],
|
|
262
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
263
|
+
ratioState: Number(decodedData[3]),
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
exports.sparkQuotePriceTrigger = {
|
|
268
|
+
encode(baseTokenAddress, quoteTokenAddress, price, ratioState) {
|
|
269
|
+
// Price is always in 8 decimals
|
|
270
|
+
const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
|
|
271
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
|
|
272
|
+
},
|
|
273
|
+
decode(triggerData) {
|
|
274
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
275
|
+
// Price is always in 8 decimals
|
|
276
|
+
const price = new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 8)).toDP(8).toString();
|
|
277
|
+
return {
|
|
278
|
+
price,
|
|
279
|
+
baseTokenAddress: decodedData[0],
|
|
280
|
+
quoteTokenAddress: decodedData[1],
|
|
281
|
+
ratioState: +decodedData[3],
|
|
282
|
+
};
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
exports.curveUsdBorrowRateTrigger = {
|
|
286
|
+
encode(market, targetRate, rateState) {
|
|
287
|
+
// the form is x = (e**(rate*365*86400))-1 where x*100 is number in %
|
|
288
|
+
// we reverse engineer that so we can calculate rate = ln(y/100 + 1) / 365*86400 where y is input in %
|
|
289
|
+
const rate = new decimal_js_1.default(new decimal_js_1.default(new decimal_js_1.default(targetRate).div(100)).plus(1)).ln().div(365).div(86400)
|
|
290
|
+
.toString();
|
|
291
|
+
const rateWei = new decimal_js_1.default(rate).mul(Math.pow(10, 18)).floor().toString(); // 18 decimals
|
|
292
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint8'], [market, rateWei, rateState])];
|
|
293
|
+
},
|
|
294
|
+
decode(triggerData) {
|
|
295
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
296
|
+
const rateEth = web3Utils.fromWei(decodedData[1], 'ether');
|
|
297
|
+
// the form is x = (e**(rate*365*86400))-1 where x*100 is number in %
|
|
298
|
+
const exponentRate = new decimal_js_1.default(rateEth).mul(365).mul(86400);
|
|
299
|
+
const targetRate = new decimal_js_1.default(new decimal_js_1.default(2.718281828459).pow(exponentRate).minus(1)).mul(100)
|
|
300
|
+
.toString();
|
|
301
|
+
return {
|
|
302
|
+
market: decodedData[0],
|
|
303
|
+
targetRate,
|
|
304
|
+
rateState: +decodedData[2],
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
exports.curveUsdSoftLiquidationTrigger = {
|
|
309
|
+
encode(market, owner, percentage) {
|
|
310
|
+
// 100% = 1e18 => 1% = 1e16
|
|
311
|
+
const _percentage = new decimal_js_1.default(percentage).mul(Math.pow(10, 16)).floor().toString();
|
|
312
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256'], [market, owner, _percentage])];
|
|
313
|
+
},
|
|
314
|
+
decode(triggerData) {
|
|
315
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256'], triggerData[0]);
|
|
316
|
+
return {
|
|
317
|
+
market: decodedData[0],
|
|
318
|
+
owner: decodedData[1],
|
|
319
|
+
percentage: new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 16)).toString(),
|
|
320
|
+
};
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
exports.crvUSDRatioTrigger = {
|
|
324
|
+
encode(owner, controller, ratioPercentage, ratioState) {
|
|
325
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
326
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, controller, ratioWei, ratioState])];
|
|
327
|
+
},
|
|
328
|
+
decode(triggerData) {
|
|
329
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
330
|
+
return {
|
|
331
|
+
owner: decodedData[0],
|
|
332
|
+
controller: decodedData[1],
|
|
333
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
334
|
+
ratioState: Number(decodedData[3]),
|
|
335
|
+
};
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
exports.crvUsdHealthRatioTrigger = {
|
|
339
|
+
encode(owner, controller, ratioPercentage) {
|
|
340
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
341
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256'], [owner, controller, ratioWei])];
|
|
342
|
+
},
|
|
343
|
+
decode(triggerData) {
|
|
344
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256'], triggerData[0]);
|
|
345
|
+
return {
|
|
346
|
+
owner: decodedData[0],
|
|
347
|
+
controller: decodedData[1],
|
|
348
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
349
|
+
};
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
exports.morphoBlueRatioTrigger = {
|
|
353
|
+
encode(marketId, // bytes32
|
|
354
|
+
owner, ratioPercentage, ratioState) {
|
|
355
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
356
|
+
return [web3_eth_abi_1.default.encodeParameters(['bytes32', 'address', 'uint256', 'uint8'], [marketId, owner, ratioWei, ratioState])];
|
|
357
|
+
},
|
|
358
|
+
decode(triggerData) {
|
|
359
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['bytes32', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
360
|
+
return {
|
|
361
|
+
marketId: decodedData[0],
|
|
362
|
+
owner: decodedData[1],
|
|
363
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
364
|
+
ratioState: Number(decodedData[3]),
|
|
365
|
+
};
|
|
366
|
+
},
|
|
367
|
+
};
|