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

imp(erc20): ERC-20 registration #1997

Merged
merged 32 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b68995a
imp(erc20): ERC-20 registration
fedekunze Nov 4, 2023
83bc196
Merge branch 'main' into fedekunze/erc20-registration
MalteHerrmann Nov 10, 2023
d16fc6f
add changelog entry
MalteHerrmann Nov 10, 2023
8de2dd5
use bankkeeper import instead of erc20 types bank keeper interface in…
MalteHerrmann Nov 10, 2023
df23222
fix instantiation of erc20 keeper
MalteHerrmann Nov 10, 2023
6226516
fix checking for duplicate precompiles
MalteHerrmann Nov 10, 2023
a33420c
regenerate mocks for EVM and bank keepers using mockery
MalteHerrmann Nov 10, 2023
7423713
add instructions for mockery usage
MalteHerrmann Nov 10, 2023
110c481
run make format
MalteHerrmann Nov 10, 2023
2ed03eb
adjust comment
MalteHerrmann Nov 10, 2023
57fff81
rename IsRegistered to IsActivePrecompile and add IsAvailablePrecompi…
MalteHerrmann Nov 10, 2023
4c86af2
address linter
MalteHerrmann Nov 10, 2023
a711ec5
add IsAvailablePrecompile to interface and regenerate mock
MalteHerrmann Nov 10, 2023
bd4b98f
run make format
MalteHerrmann Nov 10, 2023
f181e1f
add tests to AddEVMExtension and GetAvailablePrecompileAddrs utility
MalteHerrmann Nov 10, 2023
c3ec0db
add tests for IsActivePrecompile
MalteHerrmann Nov 10, 2023
6dafc92
fix linter
MalteHerrmann Nov 10, 2023
1a3cbbf
check that active precompiles in params are sorted
MalteHerrmann Nov 10, 2023
85cff21
sort the active precompiles when setting parameters
MalteHerrmann Nov 10, 2023
bc63af1
improve getting available precompile addrs by pre allocating full slice
MalteHerrmann Nov 10, 2023
c541385
address linter
MalteHerrmann Nov 10, 2023
2266ac8
add test for adding multiple EVM extensions at once
MalteHerrmann Nov 10, 2023
7c869b1
add tests for RegisterERC20Extensions
MalteHerrmann Nov 10, 2023
00492f2
return with error from IterateTokenPairs instead of panic
MalteHerrmann Nov 10, 2023
3af5e66
address linter
MalteHerrmann Nov 10, 2023
410fda5
Update x/erc20/types/mocks/README.md
MalteHerrmann Nov 10, 2023
b20dc6a
fix test
MalteHerrmann Nov 10, 2023
409b071
error on iteration
fedekunze Nov 12, 2023
99fcd53
sort map addr
fedekunze Nov 12, 2023
914aeda
fix adding WERC20 precompile for evm denomination
MalteHerrmann Nov 13, 2023
71ad335
tests refactor
MalteHerrmann Nov 13, 2023
a2149c6
add test for multiple added precompiles with duplicates
MalteHerrmann Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (erc20) [#1993](https://github.com/evmos/evmos/pull/1993) Add ERC-20 Precompile transactions.
- (erc20) [#1995](https://github.com/evmos/evmos/pull/1995) Add ERC-20 precompile approvals and authorizations.
- (osmosis-outpost) [#1986](https://github.com/evmos/evmos/pull/1986) Add Osmosis outpost transaction.
- (erc20) [#1997](https://github.com/evmos/evmos/pull/1997) Add logic for ERC-20 precompile registration.

### Improvements

Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ func NewEvmos(
app.Erc20Keeper = erc20keeper.NewKeeper(
keys[erc20types.StoreKey], appCodec, authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.EvmKeeper, app.StakingKeeper, app.ClaimsKeeper,
app.AuthzKeeper, &app.TransferKeeper,
)

app.IncentivesKeeper = incentiveskeeper.NewKeeper(
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v15/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *UpgradesTestSuite) TestEnableEIPs() {
extraEIPs: []int64{3860},
expEIPs: []int64{},
expPass: false,
errContains: "is not activateable, valid EIPS are",
errContains: "is not activateable, valid EIPs are",
},
}

Expand Down
6 changes: 3 additions & 3 deletions precompiles/outposts/osmosis/osmosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

storetypes "github.com/cosmos/cosmos-sdk/store/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/ethereum/go-ethereum/accounts/abi"
Expand All @@ -17,7 +18,6 @@ import (
cmn "github.com/evmos/evmos/v15/precompiles/common"
"github.com/evmos/evmos/v15/precompiles/ics20"
erc20keeper "github.com/evmos/evmos/v15/x/erc20/keeper"
erc20types "github.com/evmos/evmos/v15/x/erc20/types"
transferkeeper "github.com/evmos/evmos/v15/x/ibc/transfer/keeper"
)

Expand Down Expand Up @@ -54,7 +54,7 @@ type Precompile struct {
osmosisXCSContract string

// Keepers
bankKeeper erc20types.BankKeeper
bankKeeper bankkeeper.Keeper
transferKeeper transferkeeper.Keeper
stakingKeeper stakingkeeper.Keeper
erc20Keeper erc20keeper.Keeper
Expand All @@ -65,7 +65,7 @@ type Precompile struct {
func NewPrecompile(
portID, channelID string,
osmosisXCSContract string,
bankKeeper erc20types.BankKeeper,
bankKeeper bankkeeper.Keeper,
transferKeeper transferkeeper.Keeper,
stakingKeeper stakingkeeper.Keeper,
erc20Keeper erc20keeper.Keeper,
Expand Down
2 changes: 1 addition & 1 deletion precompiles/werc20/werc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// abiPath defines the path to the WERC-20 precompile ABI JSON file.
const abiPath = "./abi.json"
const abiPath = "abi.json"

// Embed abi json file to the executable binary. Needed when importing as dependency.
//
Expand Down
27 changes: 18 additions & 9 deletions x/erc20/keeper/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/evmos/evmos/v15/contracts"
"github.com/evmos/evmos/v15/x/erc20/keeper"
"github.com/evmos/evmos/v15/x/erc20/types"
erc20mocks "github.com/evmos/evmos/v15/x/erc20/types/mocks"
)

func (suite *KeeperTestSuite) TestQueryERC20() {
Expand Down Expand Up @@ -53,7 +54,7 @@ func (suite *KeeperTestSuite) TestQueryERC20() {
}

func (suite *KeeperTestSuite) TestBalanceOf() {
var mockEVMKeeper *MockEVMKeeper
var mockEVMKeeper *erc20mocks.EVMKeeper
contract := utiltx.GenerateAddress()
testCases := []struct {
name string
Expand Down Expand Up @@ -90,12 +91,14 @@ func (suite *KeeperTestSuite) TestBalanceOf() {
}
for _, tc := range testCases {
suite.SetupTest() // reset
mockEVMKeeper = &MockEVMKeeper{}
mockEVMKeeper = &erc20mocks.EVMKeeper{}
suite.app.Erc20Keeper = keeper.NewKeeper(
suite.app.GetKey("erc20"), suite.app.AppCodec(),
authtypes.NewModuleAddress(govtypes.ModuleName),
suite.app.AccountKeeper, suite.app.BankKeeper,
mockEVMKeeper, suite.app.StakingKeeper, suite.app.ClaimsKeeper)
mockEVMKeeper, suite.app.StakingKeeper, suite.app.ClaimsKeeper,
s.app.AuthzKeeper, &s.app.TransferKeeper,
)

tc.malleate()

Expand Down Expand Up @@ -240,7 +243,7 @@ func (suite *KeeperTestSuite) TestCallEVMWithData() {
}

func (suite *KeeperTestSuite) TestForceFail() {
var mockEVMKeeper *MockEVMKeeper
var mockEVMKeeper *erc20mocks.EVMKeeper
erc20 := contracts.ERC20MinterBurnerDecimalsContract.ABI
testCases := []struct {
name string
Expand Down Expand Up @@ -279,11 +282,13 @@ func (suite *KeeperTestSuite) TestForceFail() {
for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
suite.SetupTest() // reset
mockEVMKeeper = &MockEVMKeeper{}
mockEVMKeeper = &erc20mocks.EVMKeeper{}
suite.app.Erc20Keeper = keeper.NewKeeper(
suite.app.GetKey("erc20"), suite.app.AppCodec(),
authtypes.NewModuleAddress(govtypes.ModuleName), suite.app.AccountKeeper,
suite.app.BankKeeper, mockEVMKeeper, suite.app.StakingKeeper, suite.app.ClaimsKeeper)
suite.app.BankKeeper, mockEVMKeeper, suite.app.StakingKeeper, suite.app.ClaimsKeeper,
s.app.AuthzKeeper, &s.app.TransferKeeper,
)

tc.malleate()

Expand All @@ -304,7 +309,7 @@ func (suite *KeeperTestSuite) TestForceFail() {
}

func (suite *KeeperTestSuite) TestQueryERC20ForceFail() {
var mockEVMKeeper *MockEVMKeeper
var mockEVMKeeper *erc20mocks.EVMKeeper
contract := utiltx.GenerateAddress()
testCases := []struct {
name string
Expand Down Expand Up @@ -368,11 +373,15 @@ func (suite *KeeperTestSuite) TestQueryERC20ForceFail() {
}
for _, tc := range testCases {
suite.SetupTest() // reset
mockEVMKeeper = &MockEVMKeeper{}

// TODO: what's the reason we are using mockEVMKeeper here? Instead of just passing the suite.app.EvmKeeper?
mockEVMKeeper = &erc20mocks.EVMKeeper{}
suite.app.Erc20Keeper = keeper.NewKeeper(
suite.app.GetKey("erc20"), suite.app.AppCodec(),
authtypes.NewModuleAddress(govtypes.ModuleName), suite.app.AccountKeeper,
suite.app.BankKeeper, mockEVMKeeper, suite.app.StakingKeeper, suite.app.ClaimsKeeper)
suite.app.BankKeeper, mockEVMKeeper, suite.app.StakingKeeper, suite.app.ClaimsKeeper,
s.app.AuthzKeeper, &s.app.TransferKeeper,
)

tc.malleate()

Expand Down
2 changes: 2 additions & 0 deletions x/erc20/keeper/ibc_callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
suite.app.EvmKeeper,
suite.app.StakingKeeper,
suite.app.ClaimsKeeper,
suite.app.AuthzKeeper,
&suite.app.TransferKeeper,
)

// Fund receiver account with EVMOS, ERC20 coins and IBC vouchers
Expand Down
37 changes: 23 additions & 14 deletions x/erc20/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
transferkeeper "github.com/evmos/evmos/v15/x/ibc/transfer/keeper"

"github.com/evmos/evmos/v15/x/erc20/types"
)
Expand All @@ -21,11 +24,13 @@ type Keeper struct {
// the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account.
authority sdk.AccAddress

accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
evmKeeper types.EVMKeeper
stakingKeeper types.StakingKeeper
claimsKeeper types.ClaimsKeeper
accountKeeper types.AccountKeeper
bankKeeper bankkeeper.Keeper
evmKeeper types.EVMKeeper
stakingKeeper types.StakingKeeper
claimsKeeper types.ClaimsKeeper
authzKeeper authzkeeper.Keeper
transferKeeper *transferkeeper.Keeper
}

// NewKeeper creates new instances of the erc20 Keeper
Expand All @@ -34,25 +39,29 @@ func NewKeeper(
cdc codec.BinaryCodec,
authority sdk.AccAddress,
ak types.AccountKeeper,
bk types.BankKeeper,
bk bankkeeper.Keeper,
evmKeeper types.EVMKeeper,
sk types.StakingKeeper,
ck types.ClaimsKeeper,
authzKeeper authzkeeper.Keeper,
transferKeeper *transferkeeper.Keeper,
) Keeper {
// ensure gov module account is set and is not nil
if err := sdk.VerifyAddressFormat(authority); err != nil {
panic(err)
}

return Keeper{
authority: authority,
storeKey: storeKey,
cdc: cdc,
accountKeeper: ak,
bankKeeper: bk,
evmKeeper: evmKeeper,
stakingKeeper: sk,
claimsKeeper: ck,
authority: authority,
storeKey: storeKey,
cdc: cdc,
accountKeeper: ak,
bankKeeper: bk,
evmKeeper: evmKeeper,
stakingKeeper: sk,
claimsKeeper: ck,
authzKeeper: authzKeeper,
transferKeeper: transferKeeper,
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/erc20/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (suite *KeeperTestSuite) TestMigrations() {
legacySubspace.GetParamSetIfExists(ctx, &outputParams)

// Added dummy keeper in order to use the test store and store key
mockKeeper := erc20keeper.NewKeeper(storeKey, nil, authtypes.NewModuleAddress(govtypes.ModuleName), nil, nil, nil, nil, nil)
mockKeeper := erc20keeper.NewKeeper(storeKey, nil, authtypes.NewModuleAddress(govtypes.ModuleName), nil, nil, nil, nil, nil, s.app.AuthzKeeper, nil)
mockSubspace := newMockSubspace(v3types.DefaultParams(), storeKey, tKey)
migrator := erc20keeper.NewMigrator(mockKeeper, mockSubspace)

Expand Down
106 changes: 0 additions & 106 deletions x/erc20/keeper/mock_test.go

This file was deleted.