finishFlush function
Finish a full-pool valuation and run the LP flush: prove every snapshotted market was valued exactly once, price the pool NAV, then drain the supply/withdraw queues at that frozen mark (mint PLP for supplies, burn PLP and pay USDC for withdrawals), release the valuation flag, retire the in-flight valuation, and return the LP-attributable pool-wide USDC NAV (frozen idle + Σ active NAV, net of the pending-protocol-profit exclusion priced from the frozen profit basis — every term as of the snapshot instant). Each drain fills only requests submitted before the flush's snapshot instant (the recorded queue cutoffs); younger requests wait for the next mark.
supply_budget and withdraw_budget bound how many requests each queue may
process this flush (None = unbounded). Fills — whole or partial — and
protocol-refunded heads — non-executable, or quoting below the request's own
minimum output — all count as processed. At ProtocolConfig's shipped attempt
count of one, a head that misses its limit is refunded by the flush that reaches
it; above one it stays queued and stops that queue for the flush. The budgets
are independent, so a supply backlog does not consume withdrawal capacity.
Capacity bounds each pass on top of the budgets and refunds nothing: supplies
fill only up to ProtocolConfig's LP pool-value cap, withdrawals only up to
idle. A head larger than the room left fills to the room, spends flush budget,
and keeps its remainder queued at a rescaled limit; a head with no usable room
carries untouched and spends none. Either way the pass stops, so an unbounded
budget does not mean every queued request is processed (RP-23).
Because queueing is permissionless and a refunded request returns its escrow in the same transaction, an operator should bound both budgets in production rather than rely on queue length staying small — see RP-12.
Implementation
MoveCallBuilder finishFlush(
{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::finish_flush',
arguments: normalizeMoveArguments(
tx,
withConfigDefaults(arguments, config,
const {'vault': 'poolVault', 'config': 'protocolConfig'}),
[null, null, '0x2::clock::Clock'],
['vault', 'config']),
);
}