Giter Club home page Giter Club logo

yield-utils-v2's People

Contributors

alcueca avatar calnix avatar devtooligan avatar egillh210 avatar hashedmae avatar iamsahu avatar sabnock01 avatar sblowpckcr avatar transmissions11 avatar uivlis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar

yield-utils-v2's Issues

Port tests to Foundry

We want to port all of the tests for yield-utils-v2 to Foundry including those contracts which do not yet have tests written, such as the various cast libraries.
image

Use Solmate for ERC1155/ERC20/Others?

One of the main reasons we wrote a lot of our own contracts instead of using the popular OpenZeppelin library is because OZ's contracts are bloated and not optimized; we wanted to have control over what goes into the contract without the bloat.

Solmate is a gas optimized, audited, set of contracts that we are considering using. We are already using their 1155 implementation with the fCash wrapper. We also discussed using the Solmate ERC20 contract as well.

We should decide if we definitely want to use either or both of these contracts as well as others. We should also decide if we want to import the contracts direct from Solmate, or use some sort of wrapper, or copy/paste the code into our repo.

Reverting approve?

Like transfer, approve may fail by returning false. Should TransferHelper have a function safeApprove?

erc721 with rewards

Hi,
Thank you for the library
I am looking to implement the ERC20Rewards.sol to erc721 owners
however the rewards per users is not accumulating.
Can you give an example of implementation, or mb tell me what I am missing ?

image

I presume the mistake is

    /// @dev Update the rewards per token accumulator.
/// @notice Needs to be called on each liquidity event
function _updateRewardsPerToken() internal {
    RewardsPerToken memory rewardsPerToken_ = rewardsPerToken;
    RewardsPeriod memory rewardsPeriod_ = rewardsPeriod;
    uint256 totalSupply_ = rewardsToken.balanceOf(address(this)); //first change here

    // We skip the update if the program hasn't started
    if (uint32(block.timestamp) < rewardsPeriod_.start) return;

    // Find out the unaccounted time
    uint32 end = earliest(uint32(block.timestamp), rewardsPeriod_.end);
    uint256 unaccountedTime = end - rewardsPerToken_.lastUpdated; // Cast to uint256 to avoid overflows later on
    if (unaccountedTime == 0) return; // We skip the storage changes if already updated in the same block

    // Calculate and update the new value of the accumulator. unaccountedTime casts it into uint256, which is desired.
    // If the first mint happens mid-program, we don't update the accumulator, no one gets the rewards for that period.
    if (totalSupply_ != 0)
    rewardsPerToken_.accumulated = uint128(rewardsPerToken_.accumulated + 1e18 * unaccountedTime * rewardsPerToken_.rate / totalSupply_); // The rewards per token are scaled up for precision
    rewardsPerToken_.lastUpdated = end;
    rewardsPerToken = rewardsPerToken_;
    
}


   /// @dev Accumulate rewards for an user.
/// @notice Needs to be called on each liquidity event, or when user balances change.
function _updateUserRewards(address user) internal returns (uint128) {
    UserRewards memory userRewards_ = rewards[user];
    RewardsPerToken memory rewardsPerToken_ = rewardsPerToken;
    
    // Calculate and update the new value user reserves. _balanceOf[user] casts it into uint256, which is desired.
    userRewards_.accumulated = uint128(userRewards_.accumulated + rewardsToken.balanceOf(user)  //2nd change here

(rewardsPerToken_.accumulated - userRewards_.checkpoint) / 1e18); // We must scale down the rewards by the precision factor
userRewards_.checkpoint = rewardsPerToken_.accumulated;
rewards[user] = userRewards_;

    return userRewards_.accumulated;
}

what should I insert instead?
I don't see the function _balanceOf[user] you mentioned on line 131

Unnecessary return of default value

SafeERC20Namer.tokenDecimals returns zero in case the decimals is not implemented by the provided token address:

https://github.com/yieldprotocol/yield-utils-v2/blob/dbeb85ac94befc477bf8cdff9f178fdf331eb83d/src/token/SafeERC20Namer.sol#L99-102

However, this is not necessary, because "0" is the implicit default value for uint8. You might be able to save a little bit of gas if you refactor the code like this:

- function tokenDecimals(address token) public view returns (uint8) {
+ function tokenDecimals(address token) public view returns (uint8 decimals) {
(bool success, bytes memory data) = token.staticcall(abi.encodeWithSelector(IERC20Metadata.decimals.selector));
- return success && data.length == 32 ? abi.decode(data, (uint8)) : 0;
+ if (success && data.length == 32) {
+     decimals = abi.decode(data, (uint8));
+ }

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.