Skip to content

Commit

Permalink
switchboard cranker hard code cu limit for
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Nov 21, 2024
1 parent 0f4acba commit 17594a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
34 changes: 12 additions & 22 deletions src/bots/switchboardCranker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ComputeBudgetProgram,
PublicKey,
} from '@solana/web3.js';
import { simulateAndGetTxWithCUs, sleepMs } from '../utils';
import { getVersionedTransaction, sleepMs } from '../utils';
import { Agent, setGlobalDispatcher } from 'undici';

setGlobalDispatcher(
Expand All @@ -23,7 +23,8 @@ setGlobalDispatcher(
})
);

const SIM_CU_ESTIMATE_MULTIPLIER = 1.5;
// ref: https://solscan.io/tx/Z5X334CFBmzbzxXHgfa49UVbMdLZf7nJdDCekjaZYinpykVqgTm47VZphazocMjYe1XJtEyeiL6QgrmvLeMesMA
const MIN_CU_LIMIT = 350_000;

export class SwitchboardCrankerBot implements Bot {
public name: string;
Expand Down Expand Up @@ -112,7 +113,7 @@ export class SwitchboardCrankerBot implements Bot {
);
const ixs = [
ComputeBudgetProgram.setComputeUnitLimit({
units: 1_400_000,
units: MIN_CU_LIMIT,
}),
];

Expand All @@ -139,38 +140,27 @@ export class SwitchboardCrankerBot implements Bot {
}
ixs.push(pullIx);

const simResult = await simulateAndGetTxWithCUs({
const tx = getVersionedTransaction(
this.driftClient.wallet.publicKey,
ixs,
connection: this.driftClient.connection,
payerPublicKey: this.driftClient.wallet.publicKey,
lookupTableAccounts: this.lookupTableAccounts,
cuLimitMultiplier: SIM_CU_ESTIMATE_MULTIPLIER,
doSimulation: true,
recentBlockhash: await this.getBlockhashForTx(),
});

if (simResult.cuEstimate < 100000) {
logger.info(
`cuEst: ${simResult.cuEstimate}, logs: ${JSON.stringify(
simResult.simTxLogs
)}`
);
}
this.lookupTableAccounts,
await this.getBlockhashForTx()
);

if (this.globalConfig.useJito) {
simResult.tx.sign([
tx.sign([
// @ts-ignore;
this.driftClient.wallet.payer,
]);
this.bundleSender?.sendTransactions(
[simResult.tx],
[tx],
undefined,
undefined,
false
);
} else {
this.driftClient
.sendTransaction(simResult.tx)
.sendTransaction(tx)
.then((txSigAndSlot: TxSigAndSlot) => {
logger.info(
`Posted update sb atomic tx for ${alias}: ${txSigAndSlot.txSig}`
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export function isSetComputeUnitsIx(ix: TransactionInstruction): boolean {
}

const PLACEHOLDER_BLOCKHASH = 'Fdum64WVeej6DeL85REV9NvfSxEJNPZ74DBk7A8kTrKP';
function getVersionedTransaction(
export function getVersionedTransaction(
payerKey: PublicKey,
ixs: Array<TransactionInstruction>,
lookupTableAccounts: AddressLookupTableAccount[],
Expand Down

0 comments on commit 17594a0

Please sign in to comment.