feat_: added new error which will be returned in case bonder fee is higher than the amount being sent
This commit is contained in:
parent
791ff9a0ed
commit
8787da1b89
|
@ -31,4 +31,5 @@ var (
|
||||||
ErrNoBestRouteFound = &errors.ErrorResponse{Code: errors.ErrorCode("WR-023"), Details: "no best route found"}
|
ErrNoBestRouteFound = &errors.ErrorResponse{Code: errors.ErrorCode("WR-023"), Details: "no best route found"}
|
||||||
ErrCannotCheckBalance = &errors.ErrorResponse{Code: errors.ErrorCode("WR-024"), Details: "cannot check balance"}
|
ErrCannotCheckBalance = &errors.ErrorResponse{Code: errors.ErrorCode("WR-024"), Details: "cannot check balance"}
|
||||||
ErrCannotCheckLockedAmounts = &errors.ErrorResponse{Code: errors.ErrorCode("WR-025"), Details: "cannot check locked amounts"}
|
ErrCannotCheckLockedAmounts = &errors.ErrorResponse{Code: errors.ErrorCode("WR-025"), Details: "cannot check locked amounts"}
|
||||||
|
ErrLowAmountInForHopBridge = &errors.ErrorResponse{Code: errors.ErrorCode("WR-026"), Details: "bonder fee greater than estimated received, a higher amount is needed to cover fees"}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1031,6 +1031,12 @@ func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute []*
|
||||||
|
|
||||||
// check the best route for the required balances
|
// check the best route for the required balances
|
||||||
for _, path := range bestRoute {
|
for _, path := range bestRoute {
|
||||||
|
if path.ProcessorName == pathprocessor.ProcessorBridgeHopName {
|
||||||
|
if path.TxBonderFees.ToInt().Cmp(path.AmountOut.ToInt()) > 0 {
|
||||||
|
return ErrLowAmountInForHopBridge
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if path.requiredTokenBalance != nil && path.requiredTokenBalance.Cmp(pathprocessor.ZeroBigIntValue) > 0 {
|
if path.requiredTokenBalance != nil && path.requiredTokenBalance.Cmp(pathprocessor.ZeroBigIntValue) > 0 {
|
||||||
key := makeBalanceKey(path.FromChain.ChainID, path.FromToken.Symbol)
|
key := makeBalanceKey(path.FromChain.ChainID, path.FromToken.Symbol)
|
||||||
if tokenBalance, ok := balanceMapCopy[key]; ok {
|
if tokenBalance, ok := balanceMapCopy[key]; ok {
|
||||||
|
|
|
@ -2585,6 +2585,46 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Bridge - Specific Single FromChain - Specific Single ToChain - Sending Small Amount",
|
||||||
|
input: &RouteInputParams{
|
||||||
|
testnetMode: false,
|
||||||
|
Uuid: uuid.NewString(),
|
||||||
|
SendType: Bridge,
|
||||||
|
AddrFrom: common.HexToAddress("0x1"),
|
||||||
|
AddrTo: common.HexToAddress("0x2"),
|
||||||
|
AmountIn: (*hexutil.Big)(big.NewInt(0.01 * testAmount1USDC)),
|
||||||
|
TokenID: pathprocessor.UsdcSymbol,
|
||||||
|
DisabledFromChainIDs: []uint64{walletCommon.EthereumMainnet, walletCommon.OptimismMainnet},
|
||||||
|
DisabledToChainIDs: []uint64{walletCommon.OptimismMainnet, walletCommon.ArbitrumMainnet},
|
||||||
|
|
||||||
|
testsMode: true,
|
||||||
|
testParams: &routerTestParams{
|
||||||
|
tokenFrom: &token.Token{
|
||||||
|
ChainID: 1,
|
||||||
|
Symbol: pathprocessor.UsdcSymbol,
|
||||||
|
Decimals: 6,
|
||||||
|
},
|
||||||
|
tokenPrices: testTokenPrices,
|
||||||
|
baseFee: big.NewInt(testBaseFee),
|
||||||
|
suggestedFees: testSuggestedFees,
|
||||||
|
balanceMap: testBalanceMapPerChain,
|
||||||
|
estimationMap: testEstimationMap,
|
||||||
|
bonderFeeMap: testBbonderFeeMap,
|
||||||
|
approvalGasEstimation: testApprovalGasEstimation,
|
||||||
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedError: ErrLowAmountInForHopBridge,
|
||||||
|
expectedCandidates: []*PathV2{
|
||||||
|
{
|
||||||
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
|
FromChain: &arbitrum,
|
||||||
|
ToChain: &mainnet,
|
||||||
|
ApprovalRequired: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue