Skip to content

Commit

Permalink
Merge pull request #7 from relevant-community/update/minor
Browse files Browse the repository at this point in the history
minor update
  • Loading branch information
balasan authored Nov 7, 2019
2 parents fa37766 + d5dc422 commit 0b0bcc9
Show file tree
Hide file tree
Showing 12 changed files with 975 additions and 152 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
# truffle build directory
build/

# local env variables
.env
Expand Down
11 changes: 6 additions & 5 deletions contracts/RelevantToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ contract RelevantToken is Initializable, ERC20, Ownable, ERC20Mintable {
}

splitRewards(releasableTokens); // split into different buckets (rewardFund, airdrop, devFund)
toDevFund(); // transfer devFund out immediately
lastRound = currentRound; // Set current round as last release
totalReleased = totalReleased.add(releasableTokens); // Increase totalReleased count
toDevFund(); // transfer devFund out immediately
emit Released(releasableTokens, rewardFund, airdropFund, developmentFund);
return true;
}
Expand Down Expand Up @@ -222,15 +222,16 @@ contract RelevantToken is Initializable, ERC20, Ownable, ERC20Mintable {
// TODO: this needs to be worked out! with https://user-images.githubusercontent.com/337721/52804952-7e3f3080-3053-11e9-8bb2-9bc1c3df19ee.jpg
// and using Bancor's Power formula for e^x
// alternatively use the integral of the reward function:
// return initRoundReward.mul(-timeConstant).mul(fixedExp(-_round/timeConstant, 18)).add(timeConstant.mul(initRoundReward));
// return initRoundReward.mul(-timeConstant).mul(fixedExp(-_round/timeConstant, 18)).add(timeConstant.mul(initRoundReward));
}

/**
* @dev Transfer eligible tokens from devFund bucket to devFundAddress
*/
function toDevFund() internal returns(bool) {
require(this.transfer(devFundAddress, developmentFund), "Transfer to devFundAddress failed");
uint256 amount = developmentFund;
developmentFund = 0;
require(this.transfer(devFundAddress, amount), "Transfer to devFundAddress failed");
return true;
}

Expand Down Expand Up @@ -263,7 +264,7 @@ contract RelevantToken is Initializable, ERC20, Ownable, ERC20Mintable {
*/
function claimTokens(uint256 _amount, bytes memory _sig) public returns(bool) {
// check _amount + account matches hash
require(allocatedRewards >= _amount);
require(allocatedRewards >= _amount, "Not enought allocated rewarads");
bytes32 hash = keccak256(abi.encodePacked(_amount, msg.sender, nonces[msg.sender]));
hash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));

Expand Down Expand Up @@ -293,7 +294,7 @@ contract RelevantToken is Initializable, ERC20, Ownable, ERC20Mintable {
}

/**
* @dev Return rounds since last release
* @dev Return rounds since last release *typo*
*/
function roundsSincleLast() public view returns (uint256) {
return roundNum() - lastRound;
Expand Down
12 changes: 6 additions & 6 deletions initToken.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@

testName='RelevantToken'
testName='Relevant'
testDecimals=18
testSymbol='RVT'
testSymbol='REL'
testVersion='v1'
testDevFundAddress='0xffcf8fdee72ac11b5c542428b35eef5769c409f0'
initRoundReward=25000 #added extra 0!
testDevFundAddress='0x6e1D15c98742d981E76fe3982027C48D8303C136'
initRoundReward=2500 #back to original
initRoundRewardBNString=$(echo "$initRoundReward*10^18" | bc)
timeConstant=$(echo "8760*10^18/l(2)" | bc -l)
timeConstantBNString=$(printf "%.0f\n" $timeConstant)
targetInflation=10880216701148
targetRound=26704
roundLength=240
roundDecayBNString=999920876739935000
totalPremintBNString=277770446297438000000000000 #added extra 0!
totalPremintBNString=27777044629743800000000000 #back to original

args=$(echo $testName,$testDecimals,$testSymbol,$testVersion,$testDevFundAddress,$initRoundRewardBNString,$timeConstantBNString,$targetInflation,$targetRound,$roundLength,$roundDecayBNString,$totalPremintBNString)
echo $args
npx zos create RelevantToken --init initialize --args $args --network local
npx zos create RelevantToken --init initialize --args $args --network rinkeby
4 changes: 2 additions & 2 deletions initTokenTest.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

testName='RelevantToken'
testName='Relevant'
testDecimals=18
testSymbol='RVT'
testSymbol='REL'
testVersion='v1'
testDevFundAddress='0xffcf8fdee72ac11b5c542428b35eef5769c409f0'
initRoundReward=2500
Expand Down
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"author": "Achill Rudolph",
"license": "ISC",
"dependencies": {
"bignumber.js": "^8.1.1",
"chai-bignumber": "^3.0.0",
"dotenv": "^6.2.0",
"openzeppelin-eth": "^2.1.3",
"truffle": "^5.0.4",
"truffle-hdwallet-provider": "^1.0.5",
"web3": "^1.0.0-beta.46",
"zos": "^2.2.1",
"zos-lib": "^2.2.1",
"bignumber.js": "^8.1.1"
"zos-lib": "^2.2.1"
},
"devDependencies": {
"big-number": "^2.0.0",
Expand Down
22 changes: 15 additions & 7 deletions test/RelevantToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,35 @@ contract('token', accounts => {
});

it('Allows user to claim rewards and fails with used nonce', async () => {
let amount = await token.allocatedRewards.call();
let startBalance = await token.balanceOf(accounts[1]);
let owner = await token.owner.call();
const user = owner;

let nonce = await token.nonceOf.call(accounts[1]);
let hash = soliditySha3(amount, accounts[1], nonce.toNumber());
// let amount = await token.allocatedRewards.call();
let amount = new BN(100);

let startBalance = await token.balanceOf(user);

let nonce = await token.nonceOf.call(user);
let hash = soliditySha3(amount, user, nonce.toNumber());
let sig = await web3.eth.sign(hash, accounts[0]);

console.log(hash);
console.log(sig);

let claimTokens = await token.claimTokens(amount, sig, {
from: accounts[1]
from: user
});
console.log('claimTokens gas ', claimTokens.receipt.gasUsed);

let endBalance = await token.balanceOf(accounts[1]);
let endBalance = await token.balanceOf(user);
expect(endBalance.sub(startBalance).toString()).to.bignumber.equal(
amount.toString()
);

// should fail with previous nonce
let didThrow = false;
try {
await token.claimTokens(amount, sig, { from: accounts[1] });
await token.claimTokens(amount, sig, { from: user });
} catch (e) {
didThrow = true;
}
Expand Down
22 changes: 22 additions & 0 deletions truffle-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const HDWalletProvider = require('truffle-hdwallet-provider');

require('dotenv').config();

module.exports = {
networks: {
coverage: {
Expand All @@ -14,6 +18,24 @@ module.exports = {
gasPrice: 5e9,
network_id: '*'
// network_id: 5777
},
rinkeby: {
provider: () => new HDWalletProvider(
process.env.MNEMONIC,
'https://rinkeby.infura.io/' + process.env.INFURA_API_KEY
),
network_id: 4,
gas: 6.9e6,
gasPrice: 2.1e9
},
mainnet: {
provider: () => new HDWalletProvider(
process.env.MNEMONIC,
'https://mainnet.infura.io/' + process.env.INFURA_API_KEY
),
gas: 6000000,
gasPrice: 2e9,
network_id: 1
}
}
};
Loading

0 comments on commit 0b0bcc9

Please sign in to comment.