@defisaver/automation-sdk 1.2.15 → 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 +1 -1
- package/esm/services/strategySubService.js +7 -2
- package/esm/services/subDataService.js +9 -7
- package/esm/services/triggerService.js +5 -5
- package/package.json +2 -1
- package/src/services/strategySubService.ts +8 -1
- package/src/services/subDataService.ts +9 -8
- package/src/services/triggerService.ts +5 -5
- package/umd/index.js +320 -540
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)[];
|
|
38
|
+
dca(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: number): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds)[];
|
|
39
39
|
limitOrder(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string, orderType: number): string[];
|
|
40
40
|
};
|
|
@@ -105,11 +105,16 @@ 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
120
|
limitOrder(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
|
|
@@ -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
|
},
|
|
@@ -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
|
};
|
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
|
},
|
|
@@ -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 };
|
|
@@ -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
|
};
|