API
buff.checkAndInvest()
Check accumulated balance and auto-swap to target asset when threshold is reached.
Signature
types.ts
typescript
1async checkAndInvest(): Promise<{2 state: AccumulatorState3 swaps: SwapResult[] // one per allocation4 quotes: SwapQuote[] // one per allocation5 swap: SwapResult | null // first swap (backward compat)6 quote: SwapQuote | null // first quote (backward compat)7}>AccumulatorState
types.ts
typescript
1interface AccumulatorState {2 balanceSol: number // Buff wallet SOL balance3 balanceUsd: number // In USD (real-time price)4 roundUpCount: number // Round-ups since last swap5 thresholdReached: boolean6 thresholdUsd: number // Configured threshold7 solPriceUsd: number // Current SOL price8}SwapResult (when threshold reached)
types.ts
typescript
1interface SwapResult {2 txSignature: string // Solana tx signature3 inputSol: number // SOL amount swapped4 asset: SupportedAsset // Target asset (BTC, ETH, etc.)5 timestamp: number // Unix timestamp6}Example
invest.ts
typescript
1// Call after each wrap()2const { state, swaps, quotes } = await buff.checkAndInvest()34if (!state.thresholdReached) {5 console.log("Accumulated: $" + state.balanceUsd.toFixed(2))6 console.log("Need: $" + (state.thresholdUsd - state.balanceUsd).toFixed(2))7 return8}910// Multi-asset: one swap per allocation11for (let i = 0; i < swaps.length; i++) {12 console.log(swaps[i].inputSol + " SOL → " + swaps[i].asset)13 console.log("Route: " + quotes[i]?.route)14}15// e.g. with allocations [{BTC:60},{ETH:40}]:16// 0.030 SOL → BTC17// 0.020 SOL → ETHNote
A 0.01 SOL reserve is kept in the Buff wallet for future transaction fees. The swap is executed via Jupiter with automatic route finding.
Preview Without Executing
quote.ts
typescript
1// Get a quote without swapping2const quote = await buff.getQuote()34if (quote) {5 console.log("Would swap:", quote.inputSol, "SOL")6 console.log("Expected output:", quote.expectedOutput)7 console.log("Route:", quote.route)8}