UNPKG

@wuwei-labs/srsly

Version:
54 lines 2.41 kB
"use strict"; /** * @purpose Simplified claimContract instruction wrapper * * Thin convenience wrapper around Codama-generated claimContract instruction. * Permissionless — anyone can trigger, but tokens always go to the owner's ATA. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.claimContract = claimContract; const kit_1 = require("@solana/kit"); const instructions_1 = require("../generated/codama/instructions"); const config_1 = require("../utils/config"); const signer_1 = require("../utils/signer"); const instructions_2 = require("../utils/instructions"); const config_2 = require("../accounts/config"); const contract_1 = require("../accounts/contract"); /** * Sweep a contract's accumulated ATLAS earnings into the owner's ATA. * Permissionless — anyone can trigger; funds always land at the owner's ATA. * * @param params - Contract claim parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) */ async function claimContract(params, config) { const finalConfig = (0, config_1.mergeConfig)(config); if (!params.payer) { throw new Error('payer is required'); } if (!params.contract) { throw new Error('contract is required'); } const payerSigner = (0, signer_1.toTransactionSigner)(params.payer); // Get atlasMint from on-chain config const configAccount = await (0, config_2.fetchConfig)(finalConfig.rpcUrl); const atlasMint = configAccount.data.atlasMint; const addresses = (0, config_1.getAddresses)(config); const programAddress = (0, kit_1.address)(addresses.srsly); // Fetch contract to get owner and contractTokenAccount const contractAccount = await (0, contract_1.fetchContract)(params.contract, finalConfig.rpcUrl); const contractAddress = (0, kit_1.address)(params.contract); const kitInstruction = await (0, instructions_1.getClaimContractInstructionAsync)({ payer: payerSigner, owner: contractAccount.data.owner, mint: atlasMint, contract: contractAddress, contractTokenAccount: contractAccount.data.managedTokenAccount, }, { programAddress }); return (0, instructions_2.prepareInstructions)(kitInstruction, { computeUnits: params.computeUnits, PublicKey: finalConfig.PublicKey, }); } //# sourceMappingURL=claimContract.js.map