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.3.tar.gz (14.6 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.3-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sophi-0.1.3.tar.gz
  • Upload date:
  • Size: 14.6 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.3.tar.gz
Algorithm Hash digest
SHA256 ba6e2a3e956c66afb9b4c073e13c5747b91b8f4f9224104af3f7ad3d2459409a
MD5 b2562eca5160ff5709a7653f76a15707
BLAKE2b-256 c875959b655f95ff57c2e23ec15f540c4710d7689685b4e04e27721dc1d5fbaf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sophi-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 15.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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aef119bf4a5bd8d6a46092e8699833b7236c1c3df3fe9129315cda7b9a35b750
MD5 ca419deb922ef7a3ebb6cdd2d477aa39
BLAKE2b-256 4e41e70839d540792055dc7a63d2daf344087e1ba808393f57f2510e30b9b4d8

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