Skip to content

Commit

Permalink
feat(ecocredit): allow denom proposal handler (#1072)
Browse files Browse the repository at this point in the history
* wip: ask denom proposal

* chore: move proposal to core

* feat: ask denom proposal handler

* fix: add ask denom setup to integration tests

* fix: add ask denom to cli integration tests

* chore: add proto message comment

* fix: grpc test use default bond denom

* chore: cleanup

* feat: added event to credit type handler

* chore: fix param changes test

* perf: switch to single regexp match for credit type validation

* chore: fix error strings, cli doc

* chore: cleanup

* fix: cli example str

* refactor: consolidate naming

* chore: remove edit

* chore: cleanup

* chore: apply suggestions from code review

Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>

* chore: fix cli string, remove exponent check

* chore: address review, cleanup askDenom remnants, change event name

* chore: imports

* fix: integration test fail

* chore: check SI units

* fix: add type registration

* chore: address review comments

* refactor: AllowedDenomProposal -> AllowDenomProposal

* refactor: file rename add_allowed_denom.go -> allow_denom.go

* refactor: change handle function name

* chore: address review

* chore: use go install

* Revert "chore: use go install"

This reverts commit 4499637.

* refactor: change handlefunc name

* chore: fix example string, remove flags

* Update x/ecocredit/client/marketplace/proposal.go

Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>

* fix: add required gov proposal type registration for credit type proposal

Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com>
Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>
Co-authored-by: Tyler Goodman <tylergoodman@Tylers-MacBook-Pro.local>
  • Loading branch information
4 people authored May 6, 2022
1 parent 8231250 commit ea43f14
Show file tree
Hide file tree
Showing 52 changed files with 2,671 additions and 3,114 deletions.
195 changes: 98 additions & 97 deletions api/regen/ecocredit/marketplace/v1/events.pulsar.go

Large diffs are not rendered by default.

756 changes: 756 additions & 0 deletions api/regen/ecocredit/marketplace/v1/types.pulsar.go

Large diffs are not rendered by default.

511 changes: 492 additions & 19 deletions api/regen/ecocredit/v1/events.pulsar.go

Large diffs are not rendered by default.

1,221 changes: 230 additions & 991 deletions api/regen/ecocredit/v1/types.pulsar.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import (
"github.com/regen-network/regen-ledger/x/ecocredit"
"github.com/regen-network/regen-ledger/x/ecocredit/basket"
ecocreditmodule "github.com/regen-network/regen-ledger/x/ecocredit/module"
ecoServer "github.com/regen-network/regen-ledger/x/ecocredit/server/core"
ecoServer "github.com/regen-network/regen-ledger/x/ecocredit/server"

// unnamed import of statik for swagger UI support
_ "github.com/regen-network/regen-ledger/v3/client/docs/statik"
Expand Down Expand Up @@ -396,7 +396,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
}
app.smm.RegisterInvariants(&app.CrisisKeeper)

govRouter.AddRoute(ecocredit.RouterKey, ecoServer.NewCreditTypeProposalHandler(ecocreditModule.Keeper))
govRouter.AddRoute(ecocredit.RouterKey, ecoServer.NewProposalHandler(ecocreditModule.Keeper))
app.GovKeeper = govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, govRouter,
Expand Down
3 changes: 2 additions & 1 deletion app/experimental_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
moduletypes "github.com/regen-network/regen-ledger/types/module"
"github.com/regen-network/regen-ledger/types/module/server"
"github.com/regen-network/regen-ledger/x/ecocredit/client/core"
"github.com/regen-network/regen-ledger/x/ecocredit/client/marketplace"
group "github.com/regen-network/regen-ledger/x/group/module"
)

Expand All @@ -41,7 +42,7 @@ func setCustomModuleBasics() []module.AppModuleBasic {
wasmclient.ProposalHandlers,
paramsclient.ProposalHandler, distrclient.ProposalHandler,
upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
core.CreditTypeProposalHandler,
core.CreditTypeProposalHandler, marketplace.AllowDenomProposalHandler,
)...,
),
wasm.AppModuleBasic{},
Expand Down
3 changes: 2 additions & 1 deletion app/stable_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import (

"github.com/regen-network/regen-ledger/types/module/server"
ecocreditcore "github.com/regen-network/regen-ledger/x/ecocredit/client/core"
"github.com/regen-network/regen-ledger/x/ecocredit/client/marketplace"
)

func setCustomModuleBasics() []module.AppModuleBasic {
return []module.AppModuleBasic{
gov.NewAppModuleBasic(
paramsclient.ProposalHandler, distrclient.ProposalHandler,
upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
ecocreditcore.CreditTypeProposalHandler,
ecocreditcore.CreditTypeProposalHandler, marketplace.AllowDenomProposalHandler,
),
}
}
Expand Down
5 changes: 3 additions & 2 deletions proto/regen/ecocredit/marketplace/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ message EventUpdateSellOrder {
uint64 order_id = 2;
}

// EventAllowAskDenom is an event emitted when an ask denom is added.
message EventAllowAskDenom {
// EventAllowDenom is an event emitted when a new denom is added for use in the
// marketplace.
message EventAllowDenom {

// denom is the denom to allow (ex. ibc/GLKHDSG423SGS)
string denom = 1;
Expand Down
24 changes: 24 additions & 0 deletions proto/regen/ecocredit/marketplace/v1/types.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
syntax = "proto3";

package regen.ecocredit.marketplace.v1;

import "regen/ecocredit/marketplace/v1/state.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/regen-network/regen-ledger/x/ecocredit/marketplace";

// AllowDenomProposal is a gov Content type for approving a denom for use in the
// marketplace.
message AllowDenomProposal {
option (gogoproto.goproto_stringer) = false;

// title is the title of the proposal.
string title = 1;

// description is the description of the proposal.
string description = 2;

// denom contains coin denom information that will be added to the
// list of allowed denoms for use in the marketplace.
AllowedDenom denom = 3;
}
7 changes: 7 additions & 0 deletions proto/regen/ecocredit/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,10 @@ message EventBatchSealed {
// batch_denom is the denom of the batch that was sealed.
string batch_denom = 1;
}

// EventAddCreditType is emitted when governance approves a new credit type.
message EventAddCreditType {

// abbreviation is the abbreviation of the credit type.
string abbreviation = 1;
}
18 changes: 0 additions & 18 deletions proto/regen/ecocredit/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,6 @@ message Params {
// allowlist_enabled is a param that enables/disables the allowlist for credit
// creation
bool allowlist_enabled = 4;

// allowed_ask_denoms is a list of denoms (and display information) allowed to
// be used in sell order ask prices.
repeated AskDenom allowed_ask_denoms = 6;
}

// AskDenom defines the structure for a coin denom.
message AskDenom {

// denom is the denom to allow (ex. ibc/GLKHDSG423SGS)
string denom = 1;

// display_denom is the denom to display to the user and is informational
string display_denom = 2;

// exponent is the exponent that relates the denom to the display_denom and is
// informational
uint32 exponent = 3;
}

// OriginTx is a reference to an external transaction or an operation
Expand Down
86 changes: 86 additions & 0 deletions x/ecocredit/client/marketplace/proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package marketplace

import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
"github.com/cosmos/cosmos-sdk/x/gov/client/rest"
"github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/regen-network/regen-ledger/x/ecocredit/marketplace"
)

var AllowDenomProposalHandler = govclient.NewProposalHandler(TxAllowDenomProposal, func(context client.Context) rest.ProposalRESTHandler {
return rest.ProposalRESTHandler{
SubRoute: "",
Handler: nil,
}
})

func TxAllowDenomProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "allow-denom-proposal [path_to_file.json] [flags]",
Args: cobra.ExactArgs(1),
Short: "Submit a proposal to add a denom to the list of allowed denoms",
Long: strings.TrimSpace(`Submit a proposal to add a denom to the list of allowed denoms for use in the marketplace.
The json file MUST take the following form:
{
"title": "some title",
"description": "some description",
"denom": {
"bank_denom": "uregen",
"display_denom": "regen",
"exponent": 6
}
}
The bank denom is the underlying coin denom (i.e. ibc/CDC4587874B85BEA4FCEC3CEA5A1195139799A1FEE711A07D972537E18FD).
Display denom is used for display purposes, and serves as the name of the coin denom (i.e. ATOM). Exponent is used to
relate the bank_denom to the display_denom and is informational`),
Example: `regen tx gov submit-proposal allow-denom-proposal my_file.json --deposit=100regen`,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposalFile, err := ioutil.ReadFile(args[0])
if err != nil {
return err
}

var proposal marketplace.AllowDenomProposal
err = json.Unmarshal(proposalFile, &proposal)
if err != nil {
return err
}
if err := proposal.ValidateBasic(); err != nil {
return fmt.Errorf("invalid proposal: %w", err)
}

depositStr, err := cmd.Flags().GetString(cli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(depositStr)
if err != nil {
return err
}
var content types.Content = &proposal
msg, err := types.NewMsgSubmitProposal(content, deposit, clientCtx.GetFromAddress())
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal")
return cmd
}
8 changes: 4 additions & 4 deletions x/ecocredit/client/testsuite/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (s *IntegrationTestSuite) TestQueryParams() {
func (s *IntegrationTestSuite) TestQuerySellOrder() {
val := s.network.Validators[0]
_, _, batchDenom := s.createClassProjectBatch(val.ClientCtx, val.Address.String())
validAsk := types.NewInt64Coin(core.DefaultParams().AllowedAskDenoms[0].Denom, 10)
validAsk := types.NewInt64Coin(types.DefaultBondDenom, 10)
expiration, err := types2.ParseDate("expiration", "2090-10-10")
s.Require().NoError(err)
orderIds, err := s.createSellOrder(val.ClientCtx, &marketplace.MsgSell{
Expand Down Expand Up @@ -311,7 +311,7 @@ func (s *IntegrationTestSuite) TestQuerySellOrder() {
func (s *IntegrationTestSuite) TestQuerySellOrders() {
val := s.network.Validators[0]
_, _, batchDenom := s.createClassProjectBatch(val.ClientCtx, val.Address.String())
validAsk := types.NewInt64Coin(core.DefaultParams().AllowedAskDenoms[0].Denom, 10)
validAsk := types.NewInt64Coin(types.DefaultBondDenom, 10)
expiration, err := types2.ParseDate("expiration", "2090-10-10")
s.Require().NoError(err)
_, err = s.createSellOrder(val.ClientCtx, &marketplace.MsgSell{
Expand Down Expand Up @@ -365,7 +365,7 @@ func (s *IntegrationTestSuite) TestQuerySellOrders() {
func (s *IntegrationTestSuite) TestQuerySellOrdersByBatchDenom() {
val := s.network.Validators[0]
_, _, batchDenom := s.createClassProjectBatch(val.ClientCtx, val.Address.String())
validAsk := types.NewInt64Coin(core.DefaultParams().AllowedAskDenoms[0].Denom, 10)
validAsk := types.NewInt64Coin(types.DefaultBondDenom, 10)
expiration, err := types2.ParseDate("expiration", "2090-10-10")
s.Require().NoError(err)
_, err = s.createSellOrder(val.ClientCtx, &marketplace.MsgSell{
Expand Down Expand Up @@ -418,7 +418,7 @@ func (s *IntegrationTestSuite) TestQuerySellOrdersByBatchDenom() {
func (s *IntegrationTestSuite) TestQuerySellOrdersByAddress() {
val := s.network.Validators[0]
_, _, batchDenom := s.createClassProjectBatch(val.ClientCtx, val.Address.String())
validAsk := types.NewInt64Coin(core.DefaultParams().AllowedAskDenoms[0].Denom, 10)
validAsk := types.NewInt64Coin(types.DefaultBondDenom, 10)
expiration, err := types2.ParseDate("expiration", "2090-10-10")
s.Require().NoError(err)
_, err = s.createSellOrder(val.ClientCtx, &marketplace.MsgSell{
Expand Down
8 changes: 4 additions & 4 deletions x/ecocredit/client/testsuite/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func (s *IntegrationTestSuite) TestQuerySellOrderCmd() {
clientCtx := val.ClientCtx
clientCtx.OutputFormat = "JSON"
_, _, batchDenom := s.createClassProjectBatch(clientCtx, val.Address.String())
validAsk := sdk.NewInt64Coin(core.DefaultParams().AllowedAskDenoms[0].Denom, 10)
validAsk := sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)
expiration, err := types.ParseDate("expiration", "2050-03-11")
s.Require().NoError(err)
orderIds, err := s.createSellOrder(clientCtx, &marketplace.MsgSell{
Expand Down Expand Up @@ -490,7 +490,7 @@ func (s *IntegrationTestSuite) TestQuerySellOrdersCmd() {
clientCtx := val.ClientCtx
clientCtx.OutputFormat = "JSON"
_, _, batchDenom := s.createClassProjectBatch(clientCtx, val.Address.String())
validAsk := sdk.NewInt64Coin(core.DefaultParams().AllowedAskDenoms[0].Denom, 10)
validAsk := sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)
expiration, err := types.ParseDate("expiration", "2050-03-11")
s.Require().NoError(err)

Expand Down Expand Up @@ -547,7 +547,7 @@ func (s *IntegrationTestSuite) TestQuerySellOrdersByAddressCmd() {
clientCtx := val.ClientCtx
clientCtx.OutputFormat = "JSON"
_, _, batchDenom := s.createClassProjectBatch(clientCtx, val.Address.String())
validAsk := sdk.NewInt64Coin(core.DefaultParams().AllowedAskDenoms[0].Denom, 10)
validAsk := sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)
expiration, err := types.ParseDate("expiration", "2050-03-11")
s.Require().NoError(err)
_, err = s.createSellOrder(clientCtx, &marketplace.MsgSell{
Expand Down Expand Up @@ -609,7 +609,7 @@ func (s *IntegrationTestSuite) TestQuerySellOrdersByBatchDenomCmd() {
clientCtx := val.ClientCtx
clientCtx.OutputFormat = "JSON"
_, _, batchDenom := s.createClassProjectBatch(clientCtx, val.Address.String())
validAsk := sdk.NewInt64Coin(core.DefaultParams().AllowedAskDenoms[0].Denom, 10)
validAsk := sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)
expiration, err := types.ParseDate("expiration", "2050-03-11")
s.Require().NoError(err)

Expand Down
13 changes: 10 additions & 3 deletions x/ecocredit/client/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
dbm "github.com/tendermint/tm-db"
"google.golang.org/protobuf/types/known/timestamppb"

marketApi "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1"
api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1"
"github.com/regen-network/regen-ledger/types"
"github.com/regen-network/regen-ledger/types/testutil/cli"
Expand Down Expand Up @@ -83,6 +84,13 @@ func (s *IntegrationTestSuite) setupCustomGenesis() {
ormCtx := ormtable.WrapContextDefault(backend)
ss, err := api.NewStateStore(modDB)
s.Require().NoError(err)
ms, err := marketApi.NewStateStore(modDB)

err = ms.AllowedDenomTable().Insert(ormCtx, &marketApi.AllowedDenom{
BankDenom: sdk.DefaultBondDenom,
DisplayDenom: sdk.DefaultBondDenom,
})
s.Require().NoError(err)

err = ss.CreditTypeTable().Insert(ormCtx, &api.CreditType{
Abbreviation: "C",
Expand Down Expand Up @@ -1113,8 +1121,7 @@ func (s *IntegrationTestSuite) TestTxUpdateSellOrders() {
val0 := s.network.Validators[0]
valAddrStr := val0.Address.String()
clientCtx := val0.ClientCtx
validAskDenom := core.DefaultParams().AllowedAskDenoms[0].Denom
askCoin := sdk.NewInt64Coin(validAskDenom, 10)
askCoin := sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)
expiration, err := types.ParseDate("expiration", "3020-04-15")
s.Require().NoError(err)
_, _, batchDenom := s.createClassProjectBatch(clientCtx, valAddrStr)
Expand All @@ -1138,7 +1145,7 @@ func (s *IntegrationTestSuite) TestTxUpdateSellOrders() {
return append(args, s.commonTxFlags()...)
}

newAsk := sdk.NewInt64Coin(validAskDenom, 3)
newAsk := sdk.NewInt64Coin(askCoin.Denom, 3)
newExpiration, err := types.ParseDate("newExpiration", "2049-07-15")
s.Require().NoError(err)

Expand Down
2 changes: 0 additions & 2 deletions x/ecocredit/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/regen-network/regen-ledger/types"
basketcli "github.com/regen-network/regen-ledger/x/ecocredit/client/basket"
corecli "github.com/regen-network/regen-ledger/x/ecocredit/client/core"
marketplacecli "github.com/regen-network/regen-ledger/x/ecocredit/client/marketplace"
"github.com/regen-network/regen-ledger/x/ecocredit/core"
)
Expand Down Expand Up @@ -47,7 +46,6 @@ func TxCmd(name string) *cobra.Command {
TxCreateProject(),
TxUpdateProjectAdminCmd(),
TxUpdateProjectMetadataCmd(),
corecli.TxCreditTypeProposalCmd(),
basketcli.TxCreateBasket(),
basketcli.TxPutInBasket(),
basketcli.TxTakeFromBasket(),
Expand Down
3 changes: 3 additions & 0 deletions x/ecocredit/core/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

func RegisterTypes(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations((*govtypes.Content)(nil), &CreditTypeProposal{})
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

Expand All @@ -24,6 +26,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgUpdateClassIssuers{}, "regen.core/MsgUpdateClassIssuers", nil)
cdc.RegisterConcrete(&MsgUpdateProjectAdmin{}, "regen.core/MsgUpdateProjectAdmin", nil)
cdc.RegisterConcrete(&MsgUpdateProjectMetadata{}, "regen.core/MsgUpdateProjectMetadata", nil)
cdc.RegisterConcrete(&CreditTypeProposal{}, "regen.core/CreditTypeProposal", nil)
}

var (
Expand Down
Loading

0 comments on commit ea43f14

Please sign in to comment.