Docs / Architecture / Fee Pipeline

The Autonomous Creator Fee Pipeline

Stonkerage turns onchain meme and stock coin trading fees into a perpetual capital flywheel. Every swap on StonkFun generates trading fees that are automatically swept, converted, bridged cross-chain to HyperCore, and deployed into an isolated leveraged perpetual position with automated take-profit harvesting.

Core Design Principle: Zero-Halt Fee Isolation Every token launched on Stonkerage possesses its own derived EVM clearinghouse address. At every stage of the pipeline, strict fee reserves are set aside before execution so that network congestion, taker fees, or bridge costs never freeze operations or cause liquidations.

Visual Execution Flow

1
StonkFun Fee Accrual (Standard Mode)
1.00% swap tax → 0.50% creator fee forwarded or claimable in quote currency
Solana L1
2
Gas Deficit & Reserve Check
Keeper verifies 0.05 SOL operational balance; automatically refills gas buffer
Safety Reserve
3
Jupiter Swap Routing (Non-SOL Quotes)
Converts SPL tokens to SOL/USDC at best market routes with ≤ 1.5% max slippage
Jupiter v6 DEX
4
Mayan Cross-Chain Bridge to HyperCore
Bridges SOL/USDC to HyperCore Spot USDC; enforces ≥ $10 net output and ≤ 15% fee ratio
Cross-Chain
5
HyperCore Spot → Perps Margin Transfer
Executes usdClassTransfer for balances ≥ $1.00; tracks contributed margin
Hyperliquid L1
6
Leveraged Position Sizing & Order Placement
computeTopUp reserves 2% taker fee buffer, snaps leverage to target, submits IOC order
Orderbook
7
Take-Profit Engine (Autonomous Flywheel)
Triggers at 1.30x equity multiple (+0.10x steps); executes 10% reduce-only market close
Take Profit

1. StonkFun Fee Accrual

Tokens launched on Stonkerage run on StonkFun LaunchLab utilizing Raydium Token-2022 pools. Each pool incurs a flat trading fee on every swap:

Standard Mode (Recommended)
1.00% total pool fee split 50/50: 0.50% accrues to the creator wallet, and 0.50% accrues to protocol LP. 100% of the creator share directly feeds the perpetual position.
Reward Mode (Custom Tax)
Tokens configured with a custom holder reward tax distribute a portion of fees directly to holders. The creator fee slice remaining continues to feed the perpetual keeper.

The keeper polls StonkFun's public API (/api/public/v1/tokens/:mint/fees). For auto-forwarding pools, balances landing in the creator's wallet are automatically detected and staged.

2. Gas & Operational Reserves

Autonomous agents often fail because cross-chain bridging or transaction fees exhaust the operator's native balance. Stonkerage prevents this with strict mathematical reserve invariants:

Permanent Operational Reserve: 0.05 SOL The keeper maintains an untouchable operational baseline of 50,000,000 lamports (0.05 SOL) plus a 0.005 SOL per-transaction gas buffer. Any incoming swap proceeds first refill any deficit in this gas reserve before a single lamport is allocated for cross-chain bridging.
// Sizing calculation in src/feeReserves.ts
const deficit = Math.max(0n, SOL_MIN_OPERATIONAL_RESERVE - currentBalance);
const refill = BigInt(Math.min(Number(deficit), Number(incomingLamports)));
const bridgeLamports = incomingLamports - refill;

3. Jupiter Auto-Swap Routing

When launched tokens are paired against xStocks, USDC, or third-party SPL tokens, the keeper routes the accrued quote tokens through Jupiter Ultra v6 DEX aggregator to swap into native SOL or USDC.

Slippage Tolerance: ≤ 1.50% (150 bps) max cap
Priority Fee Cap: Dynamic micro-lamport fee for rapid inclusion

4. Mayan Cross-Chain Bridge to HyperCore

Mayan Finance connects Solana liquidity directly to HyperCore L1 (Hyperliquid). Fees leaving Solana are converted into spot USDC credited directly to the coin's derived EVM clearinghouse account.

Bridge Quote Validation Rules Before any transaction is signed, the keeper validates the Mayan quote:
  • Destination Floor: Expected net output must be ≥ $10.00 USDC.
  • Maximum Fee Ratio: Total bridging and relayer fees must not exceed 15% of the input value.
If market fees temporarily spike, the funds remain safely on Solana until normal fee conditions return.

5. HyperCore Spot Transfer (usdClassTransfer)

Bridged funds arrive on HyperCore as spot USDC. On Hyperliquid, spot balances do not automatically back perpetual positions. The keeper issues an authenticated usdClassTransfer action signed by the token's isolated EVM key:

// Transfer spot balance into perps margin
const spotUsdc = await hlClient.getSpotUsdcBalance(evmAccount.address);
if (spotUsdc >= 1.00) {
  await hlClient.usdClassTransfer(evmAccount, spotUsdc, true);
  tpStore.addContribution(mint, spotUsdc);
}

6. Leverage Snapping & Top-Up Sizing

When new margin arrives, the keeper calculates the exact size to add so that the position snaps precisely to the target leverage ratio without ever exceeding it.

Top-Up Sizing Formula:
usableMargin = addedMargin × (1 - marginFeeBufferBps / 10000)
targetEquity = currentEquity + usableMargin
desiredSizeBase = (targetEquity × targetLeverage) / markPrice
additionalSizeBase = Math.max(0, desiredSizeBase - currentSizeBase)
* Note: marginFeeBufferBps = 200 (2.0%) is withheld as liquid buffer to absorb Hyperliquid taker fees (0.035%) and order slippage.

Multi-Hop Fee Reservation Matrix

Summary of all safety buffers reserved across each hop in the pipeline:

Stage Mechanism Reserved Amount Safety Guarantee
Solana Keeper Gas calculateSolGasReserve() 0.05 SOL permanent Keeper never runs out of gas
Solana Tx Fees SOLANA_MIN_TX_LAMPORTS 0.005 SOL buffer Priority fee spike absorption
Jupiter DEX Swap swapTokenToSol() 1.5% max slippage Prevents sandwich / MEV attacks
Mayan Bridge validateMayanBridgeFees() ≤ 15% fee ratio Rejects uneconomic bridge quotes
HyperCore Sweep usdClassTransfer() ≥ $1.00 floor Prevents zero-value API calls
Perp Execution computeTopUp() 2.0% fee margin Covers 0.035% taker fee & slippage

Take-Profit Engine (Autonomous Flywheel)

Stonkerage integrates an autonomous mathematical take-profit flywheel. Positions are not held indefinitely; as positions gain value, profit milestones trigger automated profit-taking.

First TP Milestone
1.30x
+30% position equity gain
Milestone Step
+0.10x
1.40x, 1.50x, 1.60x, ...
Reduce-Only Close
10%
of base size per trigger

Frozen Milestone Basis

When a milestone is active, activeMilestoneBasisUsd freezes the dollar capital basis. If ongoing StonkFun trading volume injects additional fee margin into the position while a milestone is in progress, the profit goalpost is not pushed further away. Only true trading profit satisfies the target.

Deterministic CLOID & Idempotency

Each milestone derives a unique deterministic Client Order ID: deriveTakeProfitCloid(mint, completedMilestones). If the keeper restarts or retries during an order execution, it checks the exchange status of that CLOID. If already filled, it simply advances the milestone state without placing a duplicate order.

Withdrawable Delta Measurement

To avoid rounding or pricing discrepancies, the keeper brackets the reduce-only close order with reads of getWithdrawable() before and after. The diff represents the exact dollar proceeds freed up and recorded as realized profit.

Non-Custodial Design & Key Derivation

Tokens are created directly by the user's connected wallet (Phantom, Solflare) using Solana Token-2022. Raydium CP-Swap pool instructions are partially signed by the user and finalized onchain without any custodial intermediaries.

Isolated EVM Clearinghouse Derivation:

Each token mint address generates a distinct, non-overlapping Hyperliquid EVM private key using HMAC-SHA256:

privKey = hmacSha256(derivationSecret, mintAddress)
evmAccount = privateKeyToAccount(privKey)

Because each token trades under its own isolated clearinghouse account, a liquidation in one token's position can never affect or cross-collateralize any other token.