From 168b450caac8bfe2bfd11d91c6cdc692b2577556 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Thu, 29 Aug 2024 17:11:59 +0200 Subject: [PATCH] Parse gas limit when using erc20 with additional data --- .github/workflows/deploy_stage.yml | 2 +- chains/evm/listener/depositHandlers/erc20.go | 7 +++++-- chains/evm/listener/depositHandlers/erc20_test.go | 10 ++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy_stage.yml b/.github/workflows/deploy_stage.yml index fffb39f5..cc27aee2 100644 --- a/.github/workflows/deploy_stage.yml +++ b/.github/workflows/deploy_stage.yml @@ -6,7 +6,7 @@ name: Sygma Devnet on: push: branches: - - main + - mpetrun5/erc20-additional-data env: ENVIRONMENT: STAGE diff --git a/chains/evm/listener/depositHandlers/erc20.go b/chains/evm/listener/depositHandlers/erc20.go index 5d056f99..1ffa339e 100644 --- a/chains/evm/listener/depositHandlers/erc20.go +++ b/chains/evm/listener/depositHandlers/erc20.go @@ -44,17 +44,20 @@ func (dh *Erc20DepositHandler) HandleDeposit( recipientAddress, } + metadata := make(map[string]interface{}) // append optional message if it exists - if len(calldata) > int(64+recipientAddressLength.Int64()) { + if len(calldata) > int(96+recipientAddressLength.Int64()) { + metadata["gasLimit"] = new(big.Int).SetBytes(calldata[64+recipientAddressLength.Int64() : 96+recipientAddressLength.Int64()]).Uint64() payload = append(payload, calldata[64+recipientAddressLength.Int64():]) } + return message.NewMessage( sourceID, destID, transfer.TransferMessageData{ DepositNonce: nonce, ResourceId: resourceID, - Metadata: nil, + Metadata: metadata, Payload: payload, Type: transfer.FungibleTransfer, }, diff --git a/chains/evm/listener/depositHandlers/erc20_test.go b/chains/evm/listener/depositHandlers/erc20_test.go index e325a9b0..7ed00ff0 100644 --- a/chains/evm/listener/depositHandlers/erc20_test.go +++ b/chains/evm/listener/depositHandlers/erc20_test.go @@ -32,8 +32,13 @@ func TestRunErc20HandlerTestSuite(t *testing.T) { func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() { // 0xf1e58fb17704c2da8479a533f9fad4ad0993ca6b recipientByteSlice := []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107} + maxFee := big.NewInt(200000) + optionalMessage := common.LeftPadBytes(maxFee.Bytes(), 32) + optionalMessage = append(optionalMessage, []byte("optionalMessage")...) + + metadata := make(map[string]interface{}) + metadata["gasLimit"] = uint64(200000) - optionalMessage := []byte("optionalMessage") calldata := evm.ConstructErc20DepositData(recipientByteSlice, big.NewInt(2)) calldata = append(calldata, optionalMessage...) depositLog := &events.Deposit{ @@ -60,7 +65,8 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() { recipientAddressParsed, optionalMessage, }, - Type: transfer.FungibleTransfer, + Type: transfer.FungibleTransfer, + Metadata: metadata, }, Type: transfer.TransferMessageType, ID: "messageID",