-
Notifications
You must be signed in to change notification settings - Fork 173
feat: message withdraw emissions #1825
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
f86c782
add a message to withdraw emission rewards
kingpinXD 7599d9b
add more tests for end blocker
kingpinXD 7d4c3cb
add unit tests for withdrawable emissions
kingpinXD da7f1a6
fix unit tests for withdrawable emissions
kingpinXD dca649e
generate files
kingpinXD ea2c810
Merge branch 'develop' into withdraw-emissions
kingpinXD 6dff9a3
fix typo
kingpinXD d2e3fd9
Merge branch 'withdraw-emissions' of github.com:zeta-chain/zeta-node …
kingpinXD c06b9eb
simply to withdrawing emission amount directly in a message
kingpinXD 2d7ab90
generate docs
kingpinXD 40aa9a5
reject zero amount withdraws
kingpinXD bba6042
reject zero amount withdraws
kingpinXD 25bed84
increase coverage for msg withdraw emissions
kingpinXD e9f4276
Merge branch 'develop' into withdraw-emissions
kingpinXD f2d4d84
fixed to error messages
kingpinXD 01c9e45
Update x/emissions/keeper/msg_server_withdraw_emissions.go
kingpinXD a17d678
Update x/emissions/keeper/msg_server_withdraw_emissions.go
kingpinXD 8f7d96a
Update x/emissions/keeper/msg_server_withdraw_emissions.go
kingpinXD f29adf2
remove minter for UndistributedObserverRewardsPool
kingpinXD 037e3ec
Merge remote-tracking branch 'origin/withdraw-emissions' into withdra…
kingpinXD 22b423e
generate files
kingpinXD f239219
Merge branch 'develop' into withdraw-emissions
kingpinXD 867fd83
Merge branch 'withdraw-emissions' of github.com:zeta-chain/zeta-node …
kingpinXD c3173de
Update x/emissions/types/keys.go
lumtis 3cc3181
change comments
kingpinXD e0560ee
Merge remote-tracking branch 'origin/withdraw-emissions' into withdra…
kingpinXD 4960fea
Merge branch 'develop' into withdraw-emissions
kingpinXD 1ae19df
add description for test
kingpinXD f35ffd7
Merge remote-tracking branch 'origin/withdraw-emissions' into withdra…
kingpinXD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
52 changes: 52 additions & 0 deletions
52
docs/cli/zetacored/zetacored_tx_emissions_withdraw-emission.md
This file contains hidden or 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,52 @@ | ||
| # tx emissions withdraw-emission | ||
|
|
||
| create a new withdrawEmission | ||
|
|
||
| ``` | ||
| zetacored tx emissions withdraw-emission [amount] [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -a, --account-number uint The account number of the signing account (offline mode only) | ||
| --aux Generate aux signer data instead of sending a tx | ||
| -b, --broadcast-mode string Transaction broadcasting mode (sync|async|block) | ||
| --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) | ||
| --fee-granter string Fee granter grants fees for the transaction | ||
| --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer | ||
| --fees string Fees to pay along with transaction; eg: 10uatom | ||
| --from string Name or address of private key with which to sign | ||
| --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) | ||
| --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) | ||
| --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) | ||
| --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) | ||
| -h, --help help for withdraw-emission | ||
| --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) | ||
| --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used | ||
| --ledger Use a connected Ledger device | ||
| --node string [host]:[port] to tendermint rpc interface for this chain | ||
| --note string Note to add a description to the transaction (previously --memo) | ||
| --offline Offline mode (does not allow any online functionality) | ||
| -o, --output string Output format (text|json) | ||
| -s, --sequence uint The sequence number of the signing account (offline mode only) | ||
| --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature | ||
| --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height | ||
| --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator | ||
| -y, --yes Skip tx broadcasting prompt confirmation | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --chain-id string The network chain ID | ||
| --home string directory for config and data | ||
| --log_format string The logging format (json|plain) | ||
| --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) | ||
| --trace print out full stack trace on errors | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [zetacored tx emissions](zetacored_tx_emissions.md) - emissions transactions subcommands | ||
|
|
This file contains hidden or 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 hidden or 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,16 @@ | ||
| # Messages | ||
|
|
||
| ## MsgWithdrawEmission | ||
|
|
||
| WithdrawEmission allows the user to withdraw from their withdrawable emissions. | ||
| on a successful withdrawal, the amount is transferred from the undistributed rewards pool to the user's account. | ||
| if the amount to be withdrawn is greater than the available withdrawable emission, the max available amount is withdrawn. | ||
| if the pool does not have enough balance to process this request, an error is returned. | ||
|
|
||
| ```proto | ||
| message MsgWithdrawEmission { | ||
| string creator = 1; | ||
| string amount = 2; | ||
| } | ||
| ``` | ||
|
|
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 @@ | ||
| // @generated by protoc-gen-es v1.3.0 with parameter "target=dts" | ||
| // @generated from file emissions/tx.proto (package zetachain.zetacore.emissions, syntax proto3) | ||
| /* eslint-disable */ | ||
| // @ts-nocheck | ||
|
|
||
| import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; | ||
| import { Message, proto3 } from "@bufbuild/protobuf"; | ||
|
|
||
| /** | ||
| * @generated from message zetachain.zetacore.emissions.MsgWithdrawEmission | ||
| */ | ||
| export declare class MsgWithdrawEmission extends Message<MsgWithdrawEmission> { | ||
| /** | ||
| * @generated from field: string creator = 1; | ||
| */ | ||
| creator: string; | ||
|
|
||
| /** | ||
| * @generated from field: string amount = 2; | ||
| */ | ||
| amount: string; | ||
|
|
||
| constructor(data?: PartialMessage<MsgWithdrawEmission>); | ||
|
|
||
| static readonly runtime: typeof proto3; | ||
| static readonly typeName = "zetachain.zetacore.emissions.MsgWithdrawEmission"; | ||
| static readonly fields: FieldList; | ||
|
|
||
| static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MsgWithdrawEmission; | ||
|
|
||
| static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): MsgWithdrawEmission; | ||
|
|
||
| static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): MsgWithdrawEmission; | ||
|
|
||
| static equals(a: MsgWithdrawEmission | PlainMessage<MsgWithdrawEmission> | undefined, b: MsgWithdrawEmission | PlainMessage<MsgWithdrawEmission> | undefined): boolean; | ||
| } | ||
|
|
||
| /** | ||
| * @generated from message zetachain.zetacore.emissions.MsgWithdrawEmissionResponse | ||
| */ | ||
| export declare class MsgWithdrawEmissionResponse extends Message<MsgWithdrawEmissionResponse> { | ||
| constructor(data?: PartialMessage<MsgWithdrawEmissionResponse>); | ||
|
|
||
| static readonly runtime: typeof proto3; | ||
| static readonly typeName = "zetachain.zetacore.emissions.MsgWithdrawEmissionResponse"; | ||
| static readonly fields: FieldList; | ||
|
|
||
| static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MsgWithdrawEmissionResponse; | ||
|
|
||
| static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): MsgWithdrawEmissionResponse; | ||
|
|
||
| static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): MsgWithdrawEmissionResponse; | ||
|
|
||
| static equals(a: MsgWithdrawEmissionResponse | PlainMessage<MsgWithdrawEmissionResponse> | undefined, b: MsgWithdrawEmissionResponse | PlainMessage<MsgWithdrawEmissionResponse> | undefined): boolean; | ||
| } | ||
|
|
This file contains hidden or 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 hidden or 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,37 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| sdkmath "cosmossdk.io/math" | ||
| "github.com/cosmos/cosmos-sdk/client" | ||
| "github.com/cosmos/cosmos-sdk/client/flags" | ||
| "github.com/cosmos/cosmos-sdk/client/tx" | ||
| "github.com/spf13/cobra" | ||
| "github.com/zeta-chain/zetacore/x/emissions/types" | ||
| ) | ||
|
|
||
| func CmdWithdrawEmission() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "withdraw-emission [amount]", | ||
| Short: "create a new withdrawEmission", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| argsAmount, ok := sdkmath.NewIntFromString(args[0]) | ||
| if !ok { | ||
| return errors.New("invalid amount") | ||
| } | ||
| clientCtx, err := client.GetClientTxContext(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| msg := types.NewMsgWithdrawEmissions(clientCtx.GetFromAddress().String(), argsAmount) | ||
| if err := msg.ValidateBasic(); err != nil { | ||
| return err | ||
| } | ||
| return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
| }, | ||
| } | ||
| flags.AddTxFlagsToCmd(cmd) | ||
| return cmd | ||
| } |
This file contains hidden or 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,45 @@ | ||
| package keeper | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| errorsmod "cosmossdk.io/errors" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| "github.com/zeta-chain/zetacore/cmd/zetacored/config" | ||
| "github.com/zeta-chain/zetacore/x/emissions/types" | ||
| ) | ||
|
|
||
| // WithdrawEmission allows the user to withdraw from their withdrawable emissions. | ||
| // on a successful withdrawal, the amount is transferred from the undistributed rewards pool to the user's account. | ||
| // if the amount to be withdrawn is greater than the available withdrawable emission, the max available amount is withdrawn. | ||
| // if the pool does not have enough balance to process this request, an error is returned. | ||
| func (k msgServer) WithdrawEmission(goCtx context.Context, msg *types.MsgWithdrawEmission) (*types.MsgWithdrawEmissionResponse, error) { | ||
| ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
|
||
| // check if the creator address is valid | ||
| address, err := sdk.AccAddressFromBech32(msg.Creator) | ||
| if err != nil { | ||
| return nil, errorsmod.Wrap(types.ErrInvalidAddress, err.Error()) | ||
| } | ||
|
|
||
| // check if the undistributed rewards pool has enough balance to process this request. | ||
| // This is just a preliminary check, the actual processing at endblock might still fail if the pool balance gets affected. | ||
| undistributedRewardsBalance := k.GetBankKeeper().GetBalance(ctx, types.UndistributedObserverRewardsPoolAddress, config.BaseDenom) | ||
| if undistributedRewardsBalance.Amount.LT(msg.Amount) { | ||
| return nil, errorsmod.Wrap(types.ErrRewardsPoolDoesNotHaveEnoughBalance, " rewards pool does not have enough balance to process this request") | ||
| } | ||
|
|
||
| err = k.RemoveWithdrawableEmission(ctx, msg.Creator, msg.Amount) | ||
| if err != nil { | ||
| return nil, errorsmod.Wrap(types.ErrUnableToWithdrawEmissions, fmt.Sprintf("error while removing withdrawable emission for address %s : %s", msg.Creator, err)) | ||
| } | ||
|
|
||
| err = k.GetBankKeeper().SendCoinsFromModuleToAccount(ctx, types.UndistributedObserverRewardsPool, address, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, msg.Amount))) | ||
| if err != nil { | ||
| ctx.Logger().Error(fmt.Sprintf("Error while processing withdraw of emission to adresss %s for amount %s : err %s", address, msg.Amount, err)) | ||
| return nil, errorsmod.Wrap(types.ErrUnableToWithdrawEmissions, err.Error()) | ||
| } | ||
|
|
||
| return &types.MsgWithdrawEmissionResponse{}, nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.