BlockPo / BlockPo-to-Tradelayer

Incubation Repo for the TradeLayer protocol, 0.2.0
http://www.tradelayer.org
Other
8 stars 8 forks source link

getExitPrice for Native #492

Open patrickdugan opened 1 year ago

patrickdugan commented 1 year ago

int64_t Register::getPosExitPrice(const uint32_t contractId, bool isOracle) const { if(isOracle) { return getOracleTwap(contractId, OL_BLOCKS); }

// refine this: native contracts mark price
return 0;

}

Gotta follow up here.

However, this is not a great approach because the mark price on the block where the trade occurred, and the actual exit price are not the same thing. In fact, this in the current code is a consensus error because in a block where oracle TWAP and therefore mark price is N, the trade can all be higher (because TWAP is lagging).

Mark price is just for triggering liquidation as a risk-management measure of a volatility-dampened measure of value... it's not meant to be a batch auction each block. In fact our engine doesn't work that way, and this would be mis-representing the values but changing the tallymap downstream in realizePNL, so... causes coins to go missing? Must be fixed with proper logic that looks at the record for trades and goes with the actual prices traded.