Skip to content

Commit

Permalink
Updated chain module exchange types
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim committed Mar 17, 2021
1 parent f167199 commit e7b7d37
Show file tree
Hide file tree
Showing 27 changed files with 13,616 additions and 21,006 deletions.
75 changes: 0 additions & 75 deletions chain/client/contract_discover.go

This file was deleted.

36 changes: 22 additions & 14 deletions chain/exchange/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

Expand All @@ -16,26 +17,33 @@ var (
ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
)

// RegisterCodec registers concrete types on the Amino codec
// RegisterInterfaces registers concrete types on the Amino codec
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgInitExchange{},
&MsgRegisterDerivativeMarket{},
&MsgSuspendDerivativeMarket{},
&MsgResumeDerivativeMarket{},
&MsgCreateDerivativeOrder{},
&MsgSoftCancelDerivativeOrder{},
&MsgRegisterSpotMarket{},
&MsgSuspendSpotMarket{},
&MsgResumeSpotMarket{},
&MsgCreateSpotOrder{},
&MsgExecuteDerivativeTakeOrder{},
&MsgExecuteTECTransaction{},
&MsgDeposit{},
&MsgWithdraw{},
&MsgInstantSpotMarketLaunch{},
&MsgCreateSpotLimitOrder{},
&MsgCreateSpotMarketOrder{},
&MsgCancelSpotOrder{},
&MsgCreateDerivativeLimitOrder{},
&MsgCreateDerivativeMarketOrder{},
&MsgCancelDerivativeOrder{},
&MsgSubaccountTransfer{},
&MsgExternalTransfer{},
)

registry.RegisterImplementations(
(*govtypes.Content)(nil),
&RegisterExchangeProposal{},
&SpotMarketParamUpdateProposal{},
&SpotMarketLaunchProposal{},
&SpotMarketStatusSetProposal{},
&PerpetualMarketLaunchProposal{},
&ExpiryFuturesMarketLaunchProposal{},
&DerivativeMarketParamUpdateProposal{},
&DerivativeMarketStatusSetProposal{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
38 changes: 38 additions & 0 deletions chain/exchange/types/coin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
// INJ defines the default coin denomination used in Ethermint in:
//
// - Staking parameters: denomination used as stake in the dPoS chain
// - Mint parameters: denomination minted due to fee distribution rewards
// - Governance parameters: denomination used for spam prevention in proposal deposits
// - Crisis parameters: constant fee denomination used for spam prevention to check broken invariant
// - EVM parameters: denomination used for running EVM state transitions in Ethermint.
InjectiveCoin string = "inj"

// BaseDenomUnit defines the base denomination unit for Photons.
// 1 photon = 1x10^{BaseDenomUnit} inj
BaseDenomUnit = 18
)

// NewInjectiveCoin is a utility function that returns an "inj" coin with the given sdk.Int amount.
// The function will panic if the provided amount is negative.
func NewInjectiveCoin(amount sdk.Int) sdk.Coin {
return sdk.NewCoin(InjectiveCoin, amount)
}

// NewInjectiveDecCoin is a utility function that returns an "inj" decimal coin with the given sdk.Int amount.
// The function will panic if the provided amount is negative.
func NewInjectiveDecCoin(amount sdk.Int) sdk.DecCoin {
return sdk.NewDecCoin(InjectiveCoin, amount)
}

// NewInjectiveCoinInt64 is a utility function that returns an "inj" coin with the given int64 amount.
// The function will panic if the provided amount is negative.
func NewInjectiveCoinInt64(amount int64) sdk.Coin {
return sdk.NewInt64Coin(InjectiveCoin, amount)
}
29 changes: 22 additions & 7 deletions chain/exchange/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
var (
ErrOrderInvalid = sdkerrors.Register(ModuleName, 1, "failed to validate order")
ErrOrderNotFound = sdkerrors.Register(ModuleName, 2, "no active order found for the hash")
ErrPairSuspended = sdkerrors.Register(ModuleName, 3, "trade pair suspended")
ErrPairNotFound = sdkerrors.Register(ModuleName, 4, "trade pair not found")
ErrSpotMarketExists = sdkerrors.Register(ModuleName, 5, "trade pair exists")
ErrPairMismatch = sdkerrors.Register(ModuleName, 6, "trade pair mismatch")
ErrSpotMarketSuspended = sdkerrors.Register(ModuleName, 3, "spot market suspended")
ErrSpotMarketNotFound = sdkerrors.Register(ModuleName, 4, "spot market not found")
ErrSpotMarketExists = sdkerrors.Register(ModuleName, 5, "spot market exists")
ErrSpotMarketMismatch = sdkerrors.Register(ModuleName, 6, "spot market mismatch")
ErrBadField = sdkerrors.Register(ModuleName, 7, "struct field error")
ErrMarketNotFound = sdkerrors.Register(ModuleName, 8, "derivative market not found")
ErrMarketInvalid = sdkerrors.Register(ModuleName, 9, "failed to validate derivative market")
Expand All @@ -21,7 +21,7 @@ var (
ErrOverLeveragedOrder = sdkerrors.Register(ModuleName, 14, "cannot add overlevered order")
ErrSubaccountNotFound = sdkerrors.Register(ModuleName, 15, "subaccount not found")
ErrOrderAlreadyExists = sdkerrors.Register(ModuleName, 16, "order already exists")
ErrInsufficientMargin = sdkerrors.Register(ModuleName, 17, "subaccount has insufficient margin")
ErrInsufficientDeposit = sdkerrors.Register(ModuleName, 17, "subaccount has insufficient margin")
ErrMarketExpired = sdkerrors.Register(ModuleName, 18, "market has already expired")
ErrOrderExpired = sdkerrors.Register(ModuleName, 19, "order has already expired")
ErrInsufficientOrderQuantity = sdkerrors.Register(ModuleName, 20, "order quantity invalid")
Expand All @@ -34,6 +34,21 @@ var (
ErrReplayTecTransaction = sdkerrors.Register(ModuleName, 27, "cannot replay TEC transaction")
ErrOrderAlreadyArchived = sdkerrors.Register(ModuleName, 28, "order already in archive store")
ErrAddressNotContract = sdkerrors.Register(ModuleName, 29, "address is not a smart contract")
ErrExchangeAlreadySet = sdkerrors.Register(ModuleName, 30, "Exchange address already set")
ErrBadExchangeAddress = sdkerrors.Register(ModuleName, 31, "Bad exchange address")
ErrOrderIDInvalid = sdkerrors.Register(ModuleName, 30, "order id is not valid")
ErrBadSubaccountID = sdkerrors.Register(ModuleName, 31, "subaccount id is not valid")
ErrInvalidTicker = sdkerrors.Register(ModuleName, 32, "invalid ticker")
ErrInvalidBaseDenom = sdkerrors.Register(ModuleName, 33, "invalid base denom")
ErrInvalidQuoteDenom = sdkerrors.Register(ModuleName, 34, "invalid quote denom")
ErrOrderDoesntExist = sdkerrors.Register(ModuleName, 35, "order doesnt exist")

ErrDepositDoesntExist = sdkerrors.Register(ModuleName, 37, "deposit doesnt exist")
ErrOrderbookDoesntExist = sdkerrors.Register(ModuleName, 38, "spot limit orderbook doesnt exist")
ErrOrderbookFillInvalid = sdkerrors.Register(ModuleName, 39, "spot limit orderbook fill invalid")
ErrPerpetualMarketExists = sdkerrors.Register(ModuleName, 40, "perpetual market exists")
ErrExpiryFuturesMarketExists = sdkerrors.Register(ModuleName, 41, "expiry futures market exists")
ErrExpiryFuturesMarketExpired = sdkerrors.Register(ModuleName, 42, "expiry futures market expired")
ErrNoLiquidity = sdkerrors.Register(ModuleName, 43, "no liquidity on the orderbook!")
ErrSlippageExceedsWorstPrice = sdkerrors.Register(ModuleName, 44, "Orderbook liquidity cannot satisfy current worst price")
ErrInsufficientOrderMargin = sdkerrors.Register(ModuleName, 45, "Order has insufficient margin")
ErrDerivativeMarketNotFound = sdkerrors.Register(ModuleName, 46, "Derivative market not found")
)
2 changes: 1 addition & 1 deletion chain/exchange/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
AttributeKeyTradePairHash = "trade_pair_hash"
AttributeKeySignedOrder = "signed_order"
AttributeKeyFilledAmount = "filled_amount"
AttributeKeyUnfilledAmount = "unfilled_amount"
AttributeKeyFillableAmount = "fillable_amount"
AttributeKeyWasActiveOrder = "was_active_order"
AttributeKeyPrice = "price"
AttributeKeyTicker = "ticker"
Expand Down
Loading

0 comments on commit e7b7d37

Please sign in to comment.