Skip to content

Commit

Permalink
Update chainIds type
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Jan 18, 2024
1 parent 58f3a2f commit e68713a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
36 changes: 18 additions & 18 deletions pkg/chain/chain_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ type NetworkType struct {
}

type L2ChainIDs struct {
OPTIMISM int
OPTIMISM_GOERLI int
OPTIMISM_HARDHAT_LOCAL int
OPTIMISM_HARDHAT_DEVNET int
OPTIMISM_BEDROCK_LOCAL_DEVNET int
OPTIMISM_BEDROCK_ALPHA_TESTNET int
BASE_GOERLI int
ZORA_GOERLI int
ZORA_MAINNET int
OPTIMISM_SEPOLIA int
BASE_SEPOLIA int
BASE_MAINNET int
OPTIMISM uint64
OPTIMISM_GOERLI uint64
OPTIMISM_HARDHAT_LOCAL uint64
OPTIMISM_HARDHAT_DEVNET uint64
OPTIMISM_BEDROCK_LOCAL_DEVNET uint64
OPTIMISM_BEDROCK_ALPHA_TESTNET uint64
BASE_GOERLI uint64
ZORA_GOERLI uint64
ZORA_MAINNET uint64
OPTIMISM_SEPOLIA uint64
BASE_SEPOLIA uint64
BASE_MAINNET uint64
}

var L2_CHAIN_ID = L2ChainIDs{
Expand Down Expand Up @@ -78,10 +78,10 @@ var OPTIMISM_PORTAL_ADDRESS = NetworkType{
}

type L1Contracts struct {
L1CrossDomainMessenger string
StateCommitmentChain string
OptimismPortal string
L2OutputOracle string
L1CrossDomainMessenger string `json:"l1CrossDomainMessenger"`
StateCommitmentChain string `json:"StateCommitmentChain"`
OptimismPortal string `json:"OptimismPortal"`
L2OutputOracle string `json:"l2OutputOracle"`
}

type ContractAddresses struct {
Expand Down Expand Up @@ -120,8 +120,8 @@ func getL1ContractsByNetworkName(network string) L1Contracts {
return L1Contracts
}

func getContractAddresses() map[int]map[string]L1Contracts {
CONTRACT_ADDRESSES := map[int]map[string]L1Contracts{
func getContractAddresses() map[uint64]map[string]L1Contracts {
CONTRACT_ADDRESSES := map[uint64]map[string]L1Contracts{
L2_CHAIN_ID.OPTIMISM: {
"l1": getL1ContractsByNetworkName("mainnet"),
// "l2": DEFAULT_L2_CONTRACT_ADDRESS,
Expand Down
12 changes: 6 additions & 6 deletions pkg/chain/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
)

func GetOracleAddressbyChainID(l2ChainID int) string {
func GetL1OracleContractAddressbyChainID(chainID uint64) string {
ContractAddresses := getContractAddresses()
address := ContractAddresses[l2ChainID]["l1"].L2OutputOracle
address := ContractAddresses[chainID]["l1"].L2OutputOracle
return address
}

// TODO: Create oracle Struct with required functions
func OracleContractInstance(client *ethclient.Client, l2ChainID int, log log.Logger) (*bindings.L2OutputOracle, error) {
oracleContractAddress := GetOracleAddressbyChainID(l2ChainID)
func OracleContractInstance(client *ethclient.Client, chainID uint64, log log.Logger) (*bindings.L2OutputOracle, error) {
oracleContractAddress := GetL1OracleContractAddressbyChainID(chainID)

contract, err := bindings.NewL2OutputOracle(common.HexToAddress(oracleContractAddress), client)

Expand All @@ -31,14 +31,14 @@ func OracleContractInstance(client *ethclient.Client, l2ChainID int, log log.Log
}

// TODO: Use EthClientInterface
func CreateContractInstance(url string, l2ChainID int, logger log.Logger) *bindings.L2OutputOracle {
func CreateContractInstance(url string, chainID uint64, logger log.Logger) *bindings.L2OutputOracle {
client, err := ethclient.Dial(url)

if err != nil {
logger.Errorf("Error occurred while connecting %w", err)
}

contract, err := OracleContractInstance(client, l2ChainID, logger)
contract, err := OracleContractInstance(client, chainID, logger)

if err != nil {
logger.Errorf("Error occurred while creating contract instance %w", err)
Expand Down

0 comments on commit e68713a

Please sign in to comment.