using System.Numerics;
using Managing.Tools.ABI.Router.ContractDefinition;
using Nethereum.Contracts.ContractHandlers;
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3;

namespace Managing.Tools.ABI.Router
{
    public class RouterService
    {
        public static Task<TransactionReceipt> DeployContractAndWaitForReceiptAsync(Web3 web3,
            RouterDeployment routerDeployment, CancellationTokenSource cancellationTokenSource = null)
        {
            return web3.Eth.GetContractDeploymentHandler<RouterDeployment>()
                .SendRequestAndWaitForReceiptAsync(routerDeployment, cancellationTokenSource);
        }

        public static async Task<RouterService> DeployContractAndGetServiceAsync(Web3 web3,
            RouterDeployment routerDeployment, CancellationTokenSource cancellationTokenSource = null)
        {
            var receipt = await DeployContractAndWaitForReceiptAsync(web3, routerDeployment, cancellationTokenSource);
            return new RouterService(web3, receipt.ContractAddress);
        }

        protected IWeb3 Web3 { get; }

        public ContractHandler ContractHandler { get; }

        public RouterService(Web3 web3, string contractAddress)
        {
            Web3 = web3;
            ContractHandler = web3.Eth.GetContractHandler(contractAddress);
        }

        public RouterService(IWeb3 web3, string contractAddress)
        {
            Web3 = web3;
            ContractHandler = web3.Eth.GetContractHandler(contractAddress);
        }

        public Task<string> AddPluginRequestAsync(AddPluginFunction addPluginFunction)
        {
            return ContractHandler.SendRequestAsync(addPluginFunction);
        }

        public Task<TransactionReceipt> AddPluginRequestAndWaitForReceiptAsync(AddPluginFunction addPluginFunction,
            CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(addPluginFunction, cancellationToken);
        }

        public Task<string> AddPluginRequestAsync(string plugin)
        {
            var addPluginFunction = new AddPluginFunction();
            addPluginFunction.Plugin = plugin;

            return ContractHandler.SendRequestAsync(addPluginFunction);
        }

        public Task<TransactionReceipt> AddPluginRequestAndWaitForReceiptAsync(string plugin,
            CancellationTokenSource cancellationToken = null)
        {
            var addPluginFunction = new AddPluginFunction();
            addPluginFunction.Plugin = plugin;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(addPluginFunction, cancellationToken);
        }

        public Task<string> ApprovePluginRequestAsync(ApprovePluginFunction approvePluginFunction)
        {
            return ContractHandler.SendRequestAsync(approvePluginFunction);
        }

        public Task<TransactionReceipt> ApprovePluginRequestAndWaitForReceiptAsync(
            ApprovePluginFunction approvePluginFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(approvePluginFunction, cancellationToken);
        }

        public Task<string> ApprovePluginRequestAsync(string plugin)
        {
            var approvePluginFunction = new ApprovePluginFunction();
            approvePluginFunction.Plugin = plugin;

            return ContractHandler.SendRequestAsync(approvePluginFunction);
        }

        public Task<TransactionReceipt> ApprovePluginRequestAndWaitForReceiptAsync(string plugin,
            CancellationTokenSource cancellationToken = null)
        {
            var approvePluginFunction = new ApprovePluginFunction();
            approvePluginFunction.Plugin = plugin;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(approvePluginFunction, cancellationToken);
        }

        public Task<bool> ApprovedPluginsQueryAsync(ApprovedPluginsFunction approvedPluginsFunction,
            BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<ApprovedPluginsFunction, bool>(approvedPluginsFunction, blockParameter);
        }


        public Task<bool> ApprovedPluginsQueryAsync(string returnValue1, string returnValue2,
            BlockParameter blockParameter = null)
        {
            var approvedPluginsFunction = new ApprovedPluginsFunction();
            approvedPluginsFunction.ReturnValue1 = returnValue1;
            approvedPluginsFunction.ReturnValue2 = returnValue2;

            return ContractHandler.QueryAsync<ApprovedPluginsFunction, bool>(approvedPluginsFunction, blockParameter);
        }

        public Task<string> DecreasePositionRequestAsync(DecreasePositionFunction decreasePositionFunction)
        {
            return ContractHandler.SendRequestAsync(decreasePositionFunction);
        }

        public Task<TransactionReceipt> DecreasePositionRequestAndWaitForReceiptAsync(
            DecreasePositionFunction decreasePositionFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(decreasePositionFunction, cancellationToken);
        }

        public Task<string> DecreasePositionRequestAsync(string collateralToken, string indexToken,
            BigInteger collateralDelta, BigInteger sizeDelta, bool isLong, string receiver, BigInteger price)
        {
            var decreasePositionFunction = new DecreasePositionFunction();
            decreasePositionFunction.CollateralToken = collateralToken;
            decreasePositionFunction.IndexToken = indexToken;
            decreasePositionFunction.CollateralDelta = collateralDelta;
            decreasePositionFunction.SizeDelta = sizeDelta;
            decreasePositionFunction.IsLong = isLong;
            decreasePositionFunction.Receiver = receiver;
            decreasePositionFunction.Price = price;

            return ContractHandler.SendRequestAsync(decreasePositionFunction);
        }

        public Task<TransactionReceipt> DecreasePositionRequestAndWaitForReceiptAsync(string collateralToken,
            string indexToken, BigInteger collateralDelta, BigInteger sizeDelta, bool isLong, string receiver,
            BigInteger price, CancellationTokenSource cancellationToken = null)
        {
            var decreasePositionFunction = new DecreasePositionFunction();
            decreasePositionFunction.CollateralToken = collateralToken;
            decreasePositionFunction.IndexToken = indexToken;
            decreasePositionFunction.CollateralDelta = collateralDelta;
            decreasePositionFunction.SizeDelta = sizeDelta;
            decreasePositionFunction.IsLong = isLong;
            decreasePositionFunction.Receiver = receiver;
            decreasePositionFunction.Price = price;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(decreasePositionFunction, cancellationToken);
        }

        public Task<string> DecreasePositionAndSwapRequestAsync(
            DecreasePositionAndSwapFunction decreasePositionAndSwapFunction)
        {
            return ContractHandler.SendRequestAsync(decreasePositionAndSwapFunction);
        }

        public Task<TransactionReceipt> DecreasePositionAndSwapRequestAndWaitForReceiptAsync(
            DecreasePositionAndSwapFunction decreasePositionAndSwapFunction,
            CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(decreasePositionAndSwapFunction,
                cancellationToken);
        }

        public Task<string> DecreasePositionAndSwapRequestAsync(List<string> path, string indexToken,
            BigInteger collateralDelta, BigInteger sizeDelta, bool isLong, string receiver, BigInteger price,
            BigInteger minOut)
        {
            var decreasePositionAndSwapFunction = new DecreasePositionAndSwapFunction();
            decreasePositionAndSwapFunction.Path = path;
            decreasePositionAndSwapFunction.IndexToken = indexToken;
            decreasePositionAndSwapFunction.CollateralDelta = collateralDelta;
            decreasePositionAndSwapFunction.SizeDelta = sizeDelta;
            decreasePositionAndSwapFunction.IsLong = isLong;
            decreasePositionAndSwapFunction.Receiver = receiver;
            decreasePositionAndSwapFunction.Price = price;
            decreasePositionAndSwapFunction.MinOut = minOut;

            return ContractHandler.SendRequestAsync(decreasePositionAndSwapFunction);
        }

        public Task<TransactionReceipt> DecreasePositionAndSwapRequestAndWaitForReceiptAsync(List<string> path,
            string indexToken, BigInteger collateralDelta, BigInteger sizeDelta, bool isLong, string receiver,
            BigInteger price, BigInteger minOut, CancellationTokenSource cancellationToken = null)
        {
            var decreasePositionAndSwapFunction = new DecreasePositionAndSwapFunction();
            decreasePositionAndSwapFunction.Path = path;
            decreasePositionAndSwapFunction.IndexToken = indexToken;
            decreasePositionAndSwapFunction.CollateralDelta = collateralDelta;
            decreasePositionAndSwapFunction.SizeDelta = sizeDelta;
            decreasePositionAndSwapFunction.IsLong = isLong;
            decreasePositionAndSwapFunction.Receiver = receiver;
            decreasePositionAndSwapFunction.Price = price;
            decreasePositionAndSwapFunction.MinOut = minOut;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(decreasePositionAndSwapFunction,
                cancellationToken);
        }

        public Task<string> DecreasePositionAndSwapETHRequestAsync(
            DecreasePositionAndSwapETHFunction decreasePositionAndSwapETHFunction)
        {
            return ContractHandler.SendRequestAsync(decreasePositionAndSwapETHFunction);
        }

        public Task<TransactionReceipt> DecreasePositionAndSwapETHRequestAndWaitForReceiptAsync(
            DecreasePositionAndSwapETHFunction decreasePositionAndSwapETHFunction,
            CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(decreasePositionAndSwapETHFunction,
                cancellationToken);
        }

        public Task<string> DecreasePositionAndSwapETHRequestAsync(List<string> path, string indexToken,
            BigInteger collateralDelta, BigInteger sizeDelta, bool isLong, string receiver, BigInteger price,
            BigInteger minOut)
        {
            var decreasePositionAndSwapETHFunction = new DecreasePositionAndSwapETHFunction();
            decreasePositionAndSwapETHFunction.Path = path;
            decreasePositionAndSwapETHFunction.IndexToken = indexToken;
            decreasePositionAndSwapETHFunction.CollateralDelta = collateralDelta;
            decreasePositionAndSwapETHFunction.SizeDelta = sizeDelta;
            decreasePositionAndSwapETHFunction.IsLong = isLong;
            decreasePositionAndSwapETHFunction.Receiver = receiver;
            decreasePositionAndSwapETHFunction.Price = price;
            decreasePositionAndSwapETHFunction.MinOut = minOut;

            return ContractHandler.SendRequestAsync(decreasePositionAndSwapETHFunction);
        }

        public Task<TransactionReceipt> DecreasePositionAndSwapETHRequestAndWaitForReceiptAsync(List<string> path,
            string indexToken, BigInteger collateralDelta, BigInteger sizeDelta, bool isLong, string receiver,
            BigInteger price, BigInteger minOut, CancellationTokenSource cancellationToken = null)
        {
            var decreasePositionAndSwapETHFunction = new DecreasePositionAndSwapETHFunction();
            decreasePositionAndSwapETHFunction.Path = path;
            decreasePositionAndSwapETHFunction.IndexToken = indexToken;
            decreasePositionAndSwapETHFunction.CollateralDelta = collateralDelta;
            decreasePositionAndSwapETHFunction.SizeDelta = sizeDelta;
            decreasePositionAndSwapETHFunction.IsLong = isLong;
            decreasePositionAndSwapETHFunction.Receiver = receiver;
            decreasePositionAndSwapETHFunction.Price = price;
            decreasePositionAndSwapETHFunction.MinOut = minOut;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(decreasePositionAndSwapETHFunction,
                cancellationToken);
        }

        public Task<string> DecreasePositionETHRequestAsync(DecreasePositionETHFunction decreasePositionETHFunction)
        {
            return ContractHandler.SendRequestAsync(decreasePositionETHFunction);
        }

        public Task<TransactionReceipt> DecreasePositionETHRequestAndWaitForReceiptAsync(
            DecreasePositionETHFunction decreasePositionETHFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(decreasePositionETHFunction, cancellationToken);
        }

        public Task<string> DecreasePositionETHRequestAsync(string collateralToken, string indexToken,
            BigInteger collateralDelta, BigInteger sizeDelta, bool isLong, string receiver, BigInteger price)
        {
            var decreasePositionETHFunction = new DecreasePositionETHFunction();
            decreasePositionETHFunction.CollateralToken = collateralToken;
            decreasePositionETHFunction.IndexToken = indexToken;
            decreasePositionETHFunction.CollateralDelta = collateralDelta;
            decreasePositionETHFunction.SizeDelta = sizeDelta;
            decreasePositionETHFunction.IsLong = isLong;
            decreasePositionETHFunction.Receiver = receiver;
            decreasePositionETHFunction.Price = price;

            return ContractHandler.SendRequestAsync(decreasePositionETHFunction);
        }

        public Task<TransactionReceipt> DecreasePositionETHRequestAndWaitForReceiptAsync(string collateralToken,
            string indexToken, BigInteger collateralDelta, BigInteger sizeDelta, bool isLong, string receiver,
            BigInteger price, CancellationTokenSource cancellationToken = null)
        {
            var decreasePositionETHFunction = new DecreasePositionETHFunction();
            decreasePositionETHFunction.CollateralToken = collateralToken;
            decreasePositionETHFunction.IndexToken = indexToken;
            decreasePositionETHFunction.CollateralDelta = collateralDelta;
            decreasePositionETHFunction.SizeDelta = sizeDelta;
            decreasePositionETHFunction.IsLong = isLong;
            decreasePositionETHFunction.Receiver = receiver;
            decreasePositionETHFunction.Price = price;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(decreasePositionETHFunction, cancellationToken);
        }

        public Task<string> DenyPluginRequestAsync(DenyPluginFunction denyPluginFunction)
        {
            return ContractHandler.SendRequestAsync(denyPluginFunction);
        }

        public Task<TransactionReceipt> DenyPluginRequestAndWaitForReceiptAsync(DenyPluginFunction denyPluginFunction,
            CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(denyPluginFunction, cancellationToken);
        }

        public Task<string> DenyPluginRequestAsync(string plugin)
        {
            var denyPluginFunction = new DenyPluginFunction();
            denyPluginFunction.Plugin = plugin;

            return ContractHandler.SendRequestAsync(denyPluginFunction);
        }

        public Task<TransactionReceipt> DenyPluginRequestAndWaitForReceiptAsync(string plugin,
            CancellationTokenSource cancellationToken = null)
        {
            var denyPluginFunction = new DenyPluginFunction();
            denyPluginFunction.Plugin = plugin;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(denyPluginFunction, cancellationToken);
        }

        public Task<string> DirectPoolDepositRequestAsync(DirectPoolDepositFunction directPoolDepositFunction)
        {
            return ContractHandler.SendRequestAsync(directPoolDepositFunction);
        }

        public Task<TransactionReceipt> DirectPoolDepositRequestAndWaitForReceiptAsync(
            DirectPoolDepositFunction directPoolDepositFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(directPoolDepositFunction, cancellationToken);
        }

        public Task<string> DirectPoolDepositRequestAsync(string token, BigInteger amount)
        {
            var directPoolDepositFunction = new DirectPoolDepositFunction();
            directPoolDepositFunction.Token = token;
            directPoolDepositFunction.Amount = amount;

            return ContractHandler.SendRequestAsync(directPoolDepositFunction);
        }

        public Task<TransactionReceipt> DirectPoolDepositRequestAndWaitForReceiptAsync(string token, BigInteger amount,
            CancellationTokenSource cancellationToken = null)
        {
            var directPoolDepositFunction = new DirectPoolDepositFunction();
            directPoolDepositFunction.Token = token;
            directPoolDepositFunction.Amount = amount;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(directPoolDepositFunction, cancellationToken);
        }

        public Task<string> GovQueryAsync(GovFunction govFunction, BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<GovFunction, string>(govFunction, blockParameter);
        }


        public Task<string> GovQueryAsync(BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<GovFunction, string>(null, blockParameter);
        }

        public Task<string> IncreasePositionRequestAsync(IncreasePositionFunction increasePositionFunction)
        {
            return ContractHandler.SendRequestAsync(increasePositionFunction);
        }

        public Task<TransactionReceipt> IncreasePositionRequestAndWaitForReceiptAsync(
            IncreasePositionFunction increasePositionFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(increasePositionFunction, cancellationToken);
        }

        public Task<string> IncreasePositionRequestAsync(List<string> path, string indexToken, BigInteger amountIn,
            BigInteger minOut, BigInteger sizeDelta, bool isLong, BigInteger price)
        {
            var increasePositionFunction = new IncreasePositionFunction();
            increasePositionFunction.Path = path;
            increasePositionFunction.IndexToken = indexToken;
            increasePositionFunction.AmountIn = amountIn;
            increasePositionFunction.MinOut = minOut;
            increasePositionFunction.SizeDelta = sizeDelta;
            increasePositionFunction.IsLong = isLong;
            increasePositionFunction.Price = price;

            return ContractHandler.SendRequestAsync(increasePositionFunction);
        }

        public Task<TransactionReceipt> IncreasePositionRequestAndWaitForReceiptAsync(List<string> path,
            string indexToken, BigInteger amountIn, BigInteger minOut, BigInteger sizeDelta, bool isLong,
            BigInteger price, CancellationTokenSource cancellationToken = null)
        {
            var increasePositionFunction = new IncreasePositionFunction();
            increasePositionFunction.Path = path;
            increasePositionFunction.IndexToken = indexToken;
            increasePositionFunction.AmountIn = amountIn;
            increasePositionFunction.MinOut = minOut;
            increasePositionFunction.SizeDelta = sizeDelta;
            increasePositionFunction.IsLong = isLong;
            increasePositionFunction.Price = price;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(increasePositionFunction, cancellationToken);
        }

        public Task<string> IncreasePositionETHRequestAsync(IncreasePositionETHFunction increasePositionETHFunction)
        {
            return ContractHandler.SendRequestAsync(increasePositionETHFunction);
        }

        public Task<TransactionReceipt> IncreasePositionETHRequestAndWaitForReceiptAsync(
            IncreasePositionETHFunction increasePositionETHFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(increasePositionETHFunction, cancellationToken);
        }

        public Task<string> IncreasePositionETHRequestAsync(List<string> path, string indexToken, BigInteger minOut,
            BigInteger sizeDelta, bool isLong, BigInteger price)
        {
            var increasePositionETHFunction = new IncreasePositionETHFunction();
            increasePositionETHFunction.Path = path;
            increasePositionETHFunction.IndexToken = indexToken;
            increasePositionETHFunction.MinOut = minOut;
            increasePositionETHFunction.SizeDelta = sizeDelta;
            increasePositionETHFunction.IsLong = isLong;
            increasePositionETHFunction.Price = price;

            return ContractHandler.SendRequestAsync(increasePositionETHFunction);
        }

        public Task<TransactionReceipt> IncreasePositionETHRequestAndWaitForReceiptAsync(List<string> path,
            string indexToken, BigInteger minOut, BigInteger sizeDelta, bool isLong, BigInteger price,
            CancellationTokenSource cancellationToken = null)
        {
            var increasePositionETHFunction = new IncreasePositionETHFunction();
            increasePositionETHFunction.Path = path;
            increasePositionETHFunction.IndexToken = indexToken;
            increasePositionETHFunction.MinOut = minOut;
            increasePositionETHFunction.SizeDelta = sizeDelta;
            increasePositionETHFunction.IsLong = isLong;
            increasePositionETHFunction.Price = price;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(increasePositionETHFunction, cancellationToken);
        }

        public Task<string> PluginDecreasePositionRequestAsync(
            PluginDecreasePositionFunction pluginDecreasePositionFunction)
        {
            return ContractHandler.SendRequestAsync(pluginDecreasePositionFunction);
        }

        public Task<TransactionReceipt> PluginDecreasePositionRequestAndWaitForReceiptAsync(
            PluginDecreasePositionFunction pluginDecreasePositionFunction,
            CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(pluginDecreasePositionFunction, cancellationToken);
        }

        public Task<string> PluginDecreasePositionRequestAsync(string account, string collateralToken,
            string indexToken, BigInteger collateralDelta, BigInteger sizeDelta, bool isLong, string receiver)
        {
            var pluginDecreasePositionFunction = new PluginDecreasePositionFunction();
            pluginDecreasePositionFunction.Account = account;
            pluginDecreasePositionFunction.CollateralToken = collateralToken;
            pluginDecreasePositionFunction.IndexToken = indexToken;
            pluginDecreasePositionFunction.CollateralDelta = collateralDelta;
            pluginDecreasePositionFunction.SizeDelta = sizeDelta;
            pluginDecreasePositionFunction.IsLong = isLong;
            pluginDecreasePositionFunction.Receiver = receiver;

            return ContractHandler.SendRequestAsync(pluginDecreasePositionFunction);
        }

        public Task<TransactionReceipt> PluginDecreasePositionRequestAndWaitForReceiptAsync(string account,
            string collateralToken, string indexToken, BigInteger collateralDelta, BigInteger sizeDelta, bool isLong,
            string receiver, CancellationTokenSource cancellationToken = null)
        {
            var pluginDecreasePositionFunction = new PluginDecreasePositionFunction();
            pluginDecreasePositionFunction.Account = account;
            pluginDecreasePositionFunction.CollateralToken = collateralToken;
            pluginDecreasePositionFunction.IndexToken = indexToken;
            pluginDecreasePositionFunction.CollateralDelta = collateralDelta;
            pluginDecreasePositionFunction.SizeDelta = sizeDelta;
            pluginDecreasePositionFunction.IsLong = isLong;
            pluginDecreasePositionFunction.Receiver = receiver;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(pluginDecreasePositionFunction, cancellationToken);
        }

        public Task<string> PluginIncreasePositionRequestAsync(
            PluginIncreasePositionFunction pluginIncreasePositionFunction)
        {
            return ContractHandler.SendRequestAsync(pluginIncreasePositionFunction);
        }

        public Task<TransactionReceipt> PluginIncreasePositionRequestAndWaitForReceiptAsync(
            PluginIncreasePositionFunction pluginIncreasePositionFunction,
            CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(pluginIncreasePositionFunction, cancellationToken);
        }

        public Task<string> PluginIncreasePositionRequestAsync(string account, string collateralToken,
            string indexToken, BigInteger sizeDelta, bool isLong)
        {
            var pluginIncreasePositionFunction = new PluginIncreasePositionFunction();
            pluginIncreasePositionFunction.Account = account;
            pluginIncreasePositionFunction.CollateralToken = collateralToken;
            pluginIncreasePositionFunction.IndexToken = indexToken;
            pluginIncreasePositionFunction.SizeDelta = sizeDelta;
            pluginIncreasePositionFunction.IsLong = isLong;

            return ContractHandler.SendRequestAsync(pluginIncreasePositionFunction);
        }

        public Task<TransactionReceipt> PluginIncreasePositionRequestAndWaitForReceiptAsync(string account,
            string collateralToken, string indexToken, BigInteger sizeDelta, bool isLong,
            CancellationTokenSource cancellationToken = null)
        {
            var pluginIncreasePositionFunction = new PluginIncreasePositionFunction();
            pluginIncreasePositionFunction.Account = account;
            pluginIncreasePositionFunction.CollateralToken = collateralToken;
            pluginIncreasePositionFunction.IndexToken = indexToken;
            pluginIncreasePositionFunction.SizeDelta = sizeDelta;
            pluginIncreasePositionFunction.IsLong = isLong;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(pluginIncreasePositionFunction, cancellationToken);
        }

        public Task<string> PluginTransferRequestAsync(PluginTransferFunction pluginTransferFunction)
        {
            return ContractHandler.SendRequestAsync(pluginTransferFunction);
        }

        public Task<TransactionReceipt> PluginTransferRequestAndWaitForReceiptAsync(
            PluginTransferFunction pluginTransferFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(pluginTransferFunction, cancellationToken);
        }

        public Task<string> PluginTransferRequestAsync(string token, string account, string receiver, BigInteger amount)
        {
            var pluginTransferFunction = new PluginTransferFunction();
            pluginTransferFunction.Token = token;
            pluginTransferFunction.Account = account;
            pluginTransferFunction.Receiver = receiver;
            pluginTransferFunction.Amount = amount;

            return ContractHandler.SendRequestAsync(pluginTransferFunction);
        }

        public Task<TransactionReceipt> PluginTransferRequestAndWaitForReceiptAsync(string token, string account,
            string receiver, BigInteger amount, CancellationTokenSource cancellationToken = null)
        {
            var pluginTransferFunction = new PluginTransferFunction();
            pluginTransferFunction.Token = token;
            pluginTransferFunction.Account = account;
            pluginTransferFunction.Receiver = receiver;
            pluginTransferFunction.Amount = amount;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(pluginTransferFunction, cancellationToken);
        }

        public Task<bool> PluginsQueryAsync(PluginsFunction pluginsFunction, BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<PluginsFunction, bool>(pluginsFunction, blockParameter);
        }


        public Task<bool> PluginsQueryAsync(string returnValue1, BlockParameter blockParameter = null)
        {
            var pluginsFunction = new PluginsFunction();
            pluginsFunction.ReturnValue1 = returnValue1;

            return ContractHandler.QueryAsync<PluginsFunction, bool>(pluginsFunction, blockParameter);
        }

        public Task<string> RemovePluginRequestAsync(RemovePluginFunction removePluginFunction)
        {
            return ContractHandler.SendRequestAsync(removePluginFunction);
        }

        public Task<TransactionReceipt> RemovePluginRequestAndWaitForReceiptAsync(
            RemovePluginFunction removePluginFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(removePluginFunction, cancellationToken);
        }

        public Task<string> RemovePluginRequestAsync(string plugin)
        {
            var removePluginFunction = new RemovePluginFunction();
            removePluginFunction.Plugin = plugin;

            return ContractHandler.SendRequestAsync(removePluginFunction);
        }

        public Task<TransactionReceipt> RemovePluginRequestAndWaitForReceiptAsync(string plugin,
            CancellationTokenSource cancellationToken = null)
        {
            var removePluginFunction = new RemovePluginFunction();
            removePluginFunction.Plugin = plugin;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(removePluginFunction, cancellationToken);
        }

        public Task<string> SetGovRequestAsync(SetGovFunction setGovFunction)
        {
            return ContractHandler.SendRequestAsync(setGovFunction);
        }

        public Task<TransactionReceipt> SetGovRequestAndWaitForReceiptAsync(SetGovFunction setGovFunction,
            CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(setGovFunction, cancellationToken);
        }

        public Task<string> SetGovRequestAsync(string gov)
        {
            var setGovFunction = new SetGovFunction();
            setGovFunction.Gov = gov;

            return ContractHandler.SendRequestAsync(setGovFunction);
        }

        public Task<TransactionReceipt> SetGovRequestAndWaitForReceiptAsync(string gov,
            CancellationTokenSource cancellationToken = null)
        {
            var setGovFunction = new SetGovFunction();
            setGovFunction.Gov = gov;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(setGovFunction, cancellationToken);
        }

        public Task<string> SwapRequestAsync(SwapFunction swapFunction)
        {
            return ContractHandler.SendRequestAsync(swapFunction);
        }

        public Task<TransactionReceipt> SwapRequestAndWaitForReceiptAsync(SwapFunction swapFunction,
            CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(swapFunction, cancellationToken);
        }

        public Task<string> SwapRequestAsync(List<string> path, BigInteger amountIn, BigInteger minOut, string receiver)
        {
            var swapFunction = new SwapFunction();
            swapFunction.Path = path;
            swapFunction.AmountIn = amountIn;
            swapFunction.MinOut = minOut;
            swapFunction.Receiver = receiver;

            return ContractHandler.SendRequestAsync(swapFunction);
        }

        public Task<TransactionReceipt> SwapRequestAndWaitForReceiptAsync(List<string> path, BigInteger amountIn,
            BigInteger minOut, string receiver, CancellationTokenSource cancellationToken = null)
        {
            var swapFunction = new SwapFunction();
            swapFunction.Path = path;
            swapFunction.AmountIn = amountIn;
            swapFunction.MinOut = minOut;
            swapFunction.Receiver = receiver;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(swapFunction, cancellationToken);
        }

        public Task<string> SwapETHToTokensRequestAsync(SwapETHToTokensFunction swapETHToTokensFunction)
        {
            return ContractHandler.SendRequestAsync(swapETHToTokensFunction);
        }

        public Task<TransactionReceipt> SwapETHToTokensRequestAndWaitForReceiptAsync(
            SwapETHToTokensFunction swapETHToTokensFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(swapETHToTokensFunction, cancellationToken);
        }

        public Task<string> SwapETHToTokensRequestAsync(List<string> path, BigInteger minOut, string receiver)
        {
            var swapETHToTokensFunction = new SwapETHToTokensFunction();
            swapETHToTokensFunction.Path = path;
            swapETHToTokensFunction.MinOut = minOut;
            swapETHToTokensFunction.Receiver = receiver;

            return ContractHandler.SendRequestAsync(swapETHToTokensFunction);
        }

        public Task<TransactionReceipt> SwapETHToTokensRequestAndWaitForReceiptAsync(List<string> path,
            BigInteger minOut, string receiver, CancellationTokenSource cancellationToken = null)
        {
            var swapETHToTokensFunction = new SwapETHToTokensFunction();
            swapETHToTokensFunction.Path = path;
            swapETHToTokensFunction.MinOut = minOut;
            swapETHToTokensFunction.Receiver = receiver;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(swapETHToTokensFunction, cancellationToken);
        }

        public Task<string> SwapTokensToETHRequestAsync(SwapTokensToETHFunction swapTokensToETHFunction)
        {
            return ContractHandler.SendRequestAsync(swapTokensToETHFunction);
        }

        public Task<TransactionReceipt> SwapTokensToETHRequestAndWaitForReceiptAsync(
            SwapTokensToETHFunction swapTokensToETHFunction, CancellationTokenSource cancellationToken = null)
        {
            return ContractHandler.SendRequestAndWaitForReceiptAsync(swapTokensToETHFunction, cancellationToken);
        }

        public Task<string> SwapTokensToETHRequestAsync(List<string> path, BigInteger amountIn, BigInteger minOut,
            string receiver)
        {
            var swapTokensToETHFunction = new SwapTokensToETHFunction();
            swapTokensToETHFunction.Path = path;
            swapTokensToETHFunction.AmountIn = amountIn;
            swapTokensToETHFunction.MinOut = minOut;
            swapTokensToETHFunction.Receiver = receiver;

            return ContractHandler.SendRequestAsync(swapTokensToETHFunction);
        }

        public Task<TransactionReceipt> SwapTokensToETHRequestAndWaitForReceiptAsync(List<string> path,
            BigInteger amountIn, BigInteger minOut, string receiver, CancellationTokenSource cancellationToken = null)
        {
            var swapTokensToETHFunction = new SwapTokensToETHFunction();
            swapTokensToETHFunction.Path = path;
            swapTokensToETHFunction.AmountIn = amountIn;
            swapTokensToETHFunction.MinOut = minOut;
            swapTokensToETHFunction.Receiver = receiver;

            return ContractHandler.SendRequestAndWaitForReceiptAsync(swapTokensToETHFunction, cancellationToken);
        }

        public Task<string> UsdgQueryAsync(UsdgFunction usdgFunction, BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<UsdgFunction, string>(usdgFunction, blockParameter);
        }


        public Task<string> UsdgQueryAsync(BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<UsdgFunction, string>(null, blockParameter);
        }

        public Task<string> VaultQueryAsync(VaultFunction vaultFunction, BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<VaultFunction, string>(vaultFunction, blockParameter);
        }


        public Task<string> VaultQueryAsync(BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<VaultFunction, string>(null, blockParameter);
        }

        public Task<string> WethQueryAsync(WethFunction wethFunction, BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<WethFunction, string>(wethFunction, blockParameter);
        }


        public Task<string> WethQueryAsync(BlockParameter blockParameter = null)
        {
            return ContractHandler.QueryAsync<WethFunction, string>(null, blockParameter);
        }
    }
}