yieldprotocol / yield-utils-v2 Goto Github PK
View Code? Open in Web Editor NEWUtility contracts for Yield v2
License: MIT License
Utility contracts for Yield v2
License: MIT License
Been trying to create a token that can reward its own holders according to proportion. Used the erc20rewards code but I keep getting errors. I need a way out
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.
Like transfer
, approve
may fail by returning false
. Should TransferHelper
have a function safeApprove
?
The Registered
event should show the merkleRoot parameter, to make changes easier to track. The merkleRoot works as a defacto unique identifier for the registration.
Implement Pausable.sol
similar to this.
Every governance contract would inherit this contract.
Conversation: yieldprotocol/environments-v2#196 (review)
setRewardsToken function uses auth() modifier to ask for a role, but roles are never granted through _grantRole anywhere in the contract.
In past versions this two roles were granted at the constructor of Erc20Rewards.sol:
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(REWARD_SETTER_ROLE, msg.sender);
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 ?
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
Move Pausable.sol into contracts/utils
, and then integrate foundry tests properly.
SafeERC20Namer.tokenDecimals
returns zero in case the decimals
is not implemented by the provided token
address:
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));
+ }
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.