@pwngh/economy-lab
    Preparing search index...

    Function openInstanceSession

    • Opens a netting session. record accepts or rejects movements (idempotent per key, affordable per the reservation registry, durable per journal batch); flush forces the pending batch out; settle derives the net from the journal, verifies the chain, and posts it in clearing chunks — once per session id; rotate epochs to keep a long-lived scope settling on cadence.

      deps is a structural subset of Ports, so a host composed via openPorts passes its ports straight through. Share ONE reservations registry across every session in the process (see Reservations).

      Parameters

      Returns InstanceSession

      // In the economy service, keyed by (not owned by) a world instance, epoch-rotated. A
      // purchase movement carries the same fee split a main-lane sale posts: buyer debit,
      // seller's net credit, REVENUE's fee credit.
      const ports = await openPorts(process.env, init);
      const reservations = createReservations(); // one per process
      const session = openInstanceSession(ports, `sess:${worldInstanceId}:0`, { reservations });
      const price = decodeAmount('5.00', 'CREDIT');
      const fee = decodeAmount('1.50', 'CREDIT');
      await session.record({
      idempotencyKey: orderId,
      legs: [
      debit(spendable(buyerId), price),
      credit(earned(creatorId), subtract(price, fee)),
      credit(SYSTEM.REVENUE, fee),
      ],
      });
      await session.settle(); // this tier's schedule: cadence, backlog, timeout, or scope close