API
buff.wrap()
Wrap a Solana transaction with Buff round-up transfer instructions.
Signature
types.ts
typescript
1async wrap(2 transaction: Transaction,3 userPubkey: PublicKey,4 options: { txValueUsd: number }5): Promise<{ transaction: Transaction; breakdown: FeeBreakdown }>Parameters
| Param | Type | Description |
|---|---|---|
| transaction | Transaction | The original Solana transaction to wrap |
| userPubkey | PublicKey | The user's main wallet public key |
| options.txValueUsd | number | Total transaction value in USD (the amount being swapped/sent/minted) |
Returns
The original transaction with two additional instructions appended (if not skipped):
| Instruction | Destination | Amount |
|---|---|---|
| Transfer 1 | User's Buff wallet | Round-up minus Buff fee |
| Transfer 2 | Buff treasury | Buff platform fee |
FeeBreakdown
breakdown.ts
typescript
1interface FeeBreakdown {2 txValueUsd: number // Original tx value3 roundToUsd: number // Plan's increment4 roundedToUsd: number // Next boundary5 roundUpUsd: number // Spare change amount6 roundUpSol: number // Converted to SOL7 buffFeePercent: number // Buff fee rate8 buffFeeUsd: number // Buff takes9 buffFeeSol: number // In SOL10 userInvestmentUsd: number // User gets11 userInvestmentSol: number // In SOL12 skipped: boolean // true if exact match13 capped: boolean // true if ceiling applied14}Example
wrap.ts
typescript
1const tx = new Transaction()2tx.add(/* your swap instruction */)34const { transaction, breakdown } = await buff.wrap(tx, userPubkey, {5 txValueUsd: 47.836})78if (breakdown.skipped) {9 console.log("Exact dollar — no round-up")10} else {11 console.log("Round-up: $" + breakdown.roundUpUsd)12 console.log("Instructions added:", transaction.instructions.length)13}1415// Sign and send as usual16await sendTransaction(transaction)Note
If the transaction value is an exact multiple of the plan increment (e.g. $2.00 on Sprout), wrap() returns the original transaction unchanged with skipped: true.