Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(efficiency): remove some token sale logic for increased nep5 GAS efficiency #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 9 additions & 38 deletions ICOTemplate/ICOTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public class ICOTemplate : Framework.SmartContract
/// list NEPs supported by this contract
/// </summary>
/// <returns></returns>
public static string SupportedStandards() => "{\"NEP-5\", \"NEP-10\"}";
public static string[] SupportedStandards() => new string[] { "NEP-5", "NEP-10" };

/// <summary>
/// should whitelisting of TransferFrom transfer/transferFrom methods be checked
Expand All @@ -209,11 +209,14 @@ public static object Main(string operation, params object[] args)
{
if (Runtime.Trigger == TriggerType.Application)
{
//Only allow InitSmartContract if contract not initialized and not calling whitelist/KYC operations
if(!Helpers.ContractInitialised() && ((operation != "admin" && (string) args[0] != "InitSmartContract") && operation != "AddAddress" && operation != "RevokeAddress" && operation != "GetGroupNumber" && operation != "crowdsale_status"))

// test if a nep5 method is being invoked
foreach (string nepMethod in NEP5.GetNEP5Methods())
{
Runtime.Log("Smart Contract not Initialised");
return false;
if (nepMethod == operation)
{
return NEP5.HandleNEP5Operation(operation, args, ExecutionEngine.CallingScriptHash, ExecutionEngine.EntryScriptHash);
}
}

if (operation == "admin" && Helpers.VerifyIsAdminAccount())
Expand All @@ -230,24 +233,6 @@ public static object Main(string operation, params object[] args)
return false;
}

// test if a nep5 method is being invoked
foreach (string nepMethod in NEP5.GetNEP5Methods())
{
if (nepMethod == operation)
{
return NEP5.HandleNEP5Operation(operation, args, ExecutionEngine.CallingScriptHash, ExecutionEngine.EntryScriptHash);
}
}

// test if a kyc method is being invoked
foreach (string kycMethod in KYC.GetKYCMethods())
{
if (kycMethod == operation)
{
return KYC.HandleKYCOperation(operation, args);
}
}

// test if a helper/misc method is being invoked
foreach (string helperMethod in Helpers.GetHelperMethods())
{
Expand All @@ -257,29 +242,15 @@ public static object Main(string operation, params object[] args)
}
}

//If MintTokensEth operation
if(operation == "MintTokensEth")
{
// Method can only be called by the ETH contributions listener account
if (Helpers.VerifyWitness(ICOTemplate.EthContributionListenerKey) && Helpers.RequireArgumentLength(args,3))
{
return EthSale.MintTokensEth((string)args[0], (byte[])args[1], (ulong)args[2]);
}
}

}
else if (Runtime.Trigger == TriggerType.Verification)
{
if (Helpers.VerifyIsAdminAccount())
{
return true;
}

// test if this transaction is allowed
object[] transactionData = Helpers.GetTransactionAndSaleData();
return TokenSale.CanUserParticipateInSale(transactionData);
}

return false;
}

Expand Down
6 changes: 2 additions & 4 deletions ICOTemplate/ICOTemplate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Neo.SmartContract.Framework, Version=2.7.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Neo.SmartContract.Framework.2.7.3\lib\net40\Neo.SmartContract.Framework.dll</HintPath>
<Reference Include="Neo.SmartContract.Framework, Version=2.9.3.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Neo.SmartContract.Framework.2.9.3.1\lib\net40\Neo.SmartContract.Framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -47,9 +47,7 @@
<ItemGroup>
<Compile Include="ICOTemplate.cs" />
<Compile Include="Token\Administration.cs" />
<Compile Include="Token\EthSale.cs" />
<Compile Include="Token\Helpers.cs" />
<Compile Include="Token\KYC.cs" />
<Compile Include="Token\NEP5.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Token\StorageKeys.cs" />
Expand Down
49 changes: 3 additions & 46 deletions ICOTemplate/Token/Administration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class Administration : Framework.SmartContract
"LockPrivateSaleAllocation",
"ContractMigrate",
"EnableTransferFromWhitelisting",
"InitSmartContract",
"UpdateAdminAddress",
"WhitelistTransferFromAdd",
"WhitelistTransferFromRemove",
Expand Down Expand Up @@ -72,8 +71,6 @@ public static object HandleAdministrationOperation(string operation, params obje
return false;
}
return ContractMigrate(args);
case "InitSmartContract":
return InitSmartContract();
case "LockPrivateSaleAllocation":
return LockPrivateSaleAllocation();
case "UpdateAdminAddress":
Expand Down Expand Up @@ -153,51 +150,11 @@ public static bool LockPrivateSaleAllocation()
/// <returns></returns>
public static bool ContractMigrate(object[] args)
{
// Contract Migrate(byte[] script, byte[] parameter_list, byte return_type, bool need_storage, string name, string version, string author, string email, string description)
Contract.Migrate((byte[])args[1], (byte[])args[2], (byte)args[3], (bool)args[4], (string)args[5], (string)args[6], (string)args[7], (string)args[8], (string)args[9]);
// Contract Migrate(byte[] script, byte[] parameter_list, byte return_type, ContractPropertyState (using storage), string name, string version, string author, string email, string description)
Contract.Migrate((byte[])args[1], (byte[])args[2], (byte)args[3], (ContractPropertyState)args[4], (string)args[5], (string)args[6], (string)args[7], (string)args[8], (string)args[9]);
return true;
}

/// <summary>
/// initialise the smart contract for use
/// </summary>
/// <returns></returns>
public static bool InitSmartContract()
{
if (Helpers.ContractInitialised())
{
// contract can only be initialised once
Runtime.Log("InitSmartContract() contract already initialised");
return false;
}


uint ContractInitTime = Helpers.GetBlockTimestamp();
Storage.Put(Storage.CurrentContext, StorageKeys.ContractInitTime(), ContractInitTime);

// assign pre-allocated tokens to the NosProjectKey() (10,000,000 tokens)
BigInteger immediateProjectAllocationValue = ICOTemplate.ImmediateCompanyReserve() * NEP5.factor;


Helpers.SetBalanceOf(ICOTemplate.NosProjectKey, immediateProjectAllocationValue);
transfer(null, ICOTemplate.NosProjectKey, immediateProjectAllocationValue);

// token allocated to private sale & vested reserves & incentives
BigInteger presaleAllocationMaxValue = ICOTemplate.LockedTokenAllocationAmount() * NEP5.factor;

// update the total supply to reflect the project allocated tokens
BigInteger totalSupply = immediateProjectAllocationValue + presaleAllocationMaxValue;
Helpers.SetTotalSupply(totalSupply);

UpdateAdminAddress(ICOTemplate.InitialAdminAccount);

EnableTransferFromWhitelisting(ICOTemplate.WhitelistTransferFromListings());

Runtime.Log("InitSmartContract() contract initialisation complete");
return true;
}



/// <summary>
/// allow the contract administrator to update the admin address
/// </summary>
Expand Down
121 changes: 0 additions & 121 deletions ICOTemplate/Token/EthSale.cs

This file was deleted.

Loading