diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index ba974251f..96905d61f 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -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) diff --git a/x/burn/burner.go b/x/burn/burner.go index d7b97ea9c..6099d5819 100644 --- a/x/burn/burner.go +++ b/x/burn/burner.go @@ -3,6 +3,7 @@ package burn import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + mintkeeper "github.com/CosmosContracts/juno/v17/x/mint/keeper" sdk "github.com/cosmos/cosmos-sdk/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" ) @@ -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 { + + // if we are burning mint denom, reduce the target staking supply + if amount.Denom == params.MintDenom { + k.mk.ReduceTargetSupply(ctx, amount) + } + } + return nil } diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index 9199e47e5..f4391f6f5 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -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") + } + + 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 {