Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support EURC #120

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include version.mk

DOCKER_COMPOSE := docker-compose -f docker-compose.yml
DOCKER_COMPOSE := docker compose -f docker-compose.yml
DOCKER_COMPOSE_STATE_DB := zkevm-state-db
DOCKER_COMPOSE_POOL_DB := zkevm-pool-db
DOCKER_COMPOSE_RPC_DB := zkevm-rpc-db
Expand Down
1 change: 1 addition & 0 deletions cmd/run_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func startServer(ctx *cli.Context, opts ...runOptionFunc) error {

messagebridge.InitUSDCLxLyProcessor(c.BusinessConfig.USDCContractAddresses, c.BusinessConfig.USDCTokenAddresses)
messagebridge.InitWstETHProcessor(c.BusinessConfig.WstETHContractAddresses, c.BusinessConfig.WstETHTokenAddresses)
messagebridge.InitEURCProcessor(c.BusinessConfig.EURCContractAddresses, c.BusinessConfig.EURCTokenAddresses)

l1ChainId := c.Etherman.L1ChainId
l2ChainIds := c.Etherman.L2ChainIds
Expand Down
2 changes: 2 additions & 0 deletions config/businessconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ type Config struct {
USDCTokenAddresses []common.Address `mapstructure:"USDCTokenAddresses"`
WstETHContractAddresses []common.Address `mapstructure:"WstETHContractAddresses"`
WstETHTokenAddresses []common.Address `mapstructure:"WstETHTokenAddresses"`
EURCContractAddresses []common.Address `mapstructure:"EURCContractAddresses"`
EURCTokenAddresses []common.Address `mapstructure:"EURCTokenAddresses"`
}
39 changes: 39 additions & 0 deletions utils/messagebridge/eurc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package messagebridge

import (
"math/big"

"github.com/0xPolygonHermez/zkevm-bridge-service/log"
"github.com/ethereum/go-ethereum/common"
)

func InitEURCProcessor(eurcContractAddresses, eurcTokenAddresses []common.Address) {
log.Debugf("EURCMapping: contracts[%v] tokens[%v]", eurcContractAddresses, eurcTokenAddresses)
if len(eurcContractAddresses) != len(eurcTokenAddresses) {
log.Errorf("InitEURCProcessor: contract addresses (%v) and token addresses (%v) have different length", len(eurcContractAddresses), len(eurcTokenAddresses))
}

contractToTokenMapping := make(map[common.Address]common.Address)
l := min(len(eurcContractAddresses), len(eurcTokenAddresses))
for i := 0; i < l; i++ {
if eurcTokenAddresses[i] == emptyAddress {
continue
}
contractToTokenMapping[eurcContractAddresses[i]] = eurcTokenAddresses[i]
}

if len(contractToTokenMapping) > 0 {
processorMap[EURC] = &Processor{
contractToTokenMapping: contractToTokenMapping,
contractAddressList: eurcContractAddresses,
tokenAddressList: eurcTokenAddresses,
DecodeMetadataFn: func(metadata []byte) (common.Address, *big.Int) {
// Metadata structure:
// - Destination address: 32 bytes
// - Bridging amount: 32 bytes
// Maybe there's a more elegant way?
return common.BytesToAddress(metadata[:32]), new(big.Int).SetBytes(metadata[32:]) //nolint:gomnd
},
}
}
}
1 change: 1 addition & 0 deletions utils/messagebridge/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ProcessorType int
const (
USDC ProcessorType = iota
WstETH
EURC
)

var (
Expand Down
Loading