Skip to content

Commit

Permalink
Merge pull request #2925 from irisnet/feature/support-erc20
Browse files Browse the repository at this point in the history
feat: enhance token module
  • Loading branch information
harvey-smith authored Apr 23, 2024
2 parents 04bc996 + ac3b20a commit 821beb8
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 49 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
### Features

* (IRISHub) [\#2908](https://github.com/irisnet/irishub/pull/2908) Add ICA module.
* (IRISHub) [\#2909](https://github.com/irisnet/irishub/pull/2909) Add cosmos LSM.
* (IRISHub) [\#2909](https://github.com/irisnet/irishub/pull/2909) Add Cosmos LSM module.
* (IRISHub) [\#2925](https://github.com/irisnet/irishub/pull/2925) Enhance token module.

### Improvements

Expand Down
41 changes: 23 additions & 18 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import (
mintkeeper "github.com/irisnet/irishub/v3/modules/mint/keeper"
minttypes "github.com/irisnet/irishub/v3/modules/mint/types"
iristypes "github.com/irisnet/irishub/v3/types"
"github.com/irisnet/irishub/v3/wrapper"
)

// AppKeepers defines a structure used to consolidate all
Expand Down Expand Up @@ -440,23 +441,6 @@ func New(
appKeepers.keys[guardiantypes.StoreKey],
)

appKeepers.TokenKeeper = tokenkeeper.NewKeeper(
appCodec,
appKeepers.keys[tokentypes.StoreKey],
appKeepers.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
).WithSwapRegistry(tokenv1.SwapRegistry{
iristypes.NativeToken.MinUnit: tokenv1.SwapParams{
MinUnit: iristypes.EvmToken.MinUnit,
Ratio: sdk.OneDec(),
},
iristypes.EvmToken.MinUnit: tokenv1.SwapParams{
MinUnit: iristypes.NativeToken.MinUnit,
Ratio: sdk.OneDec(),
},
})

appKeepers.RecordKeeper = recordkeeper.NewKeeper(
appCodec,
appKeepers.keys[recordtypes.StoreKey],
Expand Down Expand Up @@ -534,7 +518,7 @@ func New(
AddRoute(farmtypes.RouterKey, farm.NewCommunityPoolCreateFarmProposalHandler(appKeepers.FarmKeeper))

appKeepers.GovKeeper.SetHooks(govtypes.NewMultiGovHooks(
farmkeeper.NewGovHook(appKeepers.FarmKeeper),
wrapper.NewFarmGovHook(farmkeeper.NewGovHook(appKeepers.FarmKeeper)),
))

appKeepers.GovKeeper.SetLegacyRouter(govRouter)
Expand All @@ -561,6 +545,27 @@ func New(
cast.ToString(appOpts.Get(srvflags.EVMTracer)),
appKeepers.GetSubspace(evmtypes.ModuleName),
)

appKeepers.TokenKeeper = tokenkeeper.NewKeeper(
appCodec,
appKeepers.keys[tokentypes.StoreKey],
appKeepers.BankKeeper,
appKeepers.AccountKeeper,
wrapper.NewEVMKeeper(appKeepers.EvmKeeper),
wrapper.NewICS20Keeper(appKeepers.IBCTransferKeeper),
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
).WithSwapRegistry(tokenv1.SwapRegistry{
iristypes.NativeToken.MinUnit: tokenv1.SwapParams{
MinUnit: iristypes.EvmToken.MinUnit,
Ratio: sdk.OneDec(),
},
iristypes.EvmToken.MinUnit: tokenv1.SwapParams{
MinUnit: iristypes.NativeToken.MinUnit,
Ratio: sdk.OneDec(),
},
})
appKeepers.EvmKeeper = appKeepers.EvmKeeper.SetHooks(appKeepers.TokenKeeper.Hooks())
return appKeepers
}

Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/v300/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ var (
// the portion of a chain's total stake can be liquid
GlobalLiquidStakingCap = sdk.MustNewDecFromStr("0.25") // 25%

// BeaconContractAddress is the address of the beacon contract
BeaconContractAddress = ""

allowMessages = []string{"*"}
)
13 changes: 13 additions & 0 deletions app/upgrades/v300/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func upgradeHandlerConstructor(
if err := mergeEVM(ctx, box); err != nil {
return nil, err
}

if err := mergeToken(ctx, box); err != nil {
return nil, err
}
// initialize ICS27 module
initICAModule(ctx, m, fromVM)

Expand Down Expand Up @@ -71,3 +75,12 @@ func mergeEVM(ctx sdk.Context, box upgrades.Toolbox) error {
params.AllowUnprotectedTxs = true
return box.EvmKeeper.SetParams(ctx, params)
}

func mergeToken(ctx sdk.Context, box upgrades.Toolbox) error {
ctx.Logger().Info("start to run token module migrations...")

params := box.TokenKeeper.GetParams(ctx)
params.EnableErc20 = true
params.Beacon = BeaconContractAddress
return box.TokenKeeper.SetParams(ctx, params)
}
12 changes: 4 additions & 8 deletions cmd/iris/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,13 @@ func InitTestnet(
return err
}

accTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)
accStakingTokens := sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction)
accEvmTokens := sdk.TokensFromConsensusPower(5000, PowerReduction)
accIrisTokens := sdk.TokensFromConsensusPower(5000, sdk.DefaultPowerReduction)
accStakingTokens := sdk.TokensFromConsensusPower(15e8, sdk.DefaultPowerReduction)
accEvmTokens := sdk.TokensFromConsensusPower(5e8, PowerReduction)

coins := sdk.Coins{
sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), accTokens),
coins := sdk.NewCoins(
sdk.NewCoin(sdk.DefaultBondDenom, accStakingTokens),
sdk.NewCoin(iristypes.EvmToken.MinUnit, accEvmTokens),
sdk.NewCoin(nativeIrisMinUnit, accIrisTokens),
}
)

genBalances = append(
genBalances,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/cosmos/iavl v0.20.1 // indirect
github.com/cosmos/ibc-go/v7 v7.3.0
github.com/evmos/ethermint v0.22.0
github.com/irisnet/irismod v1.8.1-0.20240304075720-718d99d97674 //release/v1.8.0-lsm
github.com/irisnet/irismod v1.8.1-0.20240422082845-aafd2bd851f9 //release/v1.8.0-lsm
)

require (
Expand Down Expand Up @@ -232,6 +232,6 @@ require (
replace github.com/zondax/hid => github.com/zondax/hid v0.9.0

// use bianjieai fork of ethermint
replace github.com/evmos/ethermint => github.com/bianjieai/ethermint v0.22.0-irishub-20231207.0.20240403080035-de4b07ecf255 //release/v0.2…20231207-lsm
replace github.com/evmos/ethermint => github.com/bianjieai/ethermint v0.22.0-irishub-20231207.0.20240419023144-3cea3d782107 //release/v0.2…20231207-lsm

replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bianjieai/ethermint v0.22.0-irishub-20231207.0.20240403080035-de4b07ecf255 h1:Rngrww/saMItIkpSozg5poBQiRHsE52iZnio5zII8EQ=
github.com/bianjieai/ethermint v0.22.0-irishub-20231207.0.20240403080035-de4b07ecf255/go.mod h1:x9BFez6AUL9Yksv4zZd3QLmSazwOkyNd3h2zFV2B4RU=
github.com/bianjieai/ethermint v0.22.0-irishub-20231207.0.20240419023144-3cea3d782107 h1:ssrDDPlhLILV0UaQD+D/mRqAvQ5FeQrWB3lltaP5YTc=
github.com/bianjieai/ethermint v0.22.0-irishub-20231207.0.20240419023144-3cea3d782107/go.mod h1:x9BFez6AUL9Yksv4zZd3QLmSazwOkyNd3h2zFV2B4RU=
github.com/bianjieai/nft-transfer v1.1.3-ibc-v7.3.0 h1:399lErsTpI+faTerw5Q4OuVlXAmAQSuibVvxHR3C6OY=
github.com/bianjieai/nft-transfer v1.1.3-ibc-v7.3.0/go.mod h1:u2PNH4v8CD4AWU4Rf7yt8/qqQtrrwwHiw03qQSKERhg=
github.com/bianjieai/tibc-go v0.5.0 h1:/J1OQe4gwUUkS3Q6+nm0EsTY7MNAOPNzfnpvgIWlvKM=
Expand Down Expand Up @@ -846,8 +846,8 @@ github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19y
github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE=
github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0=
github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po=
github.com/irisnet/irismod v1.8.1-0.20240304075720-718d99d97674 h1:7fBGecB0olPrkoeY0Y7wn202BQ4Q2zF8o+KwYFzNYQs=
github.com/irisnet/irismod v1.8.1-0.20240304075720-718d99d97674/go.mod h1:kvPd2HckP0Mr4BZRtUa2RjDNH1EfOP3xHESHRIXayOY=
github.com/irisnet/irismod v1.8.1-0.20240422082845-aafd2bd851f9 h1:5uvIKhg55Y82su5FX3A4KT64sc89u0kEhacUMdhVIQc=
github.com/irisnet/irismod v1.8.1-0.20240422082845-aafd2bd851f9/go.mod h1:TQDhEmxqCIzo7OjyNy//UI0xKDuMtONjoy5LzUeRhVo=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU=
Expand Down
14 changes: 4 additions & 10 deletions modules/evm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
type Keeper struct {
evmkeeper *evmkeeper.Keeper
bankKeeper types.BankKeeper
hasHook bool
}

var _ types.MsgServer = &Keeper{}
Expand Down Expand Up @@ -139,15 +138,10 @@ func (k *Keeper) EthereumTx(
return response, nil
}

// SetHooks sets the hooks for the EVM module
// It should be called only once during initialization, it panic if called more than once.
func (k *Keeper) SetHooks(eh types.EvmHooks) *Keeper {
return &Keeper{
evmkeeper: k.evmkeeper.SetHooks(eh),
hasHook: true,
}
}

// UpdateParams updates the parameters for the EVM module.
//
// It takes a context.Context object and a *types.MsgUpdateParams object as parameters.
// The function returns a *types.MsgUpdateParamsResponse object and an error.
func (k *Keeper) UpdateParams(
goCtx context.Context,
msg *types.MsgUpdateParams,
Expand Down
2 changes: 1 addition & 1 deletion modules/evm/moudle.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewAppModule(
) AppModule {
return AppModule{
AppModule: ethermint.NewAppModule(k, ak, ss),
k: &Keeper{k, bankKeeper, false},
k: &Keeper{k, bankKeeper},
ss: ss,
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/evm/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction, fee
// snapshot to contain the tx processing and post processing in same scope
var commit func()
tmpCtx := ctx
if k.hasHook {
if k.evmkeeper.Hooks() != nil {
// Create a cache context to revert state when tx hooks fails,
// the cache context is only committed when both tx and hooks executed successfully.
// Didn't use `Snapshot` because the context stack has exponential complexity on certain operations,
Expand Down
3 changes: 2 additions & 1 deletion modules/mint/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -52,6 +53,6 @@ func (s *IntegrationTestSuite) TestMint() {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType))
params := respType.(*minttypes.Params)
s.Require().Equal("stake", params.MintDenom)
s.Require().Equal(sdk.DefaultBondDenom, params.MintDenom)
s.Require().Equal("0.040000000000000000", params.Inflation.String())
}
2 changes: 1 addition & 1 deletion modules/mint/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func RandomizedGenState(simState *module.SimulationState) {
func(r *rand.Rand) { inflation = GenInflation(r) },
)

params := types.Params{Inflation: inflation, MintDenom: types.MintDenom}
params := types.Params{Inflation: inflation, MintDenom: sdk.DefaultBondDenom}
mintGenesis := types.NewGenesisState(types.DefaultMinter(), params)

bz, err := json.MarshalIndent(&mintGenesis, "", " ")
Expand Down
3 changes: 1 addition & 2 deletions modules/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
// params store for inflation params
KeyInflation = []byte("Inflation")
KeyMintDenom = []byte("MintDenom")
MintDenom = sdk.DefaultBondDenom
)

// ParamTable for mint module
Expand All @@ -41,7 +40,7 @@ func NewParams(mintDenom string, inflation sdk.Dec) Params {
func DefaultParams() Params {
return Params{
Inflation: sdk.NewDecWithPrec(4, 2),
MintDenom: MintDenom,
MintDenom: sdk.DefaultBondDenom,
}
}

Expand Down
2 changes: 2 additions & 0 deletions types/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func init() {
Mintable: true,
Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).String(),
}
sdk.DefaultBondDenom = NativeToken.MinUnit


userHomeDir, err := os.UserHomeDir()
if err != nil {
Expand Down
53 changes: 53 additions & 0 deletions wrapper/farm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package wrapper

import (
"github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

farmkeeper "github.com/irisnet/irismod/modules/farm/keeper"
)

var _ govtypes.GovHooks = farmGovHook{}

type farmGovHook struct {
gh farmkeeper.GovHook
}

// NewFarmGovHook creates a new farmGovHook instance.
//
// It takes a parameter of type farmkeeper.GovHook and returns a farmGovHook.
func NewFarmGovHook(gh farmkeeper.GovHook) govtypes.GovHooks {
return farmGovHook{
gh: gh,
}
}

// AfterProposalDeposit implements types.GovHooks.
func (f farmGovHook) AfterProposalDeposit(ctx types.Context, proposalID uint64, depositorAddr types.AccAddress) error {
f.gh.AfterProposalDeposit(ctx, proposalID, depositorAddr)
return nil
}

// AfterProposalFailedMinDeposit implements types.GovHooks.
func (f farmGovHook) AfterProposalFailedMinDeposit(ctx types.Context, proposalID uint64) error {
f.gh.AfterProposalFailedMinDeposit(ctx, proposalID)
return nil
}

// AfterProposalSubmission implements types.GovHooks.
func (f farmGovHook) AfterProposalSubmission(ctx types.Context, proposalID uint64) error {
f.gh.AfterProposalSubmission(ctx, proposalID)
return nil
}

// AfterProposalVote implements types.GovHooks.
func (f farmGovHook) AfterProposalVote(ctx types.Context, proposalID uint64, voterAddr types.AccAddress) error {
f.gh.AfterProposalVote(ctx, proposalID,voterAddr)
return nil
}

// AfterProposalVotingPeriodEnded implements types.GovHooks.
func (f farmGovHook) AfterProposalVotingPeriodEnded(ctx types.Context, proposalID uint64) error {
f.gh.AfterProposalVotingPeriodEnded(ctx, proposalID)
return nil
}
Loading

0 comments on commit 821beb8

Please sign in to comment.