Skip to main content

Contract Reference

Complete public interface documentation for all four Writz Soroban contracts. Testnet addresses:

bitcoin-spv

verify_transaction

Verifies that a Bitcoin transaction is included in a confirmed block. Stateless — no headers are stored on-chain.
Returns:
Panics if:
  • Any header fails PoW validation (SHA256d(header) ≥ target)
  • The header chain is not continuous (headers[i].prev_block ≠ SHA256d(headers[i-1]))
  • The Merkle proof does not reconstruct headers[0].merkle_root
  • headers.len() < min_confirmations

zk-verifier

initialize

Sets the admin address and initializes the contract. Call once after deployment.

set_vkey

Stores a Groth16 verification key for a circuit type. Admin only.

verify_groth16

Verifies a Groth16 BN254 proof against a stored verification key.
Returns: true if the proof is valid. false if the pairing check fails. Transaction panics (host rejects) if the proof contains invalid curve points.

commitment-tree

initialize

deposit

Verifies a Bitcoin deposit (via SPV) and a ZK deposit proof, then queues a commitment for insertion.
Emits: DepositVerified { txid: BytesN<32>, commitment: BytesN<32> }

insert_commitment

Inserts the next pending commitment into the Poseidon Merkle tree. Admin only in Phase 1.
Emits: CommitmentInserted { commitment: BytesN<32>, root: BytesN<32>, index: u32 }

borrow

Issues a USDC loan. Amount is extracted from the ZK proof — not supplied by the caller.
Emits: Borrowed { nullifier: BytesN<32>, new_commitment: BytesN<32>, amount: i128 }

repay

Repays outstanding USDC debt (full or partial).
Emits: Repaid { nullifier: BytesN<32>, new_commitment: BytesN<32>, amount: i128 }

liquidate

Liquidates an undercollateralized position. The usdc_debt amount is extracted from the proof.
Emits: Liquidated { nullifier: BytesN<32>, usdc_debt: i128 }

supply_usdc

Supplies USDC to the lending pool.

withdraw_supply

Withdraws USDC from the lending pool.

get_merkle_root

Returns the current Poseidon Merkle root.

TTL Refresh Functions (permissionless)


private-lend

initialize

deposit

borrow

repay

liquidate

Keeper-only in Phase 1.

get_position


Events Reference

All events use Soroban’s #[contractevent] annotation and are emitted in the transaction ledger.