kangarang / is-tcr Goto Github PK
View Code? Open in Web Editor NEWInflating supply token-curated registry
License: Apache License 2.0
Inflating supply token-curated registry
License: Apache License 2.0
if users are able to change the minDeposit manually, then the reserve pool of tokens should reflect this change. the reserve pool represents the sum of all candidates' minDeposits. to do this, the Parameterizer should also have authority as a supplyOracle in order to inflate/deflate the token's totalSupply.
https://github.com/kangarang/itcr/blob/master/contracts/Parameterizer.sol#L127
// TODO: supplyOracle -> transfer to/from registry if minDeposit manually set
function setMinDeposit(uint _majorityBlocInflation, uint _tokenSupply) public onlySupplyOracle returns (uint) {
uint minDeposit = get("minDeposit");
// set the new minDeposit proportional to the inflated totalSupply
// minDeposit|totalSupply : newMinDeposit|newTotalSupply
// minDeposit * (totalSupply + majorityBlocInflation) / totalSupply
uint newMinDeposit = minDeposit.mul(_tokenSupply.add(_majorityBlocInflation)).div(_tokenSupply);
// (10 * (8000 + 2400)) / 8000 -> 13
// note: assert correct ratios?
set("minDeposit", newMinDeposit);
emit _MinDepositSet(newMinDeposit);
return newMinDeposit.sub(minDeposit);
}
in claimReward
, a voter's total reward is the sum of (1) challengeReward
: token-weighted % of challenge loser's forfeited deposit and (2) voterInflationReward
: token-weighted % of majority bloc inflation reward
challengeReward
in the following case, the value would get rounded down to 0. there's gotta be a better way to calculate and account for the token's decimals. shouldn't users be able to claim fractions of a token? isn't that why tokens have decimals?
// minDeposit: 10 -> challenger loser's forfeited numTokens
// dispensationPct: 40 -> challenge winner
// rewardPool: 6 -> winning voters
// totalWinningTokens: 5000
// 10 * 6 / 5000 = 0.012
uint challengeReward = voterTokens.mul(rewardPool).div(totalWinningTokens);
voterInflationReward
we need to add tests to confirm our suspicion that the current calculation of voterInflationReward
is not precise, then fix it so that the calculation IS more precise, and the tests pass
function claimReward(uint _challengeID, uint _salt) public {
// Ensures the voter has not already claimed tokens and challenge results have been processed
require(challenges[_challengeID].tokenClaims[msg.sender] == false);
require(challenges[_challengeID].resolved == true);
// msg sender's tokens committed/revealed for this challenge
uint voterTokens = voting.getNumPassingTokens(msg.sender, _challengeID, _salt);
// portion of the faceoff winnings that goes to the voter
uint challengeReward = voterTokens.mul(challenges[_challengeID].rewardPool).div(challenges[_challengeID].totalWinningTokens);
// calculate additional token-weighted inflation reward
uint inflationReward = voterInflationReward(_challengeID, voterTokens);
// Ensures a voter cannot claim tokens again
challenges[_challengeID].tokenClaims[msg.sender] = true;
// transfer the sum of both rewards
require(token.transfer(msg.sender, challengeReward.add(inflationReward)));
emit _RewardClaimed(_challengeID, challengeReward.add(inflationReward), msg.sender);
}
function voterInflationReward(uint _challengeID, uint _numTokens) public view returns (uint) {
// calculate the uint percentage of the majority bloc inflation reward
// (numTokens * 100) / totalWinningTokens
uint voterInflationShare = (_numTokens.mul(100)).div(challenges[_challengeID].totalWinningTokens);
// (800 * 100) / 5000 -> 16 (%)
// (5 * 100) / 5000 ->
// TODO: calculate percentages better!
// TODO: add test cases for all sorts of numbers
emit DEBUG("voterInflationShare", voterInflationShare);
// return the amount in tokens
// (voterInflationShare * majorityBlocInflation) / 100
return (voterInflationShare.mul(challenges[_challengeID].majorityBlocInflation)).div(100);
// (16 * 2400) / 100 -> 384 tokens
}
function voterReward(address _voter, uint _challengeID, uint _salt)
public view returns (uint) {
uint totalWinningTokens = challenges[_challengeID].totalWinningTokens;
uint rewardPool = challenges[_challengeID].rewardPool;
uint voterTokens = voting.getNumPassingTokens(_voter, _challengeID, _salt);
return voterTokens.mul(rewardPool).div(totalWinningTokens);
}
note: on lines 261 - 271, claimReward
subtracts the values from the challenge struct's totalTokens
and rewardPool
. why was this necessary? and does this relate to our issue?
In getMajorityBlocInflation
, calculate unmodulatedTokensToMint on the basis of the total revealed tokens irrespective of token faction.
If the challenger wins, totalNumCandidates
should decrement, as the listing will lose its candidate status. inflation occurs too early in this case.
https://github.com/kangarang/itcr/blob/master/contracts/Registry.sol#L400
do we want to implement the same inflation mechanics of the registry into the parameterizer? what are the incentive implications? would this encourage voting so much so that it incentivizes challenges? let's discuss with our designers.
related: #1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.