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

feat(tokenfactory): burn native method #1832

Merged
merged 9 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1804](https://github.com/NibiruChain/nibiru/pull/1804) - fix(inflation): update default parameters
- [#1816](https://github.com/NibiruChain/nibiru/pull/1816) - fix(ibc): fix ibc transaction from wasm contract
- [#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

#### Dapp modules: perp, spot, etc

Expand Down
2 changes: 2 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (

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

var Upgrades = []upgrades.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 @@ -8,7 +8,7 @@

option go_package = "github.com/NibiruChain/nibiru/x/inflation/types";

service Msg {

Check failure on line 11 in proto/nibiru/inflation/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present RPC "Burn" on service "Msg" was deleted.
// ToggleInflation defines a method to enable or disable inflation.
rpc ToggleInflation(MsgToggleInflation) returns (MsgToggleInflationResponse) {
option (google.api.http).post = "/nibiru/inflation/v1/toggle";
Expand All @@ -19,10 +19,6 @@
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
Loading