diff --git a/chains/evm/listener/depositHandlers/erc20.go b/chains/evm/listener/depositHandlers/erc20.go index 7d228faa..d52d3cb4 100644 --- a/chains/evm/listener/depositHandlers/erc20.go +++ b/chains/evm/listener/depositHandlers/erc20.go @@ -9,9 +9,12 @@ import ( "time" "github.com/ChainSafe/sygma-relayer/relayer/transfer" + "github.com/ethereum/go-ethereum/common" "github.com/sygmaprotocol/sygma-core/relayer/message" ) +const OPTIONAL_REVERT_GAS = 100000 + type Erc20DepositHandler struct{} // Erc20DepositHandler converts data pulled from event logs into message @@ -49,7 +52,10 @@ func (dh *Erc20DepositHandler) HandleDeposit( metadata := make(map[string]interface{}) // append optional message if it exists if len(calldata) > int(96+recipientAddressLength.Int64()) { - metadata["gasLimit"] = new(big.Int).SetBytes(calldata[64+recipientAddressLength.Int64() : 96+recipientAddressLength.Int64()]).Uint64() + maxFee := new(big.Int).Add(new(big.Int).SetBytes(calldata[64+recipientAddressLength.Int64():96+recipientAddressLength.Int64()]), big.NewInt(OPTIONAL_REVERT_GAS)) + metadata["gasLimit"] = maxFee.Uint64() + + copy(calldata[64+recipientAddressLength.Int64():96+recipientAddressLength.Int64()], common.LeftPadBytes(maxFee.Bytes(), 32)) payload = append(payload, calldata[64+recipientAddressLength.Int64():]) } diff --git a/chains/evm/listener/depositHandlers/erc20_test.go b/chains/evm/listener/depositHandlers/erc20_test.go index 0fa21251..167077e3 100644 --- a/chains/evm/listener/depositHandlers/erc20_test.go +++ b/chains/evm/listener/depositHandlers/erc20_test.go @@ -37,8 +37,11 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() { optionalMessage := common.LeftPadBytes(maxFee.Bytes(), 32) optionalMessage = append(optionalMessage, []byte("optionalMessage")...) + optionalMessageWithRevertGas := common.LeftPadBytes(new(big.Int).Add(maxFee, big.NewInt(depositHandlers.OPTIONAL_REVERT_GAS)).Bytes(), 32) + optionalMessageWithRevertGas = append(optionalMessageWithRevertGas, []byte("optionalMessage")...) + metadata := make(map[string]interface{}) - metadata["gasLimit"] = uint64(200000) + metadata["gasLimit"] = uint64(300000) calldata := evm.ConstructErc20DepositData(recipientByteSlice, big.NewInt(2)) calldata = append(calldata, optionalMessage...) @@ -65,7 +68,7 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() { Payload: []interface{}{ amountParsed, recipientAddressParsed, - optionalMessage, + optionalMessageWithRevertGas, }, Type: transfer.FungibleTransfer, Metadata: metadata,