Skip to content

Commit

Permalink
update to support SafeERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
kamescg committed Jun 28, 2021
1 parent d28c329 commit 48c55d9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions contracts/SushiYieldSource.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.6.12;

import { IYieldSource } from "@pooltogether/yield-source-interface/contracts/IYieldSource.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";

import "./ISushiBar.sol";
import "./ISushi.sol";

/// @title A pooltogether yield source for sushi token
/// @author Steffel Fenix
contract SushiYieldSource is IYieldSource {

using SafeERC20 for IERC20;
using SafeMath for uint256;

ISushiBar public immutable sushiBar;
ISushi public immutable sushiAddr;
IERC20 public immutable sushiAddr;

mapping(address => uint256) public balances;

constructor(ISushiBar _sushiBar, ISushi _sushiAddr) public {
constructor(ISushiBar _sushiBar, IERC20 _sushiAddr) public {
sushiBar = _sushiBar;
sushiAddr = _sushiAddr;
}
Expand All @@ -45,7 +45,7 @@ contract SushiYieldSource is IYieldSource {
/// @param amount The amount of `token()` to be supplied
/// @param to The user whose balance will receive the tokens
function supplyTokenTo(uint256 amount, address to) public override {
sushiAddr.transferFrom(msg.sender, address(this), amount);
sushiAddr.safeTransferFrom(msg.sender, address(this), amount);
sushiAddr.approve(address(sushiBar), amount);

ISushiBar bar = sushiBar;
Expand All @@ -65,8 +65,8 @@ contract SushiYieldSource is IYieldSource {
/// @return The actual amount of tokens that were redeemed. This may be different from the amount passed due to the fractional math involved.
function redeemToken(uint256 amount) public override returns (uint256) {
ISushiBar bar = sushiBar;
ISushi sushi = sushiAddr;

IERC20 sushi = sushiAddr;
uint256 totalShares = bar.totalSupply();
if(totalShares == 0) return 0;

Expand All @@ -86,7 +86,7 @@ contract SushiYieldSource is IYieldSource {
uint256 sushiBalanceDiff = sushiAfterBalance.sub(sushiBeforeBalance);

balances[msg.sender] = balances[msg.sender].sub(requiredSharesBalance);
sushi.transfer(msg.sender, sushiBalanceDiff);
sushi.safeTransfer(msg.sender, sushiBalanceDiff);

return (sushiBalanceDiff);
}
Expand Down

0 comments on commit 48c55d9

Please sign in to comment.