Contract Reference
Complete public interface documentation for all four Writz Soroban contracts. Testnet addresses:| Contract | Address |
|---|---|
bitcoin-spv | CAE5L7BO2GNF7MIZWXB2BTUMLYNIMQZUSWN2BWLZQS7HRHLOUSL6VLWJ |
zk-verifier | CDV45GLXG4AOU6BDZSY5YHHVNGQIAYAPD3PUGXIIIYLIO6V2XGO6SMFV |
commitment-tree | CDFAP3J4WLFZC2N5U66X5EO62POBBIBXOKCCMCM3IRLJNXT73C4IBKA7 |
private-lend | CCLH2GJYG3QSHZJI7V7VK3DNMNK3I3QJCECBSFGX3AC6CK4I7EF7ZJ2G |
bitcoin-spv
verify_transaction
Verifies that a Bitcoin transaction is included in a confirmed block. Stateless — no headers are stored on-chain.
- 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.
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.
DepositVerified { txid: BytesN<32>, commitment: BytesN<32> }
insert_commitment
Inserts the next pending commitment into the Poseidon Merkle tree. Admin only in Phase 1.
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.
Borrowed { nullifier: BytesN<32>, new_commitment: BytesN<32>, amount: i128 }
repay
Repays outstanding USDC debt (full or partial).
Repaid { nullifier: BytesN<32>, new_commitment: BytesN<32>, amount: i128 }
liquidate
Liquidates an undercollateralized position. The usdc_debt amount is extracted from the proof.
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.
| Event | Contract | Fields |
|---|---|---|
DepositVerified | commitment-tree | txid, commitment |
CommitmentInserted | commitment-tree | commitment, root, index |
Borrowed | commitment-tree | nullifier, new_commitment, amount |
Repaid | commitment-tree | nullifier, new_commitment, amount |
Liquidated | commitment-tree | nullifier, usdc_debt |
UsdcSupplied | commitment-tree | supplier, amount |
UsdcWithdrawn | commitment-tree | supplier, amount |
DepositCreated | private-lend | depositor, position_id, btc_amount_sats |
Borrowed | private-lend | position_id, amount |
Repaid | private-lend | position_id, amount |
Liquidated | private-lend | position_id, usdc_amount |