Example #1
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);
 }
Example #2
0
    // >0 if it is more mass in source volume
    // TIME IS APPLIED
    public float GetMassBalance(ChemVolume receiverVol)
    {
        ChemVolume sourceVol = GetSourceForReceiver(receiverVol);

        if (sourceVol.name == "SteamStorage")
        {
            int x = 0;
        }
        float res = (sourceVol.Pressure - receiverVol.Pressure) * Kmass * gateGap * plant.PlantDeltaTime;

        if (res > 0)
        {
            float probableMass = GasUtils.CalculateMass(sourceVol.Pressure, receiverVol.Volume, sourceVol.Mix.Temp);
            float dm           = probableMass - receiverVol.Mix.Mass;
            if (dm > 0 && res > dm)
            {
                res = dm;
            }
        }
        if (float.IsNaN(res) || float.IsInfinity(res))
        {
            throw new UnityException("GetMassBalance result is Nan or Infinity");
        }
        return(res);
    }
Example #3
0
        public async Task GetEthSendGasLimit()
        {
            string     address  = "0xb332Feee826BF44a431Ea3d65819e31578f30446";
            BigInteger gasLimit = await GasUtils.EstimateEthGasLimit(address, SolidityUtils.ConvertToUInt(0.04055123, 18));

            Assert.IsTrue(gasLimit > 0);
        }
        /// <summary>
        /// Checks the gas price entered in the gas price field.
        /// </summary>
        /// <param name="gasPrice"> The entered gas price. </param>
        private void CheckGasPriceField(string gasPrice)
        {
            decimal price;

            decimal.TryParse(gasPriceField.Text, out price);

            enteredGasPrice     = new GasPrice(GasUtils.GetFunctionalGasPrice(price));
            gasPriceField.Error = string.IsNullOrEmpty(gasPriceField.Text) || price == 0;

            OnGasChanged?.Invoke();
        }
    private void UpdateItemInfo(Hodler.Output.Item item, BigInteger lockedTimeStamp)
    {
        item.LockedTimeStamp = lockedTimeStamp;

        if (item.Unlockable && !item.UnlockableGasLimit.HasValue)
        {
            GasUtils.EstimateContractGasLimit <Hodler.Messages.Release>(hodlerContract.ContractAddress,
                                                                        userWalletManager.GetWalletAddress(),
                                                                        item.Id).OnSuccess(limit => item.UnlockableGasLimit = limit);
        }
    }
Example #6
0
    // Use this for initialization
    void Start()
    {
        float m = GasUtils.CalculateMass(Constants.WorldPressure, volume.Volume, Constants.WorldTemp);

        volume.Mix.AddFraction(new ChemFraction(O2, m * frO2));
        volume.Mix.AddFraction(new ChemFraction(N2, m * frN2));
        volume.Mix.AddFraction(new ChemFraction(CO2, m * frCO2));
        volume.Mix.AddFraction(new ChemFraction(InertGas, m * (1 - frO2 - frN2 - frCO2)));
        volume.Mix.Heat     = m * volume.Mix.HeatCapacity * Constants.WorldTemp;
        volume.Mix.Infinite = true;
    }
    /// <summary>
    /// Rechecks if the function can be executed once the ether balance changes, the gas price changes, or the gas limit is received.
    /// </summary>
    private void RecheckIfFunctionCanBeSent()
    {
        OnValueUpdated(item);

        if (!item.UnlockableGasLimit.HasValue)
        {
            return;
        }

        releasePurposeButton.interactable = item.UnlockableGasLimit.HasValue &&
                                            etherBalance > GasUtils.CalculateMaximumGasCost(StandardGasPrice.FunctionalGasPrice.Value, item.UnlockableGasLimit.Value);
    }
Example #8
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();
    }
Example #10
0
 /// <summary>
 /// Initializes this GasPrice with the functional and readable gas prices using a <see cref="BigInteger"/>.
 /// </summary>
 /// <param name="functionalGasPrice"> The <see cref="BigInteger"/> functional gas price to use when sending transactions. </param>
 public GasPrice(BigInteger functionalGasPrice)
 {
     FunctionalGasPrice = new HexBigInteger(functionalGasPrice);
     ReadableGasPrice   = GasUtils.GetReadableGasPrice(functionalGasPrice);
 }
Example #11
0
 /// <summary>
 /// Initializes this GasPrice with the functional and readable prices using a <see cref="HexBigInteger"/>.
 /// </summary>
 /// <param name="functionalGasPrice"> The <see cref="HexBigInteger"/> functional gas price to use when sending transactions. </param>
 public GasPrice(HexBigInteger functionalGasPrice)
 {
     FunctionalGasPrice = functionalGasPrice;
     ReadableGasPrice   = GasUtils.GetReadableGasPrice(functionalGasPrice.Value);
 }
 /// <summary>
 /// Gets the newest gas price estimates.
 /// </summary>
 private void GetUpdatedGasPrices() => GasUtils.EstimateGasPrice().OnSuccess(price => UpdateAllGasObservables(new HexBigInteger(price)));
Example #13
0
    /// <summary>
    /// Updates the newest gas price estimates.
    /// </summary>
    /// <param name="value"> The current value of the slider to use to estimate the gas price. </param>
    private void UpdateGasPriceEstimate(float value)
    {
        GasPrice gasPrice = EqualityComparer <GasPrice> .Default.Equals(StandardGasPrice, default(GasPrice)) ? new GasPrice(GasUtils.GetFunctionalGasPrice(10)) : StandardGasPrice;

        decimal multiplier = decimal.Round((decimal)Mathf.Lerp(0.65f, 1.4f, value) * (decimal)Mathf.Lerp(1f, 4f, value - 0.45f), 2, MidpointRounding.AwayFromZero);

        onGasPriceChanged?.Invoke(new GasPrice(new BigInteger(multiplier * (decimal)gasPrice.FunctionalGasPrice.Value)));
    }
Example #14
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);
 }
Example #15
0
        public async Task EstimateGasPrice()
        {
            BigInteger gasPrice = await GasUtils.EstimateGasPrice(GasUtils.GasPriceTarget.Standard);

            Assert.IsTrue(gasPrice > 0);
        }