Skip to content

Commit

Permalink
fix(iro): creating VFC contracts for IRO tokens (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Oct 13, 2024
1 parent c8b8406 commit 7119731
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func (a *AppKeepers) InitKeepers(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
&a.AccountKeeper,
a.BankKeeper,
a.DenomMetadataKeeper,
a.RollappKeeper,
a.GAMMKeeper,
a.IncentivesKeeper,
Expand Down
1 change: 1 addition & 0 deletions testutil/keeper/iro.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func IROKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
nil,
nil,
nil,
nil,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
Expand Down
8 changes: 4 additions & 4 deletions x/iro/keeper/create_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ func (k Keeper) MintAllocation(ctx sdk.Context, allocatedAmount math.Int, rollap
return sdk.Coin{}, errorsmod.Wrap(errors.Join(gerrc.ErrInternal, err), fmt.Sprintf("metadata: %v", metadata))
}

if k.BK.HasDenomMetaData(ctx, baseDenom) {
return sdk.Coin{}, errors.New("denom already exists")
err := k.dk.CreateDenomMetadata(ctx, metadata)
if err != nil {
return sdk.Coin{}, errorsmod.Wrap(err, "create denom metadata")
}
k.BK.SetDenomMetaData(ctx, metadata)

minted := sdk.NewCoin(baseDenom, allocatedAmount)
err := k.BK.MintCoins(ctx, types.ModuleName, sdk.NewCoins(minted))
err = k.BK.MintCoins(ctx, types.ModuleName, sdk.NewCoins(minted))
if err != nil {
return sdk.Coin{}, err
}
Expand Down
4 changes: 4 additions & 0 deletions x/iro/keeper/create_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (s *KeeperTestSuite) TestMintAllocation() {
_, found := s.App.BankKeeper.GetDenomMetaData(s.Ctx, expectedBaseDenom)
s.Require().True(found)

// assert virtual frontier bank contract created
found = s.App.EvmKeeper.HasVirtualFrontierBankContractByDenom(s.Ctx, expectedBaseDenom)
s.Require().True(found)

// assert coins minted
s.Assert().True(allocatedAmount.Equal(minted.Amount))
coins := s.App.BankKeeper.GetSupply(s.Ctx, expectedBaseDenom)
Expand Down
3 changes: 3 additions & 0 deletions x/iro/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Keeper struct {

AK types.AccountKeeper
BK types.BankKeeper
dk types.DenomMetadataKeeper
rk types.RollappKeeper
gk types.GammKeeper
pm types.PoolManagerKeeper
Expand All @@ -33,6 +34,7 @@ func NewKeeper(
authority string,
ak types.AccountKeeper,
bk types.BankKeeper,
dk types.DenomMetadataKeeper,
rk types.RollappKeeper,
gk types.GammKeeper,
ik types.IncentivesKeeper,
Expand All @@ -44,6 +46,7 @@ func NewKeeper(
authority: authority,
AK: ak,
BK: bk,
dk: dk,
rk: rk,
gk: gk,
ik: ik,
Expand Down
8 changes: 5 additions & 3 deletions x/iro/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ type AccountKeeper interface {
SetModuleAccount(ctx sdk.Context, macc authtypes.ModuleAccountI)
}

type DenomMetadataKeeper interface {
CreateDenomMetadata(ctx sdk.Context, metadata banktypes.Metadata) error
HasDenomMetadata(ctx sdk.Context, base string) bool
}

// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
HasDenomMetaData(ctx sdk.Context, denom string) bool
SetDenomMetaData(ctx sdk.Context, denomMetaData banktypes.Metadata)

SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
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
Expand Down

0 comments on commit 7119731

Please sign in to comment.