@defisaver/automation-sdk 1.2.13 → 1.2.14
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/esm/services/strategySubService.d.ts +1 -1
- package/esm/services/strategySubService.js +2 -6
- package/esm/services/subDataService.d.ts +1 -1
- package/esm/services/subDataService.js +11 -8
- package/esm/services/triggerService.js +2 -2
- package/package.json +1 -1
- package/src/services/strategySubService.ts +3 -8
- package/src/services/subDataService.ts +11 -9
- package/src/services/triggerService.ts +2 -2
- package/umd/index.js +7 -14
|
@@ -36,5 +36,5 @@ export declare const morphoAaveV2Encode: {
|
|
|
36
36
|
};
|
|
37
37
|
export declare const exchangeEncode: {
|
|
38
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:
|
|
39
|
+
limitOrder(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string): string[];
|
|
40
40
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
|
-
import { getAssetInfo
|
|
2
|
+
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
3
|
import { Bundles, ChainId, RatioState, Strategies, } from '../types/enums';
|
|
4
4
|
import * as subDataService from './subDataService';
|
|
5
5
|
import * as triggerService from './triggerService';
|
|
@@ -113,10 +113,6 @@ export const exchangeEncode = {
|
|
|
113
113
|
return [strategyId, false, triggerData, subData];
|
|
114
114
|
},
|
|
115
115
|
limitOrder(fromToken, toToken, amount, targetPrice, goodUntil) {
|
|
116
|
-
|
|
117
|
-
const subData = subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount);
|
|
118
|
-
const fromTokenDecimals = getAssetInfoByAddress(fromToken).decimals;
|
|
119
|
-
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, goodUntil, fromTokenDecimals);
|
|
120
|
-
return [strategyId, false, triggerData, subData];
|
|
116
|
+
return subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil);
|
|
121
117
|
},
|
|
122
118
|
};
|
|
@@ -83,7 +83,7 @@ export declare const exchangeDcaSubData: {
|
|
|
83
83
|
};
|
|
84
84
|
};
|
|
85
85
|
export declare const exchangeLimitOrderSubData: {
|
|
86
|
-
encode
|
|
86
|
+
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string): string[];
|
|
87
87
|
decode: (subData: string[]) => {
|
|
88
88
|
fromToken: string;
|
|
89
89
|
toToken: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
|
-
import { getAssetInfo } from '@defisaver/tokens';
|
|
2
|
+
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
3
|
import { otherAddresses } from '@defisaver/sdk';
|
|
4
4
|
import { ChainId } from '../types/enums';
|
|
5
5
|
import { ZERO_ADDRESS } from '../constants';
|
|
@@ -189,7 +189,7 @@ export const exchangeDcaSubData = {
|
|
|
189
189
|
decode: (subData) => {
|
|
190
190
|
const fromToken = mockedWeb3.eth.abi.decodeParameter('address', subData[0]).toString();
|
|
191
191
|
const toToken = mockedWeb3.eth.abi.decodeParameter('address', subData[1]).toString();
|
|
192
|
-
const amount = mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString();
|
|
192
|
+
const amount = assetAmountInEth(mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString(), getAssetInfoByAddress(fromToken).symbol);
|
|
193
193
|
const interval = mockedWeb3.eth.abi.decodeParameter('uint256', subData[3]).toString();
|
|
194
194
|
return {
|
|
195
195
|
fromToken,
|
|
@@ -200,16 +200,19 @@ export const exchangeDcaSubData = {
|
|
|
200
200
|
},
|
|
201
201
|
};
|
|
202
202
|
export const exchangeLimitOrderSubData = {
|
|
203
|
-
encode
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
203
|
+
encode(fromToken, toToken, amount, targetPrice, goodUntil) {
|
|
204
|
+
return [
|
|
205
|
+
fromToken,
|
|
206
|
+
toToken,
|
|
207
|
+
amount,
|
|
208
|
+
targetPrice,
|
|
209
|
+
goodUntil,
|
|
210
|
+
];
|
|
208
211
|
},
|
|
209
212
|
decode: (subData) => {
|
|
210
213
|
const fromToken = mockedWeb3.eth.abi.decodeParameter('address', subData[0]).toString();
|
|
211
214
|
const toToken = mockedWeb3.eth.abi.decodeParameter('address', subData[1]).toString();
|
|
212
|
-
const amount = mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString();
|
|
215
|
+
const amount = assetAmountInEth(mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString(), getAssetInfoByAddress(fromToken).symbol);
|
|
213
216
|
return { fromToken, toToken, amount };
|
|
214
217
|
},
|
|
215
218
|
};
|
|
@@ -180,10 +180,10 @@ export const exchangeOffchainPriceTrigger = {
|
|
|
180
180
|
},
|
|
181
181
|
decode(triggerData, fromTokenDecimals) {
|
|
182
182
|
const decodedData = mockedWeb3.eth.abi.decodeParameters(['uint256', 'uint256'], triggerData[0]);
|
|
183
|
-
const price = new Dec(decodedData[0]).div(
|
|
183
|
+
const price = new Dec(decodedData[0]).div(new Dec(10).pow(fromTokenDecimals)).toDP(fromTokenDecimals).toString();
|
|
184
184
|
return {
|
|
185
185
|
targetPrice: price,
|
|
186
|
-
goodUntil:
|
|
186
|
+
goodUntil: decodedData[1],
|
|
187
187
|
};
|
|
188
188
|
},
|
|
189
189
|
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
|
-
import { getAssetInfo
|
|
2
|
+
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
Bundles, ChainId, RatioState, Strategies,
|
|
@@ -250,13 +250,8 @@ export const exchangeEncode = {
|
|
|
250
250
|
toToken: EthereumAddress,
|
|
251
251
|
amount: string,
|
|
252
252
|
targetPrice: string,
|
|
253
|
-
goodUntil:
|
|
253
|
+
goodUntil: string,
|
|
254
254
|
) {
|
|
255
|
-
|
|
256
|
-
const subData = subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount);
|
|
257
|
-
const fromTokenDecimals = getAssetInfoByAddress(fromToken).decimals;
|
|
258
|
-
const triggerData = triggerService.exchangeOffchainPriceTrigger.encode(targetPrice, goodUntil, fromTokenDecimals);
|
|
259
|
-
|
|
260
|
-
return [strategyId, false, triggerData, subData];
|
|
255
|
+
return subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil);
|
|
261
256
|
},
|
|
262
257
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
|
-
import { getAssetInfo } from '@defisaver/tokens';
|
|
2
|
+
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
3
|
import { otherAddresses } from '@defisaver/sdk';
|
|
4
4
|
|
|
5
5
|
import type { EthereumAddress, SubData } from '../types';
|
|
@@ -264,7 +264,7 @@ export const exchangeDcaSubData = {
|
|
|
264
264
|
decode: (subData: SubData) => {
|
|
265
265
|
const fromToken = mockedWeb3.eth.abi.decodeParameter('address', subData[0]).toString();
|
|
266
266
|
const toToken = mockedWeb3.eth.abi.decodeParameter('address', subData[1]).toString();
|
|
267
|
-
const amount = mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString();
|
|
267
|
+
const amount = assetAmountInEth(mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString(), getAssetInfoByAddress(fromToken).symbol);
|
|
268
268
|
const interval = mockedWeb3.eth.abi.decodeParameter('uint256', subData[3]).toString();
|
|
269
269
|
return {
|
|
270
270
|
fromToken,
|
|
@@ -276,17 +276,19 @@ export const exchangeDcaSubData = {
|
|
|
276
276
|
};
|
|
277
277
|
|
|
278
278
|
export const exchangeLimitOrderSubData = {
|
|
279
|
-
encode
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
279
|
+
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string) : SubData {
|
|
280
|
+
return [
|
|
281
|
+
fromToken,
|
|
282
|
+
toToken,
|
|
283
|
+
amount,
|
|
284
|
+
targetPrice,
|
|
285
|
+
goodUntil,
|
|
286
|
+
];
|
|
285
287
|
},
|
|
286
288
|
decode: (subData: SubData) => {
|
|
287
289
|
const fromToken = mockedWeb3.eth.abi.decodeParameter('address', subData[0]).toString();
|
|
288
290
|
const toToken = mockedWeb3.eth.abi.decodeParameter('address', subData[1]).toString();
|
|
289
|
-
const amount = mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString();
|
|
291
|
+
const amount = assetAmountInEth(mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString(), getAssetInfoByAddress(fromToken).symbol);
|
|
290
292
|
return { fromToken, toToken, amount };
|
|
291
293
|
},
|
|
292
294
|
};
|
|
@@ -226,10 +226,10 @@ export const exchangeOffchainPriceTrigger = {
|
|
|
226
226
|
fromTokenDecimals: number,
|
|
227
227
|
): { targetPrice: string, goodUntil: number } {
|
|
228
228
|
const decodedData = mockedWeb3.eth.abi.decodeParameters(['uint256', 'uint256'], triggerData[0]);
|
|
229
|
-
const price = new Dec(decodedData[0]).div(10
|
|
229
|
+
const price = new Dec(decodedData[0]).div(new Dec(10).pow(fromTokenDecimals)).toDP(fromTokenDecimals).toString();
|
|
230
230
|
return {
|
|
231
231
|
targetPrice: price,
|
|
232
|
-
goodUntil:
|
|
232
|
+
goodUntil: decodedData[1],
|
|
233
233
|
};
|
|
234
234
|
},
|
|
235
235
|
};
|
package/umd/index.js
CHANGED
|
@@ -19273,7 +19273,7 @@ var exchangeDcaSubData = {
|
|
|
19273
19273
|
decode: subData => {
|
|
19274
19274
|
var fromToken = mockedWeb3.eth.abi.decodeParameter('address', subData[0]).toString();
|
|
19275
19275
|
var toToken = mockedWeb3.eth.abi.decodeParameter('address', subData[1]).toString();
|
|
19276
|
-
var amount = mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString();
|
|
19276
|
+
var amount = (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.assetAmountInEth)(mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString(), (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.getAssetInfoByAddress)(fromToken).symbol);
|
|
19277
19277
|
var interval = mockedWeb3.eth.abi.decodeParameter('uint256', subData[3]).toString();
|
|
19278
19278
|
return {
|
|
19279
19279
|
fromToken,
|
|
@@ -19284,16 +19284,13 @@ var exchangeDcaSubData = {
|
|
|
19284
19284
|
}
|
|
19285
19285
|
};
|
|
19286
19286
|
var exchangeLimitOrderSubData = {
|
|
19287
|
-
encode
|
|
19288
|
-
|
|
19289
|
-
var toTokenEncoded = mockedWeb3.eth.abi.encodeParameter('address', toToken);
|
|
19290
|
-
var amountEncoded = mockedWeb3.eth.abi.encodeParameter('uint256', amount);
|
|
19291
|
-
return [fromTokenEncoded, toTokenEncoded, amountEncoded];
|
|
19287
|
+
encode(fromToken, toToken, amount, targetPrice, goodUntil) {
|
|
19288
|
+
return [fromToken, toToken, amount, targetPrice, goodUntil];
|
|
19292
19289
|
},
|
|
19293
19290
|
decode: subData => {
|
|
19294
19291
|
var fromToken = mockedWeb3.eth.abi.decodeParameter('address', subData[0]).toString();
|
|
19295
19292
|
var toToken = mockedWeb3.eth.abi.decodeParameter('address', subData[1]).toString();
|
|
19296
|
-
var amount = mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString();
|
|
19293
|
+
var amount = (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.assetAmountInEth)(mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString(), (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.getAssetInfoByAddress)(fromToken).symbol);
|
|
19297
19294
|
return {
|
|
19298
19295
|
fromToken,
|
|
19299
19296
|
toToken,
|
|
@@ -29239,10 +29236,10 @@ var exchangeOffchainPriceTrigger = {
|
|
|
29239
29236
|
},
|
|
29240
29237
|
decode(triggerData, fromTokenDecimals) {
|
|
29241
29238
|
var decodedData = mockedWeb3.eth.abi.decodeParameters(['uint256', 'uint256'], triggerData[0]);
|
|
29242
|
-
var price = new (decimal_js__WEBPACK_IMPORTED_MODULE_0___default())(decodedData[0]).div(10
|
|
29239
|
+
var price = new (decimal_js__WEBPACK_IMPORTED_MODULE_0___default())(decodedData[0]).div(new (decimal_js__WEBPACK_IMPORTED_MODULE_0___default())(10).pow(fromTokenDecimals)).toDP(fromTokenDecimals).toString();
|
|
29243
29240
|
return {
|
|
29244
29241
|
targetPrice: price,
|
|
29245
|
-
goodUntil:
|
|
29242
|
+
goodUntil: decodedData[1]
|
|
29246
29243
|
};
|
|
29247
29244
|
}
|
|
29248
29245
|
};
|
|
@@ -29452,11 +29449,7 @@ var exchangeEncode = {
|
|
|
29452
29449
|
return [strategyId, false, triggerData, subData];
|
|
29453
29450
|
},
|
|
29454
29451
|
limitOrder(fromToken, toToken, amount, targetPrice, goodUntil) {
|
|
29455
|
-
|
|
29456
|
-
var subData = _subDataService__WEBPACK_IMPORTED_MODULE_3__.exchangeLimitOrderSubData.encode(fromToken, toToken, amount);
|
|
29457
|
-
var fromTokenDecimals = (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.getAssetInfoByAddress)(fromToken).decimals;
|
|
29458
|
-
var triggerData = _triggerService__WEBPACK_IMPORTED_MODULE_4__.exchangeOffchainPriceTrigger.encode(targetPrice, goodUntil, fromTokenDecimals);
|
|
29459
|
-
return [strategyId, false, triggerData, subData];
|
|
29452
|
+
return _subDataService__WEBPACK_IMPORTED_MODULE_3__.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil);
|
|
29460
29453
|
}
|
|
29461
29454
|
};
|
|
29462
29455
|
|