Skip to content

Commit

Permalink
update to support SafeERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
kamescg authored and Aodhgan committed Jul 2, 2021
1 parent 136890b commit 3a0c19f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions contracts/BadgerYieldSource.sol
Expand Up @@ -3,6 +3,8 @@
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 "./IBadgerSett.sol";
import "./IBadger.sol";
Expand All @@ -11,14 +13,15 @@ import "hardhat/console.sol";
/// @title A pooltogether yield source for badger sett
/// @author Steffel Fenix, 0xkarl
contract BadgerYieldSource is IYieldSource {
using SafeERC20 for IERC20;
using SafeMath for uint256;
IBadgerSett private immutable badgerSett;
IBadger private immutable badger;
IERC20 private immutable badger;
mapping(address => uint256) private balances;

constructor(address badgerSettAddr, address badgerAddr) public {
badgerSett = IBadgerSett(badgerSettAddr);
badger = IBadger(badgerAddr);
constructor(IBadgerSett badgerSettAddr, IERC20 badgerAddr) public {
badgerSett = badgerSettAddr;
badger = badgerAddr;
}

/// @notice Returns the ERC20 asset token used for deposits.
Expand All @@ -41,7 +44,7 @@ contract BadgerYieldSource 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 {
badger.transferFrom(msg.sender, address(this), amount);
badger.safeTransferFrom(msg.sender, address(this), amount);
badger.approve(address(badgerSett), amount);

uint256 beforeBalance = badgerSett.balanceOf(address(this));
Expand Down Expand Up @@ -76,7 +79,7 @@ contract BadgerYieldSource is IYieldSource {
uint256 badgerBalanceDiff = badgerAfterBalance.sub(badgerBeforeBalance);

balances[msg.sender] = balances[msg.sender].sub(requiredSharesBalance);
badger.transfer(msg.sender, badgerBalanceDiff);
badger.safeTransfer(msg.sender, badgerBalanceDiff);
return (badgerBalanceDiff);
}
}

0 comments on commit 3a0c19f

Please sign in to comment.