Developers
Program instructions
The seven Socket instructions, their Borsh arguments and their accounts, in order.
Instruction data is Borsh: a one-byte variant index, then the fields in order. Integers are little-endian. The SDK's builders produce exactly these layouts and are the reference when in doubt.
Initialize · 0#
Creates a pool, its vaults and its hook account list, and initializes a built-in hook's state when hook_init is given.
| Field | Type | Notes |
|---|---|---|
nonce | u64 | Any value; part of the pool's address. |
sqrt_price | u128 | Starting Q64.64 square-root price, inside the domain. |
tick_spacing | u16 | 1 to 32,768. |
base_fee_ppm | u32 | At most max_fee_ppm. |
max_fee_ppm | u32 | At most 100,000. |
max_delta_bps | u16 | At most 1,000. Zero for pools without a hook. |
permissions | u16 | Six bits; zero for pools without a hook. |
hook_budget | u64 | Positive for pools with a hook. |
extras | Vec<ExtraMeta> | Up to 8 × { address, owner, writable }. |
hook_init | Vec<u8> | The built-in hooks' Initialize instruction, or empty. |
Accounts: payer (writable, signer) · pool (w) · vault A (w) · vault B (w) · mint A · mint B · hook account list (w) · hook program, or the System Program for none · hook authority · SPL Token · System Program · then the extras.
OpenPosition · 1#
| Field | Type |
|---|---|
nonce | u64 |
lower_tick | i32 |
upper_tick | i32 |
Ticks must be on the pool's spacing and lower < upper. Accounts: owner (w, signer) · pool · position (w) · System Program.
AddLiquidity · 2 and RemoveLiquidity · 3#
| Field | Type | Notes |
|---|---|---|
liquidity | u128 | Positive and at most 2^64 − 1. |
max_a, max_b / min_a, min_b | u64 | Slippage limits on the token amounts. |
Accounts: owner (signer) · pool (w) · position (w) · owner's token A (w) · owner's token B (w) · vault A (w) · vault B (w) · SPL Token · hook account list · hook program · hook authority · then the extras. Both run the liquidity hooks when the pool's mask wires them.
CollectFees · 4#
No fields. Sends a position's owed fees to its owner. Same accounts as the liquidity instructions.
Swap · 5#
| Field | Type | Notes |
|---|---|---|
amount | u64 | Input for exact-in, output for exact-out. |
limit | u128 | Square-root price limit, strictly past the current price in the swap's direction. |
a_to_b | bool | |
exact_in | bool | |
threshold | u64 | Exact-in: minimum out. Exact-out: maximum in, surcharge included. |
max_total_input | u64 | Cap on input plus surcharge. |
Accounts: swapper (signer) · pool (w) · swapper's token A (w) · swapper's token B (w) · vault A (w) · vault B (w) · SPL Token · hook account list · hook program · hook authority · then the extras. See Route through Socket.
Return data: total input, output and fee as three little-endian u64s.
CollectHookFees · 6#
| Field | Type |
|---|---|
amount_a | u64 |
amount_b | u64 |
Pays recorded hook surcharges to the pool's creator, up to what is owed. Accounts: creator (signer) · pool (w) · creator's token A (w) · creator's token B (w) · vault A (w) · vault B (w) · SPL Token.
Built-in hooks program#
| Variant | Index | Called by |
|---|---|---|
Initialize(HookConfig) | 0 | Socket, inside Initialize. |
Callback(HookCall) | 1 | Socket, at each wired hook point. |
CancelOrder | 2 | A range order's owner: pool · owner (signer) · hook state (w). |
Observe { seconds_ago: u32 } | 3 | Anyone, read-only: pool · hook state. |
HookConfig variants: Noop 0, DynamicFee { ewma_weight_ppm, sensitivity_ppm, max_extra_fee_ppm, decay_per_second_ppm } 1, Twap { min_window_seconds } 2, RangeLimitOrder { owner, lower_tick, upper_tick, sell_a } 3.
Listing program#
Each instruction is a Borsh enum variant. The registry is ["registry", creator], a listing ["listing", registry, hook program], and its stake vault ["stake", listing], an SPL Token account owned by the listing.
| Variant | Index | Signed by | Accounts |
|---|---|---|---|
InitRegistry { authority, stake, lock_seconds } | 0 | The creator, once | creator (w) · registry (w) · mint · System Program. The mint must have no mint and no freeze authority. lock_seconds is how long a proposed or removed stake stays locked: on Socket, 604,800 (a vote and its hold-up). |
Propose | 1 | The hook's author | author (w) · registry · listing (w) · stake vault (w) · author's SOCKET account (w) · mint · hook program · SPL Token · System Program. Locks the registry's stake. |
Approve | 2 | The registry authority | authority · registry · listing (w). Proposed → listed. |
Remove { burn: bool } | 3 | The registry authority | authority · registry · listing (w) · stake vault (w) · mint (w) · author (w) · SPL Token. Without burn a proposed or listed hook is marked removed and the stake waits for the author; with burn the stake of a proposed, listed or removed hook is burned and both accounts close to the author. |
Withdraw | 4 | The author | author (w) · registry · listing (w) · stake vault (w) · destination SOCKET account (w) · SPL Token. Proposed or removed only, once lock_seconds have passed since it was proposed or removed; closes both accounts to the author. |
On Socket's deployment the registry authority is the SPL Governance account of Socket's realm, so Approve and Remove run only as the transaction of a passed proposal.