Skip to content

BinaryOption

Description

The BinaryOption contract provides ERC20 token functionality for the options in a BinaryOptionMarket. One BinaryOption instance is created for each of the long and short sides of the market. Once claimed, binary options can be transferred around like any other ERC20 token until they are exercised from their parent market.

This contract tracks the value on a particular side of the market throughout the entire lifecycle, handling both bid and option balances, and the basic operations of converting between them. Whenever a bid is made or refunded, or an option claimed or exercised, the values in this contract are updated by the market.

Related Contracts

Source: contracts/BinaryOption.sol

Variables

allowance

Source

The ERC20 allowances of this option. allowance[owner][spender] is the value of options spender is approved to transfer on behalf of owner.

Type: mapping(address => mapping(address => uint256))

balanceOf

Source

The ERC20 balance of this option for each account.

Type: mapping(address => uint256)

bidOf

Source

The current bid on this option made by each address.

Type: mapping(address => uint256)

decimals

Source

The ERC20 number of decimals of this token. Hardcoded to 18.

Type: uint8

market

Source

The parent market of this option.

Type: contract BinaryOptionMarket

name

Source

The ERC20 name of this token.

Type: string

symbol

Source

The ERC20 symbol of this token.

Type: string

totalBids

Source

The total value of bids made by all addresses.

Type: uint256

totalSupply

Source

The ERC20 total supply of this option.

Type: uint256

Constructor

constructor

Source

The constructor initialises the parent market address and sets the initial bid by the creator of the parent market on this option.

Details

Signature

constructor(address initialBidder, uint256 initialBid)

Visibility

public

State Mutability

``

Views

claimableBalanceOf

Source

Returns the quantity of options claimable by an account at the current price. If account contains the entire (nonzero) bid supply, then their claimable amount is the total remaining supply of options, which accounts for any slight rounding errors.

Details

Signature

claimableBalanceOf(address account) view returns (uint256)

Visibility

external

State Mutability

view

totalClaimableSupply

Source

Returns the total supply of options claimable by all bidders.

Details

Signature

totalClaimableSupply() view returns (uint256)

Visibility

external

State Mutability

view

Restricted Functions

bid

Source

Allows the parent market to increase the bid for a particular address.

Details

Signature

bid(address bidder, uint256 newBid)

Visibility

external

State Mutability

``

Modifiers

claim

Source

Allows the market to convert the entire claimable balance of a given account into options. On invocation, the bid is set to zero, while claimableBalanceOf(account) tokens are issued into the account. The Issued event emitted is accompanied by a Transfer event from the zero address.

Details

Signature

claim(address claimant, uint256 price, uint256 depositsRemaining) returns (uint256 optionsClaimed)

Visibility

external

State Mutability

``

Modifiers

Emits

exercise

Source

Allows the market to burn the entire token balance in a given account. The Burned event emitted is accompanied by a Transfer event to the zero address.

Details

Signature

exercise(address claimant)

Visibility

external

State Mutability

``

Modifiers

Emits

expire

Source

Allows the market to destroy this option contract.

Details

Signature

expire(address payable beneficiary)

Visibility

external

State Mutability

``

Modifiers

refund

Source

Allows the parent market to decrease the bid for a particular address. The transaction is reverted if the desired refund exceeds the current bid of the account.

Details

Signature

refund(address bidder, uint256 newRefund)

Visibility

external

State Mutability

``

Modifiers

Internal Functions

_claimableBalanceOf

Source

See claimableBalanceOf.

This function requires the quantity of exercisable deposits in the parent market just in case the claimable value in the last account is different from the remaining deposits by a few wei due to rounding errors.

Details

Signature

_claimableBalanceOf(uint256 _bid, uint256 price, uint256 exercisableDeposits) view returns (uint256)

Visibility

internal

State Mutability

view

Requires

_requireMinimumBid

Source

Reverts the transaction if the bid provided to its argument is less than 1 cent. This minimum value ensures that any last-bidder attacks based on the rounding error must accumulate at least 10^{16} wei worth of rounding errors before they spill over into other accounts. A single division during the claim function is the only thing that introduces such rounding errors, so such rounding-based attacks would require an infeasibly-large number of accounts to perform.

Details

Signature

_requireMinimumBid(uint256 bid) pure returns (uint256)

Visibility

internal

State Mutability

pure

Requires

_totalClaimableSupply

Source

See totalClaimableSupply. Takes the total deposits in the system for a similar reason to claimableBalanceOf.

Details

Signature

_totalClaimableSupply(uint256 exercisableDeposits) view returns (uint256)

Visibility

internal

State Mutability

view

_transfer

Source

Implements the internal behaviour of the transfer and transferFrom functions. Reverts if either sender or recipient is the zero account, or if the balance in the sending account is insufficient, or if the system is not operating.

Details

Signature

_transfer(address _from, address _to, uint256 _value) returns (bool success)

Visibility

internal

State Mutability

``

Requires

Emits

External Functions

approve

Source

Allows an account to approve another account to transfer tokens on its behalf. Reverts if the designated spender is the zero account.

Details

Signature

approve(address _spender, uint256 _value) returns (bool success)

Visibility

external

State Mutability

``

Requires

Emits

transfer

Source

Transfers a quantity of options between accounts. Reverts if the balance in the sending account is insufficient, if the destination address is the zero address, or if the system is not operating. Implemented internally by the _transfer function.

Details

Signature

transfer(address _to, uint256 _value) returns (bool success)

Visibility

external

State Mutability

``

transferFrom

Source

Allows an account to transfer a quantity of options on behalf of another account. Reverts if the either the balance or sender approval is insufficient, if either the destination or sending addresses is the zero address, or if the system is not operating. Implemented internally by the _transfer function.

Details

Signature

transferFrom(address _from, address _to, uint256 _value) returns (bool success)

Visibility

external

State Mutability

``

Requires

Modifiers

onlyMarket

Source

Reverts the transaction if the message sender is not the market.

Events

Approval

Source

A spending account was approved to transfer options by another account on its behalf.

Signature: Approval(address owner, address spender, uint256 value)

Burned

Source

A value of options was burned from the given account.

Signature: Burned(address account, uint256 value)

Issued

Source

A value of options was issued into the given account.

Signature: Issued(address account, uint256 value)

Transfer

Source

A value of options was transferred between accounts.

Signature: Transfer(address from, address to, uint256 value)