Ejemplo n.º 1
0
        public async Task <IStake> GetStakeAsync(Symbol stakeSymbol, CurrencyCode currencyCode)
        {
            var stakeInfo = GetStakeInfo(stakeSymbol);

            var stakePower = await stakingPowerRepository.GetLatestAsync(stakeInfo.ContractAddress);

            var tokenInfo = await ethplorerClient.GetTokenInfoAsync(stakeInfo.ContractAddress);

            var tokenPair = await graphClient.GetUniswapPairAsync(stakeInfo.PoolAddress);

            var circulatingSupply = tokenInfo.TotalSupply.FromBigInteger(int.Parse(tokenInfo.Decimals));
            var token             = tokenPair.Tokens
                                    .Single(x => x.Symbol.Equals(stakeInfo.Symbol.ToString(), StringComparison.OrdinalIgnoreCase));

            var now = DateTime.UtcNow;

            var priceHistory = await fundService.ListPerformanceAsync(stakeSymbol, PriceMode.Raw, now.AddDays(-29), now, currencyCode)
                               .ToListAsync(CancellationToken);

            var dailyNavs  = priceHistory.TakeLast(2);
            var weeklyNavs = priceHistory.TakeLast(8);

            return(new BusinessStake()
            {
                Name = stakeInfo.Name,
                Category = stakeInfo.Category,
                Description = stakeInfo.Description,
                InvictusUri = stakeInfo.Links.External,
                FactSheetUri = stakeInfo.Links.Fact,
                PoolUri = new Uri(string.Format(PoolTemplate, stakeInfo.PoolAddress), UriKind.Absolute),
                Token = new BusinessToken()
                {
                    Symbol = stakeInfo.Symbol,
                    ContractAddress = stakeInfo.ContractAddress,
                    Decimals = stakeInfo.Decimals
                },
                CirculatingSupply = circulatingSupply,
                Market = new BusinessMarket()
                {
                    IsTradable = true,
                    Cap = CurrencyConverter.Convert(priceHistory.Last().MarketCap.Value, currencyCode),
                    PricePerToken = CurrencyConverter.Convert(token.PricePerToken, currencyCode),
                    Total = CurrencyConverter.Convert(circulatingSupply * token.PricePerToken, currencyCode),
                    DiffDaily = dailyNavs.First().MarketAssetValuePerToken.Value.PercentageDiff(dailyNavs.Last().MarketAssetValuePerToken.Value),
                    DiffWeekly = weeklyNavs.First().MarketAssetValuePerToken.Value.PercentageDiff(weeklyNavs.Last().MarketAssetValuePerToken.Value),
                    DiffMonthly = priceHistory.First().MarketAssetValuePerToken.Value.PercentageDiff(priceHistory.Last().MarketAssetValuePerToken.Value),
                    Volume = CurrencyConverter.Convert(tokenPair.Volume, currencyCode),
                    VolumeDiffDaily = dailyNavs.First().Volume.Value.PercentageDiff(dailyNavs.Last().Volume.Value),
                    VolumeDiffWeekly = weeklyNavs.First().Volume.Value.PercentageDiff(weeklyNavs.Last().Volume.Value),
                    VolumeDiffMonthly = priceHistory.First().Volume.Value.PercentageDiff(priceHistory.Last().Volume.Value),
                },
                StakingAddress = stakeInfo.StakingAddress,
                FundMultipliers = stakeInfo.FundMultipliers,
                TimeMultipliers = stakeInfo.TimeMultipliers
                                  .Select(tm => new BusinessTimeMultiplier()
                {
                    RangeMin = tm.RangeMin,
                    RangeMax = tm.RangeMax,
                    Multiplier = tm.Multiplier
                })
                                  .ToList(),
                Power = MapStakingPower(stakeInfo, stakePower, currencyCode)
            });
        }