Beispiel #1
0
        public async Task GetEthSendGasLimit()
        {
            string     address  = "0xb332Feee826BF44a431Ea3d65819e31578f30446";
            BigInteger gasLimit = await GasUtils.EstimateEthGasLimit(address, SolidityUtils.ConvertToUInt(0.04055123, 18));

            Assert.IsTrue(gasLimit > 0);
        }
    /// <summary>
    /// Updates the ui for the newest TradableAsset.
    /// </summary>
    private void UpdateAssetUI()
    {
        var tradableAsset = tradableAssetManager.ActiveTradableAsset;

        if (tradableAsset == null)
        {
            return;
        }

        string assetBalance = tradableAsset.AssetBalance?.ToString();
        string assetSymbol  = tradableAsset.AssetSymbol;

        if (!string.IsNullOrEmpty(assetBalance))
        {
            balanceText.text = assetBalance.LimitEnd(MAX_ASSET_BALANCE_LENGTH - (assetSymbol.Length + 1), "...") + $"<style=Symbol> {assetSymbol}</size>";
        }

        if (!string.IsNullOrEmpty(assetBalance) && tradableAsset.AssetAddress.EqualsIgnoreCase(prpsContract.ContractAddress) && lockedPrpsManager.UnfulfilledItems.Count > 0)
        {
            balanceText.text = $"{balanceText.text} | {SolidityUtils.ConvertFromUInt(lockedPrpsManager.UnfulfilledItems.Select(item => item.Value).Aggregate((v1, v2) => v1 + v2), 18)}<style=Symbol> Locked</style>";
        }

        lockPurposeSection.SetActive(tradableAsset.AssetAddress.EqualsIgnoreCase(prpsContract.ContractAddress));

        assetText.text    = tradableAsset.AssetName.LimitEnd(MAX_ASSET_NAME_LENGTH, "...");
        assetImage.sprite = tradableAsset.AssetImage;

        UpdateAssetNotifications();
    }
Beispiel #3
0
 /// <summary>
 /// Gets the gas limit for the transfer of this token from the user's address to another address.
 /// </summary>
 /// <param name="receivingAddress"> The address to be receiving the tokens. </param>
 /// <param name="amount"> The amount of tokens to send and test the gas limit for. </param>
 /// <param name="onLimitReceived"> Action to execute when the gas limit has been received. </param>
 public override void GetTransferGasLimit(string receivingAddress, dynamic amount, Action <BigInteger> onLimitReceived)
 {
     GasUtils.EstimateContractGasLimit <ERC20.Messages.Transfer>(erc20TokenContract.ContractAddress,
                                                                 userWalletManager.GetWalletAddress(),
                                                                 receivingAddress,
                                                                 SolidityUtils.ConvertToUInt(amount, AssetDecimals)).OnSuccess(onLimitReceived);
 }
    /// <summary>
    /// Assigns the transaction info to all elements in this popup.
    /// </summary>
    private void AssignTransactionInfo()
    {
        var sendTransaction = transactionInfo.Type == TransactionInfo.TransactionType.Send;
        var valSymbol       = sendTransaction ? "-" : "+";
        var tradableAsset   = tradableAssetManager.GetTradableAsset(transactionInfo.AssetAddress);

        assetImage.sprite = tradableAsset.AssetImage;

        valueText.color = sendTransaction ? UIColors.Red : UIColors.Green;

        transactionHash.text = transactionInfo.TxHash;
        valueText.text       = StringUtils.LimitEnd(valSymbol + SolidityUtils.ConvertFromUInt(transactionInfo.Value, tradableAsset.AssetDecimals).ConvertDecimalToString(), 18, "...") + "<style=Symbol> " + tradableAsset.AssetSymbol + "</style>";

        fromAddress.text   = transactionInfo.From;
        toAddress.text     = transactionInfo.To;
        timestampText.text = DateTimeUtils.TimeStampToDateTime(transactionInfo.TimeStamp).GetFormattedDateAndTimeString(true);
        gasUsedText.text   = transactionInfo.GasUsed.ToString();
        txCostText.text    = (UnitConversion.Convert.FromWei(transactionInfo.GasPrice) * transactionInfo.GasUsed).ConvertDecimalToString() + "<style=Symbol> Ether</style>";
        CheckIfContact(transactionInfo.From.ToLower(), fromAddressName);
        CheckIfContact(transactionInfo.To.ToLower(), toAddressName);

        TransactionUtils.GetTransactionDetails(transactionInfo.TxHash).OnSuccess(tx =>
        {
            gasPriceText.SetText(UnitConversion.Convert.FromWei(tx.GasPrice.Value, UnitConversion.EthUnit.Gwei) + "<style=Symbol> Gwei</style>");
            gasLimitText.SetText(tx.Gas.Value.ToString());
        });
    }
Beispiel #5
0
        public async Task <decimal> QueryAllowance(string owner, string spender)
        {
            var allowance = await SimpleContractQueries.QueryUInt256Output(new Queries.Allowance {
                Owner = owner, Spender = spender
            }, ContractAddress, null);

            return(SolidityUtils.ConvertFromUInt(allowance.Value, Decimals.Value));
        }
Beispiel #6
0
        /// <summary>
        /// Gets the token balance of an address.
        /// </summary>
        /// <param name="address"> The address to check the balance of. </param>
        public async Task <decimal> QueryBalanceOf(string address)
        {
            var balance = await SimpleContractQueries.QueryUInt256Output(new Queries.BalanceOf {
                Owner = address
            }, ContractAddress, address);

            return(SolidityUtils.ConvertFromUInt(balance.Value, Decimals.Value));
        }
    /// <summary>
    /// Sets the amount of the asset that was traded in this transaction.
    /// </summary>
    /// <param name="transaction"> The info of this transaction. </param>
    /// <param name="tradableAsset"> The asset that was traded. </param>
    private void SetAmount(TransactionInfo transaction, TradableAsset tradableAsset)
    {
        var send   = transaction.Type == TransactionInfo.TransactionType.Send;
        var start  = send ? "-" : "+";
        var amount = start + SolidityUtils.ConvertFromUInt(transaction.Value, tradableAsset.AssetDecimals);
        var symbol = tradableAsset.AssetSymbol;

        amountText.SetText(amount.LimitEnd(18 - symbol.Length, "...") + "<style=Symbol> " + symbol + "</style>");
        amountText.color = send ? UIColors.Red : UIColors.Green;
    }
Beispiel #8
0
        /// <summary>
        /// Gets the total supply of this ERC20 token contract.
        /// </summary>
        public EthCallPromise <decimal> QueryTotalSupply()
        {
            EthCallPromise <decimal> promise = new EthCallPromise <decimal>();

            SimpleContractQueries.QueryUInt256Output(new Queries.TotalSupply(), ContractAddress, null)
            .OnSuccess(supply => promise.Build(() => SolidityUtils.ConvertFromUInt(supply.Value, Decimals.Value)))
            .OnError(error => promise.Build(() => "error", () => error));

            return(promise);
        }
Beispiel #9
0
        /// <summary>
        /// Transfers a certain number of tokens of this contract from a wallet to another address.
        /// </summary>
        /// <param name="gasLimit"> The gas limit to use when sending the tokens. </param>
        /// <param name="gasPrice"> The gas price to use when sending the tokens. </param>
        /// <param name="privateKey"> The private key of the address sending the tokens. </param>
        /// <param name="addressTo"> The address the tokens are being sent to. </param>
        /// <param name="address"> The address to transfer the tokens to. </param>
        /// <param name="amount"> The amount of tokens to transfer. </param>
        public Task <TransactionPoller> Transfer(string privateKey, string addressTo, decimal amount, BigInteger gasLimit, BigInteger gasPrice)
        {
            Messages.Transfer transfer = new Messages.Transfer
            {
                AmountToSend = SolidityUtils.ConvertToUInt(amount, Decimals.Value),
                To           = addressTo
            };

            return(ContractUtils.SendContractMessage(transfer, privateKey, ContractAddress, gasPrice, gasLimit));
        }
Beispiel #10
0
        public Task <TransactionPoller> Approve(string privateKey, string spender, decimal amount, BigInteger gasLimit, BigInteger gasPrice)
        {
            Messages.Approve approve = new Messages.Approve
            {
                Spender = spender,
                Value   = SolidityUtils.ConvertToUInt(amount, Decimals.Value)
            };

            return(ContractUtils.SendContractMessage(approve, privateKey, ContractAddress, gasPrice, gasLimit));
        }
Beispiel #11
0
        public EthTransactionPromise TransferFrom(string privateKey, string addressFrom, string addressTo, decimal amount, BigInteger gasLimit, BigInteger gasPrice)
        {
            Messages.TransferFrom transferFrom = new Messages.TransferFrom
            {
                AmountToSend = SolidityUtils.ConvertToUInt(amount, Decimals.Value),
                From         = addressFrom,
                To           = addressTo
            };

            return(ContractUtils.SendContractMessage(transferFrom, privateKey, ContractAddress, gasPrice, gasLimit));
        }
Beispiel #12
0
        /// <summary>
        /// Locks a certain amount of purpose into the Hodler smart contract.
        /// </summary>
        /// <param name="privateKey"> The private key of the address sending the transaction. </param>
        /// <param name="gasLimit"> The gas limit to send with the transaction. </param>
        /// <param name="gasPrice"> The gas price to send with the transaction. </param>
        /// <param name="id"> The id of the lock function call. </param>
        /// <param name="lockAmount"> The amount of purpose to lock. </param>
        /// <param name="monthsToLock"> How many months the purpose should be locked for. </param>
        public EthTransactionPromise Hodl(string privateKey, BigInteger gasLimit, BigInteger gasPrice, BigInteger id, decimal lockAmount, int monthsToLock)
        {
            Messages.Hodl hodl = new Messages.Hodl
            {
                Id     = id,
                Value  = SolidityUtils.ConvertToUInt(lockAmount, 18),
                Months = monthsToLock
            };

            return(ContractUtils.SendContractMessage(hodl, privateKey, ContractAddress, gasPrice, gasLimit));
        }
Beispiel #13
0
        public EthCallPromise <decimal> QueryAllowance(string owner, string spender)
        {
            EthCallPromise <decimal> promise = new EthCallPromise <decimal>();

            SimpleContractQueries.QueryUInt256Output(new Queries.Allowance {
                Owner = owner, Spender = spender
            }, ContractAddress, null)
            .OnSuccess(allowance => promise.Build(() => SolidityUtils.ConvertFromUInt(allowance.Value, Decimals.Value)))
            .OnError(error => promise.Build(() => "error", () => error));

            return(promise);
        }
Beispiel #14
0
        /// <summary>
        /// Gets the token balance of an address.
        /// </summary>
        /// <param name="address"> The address to check the balance of. </param>
        public EthCallPromise <decimal> QueryBalanceOf(string address)
        {
            EthCallPromise <decimal> promise = new EthCallPromise <decimal>();

            SimpleContractQueries.QueryUInt256Output(new Queries.BalanceOf {
                Owner = address
            }, ContractAddress, address)
            .OnSuccess(balance => promise.Build(() => SolidityUtils.ConvertFromUInt(balance.Value, Decimals.Value)))
            .OnError(error => promise.Build(() => "error", () => error));

            return(promise);
        }
Beispiel #15
0
        public async Task QueryTest()
        {
            SimpleOutputs.UInt256 output = await ContractUtils.QueryContract <ERC20.Queries.BalanceOf, SimpleOutputs.UInt256>(
                new ERC20.Queries.BalanceOf {
                Owner = "0x0000000000000000000000000000000000000000"
            },
                "0x6810e776880C02933D47DB1b9fc05908e5386b96",
                null).ConfigureAwait(false);

            decimal result = SolidityUtils.ConvertFromUInt(output.Value, 18);

            Assert.IsTrue(result > 0);
        }
Beispiel #16
0
 /// <summary>
 /// Transfers a specified amount of ether from the input UserWallet to a specified address.
 /// </summary>
 /// <param name="userWalletManager"> The wallet to send the ether from. </param>
 /// <param name="gasLimit"> The gas limit to use for this ether send transaction. </param>
 /// <param name="gasPrice"> The gas price to use for this ether send transaction. </param>
 /// <param name="address"> The address to send the ether to. </param>
 /// <param name="amount"> The amount of ether to send. </param>
 public override void Transfer(UserWalletManager userWalletManager, HexBigInteger gasLimit, HexBigInteger gasPrice, string address, decimal amount)
 {
     userWalletManager.SignTransaction <ConfirmTransactionPopup>(
         request => EthUtils.SendEther(request, gasLimit, gasPrice, userWalletManager.GetWalletAddress(), address, amount),
         gasLimit,
         gasPrice,
         SolidityUtils.ConvertToUInt(amount, 18),
         address,
         "",
         address,
         AssetAddress,
         amount,
         "ETH");
 }
Beispiel #17
0
        public async Task EstimateGasLimitTest()
        {
            ERC20.Messages.Transfer transfer = new ERC20.Messages.Transfer
            {
                To    = "0x5831819C84C05DdcD2568dE72963AC9f7e2833b6",
                Value = SolidityUtils.ConvertToUInt(1, 18)
            };

            BigInteger gasLimit = await GasUtils.EstimateContractGasLimit(
                transfer,
                "0x5831819C84C05DdcD2568dE72963AC9f1e6831b6",
                "0xb332Feee826BF44a431Ea3d65819e31578f30446");

            Assert.IsTrue(gasLimit > 0);
        }
    /// <summary>
    /// Gets the gas limit which would be used to lock the curent purpose balance.
    /// </summary>
    /// <param name="prpsBalance"> The output received from the BalanceOf function of the PRPS contract. </param>
    private void GetLockableGasLimit(SimpleOutputs.UInt256 prpsBalance)
    {
        PRPSBalance = SolidityUtils.ConvertFromUInt(prpsBalance.Value, 18);

        if (prpsBalance.Value <= 0)
        {
            return;
        }

        object[] funcParams = new object[] { estimationId, prpsBalance.Value, estimationMonths };
        GasUtils.EstimateContractGasLimit <Hodler.Messages.Hodl>(hodlerContract.ContractAddress,
                                                                 userWalletManager.GetWalletAddress(),
                                                                 funcParams).OnSuccess(limit => GasLimit = limit);

        OnAmountsUpdated?.Invoke();
    }
Beispiel #19
0
    /// <summary>
    /// Locks a certain amount of purpose into the Hodler smart contract.
    /// </summary>
    /// <param name="userWalletManager"> The class managing the wallet. </param>
    /// <param name="gasLimit"> The gas limit to send with the transaction. </param>
    /// <param name="gasPrice"> The gas price to send with the transaction. </param>
    /// <param name="id"> The id of the lock function call. </param>
    /// <param name="value"> The amount of purpose to lock. </param>
    /// <param name="monthsToLock"> How many months the purpose should be locked for. </param>
    public void Hodl(UserWalletManager userWalletManager, HexBigInteger gasLimit, HexBigInteger gasPrice, BigInteger id, decimal value, int monthsToLock)
    {
        var transactionInput = ContractFunction.CreateFunction <Messages.Hodl>(
            userWalletManager,
            gasPrice,
            gasLimit,
            id,
            SolidityUtils.ConvertToUInt(value, 18),
            new BigInteger(monthsToLock)).CreateTransactionInput(ContractAddress);

        userWalletManager.SignTransaction <ConfirmLockPopup>(
            request => ContractUtils.SendContractMessage("Locking PRPS", transactionInput, request),
            gasLimit,
            gasPrice,
            0,
            ContractAddress,
            transactionInput.Data,
            monthsToLock,
            value);
    }
Beispiel #20
0
    /// <summary>
    /// Transfers a certain number of tokens of this contract from a wallet to another address.
    /// </summary>
    /// <param name="userWalletManager"> The wallet to transfer the tokens from. </param>
    /// <param name="gasLimit"> The gas limit to use when sending the tokens. </param>
    /// <param name="gasPrice"> The gas price to use when sending the tokens. </param>
    /// <param name="address"> The address to transfer the tokens to. </param>
    /// <param name="amount"> The amount of tokens to transfer. </param>
    public void Transfer(UserWalletManager userWalletManager, HexBigInteger gasLimit, HexBigInteger gasPrice, string address, decimal amount)
    {
        var transactionInput = ContractFunction.CreateFunction <Messages.Transfer>(
            userWalletManager,
            gasPrice,
            gasLimit,
            address,
            SolidityUtils.ConvertToUInt(amount, Decimals.Value)).CreateTransactionInput(ContractAddress);

        userWalletManager.SignTransaction <ConfirmTransactionPopup>(
            request => ContractUtils.SendContractMessage($"Sending {Symbol}", transactionInput, request),
            gasLimit,
            gasPrice,
            0,
            ContractAddress,
            transactionInput.Data,
            address,
            ContractAddress,
            amount,
            Symbol);
    }
    /// <summary>
    /// Updates the ui elements and the transaction info whenever the HodlerItem is changed/updated.
    /// </summary>
    /// <param name="info"> The item that holds the info on the purpose locked in the contract. </param>
    protected override void OnValueUpdated(Hodler.Output.Item info)
    {
        lockedPurpose = SolidityUtils.ConvertFromUInt(info.Value, 18);
        item          = info;

        var minPercentageTime     = networkSettings.networkType == EthereumNetworkManager.NetworkType.Mainnet ? MIN_PERCENTAGE_TIME_MAINNET : MIN_PERCENTAGE_TIME_RINKEBY;
        var releaseTimeDifference = info.ReleaseTime - info.LockedTimeStamp;
        var currentTimeDifference = info.ReleaseTime - DateTimeUtils.GetCurrentUnixTime();
        var multiplier            = (decimal)releaseTimeDifference / minPercentageTime / 100;

        lockPeriodDone         = currentTimeDifference < 0;
        purposeAmountText.text = lockedPurpose.ConvertDecimalToString().LimitEnd(12, "...");
        dubiAmountText.text    = (multiplier * lockedPurpose).ConvertDecimalToString().LimitEnd(11, "...");
        lockPeriodText.text    = DateTimeUtils.GetMaxTimeInterval((int)releaseTimeDifference);

        timeLeftText.text = currentTimeDifference < 0 && !useUnlockableTime
                        ? "Done"
                        : !useUnlockableTime
                                ? GetTimeLeftString((int)currentTimeDifference)
                                : DateTimeUtils.TimeStampToDateTime((long)info.ReleaseTime).GetStringFormattedDate(true);
    }
 /// <summary>
 /// Checks the details of each purpose transaction sent to the hodl contract.
 /// </summary>
 /// <param name="tokenTransactionJson"> The json of the token transaction. </param>
 private void GetTransactionInputData(TokenTransactionJson tokenTransactionJson)
 {
     TransactionUtils.GetTransactionDetails(tokenTransactionJson.transactionHash)
     .OnSuccess(tx => GetItemFromHodlerContract(SolidityUtils.ExtractFunctionParameters(tx.Input), tokenTransactionJson.timeStamp.ConvertFromHex()));
 }
 /// <summary>
 /// Gets the most recent DUBI balance.
 /// </summary>
 /// <param name="contractAddress"> The contract address for DUBI. </param>
 /// <param name="walletAddress"> The current wallet address. </param>
 private void GetDUBIBalance(string contractAddress, string walletAddress)
 {
     SimpleContractQueries.QueryUInt256Output <ERC20.Queries.BalanceOf>(contractAddress, walletAddress, walletAddress)
     .OnSuccess(balance => DUBIBalance = SolidityUtils.ConvertFromUInt(balance.Value, 18));
 }
Beispiel #24
0
 /// <summary>
 /// Gets the token balance of an address.
 /// </summary>
 /// <param name="address"> The address to check the balance of. </param>
 /// <param name="onBalanceReceived"> Callback action which should pass in the received balance of Gold tokens on the address. </param>
 public void BalanceOf(string address, Action <dynamic> onBalanceReceived)
 {
     SimpleContractQueries.QueryUInt256Output <Queries.BalanceOf>(ContractAddress, address, address)
     .OnSuccess(balance => onBalanceReceived?.Invoke(SolidityUtils.ConvertFromUInt(balance, Decimals.Value)));
 }
Beispiel #25
0
 /// <summary>
 /// Gets the total supply of this ERC20 token contract.
 /// </summary>
 /// <param name="onSupplyReceived"> Callback action which should pass in the total supply of this token. </param>
 public void TotalSupply(Action <dynamic> onSupplyReceived)
 {
     SimpleContractQueries.QueryUInt256Output <Queries.TotalSupply>(ContractAddress, null)
     .OnSuccess(supply => onSupplyReceived?.Invoke(SolidityUtils.ConvertFromUInt(supply, Decimals.Value)));
 }
Beispiel #26
0
 /// <summary>
 /// Estimates the gas limit of transfering eth from one address to another.
 /// </summary>
 /// <param name="receivingAddress"> The address to receive the ether. </param>
 /// <param name="amount"> The amount of ether that is requesting to be sent. </param>
 /// <param name="onLimitReceived"> The action to execute when the gas limit has been received. </param>
 public override void GetTransferGasLimit(string receivingAddress, dynamic amount, Action <BigInteger> onLimitReceived)
 {
     GasUtils.EstimateEthGasLimit(receivingAddress, SolidityUtils.ConvertToUInt(amount, 18)).OnSuccess(onLimitReceived);
 }
Beispiel #27
0
        /// <summary>
        /// Gets the total supply of this ERC20 token contract.
        /// </summary>
        public async Task <decimal> QueryTotalSupply()
        {
            var supply = await SimpleContractQueries.QueryUInt256Output(new Queries.TotalSupply(), ContractAddress, null);

            return(SolidityUtils.ConvertFromUInt(supply.Value, Decimals.Value));
        }