Skip to content

Commit

Permalink
Add an ERC20 fee currency for testing purposes (#71)
Browse files Browse the repository at this point in the history
* Add an ERC20 gas token for testing purposes

This is a copy of OpenZeppelin's ERC20 with added credit/debitGasFees
functions. Inheriting from ERC20 does not work due to the need to access
the private _balances and _totalSupply fields.

* lint fix

* Initialize FeeCurrency

* test fix

* immutables test fix

* duplicate removal

* Change address

* test fixes

* another test fix

---------

Co-authored-by: pahor167 <47992132+pahor167@users.noreply.github.com>
  • Loading branch information
karlb and pahor167 authored Oct 16, 2023
1 parent bc7ee48 commit 7d2655a
Show file tree
Hide file tree
Showing 9 changed files with 1,329 additions and 3 deletions.
3 changes: 2 additions & 1 deletion op-bindings/artifacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
"MentoFeeHandlerSeller",
"UniswapFeeHandlerSeller",
"SortedOracles",
"AddressSortedLinkedListWithMedian"
"AddressSortedLinkedListWithMedian",
"FeeCurrency"
]
843 changes: 843 additions & 0 deletions op-bindings/bindings/feecurrency.go

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions op-bindings/bindings/feecurrency_more.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions op-bindings/predeploys/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
UniswapFeeHandlerSeller = "0xd3aee28548dbb65df03981f0dc0713bfcbd10a97"
SortedOracles = "0xefb84935239dacdecf7c5ba76d8de40b077b7b33"
AddressSortedLinkedListWithMedian = "0xED477A99035d0c1e11369F1D7A4e587893cc002B"
FeeCurrency = "0x4200000000000000000000000000000000001022"
)

var (
Expand Down Expand Up @@ -65,6 +66,7 @@ var (
UniswapFeeHandlerSellerAddr = common.HexToAddress(UniswapFeeHandlerSeller)
SortedOraclesAddr = common.HexToAddress(SortedOracles)
AddressSortedLinkedListWithMedianAddr = common.HexToAddress(AddressSortedLinkedListWithMedian)
FeeCurrencyAddr = common.HexToAddress(FeeCurrency)

Predeploys = make(map[string]*common.Address)
CeloPredeploys = make(map[string]*common.Address)
Expand Down Expand Up @@ -112,6 +114,7 @@ func init() {
Predeploys["UniswapFeeHandlerSeller"] = &UniswapFeeHandlerSellerAddr
Predeploys["SortedOracles"] = &SortedOraclesAddr
Predeploys["AddressSortedLinkedListWithMedian"] = &AddressSortedLinkedListWithMedianAddr
Predeploys["FeeCurrency"] = &FeeCurrencyAddr

CeloPredeploys[Predeploys["CeloRegistry"].String()] = Predeploys["CeloRegistry"]
CeloPredeploys[Predeploys["GoldToken"].String()] = Predeploys["GoldToken"]
Expand All @@ -121,4 +124,5 @@ func init() {
CeloPredeploys[Predeploys["UniswapFeeHandlerSeller"].String()] = Predeploys["UniswapFeeHandlerSeller"]
CeloPredeploys[Predeploys["SortedOracles"].String()] = Predeploys["SortedOracles"]
CeloPredeploys[Predeploys["AddressSortedLinkedListWithMedian"].String()] = Predeploys["AddressSortedLinkedListWithMedian"]
CeloPredeploys[Predeploys["FeeCurrency"].String()] = Predeploys["FeeCurrency"]
}
12 changes: 12 additions & 0 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ func NewL2ImmutableConfig(config *DeployConfig, block *types.Block) (immutables.
"minimumWithdrawalAmount": config.BaseFeeVaultMinimumWithdrawalAmount,
"withdrawalNetwork": config.BaseFeeVaultWithdrawalNetwork.ToUint8(),
}
immutable["FeeCurrency"] = immutables.ImmutableValues{
"name": "FeeCurrency",
"symbol": "FC",
}

return immutable, nil
}
Expand Down Expand Up @@ -779,6 +783,14 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
"_owner": config.ProxyAdminOwner,
"reportExpirySeconds": 600,
}
storage["FeeCurrency"] = state.StorageValues{
"_name": "FeeCurrency",
"_symbol": "FC",
"_totalSupply": 1000_000_000,
"_balances": map[any]any{
config.ProxyAdminOwner.String(): 1000_000_000,
},
}
return storage, nil
}

Expand Down
4 changes: 2 additions & 2 deletions op-chain-ops/genesis/layer_two_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestBuildL2MainnetGenesis(t *testing.T) {
config.EnableGovernance = true
config.FundDevAccounts = false
gen := testBuildL2Genesis(t, config)
require.Equal(t, 2337, len(gen.Alloc))
require.Equal(t, 2339, len(gen.Alloc))
}

func TestBuildL2MainnetNoGovernanceGenesis(t *testing.T) {
Expand All @@ -94,5 +94,5 @@ func TestBuildL2MainnetNoGovernanceGenesis(t *testing.T) {
config.EnableGovernance = false
config.FundDevAccounts = false
gen := testBuildL2Genesis(t, config)
require.Equal(t, 2337, len(gen.Alloc))
require.Equal(t, 2339, len(gen.Alloc))
}
16 changes: 16 additions & 0 deletions op-chain-ops/immutables/immutables.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ func BuildOptimism(immutable ImmutableConfig) (DeploymentResults, error) {
Name: "AddressSortedLinkedListWithMedian",
Args: []interface{}{},
},
{
Name: "FeeCurrency",
Args: []interface{}{
immutable["FeeCurrency"]["name"], immutable["FeeCurrency"]["symbol"], immutable["FeeCurrency"]["mintTo"],
},
},
}
return BuildL2(deployments)
}
Expand Down Expand Up @@ -307,6 +313,16 @@ func l2Deployer(backend *backends.SimulatedBackend, opts *bind.TransactOpts, dep
_, tx, _, err = bindings.DeploySortedOracles(opts, backend, false)
case "AddressSortedLinkedListWithMedian":
_, tx, _, err = bindings.DeployAddressSortedLinkedListWithMedian(opts, backend)
case "FeeCurrency":
name, ok := deployment.Args[0].(string)
if !ok {
return nil, fmt.Errorf("invalid fee currency name")
}
symbol, ok := deployment.Args[1].(string)
if !ok {
return nil, fmt.Errorf("invalid fee currency symbol")
}
_, tx, _, err = bindings.DeployFeeCurrency(opts, backend, name, symbol)
default:
return tx, fmt.Errorf("unknown contract: %s", deployment.Name)
}
Expand Down
5 changes: 5 additions & 0 deletions op-chain-ops/immutables/immutables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func TestBuildOptimism(t *testing.T) {
"minimumWithdrawalAmount": minimumWithdrawalAmount,
"withdrawalNetwork": uint8(0),
},
"FeeCurrency": {
"name": "FeeCurrency",
"symbol": "FC",
},
})
require.Nil(t, err)
require.NotNil(t, results)
Expand Down Expand Up @@ -113,6 +117,7 @@ func TestBuildOptimism(t *testing.T) {
"UniswapFeeHandlerSeller": true,
"SortedOracles": true,
"AddressSortedLinkedListWithMedian": true,
"FeeCurrency": true,
}

// Only the exact contracts that we care about are being
Expand Down
Loading

0 comments on commit 7d2655a

Please sign in to comment.