-
Notifications
You must be signed in to change notification settings - Fork 71
refactor: split Token into BaseToken & Token #725
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8ba9808
refactor: split Token into BaseToken & Token
mkflow27 bce6a97
chore: lint
mkflow27 6636292
refactor: more Token -> BaseToken changes
mkflow27 0cd88f7
refactor: more type refactors Token -> BaseToken
mkflow27 655b6b1
refactor: more Token -> BaseToken refactors
mkflow27 5a1bd5c
chore: lint
mkflow27 e9bae09
refactor: more Token -> BaseToken
mkflow27 fba4dd1
refactor: add NativeToken
mkflow27 e92471e
refactor: complete Token removal
mkflow27 5269593
refactor: use Token & NativeToken (rename BaseToken back to Token)
mkflow27 466a34a
refactor: Token imports
mkflow27 cbdc4fa
refactor: undo more changes
mkflow27 f51af5f
chore: add changeset
mkflow27 202693b
refactor: import from src
mkflow27 4e9a781
refactor: rename function
mkflow27 3a7a569
refactor: use isWrapped helper
mkflow27 8082f25
refactor: use isWrapped helper
mkflow27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| "@balancer/sdk": major | ||
| --- | ||
|
|
||
| **WHAT**: Removed wrapped token functionality from the `Token` class and introduced a new `NativeToken` class to handle native tokens (like ETH) separately. | ||
|
|
||
| **WHY**: This change improves type safety and separation of concerns by distinguishing between ERC-20 tokens and native tokens, making the API more explicit and preventing confusion about token types. | ||
|
|
||
| **HOW**: Update your code by: | ||
| - Replace any usage of `Token` for native tokens with the new `NativeToken` class if using the wrapped functionality | ||
| - If not using any wrapped functionality, the `Token` can remain as is | ||
| - Import `NativeToken` from the SDK: `import { NativeToken } from '@balancer/sdk'` | ||
| - Use `NativeToken` for native token operations instead of `Token` with wrapped functionality |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { Address } from 'viem'; | ||
| import { Token } from './token'; | ||
|
|
||
| /** | ||
| * NativeToken extends BaseToken and adds mandatory wrapped token functionality | ||
| * This class is specifically designed for native tokens that always have a wrapped version | ||
| */ | ||
| export class NativeToken extends Token { | ||
| public readonly wrapped: Address; | ||
|
|
||
| public constructor( | ||
| chainId: number, | ||
| address: Address, | ||
| decimals: number, | ||
| wrapped: Address, | ||
| symbol?: string, | ||
| name?: string, | ||
| ) { | ||
| // Call parent constructor with core properties | ||
| super(chainId, address, decimals, symbol, name); | ||
|
|
||
| // Set wrapped address (always mandatory for native tokens) | ||
| this.wrapped = wrapped.toLowerCase() as Address; | ||
| } | ||
|
|
||
| public isWrappedEqual(token: NativeToken) { | ||
| return this.chainId === token.chainId && this.wrapped === token.wrapped; | ||
| } | ||
|
|
||
| public isWrapped(token: Token) { | ||
| return this.chainId === token.chainId && this.wrapped === token.address; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.