TwoKey documentation

TwoKey documentation

  • Docs

›2KEY / SINGLETON-CONTRACTS

2KEY

  • Migrations
  • Ownable
  • TwoKeyConversionStates
  • TwoKeyConverterStates
  • TwoKeyTypes
  • UpgradabilityProxyAcquisition

2KEY / ACQUISITION-CAMPAIGN-CONTRACTS

  • TwoKeyAcquisitionCampaignERC20
  • TwoKeyAcquisitionLogicHandler
  • TwoKeyConversionHandler
  • TwoKeyPurchasesHandler

2KEY / CAMPAIGN-MUTUAL-CONTRACTS

  • ArcERC20
  • TwoKeyCampaign
  • TwoKeyCampaignConversionHandler
  • TwoKeyCampaignIncentiveModels
  • TwoKeyCampaignLogicHandler

2KEY / DONATION-CAMPAIGN-CONTRACTS

  • InvoiceTokenERC20
  • TwoKeyDonationCampaign
  • TwoKeyDonationCampaignType
  • TwoKeyDonationConversionHandler
  • TwoKeyDonationLogicHandler

2KEY / ERC20

  • ERC20

2KEY / INTERFACES

  • IBancorContract
  • IERC20
  • IGetImplementation
  • IHandleCampaignDeployment
  • IKyberNetworkProxy
  • IMaintainingPattern
  • IStructuredStorage
  • ITwoKeyAcquisitionCampaignERC20
  • ITwoKeyAcquisitionLogicHandler
  • ITwoKeyAdmin
  • ITwoKeyBaseReputationRegistry
  • ITwoKeyCampaign
  • ITwoKeyCampaignGetReferrers
  • ITwoKeyCampaignPublicAddresses
  • ITwoKeyCampaignValidator
  • ITwoKeyConversionHandler
  • ITwoKeyConversionHandlerGetConverterState
  • ITwoKeyDonationCampaign
  • ITwoKeyDonationCampaignFetchAddresses
  • ITwoKeyDonationConversionHandler
  • ITwoKeyDonationLogicHandler
  • ITwoKeyEventSource
  • ITwoKeyEventSourceEvents
  • ITwoKeyExchangeRateContract
  • ITwoKeyMaintainersRegistry
  • ITwoKeyPlasmaEvents
  • ITwoKeyPlasmaRegistry
  • ITwoKeyPurchasesHandler
  • ITwoKeyReg
  • ITwoKeyRegistry
  • ITwoKeyRegistryEvents
  • ITwoKeySingletoneAddressStorage
  • ITwoKeySingletoneRegistryFetchAddress
  • ITwoKeySingletonesRegistry
  • ITwoKeyWeightedVoteContract
  • IUpgradableExchange

2KEY / INTERFACES / STORAGE-CONTRACTS

  • ITwoKeyAdminStorage
  • ITwoKeyBaseReputationRegistryStorage
  • ITwoKeyCampaignValidatorStorage
  • ITwoKeyCommunityTokenPoolStorage
  • ITwoKeyDeepFreezeTokenPoolStorage
  • ITwoKeyEventSourceStorage
  • ITwoKeyExchangeRateContractStorage
  • ITwoKeyFactoryStorage
  • ITwoKeyLongTermTokenPoolStorage
  • ITwoKeyMaintainersRegistryStorage
  • ITwoKeyPlasmaEventsStorage
  • ITwoKeyPlasmaMaintainersRegistryStorage
  • ITwoKeyPlasmaRegistryStorage
  • ITwoKeyRegistryStorage
  • ITwoKeySignatureValidatorStorage
  • ITwoKeyUpgradableExchangeStorage

2KEY / LIBRARIES

  • Call
  • GetCode
  • IncentiveModels
  • SafeMath
  • Utils

2KEY / SINGLETON-CONTRACTS

  • ITwoKeySingletonUtils
  • StandardTokenModified
  • TwoKeyAdmin
  • TwoKeyBaseReputationRegistry
  • TwoKeyCampaignValidator
  • TwoKeyCongress
  • TwoKeyEconomy
  • TwoKeyEventSource
  • TwoKeyExchangeRateContract
  • TwoKeyFactory
  • TwoKeyMaintainersRegistry
  • TwoKeyPlasmaEvents
  • TwoKeyPlasmaMaintainersRegistry
  • TwoKeyPlasmaRegistry
  • TwoKeyPlasmaSingletoneRegistry
  • TwoKeyRegistry
  • TwoKeySignatureValidator
  • TwoKeySingletonesRegistry
  • TwoKeyUpgradableExchange

2KEY / SINGLETON-STORAGE-CONTRACTS

  • TwoKeyAdminStorage
  • TwoKeyBaseReputationRegistryStorage
  • TwoKeyCampaignValidatorStorage
  • TwoKeyCommunityTokenPoolStorage
  • TwoKeyDeepFreezeTokenPoolStorage
  • TwoKeyEventSourceStorage
  • TwoKeyExchangeRateStorage
  • TwoKeyFactoryStorage
  • TwoKeyLongTermTokenPoolStorage
  • TwoKeyMaintainersRegistryStorage
  • TwoKeyPlasmaEventsStorage
  • TwoKeyPlasmaMaintainersRegistryStorage
  • TwoKeyPlasmaRegistryStorage
  • TwoKeyRegistryStorage
  • TwoKeySignatureValidatorStorage
  • TwoKeyUpgradableExchangeStorage

2KEY / TOKEN-POOLS

  • TokenPool
  • TwoKeyCommunityTokenPool
  • TwoKeyDeepFreezeTokenPool
  • TwoKeyLongTermTokenPool

2KEY / UPGRADABILITY

  • Proxy
  • StructuredStorage
  • UpgradeabilityStorage
  • UpgradeabilityProxy
  • Upgradeable

2KEY / UPGRADABLE-PATTERN-CAMPAIGNS

  • ProxyCampaign
  • UpgradeabilityCampaignStorage
  • UpgradeableCampaign

TEST

  • FungibleMockToken
  • TestA
  • TestB
  • KyberNetworkTestMockContract

TwoKeyUpgradableExchange

contract TwoKeyUpgradableExchange

is Upgradeable, ITwoKeySingletonUtils

Source: contracts/2key/singleton-contracts/TwoKeyUpgradableExchange.sol

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 tokens
    receiver - is who got the tokens
    weiReceived - is how weis paid for purchase
    tokensBought - is the amount of tokens purchased
    rate - 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 - address
    beneficiary - address
    value - uint256
    amount - 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 - address
    beneficiary - address
    stableCoinsReserveBefore - uint
    stableCoinsReserveAfter - uint
    etherBalanceBefore - uint
    etherBalanceAfter - uint
    stableCoinsToWithdraw - uint
    twoKeyAmount - 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 - uint
    twoKeyUnits - 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 math
    amountOfTokensWithdrawn - 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 contract
    daiAmount - 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 - bytes32
    value - address
  • setBool

    function setBool(bytes32 key, bool value) internal
    Parameters:
    key - bytes32
    value - 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 - bytes32
    value - 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 hedge
    approvedMinConversionRate - 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.

← TwoKeySingletonesRegistryTwoKeyAdminStorage →
Copyright © 2019 2key.network