Skip to content
WritzProtocolPublic

About

Bitcoin lending on Stellar. Native BTC stays on Bitcoin, verified by an on-chain light client on Soroban, and borrowers receive USDC. No bridge, no custodian, no wrapped tokens.

Topics

Resources

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Repository files navigation

Writz

Bitcoin was built to be yours. Your loans should be too.

Borrow USDC on Stellar without selling your Bitcoin. Your BTC never leaves the Bitcoin network.
No bridge. No custodian. No wrapped tokens.

CI Network: Stellar testnet npm: @writz/sdk crates.io: writz-spv-client License: Apache 2.0

Borrow on testnet  ·  Lend on testnet  ·  Build with the SPV SDK
Testnet app  ·  Documentation  ·  Website  ·  Discord  ·  X

Important

Status: testnet only. Writz runs on Stellar testnet with Bitcoin Signet coins. It has not been externally audited, and no Writz contract is deployed on Stellar mainnet. Mainnet is planned for Q2 to Q3 2027. Do not send real funds.


Writz is a Bitcoin lending protocol on Stellar where the collateral never leaves Bitcoin. Lock native BTC directly from your Bitcoin wallet, borrow USDC on Stellar, and, if Writz ever disappears, take the BTC back alone once the timelock chosen at deposit has passed.

The BTC sits in a Bitcoin script that the borrower and the protocol can only spend from together, and that the borrower can spend from alone after the timelock. A Bitcoin light client written as a Soroban contract verifies the deposit on Stellar with proof-of-work and a Merkle proof, against a header chain anchored to a public checkpoint, so no oracle, bridge or federation attests to the deposit. USDC lenders fund the pool and earn the interest borrowers pay.

Contents


The problem

Borrowing against Bitcoin in DeFi almost always means handing it to someone else first. Wrapped BTC such as WBTC is backed by coins held by custodians. Threshold networks such as tBTC, and pegs such as Stacks sBTC, rely on a signer set that could move the coins if enough members acted together. The alternative is to sell the BTC or bridge it to another chain, which adds bridge contracts, peg mechanisms and the custody behind them.

Writz is built for holders who will not give up custody or trust a bridge in order to borrow. Read more in The problem.

How Writz solves it

Writz Custodial lenders and wrapped-BTC protocols
Who holds the BTC A Bitcoin script; neither Writz nor the borrower can move it alone before the timelock A custodian or a signer set
What the collateral is Native BTC on the Bitcoin chain A wrapped token (WBTC, tBTC and similar)
How the deposit is proven Bitcoin light client on Soroban: proof-of-work, difficulty and Merkle inclusion The issuer or bridge attests to it
If the protocol disappears CLTV timelock: the borrower reclaims the BTC alone after it passes Depends on the protocol or custodian staying available

Babylon's Trustless Bitcoin Vaults, approved in November 2026 as collateral for Aave V4, also keep BTC on Bitcoin, with a different design: Bitcoin checks a proof of the lending chain's state through garbled circuits and a closed set of challengers, where Writz has Stellar check Bitcoin through a light client. See the comparison.

Stellar is the execution layer because Circle issues USDC natively there, neither bridged nor wrapped, and Soroban's compute budget fits a full Bitcoin header light client written in Rust. Read more in Why Stellar, why now.


What you trust today

Writz removes the custodian, not every assumption. This is what each party can and cannot do on the current testnet deployment, as enforced by the contracts.

Party Can Cannot
Protocol co-signing key (Bitcoin) Refuse to co-sign a release, so the borrower waits for the timelock. A deposit's timelock can be up to 105,000 blocks (about two years) after it confirms Move BTC without the borrower's key
Relayer (Stellar account) Submit Bitcoin headers (the only submitter on testnet); co-sign and publish the release transaction. The rule "release only after full repayment" is enforced by the relayer, not by the contract Move BTC without the borrower's key; rewrite stored headers
writz-lend admin Change the price source, the bitcoin-spv address, the keeper, the relayer, the borrow cap and other limits; pause new loans. Changes take effect immediately Change contract code (there is no upgrade path); move BTC
bitcoin-spv admin Set the checkpoint once at deployment; choose the header submitter and which lending contracts may consume deposits Rewrite stored headers or the checkpoint once set
  • Signet headers are trusted. Signet blocks are authenticated by a signature the contract does not verify, so on testnet the header source is the Writz relayer. On mainnet, proof-of-work at real difficulty is the security and header submission can be open to anyone.
  • The relayer is a liveness dependency. If no header arrives for 6 hours, new borrows and liquidations pause, and a repaid loan's release waits for the relayer. The BTC is never stuck: after the timelock the borrower spends it alone.
  • Liquidation moves no BTC today. A liquidator repays the debt and receives a bonus in USDC; the BTC stays in its script until the timelock. Debt that nobody liquidates is a lender risk, limited today by a 50,000 USDC total borrow cap that the admin can change.

Planned before mainnet: Bitcoin transactions the borrower pre-signs at deposit to settle a default on Bitcoin, a 2-of-3 protocol signer set, 2-of-3 admin accounts, several independent relayers with open submission, a second price source (RedStone) and an external audit. The full analysis is in the Security model and SPV vs wrapped Bitcoin.


Status

Both protocol contracts are live on Stellar testnet, and Bitcoin Signet deposits have been verified on chain.

What Status
Bitcoin SPV verification on Soroban Live on testnet
writz-lend deposit, borrow, repay and release PSBT Live on testnet
P2WSH locking and co-signed BTC release Broadcast on Bitcoin Signet
USDC lenders earn the interest borrowers pay (evidence) Live on testnet
Receive the loan as EURC or PYUSD (Soroswap) or as USDC on Base Sepolia (Circle CCTP V2) Live on testnet

The project started as a whitepaper (v1.0, July 2026, DOI 10.5281/zenodo.23148520). The current design supersedes it in places; the technical architecture is the reference, and sets out what is live and what is designed.

Live testnet contracts

Contract Address WASM
bitcoin-spv CCCQXNWQGLAAVGOB7YCZNWNHIC456LZXML55Z65OOXRTAZ5BIPNIZ3HB 51.8 KB
writz-lend CBI4AGULYDCCNYHKAC5HBCIF7X3YEZCYFXLYVLQWUOKPLXWO7LJCKG4Q 96.5 KB

Any other bitcoin-spv or writz-lend ID is superseded. The contracts have been redeployed several times on testnet; the full history, init transactions and verified calls are in contracts/deployments/testnet.md, and the machine-readable IDs in testnet.json.


System architecture

Writz system architecture: Bitcoin custody layer, relayer services, Soroban contracts and the browser wallets

The diagrams show the protocol as designed; what runs on testnet today and what is planned before mainnet are in the technical architecture.

The protocol operates across two blockchains. Bitcoin is the custody layer: BTC never leaves the Bitcoin network. Stellar is the execution layer: SPV verification, loan logic and USDC flows run on Soroban.

  1. Bitcoin network. The user's BTC wallet locks funds into a P2WSH script with two spending conditions.
  2. Backend services. An SPV relayer watches Bitcoin blocks, submits their headers to the bitcoin-spv light client and assembles transaction proofs against them; a repay watcher co-signs the release PSBT once a loan is fully repaid.
  3. Soroban contracts. bitcoin-spv verifies Bitcoin transactions cryptographically; writz-lend registers deposits and issues, accrues and settles USDC loans.
  4. Browser. Keys stay on the user's device. The Bitcoin wallet signs the key-control proof and the release transaction; the Stellar wallet signs Soroban transactions.

Positions, amounts and collateral are public on chain, like any other lending market.


Loan lifecycle

1. Deposit and borrow

Deposit flow: BTC locked in P2WSH, proof assembled by the relayer, verified by bitcoin-spv, USDC borrowed from writz-lend
  1. The user connects a Bitcoin wallet (Xverse) and a Stellar wallet (Varial, formerly Freighter, or xBull, Lobstr, Albedo, Rabet). On testnet, an email or social sign-in with a Signet test key kept in the browser replaces both.
  2. The frontend derives a unique P2WSH address for this deposit from the user public key, the protocol public key and the timelock.
  3. The user sends BTC to that address on Bitcoin.
  4. After the required confirmations (1 on testnet, 6 planned for mainnet), the SPV relayer assembles a proof bundle: raw transaction, block headers and Merkle inclusion path.
  5. The user signs a key-control message with the Bitcoin key in the script, and calls writz-lend.deposit with the proof bundle and the signature.
  6. writz-lend rebuilds the expected P2WSH script, asks bitcoin-spv to verify the transaction's inclusion and confirmations against its stored header chain, and records the position.
  7. The user borrows USDC from the writz-lend pool while keeping a collateral ratio of at least 150% (debt up to about two thirds of the BTC value), and can keep the USDC, swap it through Soroswap (EURC, PYUSD), or send it as native USDC to Base Sepolia with Circle CCTP V2.

2. Repay and liquidation

writz-lend.borrow checks the post-borrow collateral ratio against the BTC/USD oracle price and refuses anything below 150%, or a borrow when the position's Bitcoin timelock is less than 4,320 blocks above the bitcoin-spv tip. Interest accrues on a utilization-based curve. repay accepts partial or full repayment; a full repayment closes the position and emits a repay_full event.

Below a 120% collateral ratio a position can be liquidated. A designated keeper calls liquidate, repays the debt and receives a 10% USDC bonus from the protocol reserve, capped at what the reserve holds; if the keeper has been inactive for 24 hours, anyone may call it. No BTC moves in a liquidation today, see What you trust today and Liquidation.

3. BTC release

Release flow: full repayment on Stellar, relayer co-signs and publishes the PSBT, user countersigns and broadcasts on Bitcoin

When the loan is fully repaid, the relayer's repay watcher builds the release PSBT (Partially Signed Bitcoin Transaction), co-signs it with the protocol key and publishes it on writz-lend with publish_release_psbt, so once published it can be fetched even if the rest of the Writz stack is down. The user countersigns with their Bitcoin wallet and broadcasts. The protocol never holds custody at any point.

Lending USDC

Lenders supply USDC to the same writz-lend pool and earn the interest borrowers pay, minus the 15% protocol fee. The rate is variable and zero while nothing is borrowed. See For USDC lenders and the lending guide.


Bitcoin script design

Two spending paths: protocol and user signatures together, or the user alone after the CLTV timelock

The P2WSH redeem script encodes two spending paths:

OP_IF
  <protocol_pubkey> OP_CHECKSIGVERIFY
  <user_pubkey>     OP_CHECKSIG
OP_ELSE
  <locktime>        OP_CHECKLOCKTIMEVERIFY OP_DROP
  <user_pubkey>     OP_CHECKSIG
OP_ENDIF

Path A, cooperative release (normal case). The protocol and the user both sign. The relayer's repay watcher co-signs only after writz-lend records full repayment, and publishes the PSBT on chain with publish_release_psbt.

Path B, emergency recovery (timelock). After the timelock height chosen at deposit, the user spends alone, with no protocol involvement. The timelock must be 1,008 to 105,000 blocks above the deposit block; borrow requires it to be at least 4,320 blocks (about 30 days) above the Bitcoin tip, and liquidation closes 288 blocks before it. The step-by-step procedure is in Manual emergency recovery.

The P2WSH builder, address derivation and PSBT signing toolkit live in bitcoin-script/; the design is explained in Bitcoin side.


Smart contracts

Contract Purpose Depends on
bitcoin-spv SHA256d, proof-of-work and checkpoint-anchored difficulty checks, Merkle inclusion, block header chain, deposit txid registry None
writz-lend Deposit registration, USDC lending pool (supply, withdraw, borrow, repay), interest rate model, keeper liquidation, release PSBT publication bitcoin-spv, USDC, Reflector oracle

writz-lend consumes each deposit txid in the bitcoin-spv registry, so the same Bitcoin transaction cannot back two positions (one Writz deposit per transaction). The Security model explains how this also closes the Merkle duplicate-leaf ambiguity (CVE-2012-2459 class) at the deposit layer.

Key parameters

Values in the writz-lend code and its deployment arguments: testnet as deployed, mainnet as planned.

Parameter Value
Minimum collateral ratio 150% (maximum LTV about 66.7%)
Liquidation threshold 120%
Liquidation bonus 10% of the debt in USDC from the protocol reserve, capped at what the reserve holds
Interest rate curve 0% base, rising linearly to 8% at 75% utilization, then a 200% slope above it
Protocol fee 15% of borrower interest, kept on chain as the protocol reserve
Minimum deposit 5,000 sats on testnet; 100,000 sats planned for mainnet
Bitcoin confirmations 1 on testnet; 6 planned for mainnet
Borrow timelock margin Timelock at least 4,320 blocks (about 30 days) above the Bitcoin tip known on Stellar
Liquidation cutoff No liquidation within 288 blocks (about 2 days) of the timelock
Bitcoin tip freshness Borrows and liquidations refused if the latest header is older than 6 hours
Total borrow cap 50,000 USDC across the pool (admin-set)
Price source Reflector BTC/USD oracle, rejected if older than 1 hour

The worked rate model is in Writz Lend and Stellar side. Every public function is documented in the Contract reference.


Security

Risk Mitigation
Bitcoin reorg 1 confirmation on testnet, 6 planned for mainnet; the light client follows the most-work chain through reorgs of any depth, rewriting its index across calls and refusing proofs until the switch completes. A position whose deposit is later reorged out is not unwound automatically
P2WSH script bug Internal review and tests, including releases confirmed on Signet; external review before mainnet. The timelock protects users regardless
Protocol key compromise The protocol key cannot move BTC without the user's key; a 2-of-3 protocol side in the P2WSH script is planned, with a published signing policy
SPV contract bug Header light client anchored to a public checkpoint, with proof-of-work, exact difficulty and chainwork checks; no upgrade path. Known open edge cases (proof-depth binding) are listed in SPV vs wrapped Bitcoin; independent audit before mainnet
Oracle manipulation Reflector SEP-40 feed with a one-hour staleness check; a second source (RedStone) with a divergence guard is planned
Mass liquidation (BTC crash) 150% collateral ratio, liquidation below 120%, 50,000 USDC total borrow cap; see What you trust today for what liquidation does and does not do

Audits. The Soroban contracts (bitcoin-spv, writz-lend) and the Bitcoin script get an external review before mainnet. Critical, High and Medium findings are fixed before mainnet, and the final report is published. Status: Audits. Threat model: STRIDE.

Reporting a vulnerability. Open a private GitHub Security Advisory. Policy, response targets and safe harbour are in SECURITY.md; rewards and severity bands in the Bug bounty.


Build on Writz

The Bitcoin SPV light client is open infrastructure. Any Stellar contract or app can verify that a Bitcoin Signet transaction is confirmed, with one call to bitcoin-spv. Verification is free; no per-call fee exists.

Integration facts (testnet only; for coding agents, AGENTS.md and For AI agents are the canonical reference, and llms.txt indexes the docs):

Stellar network       testnet (no Writz contract on mainnet)
Network passphrase    Test SDF Network ; September 2015
Soroban RPC           https://soroban-testnet.stellar.org
Bitcoin network       signet (no mainnet, testnet3 or testnet4); only blocks after the checkpoint, 331,476, can be proven
bitcoin-spv           CCCQXNWQGLAAVGOB7YCZNWNHIC456LZXML55Z65OOXRTAZ5BIPNIZ3HB
writz-lend            CBI4AGULYDCCNYHKAC5HBCIF7X3YEZCYFXLYVLQWUOKPLXWO7LJCKG4Q
Test USDC (SAC)       CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA
Relayer               https://api.testnet.writz.xyz, proof route GET /spv-proof/:txid?confirmations=N
cargo add writz-spv-client   # Rust, from a Soroban contract
npm install @writz/sdk       # TypeScript, from an app
verify_transaction(
    block_hash: BytesN<32>,
    merkle_proof: Vec<BytesN<32>>,
    tx_index: u32,
    raw_tx: Bytes,
    min_confirmations: u32,
) -> Result<SpvVerificationResult, SPVError>
// SpvVerificationResult { txid, block_hash, block_height, confirmations }

The relayer's /spv-proof/:txid route returns block_hash, merkle_proof, tx_index and raw_tx for a confirmed transaction.


Products and business model

Writz Lend is the only product: deposit BTC as collateral and borrow USDC, or lend USDC to the pool and earn the interest borrowers pay. It is on testnet, with mainnet planned for Q2 to Q3 2027. Possible future directions are listed in Vision and are not products.

Revenue is the protocol fee: 15% of borrower interest, kept on chain as the protocol reserve, which today funds liquidation bonuses.


Developing in this repository

Repository structure

writz/
├── contracts/                # Soroban contracts (Rust)
│   ├── contracts/
│   │   ├── bitcoin-spv/      # SHA256d, PoW, Merkle inclusion, block headers
│   │   ├── writz-lend/       # Deposits, USDC pool, interest model, liquidation
│   │   ├── spv-types/        # Types shared by bitcoin-spv and its consumers
│   │   └── writz-spv-client/ # Rust client crate for bitcoin-spv
│   └── deployments/
│       ├── testnet.md        # Live addresses, tx hashes, verified calls
│       └── testnet.json      # Machine-readable IDs, generated from testnet.md
│
├── relayer/                  # SPV relayer service (TypeScript, Express, Bun)
│   └── src/
│       ├── routes/proof.ts           # GET /spv-proof/:txid
│       ├── routes/deposit-status.ts  # GET /deposit-status/:txid
│       ├── routes/timeline.ts        # GET /timeline/:btcTxid
│       ├── routes/cctp.ts            # POST /cctp/relay, GET /cctp/relay/:burnHash
│       ├── routes/faucet.ts          # Signet faucet for social sign-in accounts (testnet)
│       └── bitcoin/                  # Esplora client, header fetching, proof assembly
│
├── bitcoin-script/           # Bitcoin locking script toolkit (TypeScript)
│   └── src/
│       ├── script.ts         # P2WSH builder
│       ├── address.ts        # Address derivation (testnet / mainnet)
│       ├── spend.ts          # Path A/B PSBT signing
│       └── keys.ts           # Key management
│
├── frontend/
│   ├── app/                  # Next.js testnet app (testnet.writz.xyz)
│   └── landing/              # writz.xyz
│
├── packages/
│   ├── sdk/                  # @writz/sdk, TypeScript client with the testnet preset
│   ├── writz-lend/           # Generated TypeScript bindings for writz-lend
│   └── brand/                # Design tokens
│
├── watchtower/               # Read-only watchtower: checks the light client and writz-lend against independent Bitcoin sources
│
├── examples/                 # Runnable integration examples
├── scripts/deploy/           # deploy_stack.mjs, e2e_local.mjs
└── docs/                     # Documentation source, published at docs.writz.xyz

Tech stack

Layer Technology
Smart contracts Rust, soroban-sdk = "26"
Bitcoin scripting P2WSH with an absolute CLTV timelock; bitcoinjs-lib, ecpair
Bitcoin wallets Xverse (sats-connect); a Signet test key in the browser on testnet
Frontend Next.js 16, React 19, TypeScript, Tailwind CSS 4
Stellar wallets Stellar Wallets Kit (Varial, xBull, Lobstr, Albedo, Rabet); Pollar email and social login on testnet
Relayer Bun, Express, Esplora; Alpine Docker image
CI GitHub Actions, one job per module plus docs sync

Prerequisites

Versions match CI (.github/workflows/ci.yml, the canonical list of commands).

rustup target add wasm32v1-none
cargo install stellar-cli --locked --version 28.1.0
node --version   # 22
bun --version    # 1.3.14

Run the test suites

Each module has its own toolchain and there is no root build. The relayer imports the local @writz/* packages through their built output, so build those first. Its main suite runs under Jest through bun run test; plain bun test picks Bun's runner and fails.

# Soroban contracts (bitcoin-spv, writz-lend, spv-types, writz-spv-client)
(cd contracts && cargo test)

# Bitcoin script toolkit, then the packages the relayer imports
(cd bitcoin-script && bun install && bun test && bun run build)
(cd packages/writz-lend && bun install)

# Relayer: Jest suite, then the Bun suite
(cd relayer && bun install && bun run test && bun run test:bun)

# Watchtower (imports packages/writz-lend, installed above)
(cd watchtower && bun install && bun run typecheck && bun run lint && bun run test)

# SDK and frontends
(cd packages/sdk && bun install && bun test)
(cd frontend/app && bun install && bun run test)
(cd frontend/landing && bun install && bun run test)

CI runs every suite on each pull request. If anything fails locally, open an issue.

Frontend dev server

cd frontend/app
cp .env.example .env.local   # already holds the current testnet contract IDs
# Set NEXT_PUBLIC_RELAYER_URL=https://api.testnet.writz.xyz
bun install && bun dev       # http://localhost:3000

Deploying the full stack, operating the relayer and recovering its state are covered in the Quick start, the Runbook and Relayer recovery.


Documentation

Everything is published at docs.writz.xyz.

Section Pages
Overview Technical architecture · What is Writz? · The problem · How Writz works · Why Stellar, why now
Use the app Start here · Get test funds · Borrow · Repay and release · Lend · Troubleshooting
Product Writz Lend
How it works Bitcoin side · SPV verification · Stellar side · Manual proof submission · Manual emergency recovery
Developers Build on Writz · For AI agents · SPV SDK · Quick start · Contract reference · Contribution guide
Security Security model · SPV vs wrapped Bitcoin · Audits · Bug bounty · STRIDE threat model
Vision Vision

Get involved

You are Start here
A Bitcoin holder who wants USDC without selling Borrow guide
A USDC holder who wants to supply the pool Lend guide
A Stellar builder who needs Bitcoin verification Build on Writz
A security researcher Bug bounty and SECURITY.md
A contributor Contribution guide

Questions and feedback: Discord and X. Writz is built by a four-person team; see writz.xyz/about.


Contributing

Fork the repo, branch from main, run the suites of the modules you touch, add tests for new features and a regression test for every bug fix, and open a PR that says what changed and why. CI must pass. Details are in CONTRIBUTING.md and the Contribution guide.

License

Apache License 2.0, see LICENSE.

About

Bitcoin lending on Stellar. Native BTC stays on Bitcoin, verified by an on-chain light client on Soroban, and borrowers receive USDC. No bridge, no custodian, no wrapped tokens.

Topics

Resources

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages