Skip to main content

Balance-based non-custodial swap language for Bitcoin

Project description

Sophi

Balance-based non-custodial swap language for Bitcoin.

Sophi is a language with one primitive: the balance. When both sides are equal, a non-custodial atomic swap executes on Bitcoin. No escrow. No intermediary. No custodian.

Install

pip install sophi

Write a swap

swap {
  alice wants  0.5 BTC
  alice gives  50000 USDT

  bob wants    50000 USDT
  bob gives    0.5 BTC
}

Save as trade.sph and run:

sophi compile trade.sph

Blind swap (private values)

swap {
  alice wants  blind(a3f8c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0)
  alice gives  blind(b1e2d3c4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2)

  bob wants    blind(b1e2d3c4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2)
  bob gives    blind(a3f8c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0)
}

Nobody sees the amounts until settlement. This is the foundation of OTC dark pool privacy.

How it works

  • wants — what a party wants to receive
  • gives — what a party is offering
  • blind(hash) — hides the value using SHA-256 commitment
  • partial — accepts partial fill
  • expires block(N) — swap expires at Bitcoin block N

The compiler checks that all balances are in equilibrium before generating anything. If alice gives does not equal bob wants, you get a clear error — not a runtime failure on a live network.

Multi-party

swap {
  alice wants  blind(H1)
  alice gives  blind(H2)

  bob wants    blind(H2)
  bob gives    blind(H3)

  carol wants  blind(H3)
  carol gives  blind(H1)
}

Up to 8 parties. All legs settle atomically.

Non-custodial by construction

Sophi has no syntax for depositing funds into a contract. The only thing you can express is a condition for transfer. Custodial code is not forbidden — it is unwritable.

License

Business Source License 1.1 — converts to Apache 2.0 after 4 years.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sophi-0.1.5.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sophi-0.1.5-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file sophi-0.1.5.tar.gz.

File metadata

  • Download URL: sophi-0.1.5.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sophi-0.1.5.tar.gz
Algorithm Hash digest
SHA256 aa7da9468e0a1b4697b75d66fde11b455d044baea4cd1df495dc1c6f256972d5
MD5 32091632ff656502359fcfbc4bb16356
BLAKE2b-256 490d593f062b39fa8fb22da0807f6335fe37ace55da095730c1a7a30cdbb5e97

See more details on using hashes here.

File details

Details for the file sophi-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: sophi-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sophi-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 717520fad09efdddbf6db5198e693a7390e2d2de6faf0d4978412a6b2657ce9d
MD5 373787c31386fb6b93fec7e7ef644a98
BLAKE2b-256 897aa562ae894dc3b26dde45f1792dec6909134a89543d9289fd7fab1aac21dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page