diff --git a/package.json b/package.json index 32002c5d..c62802a7 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "main": "lib/index.js", "license": "Apache-2.0", "dependencies": { - "@drift-labs/jit-proxy": "0.12.2", - "@drift-labs/sdk": "2.104.0-beta.6", + "@drift-labs/jit-proxy": "0.12.3", + "@drift-labs/sdk": "2.104.0-beta.8", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/src/bots/switchboardCranker.ts b/src/bots/switchboardCranker.ts index b4c3b03e..3acb226b 100644 --- a/src/bots/switchboardCranker.ts +++ b/src/bots/switchboardCranker.ts @@ -13,8 +13,9 @@ import { AddressLookupTableAccount, ComputeBudgetProgram, PublicKey, + TransactionInstruction, } from '@solana/web3.js'; -import { getVersionedTransaction, sleepMs } from '../utils'; +import { chunks, getVersionedTransaction, shuffle, sleepMs } from '../utils'; import { Agent, setGlobalDispatcher } from 'undici'; setGlobalDispatcher( @@ -24,7 +25,7 @@ setGlobalDispatcher( ); // ref: https://solscan.io/tx/Z5X334CFBmzbzxXHgfa49UVbMdLZf7nJdDCekjaZYinpykVqgTm47VZphazocMjYe1XJtEyeiL6QgrmvLeMesMA -const MIN_CU_LIMIT = 350_000; +const MIN_CU_LIMIT = 700_000; export class SwitchboardCrankerBot implements Bot { public name: string; @@ -106,11 +107,12 @@ export class SwitchboardCrankerBot implements Bot { } async runCrankLoop() { - for (const alias in this.crankConfigs.pullFeedConfigs) { + const pullFeedAliases = chunks( + shuffle(Object.keys(this.crankConfigs.pullFeedConfigs)), + 2 + ); + for (const aliasChunk of pullFeedAliases) { try { - const pubkey = new PublicKey( - this.crankConfigs.pullFeedConfigs[alias].pubkey - ); const ixs = [ ComputeBudgetProgram.setComputeUnitLimit({ units: MIN_CU_LIMIT, @@ -122,23 +124,17 @@ export class SwitchboardCrankerBot implements Bot { } else { const priorityFees = this.priorityFeeSubscriber?.getHeliusPriorityFeeLevel() || 0; - logger.info(`Priority fee for ${alias}: ${priorityFees}`); ixs.push( ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Math.floor(priorityFees), }) ); } - const pullIx = - await this.driftClient.getPostSwitchboardOnDemandUpdateAtomicIx( - pubkey, - this.slothashSubscriber.currentSlothash - ); - if (!pullIx) { - logger.error(`No pullIx for ${alias}`); - continue; - } - ixs.push(pullIx); + + const pullIxs = ( + await Promise.all(aliasChunk.map((alias) => this.getPullIx(alias))) + ).filter((ix) => ix !== undefined) as TransactionInstruction[]; + ixs.push(...pullIxs); const tx = getVersionedTransaction( this.driftClient.wallet.publicKey, @@ -163,7 +159,7 @@ export class SwitchboardCrankerBot implements Bot { .sendTransaction(tx) .then((txSigAndSlot: TxSigAndSlot) => { logger.info( - `Posted update sb atomic tx for ${alias}: ${txSigAndSlot.txSig}` + `Posted update sb atomic tx for ${aliasChunk}: ${txSigAndSlot.txSig}` ); }) .catch((e) => { @@ -171,11 +167,27 @@ export class SwitchboardCrankerBot implements Bot { }); } } catch (e) { - logger.error(`Error processing alias ${alias}: ${e}`); + logger.error(`Error processing alias ${aliasChunk}: ${e}`); } } } + async getPullIx(alias: string): Promise { + const pubkey = new PublicKey( + this.crankConfigs.pullFeedConfigs[alias].pubkey + ); + const pullIx = + await this.driftClient.getPostSwitchboardOnDemandUpdateAtomicIx( + pubkey, + this.slothashSubscriber.currentSlothash + ); + if (!pullIx) { + logger.error(`No pullIx for ${alias}`); + return; + } + return pullIx; + } + async healthCheck(): Promise { return true; } diff --git a/yarn.lock b/yarn.lock index bf51debb..8ac2631d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -197,46 +197,19 @@ enabled "2.0.x" kuler "^2.0.0" -"@drift-labs/jit-proxy@0.12.2": - version "0.12.2" - resolved "https://registry.yarnpkg.com/@drift-labs/jit-proxy/-/jit-proxy-0.12.2.tgz#3ad00d79171d0265f7a86ca677a3b5cd9611cce9" - integrity sha512-72nkZabhijSgPjJ6E3Odm/9KNsVOEfXfHafVDdP3WmDn+bUYs+kHKzoeeza49kDQNcPmredU0bafloR3Mf8HVQ== +"@drift-labs/jit-proxy@0.12.3": + version "0.12.3" + resolved "https://registry.yarnpkg.com/@drift-labs/jit-proxy/-/jit-proxy-0.12.3.tgz#310edf3c76a403e23dd72c346915ee19e76dec4c" + integrity sha512-VWaLhbiD4Rp5WrIQAS3fhMQ8IViK7n0Lt1gw5oi+HqsbTi/zIQbELmmIuFHdXQXipaKd5+YvqJc7mxTBLk70Yw== dependencies: "@coral-xyz/anchor" "^0.26.0" - "@drift-labs/sdk" "2.104.0-beta.2" + "@drift-labs/sdk" "2.104.0-beta.8" "@solana/web3.js" "1.91.7" -"@drift-labs/sdk@2.104.0-beta.2": - version "2.104.0-beta.2" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.104.0-beta.2.tgz#137a0a8254116dbdb5b430d6e910ed604ea3cd94" - integrity sha512-/J1E5mLb03MvYsfn+cjOd17yeLY6azBETJrvhpNSW/9tmWnFe0OJNUNvA+R+rMSqoXfKkPPU1uWH/JcDJrEc/Q== - dependencies: - "@coral-xyz/anchor" "0.28.0" - "@coral-xyz/anchor-30" "npm:@coral-xyz/anchor@0.30.1" - "@ellipsis-labs/phoenix-sdk" "^1.4.2" - "@grpc/grpc-js" "^1.8.0" - "@openbook-dex/openbook-v2" "0.2.10" - "@project-serum/serum" "^0.13.38" - "@pythnetwork/client" "2.5.3" - "@pythnetwork/price-service-sdk" "^1.7.1" - "@pythnetwork/pyth-solana-receiver" "^0.7.0" - "@solana/spl-token" "0.3.7" - "@solana/web3.js" "1.92.3" - "@switchboard-xyz/on-demand" "1.2.42" - "@triton-one/yellowstone-grpc" "0.6.0" - anchor-bankrun "^0.3.0" - node-cache "^5.1.2" - rpc-websockets "7.5.1" - solana-bankrun "^0.3.0" - strict-event-emitter-types "^2.0.0" - tweetnacl "1.0.3" - uuid "^8.3.2" - zstddec "^0.1.0" - -"@drift-labs/sdk@2.104.0-beta.6": - version "2.104.0-beta.6" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.104.0-beta.6.tgz#fcf3772a02e099da9e5bb662503058f1ffaf61aa" - integrity sha512-p5MJ45YvZmGmHdm20mIxJgudE4q0Gyv0EJ8hlxTx49Nb/DIddAEyfcOzcu5kNd5SsY7HE0ENfKbCT/FD/CKf4Q== +"@drift-labs/sdk@2.104.0-beta.8": + version "2.104.0-beta.8" + resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.104.0-beta.8.tgz#fbd08c358dc4f22adc76f33cb672c07f445714dd" + integrity sha512-pARGVxc4MaY9EI6kHhhIHnJXQlV5fwuSlF49wIaHuy4Gl0qdO0R00igHaR5DozP6EocaTlLPdvMkhYUw6cH0MA== dependencies: "@coral-xyz/anchor" "0.28.0" "@coral-xyz/anchor-30" "npm:@coral-xyz/anchor@0.30.1" @@ -1690,13 +1663,6 @@ js-yaml "^4.1.0" protobufjs "^7.2.6" -"@triton-one/yellowstone-grpc@0.6.0": - version "0.6.0" - resolved "https://registry.yarnpkg.com/@triton-one/yellowstone-grpc/-/yellowstone-grpc-0.6.0.tgz#9e6376cec8a42284c23dc195df2c3423c87c4f27" - integrity sha512-rgdZM2N3U9/d/QKOI5PP+9rSHUl2oSI5Uwzvuss8y/mtTaHFjbOMpXpQXviIeDkusOa+mef4wLYrbjEZCwTXiw== - dependencies: - "@grpc/grpc-js" "^1.8.0" - "@triton-one/yellowstone-grpc@1.3.0": version "1.3.0" resolved "https://registry.yarnpkg.com/@triton-one/yellowstone-grpc/-/yellowstone-grpc-1.3.0.tgz#7caa7006b525149b4780d1295c7d4c34bc6a6ff6"