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:
The CSV might omit some values. The way it was defined the CSV can omit things like the symbols, or the decimals, or the images
TokenInfo has most of the fields as required, so the types won't make you handle the undefined or empty string case.
The CSV is a text file, so it reads all the fields as strings, but then we were casting it to TokenInfo so the typechecker was not realising the chainId and the decimals where being passed as strings when they should be numbers.
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.
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
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:
TokenInfo
has most of the fields as required, so the types won't make you handle the undefined or empty string case.TokenInfo
so the typechecker was not realising thechainId
and thedecimals
where being passed as strings when they should be numbers.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