Skip to content

Commit

Permalink
Add features to support principal protected vault
Browse files Browse the repository at this point in the history
  • Loading branch information
Hd0702 committed Jul 10, 2024
1 parent 7122206 commit 2923f4c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/assets/OptionAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,24 @@ contract OptionAsset is IOptionAsset, PositionTracking, GlobalSubIdOITracking, M
function calcSettlementValue(uint subId, int balance) external view returns (int payout, bool priceSettled) {
(uint expiry, uint strike, bool isCall) = OptionEncoding.fromSubId(subId.toUint96());

// Return false if settlement price has not been locked in
if (expiry > block.timestamp) {
return (0, false);
}

(bool isSettled, uint settlementPrice) = settlementFeed.getSettlementPrice(uint64(expiry));
(bool isSettled, uint settlementPrice) = _getSettlement(expiry);
if (!isSettled) return (0, false);

return (_getSettlementValue(strike, balance, settlementPrice, isCall), true);
}

function getSettlement(uint expiry) external view returns (bool isSettled, uint settlementPrice) {
return _getSettlement(expiry);

Check warning on line 134 in src/assets/OptionAsset.sol

View check run for this annotation

Codecov / codecov/patch

src/assets/OptionAsset.sol#L134

Added line #L134 was not covered by tests
}

function _getSettlement(uint expiry) internal view returns (bool isSettled, uint settlementPrice) {
if (expiry > block.timestamp) {
return (false, 0);
}

return settlementFeed.getSettlementPrice(uint64(expiry));
}

/**
* @notice Get settlement value of a specific option position.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/IOptionAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ interface IOptionAsset is IAsset, IPositionTracking, IGlobalSubIdOITracking {
*/
function calcSettlementValue(uint subId, int balance) external view returns (int payout, bool priceSettled);

/**
* @notice Will return if an expiry is settled and the settlement price.
* @param expiry of a particular option.
* @return isSettled Whether or not the expiry has settled yet.
* @return settlementPrice The estimated price of the settlement.
*/
function getSettlement(uint expiry) external view returns (bool isSettled, uint settlementPrice);

////////////////
// Events //
////////////////
Expand Down
5 changes: 5 additions & 0 deletions test/shared/mocks/MockOptionAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ contract MockOption is MockPositionTracking, MockGlobalSubIdOITracking, IOptionA
needAllowance = true;
}

function getSettlement(uint expiry) external view returns (bool isSettled, uint settlementPrice) {
// not using the settlement Price right now. Returning 0 for now
return (expiry > block.timestamp, 0);
}

function setRevertAdjustmentFromManager(address _manager, bool _revert) external {
revertFromManager[_manager] = _revert;
}
Expand Down

0 comments on commit 2923f4c

Please sign in to comment.