mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 16:55:21 +00:00
ef874f9913
* feat: community pool deposit/withdraw proposals * fix: check community pool balance in tests * add new msg type definitions * add msg methods and tests * add module and keeper skeleton * add deposit and withdraw methods (no delegation) * untested depsit/withdraw with delegation methods * add cli cmds * fix cli argument parsing * add tests for delegate/undelegate msgs * emit un/delegate events * add godoc comments * tally handler with liquid staking support * clean up * update for liquid keeper changes * Exclude non-bkava denoms from aggregate underlying ukava calculation * wip Add claim * Add distr keeper and claiming * Add claim test * Update claim test with failures * wip Add staking rewards * -S Fix savings to earn incentive methods * Use a single accural time for all earn incentives * Add additional required liquid methods * Update genesis to only include 1 accrual time for earn * Revert "Update genesis to only include 1 accrual time for earn" This reverts commit cc7e35347298681c0c8a4a0b9bf9b9b296c25531. * Revert "Use a single accural time for all earn incentives" This reverts commit aeb49c4622d4e3d99dc6421c8830932b1b546be9. * Update tests with incentive distribution * Add earn to incentive rewards query * add earn cli tx * Update claim example to use ukava large * add proposal to gov router * fix example tx formating * add proposal handlers to gov app module * fix: define gov router after earn keeper * fix: correct proposal type * remove outdated comment * refactor withdraw so that fee pool is allows adjusted by the actual withdraw amount * fix: lint proto file * use non blocked module account instead of dist acc * add fund mod account to app, enable receiving * update to new withdraw interface * add human readable apy test cases * remove duplicate changes from previous merge * remove deprecated io/ioutil package * standardize proposal type as a pointer (also matches sdk) * minior comments and formatting * use withdraw amount in router msgs Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com> Co-authored-by: Draco <draco@dracoli.com> Co-authored-by: drklee3 <derrick@dlee.dev> Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
98 lines
3.4 KiB
Go
98 lines
3.4 KiB
Go
package rest
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
|
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
|
|
"github.com/kava-labs/kava/x/earn/types"
|
|
)
|
|
|
|
type (
|
|
// CommunityPoolDepositProposalReq defines a community pool deposit proposal request body.
|
|
CommunityPoolDepositProposalReq struct {
|
|
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
|
|
|
|
Title string `json:"title" yaml:"title"`
|
|
Description string `json:"description" yaml:"description"`
|
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
|
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
|
|
Proposer sdk.AccAddress `json:"proposer" yaml:"proposer"`
|
|
}
|
|
// CommunityPoolWithdrawProposalReq defines a community pool deposit proposal request body.
|
|
CommunityPoolWithdrawProposalReq struct {
|
|
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
|
|
|
|
Title string `json:"title" yaml:"title"`
|
|
Description string `json:"description" yaml:"description"`
|
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
|
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
|
|
Proposer sdk.AccAddress `json:"proposer" yaml:"proposer"`
|
|
}
|
|
)
|
|
|
|
// DepositProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool deposit REST handler with a given sub-route.
|
|
func DepositProposalRESTHandler(cliCtx client.Context) govrest.ProposalRESTHandler {
|
|
return govrest.ProposalRESTHandler{
|
|
SubRoute: types.ProposalTypeCommunityPoolDeposit,
|
|
Handler: postDepositProposalHandlerFn(cliCtx),
|
|
}
|
|
}
|
|
|
|
func postDepositProposalHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
var req CommunityPoolDepositProposalReq
|
|
if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) {
|
|
return
|
|
}
|
|
req.BaseReq = req.BaseReq.Sanitize()
|
|
if !req.BaseReq.ValidateBasic(w) {
|
|
return
|
|
}
|
|
content := types.NewCommunityPoolDepositProposal(req.Title, req.Description, req.Amount)
|
|
msg, err := govtypes.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
|
|
if rest.CheckBadRequestError(w, err) {
|
|
return
|
|
}
|
|
if rest.CheckBadRequestError(w, msg.ValidateBasic()) {
|
|
return
|
|
}
|
|
tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg)
|
|
}
|
|
}
|
|
|
|
// WithdrawProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool deposit REST handler with a given sub-route.
|
|
func WithdrawProposalRESTHandler(cliCtx client.Context) govrest.ProposalRESTHandler {
|
|
return govrest.ProposalRESTHandler{
|
|
SubRoute: types.ProposalTypeCommunityPoolWithdraw,
|
|
Handler: postWithdrawProposalHandlerFn(cliCtx),
|
|
}
|
|
}
|
|
|
|
func postWithdrawProposalHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
var req CommunityPoolWithdrawProposalReq
|
|
if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) {
|
|
return
|
|
}
|
|
req.BaseReq = req.BaseReq.Sanitize()
|
|
if !req.BaseReq.ValidateBasic(w) {
|
|
return
|
|
}
|
|
content := types.NewCommunityPoolWithdrawProposal(req.Title, req.Description, req.Amount)
|
|
msg, err := govtypes.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
|
|
if rest.CheckBadRequestError(w, err) {
|
|
return
|
|
}
|
|
if rest.CheckBadRequestError(w, msg.ValidateBasic()) {
|
|
return
|
|
}
|
|
tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg)
|
|
}
|
|
}
|