Integrate permissionless swaps
Tribe's native AMM is open to any Solana client. Submit the swap instruction directly to the onchain program. Anyone can sell from launch; permissionless buys open when the token reaches the onchain threshold or age gate described under Launch protection.
Mainnet program: B1x53qgNmAdZMfPVZvu89qDmNn3RpdKajRFXqCzE7UPU
Everything needed to discover a market, read a quote, build a buy or sell, and attribute a referral is available onchain. The guides use Anchor, Solana web3.js, Token-2022 helpers, and the swap IDL.
AI agents can read this page as raw Markdown, start from the documentation index, or load all documentation in one text file.
Earn from every referred swap
Set your own Solana wallet as referral when you build the swap instruction. The program pays your share to that wallet inside the same transaction. The referral wallet does not sign, and there is nothing to claim.
Every integration starts at the same default tier: 15% of Tribe's protocol fee on each attributed swap. At the common under-10k-SOL market-cap fee tier, when no real LP liquidity is present, this is approximately 0.30% of the trade's SOL side. The exact payout changes with the token's live fee tier and LP share because the referral is a share of the protocol fee, not a fixed percentage of trade volume.
Integrations that demonstrate good trading volume through their clients can receive a higher onchain tier for their referral wallet. Everyone starts at 15%, and upgrades are performance-based. The integration instructions will be updated when higher tiers are assigned.
To attribute a swap:
- Pass your payout wallet as
referral. It must differ from the trader. Prefund it once and keep it at or above the rent-exempt minimum. - Set
referrer_tier_accounttoprotocol_vault. The instruction requires this account slot, andprotocol_vaulttells the program to apply the default 15% tier. You do not need a separate tier account for the default tier. - Read the
SwapCompletedevent or the wallet's SOL balance change to reconcile the payout. Referral rewards are paid automatically by the program.
The current starting referral rate is 15% of Tribe's protocol fee. The docs will be updated if the starting rate changes.
Choose a path
| Goal | Start here |
|---|---|
| Resolve a mint and read live quote inputs | Read market state onchain |
| Build the shared transaction and wallet-signing layer | Build a swap transaction |
| Add an exact-input buy or sell | Build TypeScript swap flows |
| Generate a client in another language | Use the swap IDL and account table below |
| Add Tribe as an aggregator route | Index Token accounts, cache confirmed state, implement the quote math, and submit the same swap |
Swap contract
The integration surface is intentionally narrow: one instruction, its argument type, and the state decoders required to resolve swap accounts and calculate current fees and quotes. The inline IDL excludes launch, admin, privileged referral, LP, and protocol-management instructions.
The swap IDL is embedded below so a person or AI agent can read the exact instruction, account order, discriminators, and required state layouts directly from this page. Use the Copy IDL button to copy it as JSON.
What the swap IDL contains
| Section | Why it is necessary |
|---|---|
address and metadata | Pin the mainnet program and identify the Anchor schema and program version for compatible tooling. Metadata grants no extra capability. |
swap instruction | Its discriminator selects the permissionless handler, while its 17 account metas define signer, writable, PDA, and fixed-program requirements. |
SwapArgs | Defines the exact Borsh layout for amount, slippage limit, buy or sell direction, and ExactIn or ExactOut mode. |
| Account discriminators | The two eight-byte tags let a client prove it is decoding the expected Token or FeeTierConfig state. |
Token | Provides the onchain token ID, mint, creator, selected fee tier, curve state, reserves, and launch state used to validate the market and calculate a quote. |
FeeTierConfig and Breakpoint | Define the live fee schedule selected by the Token account. Breakpoint is present because FeeTierConfig contains an array of that nested type. |
Each included account struct is complete because standard IDL decoders deserialize fields in order. Removing an apparently unused field, padding, or reserved bytes would shift later offsets or make the decoder reject valid onchain state. Instructions, accounts, events, and errors unrelated to a swap remain omitted.
The protocol account appears in the instruction's account list because every swap must pass that PDA to the program. Its internal fields are not in the swap IDL because an integration neither decodes nor changes them to discover a market, calculate a quote, or build the instruction.
Swap IDL (inline)
{
"address": "B1x53qgNmAdZMfPVZvu89qDmNn3RpdKajRFXqCzE7UPU",
"metadata": {
"name": "tribe_amm",
"version": "0.5.0",
"spec": "0.1.0",
"description": "Tribe AMM"
},
"instructions": [
{
"name": "swap",
"discriminator": [
248,
198,
158,
145,
225,
117,
135,
200
],
"accounts": [
{
"name": "trader",
"writable": true,
"signer": true
},
{
"name": "protocol",
"pda": {
"seeds": [
{
"kind": "const",
"value": [
112,
114,
111,
116,
111,
99,
111,
108
]
}
]
}
},
{
"name": "token",
"writable": true
},
{
"name": "mint"
},
{
"name": "sol_vault",
"writable": true
},
{
"name": "token_vault",
"writable": true
},
{
"name": "pool_authority"
},
{
"name": "trader_token_account",
"writable": true
},
{
"name": "creator",
"writable": true
},
{
"name": "protocol_vault",
"writable": true
},
{
"name": "fee_tier_config"
},
{
"name": "token_2022_program",
"address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
},
{
"name": "event_authority"
},
{
"name": "program"
},
{
"name": "referral",
"writable": true
},
{
"name": "referrer_tier_account"
}
],
"args": [
{
"name": "_args",
"type": {
"defined": {
"name": "SwapArgs"
}
}
}
]
}
],
"accounts": [
{
"name": "FeeTierConfig",
"discriminator": [
9,
18,
93,
9,
32,
89,
131,
0
]
},
{
"name": "Token",
"discriminator": [
131,
254,
39,
144,
4,
179,
134,
127
]
}
],
"types": [
{
"name": "Breakpoint",
"type": {
"kind": "struct",
"fields": [
{
"name": "sqrt_price",
"type": "u128"
},
{
"name": "total_fee_rate",
"type": "u32"
},
{
"name": "creator_fee_rate",
"type": "u32"
},
{
"name": "lp_fee_rate",
"type": "u32"
},
{
"name": "_reserved",
"type": {
"array": [
"u8",
4
]
}
}
]
}
},
{
"name": "FeeTierConfig",
"type": {
"kind": "struct",
"fields": [
{
"name": "index",
"type": "u64"
},
{
"name": "start_total_fee_rate",
"type": "u32"
},
{
"name": "start_creator_fee_rate",
"type": "u32"
},
{
"name": "start_lp_fee_rate",
"type": "u32"
},
{
"name": "active_breakpoint_count",
"type": "u8"
},
{
"name": "_padding",
"type": {
"array": [
"u8",
3
]
}
},
{
"name": "breakpoints",
"type": {
"array": [
{
"defined": {
"name": "Breakpoint"
}
},
15
]
}
},
{
"name": "_reserved",
"type": {
"array": [
"u8",
64
]
}
}
]
}
},
{
"name": "SwapArgs",
"type": {
"kind": "struct",
"fields": [
{
"name": "amount",
"type": "u64"
},
{
"name": "limit",
"type": "u64"
},
{
"name": "is_buy",
"type": "bool"
},
{
"name": "swap_mode",
"type": "u8"
}
]
}
},
{
"name": "Token",
"type": {
"kind": "struct",
"fields": [
{
"name": "token_id",
"type": "u64"
},
{
"name": "creator",
"type": "pubkey"
},
{
"name": "mint",
"type": "pubkey"
},
{
"name": "sqrt_price_x64",
"type": "u128"
},
{
"name": "liquidity",
"type": "u128"
},
{
"name": "virtual_liquidity",
"type": "u128"
},
{
"name": "created_at",
"type": "i64"
},
{
"name": "paused",
"type": "bool"
},
{
"name": "bump",
"type": "u8"
},
{
"name": "sol_vault_bump",
"type": "u8"
},
{
"name": "token_vault_bump",
"type": "u8"
},
{
"name": "lp_liquidity",
"type": "u128"
},
{
"name": "fee_growth_global_sol",
"type": {
"array": [
"u8",
32
]
}
},
{
"name": "virtual_token_amount",
"type": "u64"
},
{
"name": "lp_fee_reserved_sol",
"type": "u64"
},
{
"name": "lp_position_count",
"type": "u64"
},
{
"name": "fee_tier",
"type": "pubkey"
},
{
"name": "anti_snipe_until",
"type": "i64"
},
{
"name": "anti_snipe_start_rate",
"type": "u32"
},
{
"name": "permissionless_buy_unlocked",
"type": "bool"
},
{
"name": "_reserved",
"type": {
"array": [
"u8",
115
]
}
}
]
}
}
]
}Swap arguments
| Argument | Type | Meaning |
|---|---|---|
amount | u64 | Input amount for ExactIn; desired output amount for ExactOut. |
limit | u64 | Minimum output for ExactIn; maximum input for ExactOut. |
is_buy | bool | true for SOL to token; false for token to SOL. |
swap_mode | u8 | 0 for ExactIn; 1 for ExactOut. |
Account map
- Start with the token mint. Resolve its Token account and onchain token ID using the filtered account lookup.
- Derive every PDA from the seed table. Use the trader's Token-2022 associated token account for the mint.
- For no referral, pass
protocol_vaultas bothreferralandreferrer_tier_account. For attribution, pass your prefunded payout wallet asreferralandprotocol_vaultasreferrer_tier_account. Self-referral is rejected. - Decode the Token account and its
FeeTierConfigfrom fresh confirmed state before computingamountandlimit. Add a compute-unit limit and priority fee, then simulate before asking the wallet to sign.
| PDA account | Seeds in order | Expected owner |
|---|---|---|
protocol | "protocol" | Tribe program |
protocol_vault | "protocol_vault" | System Program |
token | "token", token_id (u64 LE) | Tribe program |
sol_vault | "sol_vault", token_id (u64 LE) | System Program |
token_vault | "token_vault", mint, token | Token-2022 |
fee_tier_config | "fee_tier", index (u64 LE) | Tribe program |
pool_authority | "pool_authority" | Address-only PDA |
event_authority | "__event_authority" | Address-only PDA |
Pass the Token account's creator and fee_tier keys directly. Pass the Token-2022 program, System Program, Tribe program, mint, trader, trader token account, and derived accounts in the order declared by the swap IDL.
Safety checklist
- Validate each account by role: Tribe state is owned by the Tribe program, token accounts are Token-2022-owned, SOL vaults are System-owned, and address-only PDAs are checked by derivation rather than owner. Verify the mint and executable program IDs separately.
- Read and simulate with
confirmedcommitment; refresh the quote before asking the wallet to sign. - Never use zero as a convenience slippage limit. Reject stale quotes and surface simulation errors.
- Always configure a compute-unit limit and a nonzero, current priority fee before submission.
- Treat Token-2022 as required. A legacy SPL Token associated account is not interchangeable.
- The permissionless instruction is
swap. The separate privileged referral path requires a Tribe admin signature and is not an integration surface.