Skip to content

Commit

Permalink
lastPrice -> midPrice in precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
atvanguard committed Sep 29, 2023
1 parent d7f9217 commit d2e6d70
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions precompile/contracts/bibliophile/clearing_house.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func GetMarkets(stateDB contract.StateDB) []common.Address {
numMarkets := GetActiveMarketsCount(stateDB)
markets := make([]common.Address, numMarkets)
baseStorageSlot := marketsStorageSlot()
// @todo when we ever settle a market, here it needs to be taken care of
// because currently the following assumes that all markets are active
for i := int64(0); i < numMarkets; i++ {
amm := stateDB.GetState(common.HexToAddress(CLEARING_HOUSE_GENESIS_ADDRESS), common.BigToHash(new(big.Int).Add(baseStorageSlot, big.NewInt(i))))
markets[i] = common.BytesToAddress(amm.Bytes())
Expand All @@ -69,13 +71,13 @@ func getNotionalPositionAndMargin(stateDB contract.StateDB, input *GetNotionalPo
numMarkets := len(markets)
positions := make(map[int]*hu.Position, numMarkets)
underlyingPrices := make(map[int]*big.Int, numMarkets)
lastPrices := make(map[int]*big.Int, numMarkets)
var marketIds []int
midPrices := make(map[int]*big.Int, numMarkets)
var activeMarketIds []int
for i, market := range markets {
positions[i] = getPosition(stateDB, getMarketAddressFromMarketID(int64(i), stateDB), &input.Trader)
underlyingPrices[i] = getUnderlyingPrice(stateDB, market)
lastPrices[i] = getLastPrice(stateDB, market)
marketIds = append(marketIds, i)
midPrices[i] = getMidPrice(stateDB, market)
activeMarketIds = append(activeMarketIds, i)
}
pendingFunding := big.NewInt(0)
if input.IncludeFundingPayments {
Expand All @@ -85,8 +87,8 @@ func getNotionalPositionAndMargin(stateDB contract.StateDB, input *GetNotionalPo
&hu.HubbleState{
Assets: GetCollaterals(stateDB),
OraclePrices: underlyingPrices,
LastPrices: lastPrices,
ActiveMarkets: marketIds,
LastPrices: midPrices,
ActiveMarkets: activeMarketIds,
},
&hu.UserState{
Positions: positions,
Expand Down

0 comments on commit d2e6d70

Please sign in to comment.