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:
Anthony Laibe 2024-04-04 11:32:22 +02:00
parent aa73a0512c
commit e1cd91fafe
2 changed files with 39 additions and 8 deletions

View File

@ -87,6 +87,7 @@ 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),
@ -97,6 +98,29 @@ func (s *TransferBridge) BuildTx(network *params.Network, fromAddress common.Add
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)(big.NewInt(0)),
Data: input,
},
ChainID: network.ChainID,
}
return s.BuildTransaction(sendArgs)
}

View File

@ -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
}
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, _ = 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)))