cowprotocol / token-lists

https://files.cow.fi/tokens/CowSwap.json
Apache License 2.0
3 stars 13 forks source link

Improve token generation using Multicall, Make it typescript safe, enhance logic #405

Closed anxolin closed 1 week ago

anxolin commented 1 month ago

This PR enhances a few aspects of the generation of the lists

Issues with the list generation

Yesterday, we had some issues with the list generated from the CSV files. This issues where derived by casting to TokenInfo the information from the CSV.

This has 2 important problems:

This PR acknowledge this, so it declares 2 new types, one is for the expected type of the row in the CSV, and another is to define a partial token info, which acknowledges the possibility we haven't found all the information for a token onchain. This way, we can handle the cases, and get typescript checks to ensure the list will be well-formed.

Multi-call

Additionally, there was the issue of performance and gas consumption. Before this PR we would get all the erc20 information from the additional tokens, just to fill any missing data. Each token would make 3 RPC call (one for symbol, one for name, one for decimals).

This PR makes use of multi-call and will send 3 RPC calls in parallel for all tokens.

Add missing images

Yesterday I added, as a shortcut some images in the resulting JSON list directly.

Ideally, I should have added that in the CSV and the re-generated the token list using the script. I didn't do that because the script was broken as described above and just took a shortcut.

See this PR: https://github.com/cowprotocol/token-lists/pull/401

In this PR I add the images into the CSV, this way I can make a check that the script will generate the same token list (I verified that the JSON has no changes)

Test

Run the code, make sure the token lists don't change after running the script

yarn coingeckoToArbitrumOneList
alfetopito commented 2 weeks ago

@anxolin you still have this one pending