API

Accumulate & Swap

Check accumulated balance, get swap quotes, build and execute swaps — all via the Buff API.

Get Accumulator State

types.ts
typescript
1async getAccumulator(address: string): Promise<AccumulatorState>
2
3interface AccumulatorState {
4 balanceSol: number // Buff wallet SOL balance
5 balanceUsd: number // In USD (real-time price)
6 remaining: number // USD remaining until threshold
7 thresholdReached: boolean
8 thresholdUsd: number // Configured threshold
9 solPriceUsd: number // Current SOL price
10}

Get Swap Quote

types.ts
typescript
1async getSwapQuote(
2 inputLamports: number,
3 targetAsset: SupportedAsset
4): Promise<SwapQuote>
5
6interface SwapQuote {
7 inputSol: number
8 outputAmount: string
9 outputMint: string
10 priceImpact: string
11 route: string
12}

Build & Execute Swaps

types.ts
typescript
1// Build swap transactions server-side
2async buildSwap(buffWalletPubkey: string): Promise<{
3 ready: boolean
4 balanceSol: number
5 balanceUsd: number
6 threshold: number
7 transactions: Array<{
8 asset: string
9 pct: number
10 inputLamports: number
11 transaction: string // base64 unsigned tx — sign then executeSwap()
12 quote: SwapQuote
13 }>
14}>
15
16// Execute a signed swap transaction
17async executeSwap(signedTxBase64: string): Promise<{
18 txSignature: string
19 confirmed: boolean
20}>

Example

invest.ts
typescript
1// Check accumulator state
2const state = await buff.getAccumulator(buffWalletPubkey)
3
4if (!state.thresholdReached) {
5 console.log("Accumulated: $" + state.balanceUsd.toFixed(2))
6 console.log("Need: $" + (state.thresholdUsd - state.balanceUsd).toFixed(2))
7 return
8}
9
10// Build swap transactions (server handles routing via Jupiter)
11const { ready, transactions } = await buff.buildSwap(buffWalletPubkey)
12
13if (ready) {
14 for (const txBase64 of transactions) {
15 // Sign the transaction with the Buff wallet
16 const signed = await signTransaction(txBase64)
17 const result = await buff.executeSwap(signed)
18 console.log("Swapped →", result.asset, "tx:", result.txSignature)
19 }
20}
Note
All swap routing happens server-side via Jupiter. The client only signs and submits the pre-built transactions. A 0.01 SOL reserve is kept in the Buff wallet for future transaction fees.

Preview a Swap Quote

quote.ts
typescript
1// Get a swap quote without executing
2const quote = await buff.getSwapQuote(50000000, "BTC") // 0.05 SOL in lamports
3
4console.log("Would swap:", quote.inputSol, "SOL")
5console.log("Expected output:", quote.outputAmount)
6console.log("Route:", quote.route)
7console.log("Price impact:", quote.priceImpact + "%")