forked from DongCoNY/research-cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
9,016 additions
and
52 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
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,74 @@ | ||
package apptesting | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
ibctesting "github.com/cosmos/ibc-go/v4/testing" | ||
"github.com/cosmos/ibc-go/v4/testing/simapp" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/tendermint/tendermint/crypto/ed25519" | ||
tmtypes "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
||
"github.com/DongCoNY/research-cosmos/app" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
) | ||
|
||
var ( | ||
ChainID = "DONGTRAMCAM" | ||
) | ||
|
||
type AppTestHelper struct { | ||
suite.Suite | ||
|
||
App *app.App | ||
HostApp *simapp.SimApp | ||
|
||
IbcEnabled bool | ||
Coordinator *ibctesting.Coordinator | ||
GravityChain *ibctesting.TestChain | ||
HostChain *ibctesting.TestChain | ||
TransferPath *ibctesting.Path | ||
|
||
QueryHelper *baseapp.QueryServiceTestHelper | ||
TestAccs []sdk.AccAddress | ||
IcaAddresses map[string]string | ||
Ctx sdk.Context | ||
} | ||
|
||
// AppTestHelper Constructor | ||
func (s *AppTestHelper) Setup() { | ||
s.App = app.InitGravityTestApp(true) | ||
// nolint: exhaustruct | ||
s.Ctx = s.App.BaseApp.NewContext(false, tmtypes.Header{Height: 1, ChainID: ChainID}) | ||
s.QueryHelper = &baseapp.QueryServiceTestHelper{ | ||
GRPCQueryRouter: s.App.GRPCQueryRouter(), | ||
Ctx: s.Ctx, | ||
} | ||
s.TestAccs = CreateRandomAccounts(3) | ||
s.IbcEnabled = false | ||
s.IcaAddresses = make(map[string]string) | ||
} | ||
|
||
func (s *AppTestHelper) FundAccount(ctx sdk.Context, addr sdk.AccAddress, amounts sdk.Coins) { | ||
bankkeeper := s.App.GetBankKeeper() | ||
bankkeeper.MintCoins(ctx, minttypes.ModuleName, amounts) | ||
bankkeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts) | ||
} | ||
|
||
func (s *AppTestHelper) FundModule(ctx sdk.Context, moduleName string, amounts sdk.Coins) { | ||
bankkeeper := s.App.GetBankKeeper() | ||
bankkeeper.MintCoins(ctx, minttypes.ModuleName, amounts) | ||
bankkeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, moduleName, amounts) | ||
} | ||
|
||
// Generate random account addresss | ||
func CreateRandomAccounts(numAccts int) []sdk.AccAddress { | ||
testAddrs := make([]sdk.AccAddress, numAccts) | ||
for i := 0; i < numAccts; i++ { | ||
pk := ed25519.GenPrivKey().PubKey() | ||
testAddrs[i] = sdk.AccAddress(pk.Address()) | ||
} | ||
|
||
return testAddrs | ||
} |
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
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,90 @@ | ||
package config | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/address" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/version" | ||
) | ||
|
||
const ( | ||
// Bech32Prefix defines the Bech32 prefix used for EthAccounts | ||
Bech32Prefix = "dongtramcam" | ||
|
||
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address | ||
Bech32PrefixAccAddr = Bech32Prefix | ||
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key | ||
Bech32PrefixAccPub = Bech32Prefix + sdk.PrefixPublic | ||
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address | ||
Bech32PrefixValAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator | ||
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key | ||
Bech32PrefixValPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic | ||
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address | ||
Bech32PrefixConsAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus | ||
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key | ||
Bech32PrefixConsPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic | ||
) | ||
|
||
const ( | ||
HumanReadableCoinUnit = "DONGTRAMCAM" | ||
BaseCoinUnit = "udongtramcam" | ||
DefaultBondDenom = BaseCoinUnit | ||
) | ||
|
||
func SetupConfig() { | ||
config := sdk.GetConfig() | ||
SetBech32Prefixes(config) | ||
SetBip44CoinType(config) | ||
SetAddressPrefixes(config) | ||
config.Seal() | ||
|
||
version.AppName = "dongtramcam" | ||
version.Name = "dongtramcamd" | ||
} | ||
|
||
// SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings. | ||
func SetBech32Prefixes(config *sdk.Config) { | ||
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) | ||
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) | ||
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub) | ||
} | ||
|
||
// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets. | ||
func SetBip44CoinType(config *sdk.Config) { | ||
config.SetCoinType(sdk.CoinType) | ||
config.SetPurpose(sdk.Purpose) // Shared | ||
} | ||
|
||
// RegisterDenoms registers the base and display denominations to the SDK. | ||
func RegisterDenoms() { | ||
if err := sdk.RegisterDenom(HumanReadableCoinUnit, sdk.OneDec()); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := sdk.RegisterDenom(BaseCoinUnit, sdk.NewDecWithPrec(1, 6)); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// SetAddressPrefixes builds the Config with Bech32 addressPrefix and publKeyPrefix for accounts, validators, and consensus nodes and verifies that addresses have correct format. | ||
|
||
func SetAddressPrefixes(config *sdk.Config) { | ||
// This is copied from the cosmos sdk v0.43.0-beta1 | ||
// source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141 | ||
config.SetAddressVerifier(func(bytes []byte) error { | ||
if len(bytes) == 0 { | ||
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty") | ||
} | ||
|
||
if len(bytes) > address.MaxAddrLen { | ||
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes)) | ||
} | ||
|
||
// TODO: Do we want to allow addresses of lengths other than 20 and 32 bytes? | ||
if len(bytes) != 20 && len(bytes) != 32 { | ||
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes)) | ||
} | ||
|
||
return nil | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module dongtramcam | ||
module github.com/DongCoNY/research-cosmos | ||
|
||
go 1.18 | ||
|
||
|
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,59 @@ | ||
syntax = "proto3"; | ||
package auction.v1; | ||
|
||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/DongCoNY/research-cosmos/x/auction/types"; | ||
|
||
// AuctionPeriod represents a period of auctions. | ||
// Each AuctionPeriod has a unique identifier and a starting block height. | ||
// An AuctionPeriod can have multiple Auctions. | ||
message AuctionPeriod { | ||
uint64 id = 1; // Unique identifier for the AuctionPeriod. | ||
uint64 start_block_height = 2; // Block height at which the AuctionPeriod starts. | ||
uint64 end_block_height = 3; // Block height at which the AuctionPeriod end. | ||
} | ||
|
||
// AuctionStatus represents the status of an Auction. | ||
// An Auction can be either in progress or finished. | ||
enum AuctionStatus{ | ||
// The Auction status is unspecified. Probaly haven't started yet. | ||
AUCTION_STATUS_UNSPECIFIED = 0; | ||
// The Auction is still ongoing. | ||
AUCTION_STATUS_IN_PROGRESS = 1; | ||
// The Auction has ended. | ||
AUCTION_STATUS_FINISH = 2; | ||
} | ||
|
||
// Auction represents a single auction. | ||
// An Auction has a unique identifier relative to its Auction Period Id , an amount being auctioned, a status, and a highest bid. | ||
message Auction { | ||
uint64 id = 1; // Unique identifier for the Auction. | ||
cosmos.base.v1beta1.Coin auction_amount = 2; // Amount being auctioned. | ||
AuctionStatus status = 3; // Status of the Auction. | ||
Bid highest_bid = 4; // Highest bid on the Auction. | ||
uint64 auction_period_id = 5; // Identifier of the AuctionPeriod the Auction belongs to. | ||
} | ||
|
||
// Bid represents a bid on an Auction. | ||
// A Bid includes the identifier of the Auction, the amount of the bid, and the address of the bidder. | ||
message Bid { | ||
uint64 auction_id = 1; // Identifier of the Auction. | ||
cosmos.base.v1beta1.Coin bid_amount = 2; // Amount of the bid. | ||
string bidder_address = 3; // Address of the bidder. | ||
} | ||
|
||
// Store the block height of the last auction period | ||
message LastAuctionPeriodHeight { | ||
uint64 height = 1; | ||
} | ||
|
||
// Estimate the block height of the next auction period | ||
message EstimateNextAuctionPeriodHeight { | ||
uint64 height = 1; | ||
} | ||
|
||
// Queue of Bids for 1 auction | ||
message BidsQueue { | ||
repeated Bid queue = 1; | ||
} |
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,12 @@ | ||
syntax = "proto3"; | ||
package auction.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "auction/v1/params.proto"; | ||
|
||
option go_package = "github.com/DongCoNY/research-cosmos/x/auction/types"; | ||
|
||
// GenesisState defines the auction module's genesis state. | ||
message GenesisState { | ||
Params params = 1 [ (gogoproto.nullable) = false ]; | ||
} |
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,26 @@ | ||
syntax = "proto3"; | ||
package auction.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
import "google/api/annotations.proto"; | ||
|
||
option go_package = "github.com/DongCoNY/research-cosmos/x/auction/types"; | ||
|
||
// Msg defines the state transitions possible within auction | ||
service Msg { | ||
rpc Bid(MsgBid) returns (MsgBidResponse) { | ||
option (google.api.http).post = "/auction/v1/bid"; | ||
} | ||
} | ||
|
||
// MsgBid is a message type for placing a bid on an auction | ||
message MsgBid { | ||
uint64 auction_id = 1 [(gogoproto.customname) = "AuctionId"]; // ID of the auction to bid on | ||
string bidder = 2 [(gogoproto.customname) = "Bidder"]; // Address of the bidder | ||
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.customname) = "Amount"]; // Amount of the bid | ||
} | ||
|
||
message MsgBidResponse { | ||
bool success = 1; | ||
} |
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,35 @@ | ||
syntax = "proto3"; | ||
package auction.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/DongCoNY/research-cosmos/x/auction/types"; | ||
|
||
// Params defines the parameters for the GravityBridge auction module. | ||
message Params { | ||
// AuctionEpoch is the number of blocks to start new auctions | ||
uint64 auction_epoch = 1; | ||
|
||
// AuctionPeriod is the number of blocks that the auction will occur | ||
uint64 auction_period = 2; | ||
|
||
// MinBidAmount is the minimum bid amount | ||
uint64 min_bid_amount = 3; | ||
|
||
// BidGap is the minimum gap required to raise a bid | ||
uint64 bid_gap = 4; | ||
|
||
// AuctionRate is the percentage of the token to be auctioned from the community pool | ||
bytes auction_rate = 5 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", | ||
(gogoproto.nullable) = false, | ||
(gogoproto.jsontag) = "quorum,omitempty" | ||
]; | ||
|
||
// AllowTokens is a list of allowed tokens to be auctioned | ||
map<string, bool> allow_tokens = 6; | ||
|
||
// Recovery when a period fail to initiate | ||
// Start a new period after N blocks | ||
// uint64 recover_blocks = 7; | ||
} |
Oops, something went wrong.