mirror of
https://github.com/status-im/status-go.git
synced 2025-01-18 10:42:07 +00:00
fix_: allow sending 0 value transactions
This commit is contained in:
parent
625c11ced4
commit
4d2d20cff4
@ -438,7 +438,7 @@ func (h *HopBridgeProcessor) CalculateFees(params ProcessorInputParams) (*big.In
|
||||
// Remove token fee from bonder fee as said here:
|
||||
// https://docs.hop.exchange/v/developer-docs/api/api#get-v1-quote
|
||||
// `bonderFee` - The suggested bonder fee for the amount in. The bonder fee also includes the cost of the destination transaction fee.
|
||||
tokenFee := ZeroBigIntValue //new(big.Int).Sub(h.bonderFee.AmountIn.Int, h.bonderFee.EstimatedRecieved.Int)
|
||||
tokenFee := new(big.Int).Sub(bonderFee.AmountIn.Int, bonderFee.EstimatedRecieved.Int)
|
||||
|
||||
return bonderFee.BonderFee.Int, tokenFee, nil
|
||||
}
|
||||
|
@ -133,6 +133,24 @@ func (s SendType) canUseProcessor(p pathprocessor.PathProcessor) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (s SendType) processZeroAmountInProcessor(amountIn *big.Int, amountOut *big.Int, processorName string) bool {
|
||||
if amountIn.Cmp(pathprocessor.ZeroBigIntValue) == 0 {
|
||||
if s == Transfer {
|
||||
if processorName != pathprocessor.ProcessorTransferName {
|
||||
return false
|
||||
}
|
||||
} else if s == Swap {
|
||||
if amountOut.Cmp(pathprocessor.ZeroBigIntValue) == 0 {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (s SendType) isAvailableBetween(from, to *params.Network) bool {
|
||||
if s.IsCollectiblesTransfer() ||
|
||||
s.IsEnsTransfer() ||
|
||||
|
@ -638,6 +638,15 @@ func (r *Router) getCrossChainsOptionsForSendingAmount(input *RouteInputParams,
|
||||
|
||||
amountLocked := false
|
||||
amountToSend := input.AmountIn.ToInt()
|
||||
|
||||
if amountToSend.Cmp(pathprocessor.ZeroBigIntValue) == 0 {
|
||||
finalCrossChainAmountOptions[selectedFromChain.ChainID] = append(finalCrossChainAmountOptions[selectedFromChain.ChainID], amountOption{
|
||||
amount: amountToSend,
|
||||
locked: false,
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
lockedAmount, fromChainLocked := input.FromLockedAmount[selectedFromChain.ChainID]
|
||||
if fromChainLocked {
|
||||
amountToSend = lockedAmount.ToInt()
|
||||
@ -826,6 +835,10 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams,
|
||||
continue
|
||||
}
|
||||
|
||||
if !input.SendType.processZeroAmountInProcessor(amountOption.amount, input.AmountOut.ToInt(), pProcessor.Name()) {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, dest := range selectedTohains {
|
||||
|
||||
if !input.SendType.isAvailableFor(network) {
|
||||
|
@ -207,6 +207,54 @@ type normalTestParams struct {
|
||||
|
||||
func getNormalTestParamsList() []normalTestParams {
|
||||
return []normalTestParams{
|
||||
{
|
||||
name: "ETH transfer - No Specific FromChain - No Specific ToChain - 0 AmountIn",
|
||||
input: &RouteInputParams{
|
||||
testnetMode: false,
|
||||
Uuid: uuid.NewString(),
|
||||
SendType: Transfer,
|
||||
AddrFrom: common.HexToAddress("0x1"),
|
||||
AddrTo: common.HexToAddress("0x2"),
|
||||
AmountIn: (*hexutil.Big)(big.NewInt(0)),
|
||||
TokenID: pathprocessor.EthSymbol,
|
||||
|
||||
testsMode: true,
|
||||
testParams: &routerTestParams{
|
||||
tokenFrom: &token.Token{
|
||||
ChainID: 1,
|
||||
Symbol: pathprocessor.EthSymbol,
|
||||
Decimals: 18,
|
||||
},
|
||||
tokenPrices: testTokenPrices,
|
||||
suggestedFees: testSuggestedFees,
|
||||
balanceMap: testBalanceMapPerChain,
|
||||
estimationMap: testEstimationMap,
|
||||
bonderFeeMap: testBbonderFeeMap,
|
||||
approvalGasEstimation: testApprovalGasEstimation,
|
||||
approvalL1Fee: testApprovalL1Fee,
|
||||
},
|
||||
},
|
||||
expectedCandidates: []*PathV2{
|
||||
{
|
||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||
FromChain: &mainnet,
|
||||
ToChain: &mainnet,
|
||||
ApprovalRequired: false,
|
||||
},
|
||||
{
|
||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||
FromChain: &optimism,
|
||||
ToChain: &optimism,
|
||||
ApprovalRequired: false,
|
||||
},
|
||||
{
|
||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||
FromChain: &arbitrum,
|
||||
ToChain: &arbitrum,
|
||||
ApprovalRequired: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ETH transfer - No Specific FromChain - No Specific ToChain",
|
||||
input: &RouteInputParams{
|
||||
|
Loading…
x
Reference in New Issue
Block a user