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

ParamTypeDescription
transactionTransactionThe original Solana transaction to wrap
userPubkeyPublicKeyThe user's main wallet public key
options.txValueUsdnumberTotal transaction value in USD (the amount being swapped/sent/minted)

Returns

The original transaction with two additional instructions appended (if not skipped):

InstructionDestinationAmount
Transfer 1User's Buff walletRound-up minus Buff fee
Transfer 2Buff treasuryBuff platform fee

FeeBreakdown

breakdown.ts
typescript
1interface FeeBreakdown {
2 txValueUsd: number // Original tx value
3 roundToUsd: number // Plan's increment
4 roundedToUsd: number // Next boundary
5 roundUpUsd: number // Spare change amount
6 roundUpSol: number // Converted to SOL
7 buffFeePercent: number // Buff fee rate
8 buffFeeUsd: number // Buff takes
9 buffFeeSol: number // In SOL
10 userInvestmentUsd: number // User gets
11 userInvestmentSol: number // In SOL
12 skipped: boolean // true if exact match
13 capped: boolean // true if ceiling applied
14}

Example

wrap.ts
typescript
1const tx = new Transaction()
2tx.add(/* your swap instruction */)
3
4const { transaction, breakdown } = await buff.wrap(tx, userPubkey, {
5 txValueUsd: 47.83
6})
7
8if (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}
14
15// Sign and send as usual
16await 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.