diff --git a/test/integration/MeTokenRegistry/ResubscribeCurveDetails.ts b/test/integration/MeTokenRegistry/ResubscribeCurveDetails.ts index 1372b7ee..a9fc418c 100644 --- a/test/integration/MeTokenRegistry/ResubscribeCurveDetails.ts +++ b/test/integration/MeTokenRegistry/ResubscribeCurveDetails.ts @@ -1,3 +1,4 @@ +// TODO add tests of burn fees import { ethers, getNamedAccounts } from "hardhat"; import { hubSetup } from "../../utils/hubSetup"; import { @@ -8,6 +9,7 @@ import { toETHNumber, weightedAverageSimulation, calculateTokenReturnedFromZero, + fromETHNumber, } from "../../utils/helpers"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { BigNumber, ContractTransaction, Signer } from "ethers"; @@ -23,6 +25,8 @@ import { MeToken } from "../../../artifacts/types/MeToken"; import { UniswapSingleTransferMigration } from "../../../artifacts/types/UniswapSingleTransferMigration"; import { SingleAssetVault } from "../../../artifacts/types/SingleAssetVault"; import { mineBlock, setAutomine } from "../../utils/hardhatNode"; +import { Fees } from "../../../artifacts/types/Fees"; +import Decimal from "decimal.js"; const setup = async () => { describe("MeToken Resubscribe - Same curve, new Curve Details", () => { @@ -43,6 +47,7 @@ const setup = async () => { let account1: SignerWithAddress; let encodedCurveDetails1: string; let encodedCurveDetails2: string; + let fees: Fees; const hubId1 = 1; const hubId2 = 2; @@ -57,11 +62,13 @@ const setup = async () => { const reserveWeight1 = MAX_WEIGHT / 10; const reserveWeight2 = MAX_WEIGHT / 2; const refundRatio = 5000; - const fees = 3000; + const fee = 3000; const tokenDepositedInETH = 100; const tokenDeposited = ethers.utils.parseEther( tokenDepositedInETH.toString() ); + const burnOwnerFee = 1e8; + const burnBuyerFee = 1e9; before(async () => { let token: ERC20; @@ -84,7 +91,7 @@ const setup = async () => { const earliestSwapTime = block.timestamp + 600 * 60; // 10h in future const encodedMigrationArgs = ethers.utils.defaultAbiCoder.encode( ["uint256", "uint24"], - [earliestSwapTime, fees] + [earliestSwapTime, fee] ); // Register first and second hub @@ -99,6 +106,7 @@ const setup = async () => { account0, account1, meTokenRegistry, + fee: fees, } = await hubSetup( encodedCurveDetails1, encodedVaultArgs, @@ -124,6 +132,8 @@ const setup = async () => { await meTokenRegistry.setWarmup(warmup); await meTokenRegistry.setDuration(duration); await meTokenRegistry.setCooldown(coolDown); + await fees.setBurnOwnerFee(burnOwnerFee); + await fees.setBurnBuyerFee(burnBuyerFee); // Deploy uniswap migration and approve it to the registry migration = await deploy( @@ -211,7 +221,7 @@ const setup = async () => { expect(toETHNumber(ownerMeTokenAfter)).to.be.approximately( calculatedReturn, - 0.000000000000001 + 1e-15 ); expect(meTokenTotalSupplyAfter).to.be.equal(ownerMeTokenAfter); expect(vaultDAIAfter.sub(vaultDAIBefore)).to.equal(tokenDeposited); @@ -246,18 +256,29 @@ const setup = async () => { const vaultDAIAfter = await dai.balanceOf(singleAssetVault.address); const meTokenTotalSupplyAfter = await meToken.totalSupply(); + const burnFee = toETHNumber( + (await fees.burnBuyerFee()) + .mul(fromETHNumber(assetsReturned)) + .div(PRECISION) + ); + expect( toETHNumber(buyerDAIAfter.sub(buyerDAIBefore)) - ).to.be.approximately(assetsReturned, 0.000000000000001); + ).to.be.approximately( + new Decimal(assetsReturned).sub(new Decimal(burnFee)).toNumber(), + 1e-15 + ); + expect( + toETHNumber(vaultDAIBefore.sub(vaultDAIAfter)) + ).to.be.approximately( + new Decimal(assetsReturned).sub(new Decimal(burnFee)).toNumber(), + 1e-15 + ); expect(buyerMeTokenAfter).to.equal(0); expect(toETHNumber(meTokenTotalSupplyAfter)).to.be.approximately( toETHNumber(meTokenTotalSupply.div(2)), 1e-18 ); - expect(toETHNumber(vaultDAIBefore.sub(vaultDAIAfter))).to.approximately( - assetsReturned, - 0.000000000000001 - ); }); it("burn() [owner]: assets received based on initial Curve details", async () => { const ownerMeToken = await meToken.balanceOf(account0.address); @@ -288,12 +309,21 @@ const setup = async () => { const vaultDAIAfter = await dai.balanceOf(singleAssetVault.address); const meTokenTotalSupplyAfter = await meToken.totalSupply(); + const burnFee = toETHNumber( + (await fees.burnOwnerFee()) + .mul(fromETHNumber(assetsReturned)) + .div(PRECISION) + ); + expect(vaultDAIBefore.sub(vaultDAIAfter)).to.equal( ownerDAIAfter.sub(ownerDAIBefore) ); expect( toETHNumber(ownerDAIAfter.sub(ownerDAIBefore)) - ).to.be.approximately(assetsReturned, 0.000000000000001); + ).to.be.approximately( + new Decimal(assetsReturned).sub(new Decimal(burnFee)).toNumber(), + 1e-15 + ); expect(ownerMeTokenAfter).to.equal(0); expect(toETHNumber(meTokenTotalSupplyAfter)).to.equal(0); }); @@ -354,7 +384,7 @@ const setup = async () => { expect(toETHNumber(ownerMeTokenAfter)).to.be.approximately( calcWAvgRe, - 0.000000000000001 + 1e-15 ); expect(meTokenTotalSupplyAfter).to.be.equal(ownerMeTokenAfter); expect(vaultDAIAfter.sub(vaultDAIBefore)).to.equal(0); // new asset goes to migration @@ -412,9 +442,18 @@ const setup = async () => { const migrationWETHAfter = await weth.balanceOf(migration.address); const meTokenTotalSupplyAfter = await meToken.totalSupply(); + const burnFee = toETHNumber( + (await fees.burnBuyerFee()) + .mul(fromETHNumber(assetsReturned)) + .div(PRECISION) + ); + expect( toETHNumber(buyerWETHAfter.sub(buyerWETHBefore)) - ).to.be.approximately(assetsReturned, 1e-15); + ).to.be.approximately( + new Decimal(assetsReturned).sub(new Decimal(burnFee)).toNumber(), + 1e-15 + ); expect(buyerMeTokenAfter).to.equal(0); expect(toETHNumber(meTokenTotalSupplyAfter)).to.be.approximately( toETHNumber(meTokenTotalSupply.div(2)), @@ -422,7 +461,10 @@ const setup = async () => { ); expect( toETHNumber(migrationWETHBefore.sub(migrationWETHAfter)) - ).to.approximately(assetsReturned, 1e-15); + ).to.approximately( + new Decimal(assetsReturned).sub(new Decimal(burnFee)).toNumber(), + 1e-15 + ); }); it("burn() [owner]: assets received based on weighted average Curve details", async () => { const ownerMeToken = await meToken.balanceOf(account0.address); @@ -461,23 +503,32 @@ const setup = async () => { (toETHNumber(ownerMeToken) / toETHNumber(meTokenTotalSupply)) * toETHNumber(meTokenDetails.balanceLocked); - await mineBlock(block.timestamp + 1); - await setAutomine(true); await foundry .connect(account0) .burn(meToken.address, ownerMeToken, account0.address); + await mineBlock(block.timestamp + 1); + await setAutomine(true); const ownerMeTokenAfter = await meToken.balanceOf(account0.address); const ownerWETHAfter = await weth.balanceOf(account0.address); const migrationWETHAfter = await weth.balanceOf(migration.address); const meTokenTotalSupplyAfter = await meToken.totalSupply(); + const burnFee = toETHNumber( + (await fees.burnOwnerFee()) + .mul(fromETHNumber(assetsReturned)) + .div(PRECISION) + ); + expect(migrationWETHBefore.sub(migrationWETHAfter)).to.equal( ownerWETHAfter.sub(ownerWETHBefore) ); expect( toETHNumber(ownerWETHAfter.sub(ownerWETHBefore)) - ).to.be.approximately(assetsReturned, 0.000000000000001); + ).to.be.approximately( + new Decimal(assetsReturned).sub(new Decimal(burnFee)).toNumber(), + 1e-15 + ); expect(ownerMeTokenAfter).to.equal(0); expect(toETHNumber(meTokenTotalSupplyAfter)).to.equal(0); }); @@ -516,7 +567,7 @@ const setup = async () => { expect(toETHNumber(ownerMeTokenAfter)).to.be.approximately( calculatedTargetReturn, - 0.000000000000001 + 1e-15 ); expect(meTokenTotalSupplyAfter).to.be.equal(ownerMeTokenAfter); expect(vaultWETHAfter.sub(vaultWETHBefore)).to.equal(tokenDeposited); @@ -554,9 +605,18 @@ const setup = async () => { const vaultWETHAfter = await weth.balanceOf(singleAssetVault.address); const meTokenTotalSupplyAfter = await meToken.totalSupply(); + const burnFee = toETHNumber( + (await fees.burnBuyerFee()) + .mul(fromETHNumber(assetsReturned)) + .div(PRECISION) + ); + expect( toETHNumber(buyerWETHAfter.sub(buyerWETHBefore)) - ).to.be.approximately(assetsReturned, 1e-15); + ).to.be.approximately( + new Decimal(assetsReturned).sub(new Decimal(burnFee)).toNumber(), + 1e-15 + ); expect(buyerMeTokenAfter).to.equal(0); expect(toETHNumber(meTokenTotalSupplyAfter)).to.be.approximately( toETHNumber(meTokenTotalSupply.div(2)), @@ -564,7 +624,10 @@ const setup = async () => { ); expect( toETHNumber(vaultWETHBefore.sub(vaultWETHAfter)) - ).to.approximately(assetsReturned, 1e-15); + ).to.approximately( + new Decimal(assetsReturned).sub(new Decimal(burnFee)).toNumber(), + 1e-15 + ); }); it("burn() [owner]: assets received based on target Curve details", async () => { const ownerMeToken = await meToken.balanceOf(account0.address); @@ -596,12 +659,24 @@ const setup = async () => { const vaultWETHAfter = await dai.balanceOf(singleAssetVault.address); const meTokenTotalSupplyAfter = await meToken.totalSupply(); + const burnFee = toETHNumber( + (await fees.burnOwnerFee()) + .mul(fromETHNumber(assetsReturned)) + .div(PRECISION) + ); + console.log(toETHNumber(vaultWETHBefore.sub(vaultWETHAfter))); + console.log(toETHNumber(ownerWETHAfter.sub(ownerWETHBefore))); + console.log(burnFee); + expect(vaultWETHBefore.sub(vaultWETHAfter)).to.equal( ownerWETHAfter.sub(ownerWETHBefore) ); expect( toETHNumber(ownerWETHAfter.sub(ownerWETHBefore)) - ).to.be.approximately(assetsReturned, 0.000000000000001); + ).to.be.approximately( + new Decimal(assetsReturned).sub(new Decimal(burnFee)).toNumber(), + 1e-15 + ); expect(ownerMeTokenAfter).to.equal(0); expect(toETHNumber(meTokenTotalSupplyAfter)).to.equal(0); });