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

Create token-specific entities #2309

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

Create token-specific entities #2309

wants to merge 3 commits into from

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Jan 28, 2025

Summary

Resolves #2307

We currently parse native, ERC-20 and ERC-721 tokens as one, meaning we cannot safely assume decimals should they not exist.

This splits TokenSchema into three specific schemas per token type with the following assumptions:

  • Native tokens always have defined decimals.
  • ERC-20 tokens have 0 decimals, should they not be specified.
  • ERC-721 tokens have 0 decimals, should they not be specified.

From the parsed token, token-specific entities are mapped for Swagger.

Changes

  • Split TokenSchema into NativeTokenSchema, Erc20TokenSchema and Erc721TokenSchema
  • Infer types and create respective builders for each
  • Map Swagger-specific entities according to types
  • Update tests accordingly

@iamacook iamacook self-assigned this Jan 28, 2025
@iamacook iamacook requested a review from a team as a code owner January 28, 2025 15:57
Comment on lines +17 to +27
type: z.literal('NATIVE_TOKEN'),
decimals: z.number(),
});

const Erc20TokenSchema = BaseTokenSchema.extend({
type: z.literal('ERC20'),
decimals: z.number().catch(DEFAULT_ERC20_DECIMALS),
});

const Erc721TokenSchema = BaseTokenSchema.extend({
type: z.literal('ERC721'),
Copy link
Member Author

Choose a reason for hiding this comment

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

String types are now preferred due to type complaints when using different enums from the domain vs. route layers.

@iamacook iamacook marked this pull request as draft January 28, 2025 15:58
Erc20 = 'ERC20',
NativeToken = 'NATIVE_TOKEN',
}
import { z } from 'zod';
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the "core" change, from which everything else implemented.

@iamacook iamacook marked this pull request as ready for review February 11, 2025 18:29
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.

Create native, ERC-20 and ERC-721 entities
1 participant