Skip to content

autonity/autonity.py

Repository files navigation

autonity.py

Autonity is a public, EVM based, proof-of-stake blockchain for decentralized clearing of smart derivatives contracts. See the Autonity Documentation site to learn more.

This package provides typed Python bindings (a.k.a. wrappers) for Autonity protocol contracts using the Web3.py framework to provide users with convenient and statically-checked Python interactions with Autonity.

Installation

This package is published on PyPI as the autonity package. It can be installed in a virtualenv using pip or a compatible package manager:

pip install autonity

Usage

Example usage:

from web3 import Web3
from autonity import Autonity, Liquid, networks

# Connect to the default RPC provider on the Autonity Piccadilly Testnet
w3 = Web3(networks.piccadilly.http_provider)

# Create the typed binding around the Autonity contract
autonity = Autonity(w3)

# Get the total supply of Newton
ntn_supply = autonity.total_supply()
print(f"Total NTN supply: {ntn_supply}")

# Get the current validator list
validator_addresses = autonity.get_validators()

# Get the description of the 0-th validator and print its Liquid contract address
validator = autonity.get_validator(validator_addresses[0])
print(f"LNTN contract address: {validator.liquid_contract}")

# Query unclaimed fees for <ADDRESS> from the validator's Liquid contract
liquid = Liquid(w3, validator.liquid_contract)
unclaimed_atn, unclaimed_ntn = liquid.unclaimed_rewards("<ADDRESS>")
print(f"Unclaimed rewards: {unclaimed_atn} ATN, {unclaimed_ntn} NTN")

Development

The package uses the Hatch Python project manager. It is recommended to install Hatch using pipx:

pipx install hatch

Installing Python interpreters (optional)

This project aims to be compatible with all the officially-supported versions of Python. Check python.org Status of Python versions for more info.

To run the tests against all supported Python versions, it is necessary to install the relevant distributions of Python. Hatch is able to download these Python binaries into the user home directory:

$ hatch python install all
Installed 3.7 @ /home/develop/.local/share/hatch/pythons/3.7
Installed 3.8 @ /home/develop/.local/share/hatch/pythons/3.8
Installed 3.9 @ /home/develop/.local/share/hatch/pythons/3.9
Installed 3.10 @ /home/develop/.local/share/hatch/pythons/3.10
Installed 3.11 @ /home/develop/.local/share/hatch/pythons/3.11
Installed 3.12 @ /home/develop/.local/share/hatch/pythons/3.12
Installed pypy2.7 @ /home/develop/.local/share/hatch/pythons/pypy2.7
Installed pypy3.9 @ /home/develop/.local/share/hatch/pythons/pypy3.9
Installed pypy3.10 @ /home/develop/.local/share/hatch/pythons/pypy3.10

⚠️ Hatch will modify your shell configuration to add these directories to your $PATH.

Building and testing

To launch the tests across all supported Python versions, run:

hatch run test:all

To limit the tests to a specific Python version, add a hatch run + argument:

hatch run +py=3.12 test:all

To lint the code base, use the command:

hatch run lint:check

Updating the contract bindings

To update contract bindings for a new version of the Autonity protocol, add the new AGC version (Git tag or commit ID) to AUTONITY_VERSION, then generate the contract bindings with make:

echo v0.14.0 > AUTONITY_VERSION
make

Contract functions are ordered alphabetically in order to produce deterministic output. After executing the script against a new version of the code, the diffs can be reviewed to determine which methods have been modified, removed or added. The generated Python bindings include the contract ABIs as Python dictionaries.

If there is a new contract to include, add a new target to Makefile and a new factory function to autonity/factory.py and autonity/__init__.py.

Contributing

To contribute a non-critical bug fix, please open a pull request against the master branch as per Github Flow. If the bug is critical, then it may qualify as a hotfix, see the next section for details.

To work on a new feature described in an open issue, check the corresponding issue isn't already assigned to someone. If it's available, post a comment in the issue to request a maintainer assign it to you.

To contribute a feature that isn't tracked in an existing issue, please first open a new issue describing the feature before commencing development.

Contributing a hotfix

To qualify as a hotfix:

  • relevance: the bug affects the most recent release of the software
  • severity: the bug has an adverse impact on users of the software
  • compatibility: the fix for the bug is fully backwards-compatible

Contributing a hotfix:

  • Develop the fix on top of stable. Create a new branch starting from the stable branch to develop and test the fix.
  • Open a pull request against stable. Create a new pull request with the changes and set stable as the target branch.

Reporting a vulnerability

Please do not file a public ticket mentioning the vulnerability.

Instead, please send an email to [email protected] to report a security issue.

The following PGP key may be used to communicate sensitive information to developers:

Fingerprint: 6006 CCC3 DD11 7885 1A23 4290 7486 F832 6320 219E

-----BEGIN PGP PUBLIC KEY BLOCK-----

xsFNBGL7epsBEADHxcFdpX1a60JFFN4jW3VtvofLFNXAHKT4GlOtIayozySdZI2A
fGRg2brbYdXdlHN3MYZJbMo/kIfMlYqiVFevEtNGDEGKYmqzXiad7RRpmx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