UNPKG

@wuwei-labs/srsly

Version:
41 lines 1.73 kB
/** * @purpose Simplified createBorrower instruction wrapper * * Thin convenience wrapper around Codama-generated createBorrower instruction. * Creates a BorrowerState PDA with managed token account for a borrower. */ import { address } from '@solana/kit'; import { getCreateBorrowerInstructionAsync } from '../generated/codama/instructions'; import { mergeConfig, getAddresses } from '../utils/config'; import { toTransactionSigner } from '../utils/signer'; import { prepareInstructions } from '../utils/instructions'; import { fetchConfig } from '../accounts/config'; /** * Initialize a borrower: a BorrowerState PDA plus a managed ATLAS ATA * used to hold reservation bid refunds and knockoff bonuses. * * @param params - Borrower creation parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) */ export async function createBorrower(params, config) { const finalConfig = mergeConfig(config); if (!params.borrower) { throw new Error('borrower is required'); } const borrowerSigner = toTransactionSigner(params.borrower); // Get atlasMint from on-chain config const configAccount = await fetchConfig(finalConfig.rpcUrl); const atlasMint = configAccount.data.atlasMint; const addresses = getAddresses(config); const programAddress = address(addresses.srsly); const kitInstruction = await getCreateBorrowerInstructionAsync({ borrower: borrowerSigner, mint: atlasMint, }, { programAddress }); return prepareInstructions(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=createBorrower.js.map