Skip to content

Commit 9a5598c

Browse files
committed
init
0 parents  commit 9a5598c

40 files changed

+14399
-0
lines changed

.env.example

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TESTNET_RPC=
2+
MAINNET_RPC=
3+
ADDRESS=
4+
PRIVATE_KEY=

.gitignore

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# System files
2+
.DS_Store
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
share/python-wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.nox/
46+
.coverage
47+
.coverage.*
48+
.cache
49+
nosetests.xml
50+
coverage.xml
51+
*.cover
52+
*.py,cover
53+
.hypothesis/
54+
.pytest_cache/
55+
cover/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
73+
74+
# Sphinx documentation
75+
docs/_build/
76+
77+
# PyBuilder
78+
.pybuilder/
79+
target/
80+
81+
# Jupyter Notebook
82+
.ipynb_checkpoints
83+
84+
# IPython
85+
profile_default/
86+
ipython_config.py
87+
88+
# pyenv
89+
# For a library or package, you might want to ignore these files since the code is
90+
# intended to run in multiple environments; otherwise, check them in:
91+
# .python-version
92+
93+
# pipenv
94+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
96+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
97+
# install all needed dependencies.
98+
#Pipfile.lock
99+
100+
# poetry
101+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102+
# This is especially recommended for binary packages to ensure reproducibility, and is more
103+
# commonly ignored for libraries.
104+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105+
#poetry.lock
106+
107+
# pdm
108+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109+
#pdm.lock
110+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111+
# in version control.
112+
# https://pdm.fming.dev/#use-with-ide
113+
.pdm.toml
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.venv
128+
env/
129+
venv/
130+
ENV/
131+
env.bak/
132+
venv.bak/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# PyCharm
159+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161+
# and can be added to the global gitignore or merged into this file. For a more nuclear
162+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163+
#.idea/
164+
165+
# vs code
166+
.vscode/
167+
168+
# data
169+
data/
170+
171+
# contracts
172+
/deployments/

.pre-commit-config.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
10+
- repo: https://github.com/pre-commit/mirrors-autopep8
11+
rev: v2.0.2
12+
hooks:
13+
- id: autopep8

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Synthetix
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Synthetix SDK
2+
3+
Python SDK to interact with Synthetix smart contracts and subgraphs
4+
5+
## Development
6+
Create a python virtual environment, activate it and install libraries:
7+
8+
```bash
9+
python3 -m venv env
10+
source env/bin/activate
11+
pip install --upgrade pip
12+
pip install -r requirements.txt
13+
pip install -e ./src
14+
```

pytest.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = --log-cli-level=INFO

requirements.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
numpy==1.23.3
2+
pandas==1.4.2
3+
plotly==5.4.0
4+
requests==2.28.1
5+
streamlit
6+
web3==6.0.0
7+
autopep8
8+
pre-commit
9+
python-dotenv
10+
pytest

src/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setuptools

src/setup.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from setuptools import setup, find_packages
2+
setup(
3+
name='synthetix',
4+
version='1.0.0',
5+
description='Synthetix protocol SDK',
6+
long_description='A library containing helpful functions for interacting with the Synthetix protocol',
7+
author='Synthetix DAO',
8+
packages=['synthetix'],
9+
install_requires=[
10+
"numpy",
11+
"pandas",
12+
"requests",
13+
"web3>=6.0.0",
14+
"gql"
15+
],
16+
classifiers=[
17+
'Intended Audience :: Developers',
18+
'License :: OSI Approved :: MIT License',
19+
'Programming Language :: Python :: 3',
20+
'Programming Language :: Python :: 3.6',
21+
'Programming Language :: Python :: 3.7',
22+
'Programming Language :: Python :: 3.8',
23+
'Programming Language :: Python :: 3.9',
24+
'Programming Language :: Python :: 3.10',
25+
],
26+
python_requires=">=3.8",
27+
package_data={"synthetix": ["json/*"]},
28+
include_package_data=True,
29+
)

src/synthetix/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .synthetix import Synthetix
2+
3+
__all__ = ['Synthetix']

src/synthetix/constants.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from decimal import Decimal
2+
3+
# default
4+
DEFAULT_NETWORK_ID = 10
5+
DEFAULT_TRACKING_CODE = '0x53594e5448455449585f53444b00000000000000000000000000000000000000'
6+
DEFAULT_REFERRER = '0x0000000000000000000000000000000000000000'
7+
DEFAULT_SLIPPAGE = 2.0
8+
9+
DEFAULT_GQL_ENDPOINT_PERPS = {
10+
10: 'https://api.thegraph.com/subgraphs/name/kwenta/optimism-perps',
11+
420: 'https://api.thegraph.com/subgraphs/name/kwenta/optimism-goerli-perps'
12+
}
13+
14+
DEFAULT_GQL_ENDPOINT_RATES = {
15+
10: 'https://api.thegraph.com/subgraphs/name/kwenta/optimism-latest-rates',
16+
420: 'https://api.thegraph.com/subgraphs/name/kwenta/optimism-goerli-latest-rates'
17+
}
18+
19+
DEFAULT_PRICE_SERVICE_ENDPOINTS = {
20+
10: 'https://xc-mainnet.pyth.network',
21+
420: 'https://xc-testnet.pyth.network'
22+
}
23+
24+
ETH_DECIMAL = Decimal('1e18')

src/synthetix/contracts/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .contracts import load_contracts
2+
3+
__all__ = ['load_contracts']

src/synthetix/contracts/contracts.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import json
3+
import glob
4+
5+
def load_contracts(network_id):
6+
"""Loads the contracts for the given network id"""
7+
# get all filenames from directory `./deployments/[network_id]`
8+
deployment_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'deployments', f'{network_id}')
9+
deployment_files = glob.glob(os.path.join(deployment_dir, '*.json'))
10+
11+
contracts = {
12+
os.path.splitext(os.path.basename(contract))[0]: json.load(open(contract))
13+
for contract in deployment_files
14+
}
15+
return contracts

0 commit comments

Comments
 (0)