@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
51 lines • 2.22 kB
JavaScript
/**
* @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.
*/
import { address } from '@solana/kit';
import { getClaimContractInstructionAsync } 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';
import { fetchContract } from '../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)
*/
export async function claimContract(params, config) {
const finalConfig = mergeConfig(config);
if (!params.payer) {
throw new Error('payer is required');
}
if (!params.contract) {
throw new Error('contract is required');
}
const payerSigner = toTransactionSigner(params.payer);
// 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);
// Fetch contract to get owner and contractTokenAccount
const contractAccount = await fetchContract(params.contract, finalConfig.rpcUrl);
const contractAddress = address(params.contract);
const kitInstruction = await getClaimContractInstructionAsync({
payer: payerSigner,
owner: contractAccount.data.owner,
mint: atlasMint,
contract: contractAddress,
contractTokenAccount: contractAccount.data.managedTokenAccount,
}, { programAddress });
return prepareInstructions(kitInstruction, {
computeUnits: params.computeUnits,
PublicKey: finalConfig.PublicKey,
});
}
//# sourceMappingURL=claimContract.js.map