Skip to content

Commit

Permalink
Merge branch 'feat/update_dependencies_chain_v1_13' of https://github…
Browse files Browse the repository at this point in the history
….com/InjectiveLabs/sdk-go into feat/update_dependencies_chain_v1_13
  • Loading branch information
aarmoa committed Jul 10, 2024
2 parents 2aae7cb + 8684986 commit d7aa99d
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 249 deletions.
7 changes: 4 additions & 3 deletions chain/exchange/types/fee_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ func ValidateMakerWithTakerFee(makerFeeRate, takerFeeRate, relayerFeeShareRate,
return nil
}

// if makerFeeRate is negative, must hold: takerFeeRate * (1 - relayerFeeShareRate) + makerFeeRate > minimalProtocolFeeRate
if takerFeeRate.Mul(math.LegacyOneDec().Sub(relayerFeeShareRate)).Add(makerFeeRate).LT(minimalProtocolFeeRate) {
errMsg := fmt.Sprintf("if makerFeeRate (%v) is negative, (takerFeeRate = %v) * (1 - relayerFeeShareRate = %v) + makerFeeRate < %v", makerFeeRate.String(), takerFeeRate.String(), relayerFeeShareRate.String(), minimalProtocolFeeRate.String())
return errors.Wrap(ErrFeeRatesRelation, errMsg)
// if makerFeeRate is negative then takerFeeRate >= (minimalProtocolFeeRate - relayerFeeShareRate)/(1 - makerFeeRate)
numerator := minimalProtocolFeeRate.Sub(relayerFeeShareRate)
denominator := math.LegacyOneDec().Sub(makerFeeRate)
return errors.Wrap(ErrFeeRatesRelation, fmt.Sprintf("if maker_fee_rate is negative (%v), taker_fee_rate must be GTE than %v [ taker_fee_rate >= (minimum_protocol_fee_rate - maker_fee_rate)/(1 - relayer_fee_share_rate) ]", makerFeeRate.String(), numerator.Quo(denominator).String()))
}

return nil
Expand Down
8 changes: 6 additions & 2 deletions chain/exchange/types/spot_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ func (m *SpotLimitOrder) GetUnfilledFeeAmount(fee math.LegacyDec) math.LegacyDec
return m.GetUnfilledNotional().Mul(fee)
}

func (m *SpotOrder) GetBalanceHoldAndMarginDenom(market *SpotMarket) (balanceHold math.LegacyDec, denom string) {
func (m *SpotOrder) GetBalanceHoldAndMarginDenom(market *SpotMarket) (math.LegacyDec, string) {
var denom string
var balanceHold math.LegacyDec
if m.IsBuy() {
denom = market.QuoteDenom
if m.OrderType.IsPostOnly() {
Expand All @@ -165,7 +167,9 @@ func (m *SpotOrder) GetBalanceHoldAndMarginDenom(market *SpotMarket) (balanceHol
return balanceHold, denom
}

func (m *SpotLimitOrder) GetUnfilledMarginHoldAndMarginDenom(market *SpotMarket, isTransient bool) (balanceHold math.LegacyDec, denom string) {
func (m *SpotLimitOrder) GetUnfilledMarginHoldAndMarginDenom(market *SpotMarket, isTransient bool) (math.LegacyDec, string) {
var denom string
var balanceHold math.LegacyDec
if m.IsBuy() {
var tradeFeeRate math.LegacyDec

Expand Down
Loading

0 comments on commit d7aa99d

Please sign in to comment.