-
Notifications
You must be signed in to change notification settings - Fork 170
/
burner.go
50 lines (38 loc) · 1.27 KB
/
burner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package burn
import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
mintkeeper "github.com/CosmosContracts/juno/v22/x/mint/keeper"
)
// used to override Wasmd's NewBurnCoinMessageHandler
type BurnerWasmPlugin struct {
bk bankkeeper.Keeper
mk mintkeeper.Keeper
}
var _ wasmtypes.Burner = &BurnerWasmPlugin{}
func NewBurnerPlugin(bk bankkeeper.Keeper, mk mintkeeper.Keeper) *BurnerWasmPlugin {
return &BurnerWasmPlugin{bk: bk, mk: mk}
}
func (k *BurnerWasmPlugin) BurnCoins(ctx sdk.Context, _ 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 {
if err := k.mk.ReduceTargetSupply(ctx, amount); err != nil {
return err
}
}
}
return nil
}
func (k *BurnerWasmPlugin) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, _ string, amt sdk.Coins) error {
return k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, ModuleName, amt)
}