@defisaver/automation-sdk 1.2.22 → 1.2.24

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.
@@ -239,11 +239,11 @@ function parseLiquityBondProtection(position, parseData) {
239
239
  };
240
240
  return _position;
241
241
  }
242
- function parseExchangeDca(position, parseData) {
242
+ function parseExchangeDca(position, parseData, chainId) {
243
243
  const _position = cloneDeep(position);
244
244
  const { subStruct } = parseData.subscriptionEventData;
245
245
  _position.strategyData.decoded.triggerData = triggerService.exchangeTimestampTrigger.decode(subStruct.triggerData);
246
- _position.strategyData.decoded.subData = subDataService.exchangeDcaSubData.decode(subStruct.subData);
246
+ _position.strategyData.decoded.subData = subDataService.exchangeDcaSubData.decode(subStruct.subData, chainId);
247
247
  return _position;
248
248
  }
249
249
  function parseExchangeLimitOrder(position, parseData, chainId) {
@@ -251,7 +251,8 @@ function parseExchangeLimitOrder(position, parseData, chainId) {
251
251
  const { subStruct } = parseData.subscriptionEventData;
252
252
  _position.strategyData.decoded.subData = subDataService.exchangeLimitOrderSubData.decode(subStruct.subData, chainId);
253
253
  const fromTokenDecimals = getAssetInfoByAddress(_position.strategyData.decoded.subData.fromToken, chainId).decimals;
254
- _position.strategyData.decoded.triggerData = triggerService.exchangeOffchainPriceTrigger.decode(subStruct.triggerData, fromTokenDecimals);
254
+ const toTokenDecimals = getAssetInfoByAddress(_position.strategyData.decoded.subData.toToken, chainId).decimals;
255
+ _position.strategyData.decoded.triggerData = triggerService.exchangeOffchainPriceTrigger.decode(subStruct.triggerData, fromTokenDecimals, toTokenDecimals);
255
256
  return _position;
256
257
  }
257
258
  const parsingMethodsMapping = {
@@ -75,7 +75,7 @@ export declare const liquityPaybackUsingChickenBondSubData: {
75
75
  };
76
76
  export declare const exchangeDcaSubData: {
77
77
  encode: (fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, interval: number) => string[];
78
- decode: (subData: string[]) => {
78
+ decode: (subData: string[], chainId: ChainId) => {
79
79
  fromToken: string;
80
80
  toToken: string;
81
81
  amount: string;
@@ -188,10 +188,10 @@ export const exchangeDcaSubData = {
188
188
  const intervalEncoded = mockedWeb3.eth.abi.encodeParameter('uint256', interval);
189
189
  return [sellTokenEncoded, buyTokenEncoded, amountEncoded, intervalEncoded];
190
190
  },
191
- decode: (subData) => {
191
+ decode: (subData, chainId) => {
192
192
  const fromToken = mockedWeb3.eth.abi.decodeParameter('address', subData[0]).toString();
193
193
  const toToken = mockedWeb3.eth.abi.decodeParameter('address', subData[1]).toString();
194
- const amount = assetAmountInEth(mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString(), getAssetInfoByAddress(fromToken).symbol);
194
+ const amount = assetAmountInEth(mockedWeb3.eth.abi.decodeParameter('uint256', subData[2]).toString(), getAssetInfoByAddress(fromToken, chainId).symbol);
195
195
  const interval = mockedWeb3.eth.abi.decodeParameter('uint256', subData[3]).toString();
196
196
  return {
197
197
  fromToken,
@@ -106,7 +106,7 @@ export declare const exchangeTimestampTrigger: {
106
106
  };
107
107
  export declare const exchangeOffchainPriceTrigger: {
108
108
  encode(targetPrice: string, goodUntil: number, fromTokenDecimals: number): string[];
109
- decode(triggerData: string[], fromTokenDecimals: number): {
109
+ decode(triggerData: string[], fromTokenDecimals: number, toTokenDecimals: number): {
110
110
  orderType: number;
111
111
  targetPrice: string;
112
112
  goodUntil: any;
@@ -178,9 +178,10 @@ export const exchangeOffchainPriceTrigger = {
178
178
  const goodUntilWei = mockedWeb3.utils.toWei(new Dec(goodUntil).toString());
179
179
  return [mockedWeb3.eth.abi.encodeParameters(['uint256', 'uint256'], [price, goodUntilWei])];
180
180
  },
181
- decode(triggerData, fromTokenDecimals) {
181
+ decode(triggerData, fromTokenDecimals, toTokenDecimals) {
182
182
  const decodedData = mockedWeb3.eth.abi.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
183
- const price = new Dec(decodedData[0]).div(new Dec(10).pow(fromTokenDecimals)).toDP(fromTokenDecimals).toString();
183
+ const decimals = new Dec(toTokenDecimals).plus(18).minus(fromTokenDecimals).toString();
184
+ const price = new Dec(decodedData[0]).div(new Dec(10).pow(decimals)).toDP(fromTokenDecimals).toString();
184
185
  return {
185
186
  targetPrice: price,
186
187
  goodUntil: decodedData[1],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "1.2.22",
3
+ "version": "1.2.24",
4
4
  "description": "",
5
5
  "main": "./umd/index.js",
6
6
  "module": "./esm/index.js",
@@ -347,7 +347,8 @@ function parseExchangeLimitOrder(position: Position.Automated, parseData: ParseD
347
347
 
348
348
  _position.strategyData.decoded.subData = subDataService.exchangeLimitOrderSubData.decode(subStruct.subData, chainId);
349
349
  const fromTokenDecimals = getAssetInfoByAddress(_position.strategyData.decoded.subData.fromToken, chainId).decimals;
350
- _position.strategyData.decoded.triggerData = triggerService.exchangeOffchainPriceTrigger.decode(subStruct.triggerData, fromTokenDecimals);
350
+ const toTokenDecimals = getAssetInfoByAddress(_position.strategyData.decoded.subData.toToken, chainId).decimals;
351
+ _position.strategyData.decoded.triggerData = triggerService.exchangeOffchainPriceTrigger.decode(subStruct.triggerData, fromTokenDecimals, toTokenDecimals);
351
352
 
352
353
  return _position;
353
354
  }
@@ -224,9 +224,11 @@ export const exchangeOffchainPriceTrigger = {
224
224
  decode(
225
225
  triggerData: TriggerData,
226
226
  fromTokenDecimals: number,
227
+ toTokenDecimals: number,
227
228
  ): { orderType: number; targetPrice: string; goodUntil: any } {
228
229
  const decodedData = mockedWeb3.eth.abi.decodeParameters(['uint256', 'uint256', 'uint8'], triggerData[0]);
229
- const price = new Dec(decodedData[0]).div(new Dec(10).pow(fromTokenDecimals)).toDP(fromTokenDecimals).toString();
230
+ 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();
230
232
  return {
231
233
  targetPrice: price,
232
234
  goodUntil: decodedData[1],