Git Product home page Git Product logo

contracts-v1's People

Contributors

neverdefined avatar realkinando avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

pfanp lend2-us redm3

contracts-v1's Issues

Feedback for rl-gl branch

King @realkinando is back, hyped for V2 ๐Ÿ‘€ . Here's my feedback from looking at the contracts in v2-core

Mariposa.sol

  • State variables
    • cap doesn't seem to be changed after it's set in the constructor. You can make it immutable
      • Also, is reaching the cap an issue? Will we need a method that can raise/lower it?
  • Constructor
    • epochSeconds_ is never set, which would cause distribute to always revert since it'd never be greater than lastEpoch (which also never seems to be set)
  • For integer types, specify the number of bits so we can do variable packing (e.g. uint8/16/32/.../256)
  • Should use a formatter so our code is consistent visually
  • Add checks for all params unless it's obviously redundant/unnecessary (e.g. would be worth it for this constructor's params since it's cheaper to check to do the checks than redeploy because human error - unless there's a setter method we can use)
  • Optimization example of this for loop
    • Outer loop header
      • There's no need to initialize the control variable with 0 as it's already the default value
      • The loop condition is evaluated on each iteration so it'd be more efficient to assign the result of currentEpoch - lastEpoch to a variable and use that (vs. doing the calculation on each iteration)
        • Wouldn't currentEpoch - lastEpoch equal 1?
    • Inner loop header
      • Use j <= collectionCount instead of j < collectionCount + 1 (otherwise it'll do the calculation on every iteration, similar to the point above)
    • Inner loop body
      • Assign repeatedly accessed values to a variable (e.g. Collection storage c = getCollection[j])
      • Should break the logic into separate methods which may help with readability
  • distribute may run out of gas if there are too many collections in the future

RevenueDistributor

  • Mariposa feedback applies here
  • State variables
    • lockToken can be immutable - never re-assigned outside of constructor
    • offset can be immutable - never re-assigned outside of constructor
  • Need to use SafeTransferLib if dealing with potentially untrustworthy tokens
  • The internal methods below (and ones like it - there are many) should be made public or external (if they don't need to be called internally) and the redundant external methods can be removed:
    function _getCurrentRound() internal view returns (uint round){
        round = (block.timestamp + (offset * 1 weeks)) / (4 * 1 weeks);
    }

    function getCurrentRound() external view returns (uint round){
        round = _getCurrentRound();
    }

    function _getTimestampFromRound(uint round) internal view returns (uint timestamp){
        timestamp = ((round * 4) + offset) * 1 weeks;
    }

    function getTimestampFromRound(uint round) external view returns (uint timestamp){
        timestamp = _getTimestampFromRound(round);
    }

    function _getRewardHash(address token, bool conviction) internal view returns(bytes32 rewardHash){
        rewardHash = keccak256(abi.encode(token,conviction));
    }

    function getRewardHash(address token, bool conviction) external view returns(bytes32 rewardHash){
        rewardHash = _getRewardHash(token, conviction);
    }
  • Remove this redundant call since rewardRoundHash is the same thing

I'll update this again when I go through the other contracts.

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.