Skip to main content

Bonding curves and market makers derived from the same

Project description

bonding tests_312 tests_312_scipy_matplotlib

Bonding curves and automated market makers that use them.

Introduction:

As a kid I liked to invent board games. One was like monopoly, except that you got to buy stocks. For each stock there was a pile of cards, each card representing a share. The first card indicated a price of 100. The second card indicated a price of 130, and so forth. Landing on one square you got to buy before others did. Landing on another you got to sell.

Skipping forward to the reinvention of everything financial in web3, we have the modern equivalent with terminology bonding curve, for which there is a good simple intro here. A market maker charges a deterministic incremental price that is a monotonic (usually) function of the number of outstanding shares x. To compute hypothetical trades (e.g. size dependence bids or offers) or actual trades it performs an integration of the price curve. In this package we also account for and acrue breakage when shares are rounded by a small QUANTA, and the AMM can optionally collect a proportional fee.

If you like control theory then this is a greenfield, I suspect. I'm collating questions and literature sporadically.

Usage:

Create a market maker:

from bonding.amms.sqrtbondingcurveamm import SqrtBondingCurveAMM
amm = SqrtBondingCurveAMM(scale=1000.0, fee_rate=0.001)

Invest $1000:

shares = amm.buy_value(1000.0)

Then sell out:

sale_proceeds_value = amm.sell_shares(shares)
print(f"Proceeds from buying and selling all shares: {sale_proceeds_value}")
print(f"Net cost of buying and selling all shares: {initial_investment_value - sale_proceeds_value}")

Install

 pip install bonding
 pip install matplotlib
 pip install scipy 

Latter two are optional. Scipy is only used for numerical verification at present.

Interpretation of scale

All curves satisfy:

 price(0)=1
 price(scale)=2 

See the bondingcurve.py for verification methods.

They are also monotonic, as you can verify. For example:

 from bonding.amms.sqrtbondingcurve import SqrtBondingCurve
 SqrtBondingCurve(scale=10).plot()

Automated market maker properties

Round trip buying and selling, in either direction, cannot yield an arbitrage whether we specify quantity or cost. See bondingcurveamm,py for verification methods.

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

bonding-0.0.5.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

bonding-0.0.5-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file bonding-0.0.5.tar.gz.

File metadata

  • Download URL: bonding-0.0.5.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for bonding-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6874a96aa7589ad9a4d9a3a80268745adaee739bb07d7ec9d6f3e86439a419e6
MD5 b96f999f9d75b51d0fb6b52e142e66fd
BLAKE2b-256 c8289103629e51ede32a5c7fbe059b17707507969c74bb2fa3184e0b9d638353

See more details on using hashes here.

File details

Details for the file bonding-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: bonding-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for bonding-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3c1864fc468a76ac56eb05f2891c7855db7a7203e89588ef5144b1a2e1427d5e
MD5 6636b902ff5487a3bb01ce98f0fd2187
BLAKE2b-256 7c2096a27e45cd65ad4bb9ae6fbd013e588cfdc44d62462a0697012da05cb043

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