Skip to content

Commit

Permalink
fix(contract): approve max amount in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Jul 12, 2021
1 parent 5ff8431 commit bb001e1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions contracts/SushiYieldSource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ contract SushiYieldSource is IYieldSource, ReentrancyGuard {

sushiBar = _sushiBar;
sushiAddr = _sushiAddr;
}

/// @notice Approve SUSHI to spend infinite sushiBar (xSUSHI)
function intialize() external {
sushiAddr.safeApprove(address(sushiBar), type(uint256).max);
_sushiAddr.safeApprove(address(_sushiBar), type(uint256).max);
}

/// @notice Returns the ERC20 asset token used for deposits.
Expand All @@ -77,7 +74,7 @@ contract SushiYieldSource is IYieldSource, ReentrancyGuard {
/// @param to The user whose balance will receive the tokens
function supplyTokenTo(uint256 amount, address to) external override nonReentrant {
ISushiBar bar = sushiBar;
ISushi sushi = sushiAddr;
IERC20 sushi = sushiAddr;

sushi.safeTransferFrom(msg.sender, address(this), amount);

Expand Down
3 changes: 1 addition & 2 deletions test/integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ describe("SushiYieldSource integration", function () {
"0x6B3595068778DD592e39A122f4f5a5cF09C90fE2",
{ gasLimit: 9500000 }
);
await yieldSource.intialize()


const yieldSourcePrizePoolConfig = {
yieldSource: yieldSource.address,
maxExitFeeMantissa: toWei("0.5"),
Expand Down
5 changes: 3 additions & 2 deletions 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,11 +51,11 @@ describe("SushiYieldSource", function () {
);

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

amount = toWei("100");
await yieldSource.intialize()

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

0 comments on commit bb001e1

Please sign in to comment.