rebalanceExpiryCash function
Move cash between pool idle liquidity and one expiry market.
Permissionless and standalone: anyone may call it at any cadence. Handles all
three per-market cases — initial funding of a freshly registered (unfunded)
market, ongoing live rebalance/surplus-sweep toward target, and the
settled-market sweep (deactivate, return all free cash, materialize profit).
Call expiry_market::try_settle first in the same PTB when settlement may be
due. An expired unsettled market is a no-op until that transition succeeds. Mint
asserts backing but never pulls pool cash, so this is what makes a market
mintable. The market must already be registered to this vault
(registry::create_and_share_expiry_market). Runs at any time, including while
a flush is in flight — every figure the mark reads was frozen at the snapshot
instant, so no move here can reach it. The one refusal is the still-open
snapshot stage (start → seal, a single transaction): a cross-move landing
between a market's stamp and the seal's vault capture would skew the frozen
figures, so it is structurally rejected rather than corrected for.
Implementation
MoveCallBuilder rebalanceExpiryCash(
{dynamic arguments, String? package, Map<String, dynamic>? config}) {
final packageAddress = package ??
(config?['predictPackageId'] as String?) ??
'@local-pkg/deepbook_predict';
return (tx) => tx.moveCall(
'$packageAddress::plp::rebalance_expiry_cash',
arguments: normalizeMoveArguments(
tx,
withConfigDefaults(arguments, config,
const {'vault': 'poolVault', 'config': 'protocolConfig'}),
[null, null, null, '0x2::clock::Clock'],
['vault', 'market', 'config']),
);
}