Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create jito_jsonrpc_sdk.py #1

Merged
merged 56 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a90fee2
Create jito_jsonrpc_sdk.py
mdr0id Jul 18, 2024
c9969fc
Create example.py
mdr0id Jul 18, 2024
03e7482
Update README.md
mdr0id Jul 18, 2024
25fe8f6
Update example.py
mdr0id Jul 18, 2024
62652e2
Update jito_jsonrpc_sdk.py
mdr0id Jul 23, 2024
0315e59
test out CI across Python versions
mdr0id Jul 23, 2024
6a20a38
Add in initial tests for stubs
mdr0id Jul 23, 2024
6eef2c2
update paths
mdr0id Jul 23, 2024
3850c78
check env
mdr0id Jul 23, 2024
691642c
update destination call
mdr0id Jul 23, 2024
a8cb036
update hiearchy
mdr0id Jul 23, 2024
88bf4bb
update calls to none default
mdr0id Jul 23, 2024
70a73e8
import local module
mdr0id Jul 23, 2024
72ff592
Add path
mdr0id Jul 23, 2024
8d8612e
check path
mdr0id Jul 23, 2024
58d1673
update install
mdr0id Jul 23, 2024
38581e6
update calling sequence and proper install
mdr0id Jul 23, 2024
5b029bf
update calling sequence for proper hiearchy
mdr0id Jul 23, 2024
9a101b9
check if needs system access
mdr0id Jul 23, 2024
0b31d2f
update to pyenv
mdr0id Jul 23, 2024
e45db39
update to pyenv install
mdr0id Jul 23, 2024
3e71272
Update install
mdr0id Jul 23, 2024
7d6f61a
Update install 2
mdr0id Jul 23, 2024
27d88b7
Update pyenv bashrc process via actions mechanisms
mdr0id Jul 23, 2024
a7940aa
Sanity check sourcing of files
mdr0id Jul 23, 2024
be22d0f
Update pyenv setup
mdr0id Jul 23, 2024
6edd73a
remove env exports
mdr0id Jul 23, 2024
7675828
Ensure pyenv is set
mdr0id Jul 23, 2024
b6296da
update sourcing
mdr0id Jul 23, 2024
4965979
update sourcing2
mdr0id Jul 23, 2024
61c6d73
Fix env
mdr0id Jul 23, 2024
015ab1c
Fix env
mdr0id Jul 23, 2024
1bb6f52
Fix env2
mdr0id Jul 23, 2024
d87add1
basic check on some version
mdr0id Jul 23, 2024
1cebe8a
remove version
mdr0id Jul 23, 2024
c95833a
remove version 2
mdr0id Jul 23, 2024
64807ab
remove version 2
mdr0id Jul 23, 2024
6dc490e
fix annoying spacing
mdr0id Jul 23, 2024
7bc7b3d
sanity check naming import
mdr0id Jul 23, 2024
ce89d6c
sanity check naming import2
mdr0id Jul 23, 2024
f24ad32
what module is installed
mdr0id Jul 23, 2024
546d14e
where is the module
mdr0id Jul 23, 2024
509ab02
sanity check where pytest looks
mdr0id Jul 23, 2024
ae5b962
manually add it
mdr0id Jul 23, 2024
d116db7
manually add it2
mdr0id Jul 23, 2024
ce18698
check editable flag
mdr0id Jul 23, 2024
7348aa8
there's a chance
mdr0id Jul 23, 2024
236e605
Remove testing; add back in each environment
mdr0id Jul 23, 2024
cee0d13
Simplify logic to sdk
mdr0id Jul 25, 2024
1e401f8
Update README
mdr0id Jul 25, 2024
dfdbc49
Update README
mdr0id Jul 25, 2024
04c97c8
Remove generated files
mdr0id Jul 25, 2024
a47a517
Remove generated files2
mdr0id Jul 25, 2024
f8351c5
Update minor errors
mdr0id Jul 25, 2024
f222667
Update README
mdr0id Jul 26, 2024
1c8c8ad
Wow discord link
mdr0id Jul 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Python application

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest responses
pip install -e .

- name: Run tests
env:
JITO_TESTNET_URL: https://dallas.testnet.block-engine.jito.wtf/api/v1
run: pytest ./tests/test_jito_json_rpc_sdk.py
157 changes: 157 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Byte-compiled / optimized / DLL files
__pycache__/
sdk/__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual environment
.env/
.venv/
env/
venv/
ENV/
env.bak/
venv.bak/

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
docs/_static/
docs/_templates/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
spyderproject
spyderworkspace

# VS Code
.vscode/
history/

# PyCharm
.idea/
*.iml
*.iws
*.ipr
out/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Pycharm
.idea/
*.iml
*.iws
*.ipr
out/

# MacOS specific files
.DS_Store

# Windows specific files
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/

# Anaconda environments
.envs/
.conda/

# Miscellaneous
*.swp
*~
124 changes: 122 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,122 @@
# jito-py-rpc
Jito Python JSON RPC SDK
# Welcome to the Jito Python JSON RPC SDK!

[![Discord](https://img.shields.io/discord)](https://discord.gg/jito)
[![Python](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/)


This is a minimal SDK that interfaces with the Block-Engine JSON-RPC API using [JSON-RPC 2.0](https://www.jsonrpc.org/specification) specification.

#### Jito MEV Background
For additional information on Jito MEV topics:

https://jito-labs.gitbook.io/mev

#### Jito JSON-RPC HTTP Method
For more information on the complete JSON-RPC method specification:

https://github.com/jito-labs/mev-protos/blob/master/json_rpc/http.md

## Getting Started

### Setting Up the SDK

#### Step 1: Clone the Repository
Clone the [repo](https://github.com/mdr0id/JitoJsonRpcSDK) to your local machine.

```
git clone [email protected]:mdr0id/JitoJsonRpcSDK.git
```

#### Step 2: Install Dependencies
You will need the Python `requests` module to make HTTP requests. If you don't have `requests` installed, you can install it using pip:

```
pip install requests
```

## Using the SDK
#### Step 1: Import the SDK

```
from sdk.jito_jsonrpc_sdk import JitoJsonRpcSDK
```

#### Step 2: Initialize the SDK
Depending on what network you would like to connect to, please select one of the following(e.g mainnet or testnet).

#### Step 3 (Optional): Environment Config for Authentication
If you are using authentication with UUIDs it is recommended to setup an `.envrc` like below:

```
export JITO_UUID=513f9c0c-260d-4e14-b5b4-495785548cd2
```

For instructions on setting up `direnv` please look [here](https://direnv.net/docs/installation.html)


##### Mainnet
For current list of of `mainnet` addresses, please see:

https://jito-labs.gitbook.io/mev/searcher-resources/block-engine/mainnet-addresses
```
BLOCK_ENG_URL = "https://mainnet.block-engine.jito.wtf:443/api/v1/bundles"
sdk = JitoJsonRpcSDK(BLOCK_ENG_URL)
```
##### Testnet
For current list of of `testnet` addresses, please see:

https://jito-labs.gitbook.io/mev/searcher-resources/block-engine/testnet-addresses
```
BLOCK_ENG_URL = "https://dallas.testnet.block-engine.jito.wtf/api/v1/bundles"
sdk = JitoJsonRpcSDK(BLOCK_ENG_URL)
```

#### Step 3: Call JSON-RPC Methods
You can now call JSON-RPC methods defined in the `http.md` document:

https://github.com/jito-labs/mev-protos/blob/master/json_rpc/http.md#json-rpc-api-reference

##### Example: getTipAccounts

###### Parameters
- `None`

```
sdk.get_tip_accounts()
```

##### Example: sendBundle

###### Parameters
- `<array[string]>`: `required` Fully-signed Transactions, as encoded string (base-58) upto a maximum of 5. Please note that at this point, we don't support base-64 encoded transactions

```
params = [
"4VbvoRYXFaXzDBUYfMXP1irhMZ9XRE6F1keS8GbYzKxgdpEasZtRv6GXxbygPp3yBVeSR4wN9JEauSTnVTKjuq3ktM3JpMebYpdGxZWUttJv9N2DzxBm4vhySdq2hbu1LQX7WxS2xsHG6vNwVCjP33Z2ZLP7S5dZujcan1Xq5Z2HibbbK3M3LD59QVuczyK44Fe3k27kVQ43oRH5L7KgpUS1vBoqTd9ZTzC32H62WPHJeLrQiNkmSB668FivXBAfMg13Svgiu9E",
"6HZu11s3SDBz5ytDj1tyBuoeUnwa1wPoKvq6ffivmfhTGahe3xvGpizJkofHCeDn1UgPN8sLABueKE326aGLXkn5yQyrrpuRF9q1TPZqqBMzcDvoJS1khPBprxnXcxNhMUbV78cS2R8LrCU29wjYk5b4JpVtF23ys4ZBZoNZKmPekAW9odcPVXb9HoMnWvx8xwqd7GsVB56R343vAX6HGUMoiB1WgR9jznG655WiXQTff5gPsCP3QJFTXC7iYEYtrcA3dUeZ3q4YK9ipdYZsgAS9H46i9dhDP2Zx3"
]
sdk.send_bundle(params)
```

##### Example: getBundleStatuses

###### Parameters
- `<array[string]>`: `required` An array of bundle ids to confirm, as base-58 encoded strings (up to a maximum of 5).
```
params = ["892b79ed49138bfb3aa5441f0df6e06ef34f9ee8f3976c15b323605bae0cf51d"]
sdk.get_bundle_statuses(params)
```

##### Example: sendTransaction

###### Parameters
- `[string]`: `required` Fully-signed Transaction, as encoded string.
```
params = [
"4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT"
]
sdk.send_txn(params)
```

### Step 4: Handling Responses
The sdk RPC methods return the JSON response from the server. You can then handle the response according to your program's requirements. For an example, please see example.py when handling a bundle that was not found.
39 changes: 39 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from sdk.jito_jsonrpc_sdk import JitoJsonRpcSDK


def main():
# Initialize the SDK
# mainnet
#BLOCK_ENG_URL = "https://mainnet.block-engine.jito.wtf:443/api/v1"

# testnet
BLOCK_ENG_URL = "https://dallas.testnet.block-engine.jito.wtf/api/v1"
sdk = JitoJsonRpcSDK(BLOCK_ENG_URL)

# If you are using authentication which is not needed unless you request rate limit increase
#UUID_ENV = "JITO_UUID"
#sdk = JitoJsonRpcSDK(BLOCK_ENG_URL, UUID_ENV)

result = sdk.get_tip_accounts()
print(result)

params = [
"4VbvoRYXFaXzDBUYfMXP1irhMZ9XRE6F1keS8GbYzKxgdpEasZtRv6GXxbygPp3yBVeSR4wN9JEauSTnVTKjuq3ktM3JpMebYpdGxZWUttJv9N2DzxBm4vhySdq2hbu1LQX7WxS2xsHG6vNwVCjP33Z2ZLP7S5dZujcan1Xq5Z2HibbbK3M3LD59QVuczyK44Fe3k27kVQ43oRH5L7KgpUS1vBoqTd9ZTzC32H62WPHJeLrQiNkmSB668FivXBAfMg13Svgiu9E",
"6HZu11s3SDBz5ytDj1tyBuoeUnwa1wPoKvq6ffivmfhTGahe3xvGpizJkofHCeDn1UgPN8sLABueKE326aGLXkn5yQyrrpuRF9q1TPZqqBMzcDvoJS1khPBprxnXcxNhMUbV78cS2R8LrCU29wjYk5b4JpVtF23ys4ZBZoNZKmPekAW9odcPVXb9HoMnWvx8xwqd7GsVB56R343vAX6HGUMoiB1WgR9jznG655WiXQTff5gPsCP3QJFTXC7iYEYtrcA3dUeZ3q4YK9ipdYZsgAS9H46i9dhDP2Zx3"
]
result = sdk.send_bundle(params)
print(result)

params = ["892b79ed49138bfb3aa5441f0df6e06ef34f9ee8f3976c15b323605bae0cf51d"]
result = sdk.get_bundle_statuses(params)
print(result)

params = [
"4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT"
]
result = sdk.send_txn(params)
print(result)


if __name__ == "__main__":
main()
Empty file added sdk/__init__.py
Empty file.
Binary file added sdk/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added sdk/__pycache__/jito_jsonrpc_sdk.cpython-310.pyc
Binary file not shown.
Loading
Loading