Skip to content

Commit 44a940a

Browse files
committed
add more unit tests
1 parent c88ecd5 commit 44a940a

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

test/protocol/integration/amm/ArrakisUniswapV3AmmAdapter.spec.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { BigNumber } from "ethers";
33
import { ether } from "@utils/index";
44
import { Account } from "@utils/test/types";
55
import { Address } from "@utils/types";
6+
import {
7+
ZERO,
8+
} from "@utils/constants";
69
import { AmmModule, ArrakisUniswapV3AmmAdapter } from "@utils/contracts";
710
import DeployHelper from "@utils/deploys";
811
import {
@@ -240,4 +243,113 @@ describe("ArrakisUniswapV3AmmAdapter", () => {
240243
});
241244
});
242245

246+
describe("getProvideLiquidityCalldata", async () => {
247+
let subjectAmmPool: Address;
248+
let subjectComponents: Address[];
249+
let subjectMaxTokensIn: BigNumber[];
250+
let subjectMinLiquidity: BigNumber;
251+
252+
beforeEach(async () => {
253+
subjectAmmPool = arrakisV1Setup.wethDaiPool.address;
254+
subjectComponents = [setup.weth.address, setup.dai.address];
255+
subjectMaxTokensIn = [ether(1), ether(3000)];
256+
const mintAmount = await arrakisV1Setup.wethDaiPool.getMintAmounts(subjectMaxTokensIn[0], subjectMaxTokensIn[1]);
257+
subjectMinLiquidity = mintAmount[2];
258+
});
259+
260+
async function subject(): Promise<any> {
261+
return await arrakisUniswapV3AmmAdapter.getProvideLiquidityCalldata(
262+
owner.address,
263+
subjectAmmPool,
264+
subjectComponents,
265+
subjectMaxTokensIn,
266+
subjectMinLiquidity);
267+
}
268+
269+
it("should return the correct provide liquidity calldata", async () => {
270+
const calldata = await subject();
271+
272+
// Determine how much of each token the _minLiquidity would return
273+
const mintAmount = await arrakisV1Setup.wethDaiPool.getMintAmounts(subjectMaxTokensIn[0], subjectMaxTokensIn[1]);
274+
const amountAMin = mintAmount[0];
275+
const amountBMin = mintAmount[1];
276+
277+
const expectedCallData = arrakisV1Setup.router.interface.encodeFunctionData("addLiquidity", [
278+
subjectAmmPool,
279+
subjectMaxTokensIn[0],
280+
subjectMaxTokensIn[1],
281+
amountAMin,
282+
amountBMin,
283+
owner.address
284+
]);
285+
expect(JSON.stringify(calldata)).to.eq(JSON.stringify([arrakisV1Setup.router.address, ZERO, expectedCallData]));
286+
});
287+
288+
describe("when the either of the _maxTokensIn is zero", async () => {
289+
beforeEach(async () => {
290+
subjectMaxTokensIn = [ZERO, ether(3000)];
291+
});
292+
293+
it("should revert", async () => {
294+
await expect(subject()).to.be.revertedWith("Component quantity must be nonzero");
295+
});
296+
});
297+
298+
describe("when the _minLiquidity is too high", async () => {
299+
beforeEach(async () => {
300+
subjectMinLiquidity = subjectMinLiquidity.mul(2);
301+
});
302+
303+
it("should revert", async () => {
304+
await expect(subject()).to.be.revertedWith("_minLiquidity is too high for input token limit");
305+
});
306+
});
307+
});
308+
309+
describe("getRemoveLiquidityCalldata", async () => {
310+
let subjectAmmPool: Address;
311+
let subjectComponents: Address[];
312+
let subjectMinTokensOut: BigNumber[];
313+
let subjectLiquidity: BigNumber;
314+
315+
beforeEach(async () => {
316+
subjectAmmPool = arrakisV1Setup.wethDaiPool.address;
317+
subjectComponents = [setup.weth.address, setup.dai.address];
318+
subjectLiquidity = await arrakisV1Setup.wethDaiPool.balanceOf(owner.address);
319+
subjectMinTokensOut = [ether(1), ether(3000)];
320+
});
321+
322+
async function subject(): Promise<any> {
323+
return await arrakisUniswapV3AmmAdapter.getRemoveLiquidityCalldata(
324+
owner.address,
325+
subjectAmmPool,
326+
subjectComponents,
327+
subjectMinTokensOut,
328+
subjectLiquidity);
329+
}
330+
331+
it("should return the correct remove liquidity calldata", async () => {
332+
const calldata = await subject();
333+
334+
const expectedCallData = arrakisV1Setup.router.interface.encodeFunctionData("removeLiquidity", [
335+
subjectAmmPool,
336+
subjectLiquidity,
337+
subjectMinTokensOut[0],
338+
subjectMinTokensOut[1],
339+
owner.address
340+
]);
341+
expect(JSON.stringify(calldata)).to.eq(JSON.stringify([arrakisV1Setup.router.address, ZERO, expectedCallData]));
342+
});
343+
344+
describe("when the _liquidity is more than available", async () => {
345+
beforeEach(async () => {
346+
subjectLiquidity = (await arrakisV1Setup.wethDaiPool.balanceOf(owner.address)).add(ether(1));
347+
});
348+
349+
it("should revert", async () => {
350+
await expect(subject()).to.be.revertedWith("_liquidity must be <= to current balance");
351+
});
352+
});
353+
});
354+
243355
});

0 commit comments

Comments
 (0)