Once an order expires, TWAMM executes a virtual long-term orders, which is not a real swap, but only a calculation of the accumulated swap proceeds until the user cancels the long-term orders or the order expires in full, and then directly withdraws the corresponding tokens according to the accumulated swap proceeds.
Computing the result of the closed-form mathematical formula described in Mathematical Principle of TWAMM can alternately be described as performing a virtual order execution iteration, where each iteration occurs at a specific block height. Pulsar use Binary Search Tree (BST) which is used to store and organize all the nodes that are long-term order expiration block heights.The block where each iteration occurs is controlled by the OBI and when the order pool was deployed. Importantly, OBI will be shown to significantly reduce gas usage by reducing the number of iterations that the closed form mathematical formula need be computed for periods of inactivity during active Term Swaps.
If no TWAMM operations necessitating virtual order execution occur for an arbitrary number of blocks, a.k.a. blocks of inactivity, the next TWAMM operation requiring virtual order execution incurs the cost of executing all the virtual orders since the last such operation.
The result of the Order Execution of TWAMM long-term orders at expiration is as follows: