-
Notifications
You must be signed in to change notification settings - Fork 10
Feature/refferal contract #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
udkreddySomish
wants to merge
19
commits into
master
Choose a base branch
from
feature/refferalContract
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
031944f
Added contract for refferal rewards
udkreddySomish 3217530
Corrected function signature
udkreddySomish 781b754
Set default referral amount
udkreddySomish e40a538
Added LICENSE header for refferal contract
udkreddySomish e163ddb
Added check that provided hash must be of senders
udkreddySomish 9bb1ec7
Added testcases for refferal contract
udkreddySomish e0a9000
Renamed contract
udkreddySomish bebad79
Added zero value checks
udkreddySomish d25c5c0
Renamed contract
udkreddySomish ea90652
Corrected check
udkreddySomish c1fe353
Added assert for referral amount
udkreddySomish 3df86c7
Corrected indentation
udkreddySomish eacfb21
Added function to update signer address
udkreddySomish 439e57d
Removed message hash argument from claim function
udkreddySomish c1af205
Removed commented code
udkreddySomish d24e986
Minor corrections
udkreddySomish 92dca28
Added function to end camapaign earlier
udkreddySomish cc165bc
Updated test cases
udkreddySomish 6d3ff56
Added ReferralV2 contract
udkreddySomish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* Copyright (C) 2020 PlotX.io | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see http://www.gnu.org/licenses/ */ | ||
|
||
pragma solidity 0.5.7; | ||
|
||
import "./PlotXToken.sol"; | ||
import "./external/openzeppelin-solidity/math/SafeMath.sol"; | ||
import "./external/openzeppelin-solidity/token/ERC20/ERC20.sol"; | ||
|
||
interface IbLOTToken { | ||
function mint(address account, uint256 amount) external returns (bool); | ||
} | ||
|
||
contract Referral { | ||
|
||
using SafeMath for uint256; | ||
IbLOTToken bLotToken; | ||
PlotXToken public plotToken; | ||
address public owner; | ||
address public signer; | ||
uint public endDate; | ||
uint public remainingbudget; | ||
uint public referralAmount; | ||
|
||
|
||
/// @dev mapping to maintain if user have claimed or not | ||
mapping(address => bool) public userClaimed; | ||
|
||
/** | ||
* @dev modifier that allows only the owner to execute the function | ||
*/ | ||
modifier onlyOwner() { | ||
require(owner == msg.sender, "Not owner"); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Constructor | ||
* @param _plotToken The address of plot token | ||
* @param _bLotToken The address of BLot token | ||
* @param _endDate user can claim thier allocated amounts before this time. | ||
* @param _budget total amount of BLot to be minted | ||
*/ | ||
constructor(address _plotToken, address _bLotToken, address _signer, uint _endDate, uint _budget, uint _referralAmount) public | ||
{ | ||
require(_plotToken != address(0),"Cannot be null address"); | ||
require(_bLotToken != address(0),"Cannot be null address"); | ||
require(_signer != address(0),"Cannot be null address"); | ||
require(_referralAmount != 0,"Cannot be zero referral amount"); | ||
require(_budget >= _referralAmount,"Cannot be less than referral amount"); | ||
require(_endDate > now,"End date cannot be past time"); | ||
plotToken = PlotXToken(_plotToken); | ||
bLotToken = IbLOTToken(_bLotToken); | ||
owner = msg.sender; | ||
signer = _signer; | ||
endDate = _endDate; | ||
remainingbudget = _budget; | ||
referralAmount = _referralAmount; | ||
plotToken.approve(address(bLotToken), _budget); | ||
} | ||
|
||
/** | ||
* @dev Allows owner to take back left over plot token after end date. | ||
*/ | ||
function takeLeftOverPlot() external onlyOwner { | ||
require(endDate <= now, "Callable only after end date"); | ||
plotToken.transfer(owner, plotToken.balanceOf(address(this))); | ||
} | ||
|
||
/** | ||
* @dev Allows owner to end the referral program and take back left over plot token. | ||
*/ | ||
function endReferralCampaign() external onlyOwner { | ||
endDate = now; | ||
plotToken.transfer(owner, plotToken.balanceOf(address(this))); | ||
} | ||
|
||
/** | ||
* @dev Allows users to claim their allocated tokens. | ||
* user should claim before end date. | ||
*/ | ||
function claim(uint8 v, bytes32 r, bytes32 s) external { | ||
require(endDate > now, "Callable only before end date"); | ||
require(!userClaimed[msg.sender], "Already claimed"); | ||
bytes memory hash = abi.encode(msg.sender); | ||
require(isValidSignature(hash, v, r, s)); | ||
userClaimed[msg.sender] = true; | ||
bLotToken.mint(msg.sender, referralAmount); | ||
} | ||
|
||
/** | ||
* @dev Verifies signature. | ||
* @param hash order hash | ||
* @param v argument from vrs hash. | ||
* @param r argument from vrs hash. | ||
* @param s argument from vrs hash. | ||
*/ | ||
function isValidSignature(bytes memory hash, uint8 v, bytes32 r, bytes32 s) public view returns(bool) { | ||
bytes memory prefix = "\x19Ethereum Signed Message:\n32"; | ||
bytes32 prefixedHash = keccak256(abi.encodePacked(prefix, hash)); | ||
address _signer = ecrecover(prefixedHash, v, r, s); | ||
return (_signer == signer); | ||
} | ||
|
||
/** | ||
* @dev Allows owner to transfer ownership to other address. | ||
* @param _newOwner new owner address | ||
*/ | ||
function tranferOwnership(address _newOwner) external onlyOwner { | ||
require(_newOwner != address(0), "Can not be null address"); | ||
owner = _newOwner; | ||
} | ||
|
||
/** | ||
* @dev Allows owner to update the signer address. | ||
* @param _newSigner new signer address | ||
*/ | ||
function updateSigner(address _newSigner) external onlyOwner { | ||
require(_newSigner != address(0), "Can not be null address"); | ||
signer = _newSigner; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* Copyright (C) 2020 PlotX.io | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see http://www.gnu.org/licenses/ */ | ||
|
||
pragma solidity 0.5.7; | ||
|
||
import "./Referral.sol"; | ||
|
||
contract ReferralV2 is Referral { | ||
|
||
Referral public referralV1; | ||
|
||
/** | ||
* @dev Constructor | ||
* @param _plotToken The address of PLOT token | ||
* @param _bLotToken The address of BPlot token | ||
* @param _endDate user can claim thier allocated amounts before this time. | ||
* @param _budget total amount of BLot to be minted | ||
*/ | ||
constructor(address _plotToken, address _bLotToken, address _signer, uint _endDate, uint _budget, uint _referralAmount, address _referralV1Address) public | ||
Referral(_plotToken, _bLotToken, _signer, _endDate, _budget, _referralAmount){ | ||
referralV1 = Referral(_referralV1Address); | ||
} | ||
|
||
/** | ||
* @dev Allows users to claim their allocated tokens. | ||
* user should claim before end date. | ||
*/ | ||
function claim(uint8 v, bytes32 r, bytes32 s) external { | ||
require(endDate > now, "Callable only before end date"); | ||
require(!userClaimed[msg.sender] && !referralV1.userClaimed(msg.sender), "Already claimed"); | ||
bytes memory hash = abi.encode(msg.sender); | ||
require(isValidSignature(hash, v, r, s)); | ||
userClaimed[msg.sender] = true; | ||
bLotToken.mint(msg.sender, referralAmount); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest adding a function to change the signer in case the signer gets compromised or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a function to update signer address