UNPKG

@wuwei-labs/srsly

Version:
145 lines 5.17 kB
/** * @purpose Simplified createContract instruction wrapper * * Thin convenience wrapper around Codama-generated createContract instruction. * Handles parameter conversion and optional web3.js compatibility. */ import { type Address } from '@solana/kit'; import { type SdkConfig } from '../utils/config'; import { type UniversalSigner } from '../utils/signer'; import { type AmountParam } from '../params/amount'; import { type DurationParam } from '../params/duration'; import { type ScheduleParam } from '../params/schedule'; import { type SolParam } from '../params/sol'; import { prepareInstructions } from '../utils/instructions'; /** * Parameters for creating a rental contract */ export interface CreateContractParams { /** * Fleet owner who will receive rental payments * Accepts string address, web3.js Keypair, or @solana/kit signer */ owner: UniversalSigner; /** * Fleet address to be rented out * Must be a valid Star Atlas SAGE fleet * The fleet's ownerProfile and gameId will be fetched automatically */ fleet: Address | string; /** * Rental rate per payment period. * Accepts a plain number / bigint (stardust), `{ atlas: number }`, or * `{ stardust: number | bigint }`. * @example { atlas: 100 } // 100 ATLAS * @example { atlas: 1.5 } // 1.5 ATLAS * @example { stardust: 150_000_000 } // Explicit stardust (smallest unit) */ rate: AmountParam; /** * Minimum rental duration * @example { hours: 1 } // 1 hour minimum * @example { days: 1 } // 1 day minimum * @example 3600 // 1 hour in seconds */ durationMin?: DurationParam; /** * Maximum rental duration * @example { days: 30 } // 30 day maximum * @example { months: 3 } // 3 month maximum * @example 2592000 // 30 days in seconds */ durationMax: DurationParam; /** * Owner's key index in SAGE * @default 0 */ ownerKeyIndex?: number; /** * Minimum cancellation delay required for borrowers. * Defaults to `durationMin` if omitted, so the borrower can never * exit a rental earlier than the contract's own minimum lease window. * Set explicitly to allow earlier (or later) cancellation. * @example { hours: 0 } // Allow instant cancellation * @example { hours: 1 } // Minimum 1 hour delay * @example { days: 1 } // Minimum 1 day delay * @default * ```ts * durationMin // matches the contract's minimum rental duration * ``` */ cancelDelayMin?: DurationParam; /** * Whether reservations are disabled for this contract * When true, other borrowers cannot reserve this contract. * Set to false to enable the reservation system. * @default true */ reservationsDisabled?: boolean; /** * Number of contests that must accumulate before the contract rate * auto-increments by `capture_rate_bps`. Owner-tunable per contract. * * - `0` disables capture-rate entirely (rate stays fixed forever). * - `1..=10` enables it with the chosen sensitivity. * * @default 1 */ contestedThreshold?: number; /** * Enable contract automation thread. * When true, bundles createContractThread into the same transaction. * Set to false for manual-mode contracts without automation. * @default true */ automated?: boolean; /** * Payment processing frequency — required when automated is true * @example 'hourly' * @example '@daily' * @example '0 0 6 * * *' — every day at 6am * @default '@daily' */ paymentsFreq?: ScheduleParam; /** * Additional SOL preload for thread execution fees (on top of 0.04 SOL base). * Only used when automated is true. When omitted, the SDK preloads * enough lamports to cover ~1 year of `@daily` cron ticks. * Accepts a plain number / bigint (lamports), `{ sol: number }`, or * `{ lamports: number | bigint }`. * @example { sol: 0.1 } // 0.1 SOL extra * @example { lamports: 50_000_000 } * @default * ```ts * { sol: 0.00219 } // ~1 year of `@daily` triggers * ``` */ threadLamports?: SolParam; /** * Sets compute units to allocate for the transaction. * @example 400000 */ computeUnits?: number; } /** * List a Star Atlas fleet for rent. Sets the per-period rate, allowed * duration window, fee, and (optionally) automation parameters. * * @param params - Contract creation parameters * @param config - Optional SDK configuration overrides * @returns Kit instruction (or web3.js if PublicKey in config) * * @example * ```typescript * // With global config - auto-fetch ownerProfile and gameId from fleet * setSdkConfig({ network: 'atlasnet' }); * const ix = await createContract({ * owner: wallet, * fleet: fleetAddress, * rate: 100, * durationMax: { days: 30 } * }); * ``` */ export declare function createContract(params: CreateContractParams, config?: Partial<SdkConfig>): Promise<ReturnType<typeof prepareInstructions>>; //# sourceMappingURL=createContract.d.ts.map