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 | name: pump-fee-system |
| #3 | description: "Complete Pump protocol fee system — tiered protocol fees based on market cap, creator fee collection across two programs, basis point arithmetic, and ceiling division for dust-safe calculations." |
| #4 | metadata: |
| #5 | openclaw: |
| #6 | homepage: https://github.com/nirholas/pump-fun-sdk |
| #7 | --- |
| #8 | |
| #9 | # Fee System — Tiered Fees, Creator Fees & Protocol Fees |
| #10 | |
| #11 | Implement and extend the Pump protocol's fee system: tiered protocol fees based on market cap, creator fee collection across two programs, and fee computation with ceiling division. |
| #12 | |
| #13 | ## Context |
| #14 | |
| #15 | The Pump protocol charges fees on every buy/sell transaction. Fees flow to protocol fee recipients and token creators. The fee system spans three programs and must handle tokens in both bonding curve and graduated (AMM) states. |
| #16 | |
| #17 | ## Fee Types |
| #18 | |
| #19 | | Fee | Recipient | When Charged | |
| #20 | |-----|-----------|-------------| |
| #21 | | Protocol fee | `feeRecipients[]` in `Global` | Every buy/sell | |
| #22 | | Creator fee | Token creator's vault PDA | Every buy/sell (if creator is set) | |
| #23 | | LP fee | Liquidity providers (AMM only) | Post-graduation trades | |
| #24 | |
| #25 | ## Tiered Fee Calculation |
| #26 | |
| #27 | When a `FeeConfig` exists, fees are market-cap-dependent: |
| #28 | |
| #29 | ```typescript |
| #30 | function calculateFeeTier({ feeTiers, marketCap }): Fees { |
| #31 | // Iterate tiers in REVERSE order |
| #32 | for (let i = feeTiers.length - 1; i >= 0; i--) { |
| #33 | if (marketCap >= feeTiers[i].marketCapLamportsThreshold) { |
| #34 | return feeTiers[i].fees; |
| #35 | } |
| #36 | } |
| #37 | return feeTiers[0].fees; // fallback to lowest tier |
| #38 | } |
| #39 | ``` |
| #40 | |
| #41 | ## Fee Computation |
| #42 | |
| #43 | ```typescript |
| #44 | function getFee({ global, feeConfig, mintSupply, bondingCurve, amount }): BN { |
| #45 | const { protocolFeeBps, creatorFeeBps } = computeFeesBps(...); |
| #46 | const protocolFee = ceilDiv(amount * protocolFeeBps, 10000); |
| #47 | const creatorFee = hasCreator ? ceilDiv(amount * creatorFeeBps, 10000) : 0; |
| #48 | return protocolFee + creatorFee; |
| #49 | } |
| #50 | ``` |
| #51 | |
| #52 | ## Creator Vault Balance |
| #53 | |
| #54 | Creator fees accumulate in PDAs: |
| #55 | - `creatorVaultPda(creator)` — Pump program vault |
| #56 | - `ammCreatorVaultPda(creator)` — PumpAMM program vault |
| #57 | |
| #58 | Balance = total lamports - rent exemption minimum. |
| #59 | |
| #60 | ## Error Classes |
| #61 | |
| #62 | | Error | Condition | |
| #63 | |-------|-----------| |
| #64 | | `NoShareholdersError` | Empty shareholders array | |
| #65 | | `TooManyShareholdersError` | More than 10 shareholders | |
| #66 | | `ZeroShareError` | Shareholder has `shareBps <= 0` | |
| #67 | | `InvalidShareTotalError` | Shares don't sum to 10,000 bps | |
| #68 | | `DuplicateShareholderError` | Duplicate addresses | |
| #69 | |
| #70 | ## Patterns to Follow |
| #71 | |
| #72 | - Use ceiling division (`ceilDiv`) for all fee calculations to prevent dust loss |
| #73 | - Always check both creator vaults (Pump + AMM) when querying balances |
| #74 | - Use transaction simulation (`simulateTransaction`) for read-only fee queries |
| #75 | - Creator fee is only charged when `bondingCurve.creator != PublicKey.default` or it's a new curve |
| #76 | |
| #77 | ## Common Pitfalls |
| #78 | |
| #79 | - Fee tiers must be iterated in reverse — the first match from the end is used |
| #80 | - `computeFeesBps` returns different results depending on whether `feeConfig` is null (legacy vs tiered) |
| #81 | - Creator fees are zero for tokens without a set creator |
| #82 | - `getMinimumDistributableFee` requires transaction simulation — it cannot be computed offline |
| #83 | - `transferCreatorFeesToPump` is only for graduated tokens — non-graduated tokens will fail |
| #84 | |
| #85 |