[Questions].sol This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters pragma solidity ^ 0.5.2 ; /* Q. If we call up an contract that is inheriting certain special permission contracts like Ownable. So when we deploy the contract, is it the time when the Ownable contract sets me the owner? / Address.sol This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters pragma solidity ^ 0.5.2 ; /* * Utility library of inline functions on addresses / library Address { /* * Returns whether the target address is a contract * @dev This function will return false if invoked during the constructor of a contract, * as the code is not actually created until after the constructor finishes. * @param account address of the account to check * @return whether the target address is a contract / function isContract ( address account ) internal view returns ( bool ) { uint256 size; // XXX Currently there is no better way to check if there is a contract in an address // than to check the size of the code at that address. // See https://ethereum.stackexchange.com/a/14016/36603 // for more details about how this works. // TODO Check this again before the Serenity release, because all addresses will be // contracts then. // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize (account) } return size > 0 ; } } CappedCrowdsale.sol This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters pragma solidity ^ 0.5.2 ; import " ./SafeMath.sol " ; import " ./Crowdsale.sol " ; /* * @title CappedCrowdsale * @dev Crowdsale with a limit for total contributions. / contract CappedCrowdsale is Crowdsale { using SafeMath for uint256 ; uint256 private _cap; /* * @dev Constructor, takes maximum amount of wei accepted in the crowdsale. * @param cap Max amount of wei to be contributed / constructor ( uint256 cap ) public { require (cap > 0 ); _cap = cap; } /* * @return the cap of the crowdsale. / function cap () public view returns ( uint256 ) { return _cap; } /* * @dev Checks whether the cap has been reached. * @return Whether the cap was reached / function capReached () public view returns ( bool ) { return weiRaised () >= _cap; } /* * @dev Extend parent behavior requiring purchase to respect the funding cap. * @param beneficiary Token purchaser * @param weiAmount Amount of wei contributed / function _preValidatePurchase ( address beneficiary , uint256 weiAmount ) internal view { super . _preValidatePurchase (beneficiary, weiAmount); require ( weiRaised (). add (weiAmount) <= _cap); } } ConditionalEscrow.sol This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters pragma solidity ^ 0.5.2 ; import " ./Escrow.sol " ; /* * @title ConditionalEscrow * @dev Base abstract escrow to only allow withdrawal if a condition is met. * @dev Intended usage: See Escrow.sol. Same usage guidelines apply here. / contract ConditionalEscrow is Escrow { /* * @dev Returns whether an address is allowed to withdraw their funds. To be * implemented by derived contracts. * @param payee The destination address of the funds. / function withdrawalAllowed ( address payee ) public view returns ( bool ); function withdraw ( address payable payee ) public { require ( withdrawalAllowed (payee)); super . withdraw (payee); } } Crowdsale.sol This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters pragma solidity ^ 0.5.2 ; import " ./IERC20.sol " ; import " ./SafeMath.sol " ; import " ./SafeERC20.sol " ; import " ./ReentrancyGuard.sol " ; /* * @title Crowdsale * @dev Crowdsale is a base contract for managing a token crowdsale, * allowing investors to purchase tokens with ether. This contract implements * such functionality in its most fundamental form and can be extended to provide additional * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conforms * the base architecture for crowdsales. It is not intended to be modified / overridden. * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropriate to concatenate * behavior. / contract Crowdsale is ReentrancyGuard { using SafeMath for uint256 ; using SafeERC20 for IERC20 ; // The token being sold IERC20 private _token; // Address where funds are collected address payable private _wallet; // How many token units a buyer gets per wei. // The rate is the conversion between wei and the smallest and indivisible token unit. // So, if you are using a rate of 1 with a ERC20Detailed token with 3 decimals called TOK // 1 wei will give you 1 unit, or 0.001 TOK. uint256 private _rate; // Amount of wei raised uint256 private _weiRaised; /* * Event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased / event TokensPurchased ( address indexed purchaser , address indexed beneficiary , uint256 value , uint256 amount ); /* * @param rate Number of token units a buyer gets per wei * @dev The rate is the conversion between wei and the smallest and indivisible * token unit. So, if you are using a rate of 1 with a ERC20Detailed token * with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK. * @param wallet Address where collected funds will be forwarded to * @param token Address of the token being sold / constructor ( uint256 rate , address payable wallet , IERC20 token ) public { require (rate > 0 ); require (wallet != address ( 0 )); require ( address (token) != address ( 0 )); _rate = rate; _wallet = wallet; _token = token; } /* * @dev fallback function DO NOT OVERRIDE * Note that other contracts will transfer funds with a base gas stipend * of 2300, which is not enough to call buyTokens. Consider calling * buyTokens directly when purchasing tokens from a contract. / function () external payable { buyTokens ( msg . sender ); } /* * @return the token being sold. / function token () public view returns ( IERC20 ) { return _token; } /* * @return the address where funds are collected. / function wallet () public view returns ( address payable ) { return _wallet; } /* * @return the number of token units a buyer gets per wei. / function rate () public view returns ( uint256 ) { return _rate; } /* * @return the amount of wei raised. / function weiRaised () public view returns ( uint256 ) { return _weiRaised; } /* * @dev low level token purchase DO NOT OVERRIDE * This function has a non-reentrancy guard, so it shouldn't be called by * another nonReentrant function. * @param beneficiary Recipient of the token purchase / function buyTokens ( address beneficiary ) public nonReentrant payable { uint256 weiAmount = msg . value ; _preValidatePurchase (beneficiary, weiAmount); // calculate token amount to be created uint256 tokens = _getTokenAmount (weiAmount); // update state _weiRaised = _weiRaised. add (weiAmount); _processPurchase (beneficiary, tokens); emit TokensPurchased ( msg . sender , beneficiary, weiAmount, tokens); _updatePurchasingState (beneficiary, weiAmount); _forwardFunds (); _postValidatePurchase (beneficiary, weiAmount); } /* * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. * Use super in contracts that inherit from Crowdsale to extend their validations. * Example from CappedCrowdsale.sol's _preValidatePurchase method: * super._preValidatePurchase(beneficiary, weiAmount); * require(weiRaised().add(weiAmount) <= cap); * @param beneficiary Address performing the token purchase * @param weiAmount Value in wei involved in the purchase / function _preValidatePurchase ( address beneficiary , uint256 weiAmount ) internal view { require (beneficiary != address ( 0 )); require (weiAmount != 0 ); } /* * @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid * conditions are not met. * @param beneficiary Address performing the token purchase * @param weiAmount Value in wei involved in the purchase / function _postValidatePurchase ( address beneficiary , uint256 weiAmount ) internal view { // solhint-disable-previous-line no-empty-blocks } /* * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends * its tokens. * @param beneficiary Address performing the token purchase * @param tokenAmount Number of tokens to be emitted / function _deliverTokens ( address beneficiary , uint256 tokenAmount ) internal { _token. safeTransfer (beneficiary, tokenAmount); } /* * @dev Executed when a purchase has been validated and is ready to be executed. Doesn't necessarily emit/send * tokens. * @param beneficiary Address receiving the tokens * @param tokenAmount Number of tokens to be purchased / function _processPurchase ( address beneficiary , uint256 tokenAmount ) internal { _deliverTokens (beneficiary, tokenAmount); } /* * @dev Override for extensions that require an internal state to check for validity (current user contributions, * etc.) * @param beneficiary Address receiving the tokens * @param weiAmount Value in wei involved in the purchase / function _updatePurchasingState ( address beneficiary , uint256 weiAmount ) internal { // solhint-disable-previous-line no-empty-blocks } /* * @dev Override to extend the way in which ether is converted to tokens. * @param weiAmount Value in wei to be converted into tokens * @return Number of tokens that can be purchased with the specified weiAmount / function _getTokenAmount ( uint256 weiAmount ) internal view returns ( uint256 ) { return weiAmount. mul (_rate); } /* * @dev Determines how ETH is stored/forwarded on purchases. / function _forwardFunds () internal { _wallet. transfer ( msg . value ); } } ERC20.sol This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters pragma solidity ^ 0.5.2 ; import " ./IERC20.sol " ; import " ./SafeMath.sol " ; /* * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md * Originally based on code by FirstBlood: * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol * * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for * all accounts just by listening to said events. Note that this isn't required by the specification, and other * compliant implementations may not do it. / contract ERC20 is IERC20 { using SafeMath for uint256 ; mapping ( address => uint256 ) private _balances; mapping ( address => mapping ( address => uint256 )) private _allowed; uint256 private _totalSupply; /* * @dev Total number of tokens in existence / function totalSupply () public view returns ( uint256 ) { return _totalSupply; } /* * @dev Gets the balance of the specified address. * @param owner The address to query the balance of. * @return An uint256 representing the amount owned by the passed address. / function balanceOf ( address owner ) public view returns ( uint256 ) { return _balances[owner]; } /* * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param owner address The address which owns the funds. * @param spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. / function allowance ( address owner , address spender ) public view returns ( uint256 ) { return _allowed[owner][spender]; } /* * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. / function transfer ( address to , uint256 value ) public returns ( bool ) { _transfer ( msg . sender , to, value); return true ; } /* * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * 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 * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. / function approve ( address spender , uint256 value ) public returns ( bool ) { _approve ( msg . sender , spender, value); return true ; } /* * @dev Transfer tokens from one address to another. * Note that while this function emits an Approval event, this is not required as per the specification, * and other compliant implementations may not emit the event. * @param from address The address which you want to send tokens from * @param to address The address which you want to transfer to * @param value uint256 the amount of tokens to be transferred / function transferFrom ( address from , address to , uint256 value ) public returns ( bool ) { require (value <= _balances[from]); require (value <= _allowed[from][ msg . sender ]); _transfer (from, to, value); _approve (from, msg . sender , _allowed[from][ msg . sender ]. sub (value)); return true ; } /* * @dev Increase the amount of tokens that an owner allowed to a spender. * approve should be called when allowed[spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param addedValue The amount of tokens to increase the allowance by. / function increaseAllowance ( address spender , uint256 addedValue ) public returns ( bool ) { _approve ( msg . sender , spender, _allowed[ msg . sender ][spender]. add (addedValue)); return true ; } /* * @dev Decrease the amount of tokens that an owner allowed to a spender. * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * Emits an Approval event. * @param spender The address which will spend the funds. * @param subtractedValue The amount of tokens to decrease the allowance by. / function decreaseAllowance ( address spender , uint256 subtractedValue ) public returns ( bool ) { _approve ( msg . sender , spender, _allowed[ msg . sender ][spender]. sub (subtractedValue)); return true ; } /* * @dev Transfer token for a specified addresses * @param from The address to transfer from. * @param to The address to transfer to. * @param value The amount to be transferred. / function _transfer ( address from , address to , uint256 value ) internal { require (to != address ( 0 )); _balances[from] = _balances[from]. sub (value); _balances[to] = _balances[to]. add (value); emit Transfer (from, to, value); } /* * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the * proper events are emitted. * @param account The account that will receive the created tokens. * @param value The amount that will be created. / function _mint ( address account , uint256 value ) public { require (account != address ( 0 )); _totalSupply = _totalSupply. add (value); _balances[account] = _balances[account]. add (value); emit Transfer ( address ( 0 ), account, value); } /* * @dev Internal function that burns an amount of the token of a given * account. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. / function _burn ( address account , uint256 value ) internal { require (account != address ( 0 )); _totalSupply = _totalSupply. sub (value); _balances[account] = _balances[account]. sub (value); emit Transfer (account, address ( 0 ), value); } /* * @dev Approve an address to spend another addresses' tokens. * @param owner The address that owns the tokens. * @param spender The address that will spend the tokens. * @param value The number of tokens that can be spent. / function _approve ( address owner , address spender , uint256 value ) internal { require (spender != address ( 0 )); require (owner != address ( 0 )); _allowed[owner][spender] = value; emit Approval (owner, spender, value); } /* * @dev Internal function that burns an amount of the token of a given * account, deducting from the sender's allowance for said account. Uses the * internal burn function. * Emits an Approval event (reflecting the reduced allowance). * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. / function _burnFrom ( address account , uint256 value ) internal { _burn (account, value); _approve (account, msg . sender , _allowed[account][ msg . sender ]. sub (value)); } } ERC20Mintable.sol This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters pragma solidity ^ 0.5.2 ; import " ./ERC20.sol " ; import " ./MinterRole.sol " ; /* * @title ERC20Mintable * @dev ERC20 minting logic / contract ERC20Mintable is ERC20 , MinterRole { /* * @dev Function to mint tokens * @param to The address that will receive the minted tokens. * @param value The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. / function mint ( address to , uint256 value ) public onlyMinter returns ( bool ) { _mint (to, value); return true ; } } Escrow.sol This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters pragma solidity ^ 0.5.2 ; import " ./SafeMath.sol " ; import " ./Secondary.sol " ; /* * @title Escrow * @dev Base escrow contract, holds funds designated for a payee until they * withdraw them. * @dev Intended usage: This contract (and derived escrow contracts) should be a * standalone contract, that only interacts with the contract that instantiated * it. That way, it is guaranteed that all Ether will be handled according to * the Escrow rules, and there is no need to check for payable functions or * transfers in the inheritance tree. The contract that uses th