Docs

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.

FieldTypeNotes
nonceu64Any value; part of the pool's address.
sqrt_priceu128Starting Q64.64 square-root price, inside the domain.
tick_spacingu161 to 32,768.
base_fee_ppmu32At most max_fee_ppm.
max_fee_ppmu32At most 100,000.
max_delta_bpsu16At most 1,000. Zero for pools without a hook.
permissionsu16Six bits; zero for pools without a hook.
hook_budgetu64Positive for pools with a hook.
extrasVec<ExtraMeta>Up to 8 × { address, owner, writable }.
hook_initVec<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#

FieldType
nonceu64
lower_ticki32
upper_ticki32

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#

FieldTypeNotes
liquidityu128Positive and at most 2^64 − 1.
max_a, max_b / min_a, min_bu64Slippage 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#

FieldTypeNotes
amountu64Input for exact-in, output for exact-out.
limitu128Square-root price limit, strictly past the current price in the swap's direction.
a_to_bbool
exact_inbool
thresholdu64Exact-in: minimum out. Exact-out: maximum in, surcharge included.
max_total_inputu64Cap 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#

FieldType
amount_au64
amount_bu64

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#

VariantIndexCalled by
Initialize(HookConfig)0Socket, inside Initialize.
Callback(HookCall)1Socket, at each wired hook point.
CancelOrder2A range order's owner: pool · owner (signer) · hook state (w).
Observe { seconds_ago: u32 }3Anyone, 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.

VariantIndexSigned byAccounts
InitRegistry { authority, stake, lock_seconds }0The creator, oncecreator (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).
Propose1The hook's authorauthor (w) · registry · listing (w) · stake vault (w) · author's SOCKET account (w) · mint · hook program · SPL Token · System Program. Locks the registry's stake.
Approve2The registry authorityauthority · registry · listing (w). Proposed → listed.
Remove { burn: bool }3The registry authorityauthority · 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.
Withdraw4The authorauthor (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.