Skip to content

Commit

Permalink
merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Jun 27, 2024
1 parent 0058421 commit 3bfc3c1
Showing 1 changed file with 0 additions and 91 deletions.
91 changes: 0 additions & 91 deletions protocol/x/perpetuals/keeper/perpetual.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ import (
"github.com/dydxprotocol/v4-chain/protocol/lib/log"
"github.com/dydxprotocol/v4-chain/protocol/lib/metrics"
epochstypes "github.com/dydxprotocol/v4-chain/protocol/x/epochs/types"
<<<<<<< HEAD
=======
"github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/funding"
perplib "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/lib"
>>>>>>> 87a919e6 ([chore] Move `perpetuals/keeper` helper functions to `perpetuals/lib` (#1678))
"github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types"
pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types"
gometrics "github.com/hashicorp/go-metrics"
Expand Down Expand Up @@ -969,61 +965,6 @@ func (k Keeper) GetMarginRequirements(
return bigInitialMarginQuoteQuantums, bigMaintenanceMarginQuoteQuantums, nil
}

<<<<<<< HEAD
// GetMarginRequirementsInQuoteQuantums returns initial and maintenance margin requirements
// in quote quantums, given the position size in base quantums.
//
// Note that this is a stateless function.
func GetMarginRequirementsInQuoteQuantums(
perpetual types.Perpetual,
marketPrice pricestypes.MarketPrice,
liquidityTier types.LiquidityTier,
bigQuantums *big.Int,
) (
bigInitialMarginQuoteQuantums *big.Int,
bigMaintenanceMarginQuoteQuantums *big.Int,
) {
// Always consider the magnitude of the position regardless of whether it is long/short.
bigAbsQuantums := new(big.Int).Set(bigQuantums).Abs(bigQuantums)

// Calculate the notional value of the position in quote quantums.
bigQuoteQuantums := lib.BaseToQuoteQuantums(
bigAbsQuantums,
perpetual.Params.AtomicResolution,
marketPrice.Price,
marketPrice.Exponent,
)
// Calculate the perpetual's open interest in quote quantums.
openInterestQuoteQuantums := lib.BaseToQuoteQuantums(
perpetual.OpenInterest.BigInt(), // OpenInterest is represented as base quantums.
perpetual.Params.AtomicResolution,
marketPrice.Price,
marketPrice.Exponent,
)

// Initial margin requirement quote quantums = size in quote quantums * initial margin PPM.
bigBaseInitialMarginQuoteQuantums := liquidityTier.GetInitialMarginQuoteQuantums(
bigQuoteQuantums,
big.NewInt(0), // pass in 0 as open interest to get base IMR.
)
// Maintenance margin requirement quote quantums = IM in quote quantums * maintenance fraction PPM.
bigMaintenanceMarginQuoteQuantums = lib.BigRatRound(
lib.BigRatMulPpm(
new(big.Rat).SetInt(bigBaseInitialMarginQuoteQuantums),
liquidityTier.MaintenanceFractionPpm,
),
true,
)

bigInitialMarginQuoteQuantums = liquidityTier.GetInitialMarginQuoteQuantums(
bigQuoteQuantums,
openInterestQuoteQuantums, // pass in current OI to get scaled IMR.
)
return bigInitialMarginQuoteQuantums, bigMaintenanceMarginQuoteQuantums
}

=======
>>>>>>> 87a919e6 ([chore] Move `perpetuals/keeper` helper functions to `perpetuals/lib` (#1678))
// GetSettlementPpm returns the net settlement amount ppm (in quote quantums) given
// the perpetual Id and position size (in base quantums).
// When handling rounding, always round positive settlement amount to zero, and
Expand Down Expand Up @@ -1058,38 +999,6 @@ func (k Keeper) GetSettlementPpm(
return bigNetSettlementPpm, newFundingIndex, nil
}

<<<<<<< HEAD
// GetSettlementPpm returns the net settlement amount ppm (in quote quantums) given
// the perpetual and position size (in base quantums).
//
// Note that this function is a stateless utility function.
func GetSettlementPpmWithPerpetual(
perpetual types.Perpetual,
quantums *big.Int,
index *big.Int,
) (
bigNetSettlementPpm *big.Int,
newFundingIndex *big.Int,
) {
indexDelta := new(big.Int).Sub(perpetual.FundingIndex.BigInt(), index)

// if indexDelta is zero, then net settlement is zero.
if indexDelta.Sign() == 0 {
return big.NewInt(0), perpetual.FundingIndex.BigInt()
}

bigNetSettlementPpm = new(big.Int).Mul(indexDelta, quantums)

// `bigNetSettlementPpm` carries sign. `indexDelta`` is the increase in `fundingIndex`, so if
// the position is long (positive), the net settlement should be short (negative), and vice versa.
// Thus, always negate `bigNetSettlementPpm` here.
bigNetSettlementPpm = bigNetSettlementPpm.Neg(bigNetSettlementPpm)

return bigNetSettlementPpm, perpetual.FundingIndex.BigInt()
}

=======
>>>>>>> 87a919e6 ([chore] Move `perpetuals/keeper` helper functions to `perpetuals/lib` (#1678))
// GetPremiumSamples reads premium samples from the current `funding-tick` epoch,
// stored in a `PremiumStore` struct.
func (k Keeper) GetPremiumSamples(ctx sdk.Context) (
Expand Down

0 comments on commit 3bfc3c1

Please sign in to comment.