Skip to content

Commit

Permalink
fix: fusestaking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Jan 11, 2024
1 parent 9f8ab23 commit db3ccd3
Showing 1 changed file with 23 additions and 54 deletions.
77 changes: 23 additions & 54 deletions test/staking/FuseStaking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ describe("FuseStakingV3", () => {
let founder, staker1, staker2;
let signers;

let uniswap: waffle.MockContract,
uniswapFactory,
uniswapPair,
gdusdcPair,
fusefusdPair,
ubiMock;
let uniswap: waffle.MockContract, uniswapFactory, uniswapPair, gdusdcPair, fusefusdPair, ubiMock;

const deployMocks = async () => {
let u = await hre.artifacts.readArtifact("Uniswap");
Expand All @@ -35,24 +30,14 @@ describe("FuseStakingV3", () => {
await uniswap.mock.WETH.returns(signers[3].address);
await uniswapFactory.mock.getPair.returns(uniswapPair.address);
await uniswapFactory.mock.getPair
.withArgs(
ethers.constants.AddressZero,
"0x620fd5fa44BE6af63715Ef4E65DDFA0387aD13F5"
)
.withArgs(ethers.constants.AddressZero, "0x620fd5fa44BE6af63715Ef4E65DDFA0387aD13F5")
.returns(gdusdcPair.address);

await uniswapFactory.mock.getPair
.withArgs(
signers[3].address,
"0x249BE57637D8B013Ad64785404b24aeBaE9B098B"
)
.withArgs(signers[3].address, "0x249BE57637D8B013Ad64785404b24aeBaE9B098B")
.returns(fusefusdPair.address);

await uniswapPair.mock.getReserves.returns(
ethers.utils.parseEther("1000"),
"100000",
"0"
);
await uniswapPair.mock.getReserves.returns(ethers.utils.parseEther("1000"), "100000", "0");
await gdusdcPair.mock.getReserves.returns("4984886100", "10789000000", "0");
await fusefusdPair.mock.getReserves.returns(
ethers.utils.parseEther("10000"),
Expand All @@ -67,9 +52,7 @@ describe("FuseStakingV3", () => {
await deployMocks();

let network = networkConfig.name;
staking = (await (
await ethers.getContractFactory("FuseStakingV3")
).deploy()) as FuseStakingV3;
staking = (await (await ethers.getContractFactory("FuseStakingV3")).deploy()) as FuseStakingV3;

await staking.initialize(uniswap.address, NULL_ADDRESS);
await staking.setUBIScheme(ubiMock.address);
Expand All @@ -80,54 +63,42 @@ describe("FuseStakingV3", () => {
});

it("should calc quantity with slippage", async () => {
const res = await staking[
"calcMaxTokenWithPriceImpact(uint256,uint256,uint256)"
]("6917100025787759640000", "265724494", ethers.utils.parseEther("500"));
const res = await staking["calcMaxTokenWithPriceImpact(uint256,uint256,uint256)"](
"6917100025787759640000",
"265724494",
ethers.utils.parseEther("500")
);

// const fuseQuantity = ethers.utils.formatEther(res);
expect(res.maxToken).to.gt(0);
expect(res.maxToken).to.equal(
BigNumber.from("6917100025787759640000").mul(3).div(100)
);
expect(res.tokenOut).to.equal(7717004);
expect(res.maxToken).to.equal(BigNumber.from("6917100025787759640000").mul(6).div(1000));
expect(res.tokenOut).to.equal(1580111);
});

it("should calc quantity with uniswap mock", async () => {
const res = await staking["calcMaxFuseWithPriceImpact(uint256)"](
ethers.utils.parseEther("500")
);
const res = await staking["calcMaxFuseWithPriceImpact(uint256)"](ethers.utils.parseEther("500"));

// const fuseQuantity = ethers.utils.formatEther(res);
expect(res.fuseAmount).to.gt(0);
expect(res.fuseAmount).to.equal(ethers.utils.parseEther("30"));
expect(res.fuseAmount).to.equal(ethers.utils.parseEther("6"));

await uniswapPair.mock.getReserves.returns(
ethers.utils.parseEther("100"),
"500000",
"0"
);
const res2 = await staking["calcMaxFuseWithPriceImpact(uint256)"](
ethers.utils.parseEther("500")
);
await uniswapPair.mock.getReserves.returns(ethers.utils.parseEther("100"), "500000", "0");
const res2 = await staking["calcMaxFuseWithPriceImpact(uint256)"](ethers.utils.parseEther("500"));

expect(res2.fuseAmount).to.equal(ethers.utils.parseEther("3"));
expect(res2.fuseAmount).to.equal(ethers.utils.parseEther("0.6"));
});

it("should calculate gd/usdc quantity with 0 price impact ", async () => {
const res = await staking["calcMaxFuseUSDCWithPriceImpact(uint256)"](
ethers.utils.parseEther("10")
);
const res = await staking["calcMaxFuseUSDCWithPriceImpact(uint256)"](ethers.utils.parseEther("10"));
//exchanging 10 fuse which are equal 2$ USDC should have no significant price impact on usdc/gd swap so we should be able to swap the whole 10
expect(res.maxFuse).to.gt(0);
expect(res.maxFuse).to.equal(ethers.utils.parseEther("10"));
});

it("should detect gd/usdc price impact", async () => {
const res = await staking["calcMaxFuseUSDCWithPriceImpact(uint256)"](
ethers.utils.parseEther("10000")
);
const res = await staking["calcMaxFuseUSDCWithPriceImpact(uint256)"](ethers.utils.parseEther("10000"));
expect(res.maxFuse).to.lt(ethers.utils.parseEther("10000"));
expect(res.maxFuse).to.equal(ethers.utils.parseEther("1618.35")); //on fuse swap it was around 335$ on above gd/usdc reserves that reaches 3% impact, that means 335*5=1675fuse
expect(res.maxFuse).to.equal(ethers.utils.parseEther("323.67")); //on fuse swap it was around 335$ on above gd/usdc reserves that reaches 3% impact, that means 335*5=1675fuse
});

it("should match fuseswap and allow to exchange +-4600 fuse to G$", async () => {
Expand All @@ -141,10 +112,8 @@ describe("FuseStakingV3", () => {
"0"
);

const res = await staking["calcMaxFuseUSDCWithPriceImpact(uint256)"](
ethers.utils.parseEther("10000")
);
expect(res.maxFuse).to.lt(ethers.utils.parseEther("5000"));
expect(res.maxFuse).to.gt(ethers.utils.parseEther("4500"));
const res = await staking["calcMaxFuseUSDCWithPriceImpact(uint256)"](ethers.utils.parseEther("10000"));
expect(res.maxFuse).to.lt(ethers.utils.parseEther("1000"));
expect(res.maxFuse).to.gt(ethers.utils.parseEther("450"));
});
});

0 comments on commit db3ccd3

Please sign in to comment.