Skip to content

Commit

Permalink
fix(contract): fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Jul 2, 2021
1 parent 680ab8b commit 2def836
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
1 change: 0 additions & 1 deletion contracts/ISushiBar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ interface ISushiBar {
function totalSupply() external view returns (uint256);

function balanceOf(address account) external view returns (uint256);

}
22 changes: 14 additions & 8 deletions contracts/SushiYieldSource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.6.12;

import { IYieldSource } from "@pooltogether/yield-source-interface/contracts/IYieldSource.sol";
import "@pooltogether/yield-source-interface/contracts/IYieldSource.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";

Expand All @@ -21,8 +21,14 @@ contract SushiYieldSource is IYieldSource {
mapping(address => uint256) public balances;

constructor(ISushiBar _sushiBar, ISushi _sushiAddr) public {
require(address(_sushiBar).isContract(), "SushiYieldSource/sushiBar-not-contract-address");
require(address(_sushiAddr).isContract(), "SushiYieldSource/sushiAddr-not-contract-address");
require(
address(_sushiBar).isContract(),
"SushiYieldSource/sushiBar-not-contract-address"
);
require(
address(_sushiAddr).isContract(),
"SushiYieldSource/sushiAddr-not-contract-address"
);

sushiBar = _sushiBar;
sushiAddr = _sushiAddr;
Expand Down Expand Up @@ -72,15 +78,16 @@ contract SushiYieldSource is IYieldSource {
ISushi sushi = sushiAddr;

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

uint256 barSushiBalance = sushi.balanceOf(address(bar));
if(barSushiBalance == 0) return 0;
if (barSushiBalance == 0) return 0;

uint256 sushiBeforeBalance = sushi.balanceOf(address(this));

uint256 requiredShares = ((amount.mul(totalShares) + totalShares)).div(barSushiBalance);
if(requiredShares == 0) return 0;
uint256 requiredShares =
((amount.mul(totalShares) + totalShares)).div(barSushiBalance);
if (requiredShares == 0) return 0;

uint256 requiredSharesBalance = requiredShares.sub(1);
bar.leave(requiredSharesBalance);
Expand All @@ -94,5 +101,4 @@ contract SushiYieldSource is IYieldSource {

return (sushiBalanceDiff);
}

}
14 changes: 7 additions & 7 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,35 @@ async function getYieldSourcePrizePoolProxy(tx) {
}

async function run() {
console.log("running fork script")
console.log("running fork script");

await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [SUSHI_HOLDER],
});

const SUSHI_TOKEN_ADDRESS = "0x6B3595068778DD592e39A122f4f5a5cF09C90fE2"
const XSUSHI_ADDRESS = "0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272"
const SUSHI_TOKEN_ADDRESS = "0x6B3595068778DD592e39A122f4f5a5cF09C90fE2";
const XSUSHI_ADDRESS = "0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272";

const sushiHolder = await ethers.provider.getUncheckedSigner(SUSHI_HOLDER);
const sushi = await ethers.getContractAt(
"IERC20Upgradeable",
SUSHI_TOKEN_ADDRESS,
sushiHolder
);
console.log("getting builder")
console.log("getting builder");
const builder = await ethers.getContractAt(
"PoolWithMultipleWinnersBuilder",
"0x39E2F33ff4Ad3491106B3BB15dc66EbE24e4E9C7"
);
console.log("deploying")
console.log("deploying");
SushiYieldSourceFactory = await ethers.getContractFactory("SushiYieldSource");
sushiYieldSource = await SushiYieldSourceFactory.deploy(
XSUSHI_ADDRESS,
SUSHI_TOKEN_ADDRESS
SUSHI_TOKEN_ADDRESS
);

console.log("deployed SushiYieldSource at ", sushiYieldSource.address)
console.log("deployed SushiYieldSource at ", sushiYieldSource.address);

const block = await ethers.provider.getBlock();

Expand Down
30 changes: 15 additions & 15 deletions test/unit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("SushiYieldSource", function () {
sushiAddress,
overrides
);
}
};

beforeEach(async function () {
[wallet, wallet2] = await ethers.getSigners();
Expand Down Expand Up @@ -60,7 +60,7 @@ describe("SushiYieldSource", function () {
await sushiBar.connect(wallet2).enter(amount.mul(99));
});

describe('constructor()', () => {
describe("constructor()", () => {
let randomWalletAddress;

before(() => {
Expand All @@ -75,28 +75,28 @@ describe("SushiYieldSource", function () {
isDeployTest = false;
});

it('should fail if sushiBar address is not a contract', async () => {
await expect(deploySushiYieldSource(randomWalletAddress, sushi.address)).to.be.revertedWith(
'SushiYieldSource/sushiBar-not-contract-address',
);
it("should fail if sushiBar address is not a contract", async () => {
await expect(
deploySushiYieldSource(randomWalletAddress, sushi.address)
).to.be.revertedWith("SushiYieldSource/sushiBar-not-contract-address");
});

it('should fail if sushiBar address is address 0', async () => {
it("should fail if sushiBar address is address 0", async () => {
await expect(
deploySushiYieldSource(ethers.constants.AddressZero, sushi.address),
).to.be.revertedWith('SushiYieldSource/sushiBar-not-contract-address');
deploySushiYieldSource(ethers.constants.AddressZero, sushi.address)
).to.be.revertedWith("SushiYieldSource/sushiBar-not-contract-address");
});

it('should fail if sushi address is not a contract', async () => {
it("should fail if sushi address is not a contract", async () => {
await expect(
deploySushiYieldSource(sushiBar.address, randomWalletAddress),
).to.be.revertedWith('SushiYieldSource/sushiAddr-not-contract-address');
deploySushiYieldSource(sushiBar.address, randomWalletAddress)
).to.be.revertedWith("SushiYieldSource/sushiAddr-not-contract-address");
});

it('should fail if sushi address is address 0', async () => {
it("should fail if sushi address is address 0", async () => {
await expect(
deploySushiYieldSource(sushiBar.address, ethers.constants.AddressZero),
).to.be.revertedWith('SushiYieldSource/sushiAddr-not-contract-address');
deploySushiYieldSource(sushiBar.address, ethers.constants.AddressZero)
).to.be.revertedWith("SushiYieldSource/sushiAddr-not-contract-address");
});
});

Expand Down

0 comments on commit 2def836

Please sign in to comment.