Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for oracle orders to liquidator bots #93

Open
crispheaney opened this issue Dec 2, 2023 · 3 comments
Open

Add support for oracle orders to liquidator bots #93

crispheaney opened this issue Dec 2, 2023 · 3 comments
Labels
good first issue Good for newcomers

Comments

@crispheaney
Copy link
Member

Have liquidators close out their position using oracle orders

Example of placing oracle order here: https://drift-labs.github.io/v2-teacher/#placing-oracle-market-orders

@crispheaney crispheaney added the good first issue Good for newcomers label Dec 2, 2023
@nilswx
Copy link

nilswx commented Dec 3, 2023

We can add opts.deriskOrderType to let liquidators choose between current logic (OracleType.MARKET with limit) and OrderType.ORACLE with auction. Should oracle order become default for derisking spot & perp?

Liquidator already calculates a worst-case price against infinite slippage:

private calculateOrderLimitPrice(
oracle: OraclePriceData,
direction: PositionDirection
): BN {
const slippageBN = new BN(this.liquidatorConfig.maxSlippagePct! * 10000);
if (isVariant(direction, 'long')) {
return oracle.price.mul(new BN(10000).add(slippageBN)).div(new BN(10000));
} else {
return oracle.price.mul(new BN(10000).sub(slippageBN)).div(new BN(10000));
}
}

When closing out via oracle order, that would be auctionEndPrice? With oraclePrice as auctionStartPrice, or something more optimistic?

Perhaps auctionStartPrice, auctionEndPrice and auctionDuration should be more configurable, like https://docs.drift.trade/auction-parameters. I'm more of liquidatee myself, so I'm happy to hear ideas.

@crispheaney
Copy link
Member Author

I think we could probably change calculateOrderLimitPrice to be calculateOrderAuctionParams and have it return an auctionStartPrice, auctionEndPrice and limitPrice/oraclePriceOffset.

IF the liquidator is configured for market orders:

  • auction start: oracle or best offer
  • auction end: oracle +/- max slippage
  • limit: oracle +/- max slippage

If liquidate is configured for market oracle order:

  • auction start: (oracle or best offer) - oracle
  • auction end: +/- max slippage
  • oraclePriceOffset: +/- max slippage

We already have the deriveOracleAuctionParams (https://github.com/drift-labs/protocol-v2/blob/3d9105fa85fe90cebd3cc2178a3fc55d52aedbba/sdk/src/math/auction.ts#L117) to get the market oracle params from the market order params

wdyt @0xbigz @wphan

@wphan
Copy link
Member

wphan commented Jan 3, 2024

#119 is a quick fix for this issue, might be a good PR to refer to (since it touches the relevant areas of code) if someone wants to take a stab at this and make liquidator derisk smarter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants