-
Notifications
You must be signed in to change notification settings - Fork 300
feat(sdk-coin-sol): token 2022 transfer hook implementation #7103
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 all commits
Commits
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,42 @@ | ||
| import type { Token2022Config } from '../lib/token2022Config'; | ||
|
|
||
| export const TOKEN_2022_STATIC_CONFIGS: Token2022Config[] = [ | ||
| { | ||
| mintAddress: '4MmJVdwYN8LwvbGeCowYjSx7KoEi6BJWg8XXnW4fDDp6', | ||
| symbol: 'tbill', | ||
| name: 'OpenEden T-Bills', | ||
| decimals: 6, | ||
| programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', | ||
| transferHook: { | ||
| programId: '48n7YGEww7fKMfJ5gJ3sQC3rM6RWGjpUsghqVfXVkR5A', | ||
| authority: 'CPNEkz5SaAcWqGMezXTti39ekErzMpDCtuPMGw9tt4CZ', | ||
| extraAccountMetas: [ | ||
| { | ||
| pubkey: '4zDeEh2D6K39H8Zzn99CpQkaUApbpUWfbCgqbwgZ2Yf', | ||
| isSigner: false, | ||
| isWritable: true, | ||
| }, | ||
| ], | ||
| extraAccountMetasPDA: '9sQhAH7vV3RKTCK13VY4EiNjs3qBq1srSYxdNufdAAXm', | ||
| }, | ||
| }, | ||
| { | ||
| mintAddress: '3BW95VLH2za2eUQ1PGfjxwMbpsnDFnmkA7m5LDgMKbX7', | ||
| symbol: 't1test', | ||
| name: 'T1TEST', | ||
| decimals: 6, | ||
| programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', | ||
| transferHook: { | ||
| programId: '2Te6MFDwstRP2sZi6DLbkhVcSfaQVffmpbudN6pmvAXo', | ||
| authority: 'BLZvvaQgPUvL2RWoJeovudbHMhqH4S3kdenN5eg1juDr', | ||
| extraAccountMetas: [ | ||
| { | ||
| pubkey: '4zDeEh2D6K39H8Zzn99CpQkaUApbpUWfbCgqbwgZ2Yf', | ||
| isSigner: false, | ||
| isWritable: true, | ||
| }, | ||
| ], | ||
| extraAccountMetasPDA: 'FR5YBEisx8mDe4ruhWKmpH5nirdJopj4uStBAVufqjMo', | ||
| }, | ||
| }, | ||
| ]; |
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,85 @@ | ||
| /** | ||
| * Token-2022 Configuration for Solana tokens with transfer hooks | ||
| * This file contains static configurations for Token-2022 tokens to avoid RPC calls | ||
| * when building transfer transactions with transfer hooks. | ||
| */ | ||
|
|
||
| import { TOKEN_2022_STATIC_CONFIGS } from '../config/token2022StaticConfig'; | ||
|
|
||
| /** | ||
| * Interface for extra account metadata needed by transfer hooks | ||
| */ | ||
| export interface ExtraAccountMeta { | ||
| /** The public key of the account */ | ||
| pubkey: string; | ||
| /** Whether the account is a signer */ | ||
| isSigner: boolean; | ||
| /** Whether the account is writable */ | ||
| isWritable: boolean; | ||
| /** Optional seed for PDA derivation */ | ||
| seeds?: Array<{ | ||
| /** Literal seed value or instruction account index reference */ | ||
| value: string | number; | ||
| /** Type of seed: 'literal' for string/buffer, 'accountKey' for instruction account index */ | ||
| type: 'literal' | 'accountKey'; | ||
| }>; | ||
| } | ||
|
|
||
| /** | ||
| * Interface for transfer hook configuration | ||
| */ | ||
| export interface TransferHookConfig { | ||
| /** The transfer hook program ID */ | ||
| programId: string; | ||
| /** The transfer hook authority */ | ||
| authority: string; | ||
| /** Extra account metas required by the transfer hook */ | ||
| extraAccountMetas: ExtraAccountMeta[]; | ||
| /** The PDA address for extra account metas (cached) */ | ||
| extraAccountMetasPDA?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Interface for Token-2022 configuration | ||
| */ | ||
| export interface Token2022Config { | ||
| /** The mint address of the token */ | ||
| mintAddress: string; | ||
| /** Token symbol */ | ||
| symbol: string; | ||
| /** Token name */ | ||
| name: string; | ||
| /** Number of decimal places */ | ||
| decimals: number; | ||
| /** Program ID (TOKEN_2022_PROGRAM_ID) */ | ||
| programId: string; | ||
| /** Transfer hook configuration if applicable */ | ||
| transferHook?: TransferHookConfig; | ||
| /** Whether the token has transfer fees */ | ||
| hasTransferFees?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Token configurations map | ||
| * Key: mintAddress or symbol | ||
| */ | ||
| export const TOKEN_2022_CONFIGS: Record<string, Token2022Config> = {}; | ||
|
|
||
| TOKEN_2022_STATIC_CONFIGS.forEach((config) => { | ||
| TOKEN_2022_CONFIGS[config.mintAddress] = config; | ||
| TOKEN_2022_CONFIGS[config.symbol] = config; | ||
| }); | ||
|
|
||
| // Create symbol mappings for convenience | ||
| Object.values(TOKEN_2022_CONFIGS).forEach((config) => { | ||
| TOKEN_2022_CONFIGS[config.symbol] = config; | ||
| }); | ||
|
|
||
| /** | ||
| * Get token configuration by mint address | ||
| * @param mintAddress - The mint address of the token | ||
| * @returns Token configuration or undefined if not found | ||
| */ | ||
| export function getToken2022Config(mintAddress: string): Token2022Config | undefined { | ||
| return TOKEN_2022_CONFIGS[mintAddress]; | ||
| } |
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.