generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SDK helper to choose compression programs (#117)
* Add SDK helper to choose compression programs * Change variable name
- Loading branch information
Showing
4 changed files
with
82 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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,49 @@ | ||
import { Context, PublicKey } from '@metaplex-foundation/umi'; | ||
import { | ||
SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, | ||
SPL_NOOP_PROGRAM_ID, | ||
} from './generated'; | ||
|
||
export const MPL_ACCOUNT_COMPRESSION_PROGRAM_ID = | ||
'mcmt6YrQEMKw8Mw43FmpRLmf7BqRnFMKmAcbxE3xkAW' as PublicKey<'mcmt6YrQEMKw8Mw43FmpRLmf7BqRnFMKmAcbxE3xkAW'>; | ||
|
||
export const MPL_NOOP_PROGRAM_ID = | ||
'mnoopTCrg4p8ry25e4bcWA9XZjbNjMTfgYVGGEdRsf3' as PublicKey<'mnoopTCrg4p8ry25e4bcWA9XZjbNjMTfgYVGGEdRsf3'>; | ||
|
||
// Constants for known genesis blockhashes on Solana. | ||
const SOLANA_MAINNET_GENESIS_HASH = | ||
'5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d'; | ||
const SOLANA_DEVNET_GENESIS_HASH = | ||
'EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG'; | ||
const SOLANA_TESTNET_GENESIS_HASH = | ||
'4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY'; | ||
|
||
export type CompressionPrograms = { | ||
logWrapper: PublicKey; | ||
compressionProgram: PublicKey; | ||
}; | ||
|
||
export async function getCompressionPrograms( | ||
context: Pick<Context, 'programs' | 'eddsa' | 'rpc'> | ||
): Promise<CompressionPrograms> { | ||
const genesisHash = await context.rpc.call<string>('getGenesisHash'); | ||
|
||
// Determine if the genesis hash matches known clusters. | ||
const isSolanaCluster = [ | ||
SOLANA_MAINNET_GENESIS_HASH, | ||
SOLANA_DEVNET_GENESIS_HASH, | ||
SOLANA_TESTNET_GENESIS_HASH, | ||
].includes(genesisHash); | ||
|
||
// Return appropriate program IDs based on the cluster. | ||
if (isSolanaCluster) { | ||
return { | ||
logWrapper: SPL_NOOP_PROGRAM_ID, | ||
compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, | ||
}; | ||
} | ||
return { | ||
logWrapper: MPL_NOOP_PROGRAM_ID, | ||
compressionProgram: MPL_ACCOUNT_COMPRESSION_PROGRAM_ID, | ||
}; | ||
} |
This file contains 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 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 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