Skip to content

Commit

Permalink
Merge c31f9bd into 14389a9
Browse files Browse the repository at this point in the history
  • Loading branch information
kamescg committed Jul 8, 2021
2 parents 14389a9 + c31f9bd commit ace7511
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"not-rely-on-time": "off",
"reason-string": ["warn", {"maxLength": 64}]
}
}
}
17 changes: 0 additions & 17 deletions contracts/ISushi.sol

This file was deleted.

17 changes: 10 additions & 7 deletions contracts/SushiYieldSource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
pragma solidity 0.6.12;

import "@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;

Expand All @@ -33,7 +35,7 @@ contract SushiYieldSource is IYieldSource {
address indexed to
);

constructor(ISushiBar _sushiBar, ISushi _sushiAddr) public {
constructor(ISushiBar _sushiBar, IERC20 _sushiAddr) public {
require(
address(_sushiBar) != address(0),
"SushiYieldSource/sushiBar-not-zero-address"
Expand All @@ -45,6 +47,8 @@ contract SushiYieldSource is IYieldSource {

sushiBar = _sushiBar;
sushiAddr = _sushiAddr;

_sushiAddr.safeApprove(address(_sushiBar), type(uint256).max);
}

/// @notice Returns the ERC20 asset token used for deposits.
Expand All @@ -68,8 +72,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) external override {
sushiAddr.transferFrom(msg.sender, address(this), amount);
sushiAddr.approve(address(sushiBar), amount);
sushiAddr.safeTransferFrom(msg.sender, address(this), amount);

ISushiBar bar = sushiBar;
uint256 beforeBalance = bar.balanceOf(address(this));
Expand All @@ -89,7 +92,7 @@ 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) external override returns (uint256) {
ISushiBar bar = sushiBar;
ISushi sushi = sushiAddr;
IERC20 sushi = sushiAddr;

uint256 totalShares = bar.totalSupply();
if (totalShares == 0) return 0;
Expand All @@ -110,7 +113,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);
emit RedeemedToken(msg.sender, requiredSharesBalance, amount);

return (sushiBalanceDiff);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"hardhat-typechain": "^0.3.5",
"prettier": "^2.2.1",
"prettier-plugin-solidity": "^1.0.0-beta.6",
"solhint": "3.3.6",
"solidity-coverage": "0.7.16",
"ts-generator": "^0.1.1",
"ts-node": "^9.1.1",
Expand Down
1 change: 1 addition & 0 deletions test/integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ describe("SushiYieldSource integration", function () {
"0x6B3595068778DD592e39A122f4f5a5cF09C90fE2",
{ gasLimit: 9500000 }
);

const yieldSourcePrizePoolConfig = {
yieldSource: yieldSource.address,
maxExitFeeMantissa: toWei("0.5"),
Expand Down
4 changes: 3 additions & 1 deletion test/unit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe("SushiYieldSource", function () {
wallet,
overrides
);

sushi = await ERC20MintableContract.deploy("Sushi", "SUSHI");

const SushiBarContract = await hre.ethers.getContractFactory(
Expand All @@ -50,10 +51,11 @@ describe("SushiYieldSource", function () {
);

if (!isDeployTest) {
deploySushiYieldSource(sushiBar.address, sushi.address);
await deploySushiYieldSource(sushiBar.address, sushi.address);
}

amount = toWei("100");

await sushi.mint(wallet.address, amount);
await sushi.mint(wallet2.address, amount.mul(99));
await sushi.connect(wallet2).approve(sushiBar.address, amount.mul(99));
Expand Down
39 changes: 39 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,13 @@
resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.12.0.tgz#18a0fb2a9d2484b23176f63b16093c64794fc323"
integrity sha512-DT3f/Aa4tQysZwUsuqBwvr8YRJzKkvPUKV/9o2/o5EVw3xqlbzmtx4O60lTUcZdCawL+N8bBLNUyOGpHjGlJVQ==

"@solidity-parser/parser@^0.13.2":
version "0.13.2"
resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.13.2.tgz#b6c71d8ca0b382d90a7bbed241f9bc110af65cbe"
integrity sha512-RwHnpRnfrnD2MSPveYoPh8nhofEvX7fgjHk1Oq+NNvCcLx4r1js91CO9o+F/F3fBzOCyvm8kKRTriFICX/odWw==
dependencies:
antlr4ts "^0.5.0-alpha.4"

"@solidity-parser/parser@^0.5.2":
version "0.5.2"
resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.5.2.tgz#4d74670ead39e4f4fdab605a393ba8ea2390a2c4"
Expand Down Expand Up @@ -1644,6 +1651,11 @@ antlr4@4.7.1:
resolved "https://registry.yarnpkg.com/antlr4/-/antlr4-4.7.1.tgz#69984014f096e9e775f53dd9744bf994d8959773"
integrity sha512-haHyTW7Y9joE5MVs37P2lNYfU2RWBLfcRDD8OWldcdZm5TiCE91B5Xl1oWSwiDUSd4rlExpt2pu1fksYQjRBYQ==

antlr4ts@^0.5.0-alpha.4:
version "0.5.0-alpha.4"
resolved "https://registry.yarnpkg.com/antlr4ts/-/antlr4ts-0.5.0-alpha.4.tgz#71702865a87478ed0b40c0709f422cf14d51652a"
integrity sha512-WPQDt1B74OfPv/IMS2ekXAKkTZIHl88uMetg6q3OTqgFxZ/dxDXI0EWLyZid/1Pe6hTftyg5N7gel5wNAGxXyQ==

anymatch@~3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.1.tgz#c55ecf02185e2469259399310c173ce31233b142"
Expand Down Expand Up @@ -1747,6 +1759,11 @@ assign-symbols@^1.0.0:
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
integrity sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c=

ast-parents@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/ast-parents/-/ast-parents-0.0.1.tgz#508fd0f05d0c48775d9eccda2e174423261e8dd3"
integrity sha1-UI/Q8F0MSHddnszaLhdEIyYejdM=

astral-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
Expand Down Expand Up @@ -8487,6 +8504,28 @@ solc@^0.6.3:
semver "^5.5.0"
tmp "0.0.33"

solhint@3.3.6:
version "3.3.6"
resolved "https://registry.yarnpkg.com/solhint/-/solhint-3.3.6.tgz#abe9af185a9a7defefba480047b3e42cbe9a1210"
integrity sha512-HWUxTAv2h7hx3s3hAab3ifnlwb02ZWhwFU/wSudUHqteMS3ll9c+m1FlGn9V8ztE2rf3Z82fQZA005Wv7KpcFA==
dependencies:
"@solidity-parser/parser" "^0.13.2"
ajv "^6.6.1"
antlr4 "4.7.1"
ast-parents "0.0.1"
chalk "^2.4.2"
commander "2.18.0"
cosmiconfig "^5.0.7"
eslint "^5.6.0"
fast-diff "^1.1.2"
glob "^7.1.3"
ignore "^4.0.6"
js-yaml "^3.12.0"
lodash "^4.17.11"
semver "^6.3.0"
optionalDependencies:
prettier "^1.14.3"

solhint@^2.0.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/solhint/-/solhint-2.3.1.tgz#6fee8fc2635112bf5812f7cba8359c14e9d9a491"
Expand Down

0 comments on commit ace7511

Please sign in to comment.