Skip to content

Commit

Permalink
Merge pull request #169 from InjectiveLabs/dev
Browse files Browse the repository at this point in the history
feat/release changes for chain 1.22
  • Loading branch information
aarmoa authored Nov 1, 2023
2 parents d348923 + 3ac4c12 commit ed88785
Show file tree
Hide file tree
Showing 83 changed files with 32,308 additions and 25,427 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ copy-exchange-client:

copy-chain-types:
cp ../injective-core/injective-chain/types/*.go chain/types
rm -rf chain/types/*test.go rm -rf chain/types/*gw.go
cp ../injective-core/injective-chain/crypto/ethsecp256k1/*.go chain/crypto/ethsecp256k1
rm -rf chain/crypto/ethsecp256k1/*test.go rm -rf chain/crypto/ethsecp256k1/*gw.go
cp ../injective-core/injective-chain/modules/auction/types/*.go chain/auction/types
rm -rf chain/auction/types/*test.go rm -rf chain/auction/types/*gw.go
cp ../injective-core/injective-chain/modules/exchange/types/*.go chain/exchange/types
Expand All @@ -46,6 +48,8 @@ copy-chain-types:
rm -rf chain/wasmx/types/*test.go rm -rf chain/wasmx/types/*gw.go
cp ../injective-core/injective-chain/modules/tokenfactory/types/*.go chain/tokenfactory/types
rm -rf chain/tokenfactory/types/*test.go rm -rf chain/tokenfactory/types/*gw.go
cp ../injective-core/injective-chain/stream/types/*.go chain/stream/types

echo "👉 Replace injective-core/injective-chain/modules with sdk-go/chain"
echo "👉 Replace injective-core/injective-chain/types with sdk-go/chain/types"
echo "👉 Replace injective-core/injective-chain/crypto with sdk-go/chain/crypto"
8 changes: 8 additions & 0 deletions chain/exchange/types/common_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,11 @@ func (m *OrderType) UnmarshalJSON(data []byte) error {
*m = OrderType(value)
return nil
}

// GetOrderIdentifier returns the cid of an order if it exists, otherwise returns the order hash
func GetOrderIdentifier(orderHash, cid string) any {
if cid != "" {
return cid
}
return common.HexToHash(orderHash)
}
17 changes: 14 additions & 3 deletions chain/exchange/types/common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func IsValidOrderHash(orderHash string) bool {
return IsHexHash(orderHash)
}

func IsValidCid(cid string) bool {
// Arbitrarily setting max length of cid to uuid length
return len(cid) <= 36
}

// IsHexHash verifies whether a string can represent a valid hex-encoded hash or not.
func IsHexHash(s string) bool {
if !isHexString(s) {
Expand Down Expand Up @@ -337,12 +342,18 @@ func HasDuplicatesCoin(slice []sdk.Coin) bool {
}

func HasDuplicatesOrder(slice []*OrderData) bool {
seen := make(map[string]struct{})
seenHashes := make(map[string]struct{})
seenCids := make(map[string]struct{})
for _, item := range slice {
if _, ok := seen[item.OrderHash]; ok {
hash, cid := item.GetOrderHash(), item.GetCid()
_, hashExists := seenHashes[hash]
_, cidExists := seenCids[cid]

if (hash != "" && hashExists) || (cid != "" && cidExists) {
return true
}
seen[item.OrderHash] = struct{}{}
seenHashes[hash] = struct{}{}
seenCids[cid] = struct{}{}
}
return false
}
28 changes: 21 additions & 7 deletions chain/exchange/types/derivative_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import (
"github.com/ethereum/go-ethereum/common"
)

func NewMarketOrderForLiquidation(position *Position, positionSubaccountID common.Hash, liquidator sdk.AccAddress) *DerivativeMarketOrder {
func NewMarketOrderForLiquidation(
position *Position,
positionSubaccountID common.Hash,
liquidator sdk.AccAddress,
worstPrice sdk.Dec,
) *DerivativeMarketOrder {
var (
worstPrice sdk.Dec
orderType OrderType
orderType OrderType
)

// if long position, market sell order at price 0
// if short position, market buy order at price infinity
// if long position, market sell order
// if short position, market buy order
if position.IsLong {
worstPrice = sdk.ZeroDec()
orderType = OrderType_SELL
} else {
worstPrice = MaxOrderPrice
orderType = OrderType_BUY
}

Expand Down Expand Up @@ -447,10 +449,22 @@ func (o *DerivativeLimitOrder) IsConditional() bool {
return o.OrderType.IsConditional()
}

func (o *DerivativeLimitOrder) Cid() string {
return o.OrderInfo.GetCid()
}

func (o *DerivativeMarketOrder) Cid() string {
return o.OrderInfo.GetCid()
}

func (o *DerivativeOrder) SubaccountID() common.Hash {
return o.OrderInfo.SubaccountID()
}

func (o *DerivativeOrder) Cid() string {
return o.OrderInfo.GetCid()
}

func (o *DerivativeOrder) IsFromDefaultSubaccount() bool {
return o.OrderInfo.IsFromDefaultSubaccount()
}
Expand Down
3 changes: 3 additions & 0 deletions chain/exchange/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ var (
ErrTooMuchOrderMargin = errors.Register(ModuleName, 93, "Order has too much margin")
ErrBadSubaccountNonce = errors.Register(ModuleName, 94, "Subaccount nonce is invalid")
ErrInsufficientFunds = errors.Register(ModuleName, 95, "insufficient funds")
ErrPostOnlyMode = errors.Register(ModuleName, 96, "exchange is in post-only mode")
ErrClientOrderIdAlreadyExists = errors.Register(ModuleName, 97, "client order id already exists")
ErrInvalidCid = errors.Register(ModuleName, 98, "client order id is invalid. Max length is 36 chars")
)
4 changes: 1 addition & 3 deletions chain/exchange/types/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ func (e ExecutionType) IsTaker() bool {

func (s MarketStatus) SupportsOrderCancellations() bool {
switch s {
case MarketStatus_Active, MarketStatus_Demolished, MarketStatus_Expired:
case MarketStatus_Active, MarketStatus_Demolished, MarketStatus_Expired, MarketStatus_Paused:
return true
case MarketStatus_Paused:
return false
default:
return false
}
Expand Down
Loading

0 comments on commit ed88785

Please sign in to comment.