@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
131 lines • 4.48 kB
JavaScript
;
/**
* @purpose Centralized program and token addresses for different networks
*
* Single source of truth for all Solana program addresses used by SRSLY.
* Supports mainnet-beta, devnet, and localnet environments.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ATLASNET_ADDRESSES = exports.MAINNET_ADDRESSES = exports.ATLASNET_GENESIS = exports.DEVNET_GENESIS = exports.MAINNET_GENESIS = void 0;
exports.resolveGenesisHash = resolveGenesisHash;
exports.getProgramAddresses = getProgramAddresses;
exports.getNetworkAddresses = getNetworkAddresses;
exports.isValidProgramSet = isValidProgramSet;
exports.isValidNetwork = isValidNetwork;
const codama_1 = require("../generated/codama");
const constants_1 = require("../pda/constants");
/**
* Genesis hash constants — canonical chain identifiers
*/
exports.MAINNET_GENESIS = '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d';
exports.DEVNET_GENESIS = 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG';
exports.ATLASNET_GENESIS = 'Ccod9gttTtZWqCeMgyTW3iCSoPLjkptAGsBUeP2CpchR';
const ALIAS_TO_GENESIS = {
mainnet: exports.MAINNET_GENESIS,
atlasnet: exports.ATLASNET_GENESIS,
holosim: exports.ATLASNET_GENESIS,
localnet: exports.ATLASNET_GENESIS,
};
/**
* Antegen program address (same across all networks)
*/
const ANTEGEN_PROGRAM = constants_1.ANTEGEN_THREAD_PROGRAM;
/**
* Mainnet addresses (production Star Atlas)
*/
const MAINNET_ADDRESSES = {
srsly: codama_1.SRSLY_PROGRAM_ADDRESS,
sage: 'SAGE2HAwep459SNq61LHvjxPk4pLPEJLoMETef7f7EE',
antegen: ANTEGEN_PROGRAM,
atlasMint: 'ATLASXmbPQxBUYbxPsV97usA3fPQYEqzQBUHgiFCUsXx',
profileFaction: 'pFACSRuobDmvfMKq1bAzwj27t6d2GJhSCHb1VcfnRmq',
gameId: 'GAMEC7U7cqmFFaRow33j1LwuV8u4YhAS1mJ5Dqjnar2k',
};
exports.MAINNET_ADDRESSES = MAINNET_ADDRESSES;
/**
* Atlasnet addresses (Star Atlas testnet/devnet)
*/
const ATLASNET_ADDRESSES = {
srsly: codama_1.SRSLY_PROGRAM_ADDRESS,
sage: 'SAgEeT8u14TE69JXtanGSgNkEdoPUcLabeyZD2uw8x9',
antegen: ANTEGEN_PROGRAM,
atlasMint: '6PhneWhbN4R3nFutrRUVnE3sNgRsFS6yPrjRC29mMWnv',
profileFaction: 'pFACzkX2eSpAjDyEohD6i3VRJvREtH9ynbtM1DwVFsj',
gameId: 'GAmEqxNYaUqLmLkXGhzUvv4Ud8FotnWPLj6ChdBkUh9j',
};
exports.ATLASNET_ADDRESSES = ATLASNET_ADDRESSES;
/**
* Program address sets keyed by genesis hash (source of truth)
*/
const PROGRAM_ADDRESS_SETS = {
[exports.MAINNET_GENESIS]: MAINNET_ADDRESSES,
[exports.DEVNET_GENESIS]: ATLASNET_ADDRESSES,
[exports.ATLASNET_GENESIS]: ATLASNET_ADDRESSES,
};
/**
* Resolve a program set input (alias or genesis hash) to a genesis hash
*
* @param programSet - Named alias or genesis hash string
* @returns Genesis hash string
*/
function resolveGenesisHash(programSet) {
// Check if it's a named alias
if (programSet in ALIAS_TO_GENESIS) {
return ALIAS_TO_GENESIS[programSet];
}
// Otherwise treat as genesis hash directly
return programSet;
}
/**
* Get addresses for a specific program set
*
* @param programSet - Program set identifier ('mainnet', 'atlasnet', or 'localnet')
* @returns Program-specific addresses
* @throws Error if program set is unknown
*
* @example
* ```typescript
* const addresses = getProgramAddresses('mainnet');
* console.log(addresses.atlasMint); // 'ATLASXmbP...'
*
* const testnetAddresses = getProgramAddresses('atlasnet');
* console.log(testnetAddresses.sage); // 'SAGEqqFew...'
* ```
*/
function getProgramAddresses(programSet) {
const genesisHash = resolveGenesisHash(programSet);
const addresses = PROGRAM_ADDRESS_SETS[genesisHash];
if (!addresses) {
// Unknown genesis hash — fall back to devnet addresses
return PROGRAM_ADDRESS_SETS[exports.DEVNET_GENESIS];
}
return addresses;
}
/**
* @deprecated Use getProgramAddresses instead
*/
function getNetworkAddresses(network) {
return getProgramAddresses(network);
}
/**
* Check if a program set is valid
*
* @param programSet - Program set to validate
* @returns True if program set is supported
*/
function isValidProgramSet(programSet) {
// Accept named aliases
if (programSet in ALIAS_TO_GENESIS)
return true;
// Accept known genesis hashes
if (programSet in PROGRAM_ADDRESS_SETS)
return true;
return false;
}
/**
* @deprecated Use isValidProgramSet instead
*/
function isValidNetwork(network) {
return isValidProgramSet(network);
}
//# sourceMappingURL=addresses.js.map