Builder Codes
Builder Codes (DBC) let integrators earn fees by routing flow through their application. The workflow has 3 steps: builder initializes revenue share → user creates escrow → user approves builder with max fee.
Setup
First, initialize the DriftClient for both the builder and user:
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();SDK Usage
Builder: Initialize Revenue Share
await builderClient.initializeRevenueShare(builderAuthority);Method DriftClient.initializeRevenueShareReference ↗| Name | Type | Default |
|---|---|---|
authority | PublicKey | |
txParams | TxParams |
User: Initialize Escrow
await userClient.initializeRevenueShareEscrow(takerAuthority, 16);Method DriftClient.initializeRevenueShareEscrowReference ↗| Name | Type | Default |
|---|---|---|
authority | PublicKey | |
numOrders | number | |
txParams | TxParams |
User: Approve a Builder (Max Fee)
// max fee is expressed in tenths of a basis point (100 = 10 bps)
await userClient.changeApprovedBuilder(builderAuthority, 200, true);Method DriftClient.changeApprovedBuilderReference ↗Last updated on