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

More test coverage on sad paths #94

Merged
merged 5 commits into from
Nov 10, 2022
Merged
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
33 changes: 1 addition & 32 deletions src/OptionSettlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ contract OptionSettlementEngine is ERC1155, IOptionSettlementEngine {
revert InvalidOption(_optionIdU160b);
}
if (expiry <= block.timestamp) {
revert ExpiredOption(uint256(_optionIdU160b) << 96, expiry);
revert ExpiredOption(uint256(_optionIdU160b) << 96, expiry); // TODO measure gas savings and just use optionId
}

uint256 rxAmount = amount * optionRecord.underlyingAmount;
Expand Down Expand Up @@ -443,37 +443,6 @@ contract OptionSettlementEngine is ERC1155, IOptionSettlementEngine {
// **********************************************************************
// INTERNAL HELPERS
// **********************************************************************
/**
* @dev Writes the specified number of options, transferring in the requisite
* underlying assets, and trasnsferring fungible ERC1155 tokens to caller.
* Reverts if insufficient underlying assets are not available from caller.
* @param _optionId The options to write.
* @param amount The amount of options to write.
*/
function _writeOptions(uint160 _optionId, uint112 amount) internal returns (Option storage) {
if (amount == 0) {
revert AmountWrittenCannotBeZero();
}

Option storage optionRecord = _option[_optionId];

if (optionRecord.expiryTimestamp <= block.timestamp) {
revert ExpiredOption(uint256(_optionId) << 96, optionRecord.expiryTimestamp);
}

uint256 rxAmount = amount * optionRecord.underlyingAmount;
uint256 fee = ((rxAmount / 10000) * feeBps);
address underlyingAsset = optionRecord.underlyingAsset;

// Transfer the requisite underlying asset
SafeTransferLib.safeTransferFrom(ERC20(underlyingAsset), msg.sender, address(this), (rxAmount + fee));

feeBalance[underlyingAsset] += fee;

emit FeeAccrued(underlyingAsset, msg.sender, fee);

return optionRecord;
}

/// @dev Performs fair exercise assignment by pseudorandomly selecting a claim
/// bucket between the intial creation of the option type and "today". The buckets
Expand Down
Loading