pip install git+https://github.com/velodrome-finance/sugar-sdk
TODO: push to pypi
# load env
from dotenv import load_dotenv
load_dotenv()
True
from sugar.chains import BaseChain, AsyncBaseChain
# async version
async with AsyncBaseChain() as chain:
prices = await chain.get_prices(await chain.get_all_tokens())
for p in prices[:5]:
print(f"{p.token.symbol} price: {p.price}")
# sync version
with BaseChain() as chain:
for p in chain.get_prices(chain.get_all_tokens())[:5]:
print(f"{p.token.symbol} price: {p.price}")
ETH price: 2493.730879871026
tBTC price: 89224.39116374683
USDbC price: 1.0017660536011292
WETH price: 2493.730879871026
T price: 0.017866263433246897
ETH price: 2493.740797040875
tBTC price: 89224.74599491524
USDbC price: 1.0017697172914204
WETH price: 2493.740797040875
T price: 0.01786632641861627
from sugar.chains import AsyncOPChain, OPChain
async with AsyncOPChain() as chain:
prices = await chain.get_prices(await chain.get_all_tokens())
for p in prices[:5]:
print(f"{p.token.symbol} price: {p.price}")
with OPChain() as chain:
for p in chain.get_prices(chain.get_all_tokens())[:5]:
print(f"{p.token.symbol} price: {p.price}")
ETH price: 2553.3386872068204
VELO price: 0.06543596476209321
RED price: 0.12055408976396115
USDC price: 1.0
WETH price: 2553.3386872068204
ETH price: 2553.3386872068204
VELO price: 0.06543596476209321
RED price: 0.12055408976396115
USDC price: 1.0
WETH price: 2553.3386872068204
from sugar.chains import AsyncOPChain, OPChain
async with AsyncOPChain() as chain:
pools = await chain.get_pools()
usdc_velo = next(iter([p for p in pools if p.token0.token_address == OPChain.usdc and p.token1.token_address == OPChain.velo]), None)
print(f"{usdc_velo.symbol}")
print("-----------------------")
print(f"Volume: {usdc_velo.token0_volume} {usdc_velo.token0.symbol} | {usdc_velo.token1_volume} {usdc_velo.token1.symbol} | ${usdc_velo.volume}")
print(f"Fees: {usdc_velo.token0_fees.amount} {usdc_velo.token0.symbol} | {usdc_velo.token1_fees.amount} {usdc_velo.token1.symbol} | ${usdc_velo.total_fees}")
print(f"TVL: {usdc_velo.reserve0.amount} {usdc_velo.token0.symbol} | {usdc_velo.reserve1.amount} {usdc_velo.token1.symbol} | ${usdc_velo.tvl}")
print(f"APR: {usdc_velo.apr}%")
with OPChain() as chain:
pools = chain.get_pools()
usdc_velo = next(iter([p for p in pools if p.token0.token_address == OPChain.usdc and p.token1.token_address == OPChain.velo]), None)
print(f"{usdc_velo.symbol}")
print("-----------------------")
print(f"Volume: {usdc_velo.token0_volume} {usdc_velo.token0.symbol} | {usdc_velo.token1_volume} {usdc_velo.token1.symbol} | ${usdc_velo.volume}")
print(f"Fees: {usdc_velo.token0_fees.amount} {usdc_velo.token0.symbol} | {usdc_velo.token1_fees.amount} {usdc_velo.token1.symbol} | ${usdc_velo.total_fees}")
print(f"TVL: {usdc_velo.reserve0.amount} {usdc_velo.token0.symbol} | {usdc_velo.reserve1.amount} {usdc_velo.token1.symbol} | ${usdc_velo.tvl}")
print(f"APR: {usdc_velo.apr}%")
vAMM-USDC/VELO
-----------------------
Volume: 756749.1011111111 USDC | 13151147.940511389 VELO | $1637676.1540950162
Fees: 6810.74191 USDC | 118360.3314646025 VELO | $14739.085386855146
TVL: 2286090.488682 USDC | 35949447.85712064 VELO | $4700011.161312506
APR: 28.920762224848183%
vAMM-USDC/VELO
-----------------------
Volume: 756749.1011111111 USDC | 13151147.940511389 VELO | $1637675.781948628
Fees: 6810.74191 USDC | 118360.3314646025 VELO | $14739.082037537652
TVL: 2286090.488682 USDC | 35949447.85712064 VELO | $4700010.093279505
APR: 28.92076222484818%
In order to deposit, make sure spender’s account’s private key is
provided via SUGAR_PK
env var. Here’s how you can deposit
vAMM-USDC/AERO
from sugar.chains import AsyncBaseChain
from sugar.deposit import Deposit
async with AsyncBaseChain() as chain:
pools = await chain.get_pools()
pools = list(filter(lambda x: "vAMM-USDC" in x.symbol and "AERO" in x.symbol, pools))
# 0.02 USDC
await chain.deposit(Deposit(pools[0], 0.02))
Full list of configuration parameters for Sugar. Chain IDs can be found
here. Sugar uses decimal versions: Base is
8453
, OP is 10
.
config | env | default value |
---|---|---|
native_token_symbol | ETH | |
native_token_decimals | 18 | |
wrapped_native_token_addr | SUGAR_WRAPPED_NATIVE_TOKEN_ADDR_<CHAIN_ID> |
chain specific |
rpc_uri | SUGAR_RPC_URI_<CHAIN_ID> |
chain specific |
sugar_contract_addr | SUGAR_CONTRACT_ADDR_<CHAIN_ID> |
chain specific |
slipstream_contract_addr | SUGAR_SLIPSTREAM_CONTRACT_ADDR_<CHAIN_ID> |
chain specific |
nfpm_contract_addr | SUGAR_NFPM_CONTRACT_ADDR |
chain specific |
price_oracle_contract_addr | SUGAR_PRICE_ORACLE_ADDR_<CHAIN_ID> |
chain specific |
router_contract_addr | SUGAR_ROUTER_CONTRACT_ADDR_<CHAIN_ID> |
chain specific |
token_addr | SUGAR_TOKEN_ADDR_<CHAIN_ID> |
chain specific |
stable_token_addr | SUGAR_STABLE_TOKEN_ADDR_<CHAIN_ID> |
chain specific |
connector_tokens_addrs | SUGAR_CONNECTOR_TOKENS_ADDRS_<CHAIN_ID> |
chain specific |
price_batch_size | SUGAR_PRICE_BATCH_SIZE |
40 |
price_threshold_filter | SUGAR_PRICE_THRESHOLD_FILTER |
10 |
pool_page_size | SUGAR_POOL_PAGE_SIZE |
500 |
pagination_limit | SUGAR_PAGINATION_LIMIT |
2000 |
In order to write to Sugar contracts, you need to set your wallet
private key using env var SUGAR_PK
You can override specific settings in 2 ways:
- by setting corresponding env var:
SUGAR_RPC_URI_10=https://myrpc.com
- in code:
from sugar.chains import OPChain
async with OPChain(rpc_uri="https://myrpc.com") as chain:
...
python3 -m venv env
source env/bin/activate
pip install nbdev pre-commit
pip install -e '.[dev]'
pre-commit install