-
Notifications
You must be signed in to change notification settings - Fork 22
Add NectarRepAllocation.sol #658
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,72 @@ | ||
| pragma solidity ^0.5.11; | ||
|
|
||
| import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | ||
|
|
||
|
|
||
| contract MiniMeToken { | ||
| function balanceOfAt(address _owner, uint _blockNumber) public view returns (uint); | ||
| function totalSupplyAt(uint _blockNumber) public view returns(uint); | ||
| } | ||
|
|
||
| /** | ||
| * @title NectarRepAllocation contract | ||
| * This contract should be use to calculate reputation allocation for nextar dao bootstrat | ||
| * this contract can be used as the rep mapping contract for RepitationFromToken contract. | ||
| */ | ||
|
|
||
| contract NectarRepAllocation { | ||
| using SafeMath for uint256; | ||
|
|
||
| uint256 public reputationReward; | ||
| uint256 public claimingStartTime; | ||
| uint256 public claimingEndTime; | ||
| uint256 public totalTokenSupplyAt; | ||
| uint256 public blockReference; | ||
| MiniMeToken public token; | ||
|
|
||
| /** | ||
| * @dev initialize | ||
| * @param _reputationReward the total reputation which will be used to calc the reward | ||
| * for the token locking | ||
| * @param _claimingStartTime claiming starting period time. | ||
| * @param _claimingEndTime the claiming end time. | ||
| * claiming is disable after this time. | ||
| * @param _blockReference the block nbumber reference which is used to takle the balance from. | ||
| * @param _token nectar token address | ||
| */ | ||
| function initialize( | ||
| uint256 _reputationReward, | ||
| uint256 _claimingStartTime, | ||
| uint256 _claimingEndTime, | ||
| uint256 _blockReference, | ||
| MiniMeToken _token) | ||
| external | ||
| { | ||
| require(token == MiniMeToken(0), "can be called only one time"); | ||
| require(_token != MiniMeToken(0), "token cannot be zero"); | ||
| token = _token; | ||
| reputationReward = _reputationReward; | ||
| claimingStartTime = _claimingStartTime; | ||
| claimingEndTime = _claimingEndTime; | ||
| blockReference = _blockReference; | ||
| if ((claimingStartTime != 0) || (claimingEndTime != 0)) { | ||
| require(claimingEndTime > claimingStartTime, "claimingStartTime > claimingEndTime"); | ||
| } | ||
| totalTokenSupplyAt = token.totalSupplyAt(_blockReference); | ||
| } | ||
|
|
||
| /** | ||
| * @dev get balanceOf _beneficiary function | ||
| * @param _beneficiary addresses | ||
| */ | ||
| function balanceOf(address _beneficiary) public view returns(uint256 reputation) { | ||
| if (((claimingStartTime != 0) || (claimingEndTime != 0)) && | ||
| // solhint-disable-next-line not-rely-on-time | ||
| ((now >= claimingEndTime) || (now < claimingStartTime))) { | ||
| reputation = 0; | ||
| } else { | ||
| reputation = token.balanceOfAt(_beneficiary, blockReference).mul(reputationReward).div(totalTokenSupplyAt); | ||
| } | ||
| } | ||
|
|
||
| } | ||
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,78 @@ | ||
| const helpers = require('./helpers'); | ||
| const NectarToken = artifacts.require('./Reputation.sol'); | ||
| var NectarRepAllocation = artifacts.require("./NectarRepAllocation.sol"); | ||
|
|
||
|
|
||
| const setup = async function (accounts, | ||
| _initialize = true, | ||
| _reputationReward = 100000, | ||
| _claimingStartTime = 0, | ||
| _claimingEndTime = (30*60*60*24) | ||
| ) { | ||
| var testSetup = new helpers.TestSetup(); | ||
| testSetup.nectarToken = await NectarToken.new(); | ||
| await testSetup.nectarToken.mint(accounts[0],100); | ||
| await testSetup.nectarToken.mint(accounts[1],200); | ||
| testSetup.blockReference = await web3.eth.getBlockNumber(); | ||
|
|
||
| await testSetup.nectarToken.mint(accounts[2],300); | ||
|
|
||
| testSetup.claimingStartTime = (await web3.eth.getBlock("latest")).timestamp + _claimingStartTime; | ||
| testSetup.claimingEndTime = (await web3.eth.getBlock("latest")).timestamp + _claimingEndTime; | ||
|
|
||
| testSetup.nectarRepAllocation = await NectarRepAllocation.new(); | ||
|
|
||
| testSetup.reputationReward = _reputationReward; | ||
| if (_initialize === true ) { | ||
| await testSetup.nectarRepAllocation.initialize( | ||
| testSetup.reputationReward, | ||
| testSetup.claimingStartTime, | ||
| testSetup.claimingEndTime, | ||
| testSetup.blockReference, | ||
| testSetup.nectarToken.address); | ||
| } | ||
|
|
||
| return testSetup; | ||
| }; | ||
|
|
||
| contract('NectarRepAllocation', accounts => { | ||
| it("initialize", async () => { | ||
| let testSetup = await setup(accounts); | ||
| assert.equal(await testSetup.nectarRepAllocation.claimingStartTime(),testSetup.claimingStartTime); | ||
| assert.equal(await testSetup.nectarRepAllocation.claimingEndTime(),testSetup.claimingEndTime); | ||
| assert.equal(await testSetup.nectarRepAllocation.blockReference(),testSetup.blockReference); | ||
| assert.equal(await testSetup.nectarRepAllocation.token(),testSetup.nectarToken.address); | ||
| }); | ||
|
|
||
| it("balanceOf", async () => { | ||
| let testSetup = await setup(accounts); | ||
| assert.equal(await testSetup.nectarRepAllocation.balanceOf(accounts[0]),Math.floor((100*testSetup.reputationReward)/300)); | ||
| assert.equal(await testSetup.nectarRepAllocation.balanceOf(accounts[1]),Math.floor((200*testSetup.reputationReward)/300)); | ||
| assert.equal(await testSetup.nectarRepAllocation.balanceOf(accounts[2]),0); | ||
|
|
||
| }); | ||
|
|
||
| it("cannot initialize twice", async () => { | ||
| let testSetup = await setup(accounts); | ||
| try { | ||
| await testSetup.nectarRepAllocation.initialize( | ||
| testSetup.reputationReward, | ||
| testSetup.claimingStartTime, | ||
| testSetup.claimingEndTime, | ||
| testSetup.blockReference, | ||
| testSetup.nectarToken.address); | ||
| assert(false, "cannot initialize twice"); | ||
|
|
||
| } catch(error) { | ||
| helpers.assertVMException(error); | ||
| } | ||
| }); | ||
|
|
||
| it("claim after end return 0", async () => { | ||
| let testSetup = await setup(accounts); | ||
| await helpers.increaseTime((30*60*60*24)+1); | ||
| assert.equal(await testSetup.nectarRepAllocation.balanceOf(accounts[0]),0); | ||
| }); | ||
|
|
||
|
|
||
| }); |
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
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.
This means I cannot have a start with no end, right?
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.
right.
though you can have end time without start time.