For developers
The program
Every account, instruction, event and error of the on-chain program, with arguments and what each one does.
On this page
The program is called poffert. It is written in Rust with Anchor and does everything on chain. This page is the reference for developers: what it stores, what you can call and what it tells you back.
All amounts are whole numbers in raw units: lamports for SOL (1 SOL = 1,000,000,000) and base units for tokens (6 decimals, so 1 token = 1,000,000). Fees are in basis points (1 bp = 0.01%). Timestamps are Unix seconds.
Accounts#
| Account | Address (PDA seeds) | Holds |
|---|---|---|
| GlobalConfig | ["global"] |
The admin, the fee wallet, the pause switches, the defaults for new tokens and the fees. One per program. |
| BondingCurve | ["bonding_curve", mint] |
One curve per token: its reserves, fees and state. It also holds the curve's SOL as lamports. |
| CreatorVault | ["creator_vault", creator] |
A small account where a creator's curve fees collect. |
| Pool | ["pool", mint_a, mint_b] with mint_a < mint_b (byte order) |
One pool per pair: tracked reserves, fees and accrued fee balances. |
| Pool vault | ["pool_vault", pool, mint] |
A token account holding one side of a pool. |
| LP mint | ["pool_lp_mint", pool] |
The pool's LP token (a standard token with 6 decimals, mint authority = the pool). |
| Event authority | ["__event_authority"] |
The account that signs event self-calls. |
A curve's token vault is the standard associated token account of the curve account for the token's mint.
GlobalConfig#
| Field | Type | Meaning |
|---|---|---|
admin |
pubkey | Who can change the config and pause. |
pending_admin |
optional pubkey | A proposed successor, if a transfer is under way. |
fee_recipient |
pubkey | Where the platform's fees are paid. |
paused_launch, paused_curve_trading, paused_amm |
bool | The three pause switches. |
initial_virtual_sol |
u64 | Starting SOL pile of new curves (30 SOL). |
initial_virtual_tokens |
u64 | Starting token pile of new curves (1,073,000,000 tokens). |
initial_real_tokens |
u64 | Tokens for sale on a new curve (793,100,000). |
token_total_supply |
u64 | Supply of a new token (1,000,000,000). |
curve_protocol_fee_bps, curve_creator_fee_bps |
u16 | Curve fee split (95 and 30). |
amm_lp_fee_bps, amm_protocol_fee_bps, amm_creator_fee_bps |
u16 | Graduated-pool fee split (20, 5, 5). |
migration_fee_lamports |
u64 | Fee paid out of the curve's SOL at graduation (0). Not capped. |
bump |
u8 | PDA bump. |
The live values are in this account. The API's /api/config endpoint currently returns the launch defaults built into the service (it says "source": "defaults"), not the live account. To know what is in force right now, read the GlobalConfig account.
BondingCurve#
| Field | Type | Meaning |
|---|---|---|
mint, creator |
pubkey | The token and who launched it. |
virtual_sol_reserves, virtual_token_reserves |
u64 | The two piles the price is computed from. |
real_sol_reserves |
u64 | SOL actually paid in (not counting rent). |
real_token_reserves |
u64 | Tokens still for sale. |
token_total_supply, initial_real_tokens |
u64 | Supply and the tokens that were for sale at the start (for the progress bar). |
protocol_fee_bps, creator_fee_bps |
u16 | The fees this curve was created with. |
complete |
bool | All curve tokens are sold. |
migrated |
bool | The curve has been moved into a pool. |
pool |
pubkey | The pool, once migrated. |
created_at |
i64 | Creation time. |
bump |
u8 | PDA bump. |
The curve account's lamports are always rent-exempt minimum + real_sol_reserves, and every trade asserts this.
Pool#
| Field | Type | Meaning |
|---|---|---|
mint_a, mint_b |
pubkey | The two tokens (mint_a < mint_b). |
vault_a, vault_b, lp_mint |
pubkey | The pool's vaults and LP mint. |
reserve_a, reserve_b |
u64 | Tracked reserves. Prices use these, never the vault balances, so donations change nothing. |
lp_supply |
u64 | Tracked LP supply. It includes the locked minimum and, for graduated pools, the never-minted starting liquidity. |
lp_fee_bps, protocol_fee_bps, creator_fee_bps |
u16 | The pool's fee split. |
creator |
optional pubkey | The token's creator (graduated pools only). |
protocol_fees_a, protocol_fees_b, creator_fees_a, creator_fees_b |
u64 | Fees owed, kept in the vaults outside the reserves. |
origin |
enum | Graduated or Permissionless. |
bump |
u8 | PDA bump. |
Instructions#
deadline is an optional Unix time: the instruction fails with DeadlineExceeded if it runs later.
Launching and trading on a curve#
| Instruction | Arguments | Who | What it does |
|---|---|---|---|
create_token |
name, symbol, uri |
Anyone (mint keypair also signs) | Creates the mint (6 decimals), writes immutable metadata, mints the full supply into the curve's vault, revokes the mint authority, and sets no freeze authority. Name up to 32 bytes, symbol up to 10, uri up to 200. Blocked while launching is paused. |
buy_exact_sol_in |
sol_in, min_tokens_out, deadline |
Anyone | Spend an exact amount of SOL. The last buyer is capped to the remaining tokens and charged only for them. |
buy |
token_amount, max_sol_cost, deadline |
Anyone | Buy an exact number of tokens, failing if the cost plus fee exceeds the maximum. |
sell |
token_amount, min_sol_out, deadline |
Anyone | Sell an exact number of tokens. Not blocked by the pause. |
claim_creator_fees |
none | The creator | Pays out the creator vault's SOL above its rent-exempt minimum. Not blocked by the pause. |
After a curve is complete, both buy and sell fail with CurveComplete: selling back would disturb the tokens reserved for the pool.
Graduation#
| Instruction | Arguments | Who | What it does |
|---|---|---|---|
migrate |
none | Anyone (once the curve is complete and not migrated) | Creates the pool, its vaults and LP mint (the caller pays their rent), wraps the curve's SOL (minus the migration fee) into the pool's SOL vault, moves the reserved tokens in, and sets migrated. No LP is minted. Blocked while the AMM is paused. |
Pools#
| Instruction | Arguments | Who | What it does |
|---|---|---|---|
create_pool |
amount_a, amount_b, deadline |
Anyone | Opens a pool (0.20% LP + 0.05% protocol). Both mints must pass the token check, and neither may have a running curve (MintHasActiveCurve). Initial LP is isqrt(a × b) − 1,000, and 1,000 stays locked. |
add_liquidity |
max_a, max_b, min_lp_out, deadline |
Anyone | Deposits at the pool's current ratio. |
remove_liquidity |
lp_amount, min_a, min_b, deadline |
LP holder | Burns LP and pays out pro rata. Not blocked by the pause. |
swap |
amount_in, min_amount_out, a_to_b, deadline |
Anyone | Exact-input swap. |
swap_exact_out |
amount_out, max_amount_in, a_to_b, deadline |
Anyone | Exact-output swap. |
collect_protocol_fees |
none | Anyone | Pays the pool's accrued platform fees to the fee wallet's token accounts. |
claim_pool_creator_fees |
none | The creator | Pays the creator share of a graduated pool. A separate instruction because pool fees accrue in tokens and wrapped SOL. |
Administration#
| Instruction | Arguments | Who | What it does |
|---|---|---|---|
initialize_global |
admin, fee_recipient, params |
The program's upgrade authority, once | Creates the GlobalConfig. |
update_config |
optional fields | Admin | Changes the fee wallet, curve defaults, fees and the migration fee. Fee caps are re-checked every time. Running curves are unaffected. |
set_pause |
three optional booleans | Admin | Sets the pause switches. |
propose_admin, accept_admin |
new_admin |
Admin, then the nominee | Two-step admin transfer. |
Events#
Events are emitted through the program's own event authority, so every instruction that emits has two extra accounts at the end: event_authority and program. Decode them from the transaction's inner instructions, and check the program id and the event authority before trusting one.
| Event | Fields |
|---|---|
TokenCreated |
mint, creator, name, symbol, uri, virtual_sol, virtual_tokens, real_tokens, total_supply, timestamp |
CurveTrade |
mint, trader, is_buy, sol_amount, token_amount, protocol_fee, creator_fee, virtual_sol_after, virtual_tokens_after, real_sol_after, real_tokens_after, timestamp |
CurveCompleted |
mint, timestamp |
Migrated |
mint, pool, sol_amount, token_amount, lp_burned, timestamp |
PoolCreated |
pool, mint_a, mint_b, lp_mint, creator, origin, amount_a, amount_b, lp_minted, timestamp |
LiquidityChanged |
pool, owner, is_add, amount_a, amount_b, lp_amount, reserve_a_after, reserve_b_after, lp_supply_after, timestamp |
PoolSwap |
pool, trader, a_to_b, amount_in, amount_out, lp_fee, protocol_fee, creator_fee, reserve_a_after, reserve_b_after, timestamp |
PoolFeesCollected |
pool, recipient, kind (0 platform, 1 creator), amount_a, amount_b, timestamp |
CreatorFeesClaimed |
creator, lamports, timestamp |
ConfigUpdated |
admin, timestamp |
CurveTrade.sol_amount is the SOL that moved through the reserves excluding fees (for a buy, the SOL added; for a sell, the gross SOL removed). Every trade event carries the reserves after the trade, so an indexer can rebuild price and market cap without reading accounts.
Errors#
| Code | Name | Meaning |
|---|---|---|
| 6000 | Paused |
The switch for this action is on. |
| 6001 | SlippageExceeded |
Your minimum or maximum was not met. |
| 6002 | DeadlineExceeded |
The deadline has passed. |
| 6003 | CurveComplete |
The curve is full. |
| 6004 | CurveNotComplete |
migrate on a curve that is not full. |
| 6005 | AlreadyMigrated |
The curve already moved to its pool. |
| 6006 | MathOverflow |
The amounts are too large to calculate. |
| 6007 | ZeroAmount |
An amount was zero. |
| 6008 | InsufficientLiquidity |
Not enough in the curve or pool. |
| 6009 | FeeTooHigh |
Fees above the caps. |
| 6010 | InvalidMintOrder |
Pool mints were not passed in sorted order. |
| 6011 | UnsupportedMintExtension |
A Token-2022 extension that pools reject. |
| 6012 | MintHasActiveCurve |
A token still on its curve cannot get a pool. |
| 6013 | Unauthorized |
The signer is not allowed. |
| 6014 | NameTooLong |
Name over 32 bytes. |
| 6015 | SymbolTooLong |
Symbol over 10 bytes. |
| 6016 | UriTooLong |
Metadata address over 200 bytes. |
| 6017 | ZeroOutput |
The result would round to nothing. |
| 6018 | InvalidParams |
Invalid configuration values. |
| 6019 | EmptyMetadata |
Name or symbol is empty. |
| 6020 | NoFeesToClaim |
Nothing to claim. |
| 6021 | InvariantViolated |
An internal accounting check failed. |
| 6022 | NoPendingAdmin |
No admin transfer is pending. |
| 6023 | InvalidMigrationMints |
migrate needs exactly the token and wrapped SOL. |
Which tokens pools accept#
- Classic SPL tokens: yes.
- Token-2022 tokens: only those that carry nothing but
MetadataPointer,TokenMetadata,GroupPointer,GroupMemberPointer,TokenGroupandTokenGroupMember. Any other extension (transfer fee, transfer hook, permanent delegate, non-transferable, default-frozen, pausable, confidential transfer and so on) is rejected. This is an allow-list, so new extensions are rejected by default. - Pools can mix the two token programs.
Measured costs#
Compute units, measured against the compiled program:
| Action | Compute units |
|---|---|
sell |
40,000 |
buy / buy_exact_sol_in |
46,000 |
| First trade on a token (also creates the trader's token account and the creator vault) | 75,000 |
claim_creator_fees |
13,000 |
swap / swap_exact_out |
50,000 |
add_liquidity / remove_liquidity |
62,000 / 61,000 |
collect_protocol_fees |
47,000 |
migrate |
90,000 |
create_token |
118,000 |
create_pool |
145,000 |
create_token plus a first buy in one transaction fits in the transaction size limit (811 bytes in tests, against 1,232 allowed). It used about 167,000 compute units on devnet; an earlier estimate from the test environment was about 210,000. Because of that spread, always set a compute limit with some margin. The web app sizes it from a simulation and adds 20%.
Design rules#
- All math is in one shared library: whole numbers, 128-bit intermediate values, checked operations, no floating point on chain.
- Rounding always favors the pool: amounts out are rounded down, amounts in up.
- Every account is checked: seeds, ownership and the expected addresses of vaults.
- No
unwrapin program code. - After editing lamports directly, every cross-program call must include all accounts whose lamports changed, otherwise the runtime fails with
UnbalancedInstruction. (This was found by the tests, inmigrate, and fixed.)