Skip to content

Commit

Permalink
chore: re-gen
Browse files Browse the repository at this point in the history
  • Loading branch information
albertchon committed Jun 30, 2022
1 parent bb88b1c commit 4ae5ee9
Show file tree
Hide file tree
Showing 13 changed files with 757 additions and 834 deletions.
22 changes: 20 additions & 2 deletions chain/exchange/types/common_order.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
package types

import (
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
ethmath "github.com/ethereum/go-ethereum/common/math"
gethsigner "github.com/ethereum/go-ethereum/signer/core"
"github.com/gogo/protobuf/proto"
"golang.org/x/crypto/sha3"

"strconv"
)

// GetRequiredBinaryOptionsOrderMargin returns the required margin for a binary options trade (or order) at a given price
func GetRequiredBinaryOptionsOrderMargin(
price sdk.Dec,
quantity sdk.Dec,
oracleScaleFactor uint32,
orderType OrderType,
isReduceOnly bool,
) sdk.Dec {
if isReduceOnly {
return sdk.ZeroDec()
}

if orderType.IsBuy() {
return price.Mul(quantity)
}
return GetScaledPrice(sdk.OneDec(), oracleScaleFactor).Sub(price).Mul(quantity)
}

func (t OrderType) IsBuy() bool {
switch t {
case OrderType_BUY, OrderType_STOP_BUY, OrderType_TAKE_BUY, OrderType_BUY_PO:
Expand Down
8 changes: 8 additions & 0 deletions chain/exchange/types/common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ func IsEqualDenoms(denoms1, denoms2 []string) bool {
return reflect.DeepEqual(denom1Map, denom2Map)
}

func IsPeggyToken(denom string) bool {
return strings.HasPrefix(denom, "peggy0x")
}

func IsIBCDenom(denom string) bool {
return strings.HasPrefix(denom, "ibc/")
}

type Account [20]byte

func SdkAccAddressToAccount(account sdk.AccAddress) Account {
Expand Down
2 changes: 1 addition & 1 deletion chain/exchange/types/derivative_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (o *DerivativeOrder) CheckMarginAndGetMarginHold(initialMarginRatio, markPr
if marketType == MarketType_BinaryOption {
requiredMargin := o.GetRequiredBinaryOptionsMargin(oracleScaleFactor)
if !o.Margin.Equal(requiredMargin) {
return sdk.Dec{}, sdkerrors.Wrapf(ErrInsufficientOrderMargin, "margin check: need %s but got %s", notional.String(), o.Margin.String())
return sdk.Dec{}, sdkerrors.Wrapf(ErrInsufficientOrderMargin, "margin check: need %s but got %s", requiredMargin.String(), o.Margin.String())
}
return marginHold, nil
}
Expand Down
263 changes: 165 additions & 98 deletions chain/exchange/types/genesis.pb.go

Large diffs are not rendered by default.

28 changes: 8 additions & 20 deletions chain/exchange/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (msg MsgInstantPerpetualMarketLaunch) ValidateBasic() error {
if err := oracleParams.ValidateBasic(); err != nil {
return err
}
if err := ValidateFee(msg.MakerFeeRate); err != nil {
if err := ValidateMakerFee(msg.MakerFeeRate); err != nil {
return err
}
if err := ValidateFee(msg.TakerFeeRate); err != nil {
Expand Down Expand Up @@ -375,12 +375,15 @@ func (msg MsgInstantBinaryOptionsMarketLaunch) ValidateBasic() error {
if msg.OracleScaleFactor > MaxOracleScaleFactor {
return ErrExceedsMaxOracleScaleFactor
}
if err := ValidateFee(msg.MakerFeeRate); err != nil {
if err := ValidateMakerFee(msg.MakerFeeRate); err != nil {
return err
}
if err := ValidateFee(msg.TakerFeeRate); err != nil {
return err
}
if msg.MakerFeeRate.GT(msg.TakerFeeRate) {
return ErrFeeRatesRelation
}
if msg.ExpirationTimestamp >= msg.SettlementTimestamp || msg.ExpirationTimestamp < 0 || msg.SettlementTimestamp < 0 {
return ErrInvalidExpiry
}
Expand Down Expand Up @@ -445,7 +448,7 @@ func (msg MsgInstantExpiryFuturesMarketLaunch) ValidateBasic() error {
if msg.Expiry <= 0 {
return sdkerrors.Wrap(ErrInvalidExpiry, "expiry should not be empty")
}
if err := ValidateFee(msg.MakerFeeRate); err != nil {
if err := ValidateMakerFee(msg.MakerFeeRate); err != nil {
return err
}
if err := ValidateFee(msg.TakerFeeRate); err != nil {
Expand Down Expand Up @@ -714,15 +717,7 @@ func NewMsgCreateBinaryOptionsLimitOrder(
orderType OrderType,
isReduceOnly bool,
) *MsgCreateBinaryOptionsLimitOrder {
margin := sdk.ZeroDec()

if !isReduceOnly {
if orderType == OrderType_BUY {
margin = price.Mul(quantity)
} else {
margin = GetScaledPrice(sdk.OneDec(), market.OracleScaleFactor).Sub(price).Mul(quantity)
}
}
margin := GetRequiredBinaryOptionsOrderMargin(price, quantity, market.OracleScaleFactor, orderType, isReduceOnly)

return &MsgCreateBinaryOptionsLimitOrder{
Sender: sender.String(),
Expand Down Expand Up @@ -862,14 +857,7 @@ func NewMsgCreateBinaryOptionsMarketOrder(
orderType OrderType,
isReduceOnly bool,
) *MsgCreateBinaryOptionsMarketOrder {
margin := sdk.ZeroDec()
if !isReduceOnly {
if orderType == OrderType_BUY {
margin = price.Mul(quantity)
} else {
margin = GetScaledPrice(sdk.OneDec(), market.OracleScaleFactor).Sub(price).Mul(quantity)
}
}
margin := GetRequiredBinaryOptionsOrderMargin(price, quantity, market.OracleScaleFactor, orderType, isReduceOnly)

return &MsgCreateBinaryOptionsMarketOrder{
Sender: sender.String(),
Expand Down
18 changes: 11 additions & 7 deletions chain/exchange/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyDerivativeMarketInstantListingFee, &p.DerivativeMarketInstantListingFee, validateDerivativeMarketInstantListingFee),
paramtypes.NewParamSetPair(KeyDefaultSpotMakerFeeRate, &p.DefaultSpotMakerFeeRate, ValidateMakerFee),
paramtypes.NewParamSetPair(KeyDefaultSpotTakerFeeRate, &p.DefaultSpotTakerFeeRate, ValidateFee),
paramtypes.NewParamSetPair(KeyDefaultDerivativeMakerFeeRate, &p.DefaultDerivativeMakerFeeRate, ValidateFee),
paramtypes.NewParamSetPair(KeyDefaultDerivativeMakerFeeRate, &p.DefaultDerivativeMakerFeeRate, ValidateMakerFee),
paramtypes.NewParamSetPair(KeyDefaultDerivativeTakerFeeRate, &p.DefaultDerivativeTakerFeeRate, ValidateFee),
paramtypes.NewParamSetPair(KeyDefaultInitialMarginRatio, &p.DefaultInitialMarginRatio, ValidateMarginRatio),
paramtypes.NewParamSetPair(KeyDefaultMaintenanceMarginRatio, &p.DefaultMaintenanceMarginRatio, ValidateMarginRatio),
Expand All @@ -147,12 +147,12 @@ func DefaultParams() Params {
return Params{
SpotMarketInstantListingFee: sdk.NewCoin("inj", sdk.NewIntWithDecimal(SpotMarketInstantListingFee, 18)),
DerivativeMarketInstantListingFee: sdk.NewCoin("inj", sdk.NewIntWithDecimal(DerivativeMarketInstantListingFee, 18)),
DefaultSpotMakerFeeRate: sdk.NewDecWithPrec(1, 3), // default 0.1% maker fees
DefaultSpotTakerFeeRate: sdk.NewDecWithPrec(2, 3), // default 0.2% taker fees
DefaultDerivativeMakerFeeRate: sdk.NewDecWithPrec(1, 3), // default 0.1% maker fees
DefaultDerivativeTakerFeeRate: sdk.NewDecWithPrec(2, 3), // default 0.2% taker fees
DefaultInitialMarginRatio: sdk.NewDecWithPrec(5, 2), // default 5% initial margin ratio
DefaultMaintenanceMarginRatio: sdk.NewDecWithPrec(2, 2), // default 2% maintenance margin ratio
DefaultSpotMakerFeeRate: sdk.NewDecWithPrec(-1, 4), // default -0.01% maker fees
DefaultSpotTakerFeeRate: sdk.NewDecWithPrec(1, 3), // default 0.1% taker fees
DefaultDerivativeMakerFeeRate: sdk.NewDecWithPrec(-1, 4), // default -0.01% maker fees
DefaultDerivativeTakerFeeRate: sdk.NewDecWithPrec(1, 3), // default 0.1% taker fees
DefaultInitialMarginRatio: sdk.NewDecWithPrec(5, 2), // default 5% initial margin ratio
DefaultMaintenanceMarginRatio: sdk.NewDecWithPrec(2, 2), // default 2% maintenance margin ratio
DefaultFundingInterval: DefaultFundingIntervalSeconds,
FundingMultiple: DefaultFundingMultipleSeconds,
RelayerFeeShareRate: sdk.NewDecWithPrec(40, 2), // default 40% relayer fee share
Expand Down Expand Up @@ -295,6 +295,10 @@ func ValidateMakerFee(i interface{}) error {
return fmt.Errorf("exchange fee cannot be greater than 1: %s", v)
}

if v.LT(sdk.OneDec().Neg()) {
return fmt.Errorf("exchange fee cannot be less than -1: %s", v)
}

return nil
}

Expand Down
18 changes: 18 additions & 0 deletions chain/exchange/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ func (p *BatchExchangeModificationProposal) ValidateBasic() error {
}
}

for _, proposal := range p.BinaryOptionsMarketLaunchProposals {
if err := proposal.ValidateBasic(); err != nil {
return err
}
}

for _, proposal := range p.BinaryOptionsParamUpdateProposals {
if err := proposal.ValidateBasic(); err != nil {
return err
}
}

if p.DenomDecimalsUpdateProposal != nil {
if err := p.DenomDecimalsUpdateProposal.ValidateBasic(); err != nil {
return err
}
}

return gov.ValidateAbstract(p)
}

Expand Down
Loading

0 comments on commit 4ae5ee9

Please sign in to comment.