Skip to content

Commit

Permalink
Stupid Raffle Update & PolyFarm Fee
Browse files Browse the repository at this point in the history
  • Loading branch information
sudiptab2100 committed Jun 23, 2021
1 parent bd139a7 commit b43e080
Show file tree
Hide file tree
Showing 17 changed files with 38,655 additions and 42,347 deletions.
24,753 changes: 6,095 additions & 18,658 deletions build/contracts/IDO.json

Large diffs are not rendered by default.

242 changes: 121 additions & 121 deletions build/contracts/IStaker.json

Large diffs are not rendered by default.

11,071 changes: 5,943 additions & 5,128 deletions build/contracts/PolyFarm.json

Large diffs are not rendered by default.

16,568 changes: 9,252 additions & 7,316 deletions build/contracts/RaffleWrap.json

Large diffs are not rendered by default.

11,747 changes: 6,029 additions & 5,718 deletions build/contracts/RaffleWrapTest.json

Large diffs are not rendered by default.

8,692 changes: 5,254 additions & 3,438 deletions build/contracts/Random.json

Large diffs are not rendered by default.

4,164 changes: 2,203 additions & 1,961 deletions build/contracts/RandomTest.json

Large diffs are not rendered by default.

455 changes: 455 additions & 0 deletions contracts/FlattendContracts/PolCoin.sol

Large diffs are not rendered by default.

1,038 changes: 1,038 additions & 0 deletions contracts/FlattendContracts/PolyFarm.sol

Large diffs are not rendered by default.

1,068 changes: 1,068 additions & 0 deletions contracts/FlattendContracts/RaffleWrap.sol

Large diffs are not rendered by default.

693 changes: 693 additions & 0 deletions contracts/FlattendContracts/Staker.sol

Large diffs are not rendered by default.

455 changes: 455 additions & 0 deletions contracts/FlattendContracts/TestToken.sol

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions contracts/IDOStaker/IDO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract IDO is Ownable, ReentrancyGuard {
abstract contract IDO is Ownable, ReentrancyGuard {

IStaker public iStaker;
IERC20Metadata public nativeToken; // The token staked
Expand Down Expand Up @@ -35,6 +35,7 @@ contract IDO is Ownable, ReentrancyGuard {
bool purchased;
}
mapping(address => UserLog) public userlog;
address[] public participantList;

bool public isInitialized;

Expand Down Expand Up @@ -131,6 +132,7 @@ contract IDO is Ownable, ReentrancyGuard {
userlog[account].registeredPool = _poolNo;
pools[_poolNo].participants += 1;

participantList.push(account);

emit Registration(msg.sender, _poolNo);
}
Expand All @@ -139,6 +141,10 @@ contract IDO is Ownable, ReentrancyGuard {
return userlog[account].registeredPool;
}

function noOfParticipants() public view returns(uint256) {
return participantList.length;
}

function getRegistrationStatus(address account) public view returns(bool) {
return userlog[account].isRegistered;
}
Expand All @@ -157,12 +163,23 @@ contract IDO is Ownable, ReentrancyGuard {
return (tokenAmount, price);
}

function allocationByAddress(address account) public view returns(uint256 tokens, uint256 price) {
(tokens, price) = tokensAndPriceByPoolNo(userlog[account].registeredPool); // Normal Allocation
(uint256 rTokens, uint256 rPrice) = _raffleAllocation(account); // Raffle Allocation

tokens += rTokens;
price += rPrice;
}

// This will be implemented in RaffleWrap
function _raffleAllocation(address account) internal view virtual returns(uint256 tokens, uint256 price);

function buyNow() external
payable
validSale
nonReentrant {
UserLog storage usr = userlog[msg.sender];
(uint256 amount, uint256 price) = tokensAndPriceByPoolNo(usr.registeredPool);
(uint256 amount, uint256 price) = allocationByAddress(msg.sender);
require(price != 0 && amount != 0, "Values Can't Be Zero");
require(price == msg.value, "Not Valid Eth Amount");

Expand Down
24 changes: 21 additions & 3 deletions contracts/IDOStaker/RaffleWrap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ contract RaffleWrap is IDO, Random {
mapping(uint256 => address) public ticketToOwner; // owner of a ticket
mapping(address => uint256) public addressToTicketCount; // No Of Tickets Owned By an Address
mapping(address => uint256[]) public addressToTicketsOwned; // Tickets That an address own
mapping(address => bool) public hasWonRaffle;

uint256 public ticketPrice = 3 * 10 ** 18; // Price of a ticket(no. of tokens)
uint256 public constant RAFFLE_POOL = 2;
uint256 public constant ticketPrice = 3 * 10 ** 18; // Price of a ticket(no. of tokens)

modifier raffleParticipationPeriod() {
require(regStarts <= block.timestamp, "Raffle: Participation Didn't Begin");
Expand Down Expand Up @@ -126,7 +128,7 @@ contract RaffleWrap is IDO, Random {

// Buy Tickets
function buyTickets(uint256 _noOfTickets) external raffleParticipationPeriod nonReentrant {
require(!getRegistrationStatus(msg.sender), "Already Participated In IDO");
require(isRaffleEligible(msg.sender), "Already Participated In IDO");
uint256 nextTicket = ticketsSold;
nativeToken.transferFrom(msg.sender, owner(), _noOfTickets * ticketPrice);

Expand All @@ -139,6 +141,18 @@ contract RaffleWrap is IDO, Random {
ticketsSold += _noOfTickets;
}

// Check if Account Is Eligible For Raffle Or Not
function isRaffleEligible(address account) public view returns(bool) {
return !getRegistrationStatus(account) || getPoolNo(account) != RAFFLE_POOL;
}

function _raffleAllocation(address account) internal view override returns(uint256 tokens, uint256 price) {
tokens = price = 0;
if(hasWonRaffle[account]) {
(tokens, price) = tokensAndPriceByPoolNo(RAFFLE_POOL);
}
}

// Generates The Random Winners
function genRandom() external once raffleResultPeriod nonReentrant {
uint256 seed = uint256(keccak256(abi.encodePacked(msg.sender)));
Expand All @@ -157,9 +171,13 @@ contract RaffleWrap is IDO, Random {
address[] memory list = _getWinners();
for(uint256 i=0; i<list.length; i++) {
address account = list[i];
uint256 _poolNo = 2; // Raffle Entry Pool
uint256 _poolNo = RAFFLE_POOL; // Raffle Entry Pool

if(!getRegistrationStatus(account)) _register(account, _poolNo);
else if(getPoolNo(account) != RAFFLE_POOL) {
hasWonRaffle[account] = true;
pools[_poolNo].participants++;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions contracts/IDOStaker/RaffleWrapTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ contract RaffleWrapTest is IDO, RandomTest {
ticketsSold += _noOfTickets;
}

function _raffleAllocation(address account) internal view override returns(uint256 tokens, uint256 price) {

}

// Generates The Random Winners
function genRandom() external once raffleResultPeriod nonReentrant {
uint256 seed = uint256(keccak256(abi.encodePacked(msg.sender)));
Expand Down
5 changes: 4 additions & 1 deletion contracts/StakingFarm/PolyFarm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ contract PolyFarm is ReentrancyGuard, Pausable, Ownable {
uint256 public rewardsDuration = 30 days;
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;
uint256 public feePercentage = 10;

mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;
Expand Down Expand Up @@ -121,9 +122,11 @@ contract PolyFarm is ReentrancyGuard, Pausable, Ownable {

function getReward() public nonReentrant updateReward(msg.sender) {
uint256 reward = rewards[msg.sender];
uint256 fee = reward.mul(feePercentage).div(100);
if (reward > 0) {
rewards[msg.sender] = 0;
rewardsToken.safeTransfer(msg.sender, reward);
rewardsToken.safeTransfer(owner(), reward.sub(fee));
rewardsToken.safeTransfer(msg.sender, reward.sub(fee));
emit RewardPaid(msg.sender, reward);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/2-ido-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ chai.use(require('chai-as-promised'))
const PolCoin = artifacts.require("PolCoin")
const TestToken = artifacts.require("TestToken")
const Staker = artifacts.require("Staker")
const IDO = artifacts.require("IDO")
const IDO = artifacts.require("RaffleWrapTest")

function timeout(s) {
return new Promise(resolve => setTimeout(resolve, s * 1000));
Expand Down

0 comments on commit b43e080

Please sign in to comment.