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

Commitment Module Denom Checks #55

Merged
merged 4 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,15 @@ func NewElysApp(
govConfig,
)

app.AssetprofileKeeper = *assetprofilemodulekeeper.NewKeeper(
appCodec,
keys[assetprofilemoduletypes.StoreKey],
keys[assetprofilemoduletypes.MemStoreKey],
app.GetSubspace(assetprofilemoduletypes.ModuleName),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
assetprofileModule := assetprofilemodule.NewAppModule(appCodec, app.AssetprofileKeeper, app.AccountKeeper, app.BankKeeper)

commitmentKeeper := *commitmentmodulekeeper.NewKeeper(
appCodec,
keys[commitmentmoduletypes.StoreKey],
Expand All @@ -566,6 +575,7 @@ func NewElysApp(

app.BankKeeper,
app.StakingKeeper,
app.AssetprofileKeeper,
)

app.IncentiveKeeper = *incentivemodulekeeper.NewKeeper(
Expand Down Expand Up @@ -597,15 +607,6 @@ func NewElysApp(
)
epochsModule := epochsmodule.NewAppModule(appCodec, app.EpochsKeeper)

app.AssetprofileKeeper = *assetprofilemodulekeeper.NewKeeper(
appCodec,
keys[assetprofilemoduletypes.StoreKey],
keys[assetprofilemoduletypes.MemStoreKey],
app.GetSubspace(assetprofilemoduletypes.ModuleName),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
assetprofileModule := assetprofilemodule.NewAppModule(appCodec, app.AssetprofileKeeper, app.AccountKeeper, app.BankKeeper)

app.LiquidityproviderKeeper = *liquidityprovidermodulekeeper.NewKeeper(
appCodec,
keys[liquidityprovidermoduletypes.StoreKey],
Expand Down
6 changes: 6 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ genesis:
permissions: []
transferLimit: ""
unitDenom: ""
commitEnabled: false
withdrawEnabled: true
- address: ""
authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3
baseDenom: cusdc
Expand All @@ -119,6 +121,8 @@ genesis:
permissions: []
transferLimit: ""
unitDenom: ""
commitEnabled: false
withdrawEnabled: true
- address: ""
authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3
baseDenom: ueden
Expand All @@ -136,6 +140,8 @@ genesis:
permissions: []
transferLimit: ""
unitDenom: ""
commitEnabled: true
withdrawEnabled: true
epochs:
epochs:
- identifier: week
Expand Down
2 changes: 2 additions & 0 deletions proto/elys/assetprofile/entry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ message Entry {
string ibcCounterpartyDenom = 15;
string ibcCounterpartyChainId = 16;
string authority = 17;
bool commit_enabled = 18;
bool withdraw_enabled = 19;
}

1 change: 1 addition & 0 deletions testutil/keeper/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func CommitmentKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
paramsSubspace,
nil,
nil,
nil,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
Expand Down
143 changes: 116 additions & 27 deletions x/assetprofile/types/entry.pb.go

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

2 changes: 1 addition & 1 deletion x/assetprofile/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (

// x/assetprofile module sentinel errors
var (
ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error")
ErrAssetProfileNotFound = sdkerrors.Register(ModuleName, 1100, "asset profile not found for denom")
)
3 changes: 3 additions & 0 deletions x/commitment/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type (

bankKeeper types.BankKeeper
stakingKeeper types.StakingKeeper
apKeeper types.AssetProfileKeeper
}
)

Expand All @@ -51,6 +52,7 @@ func NewKeeper(

bankKeeper types.BankKeeper,
stakingKeeper types.StakingKeeper,
apKeeper types.AssetProfileKeeper,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
Expand All @@ -65,6 +67,7 @@ func NewKeeper(

bankKeeper: bankKeeper,
stakingKeeper: stakingKeeper,
apKeeper: apKeeper,
}
}

Expand Down
10 changes: 10 additions & 0 deletions x/commitment/keeper/msg_server_commit_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
aptypes "github.com/elys-network/elys/x/assetprofile/types"
"github.com/elys-network/elys/x/commitment/types"
)

func (k msgServer) CommitTokens(goCtx context.Context, msg *types.MsgCommitTokens) (*types.MsgCommitTokensResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

assetProfile, found := k.apKeeper.GetEntry(ctx, msg.Denom)
if !found {
Copy link
Contributor

@kenta-elys kenta-elys Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find eden boost in asset profile genesis list. How can we commit it as it isn't listed.

return nil, sdkerrors.Wrapf(aptypes.ErrAssetProfileNotFound, "denom: %s", msg.Denom)
}

if !assetProfile.CommitEnabled {
return nil, sdkerrors.Wrapf(types.ErrCommitDisabled, "denom: %s", msg.Denom)
}

// Get the Commitments for the creator
commitments, found := k.GetCommitments(ctx, msg.Creator)
if !found {
Expand Down
4 changes: 4 additions & 0 deletions x/commitment/keeper/msg_server_commit_tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/app"
aptypes "github.com/elys-network/elys/x/assetprofile/types"
commitmentkeeper "github.com/elys-network/elys/x/commitment/keeper"
"github.com/elys-network/elys/x/commitment/types"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -41,6 +42,9 @@ func TestCommitTokens(t *testing.T) {

keeper.SetCommitments(ctx, initialCommitments)

// Set assetprofile entry for denom
app.AssetprofileKeeper.SetEntry(ctx, aptypes.Entry{BaseDenom: denom, CommitEnabled: true})

// Call the CommitTokens function
msg := types.MsgCommitTokens{
Creator: creator,
Expand Down
10 changes: 10 additions & 0 deletions x/commitment/keeper/msg_server_deposit_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
aptypes "github.com/elys-network/elys/x/assetprofile/types"
"github.com/elys-network/elys/x/commitment/types"
)

func (k msgServer) DepositTokens(goCtx context.Context, msg *types.MsgDepositTokens) (*types.MsgDepositTokensResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

assetProfile, found := k.apKeeper.GetEntry(ctx, msg.Denom)
if !found {
return nil, sdkerrors.Wrapf(aptypes.ErrAssetProfileNotFound, "denom: %s", msg.Denom)
}

if !assetProfile.CommitEnabled {
return nil, sdkerrors.Wrapf(types.ErrCommitDisabled, "denom: %s", msg.Denom)
}

depositCoins := sdk.NewCoins(sdk.NewCoin(msg.Denom, msg.Amount))

addr, err := sdk.AccAddressFromBech32(msg.Creator)
Expand Down
4 changes: 4 additions & 0 deletions x/commitment/keeper/msg_server_deposit_tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/app"
aptypes "github.com/elys-network/elys/x/assetprofile/types"
commitmentkeeper "github.com/elys-network/elys/x/commitment/keeper"
"github.com/elys-network/elys/x/commitment/types"
"github.com/stretchr/testify/require"
Expand All @@ -31,6 +32,9 @@ func TestDepositTokens(t *testing.T) {
Amount: sdk.NewInt(100),
}

// Set assetprofile entry for denom
app.AssetprofileKeeper.SetEntry(ctx, aptypes.Entry{BaseDenom: depositMsg.Denom, CommitEnabled: true})

// Add initial funds to creator's account
coins := sdk.NewCoins(sdk.NewCoin("ueden", sdk.NewInt(200)))
err := app.BankKeeper.MintCoins(ctx, types.ModuleName, coins)
Expand Down
Loading