Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: isSettlementAllowedWithDetails() and getVaultWithDetails() #431

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions contracts/core/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
* @param _expiry otoken expiry timestamp
* @return True if the oToken has expired AND all oracle prices at the expiry timestamp have been finalized, False if not
*/
function isSettlementAllowed(
function isSettlementAllowedWithDetails(
address _underlying,
address _strike,
address _collateral,
Expand All @@ -555,6 +555,27 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
return isUnderlyingFinalized && isStrikeFinalized && isCollateralFinalized;
}

/**
* @dev return if an expired oToken contract’s settlement price has been finalized
* @param _otoken address of the oToken
* @return True if the oToken has expired AND all oracle prices at the expiry timestamp have been finalized, False if not
*/
function isSettlementAllowed(address _otoken) public view returns (bool) {
OtokenInterface otoken = OtokenInterface(_otoken);

address underlying = otoken.underlyingAsset();
address strike = otoken.strikeAsset();
address collateral = otoken.collateralAsset();

uint256 expiry = otoken.expiryTimestamp();

bool isUnderlyingFinalized = oracle.isDisputePeriodOver(underlying, expiry);
bool isStrikeFinalized = oracle.isDisputePeriodOver(strike, expiry);
bool isCollateralFinalized = oracle.isDisputePeriodOver(collateral, expiry);

return isUnderlyingFinalized && isStrikeFinalized && isCollateralFinalized;
}

/**
* @notice get the number of vaults for a specified account owner
* @param _accountOwner account owner address
Expand Down Expand Up @@ -878,7 +899,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade
// only allow redeeming expired otoken
require(now >= expiry, "CO28");

require(isSettlementAllowed(underlying, strike, collateral, expiry), "CO29");
require(isSettlementAllowedWithDetails(underlying, strike, collateral, expiry), "CO29");

uint256 payout = getPayout(_args.otoken, _args.amount);

Expand Down Expand Up @@ -925,7 +946,7 @@ contract Controller is Initializable, OwnableUpgradeSafe, ReentrancyGuardUpgrade

// do not allow settling vault with un-expired otoken
require(now >= expiry, "CO31");
require(isSettlementAllowed(underlying, strike, collateral, expiry), "CO29");
require(isSettlementAllowedWithDetails(underlying, strike, collateral, expiry), "CO29");

(uint256 payout, bool isValidVault) = calculator.getExcessCollateral(vault, typeVault);

Expand Down
4 changes: 2 additions & 2 deletions docs/contracts-documentation/core/Controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Contract that controls the Gamma Protocol and the interaction of all sub contrac

- `getPayout(address _otoken, uint256 _amount) (public)`

- `isSettlementAllowed(address _underlying, address _strike, address _collateral, uint256 _expiry) (public)`
- `isSettlementAllowedWithDetails(address _underlying, address _strike, address _collateral, uint256 _expiry) (public)`

- `getAccountVaultCounter(address _accountOwner) (external)`

Expand Down Expand Up @@ -376,7 +376,7 @@ get an oToken's payout/cash value after expiry, in the collateral asset

- amount of collateral to pay out

### Function `isSettlementAllowed(address _underlying, address _strike, address _collateral, uint256 _expiry) → bool public`
### Function `isSettlementAllowedWithDetails(address _underlying, address _strike, address _collateral, uint256 _expiry) → bool public`

return if an expired oToken is ready to be settled, only true when price for underlying,

Expand Down
2 changes: 1 addition & 1 deletion docs/uml/GammaController.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/uml/GammaUML.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/unit-tests/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3770,7 +3770,7 @@ contract(

const expectedResutl = false
assert.equal(
await controllerProxy.isSettlementAllowed(underlying, strike, collateral, expiryTimestamp),
await controllerProxy.isSettlementAllowedWithDetails(underlying, strike, collateral, expiryTimestamp),
expectedResutl,
'Price is not finalized because dispute period is not over yet',
)
Expand Down Expand Up @@ -3802,7 +3802,7 @@ contract(

const expectedResutl = true
assert.equal(
await controllerProxy.isSettlementAllowed(underlying, strike, collateral, expiryTimestamp),
await controllerProxy.isSettlementAllowedWithDetails(underlying, strike, collateral, expiryTimestamp),
expectedResutl,
'Price is not finalized',
)
Expand Down