Skip to content

Commit

Permalink
fillers: fix multimaker retry logic (#325)
Browse files Browse the repository at this point in the history
* fillers: fix multimaker retry logic

* add missing tip ix
  • Loading branch information
wphan authored Dec 19, 2024
1 parent 7b9ed59 commit 28cb4ff
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 104 deletions.
33 changes: 17 additions & 16 deletions src/bots/filler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1427,22 +1427,6 @@ export class FillerBot extends TxThreaded implements Bot {
nodeToFill: NodeToFill,
buildForBundle: boolean
): Promise<boolean> {
const ixs: Array<TransactionInstruction> = [
ComputeBudgetProgram.setComputeUnitLimit({
units: 1_400_000,
}),
];
if (!buildForBundle) {
ixs.push(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: Math.floor(
this.priorityFeeSubscriber.getCustomStrategyResult() *
this.driftClient.txSender.getSuggestedPriorityFeeMultiplier()
),
})
);
}

try {
const {
makerInfos,
Expand Down Expand Up @@ -1477,6 +1461,23 @@ export class FillerBot extends TxThreaded implements Bot {
ixs: Array<TransactionInstruction>;
simResult: SimulateAndGetTxWithCUsResponse;
}> => {
const ixs: Array<TransactionInstruction> = [
ComputeBudgetProgram.setComputeUnitLimit({
units: 1_400_000,
}),
];
if (buildForBundle) {
ixs.push(this.bundleSender!.getTipIx());
} else {
ixs.push(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: Math.floor(
this.priorityFeeSubscriber.getCustomStrategyResult() *
this.driftClient.txSender.getSuggestedPriorityFeeMultiplier()
),
})
);
}
ixs.push(
await this.driftClient.getFillPerpOrderIx(
await getUserAccountPublicKey(
Expand Down
34 changes: 17 additions & 17 deletions src/bots/spotFiller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1741,23 +1741,6 @@ export class SpotFillerBot implements Bot {
buildForBundle: boolean,
spotPrecision: BN
): Promise<boolean> {
const ixs: Array<TransactionInstruction> = [
ComputeBudgetProgram.setComputeUnitLimit({
units: 1_400_000,
}),
];
if (buildForBundle) {
ixs.push(this.bundleSender!.getTipIx());
} else {
ixs.push(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: Math.floor(
this.priorityFeeSubscriber.getCustomStrategyResult()
),
})
);
}

try {
const {
makerInfos,
Expand Down Expand Up @@ -1788,6 +1771,23 @@ export class SpotFillerBot implements Bot {
const buildTxWithMakerInfos = async (
makers: DataAndSlot<MakerInfo>[]
): Promise<SimulateAndGetTxWithCUsResponse> => {
const ixs: Array<TransactionInstruction> = [
ComputeBudgetProgram.setComputeUnitLimit({
units: 1_400_000,
}),
];
if (buildForBundle) {
ixs.push(this.bundleSender!.getTipIx());
} else {
ixs.push(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: Math.floor(
this.priorityFeeSubscriber.getCustomStrategyResult()
),
})
);
}

ixs.push(
await this.driftClient.getFillSpotOrderIx(
new PublicKey(takerUserPubKey),
Expand Down
107 changes: 55 additions & 52 deletions src/experimental-bots/filler/fillerMultithreaded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1546,12 +1546,6 @@ export class FillerMultithreaded {
fillTxId: number,
nodeToFill: NodeToFillWithBuffer
): Promise<boolean> {
let ixs: Array<TransactionInstruction> = [
ComputeBudgetProgram.setComputeUnitLimit({
units: 1_400_000,
}),
];

try {
const {
makerInfos,
Expand All @@ -1563,60 +1557,69 @@ 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;
}

const priorityFeePrice = Math.floor(
this.priorityFeeSubscriber.getPriorityFees(
'perp',
nodeToFill.node.order!.marketIndex!
)!.high * this.driftClient.txSender.getSuggestedPriorityFeeMultiplier()
);
const buildForBundle = this.shouldBuildForBundle();

if (buildForBundle) {
ixs.push(this.bundleSender!.getTipIx());
} else {
ixs.push(
getPriorityFeeInstruction(
priorityFeePrice,
this.driftClient.getOracleDataForPerpMarket(0).price,
this.config.bidToFillerReward ? fillerRewardEstimate : undefined,
this.globalConfig.priorityFeeMultiplier
)
);
}

logMessageForNodeToFill(
nodeToFill,
takerUserPubKey,
takerUserSlot,
makerInfos,
this.slotSubscriber.getSlot(),
fillTxId,
'multiMakerFill',
this.revertOnFailure ?? false,
removeLastIxPostSim ?? false
);

if (!isVariant(marketType, 'perp')) {
throw new Error('expected perp market type');
}

let makerInfosToUse = makerInfos;

const buildTxWithMakerInfos = async (
makers: DataAndSlot<MakerInfo>[]
): Promise<SimulateAndGetTxWithCUsResponse | undefined> => {
if (makers.length === 0) {
return undefined;
}

let ixs: Array<TransactionInstruction> = [
ComputeBudgetProgram.setComputeUnitLimit({
units: 1_400_000,
}),
];

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 priorityFeePrice = Math.floor(
this.priorityFeeSubscriber.getPriorityFees(
'perp',
nodeToFill.node.order!.marketIndex!
)!.high *
this.driftClient.txSender.getSuggestedPriorityFeeMultiplier()
);

if (buildForBundle) {
ixs.push(this.bundleSender!.getTipIx());
} else {
ixs.push(
getPriorityFeeInstruction(
priorityFeePrice,
this.driftClient.getOracleDataForPerpMarket(0).price,
this.config.bidToFillerReward ? fillerRewardEstimate : undefined,
this.globalConfig.priorityFeeMultiplier
)
);
}

logMessageForNodeToFill(
nodeToFill,
takerUserPubKey,
takerUserSlot,
makerInfos,
this.slotSubscriber.getSlot(),
fillTxId,
'multiMakerFill',
this.revertOnFailure ?? false,
removeLastIxPostSim ?? false
);

if (!isVariant(marketType, 'perp')) {
throw new Error('expected perp market type');
}

ixs.push(
await this.driftClient.getFillPerpOrderIx(
await getUserAccountPublicKey(
Expand Down
40 changes: 21 additions & 19 deletions src/experimental-bots/spotFiller/spotFillerMultithreaded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,25 +948,6 @@ export class SpotFillerMultithreaded {
)!.decimals
)
);
const ixs: Array<TransactionInstruction> = [
ComputeBudgetProgram.setComputeUnitLimit({
units: 1_400_000,
}),
];
if (buildForBundle) {
ixs.push(this.bundleSender!.getTipIx());
} else {
ixs.push(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: Math.floor(
this.priorityFeeSubscriber.getPriorityFees(
'spot',
nodeToFill.node.order!.marketIndex
)!.high
),
})
);
}

try {
const {
Expand Down Expand Up @@ -1002,6 +983,27 @@ export class SpotFillerMultithreaded {
if (makers.length === 0) {
return undefined;
}

const ixs: Array<TransactionInstruction> = [
ComputeBudgetProgram.setComputeUnitLimit({
units: 1_400_000,
}),
];
if (buildForBundle) {
ixs.push(this.bundleSender!.getTipIx());
} else {
ixs.push(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: Math.floor(
this.priorityFeeSubscriber.getPriorityFees(
'spot',
nodeToFill.node.order!.marketIndex
)!.high
),
})
);
}

ixs.push(
await this.driftClient.getFillSpotOrderIx(
new PublicKey(takerUserPubKey),
Expand Down

0 comments on commit 28cb4ff

Please sign in to comment.