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

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

Merged
merged 5 commits into from
Jun 25, 2024

Conversation

anxolin
Copy link
Contributor

@anxolin anxolin commented Jun 5, 2024

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.

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

yarn coingeckoToArbitrumOneList

@anxolin anxolin changed the title Enhance logic Improve token generation using Multicall, Make it typescript safe, enhance logic Jun 5, 2024
src/scripts/generateBridgeList.ts Show resolved Hide resolved
src/scripts/generateBridgeList.ts Show resolved Hide resolved
src/scripts/utils/tokens.ts Outdated Show resolved Hide resolved
src/scripts/utils/tokens.ts Outdated Show resolved Hide resolved
src/scripts/utils/tokens.ts Show resolved Hide resolved
src/scripts/utils/tokens.ts Outdated Show resolved Hide resolved
src/scripts/utils/tokens.ts Outdated Show resolved Hide resolved
@anxolin anxolin requested review from alfetopito and a team June 6, 2024 09:33
@@ -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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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

src/scripts/utils/tokens.ts Outdated Show resolved Hide resolved
@alfetopito
Copy link
Collaborator

@anxolin you still have this one pending

@alfetopito alfetopito merged commit dda62f8 into main Jun 25, 2024
5 checks passed
@alfetopito alfetopito deleted the enhance-logic branch June 25, 2024 08:47
@github-actions github-actions bot locked and limited conversation to collaborators Jun 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants