API

buff.getWrapInstructions()

Get round-up transfer instructions from the Buff API to add to your transaction.

Signature

types.ts
typescript
1async getWrapInstructions(
2 txValueUsd: number,
3 userPubkey: string,
4 buffWalletPubkey: string
5): Promise<{ instructions: string[]; breakdown: RoundUpBreakdown }>

Parameters

ParamTypeDescription
txValueUsdnumberTotal transaction value in USD (the amount being swapped/sent/minted)
userPubkeystringThe user's main wallet public key
buffWalletPubkeystringThe user's Buff wallet public key (from deriveWallet)

Returns

An object with transfer instructions to append to your transaction, plus a breakdown of the round-up calculation. All fee logic is computed server-side — the treasury address is never exposed to the client.

InstructionDestinationAmount
Transfer 1User's Buff walletRound-up minus Buff fee
Transfer 2Buff treasury (hidden)Buff platform fee

RoundUpBreakdown

breakdown.ts
typescript
1interface RoundUpBreakdown {
2 txValueUsd: number // Original tx value
3 roundToUsd: number // Plan's increment
4 roundedToUsd: number // Next boundary
5 roundUpUsd: number // Spare change amount
6 buffFeePercent: number // Buff fee rate
7 buffFeeUsd: number // Buff takes
8 userInvestmentUsd: number // User gets
9 roundUpLamports: number // Total in lamports
10 userInvestmentLamports: number // User portion in lamports
11 buffFeeLamports: number // Fee portion in lamports
12 solPriceUsd: number // SOL price used
13 skipped: boolean // true if exact match
14 capped: boolean // true if ceiling applied
15}

Calculate Without Wrapping

calculate.ts
typescript
1// Preview the round-up without generating instructions
2const breakdown = await buff.calculateRoundUp(47.83)
3
4console.log("Round-up would be: $" + breakdown.roundUpUsd)
5console.log("User would invest: $" + breakdown.userInvestmentUsd)
6console.log("Buff fee: $" + breakdown.buffFeeUsd)

Example

wrap.ts
typescript
1const { instructions, breakdown } = await buff.getWrapInstructions(
2 47.83, userPubkey, buffWalletPubkey
3)
4
5if (breakdown.skipped) {
6 console.log("Exact dollar — no round-up")
7} else {
8 console.log("Round-up: $" + breakdown.roundUpUsd)
9
10 // Add instructions to your transaction
11 const tx = new Transaction()
12 tx.add(/* your swap instruction */)
13 for (const ix of instructions) tx.add(ix)
14
15 // Sign and send as usual
16 await sendTransaction(tx)
17}
Note
If the transaction value is an exact multiple of the plan increment (e.g. $2.00 on Sprout), getWrapInstructions() returns empty instructions with skipped: true in the breakdown.