Skip to content

Commit

Permalink
test(flash-swap): flash borrow other token when token order is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRBerg committed Nov 5, 2021
1 parent 190e0ec commit 5ced780
Showing 1 changed file with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,39 @@ export function shouldBehaveLikeUniswapV2Call(): void {
await this.contracts.uniswapV2Pair.sync();
});

it("flash swaps USDC making no USDC profit and paying the flash swap fee", async function () {
const to: string = this.contracts.underlyingFlashUniswapV2.address;
const oldLiquidatorUsdcBalance = await this.contracts.usdc.balanceOf(this.signers.liquidator.address);
const oldSubsidizerUsdcBalance = await this.contracts.usdc.balanceOf(this.signers.subsidizer.address);
await this.contracts.uniswapV2Pair
.connect(this.signers.liquidator)
.swap(localToken0Amount, localToken1Amount, to, data);
const newLiquidatorUsdcBalance = await this.contracts.usdc.balanceOf(this.signers.liquidator.address);
const newSubsidizerUsdcBalance = await this.contracts.usdc.balanceOf(this.signers.subsidizer.address);
expect(newLiquidatorUsdcBalance).to.equal(oldLiquidatorUsdcBalance);
expect(oldSubsidizerUsdcBalance.sub(newSubsidizerUsdcBalance)).to.equal(feeUnderlyingAmount);
context("when the other token is flash borrowed", function () {
it("reverts", async function () {
const { token0Amount, token1Amount } = await getTokenAmounts.call(this, WBTC("1"), Zero);
const to: string = this.contracts.underlyingFlashUniswapV2.address;
await expect(
this.contracts.uniswapV2Pair
.connect(this.signers.raider)
.swap(token0Amount, token1Amount, to, data),
).to.be.revertedWith(UnderlyingFlashUniswapV2Errors.FlashBorrowOtherToken);
});
});

context("when the underlying is flash borrowed", function () {
it("flash swaps USDC making no USDC profit and paying the flash swap fee", async function () {
const to: string = this.contracts.underlyingFlashUniswapV2.address;
const oldLiquidatorUsdcBalance = await this.contracts.usdc.balanceOf(
this.signers.liquidator.address,
);
const oldSubsidizerUsdcBalance = await this.contracts.usdc.balanceOf(
this.signers.subsidizer.address,
);
await this.contracts.uniswapV2Pair
.connect(this.signers.liquidator)
.swap(localToken0Amount, localToken1Amount, to, data);
const newLiquidatorUsdcBalance = await this.contracts.usdc.balanceOf(
this.signers.liquidator.address,
);
const newSubsidizerUsdcBalance = await this.contracts.usdc.balanceOf(
this.signers.subsidizer.address,
);
expect(newLiquidatorUsdcBalance).to.equal(oldLiquidatorUsdcBalance);
expect(oldSubsidizerUsdcBalance.sub(newSubsidizerUsdcBalance)).to.equal(feeUnderlyingAmount);
});
});
});

Expand Down

0 comments on commit 5ced780

Please sign in to comment.