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

Make the Addresses dynamic based on #7

Open
Evan-Kim2028 opened this issue Dec 27, 2024 · 0 comments
Open

Make the Addresses dynamic based on #7

Evan-Kim2028 opened this issue Dec 27, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Evan-Kim2028
Copy link
Collaborator

Problem

The testnet addresses on mev-commit testnet are hard coded into the contracts.go folder. It is used to retrieve the streamed opened commitment events to get feedback on whether the commitment was accepted or not.

Goal

Refactor to be able to dynamically fetch the address based on a variable "testnet" or "mainnet". This is already done in the bidder node script here. Can use it as a starting point.

https://github.com/primev/bidder_node_docker/blob/main/entrypoint.sh

contracts.go

var (
	BidderRegistryAddress common.Address
	BlockTrackerAddress   common.Address
	PreconfManagerAddress common.Address
)

func init() {
	// Load custom environment file if specified, otherwise default to .env
	envFile := os.Getenv("ENV_FILE")
	if envFile == "" {
		envFile = ".env" // default to .env if ENV_FILE is not set
	}

	if _, err := os.Stat(envFile); err == nil {
		if err := loadEnvFile(envFile); err != nil {
			slog.Error("Error loading .env file",
				"err", err,
				"env_file", envFile,
			)
			return
		}
	}

	// Read environment variables with default values
	bidderRegistry := os.Getenv("BIDDER_REGISTRY_ADDRESS")
	if bidderRegistry == "" {
		bidderRegistry = "0x401B3287364f95694c43ACA3252831cAc02e5C41"
	}
	BidderRegistryAddress = common.HexToAddress(bidderRegistry)

	blockTracker := os.Getenv("BLOCK_TRACKER_ADDRESS")
	if blockTracker == "" {
		blockTracker = "0x7538F3AaA07dA1990486De21A0B438F55e9639e4"
	}
	BlockTrackerAddress = common.HexToAddress(blockTracker)

	preconfManager := os.Getenv("PRECONF_MANAGER_ADDRESS")
	if preconfManager == "" {
		preconfManager = "0x9433bCD9e89F923ce587f7FA7E39e120E93eb84D"
	}
	PreconfManagerAddress = common.HexToAddress(preconfManager)

	// // Log loaded contract addresses
	// slog.Info("Loaded contract addresses",
	// 	"BidderRegistry", BidderRegistryAddress.Hex(),
	// 	"BlockTracker", BlockTrackerAddress.Hex(),
	// 	"PreconfManager", PreconfManagerAddress.Hex(),
	// )
}```
@Evan-Kim2028 Evan-Kim2028 added the enhancement New feature or request label Dec 27, 2024
@Evan-Kim2028 Evan-Kim2028 self-assigned this Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant