UNPKG

@wuwei-labs/srsly

Version:
78 lines 2.87 kB
/** * @purpose Simplified createConfig instruction wrapper * * Thin convenience wrapper around Codama-generated createConfig instruction. * One-time creation of the global program configuration. */ import { address } from '@solana/kit'; import { getCreateConfigInstructionAsync } from '../generated/codama/instructions'; import { mergeConfig, getAddresses } from '../utils/config'; import { toTransactionSigner } from '../utils/signer'; import { prepareInstructions } from '../utils/instructions'; /** * One-time initialization of the global program config. Required before * any other instruction can run. * * @param params - Configuration creation parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) * * @example * ```typescript * // Create with default authority * const ix = await createConfig({ * vault: vaultAddress, * vaultTokenAccount: vaultTokenAccountAddress * }); * * // Create with custom authority * const ix2 = await createConfig({ * authority: adminWallet, * vault: vaultAddress, * vaultTokenAccount: vaultTokenAccountAddress * }); * ``` */ export async function createConfig(params, config) { // Merge config const finalConfig = mergeConfig(config); // Validate required params if (!params.vault) { throw new Error('vault is required'); } if (!params.vaultTokenAccount) { throw new Error('vaultTokenAccount is required'); } if (!params.lookupTable) { throw new Error('lookupTable is required'); } if (params.recentSlot === undefined || params.recentSlot === null) { throw new Error('recentSlot is required'); } // Get network-specific addresses const addresses = getAddresses(config); const atlasMint = address(addresses.atlasMint); const programAddress = address(addresses.srsly); const sageProgram = address(addresses.sage); const antegenProgram = address(addresses.antegen); // Convert authority to TransactionSigner const authoritySigner = toTransactionSigner(params.authority); // Call Codama-generated instruction // srslyProgram is passed automatically as programAddress for vault derivation const kitInstruction = await getCreateConfigInstructionAsync({ authority: authoritySigner, mint: atlasMint, vault: address(params.vault), vaultTokenAccount: address(params.vaultTokenAccount), lookupTable: address(params.lookupTable), sageProgram, antegenProgram, srslyProgram: programAddress, recentSlot: BigInt(params.recentSlot), }, { programAddress }); return prepareInstructions(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=createConfig.js.map