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

feat(build): save ckERC20 metadata #5043

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

AntonioVentilii
Copy link
Collaborator

@AntonioVentilii AntonioVentilii commented Mar 5, 2025

Motivation

Ideally we would like to have the ckERC20 metadata already in the code base, to avoid fetching them at runtime, for each user. So, we duplicate what we do for the SNS tokens and fetch and save the metadata in the scripts that build the ckERC20 JSON file.

The next step will be to use such data and remove the fetching in the code.

Changes

  • Create some utils for building tokens, for example to get metadata and to create an agent.
  • Create more types/schemas to have env ck ERC20 tokens with metadata and icons.
  • Fetch metadata when building the orchestrators info.
  • Split the metadata that we need from the icons.
  • Change method saveTokenLogo to simply use the data already fetched.

Tests

I first injected a few changes in tokens.ckerc20.json and then run the script on this PR.

@AntonioVentilii AntonioVentilii marked this pull request as ready for review March 5, 2025 21:06
@AntonioVentilii AntonioVentilii requested a review from a team as a code owner March 5, 2025 21:06

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR introduces changes to include ckERC20 token metadata directly in the codebase, avoiding runtime metadata fetching by leveraging build-time scripts and schema updates.

  • Introduce utilities in build.tokens.utils.ts to fetch and load token metadata.
  • Update build.tokens.ckerc20.ts to accumulate tokens and icons with metadata and adjust logo saving.
  • Enhance token and metadata schemas and types to support the new metadata structure.

Reviewed Changes

File Description
scripts/build.tokens.utils.ts Adds utility functions to fetch and load token metadata
scripts/build.tokens.ckerc20.ts Refactors orchestrator info building & updates token logo saving
src/frontend/src/env/schema/env-token-ckerc20.schema.ts Updates schemas to merge token metadata with icons
src/frontend/src/env/types/env-icrc-token.ts Adjusts type definitions for token metadata with icon
src/frontend/src/env/schema/env-icrc-token.schema.ts Merges metadata and icon schemas into one combined schema
src/frontend/src/env/types/env-token-ckerc20.ts Adds new type for tokens with metadata based on updated schema

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

scripts/build.tokens.ckerc20.ts:113

  • [nitpick] Using an async reduce can obscure error handling and reduce code clarity. Consider refactoring this accumulate logic to use an explicit for-of loop to improve maintainability.
return await Object.entries(tokens).reduce<Promise<TokensAndIcons>>(

scripts/build.tokens.ckerc20.ts:161

  • This line assumes a fixed format for logoData. Adding validation or error handling for the split operation could prevent potential runtime errors if the data format changes.
const [encoding, encodedStr] = logoData.split(';')[1].split(',');
@AntonioVentilii AntonioVentilii requested a review from Copilot March 6, 2025 14:22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR integrates ckERC20 token metadata into the codebase to avoid runtime fetching by enriching token data and icons during build time. Key changes include:

  • Refactoring the build tokens script to load metadata and combine tokens with associated icons.
  • Updating and merging schemas and types to support token metadata.
  • Adding a new tokens utility module to encapsulate agent creation and metadata loading functions.

Reviewed Changes

File Description
scripts/build.tokens.ckerc20.ts Updated the orchestrator info builder to load metadata and icons
src/frontend/src/env/schema/env-token-ckerc20.schema.ts Merged metadata into the ckERC20 token schema
src/frontend/src/env/schema/env-icrc-token.schema.ts Added a merged metadata with icon schema
src/frontend/src/env/types/env-token-ckerc20.ts Introduced type for tokens with metadata
src/frontend/src/env/types/env-icrc-token.ts Updated type definition to use the merged metadata schema
scripts/build.tokens.utils.ts New module for creating the agent and loading token metadata

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

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

Successfully merging this pull request may close these issues.

1 participant