Skip to content

Commit

Permalink
fix tokenfactory
Browse files Browse the repository at this point in the history
  • Loading branch information
tubackkhoa committed Jul 31, 2024
1 parent 5ba1a71 commit ddef02b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
24 changes: 24 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ import (
packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types"

"github.com/CosmWasm/wasmd/x/tokenfactory"
"github.com/CosmWasm/wasmd/x/tokenfactory/bindings"
tokenfactorykeeper "github.com/CosmWasm/wasmd/x/tokenfactory/keeper"
tokenfactorytypes "github.com/CosmWasm/wasmd/x/tokenfactory/types"
)

const appName = "WasmApp"
Expand All @@ -153,6 +158,12 @@ const appName = "WasmApp"
var (
NodeDir = ".oraid"
Bech32Prefix = "orai"

EnabledCapabilities = []string{
tokenfactorytypes.EnableBurnFrom,
// tokenfactorytypes.EnableForceTransfer,
tokenfactorytypes.EnableSetMetadata,
}
)

// These constants are derived from the above variables.
Expand Down Expand Up @@ -248,6 +259,7 @@ type WasmApp struct {
ClockKeeper clockkeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
PacketForwardKeeper *packetforwardkeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper

// Middleware wrapper
Ics20WasmHooks *ibchooks.WasmHooks
Expand Down Expand Up @@ -663,6 +675,8 @@ func NewWasmApp(
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}

wasmOpts = append(bindings.RegisterCustomPlugins(&app.BankKeeper, &app.TokenFactoryKeeper), wasmOpts...)

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
app.WasmKeeper = wasmkeeper.NewKeeper(
Expand Down Expand Up @@ -693,6 +707,15 @@ func NewWasmApp(
*app.ContractKeeper,
)

app.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper(
keys[tokenfactorytypes.StoreKey],
app.GetSubspace(tokenfactorytypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.DistrKeeper,
EnabledCapabilities,
)

app.IBCHooksKeeper = ibchookskeeper.NewKeeper(
app.keys[ibchookstypes.StoreKey],
app.GetSubspace(ibchookstypes.ModuleName),
Expand Down Expand Up @@ -817,6 +840,7 @@ func NewWasmApp(
clocktypes.ModuleName: clock.AppModuleBasic{},
ibchookstypes.ModuleName: ibchooks.AppModuleBasic{},
packetforwardtypes.ModuleName: packetforward.AppModuleBasic{},
tokenfactorytypes.ModuleName: tokenfactory.AppModuleBasic{},
})
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
Expand Down
20 changes: 7 additions & 13 deletions x/tokenfactory/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,11 @@ type TokenfactoryKeeper interface {
GetDenomsFromCreator(ctx sdk.Context, creator string) []string
}

type BankKeeper interface {
simulation.BankKeeper
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
}

func WeightedOperations(
appParams simtypes.AppParams,
tfKeeper TokenfactoryKeeper,
ak types.AccountKeeper,
bk BankKeeper,
bk types.BankKeeper,
) simulation.WeightedOperations {
var (
weightMsgCreateDenom int
Expand Down Expand Up @@ -152,7 +146,7 @@ func DefaultSimulationDenomSelector(r *rand.Rand, ctx sdk.Context, tfKeeper Toke
func SimulateMsgSetDenomMetadata(
tfKeeper TokenfactoryKeeper,
ak types.AccountKeeper,
bk BankKeeper,
bk types.BankKeeper,
denomSelector DenomSelector,
) simtypes.Operation {
return func(
Expand Down Expand Up @@ -206,7 +200,7 @@ func SimulateMsgSetDenomMetadata(
func SimulateMsgChangeAdmin(
tfKeeper TokenfactoryKeeper,
ak types.AccountKeeper,
bk BankKeeper,
bk types.BankKeeper,
denomSelector DenomSelector,
) simtypes.Operation {
return func(
Expand Down Expand Up @@ -256,7 +250,7 @@ func SimulateMsgChangeAdmin(
func SimulateMsgBurn(
tfKeeper TokenfactoryKeeper,
ak types.AccountKeeper,
bk BankKeeper,
bk types.BankKeeper,
denomSelector DenomSelector,
) simtypes.Operation {
return func(
Expand Down Expand Up @@ -310,7 +304,7 @@ func SimulateMsgBurn(
func SimulateMsgMint(
tfKeeper TokenfactoryKeeper,
ak types.AccountKeeper,
bk BankKeeper,
bk types.BankKeeper,
denomSelector DenomSelector,
) simtypes.Operation {
return func(
Expand Down Expand Up @@ -354,7 +348,7 @@ func SimulateMsgMint(
}

// Simulate msg create denom
func SimulateMsgCreateDenom(tfKeeper TokenfactoryKeeper, ak types.AccountKeeper, bk BankKeeper) simtypes.Operation {
func SimulateMsgCreateDenom(tfKeeper TokenfactoryKeeper, ak types.AccountKeeper, bk types.BankKeeper) simtypes.Operation {
return func(
r *rand.Rand,
app *baseapp.BaseApp,
Expand Down Expand Up @@ -395,7 +389,7 @@ func BuildOperationInput(
},
simAccount simtypes.Account,
ak types.AccountKeeper,
bk BankKeeper,
bk types.BankKeeper,
deposit sdk.Coins,
) simulation.OperationInput {
interfaceRegistry := codectypes.NewInterfaceRegistry()
Expand Down
24 changes: 12 additions & 12 deletions x/tokenfactory/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ import (

type BankKeeper interface {
// Methods imported from bank should be defined here
GetDenomMetaData(ctx sdk.Context, denom string) (banktypes.Metadata, bool)
SetDenomMetaData(ctx sdk.Context, denomMetaData banktypes.Metadata)
GetDenomMetaData(ctx context.Context, denom string) (banktypes.Metadata, bool)
SetDenomMetaData(ctx context.Context, denomMetaData banktypes.Metadata)

HasSupply(ctx sdk.Context, denom string) bool
HasSupply(ctx context.Context, denom string) bool

SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx context.Context, moduleName string, amt sdk.Coins) error

SendCoins(ctx context.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
HasBalance(ctx context.Context, addr sdk.AccAddress, amt sdk.Coin) bool
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
BlockedAddr(addr sdk.AccAddress) bool
}

type AccountKeeper interface {
SetModuleAccount(ctx sdk.Context, macc sdk.ModuleAccountI)
SetModuleAccount(ctx context.Context, macc sdk.ModuleAccountI)
// Retrieve an account from the store.
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
}

// CommunityPoolKeeper defines the contract needed to be fulfilled for community pool interactions.
type CommunityPoolKeeper interface {
FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error
FundCommunityPool(ctx context.Context, amount sdk.Coins, sender sdk.AccAddress) error
}

0 comments on commit ddef02b

Please sign in to comment.