The Margin Engine is responsible for the management of the underlying assets that collateralize traders and liquidity providers. At the maturity of an IRS pool, it facilitates cash flow movements between positions in the pool in order to settle active interest rate swap contracts initiated before the pool maturity.
The Margin Engine the has 2 key responsibilities:
Traders and Liquidity Providers can either add or remove underlying tokens from their margin account via the Margin Engine
After the maturity of the IRS pool, traders and liquidity providers can settle their interest rate swaps via the Margin Engine
The updatePositionMargin function updates the position margin account balance in the underlying ERC20 token, the position can be uniquely identified by its owner address, upper and lower ticks.
Removing margin from a given position’s margin account is only possible if the function is called by the position owner address or by an address trusted by the position owner (refer to Factory).
If a position is engaged in active interest rate swaps it is only possible to remove margin as long as the remaining balance in the margin account is above or equal to the liquidation margin requirement of the position.
Adding margin on behalf of a position owner can be done by any address (msg.sender).
The delta (either positive or negative) applied to the margin account of the position in underlying tokens.
The settlePosition function can only be called after a given IRS pool has matured. A position with an active interest rate swap can call settlePosition in order to settle (fixed-to-variable or variable-to-fixed) cashflows with the pool.