Example #1
0
        public SwapManager(
            IAccount account,
            ISwapClient swapClient,
            ICurrencyQuotesProvider quotesProvider,
            IMarketDataRepository marketDataRepository)
        {
            _account              = account ?? throw new ArgumentNullException(nameof(account));
            _swapClient           = swapClient ?? throw new ArgumentNullException(nameof(swapClient));
            _quotesProvider       = quotesProvider;
            _marketDataRepository = marketDataRepository ?? throw new ArgumentNullException(nameof(marketDataRepository));

            var currencySwaps = _account.Currencies
                                .Select(c =>
            {
                var currencySwap = CurrencySwapCreator.Create(
                    currency: c,
                    account: _account);

                currencySwap.InitiatorPaymentConfirmed += InitiatorPaymentConfirmed;
                currencySwap.AcceptorPaymentConfirmed  += AcceptorPaymentConfirmed;
                currencySwap.AcceptorPaymentSpent      += AcceptorPaymentSpent;
                currencySwap.SwapUpdated += SwapUpdatedHandler;

                return(currencySwap);
            });

            _currencySwaps = currencySwaps.ToDictionary(cs => cs.Currency);
        }
        public static ICurrencySwap Create(
            Currency currency,
            IAccount account,
            ISwapClient swapClient,
            IBackgroundTaskPerformer taskPerformer)
        {
            switch (currency)
            {
            case BitcoinBasedCurrency _:
                return(new BitcoinBasedSwap(
                           currency: currency,
                           account: account,
                           swapClient: swapClient,
                           taskPerformer: taskPerformer,
                           transactionFactory: new BitcoinBasedSwapTransactionFactory()));

            case Atomix.Ethereum _:
                return(new EthereumSwap(
                           currency: currency,
                           account: account,
                           swapClient: swapClient,
                           taskPerformer: taskPerformer));

            case Atomix.Tezos _:
                return(new TezosSwap(
                           currency: currency,
                           account: account,
                           swapClient: swapClient,
                           taskPerformer: taskPerformer));

            default:
                throw new NotSupportedException($"Not supported currency {currency.Name}");
            }
        }
Example #3
0
        public ClientSwapManager(
            IAccount account,
            ISwapClient swapClient,
            IBackgroundTaskPerformer taskPerformer)
        {
            _account    = account ?? throw new ArgumentNullException(nameof(account));
            _swapClient = swapClient ?? throw new ArgumentNullException(nameof(swapClient));

            _swaps = _account.Currencies
                     .Select(c =>
            {
                var currencySwap = CurrencySwapCreator.Create(
                    currency: c,
                    account: _account,
                    swapClient: swapClient,
                    taskPerformer: taskPerformer);

                currencySwap.InitiatorPaymentConfirmed += InitiatorPaymentConfirmed;
                currencySwap.AcceptorPaymentConfirmed  += AcceptorPaymentConfirmed;
                currencySwap.AcceptorPaymentSpent      += AcceptorPaymentSpent;
                currencySwap.SwapUpdated += SwapUpdatedHandler;

                return(currencySwap);
            })
                     .ToDictionary(cs => cs.Currency.Name);
        }
 public EthereumSwap(
     EthereumAccount account,
     ISwapClient swapClient,
     ICurrencies currencies)
     : base(account.Currency, swapClient, currencies)
 {
     _account = account ?? throw new ArgumentNullException(nameof(account));
 }
Example #5
0
 public FA12Swap(
     FA12Account account,
     TezosAccount tezosAccount,
     ISwapClient swapClient,
     ICurrencies currencies)
     : base(account, swapClient, currencies)
 {
     TezosAccount = tezosAccount ?? throw new ArgumentNullException(nameof(account));
 }
Example #6
0
 public BitcoinBasedSwap(
     BitcoinBasedAccount account,
     ISwapClient swapClient,
     ICurrencies currencies)
     : base(account.Currency, swapClient, currencies)
 {
     _account            = account ?? throw new ArgumentNullException(nameof(account));
     _transactionFactory = new BitcoinBasedSwapTransactionFactory();
 }
Example #7
0
 public ERC20Swap(
     ERC20Account account,
     EthereumAccount ethereumAccount,
     ISwapClient swapClient,
     ICurrencies currencies)
     : base(account, swapClient, currencies)
 {
     EthereumAccount = ethereumAccount ?? throw new ArgumentNullException(nameof(account));
 }
Example #8
0
 protected CurrencySwap(
     string currency,
     ISwapClient swapClient,
     ICurrencies currencies)
 {
     Currency   = currency;
     SwapClient = swapClient ?? throw new ArgumentNullException(nameof(swapClient));
     Currencies = currencies ?? throw new ArgumentNullException(nameof(currencies));
 }
 protected CurrencySwap(
     Currency currency,
     IAccount account,
     ISwapClient swapClient,
     IBackgroundTaskPerformer taskPerformer)
 {
     Currency      = currency;
     Account       = account ?? throw new ArgumentNullException(nameof(account));
     SwapClient    = swapClient ?? throw new ArgumentNullException(nameof(swapClient));
     TaskPerformer = taskPerformer ?? throw new ArgumentNullException(nameof(taskPerformer));
 }
Example #10
0
 public TezosSwap(
     Currency currency,
     IAccount account,
     ISwapClient swapClient,
     IBackgroundTaskPerformer taskPerformer)
     : base(
         currency,
         account,
         swapClient,
         taskPerformer)
 {
 }
 public BitcoinBasedSwap(
     Currency currency,
     IAccount account,
     ISwapClient swapClient,
     IBackgroundTaskPerformer taskPerformer,
     IBitcoinBasedSwapTransactionFactory transactionFactory)
     : base(
         currency,
         account,
         swapClient,
         taskPerformer)
 {
     _transactionFactory = transactionFactory ??
                           throw new ArgumentNullException(nameof(transactionFactory));
 }
 public static ICurrencySwap Create(
     Currency currency,
     IAccount account,
     ISwapClient swapClient)
 {
     return(currency switch
     {
         BitcoinBasedCurrency _ => (ICurrencySwap) new BitcoinBasedSwap(
             account: account.GetCurrencyAccount <BitcoinBasedAccount>(currency.Name),
             swapClient: swapClient,
             currencies: account.Currencies),
         ERC20 _ => (ICurrencySwap) new ERC20Swap(
             account: account.GetCurrencyAccount <ERC20Account>(currency.Name),
             ethereumAccount: account.GetCurrencyAccount <EthereumAccount>("ETH"),
             swapClient: swapClient,
             currencies: account.Currencies),
         Atomex.Ethereum _ => (ICurrencySwap) new EthereumSwap(
             account: account.GetCurrencyAccount <EthereumAccount>(currency.Name),
             swapClient: swapClient,
             currencies: account.Currencies),
         NYX _ => (ICurrencySwap) new NYXSwap(
             account: account.GetCurrencyAccount <NYXAccount>(currency.Name),
             tezosAccount: account.GetCurrencyAccount <TezosAccount>("XTZ"),
             swapClient: swapClient,
             currencies: account.Currencies),
         FA2 _ => (ICurrencySwap) new FA2Swap(
             account: account.GetCurrencyAccount <FA2Account>(currency.Name),
             tezosAccount: account.GetCurrencyAccount <TezosAccount>("XTZ"),
             swapClient: swapClient,
             currencies: account.Currencies),
         FA12 _ => (ICurrencySwap) new FA12Swap(
             account: account.GetCurrencyAccount <FA12Account>(currency.Name),
             tezosAccount: account.GetCurrencyAccount <TezosAccount>("XTZ"),
             swapClient: swapClient,
             currencies: account.Currencies),
         Atomex.Tezos _ => (ICurrencySwap) new TezosSwap(
             account: account.GetCurrencyAccount <TezosAccount>(currency.Name),
             swapClient: swapClient,
             currencies: account.Currencies),
         _ => throw new NotSupportedException($"Not supported currency {currency.Name}"),
     });
Example #13
0
        public SwapManager(IAccount account, ISwapClient swapClient)
        {
            _account    = account ?? throw new ArgumentNullException(nameof(account));
            _swapClient = swapClient ?? throw new ArgumentNullException(nameof(swapClient));

            _currencySwaps = _account.Currencies
                             .Select(c =>
            {
                var currencySwap = CurrencySwapCreator.Create(
                    currency: c,
                    account: _account,
                    swapClient: swapClient);

                currencySwap.InitiatorPaymentConfirmed += InitiatorPaymentConfirmed;
                currencySwap.AcceptorPaymentConfirmed  += AcceptorPaymentConfirmed;
                currencySwap.AcceptorPaymentSpent      += AcceptorPaymentSpent;
                currencySwap.SwapUpdated += SwapUpdatedHandler;

                return(currencySwap);
            })
                             .ToDictionary(cs => cs.Currency);

            _semaphores = new ConcurrentDictionary <long, SemaphoreSlim>();
        }