Example #1
0
        public static async Task <decimal> CornPrice(BitcornContext dbContext)
        {
            var cornPrice = dbContext.Price.FirstOrDefault(p => p.Symbol == "CORN");

            try
            {
                if (cornPrice == null)
                {
                    var price = new Price();
                    price.Symbol      = "CORN";
                    price.LatestPrice = (await ProbitApi.GetCornPriceAsync(dbContext));
                    dbContext.Price.Add(price);
                    await dbContext.SaveAsync();

                    return(price.LatestPrice);
                }

                cornPrice.LatestPrice = (await ProbitApi.GetCornPriceAsync(dbContext));
                await dbContext.SaveAsync();
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(dbContext, e, null);
            }
            return(cornPrice.LatestPrice);
        }
Example #2
0
        public static async Task BonusPayout(BitcornContext dbContext, UserReferral userReferral, Referrer referrer, User user, User referrerUser,
                                             UserStat referrerStat)
        {
            if (userReferral != null &&
                userReferral.SignupReward != null &&
                userReferral.MinimumBalanceDate != null &&
                userReferral.WalletDownloadDate != null &&
                userReferral.SyncDate != null &&
                userReferral.Bonus == null &&
                userReferral.ReferrerBonus == null &&
                userReferral.UserSubscriptionId == null &&
                referrer != null &&
                !user.IsBanned &&
                !referrerUser.IsBanned)
            {
                var subQuery = SubscriptionUtils.GetActiveSubscription(dbContext, user, "BITCORNFarms", 1);
                if (subQuery == null)
                {
                    return;
                }

                var userSubInfo = await subQuery.FirstOrDefaultAsync();

                if (userSubInfo == null)
                {
                    return;
                }

                userReferral.UserSubscriptionId = userSubInfo.UserSubcriptionTierInfo.UserSubscription.UserSubscriptionId;

                var amount      = BONUS_PAYOUT;
                var bonusReward = await TxUtils.SendFromBitcornhub(user, amount, "BITCORNFarms", "Referral bonus reward", dbContext);

                if (IsValidReferrer(referrer))
                {
                    if (bonusReward)
                    {
                        userReferral.Bonus = DateTime.Now;
                        await LogReferralTx(dbContext, user.UserId, amount, "Recruit bonus reward");

                        var referrerBonusReward = await TxUtils.SendFromBitcornhub(referrerUser, amount, "BITCORNFarms", "Referral bonus reward", dbContext);

                        if (referrerBonusReward)
                        {
                            await UpdateYtdTotal(dbContext, referrer, amount);
                            await LogReferralTx(dbContext, referrerUser.UserId, amount, "Referral bonus reward");

                            referrerStat.TotalReferralRewardsCorn += amount;
                            referrerStat.TotalReferralRewardsUsdt += (amount * await ProbitApi.GetCornPriceAsync(dbContext));
                            userReferral.ReferrerBonus             = DateTime.Now;
                        }
                    }
                }
            }
        }
        static async Task <bool> ShareSubscriptionPaymentWithReferrer(BitcornContext dbContext,
                                                                      Subscription subInfo,
                                                                      decimal cost,
                                                                      SubTx subTx,
                                                                      Referrer referrer,
                                                                      User referrerUser,
                                                                      User subscriptionPaymentRecipient)
        {
            if (referrer.EnableSubscriptionRewards)
            {
                //get referrer user info
                if (!subInfo.RestrictReferralRewards || (subInfo.RestrictReferralRewards && (referrerUser.Level == "BEST" ||
                                                                                             referrerUser.Level == "BAIT" ||
                                                                                             referrerUser.IsAdmin() ||
                                                                                             referrer.Tier >= 3)))
                {
                    //calculate amount that will be sent to the referrer
                    var referralShare = cost * subInfo.ReferrerPercentage.Value;
                    //prepare transaction to the referrer
                    var referralShareTx = await TxUtils.PrepareTransaction(subscriptionPaymentRecipient, referrerUser, referralShare, "BITCORNFarms", "$sub referral share", dbContext);

                    //make sure stat tracking values have been initialized
                    if (referrerUser.UserStat.TotalReferralRewardsCorn == null)
                    {
                        referrerUser.UserStat.TotalReferralRewardsCorn = 0;
                    }
                    //make sure stat tracking values have been initialized
                    if (referrerUser.UserStat.TotalReferralRewardsUsdt == null)
                    {
                        referrerUser.UserStat.TotalReferralRewardsUsdt = 0;
                    }
                    //increment total received corn rewards
                    referrerUser.UserStat.TotalReferralRewardsCorn += referralShare;
                    //inceremnt total received usdt rewards
                    referrerUser.UserStat.TotalReferralRewardsUsdt +=
                        ((referralShare) * (await ProbitApi.GetCornPriceAsync(dbContext)));
                    //execute transaction
                    if (await TxUtils.ExecuteTransaction(referralShareTx, dbContext))
                    {
                        //if transaction was made, log & update ytd total
                        await ReferralUtils.UpdateYtdTotal(dbContext, referrer, referralShare);

                        var referralTx = await ReferralUtils.LogReferralTx(dbContext, referrerUser.UserId, referralShare, "$sub referral share");

                        subTx.ReferralTxId = referralTx.ReferralTxId;
                        await dbContext.SaveAsync();

                        return(true);
                    }
                }
            }
            return(false);
        }
Example #4
0
        public static async Task ReferralRewards(BitcornContext dbContext, WalletDownload walletDownload, UserReferral userReferral, User referrerUser,
                                                 User user, string type)
        {
            if (user.IsBanned || referrerUser.IsBanned)
            {
                return;
            }

            var referrer = await dbContext.Referrer
                           .FirstOrDefaultAsync(w => w.UserId == walletDownload.ReferralUserId);

            userReferral.WalletDownloadDate = DateTime.Now;

            if (IsValidReferrer(referrer))
            {
                var referralPayoutTotal = await ReferralUtils.TotalReward(dbContext, referrer) + await ReferralUtils.WalletBonusReward(dbContext, referrer, 10);;
                var referrerReward      = await TxUtils.SendFromBitcornhub(referrerUser, referralPayoutTotal, "BITCORNFarms",
                                                                           type, dbContext);

                var referreeReward = await TxUtils.SendFromBitcornhub(user, referrer.Amount + 10, "BITCORNFarms",
                                                                      type, dbContext);

                if (referrerReward && referreeReward)
                {
                    await ReferralUtils.LogReferralTx(dbContext, referrerUser.UserId, referralPayoutTotal,
                                                      type);

                    await ReferralUtils.LogReferralTx(dbContext, user.UserId, referrer.Amount + 10,
                                                      $"Recruit {type}");

                    await ReferralUtils.UpdateYtdTotal(dbContext, referrer, referralPayoutTotal);

                    if (referrerUser.UserStat.TotalReferralRewardsCorn == null)
                    {
                        referrerUser.UserStat.TotalReferralRewardsCorn = 0;
                    }
                    if (referrerUser.UserStat.TotalReferralRewardsUsdt == null)
                    {
                        referrerUser.UserStat.TotalReferralRewardsUsdt = 0;
                    }
                    referrerUser.UserStat.TotalReferralRewardsCorn += referralPayoutTotal;
                    referrerUser.UserStat.TotalReferralRewardsUsdt +=
                        ((referralPayoutTotal) * (await ProbitApi.GetCornPriceAsync(dbContext)));
                    userReferral.WalletDownloadDate = DateTime.Now;
                    await ReferralUtils.BonusPayout(dbContext, userReferral, referrer, user, referrerUser,
                                                    referrerUser.UserStat);
                }
            }
        }
Example #5
0
        public static async Task UpdateReferralSync(BitcornContext dbContext, PlatformId platformId)
        {
            var user = BitcornUtils.GetUserForPlatform(platformId, dbContext).FirstOrDefault();

            try
            {
                if (user != null && user.UserId != 0)
                {
                    if (user.IsBanned)
                    {
                        return;
                    }
                    if (!UserLockCollection.Lock(user.UserId))
                    {
                        throw new Exception("User is locked");
                    }

                    var userReferral = await dbContext.UserReferral.FirstOrDefaultAsync(u => u.UserId == user.UserId);

                    if (userReferral != null && userReferral.SyncDate == null)
                    {
                        var referrer = await
                                       dbContext.Referrer.FirstOrDefaultAsync(r => r.ReferralId == userReferral.ReferralId);

                        if (referrer != null && (referrer.YtdTotal < 600 || (referrer.ETag != null && referrer.Key != null)))
                        {
                            var referralPayoutTotal = await ReferralUtils.TotalReward(dbContext, referrer);

                            var referrerUser = await dbContext.User.FirstOrDefaultAsync(u => u.UserId == referrer.UserId);

                            if (referrerUser.IsBanned)
                            {
                                if (user != null)
                                {
                                    UserLockCollection.Release(user.UserId);
                                }
                                return;
                            }
                            var referreeReward = await TxUtils.SendFromBitcornhub(user, referrer.Amount, "BITCORNfarms", "Recruit social sync", dbContext);

                            var referrerReward = await TxUtils.SendFromBitcornhub(referrerUser, referralPayoutTotal, "BITCORNfarms", "Social sync", dbContext);

                            if (referrerReward && referreeReward)
                            {
                                userReferral.SyncDate = DateTime.Now;
                                await UpdateYtdTotal(dbContext, referrer, referralPayoutTotal);
                                await LogReferralTx(dbContext, referrer.UserId, referralPayoutTotal, "Social Sync");
                                await LogReferralTx(dbContext, user.UserId, referralPayoutTotal, "Recruit social Sync");

                                var userStat = await dbContext.UserStat.FirstOrDefaultAsync(s => s.UserId == referrer.UserId);

                                userStat.TotalReferralRewardsCorn += referralPayoutTotal;
                                userStat.TotalReferralRewardsUsdt += (referralPayoutTotal * (await ProbitApi.GetCornPriceAsync(dbContext)));
                                await ReferralUtils.BonusPayout(dbContext, userReferral, referrer, user, referrerUser, userStat);
                            }
                        }
                    }

                    await dbContext.SaveAsync();
                }
            }
            catch (Exception e)
            {
                await BITCORNLogger.LogError(dbContext, e, null);

                throw;
            }
            finally
            {
                if (user != null)
                {
                    UserLockCollection.Release(user.UserId);
                }
            }
        }
Example #6
0
 public static async Task UpdateYtdTotal(BitcornContext dbContext, Referrer referrer, decimal amount)
 {
     referrer.YtdTotal += (amount * (await ProbitApi.GetCornPriceAsync(dbContext)));
     await dbContext.SaveAsync();
 }
        public static async Task <decimal> CalculateUsdtToCornCost(BitcornContext dbContext, SubscriptionTier tier)
        {
            var price = await ProbitApi.GetCornPriceAsync(dbContext);

            return(CalculateUsdtToCornCost(price, tier));
        }