Skip to Content
DevelopersDrift SDKBuilder Codes

Builder Codes

Builder Codes (DBC) let integrators earn fees by routing flow through their application. The workflow has 3 steps: builder initializes revenue shareuser creates escrowuser approves builder with max fee.

Setup

First, initialize the DriftClient for both the builder and user:

Create and subscribe separate DriftClient instances for builder and user authorities.

import { DriftClient } from "@drift-labs/sdk"; import { Connection, Keypair, PublicKey } from "@solana/web3.js"; // Initialize connection const connection = new Connection("https://api.mainnet-beta.solana.com"); // Builder wallet (revenue share provider) const builderWallet = Keypair.fromSecretKey(/* builder secret key */); const builderAuthority = builderWallet.publicKey; // User wallet (end user) const userWallet = Keypair.fromSecretKey(/* user secret key */); const takerAuthority = userWallet.publicKey; // Builder client const builderClient = new DriftClient({ connection, wallet: builderWallet, env: "mainnet-beta" }); await builderClient.subscribe(); // User client const userClient = new DriftClient({ connection, wallet: userWallet, env: "mainnet-beta" }); await userClient.subscribe();
Example Builder codes setupReference ↗
TypeScript docs unavailable for Builder codes setup.

SDK Usage

Builder: Initialize Revenue Share

Create the builder’s onchain revenue-share configuration account.

await builderClient.initializeRevenueShare(builderAuthority);
Method DriftClient.initializeRevenueShareReference ↗
ParameterTypeRequired
authority
PublicKey
Yes
txParams
TxParams
No
Returns
Promise<string>

User: Initialize Escrow

Create the user’s revenue-share escrow account used for builder fee routing.

await userClient.initializeRevenueShareEscrow(takerAuthority, 16);
Method DriftClient.initializeRevenueShareEscrowReference ↗
ParameterTypeRequired
authority
PublicKey
Yes
numOrders
number
Yes
txParams
TxParams
No
Returns
Promise<string>

User: Approve a Builder (Max Fee)

Approve a builder for this user and set the maximum fee they can charge.

// max fee is expressed in tenths of a basis point (100 = 10 bps) await userClient.changeApprovedBuilder(builderAuthority, 200, true);
Method DriftClient.changeApprovedBuilderReference ↗
ParameterTypeRequired
builder
PublicKey
The public key of the builder to add or update.
Yes
maxFeeTenthBps
number
The maximum fee tenth bps to set for the builder.
Yes
add
boolean
Whether to add or update the builder. If the builder already exists, `add = true` will update the `maxFeeTenthBps`, otherwise it will add the builder. If `add = false`, the builder's `maxFeeTenthBps` will be set to 0.
Yes
txParams
TxParams
The transaction parameters to use for the transaction.
No
Returns
Promise<string>
Last updated on