rubic-sdk 4.29.0-alpha-aerodrome-dex.5 → 4.29.1-alpha-xy-amount.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -225233,6 +225233,8 @@ XyCrossChainProvider.apiEndpoint = 'https://open-api.xy.finance/v1';
225233
225233
 
225234
225234
  Object.defineProperty(exports, "__esModule", ({ value: true }));
225235
225235
  exports.XyCrossChainTrade = void 0;
225236
+ const updated_rates_error_1 = __webpack_require__(/*! ../../../../../common/errors/cross-chain/updated-rates-error */ "./src/common/errors/cross-chain/updated-rates-error.ts");
225237
+ const tokens_1 = __webpack_require__(/*! ../../../../../common/tokens */ "./src/common/tokens/index.ts");
225236
225238
  const evm_web3_pure_1 = __webpack_require__(/*! ../../../../../core/blockchain/web3-pure/typed-web3-pure/evm-web3-pure/evm-web3-pure */ "./src/core/blockchain/web3-pure/typed-web3-pure/evm-web3-pure/evm-web3-pure.ts");
225237
225239
  const web3_pure_1 = __webpack_require__(/*! ../../../../../core/blockchain/web3-pure/web3-pure */ "./src/core/blockchain/web3-pure/web3-pure.ts");
225238
225240
  const injector_1 = __webpack_require__(/*! ../../../../../core/injector/injector */ "./src/core/injector/injector.ts");
@@ -225378,7 +225380,8 @@ class XyCrossChainTrade extends evm_cross_chain_trade_1.EvmCrossChainTrade {
225378
225380
  ...this.transactionRequest,
225379
225381
  ...(receiverAddress && { receiveAddress: receiverAddress })
225380
225382
  };
225381
- const { tx } = await injector_1.Injector.httpClient.get(`${xy_cross_chain_provider_1.XyCrossChainProvider.apiEndpoint}/swap`, { params: { ...params } });
225383
+ const { tx, toTokenAmount } = await injector_1.Injector.httpClient.get(`${xy_cross_chain_provider_1.XyCrossChainProvider.apiEndpoint}/swap`, { params: { ...params } });
225384
+ await this.checkOrderAmount(toTokenAmount);
225382
225385
  return tx;
225383
225386
  }
225384
225387
  getUsdPrice() {
@@ -225399,6 +225402,35 @@ class XyCrossChainTrade extends evm_cross_chain_trade_1.EvmCrossChainTrade {
225399
225402
  this.slippage * 10000
225400
225403
  ];
225401
225404
  }
225405
+ async checkOrderAmount(toTokenAmount) {
225406
+ const newAmount = web3_pure_1.Web3Pure.fromWei(toTokenAmount, this.to.decimals);
225407
+ const acceptableExpensesChangePercent = 2;
225408
+ const amountPlusPercent = this.to.tokenAmount.plus(this.to.tokenAmount.multipliedBy(acceptableExpensesChangePercent).dividedBy(100));
225409
+ const infoObject = {
225410
+ newAmount: newAmount.toFixed(),
225411
+ oldAmount: this.to.tokenAmount.toFixed(),
225412
+ oldAmountPlusPercent: amountPlusPercent.toFixed(),
225413
+ newAmountLessThenOld: newAmount.lt(this.to.tokenAmount),
225414
+ newAmountGreatThenOldMore2Percent: newAmount.gt(amountPlusPercent)
225415
+ };
225416
+ console.log(infoObject);
225417
+ if (newAmount.lt(this.to.tokenAmount) || newAmount.gt(amountPlusPercent)) {
225418
+ const newTo = await tokens_1.PriceTokenAmount.createFromToken({
225419
+ ...this.to,
225420
+ tokenAmount: newAmount
225421
+ });
225422
+ throw new updated_rates_error_1.UpdatedRatesError(new XyCrossChainTrade({
225423
+ from: this.from,
225424
+ to: newTo,
225425
+ transactionRequest: this.transactionRequest,
225426
+ gasData: this.gasData,
225427
+ priceImpact: this.from.calculatePriceImpactPercent(newTo),
225428
+ slippage: this.slippage,
225429
+ feeInfo: this.feeInfo,
225430
+ onChainTrade: null
225431
+ }, this.providerAddress));
225432
+ }
225433
+ }
225402
225434
  }
225403
225435
  exports.XyCrossChainTrade = XyCrossChainTrade;
225404
225436
  XyCrossChainTrade.nativeAddress = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';