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.2.tar.gz (11.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.2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sophi-0.1.2.tar.gz
  • Upload date:
  • Size: 11.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.2.tar.gz
Algorithm Hash digest
SHA256 2524d45762d94889c054b0ae0fbaca15332c64c48e5d875f6dfa9efb06fc104d
MD5 4564c6f375537ca64e3019a712a82573
BLAKE2b-256 9c2aea16a829c7f7d48f7069a29582ff08bb44adb6b9e7d6107cd7d0f6bc9cd1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sophi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.5 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7db5058c6ce51bbcb632c6267eeda7101e5a1a34248c543cd408da6cd62fdaa3
MD5 d1dddbee87b41a1b7ab148ada6a2930e
BLAKE2b-256 bd11a59062c4debc0387a1938f29ac7f2f05ac43136c52a971d6c5b568e1cb01

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