-
Notifications
You must be signed in to change notification settings - Fork 18
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
Improve token generation using Multicall, Make it typescript safe, enhance logic #405
Conversation
Co-authored-by: Leandro <[email protected]>
@@ -126,30 +126,42 @@ export async function generateBridgedList(params: GenerateBridgedListParams): Pr | |||
|
|||
|
|||
// Create a Map of symbols to the additional tokens to add | |||
const tokenInfoBySymbol = tokensToAdd.reduce((acc, token) => { | |||
const onchainInfoBySymbol = tokensToAdd.reduce((acc, token) => { | |||
if (!token.symbol) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might token.address
also be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it can't be. Its a mandatory field
return tokenInfos | ||
} | ||
|
||
const erc20Contract = new Contract(tokenAddresses[0], ERC20_ABI, provider) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first, I was confused why the contract is created with the first token address?
But then I got why.
Anyway, we could move the interface to a global const:
export const ERC20_INTERFACE = new Contract('', ERC20_ABI).interface
@anxolin you still have this one pending |
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:
#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