@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
89 lines • 3.62 kB
TypeScript
/**
* @purpose Reservation bid math helpers
*
* Pure-math + on-chain-fetch helpers for computing the contest minimum-bid
* floor that a challenger must clear to take an existing reservation.
* Mirrors the on-chain `ConfigState::bid_min_stardust` formula so client UIs
* (and on-chain-aware tooling) can preview the floor without hitting an RPC
* for every keystroke.
*/
import { type Address } from '@solana/kit';
/**
* Pure math: contest minimum-bid floor in stardust.
*
* Mirror of `ConfigState::bid_min_stardust` on-chain.
*
* floor = max(rate, defenderBid) × ramp
* ramp = max(captureRate, 1 + (maxMult - 1) × closeness)
*
* `closenessFraction` is in `[0, 1]` — the fraction of the active rental's
* remaining window that has elapsed since the defender's reservation. 0 =
* defender just placed; 1 = active rental about to end (snipe).
*
* `contestedMultiplierMaxBps` is on the protocol's custom 100=1× scale:
* 100 disables the ramp, 10_000 = 100×.
*/
export declare function computeMinimumBid(args: {
rateStardust: bigint;
defenderBidStardust?: bigint;
contestedMultiplierMaxBps: number;
captureRateBps: bigint;
closenessFraction: number;
}): bigint;
export type MinimumBid = {
/** Stardust amount a challenger must bid to clear the floor. */
minBidStardust: bigint;
/** Stardust amount of the existing defender bid (sum of bidAtlas + bidPoints
* converted via `atlasPerPoint`). 0 if no defender. */
defenderBidStardust: bigint;
/** Contract rate per day in stardust. */
rateStardust: bigint;
/** Closeness fraction at the moment of evaluation (0..1). */
closenessFraction: number;
/** Effective ramp multiplier applied (e.g. 4.65 for 4.65×). */
rampMultiplier: number;
/** Unix-second timestamp the floor was computed for (now + delaySeconds). */
evaluatedAtSeconds: number;
/** Active rental's end_time in unix seconds, if an active rental exists. */
activeEndSeconds: number | null;
/** Active rental's start_time in unix seconds, if one exists. */
activeStartSeconds: number | null;
};
/**
* High-level helper: compute the contest minimum bid for a contract right
* now (or at `now + delaySeconds`).
*
* Fetches `ConfigState`, `ContractState`, and the active/queued `RentalState`
* accounts, derives `closeness` from the active rental window, and returns
* the floor a challenger must clear plus enough context to render a UI.
*
* @example
* ```ts
* const floor = await getMinimumBid({ contractAddress: 'Abc...' });
* console.log('Bid at least', floor.minBidStardust, 'stardust');
*
* // Preview the floor 4 hours from now (snipe-window pricing):
* const later = await getMinimumBid({
* contractAddress: 'Abc...',
* delaySeconds: 4 * 60 * 60,
* });
* ```
*
* If the contract has no active rental yet, closeness = 0 and the floor
* collapses to the rate-bump floor (`rate × captureRate`).
*/
export declare function getMinimumBid(args: {
contractAddress: Address | string;
/** Seconds to advance the evaluation past `now`. Negative values are
* clamped to 0 (no back-dating). Default 0. */
delaySeconds?: number;
/** Override the evaluation moment outright (unix seconds). Takes priority
* over `delaySeconds`. */
nowSeconds?: number;
/** ATLAS-per-point conversion (whole-ATLAS per whole-point). Defaults to
* the cached `cfg.atlasPerPoint`; override if you want to project a
* different conversion. */
atlasPerPoint?: bigint;
rpcUrl?: string;
}): Promise<MinimumBid>;
//# sourceMappingURL=bidMath.d.ts.map