Skip to content

Commit

Permalink
Move addresses to own package
Browse files Browse the repository at this point in the history
...to avoid circular dependencies.
  • Loading branch information
karlb committed May 29, 2024
1 parent c9116b5 commit 1cc16d1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package contracts
package addresses

import "github.com/ethereum/go-ethereum/common"

Expand Down
3 changes: 2 additions & 1 deletion contracts/fee_currencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/contracts/addresses"
"github.com/ethereum/go-ethereum/contracts/celo/abigen"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -114,7 +115,7 @@ func CreditFees(
// GetExchangeRates returns the exchange rates for all gas currencies from CELO
func GetExchangeRates(caller bind.ContractCaller) (common.ExchangeRates, error) {
exchangeRates := map[common.Address]*big.Rat{}
directory, err := abigen.NewFeeCurrencyDirectoryCaller(FeeCurrencyDirectoryAddress, caller)
directory, err := abigen.NewFeeCurrencyDirectoryCaller(addresses.FeeCurrencyDirectoryAddress, caller)
if err != nil {
return exchangeRates, fmt.Errorf("Failed to access FeeCurrencyDirectory: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion core/blockchain_celo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/common/exchange"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/contracts"
"github.com/ethereum/go-ethereum/contracts/addresses"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -137,7 +138,7 @@ func testNativeTransferWithFeeCurrency(t *testing.T, scheme string, feeCurrencyA
}

// 5: Check that base fee has been moved to the fee handler.
actual, _ = contracts.GetBalanceERC20(&backend, contracts.FeeHandlerAddress, feeCurrencyAddr)
actual, _ = contracts.GetBalanceERC20(&backend, addresses.FeeHandlerAddress, feeCurrencyAddr)
expected = new(big.Int).SetUint64(block.GasUsed() * baseFeeInFeeCurrency.Uint64())
if actual.Cmp(expected) != 0 {
t.Fatalf("fee handler balance incorrect: expected %d, got %d", expected, actual)
Expand Down
8 changes: 4 additions & 4 deletions core/celo_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/contracts"
"github.com/ethereum/go-ethereum/contracts/addresses"
"github.com/ethereum/go-ethereum/contracts/celo"
"github.com/ethereum/go-ethereum/crypto"
)
Expand Down Expand Up @@ -95,7 +95,7 @@ func celoGenesisAccounts(fundedAddr common.Address) GenesisAlloc {
panic("Couldn not set faucet balance!")
}
genesisAccounts := map[common.Address]GenesisAccount{
contracts.RegistryAddress: { // Registry Proxy
addresses.RegistryAddress: { // Registry Proxy
Code: proxyBytecode,
Storage: map[common.Hash]common.Hash{
common.HexToHash("0x0"): DevAddr32, // `_owner` slot in Registry contract
Expand All @@ -108,7 +108,7 @@ func celoGenesisAccounts(fundedAddr common.Address) GenesisAlloc {
Code: registryBytecode,
Balance: big.NewInt(0),
},
contracts.GoldTokenAddress: { // GoldToken Proxy
addresses.GoldTokenAddress: { // GoldToken Proxy
Code: proxyBytecode,
Storage: map[common.Hash]common.Hash{
proxy_implementation_slot: common.HexToHash("0xce13"),
Expand Down Expand Up @@ -176,7 +176,7 @@ func celoGenesisAccounts(fundedAddr common.Address) GenesisAlloc {
// add entries to currencyConfig mapping
addFeeCurrencyToStorage(DevFeeCurrencyAddr, mockOracleAddr, feeCurrencyDirectoryStorage)
addFeeCurrencyToStorage(DevFeeCurrencyAddr2, mockOracleAddr2, feeCurrencyDirectoryStorage)
genesisAccounts[contracts.FeeCurrencyDirectoryAddress] = GenesisAccount{
genesisAccounts[addresses.FeeCurrencyDirectoryAddress] = GenesisAccount{
Code: feeCurrencyDirectoryBytecode,
Balance: big.NewInt(0),
Storage: feeCurrencyDirectoryStorage,
Expand Down
3 changes: 2 additions & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/common/exchange"
cmath "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/contracts"
"github.com/ethereum/go-ethereum/contracts/addresses"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
Expand Down Expand Up @@ -726,7 +727,7 @@ func (st *StateTransition) distributeTxFees() error {
tipTxFee := new(big.Int).Sub(totalTxFee, baseTxFee)

feeCurrency := st.msg.FeeCurrency
feeHandlerAddress := contracts.FeeHandlerAddress
feeHandlerAddress := addresses.FeeHandlerAddress

log.Trace("distributeTxFees", "from", from, "refund", refund, "feeCurrency", st.msg.FeeCurrency,
"coinbaseFeeRecipient", st.evm.Context.Coinbase, "coinbaseFee", tipTxFee,
Expand Down
5 changes: 2 additions & 3 deletions core/vm/celo_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/contracts/addresses"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
)

var GoldTokenAddress = common.HexToAddress("0x471ece3750da237f93b8e339c536989b8978a438")

type CeloPrecompiledContract interface {
RequiredGas(input []byte) uint64 // RequiredGas calculates the contract gas use
Run(input []byte, ctx *celoPrecompileContext) ([]byte, error) // Run runs the precompiled contract
Expand Down Expand Up @@ -48,7 +47,7 @@ func celoPrecompileAddress(index byte) common.Address {
}

func (ctx *celoPrecompileContext) IsCallerGoldToken() (bool, error) {
return GoldTokenAddress == ctx.caller, nil
return addresses.GoldTokenAddress == ctx.caller, nil
}

// Native transfer contract to make Celo Gold ERC20 compatible.
Expand Down
3 changes: 2 additions & 1 deletion core/vm/celo_contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/contracts/addresses"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestPrecompileTransfer(t *testing.T) {
name: "Test transfer with short input",
args: args{
input: []byte("0000"),
ctx: NewContext(GoldTokenAddress, mockEVM),
ctx: NewContext(addresses.GoldTokenAddress, mockEVM),
},
wantErr: true,
expectedErr: "invalid input length",
Expand Down

0 comments on commit 1cc16d1

Please sign in to comment.