@defisaver/automation-sdk 1.2.14 → 1.2.16
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 +3 -67
- package/esm/services/strategySubService.d.ts +2 -2
- package/esm/services/strategySubService.js +9 -4
- package/esm/services/subDataService.d.ts +1 -1
- package/esm/services/subDataService.js +12 -9
- package/esm/services/triggerService.d.ts +2 -1
- package/esm/services/triggerService.js +7 -6
- package/package.json +2 -1
- package/src/services/strategySubService.ts +10 -2
- package/src/services/subDataService.ts +12 -10
- package/src/services/triggerService.ts +8 -7
- package/umd/index.js +327 -546
package/.eslintrc.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
module.exports = {
|
|
3
|
-
extends: ['
|
|
4
|
-
plugins: ['import'],
|
|
3
|
+
extends: ['@defisaver/eslint-config/base-config'],
|
|
5
4
|
parser: '@babel/eslint-parser',
|
|
6
5
|
env: {
|
|
7
6
|
es6: true,
|
|
@@ -10,7 +9,7 @@ module.exports = {
|
|
|
10
9
|
overrides: [{
|
|
11
10
|
// these are overrides for .ts files, meaning these are only applied to .ts files
|
|
12
11
|
files: ['*.ts'],
|
|
13
|
-
extends: ['
|
|
12
|
+
extends: ['@defisaver/eslint-config/base-config-typescript'],
|
|
14
13
|
plugins: ['@typescript-eslint'],
|
|
15
14
|
parser: '@typescript-eslint/parser',
|
|
16
15
|
parserOptions: {
|
|
@@ -19,77 +18,14 @@ module.exports = {
|
|
|
19
18
|
},
|
|
20
19
|
// typescript rules must be added here to work
|
|
21
20
|
rules: {
|
|
22
|
-
'@typescript-eslint/no-unused-vars': 0,
|
|
23
|
-
'@typescript-eslint/naming-convention': 0,
|
|
24
|
-
'@typescript-eslint/default-param-last': 0,
|
|
25
21
|
'@typescript-eslint/consistent-type-imports': 2,
|
|
22
|
+
'max-len': 0,
|
|
26
23
|
},
|
|
27
24
|
}],
|
|
28
25
|
parserOptions: {
|
|
29
26
|
ecmaVersion: 2018,
|
|
30
27
|
sourceType: 'module',
|
|
31
28
|
},
|
|
32
|
-
rules: {
|
|
33
|
-
'no-restricted-syntax': 0,
|
|
34
|
-
'no-continue': 0,
|
|
35
|
-
'jsx-a11y/control-has-associated-label': 0,
|
|
36
|
-
'arrow-parens': 0,
|
|
37
|
-
'no-async-promise-executor': 0,
|
|
38
|
-
'no-multiple-empty-lines': [2, { max: 2 }],
|
|
39
|
-
camelcase: [2, { allow: ['^UNSAFE_'] }],
|
|
40
|
-
'no-mixed-operators': [2, { allowSamePrecedence: true }],
|
|
41
|
-
'no-plusplus': 0,
|
|
42
|
-
'no-minusminus': 0,
|
|
43
|
-
'prefer-destructuring': 0,
|
|
44
|
-
'max-len': 0,
|
|
45
|
-
'class-methods-use-this': 0,
|
|
46
|
-
'jsx-a11y/href-no-hash': 'off',
|
|
47
|
-
'jsx-a11y/no-autofocus': 0,
|
|
48
|
-
'no-unused-vars': 0,
|
|
49
|
-
'no-underscore-dangle': 0,
|
|
50
|
-
'global-require': 0,
|
|
51
|
-
'no-console': 0,
|
|
52
|
-
'new-cap': 0,
|
|
53
|
-
'eol-last': 0,
|
|
54
|
-
'jsx-a11y/label-has-for': 0,
|
|
55
|
-
'linebreak-style': 0,
|
|
56
|
-
'consistent-return': 0,
|
|
57
|
-
'import/prefer-default-export': 0,
|
|
58
|
-
'no-unescaped-entities': 0,
|
|
59
|
-
'jsx-a11y/no-static-element-interactions': 0,
|
|
60
|
-
'jsx-a11y/click-events-have-key-events': 0,
|
|
61
|
-
'jsx-a11y/anchor-is-valid': 0,
|
|
62
|
-
'no-shadow': 0,
|
|
63
|
-
'prefer-promise-reject-errors': 0,
|
|
64
|
-
'function-paren-newline': 0,
|
|
65
|
-
'operator-linebreak': 0,
|
|
66
|
-
'jsx-a11y/no-noninteractive-element-interactions': 0,
|
|
67
|
-
'jsx-a11y/label-has-associated-control': 0,
|
|
68
|
-
'no-nested-ternary': 0,
|
|
69
|
-
'import/no-cycle': 0,
|
|
70
|
-
'import/no-unresolved': 0,
|
|
71
|
-
'function-call-argument-newline': 0,
|
|
72
|
-
'import/extensions': [
|
|
73
|
-
'error',
|
|
74
|
-
'always',
|
|
75
|
-
{
|
|
76
|
-
pattern: {
|
|
77
|
-
js: 'never',
|
|
78
|
-
ts: 'never',
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
globals: {
|
|
84
|
-
web3: true,
|
|
85
|
-
ethereum: true,
|
|
86
|
-
$: true,
|
|
87
|
-
window: true,
|
|
88
|
-
document: true,
|
|
89
|
-
fetch: true,
|
|
90
|
-
location: true,
|
|
91
|
-
localStorage: true,
|
|
92
|
-
},
|
|
93
29
|
settings: {
|
|
94
30
|
'import/resolver': {
|
|
95
31
|
typescript: {
|
|
@@ -35,6 +35,6 @@ export declare const morphoAaveV2Encode: {
|
|
|
35
35
|
leverageManagement(minRatio: number, maxRatio: number, maxOptimalRatio: number, minOptimalRatio: number, boostEnabled: boolean): string[];
|
|
36
36
|
};
|
|
37
37
|
export declare const exchangeEncode: {
|
|
38
|
-
dca(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
39
|
-
limitOrder(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string): string[];
|
|
38
|
+
dca(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: number): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds)[];
|
|
39
|
+
limitOrder(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string, orderType: number): string[];
|
|
40
40
|
};
|
|
@@ -105,14 +105,19 @@ export const morphoAaveV2Encode = {
|
|
|
105
105
|
},
|
|
106
106
|
};
|
|
107
107
|
export const exchangeEncode = {
|
|
108
|
-
dca(fromToken, toToken, amount, timestamp, interval) {
|
|
108
|
+
dca(fromToken, toToken, amount, timestamp, interval, network) {
|
|
109
109
|
requireAddresses([fromToken, toToken]);
|
|
110
110
|
const subData = subDataService.exchangeDcaSubData.encode(fromToken, toToken, amount, interval);
|
|
111
111
|
const triggerData = triggerService.exchangeTimestampTrigger.encode(timestamp, interval);
|
|
112
|
-
const
|
|
112
|
+
const selectedNetwork = network === 1
|
|
113
|
+
? 'MainnetIds'
|
|
114
|
+
: network === 10
|
|
115
|
+
? 'OptimismIds'
|
|
116
|
+
: 'ArbitrumIds';
|
|
117
|
+
const strategyId = Strategies[selectedNetwork].EXCHANGE_DCA;
|
|
113
118
|
return [strategyId, false, triggerData, subData];
|
|
114
119
|
},
|
|
115
|
-
limitOrder(fromToken, toToken, amount, targetPrice, goodUntil) {
|
|
116
|
-
return subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil);
|
|
120
|
+
limitOrder(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
|
|
121
|
+
return subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType);
|
|
117
122
|
},
|
|
118
123
|
};
|
|
@@ -83,7 +83,7 @@ export declare const exchangeDcaSubData: {
|
|
|
83
83
|
};
|
|
84
84
|
};
|
|
85
85
|
export declare const exchangeLimitOrderSubData: {
|
|
86
|
-
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string): string[];
|
|
86
|
+
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: number): string[];
|
|
87
87
|
decode: (subData: string[]) => {
|
|
88
88
|
fromToken: string;
|
|
89
89
|
toToken: string;
|
|
@@ -136,15 +136,17 @@ export const compoundV3LeverageManagementSubData = {
|
|
|
136
136
|
};
|
|
137
137
|
export const morphoAaveV2LeverageManagementSubData = {
|
|
138
138
|
encode(minRatio, maxRatio, maxOptimalRatio, minOptimalRatio, boostEnabled) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
return [
|
|
140
|
+
ratioPercentageToWei(minRatio),
|
|
141
|
+
ratioPercentageToWei(maxRatio),
|
|
142
|
+
ratioPercentageToWei(maxOptimalRatio),
|
|
143
|
+
ratioPercentageToWei(minOptimalRatio),
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
boostEnabled,
|
|
146
|
+
];
|
|
145
147
|
},
|
|
146
148
|
decode(subData) {
|
|
147
|
-
const ratioWei = mockedWeb3.eth.abi.decodeParameter('uint128', subData[
|
|
149
|
+
const ratioWei = mockedWeb3.eth.abi.decodeParameter('uint128', subData[1]);
|
|
148
150
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
149
151
|
return { targetRatio };
|
|
150
152
|
},
|
|
@@ -200,13 +202,14 @@ export const exchangeDcaSubData = {
|
|
|
200
202
|
},
|
|
201
203
|
};
|
|
202
204
|
export const exchangeLimitOrderSubData = {
|
|
203
|
-
encode(fromToken, toToken, amount, targetPrice, goodUntil) {
|
|
205
|
+
encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
|
|
204
206
|
return [
|
|
205
207
|
fromToken,
|
|
206
208
|
toToken,
|
|
207
209
|
amount,
|
|
208
210
|
targetPrice,
|
|
209
|
-
goodUntil,
|
|
211
|
+
new Dec(goodUntil).toString(),
|
|
212
|
+
new Dec(orderType).toString(),
|
|
210
213
|
];
|
|
211
214
|
},
|
|
212
215
|
decode: (subData) => {
|
|
@@ -107,7 +107,8 @@ export declare const exchangeTimestampTrigger: {
|
|
|
107
107
|
export declare const exchangeOffchainPriceTrigger: {
|
|
108
108
|
encode(targetPrice: string, goodUntil: number, fromTokenDecimals: number): string[];
|
|
109
109
|
decode(triggerData: string[], fromTokenDecimals: number): {
|
|
110
|
+
orderType: number;
|
|
110
111
|
targetPrice: string;
|
|
111
|
-
goodUntil:
|
|
112
|
+
goodUntil: any;
|
|
112
113
|
};
|
|
113
114
|
};
|
|
@@ -49,15 +49,15 @@ export const aaveV3RatioTrigger = {
|
|
|
49
49
|
};
|
|
50
50
|
export const morphoAaveV2RatioTrigger = {
|
|
51
51
|
encode(owner, ratioPercentage, ratioState) {
|
|
52
|
-
const ratioWei =
|
|
53
|
-
return [mockedWeb3.eth.abi.encodeParameters(['address', '
|
|
52
|
+
const ratioWei = new Dec(ratioPercentage).mul(1e16).toString();
|
|
53
|
+
return [mockedWeb3.eth.abi.encodeParameters(['address', 'uint128', 'uint8'], [owner, ratioWei, ratioState])];
|
|
54
54
|
},
|
|
55
55
|
decode(triggerData) {
|
|
56
|
-
const decodedData = mockedWeb3.eth.abi.decodeParameters(['address', '
|
|
56
|
+
const decodedData = mockedWeb3.eth.abi.decodeParameters(['address', 'uint128', 'uint8'], triggerData[0]);
|
|
57
57
|
return {
|
|
58
58
|
owner: decodedData[0],
|
|
59
|
-
ratio: new Dec(
|
|
60
|
-
ratioState: Number(decodedData[
|
|
59
|
+
ratio: new Dec(decodedData[1]).div(1e16).toNumber(),
|
|
60
|
+
ratioState: Number(decodedData[2]),
|
|
61
61
|
};
|
|
62
62
|
},
|
|
63
63
|
};
|
|
@@ -179,11 +179,12 @@ export const exchangeOffchainPriceTrigger = {
|
|
|
179
179
|
return [mockedWeb3.eth.abi.encodeParameters(['uint256', 'uint256'], [price, goodUntilWei])];
|
|
180
180
|
},
|
|
181
181
|
decode(triggerData, fromTokenDecimals) {
|
|
182
|
-
const decodedData = mockedWeb3.eth.abi.decodeParameters(['uint256', 'uint256'], triggerData[0]);
|
|
182
|
+
const decodedData = mockedWeb3.eth.abi.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
183
183
|
const price = new Dec(decodedData[0]).div(new Dec(10).pow(fromTokenDecimals)).toDP(fromTokenDecimals).toString();
|
|
184
184
|
return {
|
|
185
185
|
targetPrice: price,
|
|
186
186
|
goodUntil: decodedData[1],
|
|
187
|
+
orderType: +decodedData[2],
|
|
187
188
|
};
|
|
188
189
|
},
|
|
189
190
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./umd/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"repository": "https://github.com/defisaver/automation-sdk",
|
|
21
21
|
"license": "ISC",
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@defisaver/eslint-config": "^1.0.0",
|
|
23
24
|
"@defisaver/sdk": "^1.0.5",
|
|
24
25
|
"@defisaver/tokens": "^1.4.25",
|
|
25
26
|
"@ethersproject/address": "^5.0.10",
|
|
@@ -237,11 +237,18 @@ export const exchangeEncode = {
|
|
|
237
237
|
amount: string,
|
|
238
238
|
timestamp: number,
|
|
239
239
|
interval: number,
|
|
240
|
+
network: number,
|
|
240
241
|
) {
|
|
241
242
|
requireAddresses([fromToken, toToken]);
|
|
242
243
|
const subData = subDataService.exchangeDcaSubData.encode(fromToken, toToken, amount, interval);
|
|
243
244
|
const triggerData = triggerService.exchangeTimestampTrigger.encode(timestamp, interval);
|
|
244
|
-
const
|
|
245
|
+
const selectedNetwork = network === 1
|
|
246
|
+
? 'MainnetIds'
|
|
247
|
+
: network === 10
|
|
248
|
+
? 'OptimismIds'
|
|
249
|
+
: 'ArbitrumIds';
|
|
250
|
+
|
|
251
|
+
const strategyId = Strategies[selectedNetwork].EXCHANGE_DCA;
|
|
245
252
|
|
|
246
253
|
return [strategyId, false, triggerData, subData];
|
|
247
254
|
},
|
|
@@ -251,7 +258,8 @@ export const exchangeEncode = {
|
|
|
251
258
|
amount: string,
|
|
252
259
|
targetPrice: string,
|
|
253
260
|
goodUntil: string,
|
|
261
|
+
orderType: number,
|
|
254
262
|
) {
|
|
255
|
-
return subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil);
|
|
263
|
+
return subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType);
|
|
256
264
|
},
|
|
257
265
|
};
|
|
@@ -203,16 +203,17 @@ export const morphoAaveV2LeverageManagementSubData = {
|
|
|
203
203
|
minOptimalRatio: number,
|
|
204
204
|
boostEnabled: boolean,
|
|
205
205
|
): SubData {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
206
|
+
return [
|
|
207
|
+
ratioPercentageToWei(minRatio),
|
|
208
|
+
ratioPercentageToWei(maxRatio),
|
|
209
|
+
ratioPercentageToWei(maxOptimalRatio),
|
|
210
|
+
ratioPercentageToWei(minOptimalRatio),
|
|
211
|
+
// @ts-ignore
|
|
212
|
+
boostEnabled,
|
|
213
|
+
];
|
|
213
214
|
},
|
|
214
215
|
decode(subData: SubData): { targetRatio: number } {
|
|
215
|
-
const ratioWei = mockedWeb3.eth.abi.decodeParameter('uint128', subData[
|
|
216
|
+
const ratioWei = mockedWeb3.eth.abi.decodeParameter('uint128', subData[1]) as any as string;
|
|
216
217
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
217
218
|
|
|
218
219
|
return { targetRatio };
|
|
@@ -276,13 +277,14 @@ export const exchangeDcaSubData = {
|
|
|
276
277
|
};
|
|
277
278
|
|
|
278
279
|
export const exchangeLimitOrderSubData = {
|
|
279
|
-
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string) : SubData {
|
|
280
|
+
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: number) : SubData {
|
|
280
281
|
return [
|
|
281
282
|
fromToken,
|
|
282
283
|
toToken,
|
|
283
284
|
amount,
|
|
284
285
|
targetPrice,
|
|
285
|
-
goodUntil,
|
|
286
|
+
new Dec(goodUntil).toString(),
|
|
287
|
+
new Dec(orderType).toString(),
|
|
286
288
|
];
|
|
287
289
|
},
|
|
288
290
|
decode: (subData: SubData) => {
|
|
@@ -61,15 +61,15 @@ export const aaveV3RatioTrigger = {
|
|
|
61
61
|
|
|
62
62
|
export const morphoAaveV2RatioTrigger = {
|
|
63
63
|
encode(owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
|
|
64
|
-
const ratioWei =
|
|
65
|
-
return [mockedWeb3.eth.abi.encodeParameters(['address', '
|
|
64
|
+
const ratioWei = new Dec(ratioPercentage).mul(1e16).toString();
|
|
65
|
+
return [mockedWeb3.eth.abi.encodeParameters(['address', 'uint128', 'uint8'], [owner, ratioWei, ratioState])];
|
|
66
66
|
},
|
|
67
67
|
decode(triggerData: TriggerData) {
|
|
68
|
-
const decodedData = mockedWeb3.eth.abi.decodeParameters(['address', '
|
|
68
|
+
const decodedData = mockedWeb3.eth.abi.decodeParameters(['address', 'uint128', 'uint8'], triggerData[0]) as string[];
|
|
69
69
|
return {
|
|
70
70
|
owner: decodedData[0],
|
|
71
|
-
ratio: new Dec(
|
|
72
|
-
ratioState: Number(decodedData[
|
|
71
|
+
ratio: new Dec(decodedData[1]).div(1e16).toNumber(),
|
|
72
|
+
ratioState: Number(decodedData[2]),
|
|
73
73
|
};
|
|
74
74
|
},
|
|
75
75
|
};
|
|
@@ -224,12 +224,13 @@ export const exchangeOffchainPriceTrigger = {
|
|
|
224
224
|
decode(
|
|
225
225
|
triggerData: TriggerData,
|
|
226
226
|
fromTokenDecimals: number,
|
|
227
|
-
): { targetPrice: string
|
|
228
|
-
const decodedData = mockedWeb3.eth.abi.decodeParameters(['uint256', 'uint256'], triggerData[0]);
|
|
227
|
+
): { orderType: number; targetPrice: string; goodUntil: any } {
|
|
228
|
+
const decodedData = mockedWeb3.eth.abi.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
229
229
|
const price = new Dec(decodedData[0]).div(new Dec(10).pow(fromTokenDecimals)).toDP(fromTokenDecimals).toString();
|
|
230
230
|
return {
|
|
231
231
|
targetPrice: price,
|
|
232
232
|
goodUntil: decodedData[1],
|
|
233
|
+
orderType: +decodedData[2],
|
|
233
234
|
};
|
|
234
235
|
},
|
|
235
236
|
};
|