Skip to content

Commit

Permalink
2434, show min/max amounts errors for tron-bridgers (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoElement authored Aug 2, 2024
2 parents 40f20ce + c70c29d commit 2c9c3fe
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 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.32.6",
"version": "5.32.7",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { RubicStep } from 'src/features/cross-chain/calculation-manager/provider
import { tronCommonCrossChainAbi } from 'src/features/cross-chain/calculation-manager/providers/common/tron-cross-chain-trade/constants/tron-common-cross-chain-abi';
import { AbiItem } from 'web3-utils';

import { CrossChainTrade } from '../common/cross-chain-trade';

export class BridgersCrossChainProvider extends CrossChainProvider {
public readonly type = CROSS_CHAIN_TRADE_TYPE.BRIDGERS;

Expand Down Expand Up @@ -167,37 +169,36 @@ export class BridgersCrossChainProvider extends CrossChainProvider {
)
: null;

return {
trade: new EvmBridgersCrossChainTrade(
{
from: from as PriceTokenAmount<BridgersEvmCrossChainSupportedBlockchain>,
to: to as PriceTokenAmount<TronBlockchainName>,
toTokenAmountMin,
feeInfo,
gasData,
slippage: options.slippageTolerance
},
options.providerAddress,
await this.getRoutePath(from, to)
),
tradeType: this.type
};
}
return {
trade: new TronBridgersCrossChainTrade(
const evmTrade = new EvmBridgersCrossChainTrade(
{
from: from as PriceTokenAmount<TronBlockchainName>,
to: to as PriceTokenAmount<BridgersEvmCrossChainSupportedBlockchain>,
from: from as PriceTokenAmount<BridgersEvmCrossChainSupportedBlockchain>,
to: to as PriceTokenAmount<TronBlockchainName>,
toTokenAmountMin,
feeInfo,
slippage: options.slippageTolerance,
contractAddress: transactionData.contractAddress
gasData,
slippage: options.slippageTolerance
},
options.providerAddress,
await this.getRoutePath(from, to)
),
tradeType: this.type
};
);

return this.getCalculationResponse(from, transactionData, evmTrade);
}

const tronTrade = new TronBridgersCrossChainTrade(
{
from: from as PriceTokenAmount<TronBlockchainName>,
to: to as PriceTokenAmount<BridgersEvmCrossChainSupportedBlockchain>,
toTokenAmountMin,
feeInfo,
slippage: options.slippageTolerance,
contractAddress: transactionData.contractAddress
},
options.providerAddress,
await this.getRoutePath(from, to)
);

return this.getCalculationResponse(from, transactionData, tronTrade);
} catch (err: unknown) {
return {
trade: null,
Expand All @@ -207,6 +208,32 @@ export class BridgersCrossChainProvider extends CrossChainProvider {
}
}

private getCalculationResponse(
from: PriceTokenAmount,
transactionData: BridgersQuoteResponse['data']['txData'],
trade: CrossChainTrade<EvmEncodeConfig | TronTransactionConfig>
): CalculationResult<EvmEncodeConfig | TronTransactionConfig> {
if (from.tokenAmount.lt(transactionData.depositMin)) {
return {
trade,
error: new MinAmountError(new BigNumber(transactionData.depositMin), from.symbol),
tradeType: this.type
};
}
if (from.tokenAmount.gt(transactionData.depositMax)) {
return {
trade,
error: new MaxAmountError(new BigNumber(transactionData.depositMax), from.symbol),
tradeType: this.type
};
}

return {
trade,
tradeType: this.type
};
}

protected override async getFeeInfo(
fromBlockchain: BridgersCrossChainSupportedBlockchain,
_providerAddress: string,
Expand Down

0 comments on commit 2c9c3fe

Please sign in to comment.