/// <summary> /// return the amount of tokens left for purchase /// </summary> /// <returns></returns> public static BigInteger CrowdsaleAvailableAmount() { BigInteger amountSold = (ICOContract.TokenMaxSupply * factor) - NEP5.TotalSupply(); return(amountSold); }
/// <summary> /// retrieve information for the received transaction /// </summary> /// <returns>object[] { /// (Transaction)tx, (byte[])sender, (byte)receiver, ulong receivedNEO, ulong receivedGAS, /// (BigInteger)whiteListGroupNumber, (BigInteger)crowdsaleAvailableAmount, (BigInteger)groupMaximumContribution /// (BigInteger)totalTokensPurchased, (BigInteger)neoRemainingAfterPurchase, (BigInteger)gasRemainingAfterPurchase /// (BigInteger)totalContributionBalance /// } /// </returns> public static object[] GetTransactionAndSaleData() { Transaction tx = (Transaction)ExecutionEngine.ScriptContainer; TransactionOutput[] inputs = tx.GetReferences(); TransactionOutput reference = inputs[0]; TransactionOutput[] outputs = tx.GetOutputs(); byte[] sender = reference.ScriptHash; byte[] receiver = ExecutionEngine.ExecutingScriptHash; ulong receivedNEO = 0; ulong receivedGAS = 0; foreach (var input in inputs) { // ensure that the provided inputs are valid if (input.ScriptHash == receiver) { throw new System.Exception(); } } foreach (TransactionOutput output in outputs) { if (output.ScriptHash == receiver) { // only add funds to total received value if receiver is the recipient of the output ulong receivedValue = (ulong)output.Value; Runtime.Notify("GetTransactionData() Received Deposit type", receiver, reference.AssetId); if (reference.AssetId == NEP5.NEO) { receivedNEO += receivedValue; } else if (reference.AssetId == NEP5.GAS) { receivedGAS += receivedValue; } } } BigInteger whiteListGroupNumber = KYC.GetWhitelistGroupNumber(sender); BigInteger crowdsaleAvailableAmount = NEP5.CrowdsaleAvailableAmount(); BigInteger groupMaximumContribution = KYC.GetGroupMaxContribution(whiteListGroupNumber) * NEP5.factor; BigInteger totalTokensPurchased = 0; BigInteger neoRemainingAfterPurchase = 0; BigInteger gasRemainingAfterPurchase = 0; BigInteger runningCrowdsaleAmount = crowdsaleAvailableAmount; if (ICOTemplate.ICOAllowsNEO() && receivedNEO > 0) { BigInteger neoTokenValue = receivedNEO * ICOTemplate.ICONeoToTokenExchangeRate(); if (neoTokenValue > runningCrowdsaleAmount) { // the user is trying to purchase more tokens than are available // figure out how much LX can be purchased without exceeding the cap neoRemainingAfterPurchase = (neoTokenValue - runningCrowdsaleAmount) / (ICOTemplate.ICONeoToTokenExchangeRate()); totalTokensPurchased = runningCrowdsaleAmount; } else { // there is enough LX left for this purchase to complete totalTokensPurchased = neoTokenValue; } // ensure amountAvailable now reflects number of tokens purchased with NEO runningCrowdsaleAmount -= totalTokensPurchased; } if (ICOTemplate.ICOAllowsGAS() && receivedGAS > 0) { BigInteger gasTokenValue = receivedGAS * ICOTemplate.ICOGasToTokenExchangeRate(); if (gasTokenValue > runningCrowdsaleAmount) { // the user is trying to purchase more tokens than are available // figure out how much LX can be purchased without exceeding the cap gasRemainingAfterPurchase = (gasTokenValue - runningCrowdsaleAmount) / (ICOTemplate.ICOGasToTokenExchangeRate()); totalTokensPurchased = totalTokensPurchased + runningCrowdsaleAmount; } else { totalTokensPurchased = totalTokensPurchased + gasTokenValue; } } BigInteger totalContributionBalance = BalanceOfSaleContribution(sender) + totalTokensPurchased; return(new object[] { tx, // neo transaction object sender, // who initiated the transfer receiver, // who the assets were sent to receivedNEO, // how many neo were transferred receivedGAS, // how many gas were transferred whiteListGroupNumber, // what whitelist group is the sender in crowdsaleAvailableAmount, // how many tokens are left to be purchased groupMaximumContribution, // how many tokens can members of this whitelist group purchase totalTokensPurchased, // the total number of tokens purchased in this transaction neoRemainingAfterPurchase, // how much neo is left after purchase of tokens gasRemainingAfterPurchase, // how much gas is left after purchase of tokens totalContributionBalance // the total amount of tokens sender has purchased during public sale }); }
/// <summary> /// return the amount of tokens left for purchase /// </summary> /// <returns></returns> public static BigInteger CrowdsaleAvailableAmount() { BigInteger amountAvailable = (ICOTemplate.TokenMaxSupply * factor) - NEP5.TotalSupply(); return(amountAvailable); }