Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onlySendDuringJitoLeader config #177

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ global:
jitoTipMultiplier: 3
jitoBlockEngineUrl: frankfurt.mainnet.block-engine.jito.wtf
jitoAuthPrivateKey: /path/to/jito/bundle/signing/key/auth.json
onlySendDuringJitoLeader: false

# Which bots to run, be careful with this, running multiple bots in one instance
# might use more resources than expected.
Expand Down
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.10.366",
"@drift-labs/sdk": "2.78.0-beta.0",
"@drift-labs/jit-proxy": "0.10.369",
"@drift-labs/sdk": "2.79.0-beta.2",
"@opentelemetry/api": "^1.1.0",
"@opentelemetry/auto-instrumentations-node": "^0.31.1",
"@opentelemetry/exporter-prometheus": "^0.31.0",
Expand Down
55 changes: 33 additions & 22 deletions src/bots/filler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export class FillerBot implements Bot {
protected lookupTableAccount?: AddressLookupTableAccount;
protected bundleSender?: BundleSender;

private fillerConfig: FillerConfig;
private globalConfig: GlobalConfig;
private dlobSubscriber?: DLOBSubscriber;

Expand Down Expand Up @@ -249,14 +250,15 @@ export class FillerBot implements Bot {
userMap: UserMap | undefined,
runtimeSpec: RuntimeSpec,
globalConfig: GlobalConfig,
config: FillerConfig,
fillerConfig: FillerConfig,
priorityFeeSubscriber: PriorityFeeSubscriber,
blockhashSubscriber: BlockhashSubscriber,
bundleSender?: BundleSender
) {
this.globalConfig = globalConfig;
this.name = config.botId;
this.dryRun = config.dryRun;
this.fillerConfig = fillerConfig;
this.name = this.fillerConfig.botId;
this.dryRun = this.fillerConfig.dryRun;
this.slotSubscriber = slotSubscriber;
this.driftClient = driftClient;
if (globalConfig.txConfirmationEndpoint) {
Expand All @@ -282,13 +284,16 @@ export class FillerBot implements Bot {
}
this.runtimeSpec = runtimeSpec;
this.pollingIntervalMs =
config.fillerPollingInterval ?? this.defaultIntervalMs;
this.fillerConfig.fillerPollingInterval ?? this.defaultIntervalMs;

this.initializeMetrics(config.metricsPort ?? this.globalConfig.metricsPort);
this.initializeMetrics(
this.fillerConfig.metricsPort ?? this.globalConfig.metricsPort
);
this.userMap = userMap;

this.revertOnFailure = config.revertOnFailure ?? true;
this.simulateTxForCUEstimate = config.simulateTxForCUEstimate ?? true;
this.revertOnFailure = this.fillerConfig.revertOnFailure ?? true;
this.simulateTxForCUEstimate =
this.fillerConfig.simulateTxForCUEstimate ?? true;
logger.info(
`${this.name}: revertOnFailure: ${this.revertOnFailure}, simulateTxForCUEstimate: ${this.simulateTxForCUEstimate}`
);
Expand All @@ -299,23 +304,23 @@ export class FillerBot implements Bot {
);

if (
config.rebalanceFiller &&
this.fillerConfig.rebalanceFiller &&
this.runtimeSpec.driftEnv === 'mainnet-beta'
) {
this.jupiterClient = new JupiterClient({
connection: this.driftClient.connection,
});
}
this.rebalanceFiller = config.rebalanceFiller ?? true;
this.rebalanceFiller = this.fillerConfig.rebalanceFiller ?? true;
logger.info(
`${this.name}: rebalancing enabled: ${this.jupiterClient !== undefined}`
);

if (!validMinimumAmountToFill(config.minimumAmountToFill)) {
if (!validMinimumAmountToFill(this.fillerConfig.minimumAmountToFill)) {
this.minimumAmountToFill = 0.2 * LAMPORTS_PER_SOL;
} else {
// @ts-ignore
this.minimumAmountToFill = config.minimumAmountToFill * LAMPORTS_PER_SOL;
this.minimumAmountToFill =
this.fillerConfig.minimumAmountToFill ?? 0 * LAMPORTS_PER_SOL;
}

this.priorityFeeSubscriber = priorityFeeSubscriber;
Expand Down Expand Up @@ -2386,11 +2391,7 @@ export class FillerBot implements Bot {
);
} else {
if (!this.dryRun) {
const slotsUntilJito = this.slotsUntilJitoLeader();
const buildForBundle =
this.usingJito() &&
slotsUntilJito !== undefined &&
slotsUntilJito < SLOTS_UNTIL_JITO_LEADER_TO_SEND;
const buildForBundle = this.shouldBuildForBundle();

// @ts-ignore;
simResult.tx.sign([this.driftClient.wallet.payer]);
Expand Down Expand Up @@ -2492,6 +2493,20 @@ export class FillerBot implements Bot {
return this.bundleSender?.slotsUntilNextLeader();
}

protected shouldBuildForBundle(): boolean {
if (!this.usingJito()) {
return false;
}
if (this.globalConfig.onlySendDuringJitoLeader === true) {
const slotsUntilJito = this.slotsUntilJitoLeader();
if (slotsUntilJito === undefined) {
return false;
}
return slotsUntilJito < SLOTS_UNTIL_JITO_LEADER_TO_SEND;
}
return true;
}

protected async tryFill() {
const startTime = Date.now();
let ran = false;
Expand Down Expand Up @@ -2550,11 +2565,7 @@ export class FillerBot implements Bot {
`filtered fillable nodes from ${fillableNodes.length} to ${filteredFillableNodes.length}, filtered triggerable nodes from ${triggerableNodes.length} to ${filteredTriggerableNodes.length}`
);

const slotsUntilJito = this.slotsUntilJitoLeader();
const buildForBundle =
this.usingJito() &&
slotsUntilJito !== undefined &&
slotsUntilJito < SLOTS_UNTIL_JITO_LEADER_TO_SEND;
const buildForBundle = this.shouldBuildForBundle();

// fill the perp nodes
await Promise.all([
Expand Down
24 changes: 17 additions & 7 deletions src/bots/spotFiller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ export class SpotFillerBot implements Bot {
if (!validMinimumAmountToFill(config.minimumAmountToFill)) {
this.minimumAmountToFill = 0.2 * LAMPORTS_PER_SOL;
} else {
// @ts-ignore
this.minimumAmountToFill = config.minimumAmountToFill * LAMPORTS_PER_SOL;
this.minimumAmountToFill =
config.minimumAmountToFill ?? 0 * LAMPORTS_PER_SOL;
}

logger.info(
Expand Down Expand Up @@ -1610,6 +1610,20 @@ export class SpotFillerBot implements Bot {
return this.bundleSender?.slotsUntilNextLeader();
}

private shouldBuildForBundle(): boolean {
if (!this.usingJito()) {
return false;
}
if (this.globalConfig.onlySendDuringJitoLeader === true) {
const slotsUntilJito = this.slotsUntilJitoLeader();
if (slotsUntilJito === undefined) {
return false;
}
return slotsUntilJito < SLOTS_UNTIL_JITO_LEADER_TO_SEND;
}
return true;
}

private async getBlockhashForTx(): Promise<string> {
const cachedBlockhash = this.blockhashSubscriber.getLatestBlockhash(
CACHED_BLOCKHASH_OFFSET
Expand Down Expand Up @@ -2377,11 +2391,7 @@ export class SpotFillerBot implements Bot {
`filtered triggerable nodes from ${triggerableNodes.length} to ${filteredTriggerableNodes.length} `
);

const slotsUntilJito = this.slotsUntilJitoLeader();
const buildForBundle =
this.usingJito() &&
slotsUntilJito !== undefined &&
slotsUntilJito < SLOTS_UNTIL_JITO_LEADER_TO_SEND;
const buildForBundle = this.shouldBuildForBundle();

await Promise.all([
this.executeFillableSpotNodesForMarket(fillableNodes, buildForBundle),
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export interface GlobalConfig {
jitoMaxBundleTip?: number;
jitoMaxBundleFailCount?: number;
jitoTipMultiplier?: number;
onlySendDuringJitoLeader?: boolean;

txRetryTimeoutMs?: number;
txSenderType?: 'fast' | 'retry' | 'while-valid';
Expand Down Expand Up @@ -196,6 +197,7 @@ const defaultConfig: Partial<Config> = {
jitoBlockEngineUrl: process.env.JITO_BLOCK_ENGINE_URL,
jitoAuthPrivateKey: process.env.JITO_AUTH_PRIVATE_KEY,
txRetryTimeoutMs: parseInt(process.env.TX_RETRY_TIMEOUT_MS ?? '30000'),
onlySendDuringJitoLeader: false,
txSkipPreflight: false,
txMaxRetries: 0,

Expand Down
36 changes: 19 additions & 17 deletions src/experimental-bots/filler/fillerMultithreaded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ export class FillerMultithreaded {
if (!validMinimumAmountToFill(config.minimumAmountToFill)) {
this.minimumAmountToFill = 0.2 * LAMPORTS_PER_SOL;
} else {
// @ts-ignore
this.minimumAmountToFill = config.minimumAmountToFill * LAMPORTS_PER_SOL;
this.minimumAmountToFill =
config.minimumAmountToFill ?? 0 * LAMPORTS_PER_SOL;
}

logger.info(
Expand Down Expand Up @@ -934,6 +934,20 @@ export class FillerMultithreaded {
return this.bundleSender?.slotsUntilNextLeader();
}

protected shouldBuildForBundle(): boolean {
if (!this.globalConfig.useJito) {
return false;
}
if (this.globalConfig.onlySendDuringJitoLeader === true) {
const slotsUntilJito = this.slotsUntilJitoLeader();
if (slotsUntilJito === undefined) {
return false;
}
return slotsUntilJito < SLOTS_UNTIL_JITO_LEADER_TO_SEND;
}
return true;
}

public async triggerNodes(
serializedNodesToTrigger: SerializedNodeToTrigger[]
) {
Expand All @@ -960,11 +974,7 @@ export class FillerMultithreaded {
`${logPrefix} Filtered down to ${filteredTriggerableNodes.length} triggerable nodes...`
);

const slotsUntilJito = this.slotsUntilJitoLeader();
const buildForBundle =
this.globalConfig.useJito &&
slotsUntilJito !== undefined &&
slotsUntilJito < SLOTS_UNTIL_JITO_LEADER_TO_SEND;
const buildForBundle = this.shouldBuildForBundle();

try {
await this.executeTriggerablePerpNodes(
Expand Down Expand Up @@ -1155,11 +1165,7 @@ export class FillerMultithreaded {
`${logPrefix} Filtered down to ${filteredFillableNodes.length} fillable nodes...`
);

const slotsUntilJito = this.slotsUntilJitoLeader();
const buildForBundle =
this.globalConfig.useJito &&
slotsUntilJito !== undefined &&
slotsUntilJito < SLOTS_UNTIL_JITO_LEADER_TO_SEND;
const buildForBundle = this.shouldBuildForBundle();

try {
await this.executeFillablePerpNodesForMarket(
Expand Down Expand Up @@ -1724,11 +1730,7 @@ export class FillerMultithreaded {
);
} else {
if (!this.dryRun) {
const slotsUntilJito = this.slotsUntilJitoLeader();
const buildForBundle =
this.globalConfig.useJito &&
slotsUntilJito !== undefined &&
slotsUntilJito < SLOTS_UNTIL_JITO_LEADER_TO_SEND;
const buildForBundle = this.shouldBuildForBundle();

// @ts-ignore;
simResult.tx.sign([this.driftClient.wallet.payer]);
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,19 @@
enabled "2.0.x"
kuler "^2.0.0"

"@drift-labs/[email protected].366":
version "0.10.366"
resolved "https://registry.yarnpkg.com/@drift-labs/jit-proxy/-/jit-proxy-0.10.366.tgz#cc18eef8aed2284c172ffc53800d7f3a849cafdf"
integrity sha512-MFTe73230NWgGQO1AYNXOA/JWRRGxe5TexDHCY7TT5Km1JLwi/47Dl2ALIkuuM6Ck6hwtPwTH5pp2c1VC2neXA==
"@drift-labs/[email protected].369":
version "0.10.369"
resolved "https://registry.yarnpkg.com/@drift-labs/jit-proxy/-/jit-proxy-0.10.369.tgz#313ad6d31a97587d03ede7e75e1b31a610aa417e"
integrity sha512-xYKQ/mg7HV06l2WHyqCAMZimxxsKzUcFt3XVh/VjcKP/4KCv087YLs2LlchzHjTVzBj3fSnfgslHDeLiV2k8Tg==
dependencies:
"@coral-xyz/anchor" "^0.26.0"
"@drift-labs/sdk" "2.78.0-beta.0"
"@drift-labs/sdk" "2.79.0-beta.2"
"@solana/web3.js" "1.73.2"

"@drift-labs/sdk@2.78.0-beta.0":
version "2.78.0-beta.0"
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.78.0-beta.0.tgz#5b33c41c561825ebef8849fdc71a76194715d5be"
integrity sha512-Z/+NY15Du9zRjA9ExIZFsNhxwE0OY5JGdfiu5wPk2mjRmOneEu71sltu5Z+yA89z8nGw/s0oZKdAsQnUZLzX6A==
"@drift-labs/sdk@2.79.0-beta.2":
version "2.79.0-beta.2"
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.79.0-beta.2.tgz#0b339759ceabd16334744db371843a9af3d6de36"
integrity sha512-gXgLiw60KK+fBHA78oVy/ydZKDJe9vyJva8ab1rTQEtSpHA2rGGTKQRcpmfV0qOkRM4O4e54FwNg6SOSPAUZoQ==
dependencies:
"@coral-xyz/anchor" "0.28.1-beta.2"
"@ellipsis-labs/phoenix-sdk" "^1.4.2"
Expand Down
Loading