From 2923f4c3bc6e3e6c5cae5e7c883640e4c59f87df Mon Sep 17 00:00:00 2001 From: Hayden Donofrio Date: Tue, 9 Jul 2024 20:08:00 -0500 Subject: [PATCH] Add features to support principal protected vault --- src/assets/OptionAsset.sol | 19 +++++++++++++------ src/interfaces/IOptionAsset.sol | 8 ++++++++ test/shared/mocks/MockOptionAsset.sol | 5 +++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/assets/OptionAsset.sol b/src/assets/OptionAsset.sol index 6ad63a0e..2d68bf67 100644 --- a/src/assets/OptionAsset.sol +++ b/src/assets/OptionAsset.sol @@ -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); + } + + 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. */ diff --git a/src/interfaces/IOptionAsset.sol b/src/interfaces/IOptionAsset.sol index f184515c..dd0e8e76 100644 --- a/src/interfaces/IOptionAsset.sol +++ b/src/interfaces/IOptionAsset.sol @@ -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 // //////////////// diff --git a/test/shared/mocks/MockOptionAsset.sol b/test/shared/mocks/MockOptionAsset.sol index e542c054..2f039472 100644 --- a/test/shared/mocks/MockOptionAsset.sol +++ b/test/shared/mocks/MockOptionAsset.sol @@ -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; }