Skip to content

Commit

Permalink
feat(tokenfactory): burn native method (#1832)
Browse files Browse the repository at this point in the history
* refactor: move Burn rpc method to x/tokenfactory

* Update tx_msgs.go

* feat: add burn native method to tokenfactory msg server

* feat: add cli cmd

* fix: validate msg

* feat: add v1.2.0 upgrade handler

* Update CHANGELOG.md

* fix: register codec for MsgBurnNative

* fix: test

---------

Co-authored-by: Unique-Divine <realuniquedivine@gmail.com>
  • Loading branch information
k-yang and Unique-Divine committed Apr 2, 2024
1 parent 7d86138 commit b210bf4
Show file tree
Hide file tree
Showing 16 changed files with 769 additions and 294 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Nibiru v1.2.0 adds a burn method to the x/inflation module that allows senders t

### Features

* [#1823](https://github.com/NibiruChain/nibiru/pull/1823) - feat(inflation): add burn method
* [#1832](https://github.com/NibiruChain/nibiru/pull/1832) - feat(tokenfactory): add burn method for native tokens

## [v1.1.0](https://github.com/NibiruChain/nibiru/releases/tag/v1.1.0) - 2024-03-19

Expand Down
2 changes: 2 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
"github.com/NibiruChain/nibiru/app/upgrades/v1_0_1"
"github.com/NibiruChain/nibiru/app/upgrades/v1_0_2"
"github.com/NibiruChain/nibiru/app/upgrades/v1_1_0"
"github.com/NibiruChain/nibiru/app/upgrades/v1_2_0"
)

var Upgrades = []upgrades.Upgrade{
v1_0_1.Upgrade,
v1_0_2.Upgrade,
v1_0_3.Upgrade,
v1_1_0.Upgrade,
v1_2_0.Upgrade,
}

func (app *NibiruApp) setupUpgrades() {
Expand Down
22 changes: 22 additions & 0 deletions app/upgrades/v1_2_0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package v1_2_0

import (
"github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/NibiruChain/nibiru/app/upgrades"
)

const UpgradeName = "v1.2.0"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, cfg, fromVM)
}
},
StoreUpgrades: types.StoreUpgrades{},
}
4 changes: 0 additions & 4 deletions proto/nibiru/inflation/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ service Msg {
returns (MsgEditInflationParamsResponse) {
option (google.api.http).post = "/nibiru/inflation/edit-inflation-params";
};

rpc Burn(MsgBurn) returns (MsgBurnResponse) {
option (google.api.http).post = "/nibiru/inflation/v1/burn";
};
}

// MsgToggleInflation defines a message to enable or disable inflation.
Expand Down
12 changes: 12 additions & 0 deletions proto/nibiru/tokenfactory/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ service Msg {
rpc Burn(MsgBurn) returns (MsgBurnResponse);
rpc SetDenomMetadata(MsgSetDenomMetadata)
returns (MsgSetDenomMetadataResponse);

// burns a native token such as unibi
rpc BurnNative(MsgBurnNative) returns (MsgBurnNativeResponse) {};
}

// MsgCreateDenom: sdk.Msg that registers an a token factory denom.
Expand Down Expand Up @@ -114,3 +117,12 @@ message MsgSetDenomMetadata {
}

message MsgSetDenomMetadataResponse {}

// Burn a native token such as unibi
message MsgBurnNative {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
cosmos.base.v1beta1.Coin coin = 2
[ (gogoproto.moretags) = "yaml:\"coin\"", (gogoproto.nullable) = false ];
}

message MsgBurnNativeResponse {}
14 changes: 0 additions & 14 deletions x/inflation/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,3 @@ func (ms msgServer) ToggleInflation(
resp = &types.MsgToggleInflationResponse{}
return resp, err
}

func (ms msgServer) Burn(
goCtx context.Context, msg *types.MsgBurn,
) (resp *types.MsgBurnResponse, err error) {
ctx := sdk.UnwrapSDKContext(goCtx)

sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return nil, err
}

err = ms.Keeper.Burn(ctx, sdk.NewCoins(msg.Coin), sender)
return &types.MsgBurnResponse{}, err
}
42 changes: 0 additions & 42 deletions x/inflation/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,45 +70,3 @@ func TestMsgEditInflationParams(t *testing.T) {
params = app.InflationKeeper.GetParams(ctx)
require.EqualValues(t, params.EpochsPerPeriod, 42)
}

func TestMsgBurn(t *testing.T) {
app, ctx := testapp.NewNibiruTestAppAndContext()
sender := testutil.AccAddress()
err := app.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin("unibi", sdk.NewInt(100))))
require.NoError(t, err)
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, sdk.NewCoins(sdk.NewCoin("unibi", sdk.NewInt(100))))
require.NoError(t, err)

msgServer := keeper.NewMsgServerImpl(app.InflationKeeper)

msg := types.MsgBurn{
Sender: sender.String(),
Coin: sdk.NewCoin("unibi", sdk.NewInt(100)),
}

_, err = msgServer.Burn(ctx, &msg)
require.NoError(t, err)
supply := app.BankKeeper.GetSupply(ctx, "unibi")
require.Equal(t, sdk.ZeroInt(), supply.Amount)
}

func TestMsgBurn_NotEnoughCoins(t *testing.T) {
app, ctx := testapp.NewNibiruTestAppAndContext()
sender := testutil.AccAddress()
err := app.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin("unibi", sdk.NewInt(100))))
require.NoError(t, err)
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, sdk.NewCoins(sdk.NewCoin("unibi", sdk.NewInt(100))))
require.NoError(t, err)

msgServer := keeper.NewMsgServerImpl(app.InflationKeeper)

msg := types.MsgBurn{
Sender: sender.String(),
Coin: sdk.NewCoin("unibi", sdk.NewInt(101)),
}

_, err = msgServer.Burn(ctx, &msg)
require.EqualError(t, err, "spendable balance 100unibi is smaller than 101unibi: insufficient funds")
supply := app.BankKeeper.GetSupply(ctx, "unibi")
require.Equal(t, sdk.NewInt(100), supply.Amount)
}
123 changes: 43 additions & 80 deletions x/inflation/types/tx.pb.go

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

Loading

0 comments on commit b210bf4

Please sign in to comment.