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 8, 2021
1 parent 952ea8f commit e54d56d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 1 addition & 5 deletions contracts/SushiYieldSource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ contract SushiYieldSource is IYieldSource {

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 @@ -76,7 +73,6 @@ contract SushiYieldSource is IYieldSource {
/// @param to The user whose balance will receive the tokens
function supplyTokenTo(uint256 amount, address to) external override {
sushiAddr.safeTransferFrom(msg.sender, address(this), amount);
sushiAddr.safeApprove(address(sushiBar), amount);

ISushiBar bar = sushiBar;
uint256 beforeBalance = bar.balanceOf(address(this));
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 e54d56d

Please sign in to comment.