Exemplo n.º 1
0
        /// <summary>
        /// Deposit
        /// </summary>
        /// <param name="tokenAddress">Valid ERC20 Token</param>
        /// <param name="userAddress"></param>
        /// <param name="amount"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <string> Deposit(DepositModel depositModel, MaticTransactionOptions options)
        {
            try
            {
                //Get the Contract instance by Creating a Web3 client from the Sender's Private Key
                Web3     web3Client       = Web3ClientHelper.GetWeb3Client(ProviderUrl, options.SenderPrivateKey);
                Contract contractInstance = web3Client.Eth.GetContract(ABI, ContractAddress);
                Function function         = contractInstance.GetFunction("deposit");

                //Fill the options
                options = await TransactionEstimateHelper.GetTransactionEstimate(depositModel, options, function);

                //Convert the amount from wei to Ethers
                decimal etherEquivalent = Web3.Convert.FromWei(depositModel.Amount);

                object[] paramObjects = new object[3] {
                    depositModel.TokenAddress, depositModel.UserAddress, depositModel.Amount
                };

                string response = await function.SendTransactionAsync(options.From, new HexBigInteger(options.GasLimit), new HexBigInteger(options.GasPrice.ToString()), null, depositModel.TokenAddress, depositModel.UserAddress, depositModel.Amount);

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception($"There was an error depositing {depositModel.Amount} Ethers into {depositModel.TokenAddress} : {ex.Message}");
            }
        }
Exemplo n.º 2
0
        /// <summary>

        /// </summary>
        /// <param name="rootTokenAddress"></param>11
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <string> ProcessExits(ProcessExitsModel processExitsModel, MaticTransactionOptions options)
        {
            //Get the Contract instance by Creating a Web3 client from the Sender's Private Key
            Web3     web3Client       = Web3ClientHelper.GetWeb3Client(ProviderUrl, options.SenderPrivateKey);
            Contract contractInstance = web3Client.Eth.GetContract(ABI, ContractAddress);
            Function function         = contractInstance.GetFunction("processExits");

            options = await TransactionEstimateHelper.GetTransactionEstimate(processExitsModel, options, function);

            string response = await function.SendTransactionAsync(options.From, options.GasLimit, options.GasPrice, null, processExitsModel.RootTokenAddress);

            return(response);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="headerNumber"></param>
        /// <param name="v1"></param>
        /// <param name="blockNumber"></param>
        /// <param name="blockTimeStamp"></param>
        /// <param name="txProofRoot"></param>
        /// <param name="receiptProofRoot"></param>
        /// <param name="v2"></param>
        /// <param name="txProofValue"></param>
        /// <param name="txProofParentNodes"></param>
        /// <param name="receiptProofValue"></param>
        /// <param name="receiptProofParentNodes"></param>
        /// <returns></returns>
        public async Task <string> WithdrawBurntTokens(WithdrawBurntTokensModel withdrawModel, MaticTransactionOptions options)
        {
            //Get the Contract instance by Creating a Web3 client from the Sender's Private Key
            Web3     web3Client       = Web3ClientHelper.GetWeb3Client(ProviderUrl, options.SenderPrivateKey);
            Contract contractInstance = web3Client.Eth.GetContract(ABI, ContractAddress);
            Function function         = contractInstance.GetFunction("withdrawBurntTokens");

            options = await TransactionEstimateHelper.GetTransactionEstimate(withdrawModel, options, function);

            string response = await function.SendTransactionAsync(options.From, options.GasLimit, options.GasPrice, null, withdrawModel.HeaderNumber, withdrawModel.HeaderProof, withdrawModel.BlockNumber, withdrawModel.BlockTimeStamp, withdrawModel.TxRoot, withdrawModel.ReceiptRoot, withdrawModel.Path, withdrawModel.TxBytes, withdrawModel.TxProof, withdrawModel.ReceiptBytes, withdrawModel.ReceiptProof);

            return(response);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deposit ERC721 token into Matic chain.(older ERC721 or some newer contracts will not support this.
        /// In that case, first call `approveERC721TokenForDeposit` and `depositERC721Tokens`)
        /// </summary>
        /// <param name="rootChainAddress"></param>
        /// <param name="tokenId"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <string> SafeTransferFrom(ERC721SafeTransferFromModel safeTransferModel, MaticTransactionOptions options)
        {
            //Get the Contract instance by Creating a Web3 client from the Sender's Private Key
            Web3     web3Client       = Web3ClientHelper.GetWeb3Client(ProviderUrl, options.SenderPrivateKey);
            Contract contractInstance = web3Client.Eth.GetContract(ABI, ContractAddress);
            Function function         = contractInstance.GetFunction("SafeTransferFrom");

            options = await TransactionEstimateHelper.GetTransactionEstimate(safeTransferModel, options, function);

            string transactionHash = await function.SendTransactionAsync(options.From, new HexBigInteger(options.GasLimit), new HexBigInteger(options.GasPrice.ToString()), null, safeTransferModel.From, safeTransferModel.To, safeTransferModel.TokenId);

            return(transactionHash);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Withdraw
        /// </summary>
        /// <param name="tokenId"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <string> Withdraw(ERC721WithdrawModel withdrawModel, MaticTransactionOptions options)
        {
            //Get the Contract instance by Creating a Web3 client from the Sender's Private Key
            Web3     web3Client       = Web3ClientHelper.GetWeb3Client(ProviderUrl, options.SenderPrivateKey);
            Contract contractInstance = web3Client.Eth.GetContract(ABI, ContractAddress);
            Function function         = contractInstance.GetFunction("withdraw");

            options = await TransactionEstimateHelper.GetTransactionEstimate(withdrawModel, options, function);

            string response = await function.SendTransactionAsync(options.From, new HexBigInteger(options.GasLimit), new HexBigInteger(options.GasPrice.ToString()), null, withdrawModel.TokenId);

            return(response);
        }
Exemplo n.º 6
0
        /// <summary>
        /// The transfer function is used to Perform Transfers from one Address to another
        /// </summary>
        /// <param name="from">Source Address and Signer</param>
        /// <param name="To">Destination Address</param>
        /// <param name="Value">The Amount (In wei) of tokens to be transfered</param>
        /// <returns></returns>
        public async Task <string> Transfer(ERC20TransferModel transferModel, MaticTransactionOptions options)
        {
            //Get the Contract instance by Creating a Web3 client from the Sender's Private Key
            Web3     web3Client       = Web3ClientHelper.GetWeb3Client(ProviderUrl, options.SenderPrivateKey);
            Contract contractInstance = web3Client.Eth.GetContract(ABI, ContractAddress);
            Function function         = contractInstance.GetFunction("transfer");

            //Fill the options
            options = await TransactionEstimateHelper.GetTransactionEstimate(transferModel, options, function);

            string response = await function.SendTransactionAsync(options.From, new HexBigInteger(options.GasLimit), new HexBigInteger(options.GasPrice.ToString()), null, transferModel.To, (BigInteger)transferModel.Value);

            return(response);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Deposit Ethers
        /// </summary>
        /// <param name="options">Matic Transaction Options</param>
        /// <returns></returns>
        public async Task <string> DepositEthers(MaticTransactionOptions options)
        {
            try
            {
                //Get the Contract instance by Creating a Web3 client from the Sender's Private Key
                Web3     web3Client       = Web3ClientHelper.GetWeb3Client(ProviderUrl, options.SenderPrivateKey);
                Contract contractInstance = web3Client.Eth.GetContract(ABI, ContractAddress);
                Function function         = contractInstance.GetFunction("depositEthers");

                //Fill the options
                options = await TransactionEstimateHelper.GetTransactionEstimate(options, function);

                //Send the transaction
                string response = await function.SendTransactionAsync(options.From, new HexBigInteger(options.GasLimit), new HexBigInteger(options.GasPrice.ToString()), new HexBigInteger(options.Value.ToString()));

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception($"There was an error Depositing Ethers because {ex.Message}");
            }
        }
        /// <summary>
        /// Event
        /// </summary>
        /// <param name="rootChainAddress"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public async Task <string> Approve(ERC20ApproveModel approveModel, MaticTransactionOptions options)
        {
            try
            {
                //Get the Contract instance by Creating a Web3 client from the Sender's Private Key
                Web3     web3Client       = Web3ClientHelper.GetWeb3Client(ProviderUrl, options.SenderPrivateKey);
                Contract contractInstance = web3Client.Eth.GetContract(ABI, ContractAddress);
                Function function         = contractInstance.GetFunction("approve");

                //Fill out th options
                options = await TransactionEstimateHelper.GetTransactionEstimate(approveModel, options, function);

                //Send the transaction And recieve a response
                string response = await function.SendTransactionAsync(options.From, new HexBigInteger(options.GasLimit), new HexBigInteger(options.GasPrice.ToString()), null, approveModel.Spender, (BigInteger)approveModel.Value);

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception("There was Error Performing Approval because " + ex.Message);
            }
        }