Coder Social home page Coder Social logo

is-tcr's People

Contributors

akuanti avatar irene-lin avatar kangarang avatar kmoneal avatar marydwyer avatar medvedev-evgeny avatar miguelmota avatar mzeitlin8 avatar nigel-heeral avatar skmgoldin avatar terryli0095 avatar yorhodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

is-tcr's Issues

Parameterizer: supplyOracle

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);
    }

Inflation reward calculations

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?

Calculating inflation

In getMajorityBlocInflation, calculate unmodulatedTokensToMint on the basis of the total revealed tokens irrespective of token faction.

Parameterizer: inflation

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.