TwoKeyUpgradableExchange
contract TwoKeyUpgradableExchange
Index
- TokenPurchase
- TokenSell
- WithdrawExecuted
- _deliverTokens
- _forwardFunds
- _getTokenAmountToBeSold
- _getUSDStableCoinAmountFrom2keyUnits
- _processPurchase
- addNewContract
- buy2KEYFromBancor
- buyStableCoinWith2key
- buyTokens
- calculatePercentageToDeduct
- calculateRatioBetweenDAIandETH
- calculateSumOnAllContracts
- daiWeiAvailableToFill2KEYReserve
- daiWeiAvailableToWithdraw
- daiWeiReceivedFromHedgingPerContract
- emitEventWithdrawExecuted
- ethReceivedFromContract
- ethWeiAvailableToHedge
- ethWeiHedgedPerContract
- fallback
- get2KEY2DAIHedgedRate
- getAddress
- getAllStatsForContract
- getBool
- getContractId
- getDaiWeiAvailableToWithdrawAndDaiWeiToReduce
- getEth2DaiAverageExchangeRatePerContract
- getEth2KeyAverageRatePerContract
- getKyberExpectedRate
- getUint
- numberOfContracts
- onlyValidatedContracts
- reduceDaiWeiAvailableToWithdraw
- reduceHedgedAmountFromContractsAndIncreaseDaiAvailable
- report2KEYWithdrawnFromNetwork
- report2KEYWithdrawnFromNetworkInternal
- sellRate2key
- sent2keyToContract
- setAddress
- setBool
- setInitialParams
- setUint
- spreadWei
- startHedging
- updateAccountingValues
- updateEthWeiAvailableToHedge
- weiRaised
- withdrawERC20
- withdrawEther
Reference
Events
TokenPurchase
event TokenPurchase(address purchaser, address receiver, uint256 weiReceived, uint256 tokensBought, uint256 rate)
Event for token purchase logging.
- Parameters:
purchaser
- who paid for the tokensreceiver
- is who got the tokensweiReceived
- is how weis paid for purchasetokensBought
- is the amount of tokens purchasedrate
- is the global variable rate on the contract
TokenSell
event TokenSell(address purchaser, address beneficiary, uint256 value, uint256 amount)
Event will be fired every time someone buys tokens.
- Parameters:
purchaser
- addressbeneficiary
- addressvalue
- uint256amount
- uint256
WithdrawExecuted
event WithdrawExecuted(address caller, address beneficiary, uint stableCoinsReserveBefore, uint stableCoinsReserveAfter, uint etherBalanceBefore, uint etherBalanceAfter, uint stableCoinsToWithdraw, uint twoKeyAmount)
This event will be fired every time a withdraw is executed.
- Parameters:
caller
- addressbeneficiary
- addressstableCoinsReserveBefore
- uintstableCoinsReserveAfter
- uintetherBalanceBefore
- uintetherBalanceAfter
- uintstableCoinsToWithdraw
- uinttwoKeyAmount
- uint
Modifiers
onlyValidatedContracts
modifier onlyValidatedContracts()
Modifier which will validate if contract is allowed to buy tokens.
Functions
_deliverTokens
function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal
Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
- Parameters:
_beneficiary
- Address performing the token purchase_tokenAmount
- Number of tokens to be emitted
_forwardFunds
function _forwardFunds(address _twoKeyAdmin) internal
Determines how ETH is stored/forwarded on purchases.
- Parameters:
_twoKeyAdmin
- address
_getTokenAmountToBeSold
function _getTokenAmountToBeSold(uint256 _weiAmount) internal view returns (uint256)
Override to extend the way in which ether is converted to tokens.
- Parameters:
_weiAmount
- Value in wei to be converted into tokens- Returns:
- Number of tokens that can be purchased with the specified _weiAmount
_getUSDStableCoinAmountFrom2keyUnits
function _getUSDStableCoinAmountFrom2keyUnits(uint256 _2keyAmount, address _campaign) public view returns (uint256)
This is happening in case we're receiving (buying) 2key, Function to calculate how many stable coins we can get for specific amount of 2keys.
- Parameters:
_2keyAmount
- is the amount of 2keys sent to the contract_campaign
- address- Returns:
- uint256
_processPurchase
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal
Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.
- Parameters:
_beneficiary
- Address receiving the tokens_tokenAmount
- Number of tokens to be purchased
addNewContract
function addNewContract(address _contractAddress) internal returns (uint)
Function to register new contract with corresponding ID.
- Parameters:
_contractAddress
- is the address of the contract we're adding- Returns:
- uint
buy2KEYFromBancor
function buy2KEYFromBancor(uint amountDAI, uint amount2KEY) public payable
Function to buy 2key tokens from Bancor.
- Modifiers:
- onlyMaintainer
- Parameters:
amountDAI
- we're willing to send (daiWeiAvailableToFill2keyReserve)amount2KEY
- the minimum amount of 2KEY that is acceptable in return
buyStableCoinWith2key
function buyStableCoinWith2key(uint _twoKeyUnits, address _beneficiary) external
Function which will be called by 2key campaigns if user wants to withdraw his earnings in stableCoins.
- Modifiers:
- onlyValidatedContracts
- Parameters:
_twoKeyUnits
- is the amount of 2key tokens which will be taken from campaign_beneficiary
- is the user who will receive the tokens
buyTokens
function buyTokens(address _beneficiary) public payable returns (uint)
Function to buyTokens.
- Modifiers:
- onlyValidatedContracts
- Parameters:
_beneficiary
- to get- Returns:
- amount of tokens bought
calculatePercentageToDeduct
function calculatePercentageToDeduct(uint _ethWeiHedged, uint _sumOfAmounts) internal view returns (uint)
Function to calculate how much pnercentage will be deducted from values.
- Parameters:
_ethWeiHedged
- uint_sumOfAmounts
- uint- Returns:
- uint
calculateRatioBetweenDAIandETH
function calculateRatioBetweenDAIandETH(uint _ethWeiHedged, uint _daiReceived) internal view returns (uint)
Function to calculate ratio between eth and dai in WEI's.
- Parameters:
_ethWeiHedged
- uint_daiReceived
- uint- Returns:
- uint
calculateSumOnAllContracts
function calculateSumOnAllContracts(uint _numberOfContractsCurrently) internal view returns (uint)
Function to calculate available to hedge sum on all contracts.
- Parameters:
_numberOfContractsCurrently
- uint- Returns:
- uint
daiWeiAvailableToFill2KEYReserve
function daiWeiAvailableToFill2KEYReserve() public view returns (uint)
- Returns:
- uint
daiWeiAvailableToWithdraw
function daiWeiAvailableToWithdraw(uint _contractID) public view returns (uint)
Getter for mapping "daiWeiAvailableToWithdraw" (per contract).
- Parameters:
_contractID
- uint- Returns:
- uint
daiWeiReceivedFromHedgingPerContract
function daiWeiReceivedFromHedgingPerContract(uint _contractID) internal view returns (uint)
Function to determine how many dai received from hedging per contract.
- Parameters:
_contractID
- is the ID of the contract we're requesting information- Returns:
- uint
emitEventWithdrawExecuted
function emitEventWithdrawExecuted(address _beneficiary, uint _stableCoinsOnContractBefore, uint _stableCoinsAfter, uint _etherBalanceOnContractBefore, uint _stableCoinUnits, uint twoKeyUnits) internal
Function to emit an event, created separately because of stack depth.
- Parameters:
_beneficiary
- address_stableCoinsOnContractBefore
- uint_stableCoinsAfter
- uint_etherBalanceOnContractBefore
- uint_stableCoinUnits
- uinttwoKeyUnits
- uint
ethReceivedFromContract
function ethReceivedFromContract(uint _contractID) internal view returns (uint)
Function to get eth received from contract for specific contract ID.
- Parameters:
_contractID
- is the ID of the contract we're requesting information- Returns:
- uint
ethWeiAvailableToHedge
function ethWeiAvailableToHedge(uint _contractID) public view returns (uint)
Getter for "mapping" ethWeiAvailableToHedge (per contract).
- Parameters:
_contractID
- uint- Returns:
- uint
ethWeiHedgedPerContract
function ethWeiHedgedPerContract(uint _contractID) internal view returns (uint)
Function to get how much ethWei hedged per contract.
- Parameters:
_contractID
- is the ID of the contract we're requesting information- Returns:
- uint
fallback
function () public payable
Fallback function to handle incoming ether.
get2KEY2DAIHedgedRate
function get2KEY2DAIHedgedRate(uint _contractID) public view returns (uint)
Function to get 2key to DAI hedged rate.
- Parameters:
_contractID
- is the ID of the contract we're fetching this rate (avg)- Returns:
- uint
getAddress
function getAddress(bytes32 key) internal view returns (address)
- Parameters:
key
- bytes32- Returns:
- address
getAllStatsForContract
function getAllStatsForContract(address _contractAddress) public view returns (uint, uint, uint, uint, uint, uint)
Getter wrapping all information about income/outcome for every contract.
- Parameters:
_contractAddress
- is the main campaign address- Returns:
- uint
- uint
- uint
- uint
- uint
- uint
getBool
function getBool(bytes32 key) internal view returns (bool)
- Parameters:
key
- bytes32- Returns:
- bool
getContractId
function getContractId(address _contractAddress) internal view returns (uint)
Function to get contract id, if return 0 means contract is not existing.
- Parameters:
_contractAddress
- address- Returns:
- uint
getDaiWeiAvailableToWithdrawAndDaiWeiToReduce
function getDaiWeiAvailableToWithdrawAndDaiWeiToReduce(uint _contractID, uint amountOfTokensWithdrawn) internal view returns (uint, uint)
Internal helper function.
- Parameters:
_contractID
- is the id of the contract we'd like to do the mathamountOfTokensWithdrawn
- is the amount of tokens withdrawn from campaign- Returns:
- uint
- uint
getEth2DaiAverageExchangeRatePerContract
function getEth2DaiAverageExchangeRatePerContract(uint _contractID) public view returns (uint)
Function to get Eth2DAI average exchange rate per contract.
- Parameters:
_contractID
- is the ID of the contract we're requesting information- Returns:
- uint
getEth2KeyAverageRatePerContract
function getEth2KeyAverageRatePerContract(uint _contractID) public view returns (uint)
Function to get Eth22key average exchange rate per contract.
- Parameters:
_contractID
- is the ID of the contract we're requesting information- Returns:
- uint
getKyberExpectedRate
function getKyberExpectedRate(uint amountEthWei) public view returns (uint)
Function to get expected rate from Kyber contract.
- Parameters:
amountEthWei
- is the amount we'd like to exchange- Returns:
- if the value is 0 that means we can't
getUint
function getUint(bytes32 key) internal view returns (uint)
- Parameters:
key
- bytes32- Returns:
- uint
numberOfContracts
function numberOfContracts() public view returns (uint)
Function to return number of campaign contracts (different) interacted with this contract.
- Returns:
- uint
reduceDaiWeiAvailableToWithdraw
function reduceDaiWeiAvailableToWithdraw(address contractAddress, uint daiAmount) internal
Function to reduce amount of dai available to be withdrawn from selected contract.
- Parameters:
contractAddress
- is the address of the contractdaiAmount
- is the amount of dais
reduceHedgedAmountFromContractsAndIncreaseDaiAvailable
function reduceHedgedAmountFromContractsAndIncreaseDaiAvailable(uint _ethWeiHedged, uint _daiReceived) internal
Function to reduce available amount to hedge and increase available DAI to withdraw.
- Parameters:
_ethWeiHedged
- is how much eth was hedged_daiReceived
- is how much DAI's we got for that hedging
report2KEYWithdrawnFromNetwork
function report2KEYWithdrawnFromNetwork(uint amountOfTokensWithdrawn) public
Function which will be called every time by campaign when referrer select to withdraw directly 2key token.
- Modifiers:
- onlyValidatedContracts
- Parameters:
amountOfTokensWithdrawn
- is the amount of tokens he wants to withdraw
report2KEYWithdrawnFromNetworkInternal
function report2KEYWithdrawnFromNetworkInternal(uint amountOfTokensWithdrawn, uint _contractID) public
- Parameters:
amountOfTokensWithdrawn
- is the amount of tokens he wants to withdraw_contractID
- is the id of the contract
sellRate2key
function sellRate2key() public view returns (uint)
Getter for 2key sell rate.
- Returns:
- uint
sent2keyToContract
function sent2keyToContract(uint _contractID) internal view returns (uint)
Function to get how many 2keys are sent to selected contract.
- Parameters:
_contractID
- is the ID of the contract we're requesting information- Returns:
- uint
setAddress
function setAddress(bytes32 key, address value) internal
- Parameters:
key
- bytes32value
- address
setBool
function setBool(bytes32 key, bool value) internal
- Parameters:
key
- bytes32value
- bool
setInitialParams
function setInitialParams(ERC20 _token, address _daiAddress, address _kyberNetworkProxy, address _twoKeySingletonesRegistry, address _proxyStorageContract) external
Constructor of the contract, can be called only once.
- Parameters:
_token
- is ERC20 2key token_daiAddress
- is the address of DAI on ropsten_kyberNetworkProxy
- is the address of Kyber network contract_twoKeySingletonesRegistry
- is the address of TWO_KEY_SINGLETON_REGISTRY_proxyStorageContract
- is the address of proxy of storage contract
setUint
function setUint(bytes32 key, uint value) internal
- Parameters:
key
- bytes32value
- uint
spreadWei
function spreadWei() public view returns (uint)
- Returns:
- uint
startHedging
function startHedging(uint amountToBeHedged, uint approvedMinConversionRate) public
Only maintainer can call this function, Function to start hedging some ether amount.
- Modifiers:
- onlyMaintainer
- Parameters:
amountToBeHedged
- is the amount we'd like to hedgeapprovedMinConversionRate
- uint
updateAccountingValues
function updateAccountingValues(uint _daisReceived, uint _hedgedEthWei, uint _afterHedgingAvailableEthWei, uint _contractID) internal
Internal function created to update specific values, separated because of stack depth.
- Parameters:
_daisReceived
- is the amount of received dais_hedgedEthWei
- is the amount of ethWei hedged_afterHedgingAvailableEthWei
- is the amount available after hedging_contractID
- is the ID of the contract
updateEthWeiAvailableToHedge
function updateEthWeiAvailableToHedge(uint _contractID, uint _msgValue) internal
Setter for EthWeiAvailableToHedge.
- Parameters:
_contractID
- is the ID of the contract_msgValue
- is the amount sent
weiRaised
function weiRaised() public view returns (uint)
Getter for weiRaised.
- Returns:
- uint
withdrawERC20
function withdrawERC20(address _erc20TokenAddress, uint _tokenAmount) public
Function to withdraw any ERC20 tokens to TwoKeyAdmin.
- Parameters:
_erc20TokenAddress
- address_tokenAmount
- uint
withdrawEther
function withdrawEther() public
Withdraw all ether from contract.