Skip to content

Commit

Permalink
Parse gas limit when using erc20 with additional data
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 committed Aug 29, 2024
1 parent f772280 commit 168b450
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Sygma Devnet
on:
push:
branches:
- main
- mpetrun5/erc20-additional-data

env:
ENVIRONMENT: STAGE
Expand Down
7 changes: 5 additions & 2 deletions chains/evm/listener/depositHandlers/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
10 changes: 8 additions & 2 deletions chains/evm/listener/depositHandlers/erc20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -60,7 +65,8 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() {
recipientAddressParsed,
optionalMessage,
},
Type: transfer.FungibleTransfer,
Type: transfer.FungibleTransfer,
Metadata: metadata,
},
Type: transfer.TransferMessageType,
ID: "messageID",
Expand Down

0 comments on commit 168b450

Please sign in to comment.