fix(wallet)_: fixed crash when bridging and chain id not set

This commit is contained in:
Ivan Belyakov 2024-04-25 16:43:58 +02:00 committed by IvanBelyakoff
parent eb1ed696f6
commit 12d2a1ac2d
8 changed files with 17 additions and 13 deletions

View File

@ -109,5 +109,5 @@ type Bridge interface {
Send(sendArgs *TransactionBridge, verifiedAccount *account.SelectedExtKey) (types.Hash, error)
GetContractAddress(network *params.Network, token *token.Token) *common.Address
BuildTransaction(sendArgs *TransactionBridge) (*ethTypes.Transaction, error)
BuildTx(network *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int) (*ethTypes.Transaction, error)
BuildTx(fromNetwork, toNetwork *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int, bonderFee *big.Int) (*ethTypes.Transaction, error)
}

View File

@ -288,7 +288,7 @@ func (s *CBridge) EstimateGas(fromNetwork *params.Network, toNetwork *params.Net
return uint64(increasedEstimation), nil
}
func (s *CBridge) BuildTx(network *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int) (*ethTypes.Transaction, error) {
func (s *CBridge) BuildTx(fromNetwork, toNetwork *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int, bonderFee *big.Int) (*ethTypes.Transaction, error) {
toAddr := types.Address(toAddress)
sendArgs := &TransactionBridge{
CbridgeTx: &CBridgeTxArgs{
@ -298,11 +298,12 @@ func (s *CBridge) BuildTx(network *params.Network, fromAddress common.Address, t
Value: (*hexutil.Big)(amountIn),
Data: types.HexBytes("0x0"),
},
ChainID: network.ChainID,
ChainID: toNetwork.ChainID,
Symbol: token.Symbol,
Recipient: toAddress,
Amount: (*hexutil.Big)(amountIn),
},
ChainID: fromNetwork.ChainID,
}
return s.BuildTransaction(sendArgs)

View File

@ -101,7 +101,7 @@ func (s *ERC1155TransferBridge) EstimateGas(fromNetwork *params.Network, toNetwo
return uint64(increasedEstimation), nil
}
func (s *ERC1155TransferBridge) BuildTx(network *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int) (*ethTypes.Transaction, error) {
func (s *ERC1155TransferBridge) BuildTx(network, _ *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int, _ *big.Int) (*ethTypes.Transaction, error) {
contractAddress := types.Address(token.Address)
// We store ERC1155 Token ID using big.Int.String() in token.Symbol

View File

@ -98,7 +98,7 @@ func (s *ERC721TransferBridge) EstimateGas(fromNetwork *params.Network, toNetwor
return uint64(increasedEstimation), nil
}
func (s *ERC721TransferBridge) BuildTx(network *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int) (*ethTypes.Transaction, error) {
func (s *ERC721TransferBridge) BuildTx(network, _ *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int, _ *big.Int) (*ethTypes.Transaction, error) {
contractAddress := types.Address(token.Address)
// We store ERC721 Token ID using big.Int.String() in token.Symbol

View File

@ -3,6 +3,7 @@ package bridge
import (
"context"
"errors"
"fmt"
"math"
"math/big"
"strings"
@ -215,7 +216,7 @@ func (h *HopBridge) EstimateGas(fromNetwork *params.Network, toNetwork *params.N
return uint64(increasedEstimation), nil
}
func (h *HopBridge) BuildTx(network *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int) (*ethTypes.Transaction, error) {
func (h *HopBridge) BuildTx(fromNetwork, toNetwork *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int, bonderFee *big.Int) (*ethTypes.Transaction, error) {
toAddr := types.Address(toAddress)
sendArgs := &TransactionBridge{
HopTx: &HopTxArgs{
@ -225,11 +226,13 @@ func (h *HopBridge) BuildTx(network *params.Network, fromAddress common.Address,
Value: (*hexutil.Big)(amountIn),
Data: types.HexBytes("0x0"),
},
ChainID: network.ChainID,
Symbol: token.Symbol,
Recipient: toAddress,
Amount: (*hexutil.Big)(amountIn),
BonderFee: (*hexutil.Big)(bonderFee),
ChainID: toNetwork.ChainID,
},
ChainID: fromNetwork.ChainID,
}
return h.BuildTransaction(sendArgs)
@ -249,10 +252,10 @@ func (h *HopBridge) GetContractAddress(network *params.Network, token *token.Tok
func (h *HopBridge) sendOrBuild(sendArgs *TransactionBridge, signerFn bind.SignerFn) (tx *ethTypes.Transaction, err error) {
fromNetwork := h.contractMaker.RPCClient.NetworkManager.Find(sendArgs.ChainID)
if fromNetwork == nil {
return tx, err
return tx, fmt.Errorf("ChainID not supported %d", sendArgs.ChainID)
}
nonce, err := h.transactor.NextNonce(h.contractMaker.RPCClient, sendArgs.ChainID, sendArgs.HopTx.From)
nonce, err := h.transactor.NextNonce(h.contractMaker.RPCClient, fromNetwork.ChainID, sendArgs.HopTx.From)
if err != nil {
return tx, err
}
@ -333,7 +336,7 @@ func (h *HopBridge) swapAndSend(chainID uint64, hopArgs *HopTxArgs, signerFn bin
tx, err = ammWrapper.SwapAndSend(
txOpts,
big.NewInt(int64(hopArgs.ChainID)),
new(big.Int).SetUint64(hopArgs.ChainID),
hopArgs.Recipient,
hopArgs.Amount.ToInt(),
hopArgs.BonderFee.ToInt(),

View File

@ -115,7 +115,7 @@ func (s *SwapParaswap) GetContractAddress(network *params.Network, token *token.
return &address
}
func (s *SwapParaswap) BuildTx(network *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int) (*ethTypes.Transaction, error) {
func (s *SwapParaswap) BuildTx(network, _ *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int, _ *big.Int) (*ethTypes.Transaction, error) {
toAddr := types.Address(toAddress)
sendArgs := &TransactionBridge{
SwapTx: &SwapTxArgs{

View File

@ -85,7 +85,7 @@ func (s *TransferBridge) EstimateGas(fromNetwork *params.Network, toNetwork *par
return uint64(increasedEstimation), nil
}
func (s *TransferBridge) BuildTx(network *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int) (*ethTypes.Transaction, error) {
func (s *TransferBridge) BuildTx(network, _ *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int, bonderFee *big.Int) (*ethTypes.Transaction, error) {
toAddr := types.Address(toAddress)
if strings.EqualFold(token.Symbol, "ETH") {
sendArgs := &TransactionBridge{

View File

@ -742,7 +742,7 @@ func (r *Router) suggestedRoutes(
var l1GasFeeWei uint64
if sendType.needL1Fee() {
tx, err := bridge.BuildTx(network, addrFrom, addrTo, token, amountIn)
tx, err := bridge.BuildTx(network, dest, addrFrom, addrTo, token, amountIn, bonderFees)
if err != nil {
continue
}