-
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
base: master
Are you sure you want to change the base?
Changes from 10 commits
031944f
3217530
781b754
e40a538
e163ddb
9bb1ec7
e0a9000
bebad79
d25c5c0
ea90652
c1fe353
3df86c7
eacfb21
439e57d
c1af205
d24e986
92dca28
cc165bc
6d3ff56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /* 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 refferalAmount; | ||
|
|
||
|
|
||
| /// @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 _refferalAmount) 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(_refferalAmount != 0,"Cannot be zero referral amount"); | ||
| require(_budget >= _refferalAmount,"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; | ||
| refferalAmount = _refferalAmount; | ||
| 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 users to claim their allocated tokens. | ||
| * user should claim before end date. | ||
| */ | ||
| function claim(bytes calldata hash, uint8 v, bytes32 r, bytes32 s) external { | ||
| require(endDate > now, "Callable only before end date"); | ||
| require(!userClaimed[msg.sender], "Already claimed"); | ||
| require(msg.sender == abi.decode(hash, (address))); | ||
|
||
| require(isValidSignature(hash, v, r, s)); | ||
| userClaimed[msg.sender] = true; | ||
| bLotToken.mint(msg.sender, refferalAmount); | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a function to update signer address |
||
| /** | ||
| * @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; | ||
| } | ||
|
|
||
| } | ||
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.
indentation
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.
Fixed