Skip to content

Commit

Permalink
reduce tokens in targetsupply when burning
Browse files Browse the repository at this point in the history
  • Loading branch information
dimiandre committed Sep 1, 2023
1 parent 5ee21bd commit 5725d77
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func NewAppKeepers(
// return wasmkeeper.NewBurnCoinMessageHandler(customBurner)
// })

junoBurnerPlugin := junoburn.NewBurnerPlugin(appKeepers.BankKeeper)
junoBurnerPlugin := junoburn.NewBurnerPlugin(appKeepers.BankKeeper, appKeepers.MintKeeper)
burnOverride := wasmkeeper.WithMessageHandler(wasmkeeper.NewBurnCoinMessageHandler(junoBurnerPlugin))
wasmOpts = append(wasmOpts, burnOverride)

Expand Down
28 changes: 23 additions & 5 deletions x/burn/burner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package burn
import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

mintkeeper "github.com/CosmosContracts/juno/v17/x/mint/keeper"

Check failure on line 6 in x/burn/burner.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/CosmosContracts/juno) --custom-order (gci)
sdk "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

Check failure on line 8 in x/burn/burner.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos) -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/CosmosContracts/juno) --custom-order (gci)
)
Expand All @@ -11,17 +12,34 @@ import (

type BurnerWasmPlugin struct {
bk bankkeeper.Keeper
mk mintkeeper.Keeper
}

var _ wasmtypes.Burner = &BurnerWasmPlugin{}

func NewBurnerPlugin(bk bankkeeper.Keeper) *BurnerWasmPlugin {
return &BurnerWasmPlugin{bk: bk}
func NewBurnerPlugin(bk bankkeeper.Keeper, mk mintkeeper.Keeper) *BurnerWasmPlugin {
return &BurnerWasmPlugin{bk: bk, mk: mk}
}

func (k *BurnerWasmPlugin) BurnCoins(_ sdk.Context, _ string, _ sdk.Coins) error {
// instead of burning, we just hold in balance and subtract from the x/mint module's total supply
// return k.bk.BurnCoins(ctx, moduleName, amt)
func (k *BurnerWasmPlugin) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
// first, try to burn the coins on bank module
err := k.bk.BurnCoins(ctx, moduleName, amt)
if err != nil {
return err
}

// get mint params
params := k.mk.GetParams(ctx)

// loop the burned coins
for _, amount := range amt {

Check failure on line 36 in x/burn/burner.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
// if we are burning mint denom, reduce the target staking supply
if amount.Denom == params.MintDenom {
k.mk.ReduceTargetSupply(ctx, amount)

Check failure on line 39 in x/burn/burner.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `k.mk.ReduceTargetSupply` is not checked (errcheck)
}
}

return nil
}

Expand Down
14 changes: 14 additions & 0 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ func (k Keeper) MintCoins(ctx sdk.Context, newCoins sdk.Coins) error {
return k.bankKeeper.MintCoins(ctx, types.ModuleName, newCoins)
}

func (k Keeper) ReduceTargetSupply(ctx sdk.Context, burnCoin sdk.Coin) error {
params := k.GetParams(ctx)

if burnCoin.Denom != params.MintDenom {
return fmt.Errorf("Tried reducing target supply with non staking token")

Check failure on line 160 in x/mint/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

ST1005: error strings should not be capitalized (stylecheck)
}

minter := k.GetMinter(ctx)
minter.TargetSupply = minter.TargetSupply.Sub(burnCoin.Amount)
k.SetMinter(ctx, minter)

return nil
}

// AddCollectedFees implements an alias call to the underlying supply keeper's
// AddCollectedFees to be used in BeginBlocker.
func (k Keeper) AddCollectedFees(ctx sdk.Context, fees sdk.Coins) error {
Expand Down

0 comments on commit 5725d77

Please sign in to comment.