Documentation
    Preparing search index...

    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.

    Index
    • Parameters

      • params: { durationMs: number | bigint; session: string; wrapperId: string }

      Returns (tx: Transaction) => void

      A function that takes a Transaction object

      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 <= MAX_SESSION_DURATION_MS; an Account holds at most MAX_SESSIONS_PER_ACCOUNT distinct addresses. Re-authorizing an address replaces its expiry in place and consumes no additional slot.

    • Parameters

      • owner: string

      Returns string

      The owner's canonical ACCOUNT id — a different derived object from the wrapper. The session grants hang off this one, so this is what deriveSessionsFieldId and decodeSessions work from.

    • Parameters

      • owner: string

      Returns string

      The owner's canonical AccountWrapper id — derived off-chain, no read. Every builder here takes that id.

    • Parameters

      • owner: string

      Returns string

      The object id of the owner's DataKey<SessionsApp> dynamic field — fetch this object and pass its BCS contents to decodeSessions. There is no bulk on-chain read, so this is the route to enumerating grants.

    • Parameters

      • params: {
            expiryMarketId: string;
            higherTick: number | bigint;
            lowerTick: number | bigint;
            maxCost: number | bigint;
            maxPremium: number | bigint;
            minQuantity: number | bigint;
            pricer: TransactionArgument;
            protocolConfig: string;
            wrapperId: string;
        }

      Returns (tx: Transaction) => TransactionResult

      A function that takes a Transaction object and returns the new order id (u256)

      Mint by spending up to a premium budget, flooring the quantity received. The chain requires maxCost > 0.

    • Parameters

      • params: {
            expiryMarketId: string;
            higherTick: number | bigint;
            lowerTick: number | bigint;
            maxCost: number | bigint;
            maxProbability: number | bigint;
            pricer: TransactionArgument;
            protocolConfig: string;
            quantity: number | bigint;
            wrapperId: string;
        }

      Returns (tx: Transaction) => TransactionResult

      A function that takes a Transaction object and returns the new order id (u256)

      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.

    • Parameters

      • params: {
            closeQuantity: number | bigint;
            expiryMarketId: string;
            minProbability?: number | bigint;
            minProceeds?: number | bigint;
            orderId: bigint;
            pricer: TransactionArgument;
            protocolConfig: string;
            wrapperId: string;
        }

      Returns (tx: Transaction) => TransactionResult

      A function that takes a Transaction object and returns Option<u256> — the replacement order id when a partial close leaves quantity open

      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.

    • Parameters

      • params: {
            expiryMarketId: string;
            orderId: bigint;
            protocolConfig: string;
            wrapperId: string;
        }

      Returns (tx: Transaction) => void

      A function that takes a Transaction object

      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.

    • Parameters

      • params: { session: string; wrapperId: string }

      Returns (tx: Transaction) => void

      A function that takes a Transaction object

      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".

    • Parameters

      • params: { session: string; wrapperId: string }

      Returns (tx: Transaction) => TransactionResult

      A function that takes a Transaction object

      Read one session's absolute expiry as Option<u64>. Compose in a dev-inspect/simulate PTB and decode the returned BCS. Not version-gated.

    • Parameters

      • contents: Uint8Array

      Returns SessionGrant[]

      Decode an Account's stored grants from the raw BCS content of its DataKey<SessionsApp> dynamic FIELD object — the whole Field<DataKey<SessionsApp>, SessionsData>, as the core API returns it, not the inner SessionsData. Get the id from 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 MAX_SESSIONS_PER_ACCOUNT cap should list, drop anything already expired, and revoke before granting again.

    • Parameters

      Returns SessionGrant[]

      Grants that are already dead at nowMs — the complement of 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.