Skip to content

Commit

Permalink
handle negative toAmount for dln provider (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
IDIDOS authored Aug 13, 2024
2 parents f1f08dd + 21ebede commit 0ba9c7b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubic-sdk",
"version": "5.33.2",
"version": "5.33.3",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/common/tokens/price-token-amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ export class PriceTokenAmount<T extends BlockchainName = BlockchainName> extends
.dp(2, BigNumber.ROUND_HALF_UP)
.toNumber();

return impact > 0 ? impact : 0;
return impact;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ export class DebridgeEvmCrossChainTrade extends EvmCrossChainTrade {

const { tx, estimation } =
await DlnApiService.fetchCrossChainSwapData<DlnEvmTransactionResponse>(params);

return { config: tx, amount: estimation.dstChainTokenOut.maxTheoreticalAmount };
const toAmount = new BigNumber(estimation.dstChainTokenOut.maxTheoreticalAmount);
const receivedAmount = toAmount.gt(0) ? toAmount.toFixed() : '0';
return { config: tx, amount: receivedAmount };
}

public getTradeInfo(): TradeInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ export class DebridgeCrossChainProvider extends CrossChainProvider {
DlnEvmTransactionResponse | DlnSolanaTransactionResponse
>(requestParams);

const toAmount = new BigNumber(
debridgeResponse.estimation.dstChainTokenOut.maxTheoreticalAmount
);

const to = new PriceTokenAmount({
...toToken.asStruct,
tokenAmount: Web3Pure.fromWei(
debridgeResponse.estimation.dstChainTokenOut.maxTheoreticalAmount,
toAmount.gt(0) ? toAmount : new BigNumber(0),
debridgeResponse.estimation.dstChainTokenOut.decimals
)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class EddyBridgeTrade extends EvmCrossChainTrade {
return {
estimatedGas: this.estimatedGas,
feeInfo: this.feeInfo,
priceImpact: this.priceImpact || null,
priceImpact: this.priceImpact ?? null,
slippage: this.slippage * 100,
routePath: this.routePath
};
Expand Down

0 comments on commit 0ba9c7b

Please sign in to comment.