Skip to content

Commit

Permalink
liquidator: use SOL routes when swapping LSTs (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan authored Dec 19, 2024
1 parent cc52018 commit 8092561
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/bots/liquidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
calculateAccountValueUsd,
checkIfAccountExists,
handleSimResultError,
isSolLstToken,
simulateAndGetTxWithCUs,
SimulateAndGetTxWithCUsResponse,
} from '../utils';
Expand Down Expand Up @@ -1259,10 +1260,17 @@ export class LiquidatorBot implements Bot {
let outMarket: SpotMarketAccount | undefined;
let inMarket: SpotMarketAccount | undefined;
let amountIn: BN | undefined;
const spotMarketIsSolLst = isSolLstToken(spotMarketIndex);
if (isVariant(orderDirection, 'long')) {
// sell USDC, buy spotMarketIndex
inMarket = this.driftClient.getSpotMarketAccount(0);
outMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
if (spotMarketIsSolLst) {
// sell SOL, buy the LST
inMarket = this.driftClient.getSpotMarketAccount(1);
outMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
} else {
// sell USDC, buy spotMarketIndex
inMarket = this.driftClient.getSpotMarketAccount(0);
outMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
}
if (!inMarket || !outMarket) {
logger.error('failed to get spot markets');
return undefined;
Expand All @@ -1274,9 +1282,15 @@ export class LiquidatorBot implements Bot {
.mul(inPrecision)
.div(PRICE_PRECISION.mul(outPrecision));
} else {
// sell spotMarketIndex, buy USDC
inMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
outMarket = this.driftClient.getSpotMarketAccount(0);
if (spotMarketIsSolLst) {
// sell spotMarketIndex, buy SOL
inMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
outMarket = this.driftClient.getSpotMarketAccount(1);
} else {
// sell spotMarketIndex, buy USDC
inMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
outMarket = this.driftClient.getSpotMarketAccount(0);
}
amountIn = baseAmountIn;
}

Expand Down
11 changes: 11 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1553,3 +1553,14 @@ export function getMarketsAndOracleInfosToLoad(
spotIndexes && spotIndexes.length > 0 ? spotIndexes : undefined,
};
}

export function isSolLstToken(spotMarketIndex: number): boolean {
return [
2, // mSOL
6, // jitoSOL
8, // bSOL
16, // INF
17, // dSOL
25, // BNSOL
].includes(spotMarketIndex);
}

0 comments on commit 8092561

Please sign in to comment.