On-Chain Program Reference
Complete mera_core Anchor program reference covering program ID, accounts, PDA seeds, all 11 instructions, and all 8 emit_cpi! events.
mera_core is Mera's Solana Anchor program. It manages protocol configuration, Custom Rings, shielded SPL and Token-2022 vaults, UTXO commitment notes, nullifiers, private escrow limit orders, atomic settlements, and CPI events.
Program identifiers and constants
| Constant | Value |
|---|---|
| Program name | mera_core |
| Program ID | 3w9NcCZK118PzMLmfbS5si5Q5hpA3DMEuYyfVo5fkE1B |
MAX_FEE_BPS | 500 (5.00% maximum protocol fee) |
MAX_RING_NAME | 48 bytes (valid length 2..=48) |
| Anchor event transport | #[event_cpi] / emit_cpi! (inner instruction tag e445a52e51cb9a1d, signer PDA ["__event_authority"]) |
Accounts and PDA seeds
All account sizes below exclude the 8-byte Anchor discriminator (space = 8 + SPACE).
ProtocolConfig
PDA seeds: ["protocol"] (SPACE = 84 bytes, total 92 bytes).
| Field | Type | Description |
|---|---|---|
admin | Pubkey | Authority allowed to call update_protocol_fee |
fee_recipient | Pubkey | Wallet whose ATA receives fee_paid on every settlement |
fee_bps | u16 | Execution fee in basis points (<= 500) |
paused | bool | Halts ring creation, deposits, order placement, and settlements when true |
total_rings | u64 | Count of initialized RingConfig accounts |
total_settlements | u64 | Count of cleared settlements across all Rings |
bump | u8 | Canonical PDA bump |
RingConfig
PDA seeds: ["ring", ring_id_hash] where ring_id_hash = SHA-256(ring_id) (SPACE = 193 bytes, total 201 bytes).
| Field | Type | Description |
|---|---|---|
ring_id_hash | [u8; 32] | 32-byte hash of the Ring identifier |
name | String | Ring display name (2..=48 bytes) |
authority | Pubkey | Wallet allowed to manage RingMember accounts |
auditor_pubkey | Pubkey | Designated auditor public key (Pubkey::default() if none) |
mode | u8 | 0 = Confidential, 1 = Anonymous |
allowlist_enabled | bool | Whether allowlist enforcement is active |
frozen | bool | Blocks deposits, withdrawals, orders, and settlements when true |
is_default | bool | Marks the permissionless Default Ring |
commitment_root | [u8; 32] | Rolling SHA-256 accumulator of all commitments created in the Ring |
commitment_count | u64 | Total commitments appended to commitment_root |
settlement_count | u64 | Total settlements cleared in the Ring |
bump | u8 | Canonical PDA bump |
RingMember
PDA seeds: ["ring_member", ring_config, member_wallet] (SPACE = 67 bytes, total 75 bytes).
| Field | Type | Description |
|---|---|---|
ring | Pubkey | Parent RingConfig PDA |
member | Pubkey | Member wallet public key |
allowed | bool | Whether the wallet is allowlisted in the Ring |
frozen | bool | Whether the wallet is frozen in the Ring |
bump | u8 | Canonical PDA bump |
ShieldedVault
PDA seeds: ["vault", ring_config, mint] (SPACE = 121 bytes, total 129 bytes). Owns the associated token account vault_token_account for (shielded_vault, mint).
| Field | Type | Description |
|---|---|---|
ring | Pubkey | Parent RingConfig PDA |
mint | Pubkey | SPL or Token-2022 mint |
token_account | Pubkey | Vault ATA owned by this PDA |
total_shielded | u64 | Total shielded token base units held in the vault |
total_locked_escrow | u64 | Portion of shielded units currently locked in open PrivateEscrowOrder accounts |
total_fees_collected | u64 | Cumulative protocol fees transferred out to fee_recipient |
bump | u8 | Canonical PDA bump |
CommitmentNote
PDA seeds: ["note", ring_config, commitment] (SPACE = 146 bytes, total 154 bytes).
| Field | Type | Description |
|---|---|---|
ring | Pubkey | Parent RingConfig PDA |
mint | Pubkey | Token mint |
owner | Pubkey | Owner wallet |
commitment | [u8; 32] | 32-byte note commitment |
amount | u64 | Shielded token base units |
spent | bool | Set to true when consumed by withdrawal, escrow placement, or settlement |
created_slot | u64 | Solana slot when created |
bump | u8 | Canonical PDA bump |
NullifierRecord
PDA seeds: ["nullifier", ring_config, nullifier] (SPACE = 73 bytes, total 81 bytes).
| Field | Type | Description |
|---|---|---|
ring | Pubkey | Parent RingConfig PDA |
nullifier | [u8; 32] | Unique 32-byte nullifier |
spent_slot | u64 | Solana slot when spent |
bump | u8 | Canonical PDA bump |
PrivateEscrowOrder
PDA seeds: ["escrow", ring_config, maker, order_id_hash] (SPACE = 250 bytes, total 258 bytes).
| Field | Type | Description |
|---|---|---|
ring | Pubkey | Parent RingConfig PDA |
maker | Pubkey | Order maker wallet |
base_mint | Pubkey | Pair base mint |
quote_mint | Pubkey | Pair quote mint |
escrow_mint | Pubkey | Mint locked in escrow (base_mint for sell, quote_mint for buy) |
side | u8 | 0 = buy, 1 = sell |
limit_price_e6 | u64 | Limit price scaled by 1_000_000 |
size_commitment | [u8; 32] | 32-byte encrypted size commitment |
locked_amount | u64 | Escrowed token base units |
expiry_slot | u64 | Slot after which anyone can expire and refund the order |
status | u8 | 0 = open, 1 = filled, 2 = cancelled by maker, 3 = expired |
input_note | Pubkey | Spent CommitmentNote PDA that funded the escrow |
bump | u8 | Canonical PDA bump |
RfqSettlementRecord
PDA seeds: ["settlement", ring_config, settlement_id_hash] (SPACE = 226 bytes, total 234 bytes).
| Field | Type | Description |
|---|---|---|
ring | Pubkey | Parent RingConfig PDA |
settlement_id_hash | [u8; 32] | 32-byte hash of the settlement ID |
mode | u8 | 0 = swap, 1 = hidden-order fill, 2 = sealed-rfq |
base_mint | Pubkey | Base or input mint |
quote_mint | Pubkey | Quote or output mint |
commitment_hash | [u8; 32] | SHA-256 settlement commitment hash checked by TVK verification |
nullifier_hash | [u8; 32] | Taker input nullifier hash |
tvk_hint | [u8; 16] | First 16 bytes of commitment_hash |
fee_paid | u64 | Protocol fee paid in settlement mint base units |
settled_slot | u64 | Solana slot when settled |
bump | u8 | Canonical PDA bump |
Instructions
| Instruction | Signers | Arguments | State transitions & events |
|---|---|---|---|
init_protocol | admin | fee_bps: u16 | Initializes ProtocolConfig with fee_recipient and fee_bps <= 500. Emits ProtocolInitialized. |
update_protocol_fee | admin | fee_bps: u16, fee_recipient: Pubkey, paused: bool | Updates global fee rate (<= 500), fee recipient, and pause flag. |
create_ring | authority | ring_id_hash: [u8; 32], name: String, mode: u8, allowlist_enabled: bool, is_default: bool, auditor_pubkey: Pubkey | Initializes RingConfig, increments ProtocolConfig.total_rings. Emits RingCreated. |
set_ring_member | authority | allowed: bool, frozen: bool | Creates or updates RingMember for member_wallet (enforces ring_config.authority == authority). Emits RingMemberUpdated. |
deposit_shielded | user | amount: u64, commitment: [u8; 32] | Transfers amount from user_token_account to vault_token_account, initializes ShieldedVault if needed, initializes CommitmentNote, updates commitment_root. Emits ShieldedDeposited. |
withdraw_shielded | user | amount: u64, nullifier: [u8; 32] | Marks commitment_note.spent = true, initializes NullifierRecord, transfers amount from vault_token_account to recipient_token_account, decrements total_shielded. Emits ShieldedWithdrawn. |
place_hidden_order | maker | order_id_hash: [u8; 32], side: u8, limit_price_e6: u64, size_commitment: [u8; 32], amount: u64, nullifier: [u8; 32], expiry_slot: u64 | Spends input_note, creates NullifierRecord, increments escrow_vault.total_locked_escrow, initializes PrivateEscrowOrder. Emits HiddenOrderPlaced. |
cancel_hidden_order | caller | refund_commitment: [u8; 32] | Allowed if caller == escrow.maker (status = 2) or clock.slot >= escrow.expiry_slot (status = 3). Decrements total_locked_escrow, creates refund_note for escrow.maker, updates commitment_root. Emits HiddenOrderCancelled. |
fill_hidden_order | taker | settlement_id_hash: [u8; 32], taker_nullifier: [u8; 32], maker_out_commitment: [u8; 32], taker_out_commitment: [u8; 32], taker_amount: u64, commitment_hash: [u8; 32], tvk_hint: [u8; 16] | Spends taker_input_note, creates taker_nullifier_record, transfers fee_paid from taker_vault to fee_recipient_token_account, marks escrow.status = 1, creates maker_output_note and taker_output_note, initializes RfqSettlementRecord (mode = 1). Emits SettlementCleared. |
settle_confidential_swap | taker, maker | settlement_id_hash: [u8; 32], taker_nullifier: [u8; 32], maker_nullifier: [u8; 32], taker_out_commitment: [u8; 32], maker_out_commitment: [u8; 32], input_amount: u64, output_amount: u64, commitment_hash: [u8; 32], tvk_hint: [u8; 16] | Spends both input notes, creates both nullifiers, transfers fee_paid from output_vault to fee_recipient_token_account, creates output notes for taker (output_amount - fee_paid) and maker (input_amount), initializes RfqSettlementRecord (mode = 0). Emits SettlementCleared. |
settle_sealed_rfq | taker, maker | Same arguments as settle_confidential_swap | Same atomic two-sided settlement with RfqSettlementRecord.mode = 2. Emits SettlementCleared. |
CPI events
All 8 events are emitted via emit_cpi! so they survive Solana's 10,000-byte transaction log limit:
| Event | Fields |
|---|---|
ProtocolInitialized | admin, fee_recipient, fee_bps |
RingCreated | ring, ring_id_hash, authority, mode, allowlist_enabled, auditor_pubkey |
RingMemberUpdated | ring, member, allowed, frozen |
ShieldedDeposited | ring, mint, owner, commitment, slot |
ShieldedWithdrawn | ring, mint, owner, nullifier, slot |
HiddenOrderPlaced | ring, order, order_id_hash, side, limit_price_e6, size_commitment, expiry_slot, slot |
HiddenOrderCancelled | ring, order, status, refund_commitment, slot |
SettlementCleared | ring, settlement, settlement_id_hash, mode, commitment_hash, tvk_hint, fee_paid, slot |
For every MeraError code (6000 through 6014), see Error Codes.