@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
93 lines • 3.57 kB
TypeScript
/**
* @purpose SOL + ATLAS cost estimators for SRSLY protocol usage.
*
* Three quotes:
* - Owner setup (contract_create + contract_thread) — recoverable rents + infra + exec budget.
* - Borrower setup (borrower_create) — BorrowerState + managed ATA.
* - Per-rental (rental_accept) — SOL tx fee + ATLAS escrow + service fee.
*
* All functions use `rpc.getMinimumBalanceForRentExemption` so quotes reflect the
* target cluster's rent rate rather than hardcoded lamports.
*/
import type { Address } from '@solana/kit';
import { type SolParam } from '../params/sol';
export interface OwnerSetupCostOptions {
/**
* Execution budget preloaded into the thread on top of `MINIMUM_THREAD_FUNDING`.
* Defaults to `DEFAULT_EXECUTION_BUDGET` (~1 year daily cron).
*/
executionBudget?: SolParam;
/**
* Skip the 0.00204 SOL owner-ATA rent if the owner already has an ATLAS ATA.
* Defaults to `false` (charge it).
*/
ownerAtaExists?: boolean;
/** Override RPC for the rent-exemption lookup. */
rpcUrl?: string;
}
export interface OwnerSetupCostQuote {
/** Recoverable rents: ContractState + 2×RentalState + contract ATA (+ owner ATA). */
rentLamports: bigint;
/** Lamports sent to the thread: infra base + execution budget. */
threadLamports: bigint;
/** Base Solana tx fees for contract_create + contract_thread. */
txFees: bigint;
/** Sum of all components. */
total: bigint;
breakdown: {
contractState: bigint;
rentalStateActive: bigint;
rentalStateQueued: bigint;
contractAta: bigint;
ownerAta: bigint;
threadInfraBase: bigint;
executionBudget: bigint;
};
}
export declare function estimateOwnerSetupCost(opts?: OwnerSetupCostOptions): Promise<OwnerSetupCostQuote>;
export interface BorrowerSetupCostQuote {
rentLamports: bigint;
txFees: bigint;
total: bigint;
breakdown: {
borrowerState: bigint;
managedAta: bigint;
};
}
export declare function estimateBorrowerSetupCost(rpcUrl?: string): Promise<BorrowerSetupCostQuote>;
export interface RentalCostParams {
/** Contract PDA address. */
contract: Address | string;
/** Rental duration in seconds. */
durationSeconds: bigint | number;
/** Optional ATLAS bid for reservations (Stardust units). */
bidStardust?: bigint;
/** Override RPC. */
rpcUrl?: string;
}
export interface RentalCostQuote {
/** SOL tx fee for rental_accept (base only — priority fees excluded). */
solTxFees: bigint;
/** ATLAS paid to escrow = rate × duration / day, in Stardust. */
atlasEscrow: bigint;
/** Service fee portion of escrow (already included in `atlasEscrow`). */
atlasServiceFee: bigint;
/** Optional reservation bid (Stardust), 0 if unused. */
atlasBid: bigint;
/** atlasEscrow + atlasBid — total ATLAS (Stardust) borrower transfers. */
atlasTotal: bigint;
/** Basis points snapshot from config used for the fee calc. */
serviceFeeBps: number;
}
/**
* Quote the ATLAS cost a borrower will pay for a given rate + duration.
* Pure helper — does not build a transaction.
*/
export declare function estimateRentalCost(params: RentalCostParams): Promise<RentalCostQuote>;
/**
* Lamports burned by a given number of cron ticks at `PER_TICK_LAMPORTS` each.
* Useful for sizing a custom `executionBudget` before calling
* `estimateOwnerSetupCost`.
*/
export declare function tickBudget(ticks: bigint | number): bigint;
//# sourceMappingURL=estimate.d.ts.map