Skip to content

Commit

Permalink
Merge pull request #253 from terra-money/fix/v2.9/proto
Browse files Browse the repository at this point in the history
fix(v2.9): register pob interface
  • Loading branch information
tuky191 authored Jan 16, 2024
2 parents 40e30e1 + 7d60841 commit 7b83bd0
Show file tree
Hide file tree
Showing 9 changed files with 2,201 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/cosmos/cosmos-sdk/std"

"github.com/terra-money/core/v2/app/params"
pobtypes "github.com/terra-money/core/v2/x/builder/types"
)

var legacyCodecRegistered = false
Expand All @@ -17,6 +18,11 @@ func MakeEncodingConfig() params.EncodingConfig {
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)

// Register POB interfaces and concrete types
// for the POB module that was used back in the day.
pobtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
pobtypes.RegisterLegacyAminoCodec(encodingConfig.Amino)

if !legacyCodecRegistered {
// authz module use this codec to get signbytes.
// authz MsgExec can execute all message types,
Expand Down
44 changes: 44 additions & 0 deletions proto/pob/builder/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
syntax = "proto3";
package pob.builder.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "amino/amino.proto";

option go_package = "github.com/skip-mev/pob/x/builder/types";

// GenesisState defines the genesis state of the x/builder module.
message GenesisState { Params params = 1 [ (gogoproto.nullable) = false ]; }

// Params defines the parameters of the x/builder module.
message Params {
option (amino.name) = "cosmos-sdk/x/builder/Params";

// max_bundle_size is the maximum number of transactions that can be bundled
// in a single bundle.
uint32 max_bundle_size = 1;

// escrow_account_address is the address of the account that will receive a
// portion of the bid proceeds.
bytes escrow_account_address = 2;

// reserve_fee specifies the bid floor for the auction.
cosmos.base.v1beta1.Coin reserve_fee = 3
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];

// min_bid_increment specifies the minimum amount that the next bid must be
// greater than the previous bid.
cosmos.base.v1beta1.Coin min_bid_increment = 4
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];

// front_running_protection specifies whether front running and sandwich
// attack protection is enabled.
bool front_running_protection = 5;

// proposer_fee defines the portion of the winning bid that goes to the block
// proposer that proposed the block.
string proposer_fee = 6 [
(gogoproto.nullable) = false,
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"
];
}
67 changes: 67 additions & 0 deletions proto/pob/builder/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
syntax = "proto3";
package pob.builder.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
import "pob/builder/v1/genesis.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";

option go_package = "github.com/skip-mev/pob/x/builder/types";

// Msg defines the x/builder Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// AuctionBid defines a method for sending bids to the x/builder module.
rpc AuctionBid(MsgAuctionBid) returns (MsgAuctionBidResponse) {
option (google.api.http).post = "/pob/builder/v1/bid";
};

// UpdateParams defines a governance operation for updating the x/builder
// module parameters. The authority is hard-coded to the x/gov module account.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgAuctionBid defines a request type for sending bids to the x/builder
// module.
message MsgAuctionBid {
option (cosmos.msg.v1.signer) = "bidder";
option (amino.name) = "pob/x/builder/MsgAuctionBid";

option (gogoproto.equal) = false;

// bidder is the address of the account that is submitting a bid to the
// auction.
string bidder = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// bid is the amount of coins that the bidder is bidding to participate in the
// auction.
cosmos.base.v1beta1.Coin bid = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
// transactions are the bytes of the transactions that the bidder wants to
// bundle together.
repeated bytes transactions = 3;
}

// MsgAuctionBidResponse defines the Msg/AuctionBid response type.
message MsgAuctionBidResponse {}

// MsgUpdateParams defines a request type for updating the x/builder module
// parameters.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "pob/x/builder/MsgUpdateParams";

option (gogoproto.equal) = false;

// authority is the address of the account that is authorized to update the
// x/builder module parameters.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// params is the new parameters for the x/builder module.
Params params = 2 [ (gogoproto.nullable) = false ];
}

// MsgUpdateParamsResponse defines the Msg/UpdateParams response type.
message MsgUpdateParamsResponse {}
3 changes: 2 additions & 1 deletion scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
echo "Generating gogo proto code"
cd proto

proto_dirs=$(find ./osmosis ./juno ./terra -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
proto_dirs=$(find ./osmosis ./juno ./terra ./pob -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
# this regex checks if a proto file has its go_package set to cosmossdk.io/api/...
Expand All @@ -22,5 +22,6 @@ cd ..
# move proto files to the right places
cp -r github.com/osmosis-labs/osmosis/v17/* ./
cp -r github.com/CosmosContracts/juno/* ./
cp -r github.com/skip-mev/pob/* ./
cp -r github.com/terra-money/core/v2/* ./
rm -rf github.com
53 changes: 53 additions & 0 deletions x/builder/types/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package types

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
)

var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterLegacyAminoCodec(amino)
cryptocodec.RegisterCrypto(amino)
sdk.RegisterLegacyAminoCodec(amino)

// Register all Amino interfaces and concrete types on the authz and gov
// Amino codec so that this can later be used to properly serialize MsgGrant,
// MsgExec and MsgSubmitProposal instances.
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
}

// RegisterLegacyAminoCodec registers the necessary x/builder interfaces and
// concrete types on the provided LegacyAmino codec. These types are used for
// Amino JSON serialization.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacy.RegisterAminoMsg(cdc, &MsgAuctionBid{}, "pob/x/builder/MsgAuctionBid")
legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "pob/x/builder/MsgUpdateParams")

cdc.RegisterConcrete(Params{}, "pob/builder/Params", nil)
}

// RegisterInterfaces registers the x/builder interfaces types with the
// interface registry.
func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgAuctionBid{},
&MsgUpdateParams{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
Loading

0 comments on commit 7b83bd0

Please sign in to comment.