repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | { |
| #2 | "skillId": "pump-bonding-curve", |
| #3 | "name": "pump-bonding-curve", |
| #4 | "description": "Constant-product AMM bonding curve math for Pump token pricing — buy/sell quoting, fee-aware calculations, market cap computation, tiered fees, ceiling division, virtual vs real reserves, and edge-case handling.", |
| #5 | "category": "pump-protocol", |
| #6 | "path": "pump-bonding-curve/SKILL.md", |
| #7 | "url": "https://x402.wtf/api/skills/pump-bonding-curve", |
| #8 | "tags": [ |
| #9 | "pump", |
| #10 | "solana", |
| #11 | "bonding", |
| #12 | "curve" |
| #13 | ], |
| #14 | "requiredEnv": [], |
| #15 | "homepage": "https://github.com/nirholas/pump-fun-sdk", |
| #16 | "attestation": { |
| #17 | "status": "pending", |
| #18 | "isFormallyVerified": false, |
| #19 | "attestationPda": null, |
| #20 | "verificationTimestamp": null |
| #21 | }, |
| #22 | "markdown": "---\nname: pump-bonding-curve\ndescription: \"Constant-product AMM bonding curve math for Pump token pricing — buy/sell quoting, fee-aware calculations, market cap computation, tiered fees, ceiling division, virtual vs real reserves, and edge-case handling.\"\nmetadata:\n openclaw:\n homepage: https://github.com/nirholas/pump-fun-sdk\n---\n\n# Bonding Curve — Pricing, Quoting & AMM Mathematics\n\nImplement and maintain the constant-product AMM bonding curve math that powers Pump token pricing — including buy/sell quoting, fee-aware calculations, market cap computation, reserve management, and edge-case handling for new, active, and migrated curves.\n\n## Context\n\nPump tokens are priced using a constant-product bonding curve ($x \\times y = k$) where $x$ = virtual SOL reserves and $y$ = virtual token reserves. The bonding curve determines token prices during the pre-graduation phase. Once market cap reaches a threshold, the token \"graduates\" and migrates to a PumpAMM pool.\n\n## Key Files\n\n- `src/bondingCurve.ts` — all bonding curve math functions (buy/sell quoting, market cap)\n- `src/fees.ts` — fee computation (basis points, tiered fees, ceiling division)\n- `src/state.ts` — `BondingCurve`, `Global`, `FeeConfig`, `FeeTier` interfaces\n\n## Constant-Product Formula\n\n$$x \\times y = k$$\n\n**Buy (tokens out for SOL in):**\n$$\\text{tokensOut} = \\frac{dx \\times Y}{X + dx}$$\n\nWhere $dx$ = SOL input (after fees), $X$ = virtual SOL reserves, $Y$ = virtual token reserves.\n\n**Sell (SOL out for tokens in):**\n$$\\text{solOut} = \\frac{dy \\times X}{Y + dy}$$\n\nWhere $dy$ = tokens sold, $X$ = virtual SOL reserves, $Y$ = virtual token reserves.\n\n## Fee Stripping\n\nFees are deducted from the SOL amount **before** applying the bonding curve formula:\n\n```typescript\ninputAmount = (amount - 1) * 10000 / (totalFeeBps + 10000)\n```\n\nThe `- 1` before fee stripping is intentional to handle rounding edge cases.\n\n## Market Cap Calculation\n\n$$\\text{marketCap} = \\frac{\\text{virtualSolReserves} \\times \\text{mintSupply}}{\\text{virtualTokenReserves}}$$\n\nWhere `mintSupply` defaults to `ONE_BILLION_SUPPLY` ($1 \\times 10^{15}$ — 1B tokens with 6 decimals).\n\n## Fee Tiers\n\nWhen a `FeeConfig` exists, fees are market-cap-dependent. Fee tiers are iterated in **reverse** order — the first tier from the end whose `marketCapLamportsThreshold ≤ currentMarketCap` is selected.\n\n```typescript\ninterface FeeTier {\n marketCapLamportsThreshold: BN;\n fees: { lpFeeBps: BN; protocolFeeBps: BN; creatorFeeBps: BN };\n}\n```\n\n## Ceiling Division\n\n$$\\text{ceilDiv}(a, b) = \\frac{a + b - 1}{b}$$\n\n```typescript\nfunction ceilDiv(a: BN, b: BN): BN {\n return a.add(b).sub(new BN(1)).div(b);\n}\n```\n\n## Virtual vs Real Reserves\n\n| Reserve Type | Includes | Used For |\n|-------------|----------|----------|\n| `virtualSolReserves` | Real SOL + protocol-added virtual offset | AMM formula calculation |\n| `virtualTokenReserves` | Real tokens + virtual offset | AMM formula calculation |\n| `realTokenReserves` | Actual tokens available | Buy output cap |\n| `realSolReserves` | Actual SOL deposited | Withdrawal limit |\n\n## Edge Cases\n\n| Case | Behavior |\n|------|----------|\n| Zero amount | Returns `BN(0)` |\n| Migrated curve (`complete === true`, zero reserves) | Returns `BN(0)` |\n| Null bonding curve | Creates a fresh curve via `newBondingCurve(global)` |\n| Tokens exceed real reserves | Caps at `realTokenReserves` |\n| Creator fee | Only charged if `bondingCurve.creator != PublicKey.default` or it's a new curve |\n\n## BondingCurve State\n\n```typescript\ninterface BondingCurve {\n virtualTokenReserves: BN;\n virtualSolReserves: BN;\n realTokenReserves: BN;\n realSolReserves: BN;\n tokenTotalSupply: BN;\n complete: boolean; // true = graduated to AMM\n creator: PublicKey;\n isMayhemMode: boolean;\n}\n```\n\n## Patterns to Follow\n\n- All amounts use `BN` (bn.js) for arbitrary-precision integer arithmetic — never use JavaScript `number`\n- Fee amounts are in **basis points** (1 bps = 0.01%, 10,000 bps = 100%)\n- Always deduct fees **before** applying the AMM formula, not after\n- Use ceiling division (`ceilDiv`) for fee computation to ensure the protocol never loses dust\n- Quote functions are pure — no network calls, no side effects, no mutable state\n- Always check `bondingCurve.complete` before building trade instructions\n\n## Common Pitfalls\n\n- Confusing virtual reserves (includes virtual offset) with real reserves (actual amounts)\n- Not accounting for fees when quoting — raw quote functions give different results than fee-aware ones\n- Trying to trade on a graduated curve (`complete === true`) will fail on-chain\n- Fee tiers iterate in **reverse** order — not forward\n- Market cap calculation uses `mintSupply` not `tokenTotalSupply`\n- The fee stripping formula subtracts 1 from the amount first — this is intentional\n- `getBuySolAmountFromTokenAmountQuote` adds `+ 1` to the result to ensure sufficient SOL\n\n" |
| #23 | } |
| #24 |