Fix for erc20 transfer + other type of tx
This is 2 fix: - ENS interaction + stickers don't need L1 fees as they are only executed on mainnet - ERC20 data needs to be built when making the tx
This commit is contained in:
parent
aa73a0512c
commit
e1cd91fafe
|
@ -87,12 +87,36 @@ func (s *TransferBridge) EstimateGas(fromNetwork *params.Network, toNetwork *par
|
|||
|
||||
func (s *TransferBridge) BuildTx(network *params.Network, fromAddress common.Address, toAddress common.Address, token *token.Token, amountIn *big.Int) (*ethTypes.Transaction, error) {
|
||||
toAddr := types.Address(toAddress)
|
||||
if strings.EqualFold(token.Symbol, "ETH") {
|
||||
sendArgs := &TransactionBridge{
|
||||
TransferTx: &transactions.SendTxArgs{
|
||||
From: types.Address(fromAddress),
|
||||
To: &toAddr,
|
||||
Value: (*hexutil.Big)(amountIn),
|
||||
Data: types.HexBytes("0x0"),
|
||||
},
|
||||
ChainID: network.ChainID,
|
||||
}
|
||||
|
||||
return s.BuildTransaction(sendArgs)
|
||||
}
|
||||
abi, err := abi.JSON(strings.NewReader(ierc20.IERC20ABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
input, err := abi.Pack("transfer",
|
||||
toAddress,
|
||||
amountIn,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sendArgs := &TransactionBridge{
|
||||
TransferTx: &transactions.SendTxArgs{
|
||||
From: types.Address(fromAddress),
|
||||
To: &toAddr,
|
||||
Value: (*hexutil.Big)(amountIn),
|
||||
Data: types.HexBytes("0x0"),
|
||||
Value: (*hexutil.Big)(big.NewInt(0)),
|
||||
Data: input,
|
||||
},
|
||||
ChainID: network.ChainID,
|
||||
}
|
||||
|
|
|
@ -99,6 +99,10 @@ func (s SendType) isTransfer() bool {
|
|||
return s == Transfer || s.IsCollectiblesTransfer()
|
||||
}
|
||||
|
||||
func (s SendType) needL1Fee() bool {
|
||||
return s != ENSRegister && s != ENSRelease && s != ENSSetPubKey && s != StickersBuy
|
||||
}
|
||||
|
||||
func (s SendType) isAvailableBetween(from, to *params.Network) bool {
|
||||
if s.IsCollectiblesTransfer() {
|
||||
return from.ChainID == to.ChainID
|
||||
|
@ -713,13 +717,16 @@ func (r *Router) suggestedRoutes(
|
|||
continue
|
||||
}
|
||||
|
||||
tx, err := bridge.BuildTx(network, addrFrom, addrTo, token, amountIn)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var l1GasFeeWei uint64 = 0
|
||||
if sendType.needL1Fee() {
|
||||
tx, err := bridge.BuildTx(network, addrFrom, addrTo, token, amountIn)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
l1GasFeeWei, _ := r.s.feesManager.getL1Fee(ctx, network.ChainID, tx)
|
||||
l1GasFeeWei += l1ApprovalFee
|
||||
l1GasFeeWei, _ = r.s.feesManager.getL1Fee(ctx, network.ChainID, tx)
|
||||
l1GasFeeWei += l1ApprovalFee
|
||||
}
|
||||
gasFees.L1GasFee = weiToGwei(big.NewInt(int64(l1GasFeeWei)))
|
||||
|
||||
requiredNativeBalance := new(big.Int).Mul(gweiToWei(maxFees), big.NewInt(int64(gasLimit)))
|
||||
|
|
Loading…
Reference in New Issue