Program
Instructions
Every instruction with its accounts, arguments, errors and event.
Every instruction with its accounts in order, its arguments, the program errors it raises and the event it emits. Amounts are USDC base units (6 decimals). A PDA's seeds are listed as text constants and account names.
deposit
Moves USDC from the owner's token account into the vault and adds it to the trader account's deposited total, creating the trader account on the first deposit.
| Field | Type | Description |
|---|---|---|
owner | signer, writable | The trader wallet. |
config | read | PDA ["config"] |
trader | writable | PDA ["trader", owner] |
source | writable | The owner's USDC token account. |
vault | writable | The program-owned USDC vault, config.vault. |
token_program | read | SPL Token. TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA |
system_program | read | System program. 11111111111111111111111111111111 |
event_authority | read | Anchor event authority PDA ["__event_authority"], for events emitted by CPI. |
program | read | This program. |
| Field | Type | Description |
|---|---|---|
amount | u64 | USDC base units (6 decimals). Above zero. |
Raises: ZeroAmount, MathOverflow. Emits DepositMade. Discriminator f223c68952e1f2b6.
escape_withdraw
Once more than escape_slots slots have passed since the last batch landed, pays the owner their available equity (at most what the vault holds beyond unswept fees) and closes the trader account to the owner. No sequencer signature.
| Field | Type | Description |
|---|---|---|
owner | signer, writable | The trader wallet. |
config | read | PDA ["config"] |
trader | writable | PDA ["trader", owner] |
vault | writable | The program-owned USDC vault, config.vault. |
destination | writable | The owner's USDC token account. |
token_program | read | SPL Token. TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA |
event_authority | read | Anchor event authority PDA ["__event_authority"], for events emitted by CPI. |
program | read | This program. |
Raises: EscapeNotOpen, MathOverflow. Emits Escaped. Discriminator 387f1fcd723094e4.
initialize
Creates the config and the USDC vault, and sets the escape window, the sequencer and the fee recipient. The signer becomes the admin.
| Field | Type | Description |
|---|---|---|
admin | signer, writable | The config admin. |
config | writable | PDA ["config"] |
usdc_mint | read | The USDC mint, a classic SPL Token mint (Token-2022 is refused). |
vault | writable | The program-owned USDC vault, config.vault. PDA ["vault"] |
token_program | read | SPL Token. TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA |
system_program | read | System program. 11111111111111111111111111111111 |
| Field | Type | Description |
|---|---|---|
escape_slots | u64 | Slots without a batch before escape_withdraw opens. Above zero. |
sequencer | pubkey | The engine key that posts batches and co-signs withdrawals. |
fee_recipient | pubkey | The wallet whose USDC associated token account receives swept protocol fees. |
Raises: InvalidEscapeSlots. Emits no event. Discriminator afaf6d1f0d989bed.
post_batch
Posts settlement batch number last + 1: the state hash, the cumulative protocol fees, and one entry per trader account passed as writable remaining accounts, in entry order. Each entry sets the settled equity and how much of the deposits and withdrawals the engine had credited.
| Field | Type | Description |
|---|---|---|
sequencer | signer | The engine's key, matched against config.sequencer. |
config | writable | PDA ["config"] |
event_authority | read | Anchor event authority PDA ["__event_authority"], for events emitted by CPI. |
program | read | This program. |
| Field | Type | Description |
|---|---|---|
batch_number | u64 | Exactly the last batch number plus one. |
state_hash | [u8; 32] | SHA-256 of the engine's whole state after the batch. |
fees_total | u64 | Cumulative protocol fees, in USDC base units. Never lower than the last batch reported. |
entries | Vec<BatchEntry> | One per trader account in the remaining accounts, in the same order. |
| Field | Type | Description |
|---|---|---|
settled_equity | u64 | The account's equity at the batch, floored at zero. |
deposits_credited | u64 | How much of Trader.deposited the engine had credited at the batch. |
withdrawals_credited | u64 | How much of Trader.withdrawn the engine had credited at the batch. |
Raises: NotSequencer, BatchOutOfOrder, FeesDecreased, EntryCountMismatch, InvalidTraderAccount, TraderAlreadyInBatch, CreditExceedsDeposits, CreditExceedsWithdrawals, MathOverflow. Emits BatchPosted. Discriminator ac7bea660ed54c24.
register_session
Records a session key and its expiry in the trader account, creating the account if needed. The default (all-zero) key revokes and sets the expiry to 0.
| Field | Type | Description |
|---|---|---|
owner | signer, writable | The trader wallet. |
trader | writable | PDA ["trader", owner] |
system_program | read | System program. 11111111111111111111111111111111 |
event_authority | read | Anchor event authority PDA ["__event_authority"], for events emitted by CPI. |
program | read | This program. |
| Field | Type | Description |
|---|---|---|
session_key | pubkey | The session key; the default key revokes. |
expiry | i64 | Unix seconds. |
Raises: no program errors. Emits SessionRegistered. Discriminator 65746a2b98bd046e.
sweep_fees
Pays every reported, unswept protocol fee from the vault to the fee recipient's USDC associated token account. Anyone can send it.
| Field | Type | Description |
|---|---|---|
config | writable | PDA ["config"] |
vault | writable | The program-owned USDC vault, config.vault. |
fee_destination | writable | associated token account of config.fee_recipient |
token_program | read | SPL Token. TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA |
event_authority | read | Anchor event authority PDA ["__event_authority"], for events emitted by CPI. |
program | read | This program. |
Raises: NothingToSweep, MathOverflow. Emits FeesSwept. Discriminator afe1624776422294.
update_config
Replaces the sequencer and the fee recipient. Admin only.
| Field | Type | Description |
|---|---|---|
admin | signer | The config admin. |
config | writable | PDA ["config"] |
| Field | Type | Description |
|---|---|---|
sequencer | pubkey | The new sequencer. |
fee_recipient | pubkey | The new fee recipient. |
Raises: NotAdmin. Emits no event. Discriminator 1d9efcbf0a53db63.
withdraw
Pays an amount up to the trader's available equity from the vault to the owner's token account. Signed by the owner and co-signed by the sequencer.
| Field | Type | Description |
|---|---|---|
owner | signer | The trader wallet. |
sequencer | signer | The engine's key, matched against config.sequencer. |
config | read | PDA ["config"] |
trader | writable | PDA ["trader", owner] |
vault | writable | The program-owned USDC vault, config.vault. |
destination | writable | The owner's USDC token account. |
token_program | read | SPL Token. TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA |
event_authority | read | Anchor event authority PDA ["__event_authority"], for events emitted by CPI. |
program | read | This program. |
| Field | Type | Description |
|---|---|---|
amount | u64 | USDC base units. Above zero and at most the available equity. |
Raises: NotSequencer, ZeroAmount, InsufficientEquity, MathOverflow. Emits Withdrawn. Discriminator b712469c946da122.