Skip to content

Instantly share code, notes, and snippets.

@valo
Last active August 12, 2020 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valo/51e65937ef344d85b99a6335e16493df to your computer and use it in GitHub Desktop.
Save valo/51e65937ef344d85b99a6335e16493df to your computer and use it in GitHub Desktop.
YFI vs AMPL stacking contract. One is the contract used by YFI for token distribution. The other is the contract used by YAM to distribute using AMPL liquidity tokens.
1a2,5
> *Submitted for verification at Etherscan.io on 2020-08-11
> */
>
> /**
12c16
< * Synthetix: YFIRewards.sol
---
> * Synthetix: YAMRewards.sol
668c672
< address rewardDistribution;
---
> address public rewardDistribution;
691a696,699
> interface YAM {
> function yamsScalingFactor() external returns (uint256);
> }
>
696c704,706
< IERC20 public y = IERC20(0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8);
---
> IERC20 public ampl_eth_uni_lp = IERC20(
> 0xc5be99A02C6857f9Eac67BbCE58DF5572498F40c
> );
712c722
< y.safeTransferFrom(msg.sender, address(this), amount);
---
> ampl_eth_uni_lp.safeTransferFrom(msg.sender, address(this), amount);
718c728
< y.safeTransfer(msg.sender, amount);
---
> ampl_eth_uni_lp.safeTransfer(msg.sender, amount);
722,724c732,734
< contract YearnRewards is LPTokenWrapper, IRewardDistributionRecipient {
< IERC20 public yfi = IERC20(0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e);
< uint256 public constant DURATION = 7 days;
---
> contract YAMAMPLPool is LPTokenWrapper, IRewardDistributionRecipient {
> IERC20 public yam = IERC20(0x0e2298E3B3390e3b945a5456fBf59eCc3f55DA16);
> uint256 public constant DURATION = 625000; // ~7 1/4 days
725a736
> uint256 public starttime = 1597172400; // 2020-08-11 19:00:00 (UTC UTC +00:00)
737a749,753
> modifier checkStart() {
> require(block.timestamp >= starttime, "not start");
> _;
> }
>
775c791
< function stake(uint256 amount) public updateReward(msg.sender) {
---
> function stake(uint256 amount) public updateReward(msg.sender) checkStart {
781c797,801
< function withdraw(uint256 amount) public updateReward(msg.sender) {
---
> function withdraw(uint256 amount)
> public
> updateReward(msg.sender)
> checkStart
> {
792c812
< function getReward() public updateReward(msg.sender) {
---
> function getReward() public updateReward(msg.sender) checkStart {
796,797c816,819
< yfi.safeTransfer(msg.sender, reward);
< emit RewardPaid(msg.sender, reward);
---
> uint256 scalingFactor = YAM(address(yam)).yamsScalingFactor();
> uint256 trueReward = reward.mul(scalingFactor).div(10**18);
> yam.safeTransfer(msg.sender, trueReward);
> emit RewardPaid(msg.sender, trueReward);
806,807c828,838
< if (block.timestamp >= periodFinish) {
< rewardRate = reward.div(DURATION);
---
> if (block.timestamp > starttime) {
> if (block.timestamp >= periodFinish) {
> rewardRate = reward.div(DURATION);
> } else {
> uint256 remaining = periodFinish.sub(block.timestamp);
> uint256 leftover = remaining.mul(rewardRate);
> rewardRate = reward.add(leftover).div(DURATION);
> }
> lastUpdateTime = block.timestamp;
> periodFinish = block.timestamp.add(DURATION);
> emit RewardAdded(reward);
809,811c840,843
< uint256 remaining = periodFinish.sub(block.timestamp);
< uint256 leftover = remaining.mul(rewardRate);
< rewardRate = reward.add(leftover).div(DURATION);
---
> rewardRate = reward.div(DURATION);
> lastUpdateTime = starttime;
> periodFinish = starttime.add(DURATION);
> emit RewardAdded(reward);
813,815d844
< lastUpdateTime = block.timestamp;
< periodFinish = block.timestamp.add(DURATION);
< emit RewardAdded(reward);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment