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