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

ASA with Unicode character 🪙 in unit-name raises KeyError in pools.py #24

Closed
ipaleka opened this issue Jan 19, 2022 · 7 comments
Closed

Comments

@ipaleka
Copy link
Contributor

ipaleka commented Jan 19, 2022

pool = {
...
    liquidity_asset_name': liquidity_asset['params']['name']
...

A workaround for us is just a simple liquidity_asset['params'].get('name'), but you'd probably want a solution/name that includes the other ASA in the pool.

@fergalwalsh
Copy link
Contributor

Can you explain why you need this?
The name of the liquidity asset is enforced by the contracts so a liquidity asset without a name should be an impossibility.

@ipaleka
Copy link
Contributor Author

ipaleka commented Jan 19, 2022

I have to admit that the code we use is a few months old and we have used it to check is there a liquidity pool created for a given pair of ASA.

Is there some better method for us to retrieve such information?

@fergalwalsh
Copy link
Contributor

fergalwalsh commented Jan 19, 2022

Ah I see. It would still be odd if this was the first line to raise an error in that case though.

If a pool exists then pool.exist is True, else None
e.g

pool = client.fetch_pool(5, 0)
pool.exists == None

pool = client.fetch_pool(31566704, 0)
pool.exists == True

Is there some better method for us to retrieve such information?

Another way is to use Tinyman's analytics APIs to retrieve a list of pools or to follow the chain for pool creations and verify their integrity by comparing addresses using this SDK. That's what the analytics backend does.

@ipaleka
Copy link
Contributor Author

ipaleka commented Jan 19, 2022

Ah I see. It would still be odd if this was the first line to raise an error in that case though.

This is our original code:

    asset1 = tinyman_client.fetch_asset(asset1_id)
    asset2 = tinyman_client.fetch_asset(asset2_id)
    pool = tinyman_client.fetch_pool(asset1, asset2)

    if not pool.exists:

And it raises KeyError on the third line above.

Another way is to use Tinyman's analytics APIs to retrieve a list of pools or to follow the chain for pool creations and verify their integrity by comparing addresses using this SDK. That's what the analytics backend does.

I think we'd rather stick to "Simple is better than complex." and "Easier to ask for forgiveness than permission.". :)

try:
    pool = tinyman_client.fetch_pool(asset1, asset2)
except KeyError:
    #...  

@ipaleka
Copy link
Contributor Author

ipaleka commented Jan 19, 2022

Sorry, the title is misleading, it's not an empty unit name, it's the Unicode character in the unit name that causes this:

https://algoexplorer.io/tx/QJGZVVSTOTAISJFU5VC73GPBEJ566LUQWRQAQEREYT7KPSP5HOIQ

>>> pool = client.fetch_pool(403996358, 0)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/ipaleka/dev/venvs/asa/lib/python3.9/site-packages/tinyman/v1/client.py", line 20, in fetch_pool
    return Pool(self, asset1, asset2, fetch=fetch)
  File "/home/ipaleka/dev/venvs/asa/lib/python3.9/site-packages/tinyman/v1/pools.py", line 142, in __init__
    asset_a = client.fetch_asset(asset_a)
  File "/home/ipaleka/dev/venvs/asa/lib/python3.9/site-packages/tinyman/v1/client.py", line 25, in fetch_asset
    asset.fetch(self.algod)
  File "/home/ipaleka/dev/venvs/asa/lib/python3.9/site-packages/tinyman/assets.py", line 27, in fetch
    self.unit_name = params['unit-name']
KeyError: 'unit-name'

@ipaleka ipaleka changed the title Algorand allows empty unit name for ASA and such ASA raises KeyError in pools.py ~~Algorand allows empty unit name for~~ ASA with Unicode character in unit-name 🪙 raises KeyError in pools.py Jan 19, 2022
@ipaleka ipaleka changed the title ~~Algorand allows empty unit name for~~ ASA with Unicode character in unit-name 🪙 raises KeyError in pools.py ASA with Unicode character 🪙 in unit-name raises KeyError in pools.py Jan 19, 2022
@AtlasPilotPuppy
Copy link

The actual issue seems to be in algod.asset_info not being able to parse unicode.

@gokselcoban
Copy link
Contributor

I couldn't reproduce the issue with the latest versions of Tinyman and Algo SDK. Looks like the issue is resolved. Thank you for reporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants