Skip to content

Commit a8ff355

Browse files
authored
Merge pull request #313 from drift-labs/master
sb crank ixs
2 parents f0e6ad7 + d4b4980 commit a8ff355

File tree

3 files changed

+42
-64
lines changed

3 files changed

+42
-64
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"main": "lib/index.js",
66
"license": "Apache-2.0",
77
"dependencies": {
8-
"@drift-labs/jit-proxy": "0.12.2",
9-
"@drift-labs/sdk": "2.104.0-beta.6",
8+
"@drift-labs/jit-proxy": "0.12.3",
9+
"@drift-labs/sdk": "2.104.0-beta.8",
1010
"@opentelemetry/api": "^1.1.0",
1111
"@opentelemetry/auto-instrumentations-node": "^0.31.1",
1212
"@opentelemetry/exporter-prometheus": "^0.31.0",

src/bots/switchboardCranker.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import {
1313
AddressLookupTableAccount,
1414
ComputeBudgetProgram,
1515
PublicKey,
16+
TransactionInstruction,
1617
} from '@solana/web3.js';
17-
import { getVersionedTransaction, sleepMs } from '../utils';
18+
import { chunks, getVersionedTransaction, shuffle, sleepMs } from '../utils';
1819
import { Agent, setGlobalDispatcher } from 'undici';
1920

2021
setGlobalDispatcher(
@@ -24,7 +25,7 @@ setGlobalDispatcher(
2425
);
2526

2627
// ref: https://solscan.io/tx/Z5X334CFBmzbzxXHgfa49UVbMdLZf7nJdDCekjaZYinpykVqgTm47VZphazocMjYe1XJtEyeiL6QgrmvLeMesMA
27-
const MIN_CU_LIMIT = 350_000;
28+
const MIN_CU_LIMIT = 700_000;
2829

2930
export class SwitchboardCrankerBot implements Bot {
3031
public name: string;
@@ -106,11 +107,12 @@ export class SwitchboardCrankerBot implements Bot {
106107
}
107108

108109
async runCrankLoop() {
109-
for (const alias in this.crankConfigs.pullFeedConfigs) {
110+
const pullFeedAliases = chunks(
111+
shuffle(Object.keys(this.crankConfigs.pullFeedConfigs)),
112+
2
113+
);
114+
for (const aliasChunk of pullFeedAliases) {
110115
try {
111-
const pubkey = new PublicKey(
112-
this.crankConfigs.pullFeedConfigs[alias].pubkey
113-
);
114116
const ixs = [
115117
ComputeBudgetProgram.setComputeUnitLimit({
116118
units: MIN_CU_LIMIT,
@@ -122,23 +124,17 @@ export class SwitchboardCrankerBot implements Bot {
122124
} else {
123125
const priorityFees =
124126
this.priorityFeeSubscriber?.getHeliusPriorityFeeLevel() || 0;
125-
logger.info(`Priority fee for ${alias}: ${priorityFees}`);
126127
ixs.push(
127128
ComputeBudgetProgram.setComputeUnitPrice({
128129
microLamports: Math.floor(priorityFees),
129130
})
130131
);
131132
}
132-
const pullIx =
133-
await this.driftClient.getPostSwitchboardOnDemandUpdateAtomicIx(
134-
pubkey,
135-
this.slothashSubscriber.currentSlothash
136-
);
137-
if (!pullIx) {
138-
logger.error(`No pullIx for ${alias}`);
139-
continue;
140-
}
141-
ixs.push(pullIx);
133+
134+
const pullIxs = (
135+
await Promise.all(aliasChunk.map((alias) => this.getPullIx(alias)))
136+
).filter((ix) => ix !== undefined) as TransactionInstruction[];
137+
ixs.push(...pullIxs);
142138

143139
const tx = getVersionedTransaction(
144140
this.driftClient.wallet.publicKey,
@@ -163,19 +159,35 @@ export class SwitchboardCrankerBot implements Bot {
163159
.sendTransaction(tx)
164160
.then((txSigAndSlot: TxSigAndSlot) => {
165161
logger.info(
166-
`Posted update sb atomic tx for ${alias}: ${txSigAndSlot.txSig}`
162+
`Posted update sb atomic tx for ${aliasChunk}: ${txSigAndSlot.txSig}`
167163
);
168164
})
169165
.catch((e) => {
170166
console.log(e);
171167
});
172168
}
173169
} catch (e) {
174-
logger.error(`Error processing alias ${alias}: ${e}`);
170+
logger.error(`Error processing alias ${aliasChunk}: ${e}`);
175171
}
176172
}
177173
}
178174

175+
async getPullIx(alias: string): Promise<TransactionInstruction | undefined> {
176+
const pubkey = new PublicKey(
177+
this.crankConfigs.pullFeedConfigs[alias].pubkey
178+
);
179+
const pullIx =
180+
await this.driftClient.getPostSwitchboardOnDemandUpdateAtomicIx(
181+
pubkey,
182+
this.slothashSubscriber.currentSlothash
183+
);
184+
if (!pullIx) {
185+
logger.error(`No pullIx for ${alias}`);
186+
return;
187+
}
188+
return pullIx;
189+
}
190+
179191
async healthCheck(): Promise<boolean> {
180192
return true;
181193
}

yarn.lock

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -197,46 +197,19 @@
197197
enabled "2.0.x"
198198
kuler "^2.0.0"
199199

200-
"@drift-labs/[email protected].2":
201-
version "0.12.2"
202-
resolved "https://registry.yarnpkg.com/@drift-labs/jit-proxy/-/jit-proxy-0.12.2.tgz#3ad00d79171d0265f7a86ca677a3b5cd9611cce9"
203-
integrity sha512-72nkZabhijSgPjJ6E3Odm/9KNsVOEfXfHafVDdP3WmDn+bUYs+kHKzoeeza49kDQNcPmredU0bafloR3Mf8HVQ==
200+
"@drift-labs/[email protected].3":
201+
version "0.12.3"
202+
resolved "https://registry.yarnpkg.com/@drift-labs/jit-proxy/-/jit-proxy-0.12.3.tgz#310edf3c76a403e23dd72c346915ee19e76dec4c"
203+
integrity sha512-VWaLhbiD4Rp5WrIQAS3fhMQ8IViK7n0Lt1gw5oi+HqsbTi/zIQbELmmIuFHdXQXipaKd5+YvqJc7mxTBLk70Yw==
204204
dependencies:
205205
"@coral-xyz/anchor" "^0.26.0"
206-
"@drift-labs/sdk" "2.104.0-beta.2"
206+
"@drift-labs/sdk" "2.104.0-beta.8"
207207
"@solana/web3.js" "1.91.7"
208208

209-
"@drift-labs/[email protected]":
210-
version "2.104.0-beta.2"
211-
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.104.0-beta.2.tgz#137a0a8254116dbdb5b430d6e910ed604ea3cd94"
212-
integrity sha512-/J1E5mLb03MvYsfn+cjOd17yeLY6azBETJrvhpNSW/9tmWnFe0OJNUNvA+R+rMSqoXfKkPPU1uWH/JcDJrEc/Q==
213-
dependencies:
214-
"@coral-xyz/anchor" "0.28.0"
215-
"@coral-xyz/anchor-30" "npm:@coral-xyz/[email protected]"
216-
"@ellipsis-labs/phoenix-sdk" "^1.4.2"
217-
"@grpc/grpc-js" "^1.8.0"
218-
"@openbook-dex/openbook-v2" "0.2.10"
219-
"@project-serum/serum" "^0.13.38"
220-
"@pythnetwork/client" "2.5.3"
221-
"@pythnetwork/price-service-sdk" "^1.7.1"
222-
"@pythnetwork/pyth-solana-receiver" "^0.7.0"
223-
"@solana/spl-token" "0.3.7"
224-
"@solana/web3.js" "1.92.3"
225-
"@switchboard-xyz/on-demand" "1.2.42"
226-
"@triton-one/yellowstone-grpc" "0.6.0"
227-
anchor-bankrun "^0.3.0"
228-
node-cache "^5.1.2"
229-
rpc-websockets "7.5.1"
230-
solana-bankrun "^0.3.0"
231-
strict-event-emitter-types "^2.0.0"
232-
tweetnacl "1.0.3"
233-
uuid "^8.3.2"
234-
zstddec "^0.1.0"
235-
236-
"@drift-labs/[email protected]":
237-
version "2.104.0-beta.6"
238-
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.104.0-beta.6.tgz#fcf3772a02e099da9e5bb662503058f1ffaf61aa"
239-
integrity sha512-p5MJ45YvZmGmHdm20mIxJgudE4q0Gyv0EJ8hlxTx49Nb/DIddAEyfcOzcu5kNd5SsY7HE0ENfKbCT/FD/CKf4Q==
209+
"@drift-labs/[email protected]":
210+
version "2.104.0-beta.8"
211+
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.104.0-beta.8.tgz#fbd08c358dc4f22adc76f33cb672c07f445714dd"
212+
integrity sha512-pARGVxc4MaY9EI6kHhhIHnJXQlV5fwuSlF49wIaHuy4Gl0qdO0R00igHaR5DozP6EocaTlLPdvMkhYUw6cH0MA==
240213
dependencies:
241214
"@coral-xyz/anchor" "0.28.0"
242215
"@coral-xyz/anchor-30" "npm:@coral-xyz/[email protected]"
@@ -1690,13 +1663,6 @@
16901663
js-yaml "^4.1.0"
16911664
protobufjs "^7.2.6"
16921665

1693-
"@triton-one/[email protected]":
1694-
version "0.6.0"
1695-
resolved "https://registry.yarnpkg.com/@triton-one/yellowstone-grpc/-/yellowstone-grpc-0.6.0.tgz#9e6376cec8a42284c23dc195df2c3423c87c4f27"
1696-
integrity sha512-rgdZM2N3U9/d/QKOI5PP+9rSHUl2oSI5Uwzvuss8y/mtTaHFjbOMpXpQXviIeDkusOa+mef4wLYrbjEZCwTXiw==
1697-
dependencies:
1698-
"@grpc/grpc-js" "^1.8.0"
1699-
17001666
"@triton-one/[email protected]":
17011667
version "1.3.0"
17021668
resolved "https://registry.yarnpkg.com/@triton-one/yellowstone-grpc/-/yellowstone-grpc-1.3.0.tgz#7caa7006b525149b4780d1295c7d4c34bc6a6ff6"

0 commit comments

Comments
 (0)