Skip to content

PulsarDefi/osmosispy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Osmosis python SDK

Python SDK for interacting with the Osmosis AMM.

Project Status: WIP -- Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. PyPI Version Documentation Status Discord Osmosis Stars MIT license

The osmosispy and osmosis_proto package allows you to interact with the Osmosis AMM using Python.

README Contents

Installation from PyPI

python -m pip install --upgrade pip

pip install osmosispy  # requires Python 3.11.2+

Usage

Ex: Creating a wallet and SDK client

example.py

#!/usr/bin/env python3

import osmosispy

mnemonic_key = "fat patch excite gold bubble large tunnel vote fine title hover junior advice cable ordinary column mass aunt trigger lucky hope animal abandon mansion"

# authorize in the mainnet
network = osmosispy.Network.mainnet()

trader = osmosispy.Sdk.authorize(key=mnemonic_key).with_network(network)

# print the address
print(trader.address)
$ python3 example.py
osmo1jggt8pcj2d8m9n62luytf8sdncj5uxfs3su2my

More examples

For more examples see the examples directory.

Publishing to PyPI

The publish workflow looks like this:

  1. Code-gen the new types from the chain. If there are changes, these should be committed.

    poetry run make proto-gen
  2. Increment the package version. For example, use poetry version preminor to do a pre-release for a minor version.

    poetry version [update-keyword]
  3. Create a tag and push it the remote origin.

    git tag -asm "v1.2.3" v1.2.3
    git push --tags
  4. The tag will trigger a GitHub Action Workflow.

Convert ProtoBuf Files to Python

Requirements

  • protobuf-compiler installed on the computer

    For example in MacOs:

    brew install protobuf
  • mypy-protobuf library installed on python

    pip install mypy-protobuf

Step by step

  1. Some background:

    • The Osmosis SDK uses protobuf files to communicate with the osmosis chain, similar to the Cosmos SDK.
    • The protobuf files of the most important SDKs on Cosmos are located in the repos_protobufs folder.
    • The Python files converted from repos_protobufs are located in the osmosis_proto folder.
  2. In the scripts/generate_python_from_protobuf.py file, you can convert the proto files to Python files.

  3. In the variable PROTO_FILES, there are two examples:

    • concentratedliquidity/v1beta1/query.proto
    • concentratedliquidity/v1beta1/tick_info.proto
  4. Choose the paths of the proto files you want to convert. You can add more proto files to PROTO_FILES to be converted into Python files.

  5. Run the script with the command python generate_python_from_protobuf.py in the directory of the script:

    python generate_python_from_protobuf.py
    • If the script runs successfully, the Python files will be generated in the tmp folder. Copy the files to their destination in the osmosis_proto folder. Try to maintain the same folder structure as the repos_protobufs folder, like how the protobuf files are organized. Read the section "Alert" below for more information.

    • If the script retrieves a "File not found" error, there is probably a missing dependency. This means some protobuf files of some SDK are not present in the repos_protobufs folder.

      1. The error will provide the name of the missing dependency.
      2. Copy the dependency name, search for it on GitHub, and add the new proto files to the repos_protobufs folder.
      3. Add the new path of the proto SDK repositories to the global variables, as in the example:
        GOGO_PROTO_DIR = os.path.join(ROOT_PROTO_DIR, "gogoproto")

Alert

The version of the Protobuf compiler used in the files that are converted to .py contains an issue. The Protobuf compiler imports a non-existent library:

from google.protobuf import runtime_version as _runtime_version

Additionally, the following code (an example) is included:

_runtime_version.ValidateProtobufRuntimeVersion(
    _runtime_version.Domain.PUBLIC,
    5,
    27,
    1,
    '',
    'osmosis/concentratedliquidity/v1beta1/query.proto'
)

This code needs to be manually removed from each generated .py file. While this is somewhat tedious, after making these changes, the compilation of the repository will work correctly.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.2%
  • Go 1.5%
  • Other 0.3%