Skip to content

Commit

Permalink
Merge pull request #313 from drift-labs/master
Browse files Browse the repository at this point in the history
sb crank ixs
  • Loading branch information
NourAlharithi authored Dec 11, 2024
2 parents f0e6ad7 + d4b4980 commit a8ff355
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 64 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 31 additions & 19 deletions src/bots/switchboardCranker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -163,19 +159,35 @@ 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) => {
console.log(e);
});
}
} catch (e) {
logger.error(`Error processing alias ${alias}: ${e}`);
logger.error(`Error processing alias ${aliasChunk}: ${e}`);
}
}
}

async getPullIx(alias: string): Promise<TransactionInstruction | undefined> {
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<boolean> {
return true;
}
Expand Down
52 changes: 9 additions & 43 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,46 +197,19 @@
enabled "2.0.x"
kuler "^2.0.0"

"@drift-labs/[email protected].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/[email protected].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/[email protected]":
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/[email protected]"
"@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/[email protected]":
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/[email protected]":
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/[email protected]"
Expand Down Expand Up @@ -1690,13 +1663,6 @@
js-yaml "^4.1.0"
protobufjs "^7.2.6"

"@triton-one/[email protected]":
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/[email protected]":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@triton-one/yellowstone-grpc/-/yellowstone-grpc-1.3.0.tgz#7caa7006b525149b4780d1295c7d4c34bc6a6ff6"
Expand Down

0 comments on commit a8ff355

Please sign in to comment.