Skip to content

Commit

Permalink
Merge branch 'mainnet-beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Oct 29, 2024
2 parents 62d5a97 + 1fd49f7 commit 7bd1fef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 52 deletions.
8 changes: 6 additions & 2 deletions src/bots/filler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1697,12 +1697,14 @@ export class FillerBot extends TxThreaded implements Bot {
throw new Error('expected perp market type');
}

let removeLastIxPostSim = this.revertOnFailure;
if (
this.pythPriceSubscriber &&
((makerInfos.length == 2 && !referrerInfo) || makerInfos.length < 2)
) {
const pythIxs = await this.getPythIxsFromNode(nodeToFill);
ixs.push(...pythIxs);
removeLastIxPostSim = false;
}

const ix = await this.driftClient.getFillPerpOrderIx(
Expand Down Expand Up @@ -1781,7 +1783,7 @@ export class FillerBot extends TxThreaded implements Bot {
doSimulation: this.simulateTxForCUEstimate,
recentBlockhash: await this.getBlockhashForTx(),
dumpTx: DUMP_TXS_IN_SIM,
removeLastIxPostSim: this.revertOnFailure,
removeLastIxPostSim,
});
} catch (e) {
logger.error(
Expand Down Expand Up @@ -1923,9 +1925,11 @@ export class FillerBot extends TxThreaded implements Bot {
);
}

let removeLastIxPostSim = this.revertOnFailure;
if (this.pythPriceSubscriber) {
const pythIxs = await this.getPythIxsFromNode(nodeToTrigger);
ixs.push(...pythIxs);
removeLastIxPostSim = false;
}

ixs.push(
Expand Down Expand Up @@ -1960,7 +1964,7 @@ export class FillerBot extends TxThreaded implements Bot {
doSimulation: this.simulateTxForCUEstimate,
recentBlockhash: await this.getBlockhashForTx(),
dumpTx: DUMP_TXS_IN_SIM,
removeLastIxPostSim: this.revertOnFailure,
removeLastIxPostSim,
});
this.simulateTxHistogram?.record(simResult.simTxDuration, {
type: 'trigger',
Expand Down
53 changes: 12 additions & 41 deletions src/experimental-bots/filler/fillerMultithreaded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import {
// getStaleOracleMarketIndexes,
handleSimResultError,
logMessageForNodeToFill,
MEMO_PROGRAM_ID,
removePythIxs,
simulateAndGetTxWithCUs,
SimulateAndGetTxWithCUsResponse,
Expand Down Expand Up @@ -1237,8 +1236,6 @@ export class FillerMultithreaded {
);
}

const nonActionIxCount = ixs.length;

nodeToTrigger.node.haveTrigger = true;
// @ts-ignore
const buffer = Buffer.from(nodeToTrigger.node.userAccountData.data);
Expand All @@ -1251,14 +1248,16 @@ export class FillerMultithreaded {
}, order ${nodeToTrigger.node.order.orderId.toString()}`
);

let removeLastIxPostSim = this.revertOnFailure;
if (this.pythPriceSubscriber) {
const pythIxs = await this.getPythIxsFromNode(nodeToTrigger);
ixs.push(...pythIxs);
removeLastIxPostSim = false;
}

const nodeSignature = getNodeToTriggerSignature(nodeToTrigger);
if (this.seenTriggerableOrders.has(nodeSignature)) {
logger.debug(
logger.info(
`${logPrefix} already triggered order (account: ${
nodeToTrigger.node.userAccount
}, order ${nodeToTrigger.node.order.orderId.toString()}.
Expand Down Expand Up @@ -1286,20 +1285,10 @@ export class FillerMultithreaded {

const txSize = getSizeOfTransaction(ixs, true, this.lookupTableAccounts);
if (txSize > PACKET_DATA_SIZE) {
logger.info(`tx too large, removing pyth ixs.
`);
logger.info(`tx too large, removing pyth ixs.`);
ixs = removePythIxs(ixs);
}

if (ixs.length === nonActionIxCount) {
logger.warn(
`${logPrefix} No ixs in trigger tx (account: ${
nodeToTrigger.node.userAccount
}, order ${nodeToTrigger.node.order.orderId.toString()})`
);
return;
}

const simResult = await simulateAndGetTxWithCUs({
ixs,
connection: this.driftClient.connection,
Expand All @@ -1308,7 +1297,7 @@ export class FillerMultithreaded {
cuLimitMultiplier: SIM_CU_ESTIMATE_MULTIPLIER,
doSimulation: this.simulateTxForCUEstimate,
recentBlockhash: await this.getBlockhashForTx(),
removeLastIxPostSim: this.revertOnFailure,
removeLastIxPostSim,
});
this.simulateTxHistogram?.record(simResult.simTxDuration, {
type: 'trigger',
Expand All @@ -1328,7 +1317,7 @@ export class FillerMultithreaded {
});

logger.info(
`executeTriggerablePerpNodesForMarket estimated CUs: ${simResult.cuEstimate}`
`executeTriggerablePerpNodesForMarket (${nodeSignature}) estimated CUs: ${simResult.cuEstimate}, finalIxCount: ${ixs.length}). revertTx: ${this.revertOnFailure}}`
);

if (simResult.simError) {
Expand Down Expand Up @@ -1576,12 +1565,14 @@ export class FillerMultithreaded {
fillerRewardEstimate,
} = await this.getNodeFillInfo(nodeToFill);

let removeLastIxPostSim = this.revertOnFailure;
if (
this.pythPriceSubscriber &&
((makerInfos.length === 2 && !referrerInfo) || makerInfos.length < 2)
) {
const pythIxs = await this.getPythIxsFromNode(nodeToFill);
ixs.push(...pythIxs);
removeLastIxPostSim = false;
}

if (buildForBundle) {
Expand Down Expand Up @@ -1681,13 +1672,6 @@ export class FillerMultithreaded {
ixs = removePythIxs(ixs);
}

ixs.push(
new TransactionInstruction({
programId: MEMO_PROGRAM_ID,
keys: [],
data: Buffer.from(`mm-perp ${fillTxId} ${makers.length}`, 'utf-8'),
})
);
const simResult = await simulateAndGetTxWithCUs({
ixs,
connection: this.driftClient.connection,
Expand All @@ -1696,7 +1680,7 @@ export class FillerMultithreaded {
cuLimitMultiplier: SIM_CU_ESTIMATE_MULTIPLIER,
doSimulation: this.simulateTxForCUEstimate,
recentBlockhash: await this.getBlockhashForTx(),
removeLastIxPostSim: this.revertOnFailure,
removeLastIxPostSim,
});
this.simulateTxHistogram?.record(simResult.simTxDuration, {
type: 'multiMakerFill',
Expand Down Expand Up @@ -1814,9 +1798,11 @@ export class FillerMultithreaded {
fillerRewardEstimate,
} = await this.getNodeFillInfo(nodeToFill);

let removeLastIxPostSim = this.revertOnFailure;
if (this.pythPriceSubscriber && makerInfos.length <= 2) {
const pythIxs = await this.getPythIxsFromNode(nodeToFill);
ixs.push(...pythIxs);
removeLastIxPostSim = false;
}

if (buildForBundle) {
Expand Down Expand Up @@ -1901,14 +1887,6 @@ export class FillerMultithreaded {
ixs = removePythIxs(ixs);
}

ixs.push(
new TransactionInstruction({
programId: MEMO_PROGRAM_ID,
keys: [],
data: Buffer.from(`ff-perp ${fillTxId}`, 'utf-8'),
})
);

const simResult = await simulateAndGetTxWithCUs({
ixs,
connection: this.driftClient.connection,
Expand All @@ -1917,7 +1895,7 @@ export class FillerMultithreaded {
cuLimitMultiplier: SIM_CU_ESTIMATE_MULTIPLIER,
doSimulation: this.simulateTxForCUEstimate,
recentBlockhash: await this.getBlockhashForTx(),
removeLastIxPostSim: this.revertOnFailure,
removeLastIxPostSim,
});
logger.info(
`tryFillPerpNode estimated CUs: ${simResult.cuEstimate} (fillTxId: ${fillTxId})`
Expand Down Expand Up @@ -2103,8 +2081,6 @@ export class FillerMultithreaded {
);
}

const nonActionIxCount = ixs.length;

ixs.push(
...(await this.driftClient.getSettlePNLsIxs(
[
Expand All @@ -2119,11 +2095,6 @@ export class FillerMultithreaded {
))
);

if (ixs.length === nonActionIxCount) {
logger.warn(`${logPrefix} No ixs in settlePnls tx`);
return;
}

const simResult = await simulateAndGetTxWithCUs({
ixs,
connection: this.driftClient.connection,
Expand Down
9 changes: 0 additions & 9 deletions src/experimental-bots/spotFiller/spotFillerMultithreaded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,6 @@ export class SpotFillerMultithreaded {
);
}

const nonActionIxCount = ixs.length;

ixs.push(
await this.driftClient.getTriggerOrderIx(
new PublicKey(nodeToTrigger.node.userAccount),
Expand All @@ -739,13 +737,6 @@ export class SpotFillerMultithreaded {
);
}

if (ixs.length === nonActionIxCount) {
logger.warn(
`${logPrefix} No ixs in trigger tx for (account: ${nodeToTrigger.node.userAccount.toString()}, order: ${nodeToTrigger.node.order.orderId.toString()})`
);
return;
}

const simResult = await simulateAndGetTxWithCUs({
ixs,
connection: this.driftClient.connection,
Expand Down

0 comments on commit 7bd1fef

Please sign in to comment.