-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thin layer impl of the finalisation block rewards generation. Supersedes / replaces #61
- Loading branch information
Showing
5 changed files
with
103 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
package contract | ||
|
||
// CustomMsg is a message sent from a smart contract to the Babylon module | ||
// TODO: implement | ||
type CustomMsg struct { | ||
Test *TestMsg `json:"test,omitempty"` | ||
} | ||
import ( | ||
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types" | ||
) | ||
|
||
type TestMsg struct { | ||
Placeholder string `json:"placeholder,omitempty"` | ||
} | ||
// CustomMsg is a message sent from a smart contract to the Babylon module | ||
type ( | ||
CustomMsg struct { | ||
MintRewards *MintRewardsMsg `json:"mint_rewards,omitempty"` | ||
} | ||
// MintRewardsMsg mints the specified number of block rewards, | ||
// and sends them to the specified recipient (typically, the staking contract) | ||
MintRewardsMsg struct { | ||
Amount wasmvmtypes.Coin `json:"amount"` | ||
Recipient string `json:"recipient"` | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package keeper | ||
|
||
import ( | ||
sdkmath "cosmossdk.io/math" | ||
"github.com/babylonlabs-io/babylon-sdk/x/babylon/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// MintBlockRewards mints new tokens and sends them to the staking contract for distribution. | ||
// Authorization of the actor should be handled before entering this method. | ||
// Authorization of the recipient is being handled within the method for safety, but can | ||
// be removed for flexibility | ||
func (k Keeper) MintBlockRewards(pCtx sdk.Context, recipient sdk.AccAddress, amt sdk.Coin) (sdkmath.Int, error) { | ||
if amt.Amount.IsNil() || amt.Amount.IsZero() || amt.Amount.IsNegative() { | ||
return sdkmath.ZeroInt(), errors.ErrInvalidRequest.Wrap("amount") | ||
} | ||
|
||
// Ensure staking constraints | ||
bondDenom, err := k.Staking.BondDenom(pCtx) | ||
if err != nil { | ||
return sdkmath.ZeroInt(), err | ||
} | ||
if amt.Denom != bondDenom { | ||
return sdkmath.ZeroInt(), errors.ErrInvalidRequest.Wrapf("invalid coin denomination: got %s, expected %s", amt.Denom, bondDenom) | ||
} | ||
// FIXME? Remove this constraint for flexibility | ||
params := k.GetParams(pCtx) | ||
if recipient.String() != params.BtcStakingContractAddress { | ||
return sdkmath.ZeroInt(), errors.ErrUnauthorized.Wrapf("invalid recipient: got %s, expected staking contract (%s)", | ||
recipient, params.BtcStakingContractAddress) | ||
} | ||
|
||
// TODO?: Ensure Babylon constraints | ||
|
||
cacheCtx, done := pCtx.CacheContext() // work in a cached store as Osmosis (safety net?) | ||
|
||
// Mint rewards tokens | ||
coins := sdk.NewCoins(amt) | ||
err = k.bank.MintCoins(cacheCtx, types.ModuleName, coins) | ||
if err != nil { | ||
return sdkmath.ZeroInt(), err | ||
} | ||
|
||
// FIXME: Confirm we want this supply offset enabled for rewards, i.e. | ||
// as virtual coins that do not count to the total supply | ||
//k.bank.AddSupplyOffset(cacheCtx, bondDenom, amt.Amount.Neg()) | ||
|
||
err = k.bank.SendCoinsFromModuleToAccount(cacheCtx, types.ModuleName, recipient, coins) | ||
if err != nil { | ||
return sdkmath.ZeroInt(), err | ||
} | ||
|
||
done() | ||
return amt.Amount, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters