Skip to content

Commit

Permalink
fix: add optional revert gas to max fee set by user (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 authored Dec 4, 2024
1 parent ae06d67 commit aacf99a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion chains/evm/listener/depositHandlers/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():])
}

Expand Down
7 changes: 5 additions & 2 deletions chains/evm/listener/depositHandlers/erc20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -65,7 +68,7 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() {
Payload: []interface{}{
amountParsed,
recipientAddressParsed,
optionalMessage,
optionalMessageWithRevertGas,
},
Type: transfer.FungibleTransfer,
Metadata: metadata,
Expand Down

0 comments on commit aacf99a

Please sign in to comment.