Function: withdraw(uint256 tokenId)
This function withdraws principal after maturity.
Inputs
tokenId
Control: Fully controlled by the caller.
Constraints: N/A.
Impact: ID of position NFT.
Branches and code coverage
Intended branches
Check if the owner of position NFT is the caller.
Check if the position duration has matured.
If the position has not matured, call
mature
to mature the position.Collect any remaining fees and calculate the total amount of principal plus
tokenOwed
.Burn NFT and transfer the
totalAmount
to the caller.
Negative behavior
If the owner of position NFT is not the caller, the transaction will be reverted.
If the position duration is immature, the transaction will be reverted.