Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lapismyt committed May 14, 2024
1 parent 4d33161 commit f89f33b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "stonfi"
version = "0.9"
version = "0.10"
description = "Async Python SDK for StonFi DEX"
authors = [
{name = "LapisMYT (Nikita Gavrilin)", email = "[email protected]"}
Expand Down
2 changes: 1 addition & 1 deletion stonfi/contracts/dex/v1/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def get_expected_outputs(self,
amount: int,
jetton_wallet: Union[Address, str],
provider: LiteClientLike):

jetton_wallet = Address(jetton_wallet) if isinstance(jetton_wallet, str) else jetton_wallet
stack = await provider.run_get_method(self.address,
'get_expected_outputs',
[amount,
Expand Down
13 changes: 8 additions & 5 deletions stonfi/http/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ class HTTPAPI:
def __init__(self,
base_url: str = 'https://api.ston.fi/'):
self.base_url = base_url.rstrip('/')
self.session = aiohttp.ClientSession()

async def get(self, path: str, **kwargs):
async with self.session.get(self.base_url + path, params=kwargs) as resp:
return await resp.json()
async with aiohttp.ClientSession() as session:
async with session.get(self.base_url + path, params=kwargs) as resp:
result = await resp.json()
return result

async def post(self, path: str, **kwargs):
async with self.session.post(self.base_url + path, json=kwargs) as resp:
return await resp.json()
async with aiohttp.ClientSession() as session:
async with session.post(self.base_url + path, json=kwargs) as resp:
result = await resp.json()
return result

async def get_assets(self):
return await self.get('/v1/assets')
Expand Down
4 changes: 3 additions & 1 deletion stonfi/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from stonfi import HTTPAPI, PoolV1
import asyncio
from pytoniq import Address, LiteClientLike
from async_lru import alru_cache

@alru_cache
async def get_jetton_decimals(jetton_address: str | Address) -> int | None:
http_api = HTTPAPI()
jetton_address = jetton_address.to_str() if isinstance(jetton_address, Address) else jetton_address
Expand All @@ -15,7 +17,7 @@ async def get_pool_readiness(pool: PoolV1, provider: LiteClientLike):
state = await provider.get_account_state(pool.address)
if not state.is_active():
return False
data = await pool.get_data()
data = await pool.get_data(provider)
for x in ['reserve0', 'reserve1']:
if not data[x] > 0:
return False
Expand Down

0 comments on commit f89f33b

Please sign in to comment.