fix(wallet)_: fixed crash when bridging and chain id not set
This commit is contained in:
parent
eb1ed696f6
commit
12d2a1ac2d
|
@ -109,5 +109,5 @@ type Bridge interface {
|
||||||
Send(sendArgs *TransactionBridge, verifiedAccount *account.SelectedExtKey) (types.Hash, error)
|
Send(sendArgs *TransactionBridge, verifiedAccount *account.SelectedExtKey) (types.Hash, error)
|
||||||
GetContractAddress(network *params.Network, token *token.Token) *common.Address
|
GetContractAddress(network *params.Network, token *token.Token) *common.Address
|
||||||
BuildTransaction(sendArgs *TransactionBridge) (*ethTypes.Transaction, error)
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,7 +288,7 @@ func (s *CBridge) EstimateGas(fromNetwork *params.Network, toNetwork *params.Net
|
||||||
return uint64(increasedEstimation), nil
|
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)
|
toAddr := types.Address(toAddress)
|
||||||
sendArgs := &TransactionBridge{
|
sendArgs := &TransactionBridge{
|
||||||
CbridgeTx: &CBridgeTxArgs{
|
CbridgeTx: &CBridgeTxArgs{
|
||||||
|
@ -298,11 +298,12 @@ func (s *CBridge) BuildTx(network *params.Network, fromAddress common.Address, t
|
||||||
Value: (*hexutil.Big)(amountIn),
|
Value: (*hexutil.Big)(amountIn),
|
||||||
Data: types.HexBytes("0x0"),
|
Data: types.HexBytes("0x0"),
|
||||||
},
|
},
|
||||||
ChainID: network.ChainID,
|
ChainID: toNetwork.ChainID,
|
||||||
Symbol: token.Symbol,
|
Symbol: token.Symbol,
|
||||||
Recipient: toAddress,
|
Recipient: toAddress,
|
||||||
Amount: (*hexutil.Big)(amountIn),
|
Amount: (*hexutil.Big)(amountIn),
|
||||||
},
|
},
|
||||||
|
ChainID: fromNetwork.ChainID,
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.BuildTransaction(sendArgs)
|
return s.BuildTransaction(sendArgs)
|
||||||
|
|
|
@ -101,7 +101,7 @@ func (s *ERC1155TransferBridge) EstimateGas(fromNetwork *params.Network, toNetwo
|
||||||
return uint64(increasedEstimation), nil
|
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)
|
contractAddress := types.Address(token.Address)
|
||||||
|
|
||||||
// We store ERC1155 Token ID using big.Int.String() in token.Symbol
|
// We store ERC1155 Token ID using big.Int.String() in token.Symbol
|
||||||
|
|
|
@ -98,7 +98,7 @@ func (s *ERC721TransferBridge) EstimateGas(fromNetwork *params.Network, toNetwor
|
||||||
return uint64(increasedEstimation), nil
|
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)
|
contractAddress := types.Address(token.Address)
|
||||||
|
|
||||||
// We store ERC721 Token ID using big.Int.String() in token.Symbol
|
// We store ERC721 Token ID using big.Int.String() in token.Symbol
|
||||||
|
|
|
@ -3,6 +3,7 @@ package bridge
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -215,7 +216,7 @@ func (h *HopBridge) EstimateGas(fromNetwork *params.Network, toNetwork *params.N
|
||||||
return uint64(increasedEstimation), nil
|
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)
|
toAddr := types.Address(toAddress)
|
||||||
sendArgs := &TransactionBridge{
|
sendArgs := &TransactionBridge{
|
||||||
HopTx: &HopTxArgs{
|
HopTx: &HopTxArgs{
|
||||||
|
@ -225,11 +226,13 @@ func (h *HopBridge) BuildTx(network *params.Network, fromAddress common.Address,
|
||||||
Value: (*hexutil.Big)(amountIn),
|
Value: (*hexutil.Big)(amountIn),
|
||||||
Data: types.HexBytes("0x0"),
|
Data: types.HexBytes("0x0"),
|
||||||
},
|
},
|
||||||
ChainID: network.ChainID,
|
|
||||||
Symbol: token.Symbol,
|
Symbol: token.Symbol,
|
||||||
Recipient: toAddress,
|
Recipient: toAddress,
|
||||||
Amount: (*hexutil.Big)(amountIn),
|
Amount: (*hexutil.Big)(amountIn),
|
||||||
|
BonderFee: (*hexutil.Big)(bonderFee),
|
||||||
|
ChainID: toNetwork.ChainID,
|
||||||
},
|
},
|
||||||
|
ChainID: fromNetwork.ChainID,
|
||||||
}
|
}
|
||||||
|
|
||||||
return h.BuildTransaction(sendArgs)
|
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) {
|
func (h *HopBridge) sendOrBuild(sendArgs *TransactionBridge, signerFn bind.SignerFn) (tx *ethTypes.Transaction, err error) {
|
||||||
fromNetwork := h.contractMaker.RPCClient.NetworkManager.Find(sendArgs.ChainID)
|
fromNetwork := h.contractMaker.RPCClient.NetworkManager.Find(sendArgs.ChainID)
|
||||||
if fromNetwork == nil {
|
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 {
|
if err != nil {
|
||||||
return tx, err
|
return tx, err
|
||||||
}
|
}
|
||||||
|
@ -333,7 +336,7 @@ func (h *HopBridge) swapAndSend(chainID uint64, hopArgs *HopTxArgs, signerFn bin
|
||||||
|
|
||||||
tx, err = ammWrapper.SwapAndSend(
|
tx, err = ammWrapper.SwapAndSend(
|
||||||
txOpts,
|
txOpts,
|
||||||
big.NewInt(int64(hopArgs.ChainID)),
|
new(big.Int).SetUint64(hopArgs.ChainID),
|
||||||
hopArgs.Recipient,
|
hopArgs.Recipient,
|
||||||
hopArgs.Amount.ToInt(),
|
hopArgs.Amount.ToInt(),
|
||||||
hopArgs.BonderFee.ToInt(),
|
hopArgs.BonderFee.ToInt(),
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (s *SwapParaswap) GetContractAddress(network *params.Network, token *token.
|
||||||
return &address
|
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)
|
toAddr := types.Address(toAddress)
|
||||||
sendArgs := &TransactionBridge{
|
sendArgs := &TransactionBridge{
|
||||||
SwapTx: &SwapTxArgs{
|
SwapTx: &SwapTxArgs{
|
||||||
|
|
|
@ -85,7 +85,7 @@ func (s *TransferBridge) EstimateGas(fromNetwork *params.Network, toNetwork *par
|
||||||
return uint64(increasedEstimation), nil
|
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)
|
toAddr := types.Address(toAddress)
|
||||||
if strings.EqualFold(token.Symbol, "ETH") {
|
if strings.EqualFold(token.Symbol, "ETH") {
|
||||||
sendArgs := &TransactionBridge{
|
sendArgs := &TransactionBridge{
|
||||||
|
|
|
@ -742,7 +742,7 @@ func (r *Router) suggestedRoutes(
|
||||||
|
|
||||||
var l1GasFeeWei uint64
|
var l1GasFeeWei uint64
|
||||||
if sendType.needL1Fee() {
|
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 {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue