Skip to main content

Cointime economics framework implementation for the Ergo blockchain.

Project description

boxtime

Cointime economics framework implementation for the Ergo blockchain.

Description

Boxtime is a Python library that implements the Cointime Economics framework for Ergo. It reads pre-computed coinblocks created, destroyed, and stored — plus daily ERG/USD prices — from a database populated by the boxtime indexer.

Two connection paths are supported:

  1. Default (Supabase) — uses the hosted Supabase project via PostgREST with an embedded publishable API key. No setup needed.
  2. Custom (Postgres) — connect directly to your own Postgres instance via asyncpg.

Installation

pip install boxtime

Prerequisites

  • Python 3.10+

Quickstart

Default (Supabase — no setup needed)

from boxtime import Cointime

ct = Cointime()  # uses the hosted Supabase database

# Coinblocks created at a single height (= circulating supply in nanoERGs)
cbc = ct.coinblocks_created(500_000)

# Coinblocks destroyed at a single height
cbd = ct.coinblocks_destroyed(500_000)

# Coinblocks stored (CBC - CBD)
cbs = ct.coinblocks_stored(500_000)

# Totals over a range
total_cbc = ct.total_coinblocks_created(500_000, 500_100)
total_cbd = ct.total_coinblocks_destroyed(500_000, 500_100)
total_cbs = ct.total_coinblocks_stored(500_000, 500_100)

Custom Postgres

ct = Cointime(database_url="postgresql://user:pass@localhost:5432/boxtime")
cbc = ct.coinblocks_created(500_000)

Price data

import datetime

ct = Cointime()

# Daily ERG/USD price
price = ct.get_price(datetime.date(2024, 6, 15))

# Price range
prices = ct.get_price_range(datetime.date(2024, 1, 1), datetime.date(2024, 12, 31))
for date, usd in prices:
    print(date, usd)

Price-enriched data (for plotting)

# One CointimeDataPoint per day — last height of each day with daily price
data_points = ct.get_coinblocks_created(500_000, 510_000)
for dp in data_points:
    print(dp.height, dp.timestamp, dp.value, dp.price)

# Clean up when done
ct.close()

Each CointimeDataPoint bundles height, timestamp, value (cointime metric), and price (ERG/USD). Results are grouped by day using the last block height of each day.

API Overview

Cointime(database_url=None, *, supabase_url=..., supabase_key=...)

Parameter Default Description
database_url None If set, use direct Postgres via asyncpg
supabase_url Hosted URL Supabase project URL (default path)
supabase_key Publishable key Supabase API key (safe to embed)

Primitive metrics (single height):

  • coinblocks_created(height) — circulating supply at height
  • coinblocks_destroyed(height) — sum of input.value × lifespan for all inputs
  • coinblocks_stored(height) — CBC − CBD

Aggregate metrics (height range, inclusive):

  • total_coinblocks_created(start_height, end_height)
  • total_coinblocks_destroyed(start_height, end_height)
  • total_coinblocks_stored(start_height, end_height)

Price methods:

  • get_price(date) — daily ERG/USD price (datetime.date)
  • get_price_range(start_date, end_date)List[Tuple[date, float]]

Convenience methods (one CointimeDataPoint per day):

  • get_coinblocks_created(start_height, end_height)List[CointimeDataPoint]
  • get_coinblocks_destroyed(start_height, end_height)List[CointimeDataPoint]
  • get_coinblocks_stored(start_height, end_height)List[CointimeDataPoint]

Utility:

  • get_max_height() — check data freshness
  • close() — clean up connection pool / client

Development

# Install with test dependencies
pip install -e ".[test]"

# Run tests
pytest

License

This project is licensed under the MIT License.

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

boxtime-3.0.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

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

boxtime-3.0.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file boxtime-3.0.0.tar.gz.

File metadata

  • Download URL: boxtime-3.0.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for boxtime-3.0.0.tar.gz
Algorithm Hash digest
SHA256 5be718f8cb34ca418039a4e84d091e06a0750f1d3f9d68723ce393f02eadf45a
MD5 a74f206648a4932dbc9c2f1d0ab23faa
BLAKE2b-256 3cd6470ff304091eecb3bc5bcd506f8423fb7e5a3fc7e5a785486715aa44ac23

See more details on using hashes here.

File details

Details for the file boxtime-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: boxtime-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for boxtime-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9d404653c564b9c12efe9868bdcae09ed9c1c710a506da224c6cb4a11b87368
MD5 94b647b0f8e758b1e6c37dc0b48619fe
BLAKE2b-256 dc57486aaf35240c9ee7c8b44678f3f6a080ae53cc17d3e36bea24c13f9fee8f

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