import { TESTNET_DEPLOYMENT, TESTNET_UNITS } from "./deployments/testnet.mjs"; import { DeployedNetwork, NetworkArg, getDeployment, getUnits } from "./deployments/index.mjs"; import { DeepbookSessionsConfig } from "./contracts/deepbook_sessions/config-arguments.mjs"; import { SessionAuthorized, SessionRevoked, SessionsApp, SessionsData, sessions_d_exports } from "./contracts/deepbook_sessions/sessions.mjs"; import { session_config_d_exports } from "./contracts/deepbook_sessions/session_config.mjs"; import { Transaction, TransactionArgument, TransactionResult } from "@mysten/sui/transactions"; //#region src/sessions.d.ts /** * Deployed ids the sessions builders address. * * `accountPackageId` / `accountRegistry` are the same shared-account ids * {@link AccountContract} takes — sessions is an Account app, so it addresses the same * registry. `sessionsPackageId` and `sessionsConfig` come from the sessions deployment. */ interface SessionsConfig extends DeepbookSessionsConfig { /** The latest `deepbook_sessions` Move-call package id. */ sessionsPackageId: string; /** Original ID for v1 structs. Omit only for an unupgraded custom deployment. */ sessionsPackageIdV1?: string; /** The shared `SessionsConfig` object id. */ sessionsConfig: string; /** * The ORIGINAL shared `account` package id. The derived account and wrapper ids and the * session data key's type are built from it, so it never moves to an upgraded package. */ accountPackageId: string; /** The shared `AccountRegistry` object id. */ accountRegistry: string; /** * The latest `account` package once the network has upgraded it: the call target for any * account call composed into the same PTB as these sessions calls, which link it. A PTB can't * call account at an older version (`InvalidLinkage`). Absent while the network runs v1. */ accountPackageIdLatest?: string; } /** * Ids the DeepBook **spot** session wrappers need on top of {@link SessionsConfig}. The * Predict wrappers never take these, so they are kept off the main config rather than made * optional there. */ interface SessionsSpotIds { /** DeepBook's shared `Registry` — `deepbook_registry` on the spot entrypoints. */ deepbookRegistry: string; /** The `deepbook_core_account` Move package id. */ deepbookCoreAccountPackageId: string; } /** Ids the Predict session wrappers need beyond {@link SessionsConfig}. */ interface SessionsPredictIds { /** Every Predict wrapper takes `config: &ProtocolConfig`. */ protocolConfig: string; } /** * @description The deployed sessions ids for `network`, so a caller does not transcribe * them. Generated from the deploy manifest — see `src/deployments/`. The returned object * also carries {@link SessionsSpotIds} for the generated spot wrappers. * @throws if the network has no recorded deployment, rather than returning placeholder ids. * * ```ts * const sessions = new SessionsContract(getSessionsConfig('testnet')); * ``` */ declare function getSessionsConfig(network: NetworkArg): SessionsConfig & SessionsSpotIds & SessionsPredictIds; /** The market, queue, account and oracle objects every queued Predict session wrapper names. */ interface SessionsQueuedOrderTarget { expiryMarketId: string; wrapperId: string; /** * The order-flow companion's shared `OrderDesk` (`deepbook_predict_orders`). Predict's * `PredictConfig.objects.orderDesk`. */ orderDesk: string; /** * The order-flow companion's shared `QueueRegistry`, which every market's queue ID derives * from. Predict's `PredictConfig.objects.queueRegistry`. */ queueRegistry: string; /** * The market's `MarketQueue`. Defaults to the ID derived from `queueRegistry` and the market * (`deriveQueueId`), which is where `queue::create_and_share` puts it. */ queueId?: string; /** Predict's `ProtocolConfig`. */ protocolConfig: string; /** Predict's `OracleRegistry` (the propbook registry). */ oracleRegistry: string; /** The market's `PythFeed`. */ pythFeed: string; /** The market's `BlockScholesValueStore`. */ blockScholesValueStore: string; /** The market's `BlockScholesSVIStore`. */ blockScholesSviStore: string; } /** The maximum session duration the contract accepts: 30 days, in milliseconds. */ declare const MAX_SESSION_DURATION_MS: number; /** The maximum number of distinct session addresses one Account may store. */ declare const MAX_SESSIONS_PER_ACCOUNT = 20; /** One stored session grant. */ interface SessionGrant { /** The authorized ephemeral address. */ session: string; /** Absolute expiry, ms since epoch. The grant is dead AT this timestamp (strict `<`). */ expiresAtMs: bigint; } /** * SessionsContract — time-limited trading sessions over a canonical Account. * * An Account owner authorizes an ephemeral address to submit a bounded set of * transactions on the Account's behalf until a fixed expiry. The session key never * receives a reusable `Auth`: each wrapper mints app authorization internally and * consumes it in the same call. * * WHAT A SESSION KEY CAN DO. It cannot withdraw to an address, cannot grant or revoke * sessions, and cannot outlive its expiry — those all require owner auth. It CAN trade * the Account's full balance: the spot wrappers take a caller-chosen `Pool` and, through * `deepbook_core_account`, pull the account's entire Base, Quote and DEEP balance * (stored plus unsettled) into the embedded manager for the duration of the call, with * `price_limit` supplied by the caller. Nothing caps notional, restricts which pools are * reachable, or bounds loss to adverse pricing. Treat a session key as authority over * everything the Account holds, and fund an ephemeral-session Account accordingly. * * Operational precondition: an admin must have authorized `SessionsApp` on the account * registry. Until then — or after a `deauthorize_app` — the TRADING wrappers abort with * `EAppNotAuthorized`; `authorizeSession`, `revokeSession` and `sessionExpirationMs` use * owner auth or no auth and keep working. Note that `deauthorize_app` does not clear * `SessionsData`, so re-authorizing makes every still-unexpired grant live again at once * — it is a pause, not a kill switch. Revoking, and reading expirations, also keep * working if the sessions package is later version-gated. * * This class wraps the session lifecycle and the **Predict** entrypoints. The DeepBook * spot session wrappers are generated (see `sessionsMoveCalls`) but are not wrapped here * — note `placeLimitOrder` and `placeMarketOrder` put `accountRegistry` at index 2 and * `sessionsConfig` at 4, because `deepbookRegistry` sits between them; the other three * (`cancelLiveOrder`, `cancelLiveOrders`, `withdrawSettledAmounts`) take no * `deepbookRegistry` and so keep 1 and 3 like the Predict wrappers: * the surrounding spot-over-Account workflow — discovering the embedded balance manager, * reading resting orders and locked balances — is not modelled yet, so a wrapped builder * would be hard to use well. They are reachable from the generated bindings meanwhile. */ declare class SessionsContract { #private; constructor(config: SessionsConfig); /** * @description The owner's canonical `AccountWrapper` id — derived off-chain, no read. * Every builder here takes that id. */ deriveAccountWrapperId(owner: string): string; /** * @description The owner's canonical ACCOUNT id — a different derived object from the * wrapper. The session grants hang off this one, so this is what * {@link deriveSessionsFieldId} and {@link decodeSessions} work from. */ deriveAccountId(owner: string): string; /** * @description The object id of the owner's `DataKey` dynamic field — * fetch this object and pass its BCS contents to {@link decodeSessions}. There is no * bulk on-chain read, so this is the route to enumerating grants. */ deriveSessionsFieldId(owner: string): string; /** * @description Grant `session` authority over the Account until `now + durationMs`. * Authority is derived from the transaction SENDER, so the owner must sign this. * `durationMs` must be > 0 and <= {@link MAX_SESSION_DURATION_MS}; an Account holds at * most {@link MAX_SESSIONS_PER_ACCOUNT} distinct addresses. Re-authorizing an address * replaces its expiry in place and consumes no additional slot. * @returns A function that takes a Transaction object */ authorizeSession(params: { wrapperId: string; session: string; durationMs: number | bigint; }): (tx: Transaction) => void; /** * @description Remove `session`'s grant. Owner-signed, like `authorizeSession`. * Deliberately takes no `SessionsConfig`: revocation is not version-gated, so it keeps * working after the package is retired. Revoking an address that holds no grant is a * silent no-op — it neither aborts nor emits, so read before and after if you need to * distinguish "revoked" from "was never granted". * @returns A function that takes a Transaction object */ revokeSession(params: { wrapperId: string; session: string; }): (tx: Transaction) => void; /** * @description Read one session's absolute expiry as `Option`. Compose in a * dev-inspect/simulate PTB and decode the returned BCS. Not version-gated. * @returns A function that takes a Transaction object */ sessionExpirationMs(params: { wrapperId: string; session: string; }): (tx: Transaction) => TransactionResult; /** * @description Mint a position of an exact payout quantity, as `session`. Pass * `u64::MAX` for `maxCost` / `maxProbability` to leave either slippage cap * effectively unbounded — the chain asserts `value <= cap`, so the max value can never * trip. Both are required; there is no default. * @returns A function that takes a Transaction object and returns the new order id (u256) * @deprecated Retired by delayed execution (DBU-885): always aborts through Predict v4 * (`EDelayedExecutionRequired`). Use {@link SessionsContract.enqueueExactQuantity}. */ mintExactQuantity(params: { expiryMarketId: string; wrapperId: string; protocolConfig: string; pricer: TransactionArgument; lowerTick: number | bigint; higherTick: number | bigint; quantity: number | bigint; maxCost: number | bigint; maxProbability: number | bigint; }): (tx: Transaction) => TransactionResult; /** * @description Mint by spending up to a premium budget, flooring the quantity received. * The chain requires `maxCost > 0`. * @returns A function that takes a Transaction object and returns the new order id (u256) * @deprecated Retired by delayed execution (DBU-885): always aborts through Predict v4. * Use {@link SessionsContract.enqueueExactAmount}. */ mintExactAmount(params: { expiryMarketId: string; wrapperId: string; protocolConfig: string; pricer: TransactionArgument; lowerTick: number | bigint; higherTick: number | bigint; maxPremium: number | bigint; minQuantity: number | bigint; maxCost: number | bigint; }): (tx: Transaction) => TransactionResult; /** * Mint within an all-in budget as a session. Amounts are raw Move units. * Requires Sessions/Predict v2 or later. * @deprecated Retired by delayed execution (DBU-885): always aborts through Predict v4. * Use {@link SessionsContract.enqueueExactCost}. */ mintExactCost(params: { expiryMarketId: string; wrapperId: string; protocolConfig: string; pricer: TransactionArgument; lowerTick: number | bigint; higherTick: number | bigint; maxCost: number | bigint; minQuantity: number | bigint; }): (tx: Transaction) => TransactionResult; /** * @description Close part or all of a live position at the pricer's mark, as `session`. * `minProbability` / `minProceeds` are close-side slippage floors; `0` disables either, * and OMITTING them is `0` — unlike the mint caps, which are required. On a delegated * key this is the direction that closes a position at any price, so pass real floors * unless you mean to accept whatever the mark gives you. * @returns A function that takes a Transaction object and returns `Option` — the * replacement order id when a partial close leaves quantity open * @deprecated Retired by delayed execution (DBU-885): always aborts through Predict v4. * Account positions then have no early exit; queued fills are Open records sold with * {@link SessionsContract.enqueueRedeemOpen}. */ redeemLive(params: { expiryMarketId: string; wrapperId: string; protocolConfig: string; pricer: TransactionArgument; orderId: bigint; closeQuantity: number | bigint; minProbability?: number | bigint; minProceeds?: number | bigint; }): (tx: Transaction) => TransactionResult; /** * @description Claim a settled position in full, as `session`. Takes no pricer — the * settlement price is fixed — and no quantity: a settled claim is all-or-nothing. * @returns A function that takes a Transaction object */ redeemSettled(params: { expiryMarketId: string; wrapperId: string; protocolConfig: string; orderId: bigint; }): (tx: Transaction) => void; /** * @description Queue a mint of an exact payout quantity, as `session`. `maxCost` (all-in cap) * and `maxProbability` (at most 1e9) are required, and the chain refuses an "unlimited" * `maxCost`. * @returns A function that takes a Transaction object and returns the record id (u64) */ enqueueExactQuantity(params: SessionsQueuedOrderTarget & { lowerTick: number | bigint; higherTick: number | bigint; quantity: number | bigint; maxCost: number | bigint; maxProbability: number | bigint; }): (tx: Transaction) => TransactionResult; /** * @description Queue a premium-budget mint, as `session`: sized at τ under `maxPremium`, at * least `minQuantity`, with the all-in debit capped by the required `maxCost`. * @returns A function that takes a Transaction object and returns the record id (u64) */ enqueueExactAmount(params: SessionsQueuedOrderTarget & { lowerTick: number | bigint; higherTick: number | bigint; maxPremium: number | bigint; minQuantity: number | bigint; maxCost: number | bigint; }): (tx: Transaction) => TransactionResult; /** * @description Queue an all-in-budget mint, as `session`: sized at τ so the all-in cost fits * `maxCost`, at least `minQuantity`. * @returns A function that takes a Transaction object and returns the record id (u64) */ enqueueExactCost(params: SessionsQueuedOrderTarget & { lowerTick: number | bigint; higherTick: number | bigint; maxCost: number | bigint; minQuantity: number | bigint; }): (tx: Transaction) => TransactionResult; /** * @description Queue an early sell of the Open record `recordId` (its queue record ID, not * the position's order ID), as `session`. `minProbability` and `minProceeds` are the close * floors at τ and are required: on a delegated key, `0` closes at any price, so pass it only * on purpose. * @returns A function that takes a Transaction object and returns the new record id (u64) */ enqueueRedeemOpen(params: SessionsQueuedOrderTarget & { recordId: number | bigint; closeQuantity: number | bigint; minProbability: number | bigint; minProceeds: number | bigint; }): (tx: Transaction) => TransactionResult; /** * @description Decode an Account's stored grants from the raw BCS content of its * `DataKey` dynamic FIELD object — the whole * `Field, SessionsData>`, as the core API returns it, not the * inner `SessionsData`. Get the id from {@link deriveSessionsFieldId}. * * There is no bulk on-chain read — `sessionExpirationMs` answers one address at a time — * so listing grants means fetching that field and decoding it here. Note the field hangs * off the DERIVED ACCOUNT address, not the wrapper address; they are different objects. * * Expired grants are never pruned automatically and keep occupying slots, so callers * managing the {@link MAX_SESSIONS_PER_ACCOUNT} cap should list, drop anything already * expired, and revoke before granting again. */ static decodeSessions(contents: Uint8Array): SessionGrant[]; /** Grants from {@link decodeSessions} that are still live at `nowMs`. */ static activeSessions(grants: readonly SessionGrant[], nowMs: number | bigint): SessionGrant[]; /** * @description Grants that are already dead at `nowMs` — the complement of * {@link activeSessions}, and the list to revoke when reclaiming slots. Use this rather * than filtering by hand: `nowMs > expiresAtMs` looks equivalent but leaves the grant * expiring exactly at `nowMs` occupying a slot forever. */ static expiredSessions(grants: readonly SessionGrant[], nowMs: number | bigint): SessionGrant[]; } //#endregion export { type DeployedNetwork, MAX_SESSIONS_PER_ACCOUNT, MAX_SESSION_DURATION_MS, type NetworkArg, SessionAuthorized, SessionGrant, SessionRevoked, SessionsApp, SessionsConfig, SessionsContract, SessionsData, SessionsPredictIds, SessionsQueuedOrderTarget, SessionsSpotIds, TESTNET_DEPLOYMENT, TESTNET_UNITS, getDeployment, getSessionsConfig, getUnits, session_config_d_exports as sessionConfigMoveCalls, sessions_d_exports as sessionsMoveCalls }; //# sourceMappingURL=sessions.d.mts.map