API reference

All instructions of programs/squeeth. Accounts are listed in order. mut means writable, signer means it must sign.

init_market(funding_period: i64, twap_window: i64)

Creates the market, the power mint and the pool token account. Only the program upgrade authority.

AccountNotes
payermut, signer, must be the upgrade authority
marketinit, ["market"]
power_mintinit, ["power"], 9 decimals, authority = market
pool_tokensinit, ["pool_tokens"]
program, program_dataused to read the upgrade authority
token_program, system_program, rent

Bounds: funding_period 60 to 7,776,000 seconds, twap_window 5 to 3,600 seconds, else BadParams.

open_vault()

AccountNotes
ownermut, signer
vaultinit, ["vault", owner]
system_program

deposit(lamports: u64)

Moves SOL from owner to the vault. Accounts: owner (mut, signer), vault (mut, owned by owner), system_program.

mint_power(amount: u64)

Reads the price, applies funding, adds amount to the debt, requires 150% or more, mints to owner_tokens.

AccountNotes
ownersigner
marketmut
vaultmut, owned by owner
oraclethe Pyth SOL/USD account
power_mintmut
owner_tokensmut, token account of the power mint
token_program

burn_power(amount: u64)

Repays amount of debt by burning the owner's tokens. No price needed. Accounts: owner (signer), market (mut), vault (mut), power_mint (mut), owner_tokens (mut, authority = owner), token_program.

withdraw(lamports: u64)

Takes SOL out of the vault. If debt remains, reads the price, applies funding and requires 150% or more afterwards. Accounts: owner (mut, signer), market (mut), vault (mut), oracle.

liquidate(amount: u64)

Anyone. The vault must be under 150%. amount is at most half the debt (all of it at 0.001 token or less). Burns the liquidator's tokens, pays debt_value(amount) × 1.10 in SOL, capped at the collateral.

AccountNotes
liquidatormut, signer
marketmut
vaultmut, any owner
oraclethe Pyth SOL/USD account
power_mintmut
liquidator_tokensmut, authority = liquidator
token_program

open_lp(), add_liquidity(lamports: u64, max_tokens: u64), remove_liquidity(shares: u64)

open_lp creates ["lp", owner]. add_liquidity deposits SOL and up to max_tokens at the pool ratio (the first deposit sets it) and mints shares. remove_liquidity returns the share of both reserves.

buy(lamports_in: u64, min_out: u64), sell(tokens_in: u64, min_out: u64)

Constant product swap with a 0.3% fee against the pool. Refuses an empty pool (EmptyPool) and any output under min_out (Slippage).

AccountNotes
tradermut, signer
marketmut
trader_tokensmut, token account of the power mint
pool_tokensmut
token_program, system_program

poke()

Anyone. Reads the price and applies funding. Accounts: market (mut), oracle.

init_test_oracle(), set_test_price(price_e8: i64, conf_e8: u64)

Local tests only. In the mainnet build they always fail with Disabled, and the price reader accepts only Pyth.

Next: Errors