Blockwell

HegicOptionsETH

About

Stats

Public Functions 27
Event Types 7
Code Size 75,532 bytes

Approval Event

Parameters help
owner
address help
approved
address help
tokenId
uint256 help

ApprovalForAll Event

Parameters help
owner
address help
operator
address help
approved
bool help

Created Event

Parameters help
account
address help
tokenId
uint help
optionId
uint help

Detokenized Event

Parameters help
account
address help
tokenId
uint help
optionId
uint help
burned
bool help

Exercised Event

Parameters help
account
address help
tokenId
uint help
optionId
uint help
profit
uint help

Tokenized Event

Parameters help
account
address help
tokenId
uint help
optionId
uint help

Transfer Event

Parameters help
from
address help
to
address help
tokenId
uint256 help

Functions Expand All Collapse All

supportsInterface keyboard_arrow_up

Parameters help

Name Type
interfaceId
bytes4 help

Properties

Visibility help public
Mutability help view
Source Code
    function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
        return _supportedInterfaces[interfaceId];
    }

balanceOf keyboard_arrow_up

Parameters help

Name Type
owner
address help

Properties

Visibility help public
Mutability help view

Requirements help

Source Code
    function balanceOf(address owner) public view override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");

        return _holderTokens[owner].length();
    }

ownerOf keyboard_arrow_up

Parameters help

Name Type
tokenId
uint256 help

Properties

Visibility help public
Mutability help view
Source Code
    function ownerOf(uint256 tokenId) public view override returns (address) {
        return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token");
    }

name keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help view
Source Code
    function name() public view override returns (string memory) {
        return _name;
    }

symbol keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help view
Source Code
    function symbol() public view override returns (string memory) {
        return _symbol;
    }

tokenURI keyboard_arrow_up

Parameters help

Name Type
tokenId
uint256 help

Properties

Visibility help public
Mutability help view

Requirements help

null
Source Code
    function tokenURI(uint256 tokenId) public view override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory _tokenURI = _tokenURIs[tokenId];

        // If there is no base URI, return the token URI.
        if (bytes(_baseURI).length == 0) {
            return _tokenURI;
        }
        // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
        if (bytes(_tokenURI).length > 0) {
            return string(abi.encodePacked(_baseURI, _tokenURI));
        }
        // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
        return string(abi.encodePacked(_baseURI, tokenId.toString()));
    }

baseURI keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help view
Source Code
    function baseURI() public view returns (string memory) {
        return _baseURI;
    }

tokenOfOwnerByIndex keyboard_arrow_up

Parameters help

Name Type
owner
address help
index
uint256 help

Properties

Visibility help public
Mutability help view
Source Code
    function tokenOfOwnerByIndex(address owner, uint256 index) public view override returns (uint256) {
        return _holderTokens[owner].at(index);
    }

totalSupply keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help view
Source Code
    function totalSupply() public view override returns (uint256) {
        // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds
        return _tokenOwners.length();
    }

tokenByIndex keyboard_arrow_up

Parameters help

Name Type
index
uint256 help

Properties

Visibility help public
Mutability help view
Source Code
    function tokenByIndex(uint256 index) public view override returns (uint256) {
        (uint256 tokenId, ) = _tokenOwners.at(index);
        return tokenId;
    }

approve keyboard_arrow_up

Parameters help

Name Type
to
address help
tokenId
uint256 help

Properties

Visibility help public
Mutability help transaction
Source Code
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

getApproved keyboard_arrow_up

Parameters help

Name Type
tokenId
uint256 help

Properties

Visibility help public
Mutability help view

Requirements help

null
Source Code
    function getApproved(uint256 tokenId) public view override returns (address) {
        require(_exists(tokenId), "ERC721: approved query for nonexistent token");

        return _tokenApprovals[tokenId];
    }

setApprovalForAll keyboard_arrow_up

Parameters help

Name Type
operator
address help
approved
bool help

Properties

Visibility help public
Mutability help transaction

Requirements help

Source Code
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(operator != _msgSender(), "ERC721: approve to caller");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

isApprovedForAll keyboard_arrow_up

Parameters help

Name Type
owner
address help
operator
address help

Properties

Visibility help public
Mutability help view
Source Code
    function isApprovedForAll(address owner, address operator) public view override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

transferFrom keyboard_arrow_up

Parameters help

Name Type
from
address help
to
address help
tokenId
uint256 help

Properties

Visibility help public
Mutability help transaction
Source Code
    function transferFrom(address from, address to, uint256 tokenId) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");

        _transfer(from, to, tokenId);
    }

safeTransferFrom keyboard_arrow_up

Parameters help

Name Type
from
address help
to
address help
tokenId
uint256 help

Properties

Visibility help public
Mutability help transaction
Source Code
    function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

safeTransferFrom keyboard_arrow_up

Parameters help

Name Type
from
address help
to
address help
tokenId
uint256 help
_data
bytes help

Properties

Visibility help public
Mutability help transaction
Source Code
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
        _safeTransfer(from, to, tokenId, _data);
    }

createOption keyboard_arrow_up

Parameters help

Name Type
_period
uint help
_amount
uint help
_strike
uint help
_optionType
IHegicOptions.OptionType help
_to
address help

Properties

Visibility help public
Mutability help payable
Source Code
    function createOption(
        uint _period,
        uint _amount,
        uint _strike,
        IHegicOptions.OptionType _optionType,
        address _to
    )
        payable
        external
        returns (uint newTokenId)
    {
        uint optionId = optionsProvider.create{value: msg.value}(_period, _amount, _strike, _optionType);
        _transferBalance(msg.sender); // if sender sent more than needed, contract will return excess
        newTokenId = tokenize(optionId, _to);

        emit Created(_to, newTokenId, optionId);
    }

exerciseOption keyboard_arrow_up

Parameters help

Name Type
_tokenId
uint help

Properties

Visibility help public
Mutability help transaction

Modifiers help

onlyTokenOwnerOrApproved checks for the following:
null
Source Code
    function exerciseOption(uint _tokenId) external onlyTokenOwnerOrApproved(_tokenId) returns (uint profit){
        uint optionId = underlyingOptionId[_tokenId];
        optionsProvider.exercise(optionId);
        // contract pays token owner, even if called by an approved account
        profit = _transferBalance(ownerOf(_tokenId));

        emit Exercised(ownerOf(_tokenId), _tokenId, optionId, profit);
    }

tokenizeOption keyboard_arrow_up

Parameters help

Name Type
_optionId
uint help
_to
address help

Properties

Visibility help public
Mutability help transaction
Source Code
    function tokenizeOption(uint _optionId, address _to) external returns (uint newTokenId) {
        (, address holder, , , , , ,) = optionsProvider.options(_optionId);
        require(holder != address(this), "HONFT/already-tokenized");
        require(holder == msg.sender, "HONFT/invalid-holder");
        newTokenId = tokenize(_optionId, _to);
    }

detokenizeOption keyboard_arrow_up

Parameters help

Name Type
_tokenId
uint help
_burnToken
bool help

Properties

Visibility help public
Mutability help transaction

Modifiers help

onlyTokenOwnerOrApproved checks for the following:
null

Requirements help

null
Source Code
    function detokenizeOption(uint _tokenId, bool _burnToken) external onlyTokenOwnerOrApproved(_tokenId) {
        require(checkValidToken(_tokenId), "HONFT/option-not-owned-by-contract");
        uint optionId = underlyingOptionId[_tokenId];
        address owner = ownerOf(_tokenId);
        // checks if optionsProvider will allow to transfer option ownership
        (IHegicOptions.State state, , , , , , uint expiration , ) = getUnderlyingOptionParams(_tokenId);
        if(state == IHegicOptions.State.Active && expiration > block.timestamp)
            optionsProvider.transfer(optionId, payable(ownerOf(_tokenId)));

        delete ownedByThis[_tokenId];

        if(_burnToken) {
            delete holdingToken[optionId];
            _burn(_tokenId);
        }

        emit Detokenized(owner, _tokenId, optionId, _burnToken);
    }

burnToken keyboard_arrow_up

Parameters help

Name Type
_tokenId
uint help

Properties

Visibility help public
Mutability help transaction

Modifiers help

onlyTokenOwnerOrApproved checks for the following:
null

Requirements help

One or more of the following: - UNKNOWN VALUE must be equal to UNKNOWN VALUE - OR owner must be equal to UNKNOWN VALUE - ORnull
Source Code
    function burnToken(uint _tokenId) external onlyTokenOwnerOrApproved(_tokenId) {
        (IHegicOptions.State state, , , , , , uint expiration , ) = getUnderlyingOptionParams(_tokenId);

        // only allows to burn inactive options, even if still owned by the contract
        if(state == IHegicOptions.State.Active || expiration > block.timestamp)
            require(!ownedByThis[_tokenId], "HONFT/cannot-burn-option");

        delete holdingToken[underlyingOptionId[_tokenId]];
        _burn(_tokenId);
    }

getOptionCostETH keyboard_arrow_up

Parameters help

Name Type
_period
uint help
_amount
uint help
_strike
uint help
_optionType
IHegicOptions.OptionType help

Properties

Visibility help public
Mutability help view
Source Code
    function getOptionCostETH(
        uint _period,
        uint _amount,
        uint _strike,
        IHegicOptions.OptionType _optionType
    )
        public
        view
        override
        returns (uint ethCost)
    {
        (ethCost, , , ) = IHegicETHOptions(address(optionsProvider)).fees(_period, _amount, _strike, _optionType);
    }

getUnderlyingOptionId keyboard_arrow_up

Parameters help

Name Type
_tokenId
uint help

Properties

Visibility help public
Mutability help view
Source Code
    function getUnderlyingOptionId(uint _tokenId) external view returns (uint) {
        return underlyingOptionId[_tokenId];
    }

getUnderlyingOptionParams keyboard_arrow_up

Parameters help

Name Type
_tokenId
uint help

Properties

Visibility help public
Mutability help view
Source Code
    function getUnderlyingOptionParams(uint _tokenId)
        public
        view
        returns (
        IHegicOptions.State state,
        address payable holder,
        uint256 strike,
        uint256 amount,
        uint256 lockedAmount,
        uint256 premium,
        uint256 expiration,
        IHegicOptions.OptionType optionType)
    {
        (state,
         holder,
         strike,
         amount,
         lockedAmount,
         premium,
         expiration,
         optionType) = optionsProvider.options(underlyingOptionId[_tokenId]);
    }

isValidToken keyboard_arrow_up

Parameters help

Name Type
_tokenId
uint help

Properties

Visibility help public
Mutability help view
Source Code
    function isValidToken(uint _tokenId) external view returns (bool){
        (, address holder, , , , , ,) = getUnderlyingOptionParams(_tokenId);
        return holder == address(this);
    }

constructor keyboard_arrow_up

Parameters help

This function has no parameters.

Properties

Visibility help public
Mutability help payable
Source Code
    receive() external payable {}