@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
79 lines • 2.77 kB
TypeScript
/**
* @purpose Simplified closeContract instruction wrapper
*
* Thin convenience wrapper around Codama-generated closeContract instruction.
* Closes a contract with no active rentals and claims remaining payments.
*/
import { type Address } from '@solana/kit';
import { type SdkConfig } from '../utils/config';
import { type UniversalSigner } from '../utils/signer';
import { prepareInstructions } from '../utils/instructions';
/**
* Parameters for closing a rental contract
*/
export interface CloseContractParams {
/**
* Contract owner (must be the original owner)
* Accepts string address, web3.js Keypair, or @solana/kit signer
*/
owner: UniversalSigner;
/**
* Contract address to close (optional - derived from fleet PDA if not provided)
* Either contract or fleet must be provided
* NOTE: If using contract only, it must already exist (will be fetched to get fleet)
*/
contract?: Address | string;
/**
* SAGE fleet address (optional - fetched from contract if not provided)
* Either contract or fleet must be provided
* RECOMMENDED: Use fleet for idempotent behavior (contract created if needed)
*/
fleet?: Address | string;
/**
* SAGE program address (optional - uses config default if not provided)
*/
sageProgram?: Address | string;
/**
* Borrower address for the queued rental (optional - auto-fetched if not provided)
* Only needed when a queued rental exists
*/
queuedBorrower?: Address | string;
/**
* Sets compute units to allocate for the transaction.
* @example 400000
*/
computeUnits?: number;
}
/**
* Close a rental contract and refund rent to the owner. Idempotent —
* recovers cleanly from partial prior closes. When no rental is active,
* the contract's automation thread is closed in the same transaction.
*
* @param params - Contract closing parameters
* @param config - Optional SDK configuration overrides
* @returns Kit instruction (or web3.js if PublicKey in config)
*
* @example
* ```typescript
* // Option 1: Provide fleet only (RECOMMENDED - idempotent)
* const ix = await closeContract({
* owner: wallet,
* fleet: fleetAddress
* });
*
* // Option 2: Provide contract only (contract MUST exist)
* const ix2 = await closeContract({
* owner: wallet,
* contract: contractAddress
* });
*
* // Option 3: Provide both (most explicit, no fetching)
* const ix3 = await closeContract({
* owner: wallet,
* fleet: fleetAddress,
* contract: contractAddress
* });
* ```
*/
export declare function closeContract(params: CloseContractParams, config?: Partial<SdkConfig>): Promise<ReturnType<typeof prepareInstructions>>;
//# sourceMappingURL=closeContract.d.ts.map