@defisaver/automation-sdk 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -0
- package/esm/abis/index.js +27 -15
- package/esm/automation/private/Automation.js +9 -6
- package/esm/automation/private/LegacyAutomation.d.ts +5 -5
- package/esm/automation/private/LegacyAutomation.js +30 -23
- package/esm/automation/private/LegacyProtocol.js +4 -1
- package/esm/automation/private/Protocol.js +4 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -2
- package/esm/automation/private/StrategiesAutomation.js +27 -21
- package/esm/automation/public/ArbitrumStrategies.js +10 -4
- package/esm/automation/public/EthereumStrategies.js +10 -4
- package/esm/automation/public/OptimismStrategies.js +10 -4
- package/esm/automation/public/legacy/LegacyAaveAutomation.js +13 -7
- package/esm/automation/public/legacy/LegacyCompoundAutomation.js +13 -7
- package/esm/automation/public/legacy/LegacyMakerAutomation.js +13 -7
- package/esm/configuration.js +8 -5
- package/esm/constants/index.js +281 -265
- package/esm/index.js +57 -17
- package/esm/services/contractService.js +22 -14
- package/esm/services/ethereumService.js +18 -10
- package/esm/services/strategiesService.js +144 -100
- package/esm/services/strategySubService.d.ts +2 -0
- package/esm/services/strategySubService.js +100 -55
- package/esm/services/subDataService.d.ts +12 -0
- package/esm/services/subDataService.js +165 -127
- package/esm/services/triggerService.d.ts +8 -8
- package/esm/services/triggerService.js +125 -95
- package/esm/services/utils.js +82 -33
- package/esm/services/utils.test.d.ts +1 -0
- package/esm/services/utils.test.js +362 -0
- package/esm/types/contracts/generated/Erc20.js +2 -1
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +2 -1
- package/esm/types/contracts/generated/Legacy_AuthCheck.js +2 -1
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +2 -1
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +2 -1
- package/esm/types/contracts/generated/SubStorage.js +2 -1
- package/esm/types/contracts/generated/UniMulticall.js +2 -1
- package/esm/types/contracts/generated/index.js +2 -1
- package/esm/types/contracts/generated/types.js +2 -1
- package/esm/types/enums.d.ts +9 -1
- package/esm/types/enums.js +24 -12
- package/esm/types/index.js +2 -1
- package/package.json +12 -8
- package/src/automation/private/LegacyAutomation.ts +11 -10
- package/src/automation/private/StrategiesAutomation.ts +5 -6
- package/src/configuration.ts +0 -3
- package/src/constants/index.ts +10 -0
- package/src/index.ts +0 -1
- package/src/services/ethereumService.ts +6 -6
- package/src/services/strategiesService.ts +24 -0
- package/src/services/strategySubService.ts +30 -0
- package/src/services/subDataService.ts +104 -67
- package/src/services/triggerService.ts +86 -85
- package/src/services/utils.test.ts +414 -0
- package/src/services/utils.ts +6 -7
- package/src/types/enums.ts +9 -0
- package/tsconfig.json +1 -1
- package/umd/index.js +7142 -4138
- package/src/types/typings/process.d.ts +0 -9
- package/yarn-error.log +0 -7233
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
|
+
import AbiCoder from 'web3-eth-abi';
|
|
3
|
+
import * as web3Utils from 'web3-utils';
|
|
2
4
|
|
|
3
5
|
import type {
|
|
4
6
|
EthereumAddress, TriggerData,
|
|
5
7
|
} from '../types';
|
|
6
|
-
import type { RatioState } from '../types/enums';
|
|
8
|
+
import type { RatioState, OrderType } from '../types/enums';
|
|
7
9
|
|
|
8
|
-
import { ratioPercentageToWei } from './utils';
|
|
9
|
-
|
|
10
|
-
const { mockedWeb3 } = process;
|
|
10
|
+
import { ratioPercentageToWei, weiToRatioPercentage } from './utils';
|
|
11
11
|
|
|
12
12
|
export const chainlinkPriceTrigger = {
|
|
13
13
|
encode(tokenAddr: EthereumAddress, price: string, state: RatioState) {
|
|
14
14
|
const _price = new Dec(price).mul(1e8).floor().toString();
|
|
15
|
-
return [
|
|
15
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint8'], [tokenAddr, _price, state])];
|
|
16
16
|
},
|
|
17
17
|
decode(triggerData: TriggerData): { price: string, state: RatioState, tokenAddr: EthereumAddress } {
|
|
18
|
-
const decodedData =
|
|
19
|
-
return { tokenAddr: decodedData[0], price: new Dec(decodedData[1]).div(1e8).toString(), state: +decodedData[2] };
|
|
18
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
19
|
+
return { tokenAddr: decodedData[0] as EthereumAddress, price: new Dec(decodedData[1] as string).div(1e8).toString(), state: +decodedData[2]! };
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export const trailingStopTrigger = {
|
|
24
24
|
encode(tokenAddr: EthereumAddress, percentage: number, roundId: number) {
|
|
25
25
|
const _percentage = new Dec(percentage).mul(1e8).toString();
|
|
26
|
-
return [
|
|
26
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint80'], [tokenAddr, _percentage, roundId])];
|
|
27
27
|
},
|
|
28
28
|
decode(triggerData: TriggerData):{ triggerPercentage: number, tokenAddr: EthereumAddress, roundId: string } {
|
|
29
|
-
const decodedData =
|
|
30
|
-
const triggerPercentage = new Dec(decodedData[1]).div(1e8).toNumber();
|
|
31
|
-
return { tokenAddr: decodedData[0], triggerPercentage, roundId: decodedData[2] };
|
|
29
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint80'], triggerData[0]);
|
|
30
|
+
const triggerPercentage = new Dec(decodedData[1] as string).div(1e8).toNumber();
|
|
31
|
+
return { tokenAddr: decodedData[0] as EthereumAddress, triggerPercentage, roundId: decodedData[2] as string };
|
|
32
32
|
},
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export const makerRatioTrigger = {
|
|
36
36
|
encode(vaultId: number, ratioPercentage: number, ratioState: RatioState) {
|
|
37
37
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
38
|
-
return [
|
|
38
|
+
return [AbiCoder.encodeParameters(['uint256', 'uint256', 'uint8'], [vaultId, ratioWei, ratioState])];
|
|
39
39
|
},
|
|
40
40
|
decode(triggerData: TriggerData): { vaultId: number, ratioState: number, ratio: number } {
|
|
41
|
-
const decodedData =
|
|
42
|
-
return { vaultId: +decodedData[0]
|
|
41
|
+
const decodedData = AbiCoder.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
42
|
+
return { vaultId: +decodedData[0]!, ratio: weiToRatioPercentage(decodedData[1] as string), ratioState: +decodedData[2]! };
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
export const aaveV3RatioTrigger = {
|
|
47
47
|
encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
|
|
48
48
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
49
|
-
return [
|
|
49
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
50
50
|
},
|
|
51
51
|
decode(triggerData: TriggerData) {
|
|
52
|
-
const decodedData =
|
|
52
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
53
53
|
return {
|
|
54
54
|
owner: decodedData[0],
|
|
55
55
|
market: decodedData[1],
|
|
56
|
-
ratio:
|
|
56
|
+
ratio: weiToRatioPercentage(decodedData[2] as string),
|
|
57
57
|
ratioState: Number(decodedData[3]),
|
|
58
58
|
};
|
|
59
59
|
},
|
|
@@ -62,13 +62,13 @@ export const aaveV3RatioTrigger = {
|
|
|
62
62
|
export const morphoAaveV2RatioTrigger = {
|
|
63
63
|
encode(owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
|
|
64
64
|
const ratioWei = new Dec(ratioPercentage).mul(1e16).toString();
|
|
65
|
-
return [
|
|
65
|
+
return [AbiCoder.encodeParameters(['address', 'uint128', 'uint8'], [owner, ratioWei, ratioState])];
|
|
66
66
|
},
|
|
67
67
|
decode(triggerData: TriggerData) {
|
|
68
|
-
const decodedData =
|
|
68
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint128', 'uint8'], triggerData[0]);
|
|
69
69
|
return {
|
|
70
70
|
owner: decodedData[0],
|
|
71
|
-
ratio: new Dec(decodedData[1]).div(1e16).toNumber(),
|
|
71
|
+
ratio: new Dec(decodedData[1] as string).div(1e16).toNumber(),
|
|
72
72
|
ratioState: Number(decodedData[2]),
|
|
73
73
|
};
|
|
74
74
|
},
|
|
@@ -83,19 +83,19 @@ export const aaveV3QuotePriceTrigger = {
|
|
|
83
83
|
) {
|
|
84
84
|
// Price is always in 8 decimals
|
|
85
85
|
const _price = new Dec(price.toString()).mul(10 ** 8).floor().toString();
|
|
86
|
-
return [
|
|
86
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
|
|
87
87
|
},
|
|
88
88
|
decode(
|
|
89
89
|
triggerData: TriggerData,
|
|
90
90
|
): { baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState } {
|
|
91
|
-
const decodedData =
|
|
91
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
92
92
|
// Price is always in 8 decimals
|
|
93
|
-
const price = new Dec(decodedData[2]).div(10 ** 8).toDP(8).toString();
|
|
93
|
+
const price = new Dec(decodedData[2] as string).div(10 ** 8).toDP(8).toString();
|
|
94
94
|
return {
|
|
95
95
|
price,
|
|
96
|
-
baseTokenAddress: decodedData[0],
|
|
97
|
-
quoteTokenAddress: decodedData[1],
|
|
98
|
-
ratioState: +decodedData[3]
|
|
96
|
+
baseTokenAddress: decodedData[0] as EthereumAddress,
|
|
97
|
+
quoteTokenAddress: decodedData[1] as EthereumAddress,
|
|
98
|
+
ratioState: +decodedData[3]!,
|
|
99
99
|
};
|
|
100
100
|
},
|
|
101
101
|
};
|
|
@@ -103,14 +103,14 @@ export const aaveV3QuotePriceTrigger = {
|
|
|
103
103
|
export const compoundV2RatioTrigger = {
|
|
104
104
|
encode(owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
|
|
105
105
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
106
|
-
return [
|
|
106
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint8'], [owner, ratioWei, ratioState])];
|
|
107
107
|
},
|
|
108
108
|
decode(triggerData: TriggerData): { owner: EthereumAddress, ratioState: RatioState, ratio: number } {
|
|
109
|
-
const decodedData =
|
|
109
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
110
110
|
return {
|
|
111
|
-
owner: decodedData[0],
|
|
112
|
-
ratio:
|
|
113
|
-
ratioState: +decodedData[2]
|
|
111
|
+
owner: decodedData[0] as EthereumAddress,
|
|
112
|
+
ratio: weiToRatioPercentage(decodedData[1] as string),
|
|
113
|
+
ratioState: +decodedData[2]!,
|
|
114
114
|
};
|
|
115
115
|
},
|
|
116
116
|
};
|
|
@@ -118,27 +118,27 @@ export const compoundV2RatioTrigger = {
|
|
|
118
118
|
export const liquityRatioTrigger = {
|
|
119
119
|
encode(owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
|
|
120
120
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
121
|
-
return [
|
|
121
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint8'], [owner, ratioWei, ratioState])];
|
|
122
122
|
},
|
|
123
123
|
decode(triggerData: TriggerData): { owner: EthereumAddress, ratioState: RatioState, ratio: number } {
|
|
124
|
-
const decodedData =
|
|
124
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
125
125
|
return {
|
|
126
|
-
owner: decodedData[0],
|
|
127
|
-
ratio:
|
|
128
|
-
ratioState: +decodedData[2]
|
|
126
|
+
owner: decodedData[0] as EthereumAddress,
|
|
127
|
+
ratio: weiToRatioPercentage(decodedData[1] as string),
|
|
128
|
+
ratioState: +decodedData[2]!,
|
|
129
129
|
};
|
|
130
130
|
},
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
export const liquityDebtInFrontTrigger = {
|
|
134
134
|
encode(owner: EthereumAddress, debtInFrontMin: string) {
|
|
135
|
-
return [
|
|
135
|
+
return [AbiCoder.encodeParameters(['address', 'uint256'], [owner, debtInFrontMin])];
|
|
136
136
|
},
|
|
137
137
|
decode(triggerData: TriggerData): { owner: EthereumAddress, debtInFrontMin: string } {
|
|
138
|
-
const decodedData =
|
|
138
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256'], triggerData[0]);
|
|
139
139
|
return {
|
|
140
|
-
owner: decodedData[0],
|
|
141
|
-
debtInFrontMin: decodedData[1],
|
|
140
|
+
owner: decodedData[0] as EthereumAddress,
|
|
141
|
+
debtInFrontMin: decodedData[1] as string,
|
|
142
142
|
};
|
|
143
143
|
},
|
|
144
144
|
};
|
|
@@ -146,26 +146,26 @@ export const liquityDebtInFrontTrigger = {
|
|
|
146
146
|
export const aaveV2RatioTrigger = {
|
|
147
147
|
encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
|
|
148
148
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
149
|
-
return [
|
|
149
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
150
150
|
},
|
|
151
|
-
decode(triggerData: TriggerData): { owner: EthereumAddress, market:EthereumAddress, ratioState: RatioState, ratio: number } {
|
|
152
|
-
const decodedData =
|
|
151
|
+
decode(triggerData: TriggerData): { owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number } {
|
|
152
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
153
153
|
return {
|
|
154
|
-
owner: decodedData[0],
|
|
155
|
-
market: decodedData[1],
|
|
156
|
-
ratio:
|
|
157
|
-
ratioState: +decodedData[3]
|
|
154
|
+
owner: decodedData[0] as EthereumAddress,
|
|
155
|
+
market: decodedData[1] as EthereumAddress,
|
|
156
|
+
ratio: weiToRatioPercentage(decodedData[1] as string),
|
|
157
|
+
ratioState: +decodedData[3]!,
|
|
158
158
|
};
|
|
159
159
|
},
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
export const cBondsRebondTrigger = {
|
|
163
163
|
encode(bondId: number | string) {
|
|
164
|
-
return [
|
|
164
|
+
return [AbiCoder.encodeParameters(['uint256'], [bondId])];
|
|
165
165
|
},
|
|
166
166
|
decode(triggerData: TriggerData): { bondId: string } {
|
|
167
|
-
const decodedData =
|
|
168
|
-
return { bondId: decodedData[0] };
|
|
167
|
+
const decodedData = AbiCoder.decodeParameters(['uint256'], triggerData[0]);
|
|
168
|
+
return { bondId: decodedData[0] as string };
|
|
169
169
|
},
|
|
170
170
|
};
|
|
171
171
|
|
|
@@ -177,17 +177,17 @@ export const compoundV3RatioTrigger = {
|
|
|
177
177
|
ratioState: RatioState,
|
|
178
178
|
) {
|
|
179
179
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
180
|
-
return [
|
|
180
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
181
181
|
},
|
|
182
182
|
decode(
|
|
183
183
|
triggerData: TriggerData,
|
|
184
184
|
): { owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number } {
|
|
185
|
-
const decodedData =
|
|
185
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
186
186
|
return {
|
|
187
|
-
owner: decodedData[0],
|
|
188
|
-
market: decodedData[1],
|
|
189
|
-
ratio:
|
|
190
|
-
ratioState: +decodedData[3]
|
|
187
|
+
owner: decodedData[0] as EthereumAddress,
|
|
188
|
+
market: decodedData[1] as EthereumAddress,
|
|
189
|
+
ratio: weiToRatioPercentage(decodedData[1] as string),
|
|
190
|
+
ratioState: +decodedData[3]!,
|
|
191
191
|
};
|
|
192
192
|
},
|
|
193
193
|
};
|
|
@@ -199,15 +199,15 @@ export const exchangeTimestampTrigger = {
|
|
|
199
199
|
) {
|
|
200
200
|
const timestampWei = new Dec(timestamp).toString();
|
|
201
201
|
const intervalWei = new Dec(interval).toString();
|
|
202
|
-
return [
|
|
202
|
+
return [AbiCoder.encodeParameters(['uint256', 'uint256'], [timestampWei, intervalWei])];
|
|
203
203
|
},
|
|
204
204
|
decode(
|
|
205
205
|
triggerData: TriggerData,
|
|
206
206
|
): { timestamp: number, interval: number } {
|
|
207
|
-
const decodedData =
|
|
207
|
+
const decodedData = AbiCoder.decodeParameters(['uint256', 'uint256'], triggerData[0]);
|
|
208
208
|
return {
|
|
209
|
-
timestamp: decodedData[0],
|
|
210
|
-
interval: decodedData[1],
|
|
209
|
+
timestamp: decodedData[0] as number,
|
|
210
|
+
interval: decodedData[1] as number,
|
|
211
211
|
};
|
|
212
212
|
},
|
|
213
213
|
};
|
|
@@ -215,24 +215,25 @@ export const exchangeOffchainPriceTrigger = {
|
|
|
215
215
|
encode(
|
|
216
216
|
targetPrice: string,
|
|
217
217
|
goodUntil: number,
|
|
218
|
+
orderType: OrderType,
|
|
218
219
|
fromTokenDecimals: number,
|
|
219
220
|
) {
|
|
220
221
|
const price = new Dec(targetPrice.toString()).mul(10 ** fromTokenDecimals).floor().toString();
|
|
221
|
-
const goodUntilWei =
|
|
222
|
-
return [
|
|
222
|
+
const goodUntilWei = web3Utils.toWei(new Dec(goodUntil).toString(), 'ether');
|
|
223
|
+
return [AbiCoder.encodeParameters(['uint256', 'uint256'], [price, goodUntilWei, orderType])];
|
|
223
224
|
},
|
|
224
225
|
decode(
|
|
225
226
|
triggerData: TriggerData,
|
|
226
227
|
fromTokenDecimals: number,
|
|
227
228
|
toTokenDecimals: number,
|
|
228
|
-
): { orderType:
|
|
229
|
-
const decodedData =
|
|
229
|
+
): { orderType: OrderType; targetPrice: string; goodUntil: any } {
|
|
230
|
+
const decodedData = AbiCoder.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
230
231
|
const decimals = new Dec(toTokenDecimals).plus(18).minus(fromTokenDecimals).toString();
|
|
231
|
-
const price = new Dec(decodedData[0]).div(new Dec(10).pow(decimals)).toDP(fromTokenDecimals).toString();
|
|
232
|
+
const price = new Dec(decodedData[0] as string).div(new Dec(10).pow(decimals)).toDP(fromTokenDecimals).toString();
|
|
232
233
|
return {
|
|
233
234
|
targetPrice: price,
|
|
234
235
|
goodUntil: decodedData[1],
|
|
235
|
-
orderType: +decodedData[2]
|
|
236
|
+
orderType: +decodedData[2]!,
|
|
236
237
|
};
|
|
237
238
|
},
|
|
238
239
|
};
|
|
@@ -240,14 +241,14 @@ export const exchangeOffchainPriceTrigger = {
|
|
|
240
241
|
export const sparkRatioTrigger = {
|
|
241
242
|
encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
|
|
242
243
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
243
|
-
return [
|
|
244
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
244
245
|
},
|
|
245
246
|
decode(triggerData: TriggerData) {
|
|
246
|
-
const decodedData =
|
|
247
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
247
248
|
return {
|
|
248
249
|
owner: decodedData[0],
|
|
249
250
|
market: decodedData[1],
|
|
250
|
-
ratio:
|
|
251
|
+
ratio: weiToRatioPercentage(decodedData[2] as string),
|
|
251
252
|
ratioState: Number(decodedData[3]),
|
|
252
253
|
};
|
|
253
254
|
},
|
|
@@ -262,19 +263,19 @@ export const sparkQuotePriceTrigger = {
|
|
|
262
263
|
) {
|
|
263
264
|
// Price is always in 8 decimals
|
|
264
265
|
const _price = new Dec(price.toString()).mul(10 ** 8).floor().toString();
|
|
265
|
-
return [
|
|
266
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
|
|
266
267
|
},
|
|
267
268
|
decode(
|
|
268
269
|
triggerData: TriggerData,
|
|
269
270
|
): { baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState } {
|
|
270
|
-
const decodedData =
|
|
271
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
271
272
|
// Price is always in 8 decimals
|
|
272
|
-
const price = new Dec(decodedData[2]).div(10 ** 8).toDP(8).toString();
|
|
273
|
+
const price = new Dec(decodedData[2] as string).div(10 ** 8).toDP(8).toString();
|
|
273
274
|
return {
|
|
274
275
|
price,
|
|
275
|
-
baseTokenAddress: decodedData[0],
|
|
276
|
-
quoteTokenAddress: decodedData[1],
|
|
277
|
-
ratioState: +decodedData[3]
|
|
276
|
+
baseTokenAddress: decodedData[0] as EthereumAddress,
|
|
277
|
+
quoteTokenAddress: decodedData[1] as EthereumAddress,
|
|
278
|
+
ratioState: +decodedData[3]!,
|
|
278
279
|
};
|
|
279
280
|
},
|
|
280
281
|
};
|
|
@@ -291,22 +292,22 @@ export const curveUsdBorrowRateTrigger = {
|
|
|
291
292
|
.toString();
|
|
292
293
|
const rateWei = new Dec(rate).mul(10 ** 18).floor().toString(); // 18 decimals
|
|
293
294
|
|
|
294
|
-
return [
|
|
295
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint8'], [market, rateWei, rateState])];
|
|
295
296
|
},
|
|
296
297
|
decode(
|
|
297
298
|
triggerData: TriggerData,
|
|
298
299
|
): { market: EthereumAddress, targetRate: string, rateState: RatioState } {
|
|
299
|
-
const decodedData =
|
|
300
|
-
const rateEth =
|
|
300
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
301
|
+
const rateEth = weiToRatioPercentage(decodedData[1] as string);
|
|
301
302
|
|
|
302
303
|
// the form is x = (e**(rate*365*86400))-1 where x*100 is number in %
|
|
303
304
|
const exponentRate = new Dec(rateEth).mul(365).mul(86400);
|
|
304
305
|
const targetRate = new Dec(new Dec(2.718281828459).pow(exponentRate).minus(1)).mul(100)
|
|
305
306
|
.toString();
|
|
306
307
|
return {
|
|
307
|
-
market: decodedData[0],
|
|
308
|
+
market: decodedData[0] as EthereumAddress,
|
|
308
309
|
targetRate,
|
|
309
|
-
rateState: +decodedData[2]
|
|
310
|
+
rateState: +decodedData[2]!,
|
|
310
311
|
};
|
|
311
312
|
},
|
|
312
313
|
};
|
|
@@ -319,17 +320,17 @@ export const curveUsdSoftLiquidationTrigger = {
|
|
|
319
320
|
) {
|
|
320
321
|
// 100% = 1e18 => 1% = 1e16
|
|
321
322
|
const _percentage = new Dec(percentage).mul(10 ** 16).floor().toString();
|
|
322
|
-
return [
|
|
323
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256'], [market, owner, _percentage])];
|
|
323
324
|
},
|
|
324
325
|
decode(
|
|
325
326
|
triggerData: TriggerData,
|
|
326
327
|
): { market: EthereumAddress, owner: EthereumAddress, percentage: string } {
|
|
327
|
-
const decodedData =
|
|
328
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256'], triggerData[0]);
|
|
328
329
|
|
|
329
330
|
return {
|
|
330
|
-
market: decodedData[0],
|
|
331
|
-
owner: decodedData[1],
|
|
332
|
-
percentage: new Dec(decodedData[2]).div(10 ** 16).toString(),
|
|
331
|
+
market: decodedData[0] as EthereumAddress,
|
|
332
|
+
owner: decodedData[1] as EthereumAddress,
|
|
333
|
+
percentage: new Dec(decodedData[2] as string).div(10 ** 16).toString(),
|
|
333
334
|
};
|
|
334
335
|
},
|
|
335
336
|
};
|