Skip to content

Latest commit

 

History

History
2177 lines (1527 loc) · 54.4 KB

File metadata and controls

2177 lines (1527 loc) · 54.4 KB

Solidity API

Ownable

Contract module which provides a basic access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions. By default, the owner account will be the one that deploys the contract. This can later be changed with {transferOwnership}. This module is used through inheritance. It will make available the modifier `onlyOwner`, which can be applied to your functions to restrict their use to the owner.

_owner

address _owner

OwnershipTransferred

event OwnershipTransferred(address previousOwner, address newOwner)

constructor

constructor() internal

Initializes the contract setting the deployer as the initial owner.

owner

function owner() public view virtual returns (address)

Returns the address of the current owner.

onlyOwner

modifier onlyOwner()

Throws if called by any account other than the owner.

renounceOwnership

function renounceOwnership() public virtual

Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.

transferOwnership

function transferOwnership(address newOwner) public virtual

Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.

_setOwner

function _setOwner(address newOwner) private

ERC20

_Implementation of the {IERC20} interface. This implementation is agnostic to the way tokens are created. This means that a supply mechanism has to be added in a derived contract using {mint}. For a generic mechanism see {ERC20PresetMinterPauser}. TIP: For a detailed writeup see our guide https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How to implement supply mechanisms]. We have followed general OpenZeppelin Contracts guidelines: functions revert instead returning `false` on failure. This behavior is nonetheless conventional and does not conflict with the expectations of ERC20 applications. Additionally, an {Approval} event is emitted on calls to {transferFrom}. This allows applications to reconstruct the allowance for all accounts just by listening to said events. Other implementations of the EIP may not emit these events, as it isn't required by the specification. Finally, the non-standard {decreaseAllowance} and {increaseAllowance} functions have been added to mitigate the well-known issues around setting allowances. See {IERC20-approve}.

_balances

mapping(address => uint256) _balances

_allowances

mapping(address => mapping(address => uint256)) _allowances

_totalSupply

uint256 _totalSupply

_name

string _name

_symbol

string _symbol

constructor

constructor(string name_, string symbol_) public

Sets the values for {name} and {symbol}. The default value of {decimals} is 18. To select a different value for {decimals} you should overload it. All two of these values are immutable: they can only be set once during construction.

name

function name() public view virtual returns (string)

Returns the name of the token.

symbol

function symbol() public view virtual returns (string)

Returns the symbol of the token, usually a shorter version of the name.

decimals

function decimals() public view virtual returns (uint8)

Returns the number of decimals used to get its user representation. For example, if `decimals` equals `2`, a balance of `505` tokens should be displayed to a user as `5.05` (`505 / 10 ** 2`). Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. This is the value {ERC20} uses, unless this function is overridden; NOTE: This information is only used for display purposes: it in no way affects any of the arithmetic of the contract, including {IERC20-balanceOf} and {IERC20-transfer}.

totalSupply

function totalSupply() public view virtual returns (uint256)

See {IERC20-totalSupply}.

balanceOf

function balanceOf(address account) public view virtual returns (uint256)

See {IERC20-balanceOf}.

transfer

function transfer(address recipient, uint256 amount) public virtual returns (bool)

_See {IERC20-transfer}. Requirements:

  • `recipient` cannot be the zero address.
  • the caller must have a balance of at least `amount`._

allowance

function allowance(address owner, address spender) public view virtual returns (uint256)

See {IERC20-allowance}.

approve

function approve(address spender, uint256 amount) public virtual returns (bool)

_See {IERC20-approve}. Requirements:

  • `spender` cannot be the zero address._

transferFrom

function transferFrom(address sender, address recipient, uint256 amount) public virtual returns (bool)

_See {IERC20-transferFrom}. Emits an {Approval} event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of {ERC20}. Requirements:

  • `sender` and `recipient` cannot be the zero address.
  • `sender` must have a balance of at least `amount`.
  • the caller must have allowance for ``sender``'s tokens of at least `amount`._

increaseAllowance

function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool)

_Atomically increases the allowance granted to `spender` by the caller. This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}. Emits an {Approval} event indicating the updated allowance. Requirements:

  • `spender` cannot be the zero address._

decreaseAllowance

function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool)

_Atomically decreases the allowance granted to `spender` by the caller. This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}. Emits an {Approval} event indicating the updated allowance. Requirements:

  • `spender` cannot be the zero address.
  • `spender` must have allowance for the caller of at least `subtractedValue`._

_transfer

function _transfer(address sender, address recipient, uint256 amount) internal virtual

_Moves `amount` of tokens from `sender` to `recipient`. This internal function is equivalent to {transfer}, and can be used to e.g. implement automatic token fees, slashing mechanisms, etc. Emits a {Transfer} event. Requirements:

  • `sender` cannot be the zero address.
  • `recipient` cannot be the zero address.
  • `sender` must have a balance of at least `amount`._

_mint

function _mint(address account, uint256 amount) internal virtual

_Creates `amount` tokens and assigns them to `account`, increasing the total supply. Emits a {Transfer} event with `from` set to the zero address. Requirements:

  • `account` cannot be the zero address._

_burn

function _burn(address account, uint256 amount) internal virtual

_Destroys `amount` tokens from `account`, reducing the total supply. Emits a {Transfer} event with `to` set to the zero address. Requirements:

  • `account` cannot be the zero address.
  • `account` must have at least `amount` tokens._

_approve

function _approve(address owner, address spender, uint256 amount) internal virtual

_Sets `amount` as the allowance of `spender` over the `owner` s tokens. This internal function is equivalent to `approve`, and can be used to e.g. set automatic allowances for certain subsystems, etc. Emits an {Approval} event. Requirements:

  • `owner` cannot be the zero address.
  • `spender` cannot be the zero address._

_beforeTokenTransfer

function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual

_Hook that is called before any transfer of tokens. This includes minting and burning. Calling conditions:

  • when `from` and `to` are both non-zero, `amount` of ``from``'s tokens will be transferred to `to`.
  • when `from` is zero, `amount` tokens will be minted for `to`.
  • when `to` is zero, `amount` of ``from``'s tokens will be burned.
  • `from` and `to` are never both zero. To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]._

_afterTokenTransfer

function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual

_Hook that is called after any transfer of tokens. This includes minting and burning. Calling conditions:

  • when `from` and `to` are both non-zero, `amount` of ``from``'s tokens has been transferred to `to`.
  • when `from` is zero, `amount` tokens have been minted for `to`.
  • when `to` is zero, `amount` of ``from``'s tokens have been burned.
  • `from` and `to` are never both zero. To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]._

IERC20

Interface of the ERC20 standard as defined in the EIP.

totalSupply

function totalSupply() external view returns (uint256)

Returns the amount of tokens in existence.

balanceOf

function balanceOf(address account) external view returns (uint256)

Returns the amount of tokens owned by `account`.

transfer

function transfer(address recipient, uint256 amount) external returns (bool)

Moves `amount` tokens from the caller's account to `recipient`. Returns a boolean value indicating whether the operation succeeded. Emits a {Transfer} event.

allowance

function allowance(address owner, address spender) external view returns (uint256)

Returns the remaining number of tokens that `spender` will be allowed to spend on behalf of `owner` through {transferFrom}. This is zero by default. This value changes when {approve} or {transferFrom} are called.

approve

function approve(address spender, uint256 amount) external returns (bool)

Sets `amount` as the allowance of `spender` over the caller's tokens. Returns a boolean value indicating whether the operation succeeded. IMPORTANT: Beware that changing an allowance with this method brings the risk that someone may use both the old and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: ethereum/EIPs#20 (comment) Emits an {Approval} event.

transferFrom

function transferFrom(address sender, address recipient, uint256 amount) external returns (bool)

Moves `amount` tokens from `sender` to `recipient` using the allowance mechanism. `amount` is then deducted from the caller's allowance. Returns a boolean value indicating whether the operation succeeded. Emits a {Transfer} event.

Transfer

event Transfer(address from, address to, uint256 value)

Emitted when `value` tokens are moved from one account (`from`) to another (`to`). Note that `value` may be zero.

Approval

event Approval(address owner, address spender, uint256 value)

Emitted when the allowance of a `spender` for an `owner` is set by a call to {approve}. `value` is the new allowance.

IERC20Metadata

Interface for the optional metadata functions from the ERC20 standard. Available since v4.1.

name

function name() external view returns (string)

Returns the name of the token.

symbol

function symbol() external view returns (string)

Returns the symbol of the token.

decimals

function decimals() external view returns (uint8)

Returns the decimals places of the token.

ERC721

Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including the Metadata extension, but not including the Enumerable extension, which is available separately as {ERC721Enumerable}.

_name

string _name

_symbol

string _symbol

_owners

mapping(uint256 => address) _owners

_balances

mapping(address => uint256) _balances

_tokenApprovals

mapping(uint256 => address) _tokenApprovals

_operatorApprovals

mapping(address => mapping(address => bool)) _operatorApprovals

constructor

constructor(string name_, string symbol_) public

Initializes the contract by setting a `name` and a `symbol` to the token collection.

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool)

See {IERC165-supportsInterface}.

balanceOf

function balanceOf(address owner) public view virtual returns (uint256)

See {IERC721-balanceOf}.

ownerOf

function ownerOf(uint256 tokenId) public view virtual returns (address)

See {IERC721-ownerOf}.

name

function name() public view virtual returns (string)

See {IERC721Metadata-name}.

symbol

function symbol() public view virtual returns (string)

See {IERC721Metadata-symbol}.

tokenURI

function tokenURI(uint256 tokenId) public view virtual returns (string)

See {IERC721Metadata-tokenURI}.

_baseURI

function _baseURI() internal view virtual returns (string)

Base URI for computing {tokenURI}. If set, the resulting URI for each token will be the concatenation of the `baseURI` and the `tokenId`. Empty by default, can be overriden in child contracts.

approve

function approve(address to, uint256 tokenId) public virtual

See {IERC721-approve}.

getApproved

function getApproved(uint256 tokenId) public view virtual returns (address)

See {IERC721-getApproved}.

setApprovalForAll

function setApprovalForAll(address operator, bool approved) public virtual

See {IERC721-setApprovalForAll}.

isApprovedForAll

function isApprovedForAll(address owner, address operator) public view virtual returns (bool)

See {IERC721-isApprovedForAll}.

transferFrom

function transferFrom(address from, address to, uint256 tokenId) public virtual

See {IERC721-transferFrom}.

safeTransferFrom

function safeTransferFrom(address from, address to, uint256 tokenId) public virtual

See {IERC721-safeTransferFrom}.

safeTransferFrom

function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public virtual

See {IERC721-safeTransferFrom}.

_safeTransfer

function _safeTransfer(address from, address to, uint256 tokenId, bytes _data) internal virtual

_Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients are aware of the ERC721 protocol to prevent tokens from being forever locked. `_data` is additional data, it has no specified format and it is sent in call to `to`. This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. implement alternative mechanisms to perform token transfer, such as signature-based. Requirements:

  • `from` cannot be the zero address.
  • `to` cannot be the zero address.
  • `tokenId` token must exist and be owned by `from`.
  • If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. Emits a {Transfer} event._

_exists

function _exists(uint256 tokenId) internal view virtual returns (bool)

_Returns whether `tokenId` exists. Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. Tokens start existing when they are minted (`_mint`), and stop existing when they are burned (`burn`).

_isApprovedOrOwner

function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool)

_Returns whether `spender` is allowed to manage `tokenId`. Requirements:

  • `tokenId` must exist._

_safeMint

function _safeMint(address to, uint256 tokenId) internal virtual

_Safely mints `tokenId` and transfers it to `to`. Requirements:

  • `tokenId` must not exist.
  • If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. Emits a {Transfer} event._

_safeMint

function _safeMint(address to, uint256 tokenId, bytes _data) internal virtual

_Same as {xref-ERC721-_safeMint-address-uint256-}[`safeMint`], with an additional `data` parameter which is forwarded in {IERC721Receiver-onERC721Received} to contract recipients.

_mint

function _mint(address to, uint256 tokenId) internal virtual

_Mints `tokenId` and transfers it to `to`. WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible Requirements:

  • `tokenId` must not exist.
  • `to` cannot be the zero address. Emits a {Transfer} event._

_burn

function _burn(uint256 tokenId) internal virtual

_Destroys `tokenId`. The approval is cleared when the token is burned. Requirements:

  • `tokenId` must exist. Emits a {Transfer} event._

_transfer

function _transfer(address from, address to, uint256 tokenId) internal virtual

_Transfers `tokenId` from `from` to `to`. As opposed to {transferFrom}, this imposes no restrictions on msg.sender. Requirements:

  • `to` cannot be the zero address.
  • `tokenId` token must be owned by `from`. Emits a {Transfer} event._

_approve

function _approve(address to, uint256 tokenId) internal virtual

Approve `to` to operate on `tokenId` Emits a {Approval} event.

_checkOnERC721Received

function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes _data) private returns (bool)

Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. The call is not executed if the target address is not a contract.

Name Type Description
from address address representing the previous owner of the given token ID
to address target address that will receive the tokens
tokenId uint256 uint256 ID of the token to be transferred
_data bytes bytes optional data to send along with the call
Name Type Description
[0] bool bool whether the call correctly returned the expected magic value

_beforeTokenTransfer

function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual

_Hook that is called before any token transfer. This includes minting and burning. Calling conditions:

  • When `from` and `to` are both non-zero, ``from``'s `tokenId` will be transferred to `to`.
  • When `from` is zero, `tokenId` will be minted for `to`.
  • When `to` is zero, ``from``'s `tokenId` will be burned.
  • `from` and `to` are never both zero. To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]._

IERC721

Required interface of an ERC721 compliant contract.

Transfer

event Transfer(address from, address to, uint256 tokenId)

Emitted when `tokenId` token is transferred from `from` to `to`.

Approval

event Approval(address owner, address approved, uint256 tokenId)

Emitted when `owner` enables `approved` to manage the `tokenId` token.

ApprovalForAll

event ApprovalForAll(address owner, address operator, bool approved)

Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.

balanceOf

function balanceOf(address owner) external view returns (uint256 balance)

Returns the number of tokens in ``owner``'s account.

ownerOf

function ownerOf(uint256 tokenId) external view returns (address owner)

_Returns the owner of the `tokenId` token. Requirements:

  • `tokenId` must exist._

safeTransferFrom

function safeTransferFrom(address from, address to, uint256 tokenId) external

_Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients are aware of the ERC721 protocol to prevent tokens from being forever locked. Requirements:

  • `from` cannot be the zero address.
  • `to` cannot be the zero address.
  • `tokenId` token must exist and be owned by `from`.
  • If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
  • If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. Emits a {Transfer} event._

transferFrom

function transferFrom(address from, address to, uint256 tokenId) external

_Transfers `tokenId` token from `from` to `to`. WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. Requirements:

  • `from` cannot be the zero address.
  • `to` cannot be the zero address.
  • `tokenId` token must be owned by `from`.
  • If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. Emits a {Transfer} event._

approve

function approve(address to, uint256 tokenId) external

_Gives permission to `to` to transfer `tokenId` token to another account. The approval is cleared when the token is transferred. Only a single account can be approved at a time, so approving the zero address clears previous approvals. Requirements:

  • The caller must own the token or be an approved operator.
  • `tokenId` must exist. Emits an {Approval} event._

getApproved

function getApproved(uint256 tokenId) external view returns (address operator)

_Returns the account approved for `tokenId` token. Requirements:

  • `tokenId` must exist._

setApprovalForAll

function setApprovalForAll(address operator, bool _approved) external

_Approve or remove `operator` as an operator for the caller. Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. Requirements:

  • The `operator` cannot be the caller. Emits an {ApprovalForAll} event._

isApprovedForAll

function isApprovedForAll(address owner, address operator) external view returns (bool)

Returns if the `operator` is allowed to manage all of the assets of `owner`. See {setApprovalForAll}

safeTransferFrom

function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) external

_Safely transfers `tokenId` token from `from` to `to`. Requirements:

  • `from` cannot be the zero address.
  • `to` cannot be the zero address.
  • `tokenId` token must exist and be owned by `from`.
  • If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
  • If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. Emits a {Transfer} event._

IERC721Receiver

Interface for any contract that wants to support safeTransfers from ERC721 asset contracts.

onERC721Received

function onERC721Received(address operator, address from, uint256 tokenId, bytes data) external returns (bytes4)

Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} by `operator` from `from`, this function is called. It must return its Solidity selector to confirm the token transfer. If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.

ERC721Enumerable

This implements an optional extension of {ERC721} defined in the EIP that adds enumerability of all the token ids in the contract as well as all token ids owned by each account.

_ownedTokens

mapping(address => mapping(uint256 => uint256)) _ownedTokens

_ownedTokensIndex

mapping(uint256 => uint256) _ownedTokensIndex

_allTokens

uint256[] _allTokens

_allTokensIndex

mapping(uint256 => uint256) _allTokensIndex

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool)

See {IERC165-supportsInterface}.

tokenOfOwnerByIndex

function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual returns (uint256)

See {IERC721Enumerable-tokenOfOwnerByIndex}.

totalSupply

function totalSupply() public view virtual returns (uint256)

See {IERC721Enumerable-totalSupply}.

tokenByIndex

function tokenByIndex(uint256 index) public view virtual returns (uint256)

See {IERC721Enumerable-tokenByIndex}.

_beforeTokenTransfer

function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual

_Hook that is called before any token transfer. This includes minting and burning. Calling conditions:

  • When `from` and `to` are both non-zero, ``from``'s `tokenId` will be transferred to `to`.
  • When `from` is zero, `tokenId` will be minted for `to`.
  • When `to` is zero, ``from``'s `tokenId` will be burned.
  • `from` cannot be the zero address.
  • `to` cannot be the zero address. To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]._

_addTokenToOwnerEnumeration

function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private

Private function to add a token to this extension's ownership-tracking data structures.

Name Type Description
to address address representing the new owner of the given token ID
tokenId uint256 uint256 ID of the token to be added to the tokens list of the given address

_addTokenToAllTokensEnumeration

function _addTokenToAllTokensEnumeration(uint256 tokenId) private

Private function to add a token to this extension's token tracking data structures.

Name Type Description
tokenId uint256 uint256 ID of the token to be added to the tokens list

_removeTokenFromOwnerEnumeration

function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private

_Private function to remove a token from this extension's ownership-tracking data structures. Note that while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is not updated: this allows for gas optimizations e.g. when performing a transfer operation (avoiding double writes). This has O(1) time complexity, but alters the order of the ownedTokens array.

Name Type Description
from address address representing the previous owner of the given token ID
tokenId uint256 uint256 ID of the token to be removed from the tokens list of the given address

_removeTokenFromAllTokensEnumeration

function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private

_Private function to remove a token from this extension's token tracking data structures. This has O(1) time complexity, but alters the order of the allTokens array.

Name Type Description
tokenId uint256 uint256 ID of the token to be removed from the tokens list

IERC721Enumerable

See https://eips.ethereum.org/EIPS/eip-721

totalSupply

function totalSupply() external view returns (uint256)

Returns the total amount of tokens stored by the contract.

tokenOfOwnerByIndex

function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId)

Returns a token ID owned by `owner` at a given `index` of its token list. Use along with {balanceOf} to enumerate all of ``owner``'s tokens.

tokenByIndex

function tokenByIndex(uint256 index) external view returns (uint256)

Returns a token ID at a given `index` of all the tokens stored by the contract. Use along with {totalSupply} to enumerate all tokens.

IERC721Metadata

See https://eips.ethereum.org/EIPS/eip-721

name

function name() external view returns (string)

Returns the token collection name.

symbol

function symbol() external view returns (string)

Returns the token collection symbol.

tokenURI

function tokenURI(uint256 tokenId) external view returns (string)

Returns the Uniform Resource Identifier (URI) for `tokenId` token.

Address

Collection of functions related to the address type

isContract

function isContract(address account) internal view returns (bool)

_Returns true if `account` is a contract. [IMPORTANT] ==== It is unsafe to assume that an address for which this function returns false is an externally-owned account (EOA) and not a contract. Among others, `isContract` will return false for the following types of addresses:

  • an externally-owned account
  • a contract in construction
  • an address where a contract will be created
  • an address where a contract lived, but was destroyed ====_

sendValue

function sendValue(address payable recipient, uint256 amount) internal

Replacement for Solidity's `transfer`: sends `amount` wei to `recipient`, forwarding all available gas and reverting on errors. https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost of certain opcodes, possibly making contracts go over the 2300 gas limit imposed by `transfer`, making them unable to receive funds via `transfer`. {sendValue} removes this limitation. https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. IMPORTANT: because control is transferred to `recipient`, care must be taken to not create reentrancy vulnerabilities. Consider using {ReentrancyGuard} or the https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].

functionCall

function functionCall(address target, bytes data) internal returns (bytes)

_Performs a Solidity function call using a low level `call`. A plain `call` is an unsafe replacement for a function call: use this function instead. If `target` reverts with a revert reason, it is bubbled up by this function (like regular Solidity function calls). Returns the raw returned data. To convert to the expected return value, use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. Requirements:

  • `target` must be a contract.
  • calling `target` with `data` must not revert. Available since v3.1._

functionCall

function functionCall(address target, bytes data, string errorMessage) internal returns (bytes)

Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with `errorMessage` as a fallback revert reason when `target` reverts. Available since v3.1.

functionCallWithValue

function functionCallWithValue(address target, bytes data, uint256 value) internal returns (bytes)

_Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but also transferring `value` wei to `target`. Requirements:

  • the calling contract must have an ETH balance of at least `value`.
  • the called Solidity function must be `payable`. Available since v3.1._

functionCallWithValue

function functionCallWithValue(address target, bytes data, uint256 value, string errorMessage) internal returns (bytes)

Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but with `errorMessage` as a fallback revert reason when `target` reverts. Available since v3.1.

functionStaticCall

function functionStaticCall(address target, bytes data) internal view returns (bytes)

Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but performing a static call. Available since v3.3.

functionStaticCall

function functionStaticCall(address target, bytes data, string errorMessage) internal view returns (bytes)

Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], but performing a static call. Available since v3.3.

functionDelegateCall

function functionDelegateCall(address target, bytes data) internal returns (bytes)

Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but performing a delegate call. Available since v3.4.

functionDelegateCall

function functionDelegateCall(address target, bytes data, string errorMessage) internal returns (bytes)

Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], but performing a delegate call. Available since v3.4.

verifyCallResult

function verifyCallResult(bool success, bytes returndata, string errorMessage) internal pure returns (bytes)

Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the revert reason using the provided one. Available since v4.3.

Context

Provides information about the current execution context, including the sender of the transaction and its data. While these are generally available via msg.sender and msg.data, they should not be accessed in such a direct manner, since when dealing with meta-transactions the account sending and paying for execution may not be the actual sender (as far as an application is concerned). This contract is only required for intermediate, library-like contracts.

_msgSender

function _msgSender() internal view virtual returns (address)

_msgData

function _msgData() internal view virtual returns (bytes)

Strings

String operations.

_HEX_SYMBOLS

bytes16 _HEX_SYMBOLS

toString

function toString(uint256 value) internal pure returns (string)

Converts a `uint256` to its ASCII `string` decimal representation.

toHexString

function toHexString(uint256 value) internal pure returns (string)

Converts a `uint256` to its ASCII `string` hexadecimal representation.

toHexString

function toHexString(uint256 value, uint256 length) internal pure returns (string)

Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.

ERC165

Implementation of the {IERC165} interface. Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check for the additional interface id that will be supported. For example: ```solidity function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); } ``` Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool)

See {IERC165-supportsInterface}.

IERC165

Interface of the ERC165 standard, as defined in the https://eips.ethereum.org/EIPS/eip-165[EIP]. Implementers can declare support of contract interfaces, which can then be queried by others ({ERC165Checker}). For an implementation, see {ERC165}.

supportsInterface

function supportsInterface(bytes4 interfaceId) external view returns (bool)

Returns true if this contract implements the interface defined by `interfaceId`. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

SafeMath

Wrappers over Solidity's arithmetic operations. NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler now has built in overflow checking.

tryAdd

function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256)

Returns the addition of two unsigned integers, with an overflow flag. Available since v3.4.

trySub

function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256)

Returns the substraction of two unsigned integers, with an overflow flag. Available since v3.4.

tryMul

function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256)

Returns the multiplication of two unsigned integers, with an overflow flag. Available since v3.4.

tryDiv

function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256)

Returns the division of two unsigned integers, with a division by zero flag. Available since v3.4.

tryMod

function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256)

Returns the remainder of dividing two unsigned integers, with a division by zero flag. Available since v3.4.

add

function add(uint256 a, uint256 b) internal pure returns (uint256)

_Returns the addition of two unsigned integers, reverting on overflow. Counterpart to Solidity's `+` operator. Requirements:

  • Addition cannot overflow._

sub

function sub(uint256 a, uint256 b) internal pure returns (uint256)

_Returns the subtraction of two unsigned integers, reverting on overflow (when the result is negative). Counterpart to Solidity's `-` operator. Requirements:

  • Subtraction cannot overflow._

mul

function mul(uint256 a, uint256 b) internal pure returns (uint256)

_Returns the multiplication of two unsigned integers, reverting on overflow. Counterpart to Solidity's `*` operator. Requirements:

  • Multiplication cannot overflow._

div

function div(uint256 a, uint256 b) internal pure returns (uint256)

_Returns the integer division of two unsigned integers, reverting on division by zero. The result is rounded towards zero. Counterpart to Solidity's `/` operator. Requirements:

  • The divisor cannot be zero._

mod

function mod(uint256 a, uint256 b) internal pure returns (uint256)

_Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), reverting when dividing by zero. Counterpart to Solidity's `%` operator. This function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas). Requirements:

  • The divisor cannot be zero._

sub

function sub(uint256 a, uint256 b, string errorMessage) internal pure returns (uint256)

_Returns the subtraction of two unsigned integers, reverting with custom message on overflow (when the result is negative). CAUTION: This function is deprecated because it requires allocating memory for the error message unnecessarily. For custom revert reasons use {trySub}. Counterpart to Solidity's `-` operator. Requirements:

  • Subtraction cannot overflow._

div

function div(uint256 a, uint256 b, string errorMessage) internal pure returns (uint256)

_Returns the integer division of two unsigned integers, reverting with custom message on division by zero. The result is rounded towards zero. Counterpart to Solidity's `/` operator. Note: this function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas). Requirements:

  • The divisor cannot be zero._

mod

function mod(uint256 a, uint256 b, string errorMessage) internal pure returns (uint256)

_Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), reverting with custom message when dividing by zero. CAUTION: This function is deprecated because it requires allocating memory for the error message unnecessarily. For custom revert reasons use {tryMod}. Counterpart to Solidity's `%` operator. This function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas). Requirements:

  • The divisor cannot be zero._

DAppMarket

constructor

constructor(address tbAddress) public

_totalSupply

uint256 _totalSupply

_totalTraffic

uint256 _totalTraffic

_TBAddress

address _TBAddress

referalFee

uint256 referalFee

feePoint

uint256 feePoint

publishFee

uint256 publishFee

DAppData

mapping(uint256 => struct IDAppMarket.DAppStruct) DAppData

collectTraffic

function collectTraffic(uint256 length, uint256[] _tokenId, uint256[] _traffic) public

Collect Traffic to NFT's and transfer referalFee to this contract

Name Type Description
length uint256 uint - size of arrays
_tokenId uint256[] - array of token ids [1,2,3]
_traffic uint256[] - array of amount of bytes [1024^3, 5x1024^3, 10x1024^3]

getMetaData

function getMetaData(uint256 _tokenId) public view returns (struct IDAppMarket.DAppStruct)

return full metadata, for external apps can be expensive to check, but retuns full info

getNFTBalance

function getNFTBalance(uint256 _itemId) public view returns (uint256)

(NFT.traffic - NFT.payedTraffic) x this.tbBalance / totalTraffic

Name Type Description
_itemId uint256 - NFT token id
Name Type Description
[0] uint256 TB balance of this token

tokenURI

function tokenURI(uint256 tokenId) public view returns (string)

Returns the Uniform Resource Identifier (URI) for `tokenId` token.

tokenContentHash

function tokenContentHash(uint256 tokenId) public view returns (bytes32)

Return the content hash of resourse for `tokenId`.

totalSupply

function totalSupply() public view returns (uint256)

totalSupply - amount of minted dapps tokens

claimReward

function claimReward(uint256 _itemId) public

_Owner of item can get collected reward Check owner of itemId, no need to check exist, because in exist check owner != 0

claimRewardMany

function claimRewardMany(uint256[] _itemIds) public

Claim many

Name Type Description
_itemIds uint256[] - array of NFTids owned by user

wrappedPointer

mapping(bytes32 => uint256) wrappedPointer

keccak(origin.address + origin.id) => WNFT id

CreateDApp

function CreateDApp(string dAppURI, bytes32 _contentHash) public

Creating DApp as NFT

updateVersion

function updateVersion(uint256 tokenId, string dAppURI, bytes32 contentHash) public

owner can deploy updates, if content hash modified

onERC721Received

function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) public view returns (bytes4)

SafeTransferFrom require this function

DeNetDNS

constructor

constructor(address tbAddress) public

DeNetDNS

struct DeNetDNS {
  string URI;
  string DomainZone;
  bytes32 URIHash;
  uint256 nextPaymentBefore;
  uint256 DAppID;
  bytes32 DAppContentHash;
}

ExampleNFT

constructor

constructor(string _name, string _symbol) public

_counter

uint256 _counter

mintMe

function mintMe() public

counter

function counter() public view returns (uint256)

PoSAdmin

_Contract PoSAdmin - modifier for ProofOfStorage API's

  • onlyOldAddress
  • onlyGovernance
  • whenNotPaused
  • whenPaused
  • onlyGateway_

proofOfStorageAddress

address proofOfStorageAddress

governanceAddress

address governanceAddress

_rewardTokenAddress

address _rewardTokenAddress

paused

bool paused

_isGateway

mapping(address => bool) _isGateway

constructor

constructor(address _pos, address _reward) public

onlyGovernance

modifier onlyGovernance()

whenNotPaused

modifier whenNotPaused()

whenPaused

modifier whenPaused()

pause

function pause() external

unpause

function unpause() external

changeGovernance

function changeGovernance(address _new) external

onlyPoS

modifier onlyPoS()

onlyGateway

modifier onlyGateway()

changePoS

function changePoS(address _newAddress) public

addGateway

function addGateway(address account) public

delGateway

function delGateway(address account) public

updateRewardTokenAddress

function updateRewardTokenAddress(address _new) public

Possibility update token address for next updates, will removed at finalized version

Wrapper

_Contract WNFT - Wrapped NFT made for NFT Staking program in DeNet

  • Minimal reward ~1MB
  • Amount of reward 5% (constant) of traffic, will upgraded in future with governance_

constructor

constructor(address tbAddress) public

Address of TB Token

_totalSupply

uint256 _totalSupply

_totalTraffic

uint256 _totalTraffic

referalFee

uint256 referalFee

feePoint

uint256 feePoint

_wrappedData

mapping(uint256 => struct IWrapper.WrappedStruct) _wrappedData

collectTraffic

function collectTraffic(uint256 length, uint256[] _tokenId, uint256[] _traffic) public

Collect Traffic to NFT's and transfer referalFee to this contract

Name Type Description
length uint256 uint - size of arrays
_tokenId uint256[] - array of token ids [1,2,3]
_traffic uint256[] - array of amount of bytes [1024^3, 5x1024^3, 10x1024^3]

getMetaData

function getMetaData(uint256 _tokenId) public view returns (struct IWrapper.WrappedStruct)

return full metadata, for external apps can be expensive to check, but retuns full info

getNFTBalance

function getNFTBalance(uint256 _itemId) public view returns (uint256)

(NFT.traffic - NFT.payedTraffic) x this.tbBalance / totalTraffic

Name Type Description
_itemId uint256 - NFT token id
Name Type Description
[0] uint256 TB balance of this token

tokenURI

function tokenURI(uint256 tokenId) public view returns (string)

Returns the Uniform Resource Identifier (URI) for `tokenId` token.

tokenContentHash

function tokenContentHash(uint256 tokenId) public view returns (bytes32)

Return the content hash of resourse for `tokenId`.

totalSupply

function totalSupply() public view returns (uint256)

_totalSupply - total amount of supplied WNFT's

claimReward

function claimReward(uint256 _itemId) public

Approved operator can claim reward on own address

_Owner of item can get collected reward Check owner of itemId, no need to check exist, because in exist check owner != 0

claimRewardMany

function claimRewardMany(uint256[] _itemIds) public

Claim many

Name Type Description
_itemIds uint256[] array of NFTids owned by user

wrap

function wrap(address originAddress, uint256 tokenId, bytes32 originContentHash, string storageURI, uint256 contentSize) public

_Make NFT as WrappedNFT

  1. Create pointer: keccak(address, token_id)
  2. TransferFrom origin to this
  3. Fill Metadata_

unwrap

function unwrap(uint256 tokenId) public

_unwrap and burn

  1. Sender == Owner or Approved
  2. Transfer to Sender
  3. Burn wrapped_

IDAppMarket

DAppStruct

struct DAppStruct {
  string URI;
  uint256 traffic;
  uint256 payedTraffic;
  bytes32 contentHash;
  bool burned;
  bytes32[] versionHashes;
  uint256 currentVersion;
}

claimReward

function claimReward(uint256 _itemId) external

_Owner of item can get collected reward Check owner of itemId, no need to check exist, because in exist check owner != 0

claimRewardMany

function claimRewardMany(uint256[] _itemIds) external

Claim many

Name Type Description
_itemIds uint256[] - array of NFTids owned by user

tokenContentHash

function tokenContentHash(uint256 _itemId) external view returns (bytes32)

return Content Hash of NFT

getNFTBalance

function getNFTBalance(uint256 _itemId) external view returns (uint256)

returns NFT Balanc of earned tokens

getMetaData

function getMetaData(uint256 _tokenId) external view returns (struct IDAppMarket.DAppStruct)

return full metadata, for external apps can be expensive to check, but retuns full info

updateVersion

function updateVersion(uint256 tokenId, string dAppURI, bytes32 contentHash) external

CreateDApp

function CreateDApp(string dAppURI, bytes32 _contentHash) external

IPoSAdmin

ChangePoSAddress

event ChangePoSAddress(address newPoSAddress)

IWrapper

WrappedStruct

struct WrappedStruct {
  string URI;
  uint256 contentSize;
  uint256 traffic;
  uint256 payedTraffic;
  bytes32 contentHash;
  address oldAddress;
  uint256 tokenId;
  bool burned;
}

claimReward

function claimReward(uint256 _itemId) external

_Owner of item can get collected reward Check owner of itemId, no need to check exist, because in exist check owner != 0

claimRewardMany

function claimRewardMany(uint256[] _itemIds) external

Claim many

Name Type Description
_itemIds uint256[] - array of NFTids owned by user

wrap

function wrap(address _contract, uint256 tokenId, bytes32 _contentHash, string _DeNetStorageURI, uint256 contentSize) external

_Make NFT as WrappedNFT

  1. Check is approved
  2. Check is sender == owner
  3. Create pointer: keccak(address, token_id)
  4. Create wrapped NFT_

unwrap

function unwrap(uint256 tokenId) external

_unwrap and burn

  1. Sender == Owner
  2. Transfer to Sender
  3. Burn wrapped_

tokenContentHash

function tokenContentHash(uint256 _itemId) external view returns (bytes32)

return Content Hash of NFT

getNFTBalance

function getNFTBalance(uint256 _itemId) external view returns (uint256)

returns NFT Balanc of earned tokens

getMetaData

function getMetaData(uint256 _tokenId) external view returns (struct IWrapper.WrappedStruct)

return full metadata, for external apps can be expensive to check, but retuns full info

TokenMock

constructor

constructor(string name, string symbol) public

mint

function mint(address account, uint256 amount) external

burn

function burn(address account, uint256 amount) external