Esempio n. 1
0
 /**
  * @param array|TransactionListResult[] $transactions
  * @return Deposit[]
  */
 public function saveNewDeposits(array $transactions)
 {
     $deposits = [];
     foreach ($transactions as $transaction) {
         $this->round->getStats()->setLastCheckedTx($transaction->getTxId());
         if ($account = $this->accountRepo->findOneBy(['depositAddress' => $transaction->getAddress(), 'round' => $this->round])) {
             /* @var $account Account */
             if ($transaction->getAmount() < $this->round->getMinDeposit()) {
                 $this->round->getStats()->addTotalDonation($transaction->getAmount());
                 continue;
             }
             $amount = min($this->round->getMaxDeposit(), $transaction->getAmount());
             $donation = $transaction->getAmount() - $amount;
             if ($donation) {
                 $this->round->getStats()->addTotalDonation($donation);
             }
             $deposit = $deposits[] = new Deposit();
             $deposit->setAmount($amount);
             $deposit->setConfirmations($transaction->getConfirmations());
             $deposit->setReceivedTime($transaction->getTime());
             if ($deposit->getConfirmations() >= $this->round->getMinConfirmations()) {
                 $deposit->setConfirmed(true);
             }
             $deposit->setTxIn($transaction->getTxId());
             $deposit->setAccount($account);
             $this->payoutManager->createPayout($deposit);
             $this->em->persist($deposit);
             $this->em->flush();
         }
     }
     $this->em->flush();
     return $deposits;
 }
Esempio n. 2
0
 private function checkRoundEnd()
 {
     $time1 = new \DateTime();
     $time1->modify('-' . $this->round->getRoundTime() . ' hours');
     if ($this->round->getRoundTimeType() == Round::ROUND_TIME_TYPE_LAST_DEPOSIT) {
         $time2 = $this->round->getStats()->getLastDeposit();
     } else {
         $time2 = $this->round->getStats()->getLastPayout();
     }
     if ($time2 && $time1 > $time2) {
         $this->writeln('Round finished');
         $this->payoutManager->realiseRoundEndPayouts();
         $this->roundManager->startNextRound();
     } else {
         $this->writeln('Round not finished');
     }
 }
Esempio n. 3
0
 public function realiseRoundEndPayouts()
 {
     // last deposit
     $balance = $this->round->getStats()->getBalance();
     if (!$balance) {
         return;
     }
     $lastPayoutPercent = $this->round->getLastPayoutPercent();
     $payoutsToRealise = [];
     if ($lastPayoutPercent > 0) {
         $lastDeposit = $this->depositRepo->findOneBy(['round' => $this->round->getId()], ['id' => 'desc']);
         $payout = $payoutsToRealise[] = $lastDeposit->getDefaultPayout();
         $amount = $lastDeposit->getAmount() * $lastPayoutPercent / 100;
         $payout->setExpectedAmount($amount);
         if ($amount > $balance) {
             $amount = $balance;
         }
         $payout->setAmount($amount);
         $payout->setFee($payout->getAmount() * $this->round->getPayoutFeePercent() / 100);
         $payout->setType(Payout::TYPE_LAST_PAYOUT);
         $payout->setReadyForPayout(true);
         $this->em->persist($payout);
         $this->em->flush();
         $balance -= $payout->getAmount() + $payout->getFee();
     }
     if ($balance > 0) {
         // admin last payout
         $adminLastPayoutPercent = $this->round->getAdminLastPayoutPercent();
         if ($adminLastPayoutPercent > 0) {
             $payout = new Payout();
             $amount = $balance * $adminLastPayoutPercent / 100;
             $payout->setExpectedAmount($amount);
             if ($amount > $balance) {
                 $amount = $balance;
             }
             $payout->setAmount($amount);
             $payout->setFee(0);
             $payout->setType(Payout::TYPE_LAST_ADMIN_PAYOUT);
             $payout->setReadyForPayout(true);
             $this->em->persist($payout);
             $this->em->flush();
             $payout->setPaid(true);
             // not sending it will simply stay on the wallet account for later manual withdrawal
             $this->em->flush();
             $balance -= $payout->getAmount() + $payout->getFee();
         }
     }
     // remaining payouts
     $payouts = $this->payoutRepo->findForPayout($this->round, 'desc');
     $payoutPercent = $this->round->getRoundEndRemainingReturnPercent();
     foreach ($payouts as $payout) {
         if ($payout->isLastPayout()) {
             // already in $payoutsToRealise array
             continue;
         }
         if ($balance > 0) {
             $amount = $payout->getDeposit()->getAmount() * $payoutPercent / 100;
             $payout->isReferrerPayout() && ($amount = $amount * $this->round->getReferrerPayoutPercent() / 100);
             $payout->setExpectedAmount($amount);
             if ($amount > $balance) {
                 $amount = $balance;
             }
             $payout->setAmount($amount);
             $payout->setFee($payout->getAmount() * $this->round->getPayoutFeePercent() / 100);
             $payoutsToRealise[] = $payout;
             $balance -= $payout->getAmount() + $payout->getFee();
         }
     }
     $this->_realisePayouts($payoutsToRealise);
     $this->em->flush();
 }