Verified contractPartialMIT
IdeaTokenFactoryStateTransfer
Address0x8cd552d578cf6388292d10773baae04cc82ce99e
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.6.9
- Same code
Only this contract
Details
- Compiler
- solc 0.6.9+commit.3e3065ac
- Language
- solidity
- Optimization
- No
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 13,320,337
- Creation transaction
- 0xbc36c821d8…c80d5809c2
14 files
- IdeaTokenFactoryStateTransfer.solmain2.15 KB
- Address.sol8.01 KB
- Context.sol965 B
- ERC20.sol10.83 KB
- IERC20.sol2.78 KB
- IIdeaToken.sol384 B
- IIdeaTokenFactory.sol2.2 KB
- IIdeaTokenNameVerifier.sol299 B
- IdeaToken.sol1.84 KB
- IdeaTokenFactory.sol12.17 KB
- Initializable.sol2.19 KB
- MinimalProxy.sol1.22 KB
- Ownable.sol827 B
- SafeMath.sol7.44 KB
IdeaTokenFactoryStateTransfer.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import "./IdeaTokenFactory.sol";
/**
* @title IdeaTokenFactoryStateTransfer
* @author Alexander Schlindwein
*
* Replaces the L1 IdeaTokenFactory logic for the state transfer to Optimism L2.
*
* This implementation will disable most methods.
*/
contract IdeaTokenFactoryStateTransfer is IdeaTokenFactory {
/* **********************************************
* ************ Disabled functions ************
* **********************************************
*/
function initialize(address owner, address ideaTokenExchange, address ideaTokenLogic) external override {
owner; ideaTokenExchange; ideaTokenLogic;
revert("x");
}
function addMarket(string calldata marketName, address nameVerifier,
uint baseCost, uint priceRise, uint hatchTokens,
uint tradingFeeRate, uint platformFeeRate, bool allInterestToPlatform) external override {
marketName; nameVerifier; baseCost; priceRise; hatchTokens; tradingFeeRate; platformFeeRate; allInterestToPlatform;
revert("x");
}
function emitNewMarketEvent(MarketDetails memory marketDetails) internal override {
marketDetails;
revert("x");
}
function addToken(string calldata tokenName, uint marketID, address lister) external override {
tokenName; marketID; lister;
revert("x");
}
function isValidTokenName(string calldata tokenName, uint marketID) public view override returns (bool) {
tokenName; marketID;
revert("x");
}
function setTradingFee(uint marketID, uint tradingFeeRate) external override {
marketID; tradingFeeRate;
revert("x");
}
function setPlatformFee(uint marketID, uint platformFeeRate) external override {
marketID; platformFeeRate;
revert("x");
}
function setNameVerifier(uint marketID, address nameVerifier) external override {
marketID; nameVerifier;
revert("x");
}
}Address.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev 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
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev 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].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev 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._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev 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._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Context.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/*
* @dev 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 GSN 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.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
ERC20.sol
// SPDX-License-Identifier: MIT
/*
From https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol
The constructor has been removed and name, symbol, decimals are made internal instead of private.
This allows this contract to be used with MinimalProxy.
*/
pragma solidity 0.6.9;
import "./SafeMath.sol";
import "./Context.sol";
import "./IERC20.sol";
/**
* @dev 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 guidelines: functions revert instead
* of 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}.
*/
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string internal _name;
string internal _symbol;
uint8 internal _decimals;
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev 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 {_setupDecimals} is
* called.
*
* 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}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev 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`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev 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.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev 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`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is 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`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev 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.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev 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.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev 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 to 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].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev 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.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev 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:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev 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.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
IIdeaToken.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.9;
import "./IERC20.sol";
/**
* @title IIdeaToken
* @author Alexander Schlindwein
*/
interface IIdeaToken is IERC20 {
function initialize(string calldata __name, address owner) external;
function mint(address account, uint256 amount) external;
function burn(address account, uint256 amount) external;
}IIdeaTokenFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import "./IERC20.sol";
import "./IIdeaToken.sol";
import "./IIdeaTokenNameVerifier.sol";
/**
* @title IIdeaTokenFactory
* @author Alexander Schlindwein
*/
struct IDPair {
bool exists;
uint marketID;
uint tokenID;
}
struct TokenInfo {
bool exists;
uint id;
string name;
IIdeaToken ideaToken;
}
struct MarketDetails {
bool exists;
uint id;
string name;
IIdeaTokenNameVerifier nameVerifier;
uint numTokens;
uint baseCost;
uint priceRise;
uint hatchTokens;
uint tradingFeeRate;
uint platformFeeRate;
bool allInterestToPlatform;
}
interface IIdeaTokenFactory {
function addMarket(string calldata marketName, address nameVerifier,
uint baseCost, uint priceRise, uint hatchTokens,
uint tradingFeeRate, uint platformFeeRate, bool allInterestToPlatform) external;
function addToken(string calldata tokenName, uint marketID, address lister) external;
function isValidTokenName(string calldata tokenName, uint marketID) external view returns (bool);
function getMarketIDByName(string calldata marketName) external view returns (uint);
function getMarketDetailsByID(uint marketID) external view returns (MarketDetails memory);
function getMarketDetailsByName(string calldata marketName) external view returns (MarketDetails memory);
function getMarketDetailsByTokenAddress(address ideaToken) external view returns (MarketDetails memory);
function getNumMarkets() external view returns (uint);
function getTokenIDByName(string calldata tokenName, uint marketID) external view returns (uint);
function getTokenInfo(uint marketID, uint tokenID) external view returns (TokenInfo memory);
function getTokenIDPair(address token) external view returns (IDPair memory);
function setTradingFee(uint marketID, uint tradingFeeRate) external;
function setPlatformFee(uint marketID, uint platformFeeRate) external;
function setNameVerifier(uint marketID, address nameVerifier) external;
}IIdeaTokenNameVerifier.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.9;
/**
* @title IIdeaTokenNameVerifier
* @author Alexander Schlindwein
*
* Interface for token name verifiers
*/
interface IIdeaTokenNameVerifier {
function verifyTokenName(string calldata name) external pure returns (bool);
}IdeaToken.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.9;
import "./ERC20.sol";
import "./Ownable.sol";
import "./Initializable.sol";
import "./IIdeaToken.sol";
/**
* @title IdeaToken
* @author Alexander Schlindwein
*
* IdeaTokens are implementations of the ERC20 interface
* They can be burned and minted by the owner of the contract instance which is the IdeaTokenExchange
*
* New instances are created using a MinimalProxy
*/
contract IdeaToken is IIdeaToken, ERC20, Ownable, Initializable {
/**
* Constructs an IdeaToken with 18 decimals
* The constructor is called by the IdeaTokenFactory when a new token is listed
* The owner of the contract is set to msg.sender
*
* @param __name The name of the token. IdeaTokenFactory will prefix the market name
* @param owner The owner of this contract, IdeaTokenExchange
*/
function initialize(string calldata __name, address owner) external override initializer {
setOwnerInternal(owner);
_decimals = 18;
_symbol = "IDT";
_name = __name;
}
/**
* Mints a given amount of tokens to an address
* May only be called by the owner
*
* @param account The address to receive the minted tokens
* @param amount The amount of tokens to mint
*/
function mint(address account, uint256 amount) external override onlyOwner {
_mint(account, amount);
}
/**
* Burns a given amount of tokens from an address.
* May only be called by the owner
*
* @param account The address for the tokens to be burned from
* @param amount The amount of tokens to be burned
*/
function burn(address account, uint256 amount) external override onlyOwner {
_burn(account, amount);
}
}IdeaTokenFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import "./MinimalProxy.sol";
import "./Initializable.sol";
import "./Ownable.sol";
import "./IIdeaTokenFactory.sol";
import "./IdeaToken.sol";
import "./IIdeaToken.sol";
import "./IIdeaTokenNameVerifier.sol";
import "./SafeMath.sol";
/**
* @title IdeaTokenFactory
* @author Alexander Schlindwein
*
* Manages the creation of markets and IdeaTokens
* Sits behind an AdminUpgradabilityProxy
*/
contract IdeaTokenFactory is IIdeaTokenFactory, Initializable, Ownable {
using SafeMath for uint256;
// Contains details for each market
struct MarketInfo {
mapping(uint => TokenInfo) tokens;
mapping(string => uint) tokenIDs;
mapping(string => bool) tokenNameUsed;
MarketDetails marketDetails;
}
uint constant FEE_SCALE = 10000;
// Address of the IdeaTokenExchange contract
// This is needed to transfer ownership of a newly created IdeaToken to the IdeaTokenExchange
address _ideaTokenExchange;
// Address of the IdeaToken logic contract
address _ideaTokenLogic;
// IdeaTokenAddress => IDPair. Stores an IDPair (marketID, tokenID) for an IdeaToken
mapping(address => IDPair) _tokenIDPairs;
// marketID => MarketInfo. Stores information for a market
mapping(uint => MarketInfo) _markets;
// market name => marketID. Translates market names to market IDs.
mapping(string => uint) _marketIDs;
// The amount of existing markets.
uint _numMarkets;
event NewMarket(uint id,
string name,
uint baseCost,
uint priceRise,
uint hatchTokens,
uint tradingFeeRate,
uint platformFeeRate,
bool allInterestToPlatform,
address nameVerifier);
event NewToken(uint id, uint marketID, string name, address addr, address lister);
event NewTradingFee(uint marketID, uint tradingFeeRate);
event NewPlatformFee(uint marketID, uint platformFeeRate);
event NewNameVerifier(uint marketID, address nameVerifier);
/**
* Initializes the contract with all required values
*
* @param owner The owner of the contract
*/
function initialize(address owner, address ideaTokenExchange, address ideaTokenLogic) external virtual initializer {
require(ideaTokenExchange != address(0) && ideaTokenLogic != address(0), "invalid-params");
setOwnerInternal(owner); // Checks owner to be non-zero
_ideaTokenExchange = ideaTokenExchange;
_ideaTokenLogic = ideaTokenLogic;
}
/**
* Adds a new market
* May only be called by the owner
*
* @param marketName The name of the market
* @param nameVerifier The address of the name verifier
* @param baseCost: The initial cost in Dai per IdeaToken in the first interval
* @param priceRise: The price rise in Dai per IdeaToken per completed interval
* @param hatchTokens: The amount of IdeaTokens for which the price does not change initially
* @param tradingFeeRate: The trading fee rate
* @param platformFeeRate: The platform fee rate
* @param allInterestToPlatform: If true, all interest goes to the platform instead of the token owner
*/
function addMarket(string calldata marketName, address nameVerifier,
uint baseCost, uint priceRise, uint hatchTokens,
uint tradingFeeRate, uint platformFeeRate, bool allInterestToPlatform) external virtual override onlyOwner {
require(_marketIDs[marketName] == 0, "market-exists");
require(nameVerifier != address(0) &&
baseCost > 0 &&
tradingFeeRate.add(platformFeeRate) <= FEE_SCALE,
"invalid-params");
uint marketID = ++_numMarkets;
MarketInfo memory marketInfo = MarketInfo({
marketDetails: MarketDetails({
exists: true,
id: marketID,
name: marketName,
nameVerifier: IIdeaTokenNameVerifier(nameVerifier),
numTokens: 0,
baseCost: baseCost,
priceRise: priceRise,
hatchTokens: hatchTokens,
tradingFeeRate: tradingFeeRate,
platformFeeRate: platformFeeRate,
allInterestToPlatform: allInterestToPlatform
})
});
_markets[marketID] = marketInfo;
_marketIDs[marketName] = marketID;
emitNewMarketEvent(marketInfo.marketDetails);
}
/// Stack too deep if we do it directly in `addMarket`
function emitNewMarketEvent(MarketDetails memory marketDetails) internal virtual {
emit NewMarket(marketDetails.id,
marketDetails.name,
marketDetails.baseCost,
marketDetails.priceRise,
marketDetails.hatchTokens,
marketDetails.tradingFeeRate,
marketDetails.platformFeeRate,
marketDetails.allInterestToPlatform,
address(marketDetails.nameVerifier));
}
/**
* Adds a new IdeaToken using MinimalProxy
*
* @param tokenName The name of the token
* @param marketID The ID of the market
* @param lister The address of the account which off-chain software shall see as lister of this token. Only emitted, not stored
*/
function addToken(string calldata tokenName, uint marketID, address lister) external virtual override {
MarketInfo storage marketInfo = _markets[marketID];
require(marketInfo.marketDetails.exists, "market-not-exist");
require(isValidTokenName(tokenName, marketID), "invalid-name");
IIdeaToken ideaToken = IIdeaToken(address(new MinimalProxy(_ideaTokenLogic)));
ideaToken.initialize(string(abi.encodePacked(marketInfo.marketDetails.name, ": ", tokenName)), _ideaTokenExchange);
uint tokenID = ++marketInfo.marketDetails.numTokens;
TokenInfo memory tokenInfo = TokenInfo({
exists: true,
id: tokenID,
name: tokenName,
ideaToken: ideaToken
});
marketInfo.tokens[tokenID] = tokenInfo;
marketInfo.tokenIDs[tokenName] = tokenID;
marketInfo.tokenNameUsed[tokenName] = true;
_tokenIDPairs[address(ideaToken)] = IDPair({
exists: true,
marketID: marketID,
tokenID: tokenID
});
emit NewToken(tokenID, marketID, tokenName, address(ideaToken), lister);
}
/**
* Checks whether a token name is allowed and not used already
*
* @param tokenName The intended token name
* @param marketID The market on which the token is to be listed
*
* @return True if the name is allowed, false otherwise
*/
function isValidTokenName(string calldata tokenName, uint marketID) public virtual view override returns (bool) {
MarketInfo storage marketInfo = _markets[marketID];
MarketDetails storage marketDetails = marketInfo.marketDetails;
if(marketInfo.tokenNameUsed[tokenName] || !marketDetails.nameVerifier.verifyTokenName(tokenName)) {
return false;
}
return true;
}
/**
* Returns the market id by the market name
*
* @param marketName The market name
*
* @return The market id
*/
function getMarketIDByName(string calldata marketName) external view override returns (uint) {
return _marketIDs[marketName];
}
/**
* Returns the market details by the market id
*
* @param marketID The market id
*
* @return The market details
*/
function getMarketDetailsByID(uint marketID) external view override returns (MarketDetails memory) {
return _markets[marketID].marketDetails;
}
/**
* Returns the market details by the market name
*
* @param marketName The market name
*
* @return The market details
*/
function getMarketDetailsByName(string calldata marketName) external view override returns (MarketDetails memory) {
return _markets[_marketIDs[marketName]].marketDetails;
}
function getMarketDetailsByTokenAddress(address ideaToken) external view override returns (MarketDetails memory) {
return _markets[_tokenIDPairs[ideaToken].marketID].marketDetails;
}
/**
* Returns the amount of existing markets
*
* @return The amount of existing markets
*/
function getNumMarkets() external view override returns (uint) {
return _numMarkets;
}
/**
* Returns the token id by the token name and market id
*
* @param tokenName The token name
* @param marketID The market id
*
* @return The token id
*/
function getTokenIDByName(string calldata tokenName, uint marketID) external view override returns (uint) {
return _markets[marketID].tokenIDs[tokenName];
}
/**
* Returns the token info by the token id and market id
*
* @param marketID The market id
* @param tokenID The token id
*
* @return The token info
*/
function getTokenInfo(uint marketID, uint tokenID) external view override returns (TokenInfo memory) {
return _markets[marketID].tokens[tokenID];
}
/**
* Returns the token id pair by the tokens address
*
* @param token The tokens address
*
* @return The token id pair
*/
function getTokenIDPair(address token) external view override returns (IDPair memory) {
return _tokenIDPairs[token];
}
/**
* Sets the trading fee for a market
* May only be called by the owner
*
* @param marketID The market id for which to set the trading fee
* @param tradingFeeRate The trading fee
*/
function setTradingFee(uint marketID, uint tradingFeeRate) external virtual override onlyOwner {
MarketDetails storage marketDetails = _markets[marketID].marketDetails;
require(marketDetails.exists, "market-not-exist");
require(marketDetails.platformFeeRate.add(tradingFeeRate) <= FEE_SCALE, "invalid-fees");
marketDetails.tradingFeeRate = tradingFeeRate;
emit NewTradingFee(marketID, tradingFeeRate);
}
/**
* Sets the platform fee for a market
* May only be called by the owner
*
* @param marketID The market id for which to set the platform fee
* @param platformFeeRate The platform fee
*/
function setPlatformFee(uint marketID, uint platformFeeRate) external virtual override onlyOwner {
MarketDetails storage marketDetails = _markets[marketID].marketDetails;
require(marketDetails.exists, "market-not-exist");
require(marketDetails.tradingFeeRate.add(platformFeeRate) <= FEE_SCALE, "invalid-fees");
marketDetails.platformFeeRate = platformFeeRate;
emit NewPlatformFee(marketID, platformFeeRate);
}
/**
* Changes the address of the name verifier for a market
* May only be called by the owner
*
* @param marketID The marketID for which to change the name verifier
* @param nameVerifier The new name verifier address
*/
function setNameVerifier(uint marketID, address nameVerifier) external virtual override onlyOwner {
require(nameVerifier != address(0), "zero-verifier");
MarketDetails storage marketDetails = _markets[marketID].marketDetails;
require(marketDetails.exists, "market-not-exist");
marketDetails.nameVerifier = IIdeaTokenNameVerifier(nameVerifier);
emit NewNameVerifier(marketID, nameVerifier);
}
}Initializable.sol
// SPDX-License-Identifier: MIT
// https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/master/packages/core/contracts/Initializable.sol
pragma solidity 0.6.9;
/**
* @title Initializable
*
* @dev Helper contract to support initializer functions. To use it, replace
* the constructor with a function that has the `initializer` modifier.
* WARNING: Unlike constructors, initializer functions must be manually
* invoked. This applies both to deploying an Initializable contract, as well
* as extending an Initializable contract via inheritance.
* WARNING: When used with inheritance, manual care must be taken to not invoke
* a parent initializer twice, or ensure that all initializers are idempotent,
* because this is not dealt with automatically as with constructors.
*/
contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private initializing;
/**
* @dev Modifier to use in the initializer function of a contract.
*/
modifier initializer() {
require(initializing || isConstructor() || !initialized, "already-initialized");
bool isTopLevelCall = !initializing;
if (isTopLevelCall) {
initializing = true;
initialized = true;
}
_;
if (isTopLevelCall) {
initializing = false;
}
}
/// @dev Returns true if and only if the function is running in the constructor
function isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
// under construction or not.
address self = address(this);
uint256 cs;
assembly { cs := extcodesize(self) }
return cs == 0;
}
// Reserved storage space to allow for layout changes in the future.
uint256[50] private ______gap;
}MinimalProxy.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.9;
/**
* @title MinimalProxy
* @author Alexander Schlindwein
*
* Minimal proxy contract which delegates to an implementation
*/
contract MinimalProxy {
// Implementation address storage slot
bytes32 constant IMPLEMENTATION_SLOT = bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1);
/**
* Constructs a new proxy which delegates to the implementation address
*/
constructor(address implementation) public {
require(implementation != address(0), "invalid-params");
bytes32 slot = IMPLEMENTATION_SLOT;
assembly {
sstore(slot, implementation)
}
}
/**
* Every call is delegated to the implementation
*/
fallback() payable external {
bytes32 slot = IMPLEMENTATION_SLOT;
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), sload(slot), 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 { revert(0, returndatasize()) }
default { return(0, returndatasize()) }
}
}
}
Ownable.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.9;
/**
* @title Ownable
* @author Alexander Schlindwein
*
* @dev Implements only-owner functionality
*/
contract Ownable {
address _owner;
event OwnershipChanged(address oldOwner, address newOwner);
modifier onlyOwner {
require(_owner == msg.sender, "only-owner");
_;
}
function setOwner(address newOwner) external onlyOwner {
setOwnerInternal(newOwner);
}
function setOwnerInternal(address newOwner) internal {
require(newOwner != address(0), "zero-addr");
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipChanged(oldOwner, newOwner);
}
function getOwner() external view returns (address) {
return _owner;
}
}SafeMath.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting 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.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev 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.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev 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.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* 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.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev 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.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
Compiler settingsShow
{
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.