import { BigNumber } from 'ethers' import { ethers } from 'hardhat' import { MockTimeAtlantiswapPool } from '../../typechain/MockTimeAtlantiswapPool' import { TestERC20 } from '../../typechain/TestERC20' import { AtlantiswapFactory } from '../../typechain/AtlantiswapFactory' import { TestAtlantiswapCallee } from '../../typechain/TestAtlantiswapCallee' import { TestAtlantiswapRouter } from '../../typechain/TestAtlantiswapRouter' import { MockTimeAtlantiswapPoolDeployer } from '../../typechain/MockTimeAtlantiswapPoolDeployer' import { Fixture } from 'ethereum-waffle' interface FactoryFixture { factory: AtlantiswapFactory } async function factoryFixture(): Promise { const factoryFactory = await ethers.getContractFactory('AtlantiswapFactory') const factory = (await factoryFactory.deploy()) as AtlantiswapFactory return { factory } } interface TokensFixture { token0: TestERC20 token1: TestERC20 token2: TestERC20 } async function tokensFixture(): Promise { const tokenFactory = await ethers.getContractFactory('TestERC20') const tokenA = (await tokenFactory.deploy(BigNumber.from(2).pow(255))) as TestERC20 const tokenB = (await tokenFactory.deploy(BigNumber.from(2).pow(255))) as TestERC20 const tokenC = (await tokenFactory.deploy(BigNumber.from(2).pow(255))) as TestERC20 const [token0, token1, token2] = [tokenA, tokenB, tokenC].sort((tokenA, tokenB) => tokenA.address.toLowerCase() < tokenB.address.toLowerCase() ? -1 : 1 ) return { token0, token1, token2 } } type TokensAndFactoryFixture = FactoryFixture & TokensFixture interface PoolFixture extends TokensAndFactoryFixture { swapTargetCallee: TestAtlantiswapCallee swapTargetRouter: TestAtlantiswapRouter createPool( fee: number, tickSpacing: number, firstToken?: TestERC20, secondToken?: TestERC20 ): Promise } // Monday, October 5, 2020 9:00:00 AM GMT-05:00 export const TEST_POOL_START_TIME = 1601906400 export const poolFixture: Fixture = async function (): Promise { const { factory } = await factoryFixture() const { token0, token1, token2 } = await tokensFixture() const MockTimeAtlantiswapPoolDeployerFactory = await ethers.getContractFactory('MockTimeAtlantiswapPoolDeployer') const MockTimeAtlantiswapPoolFactory = await ethers.getContractFactory('MockTimeAtlantiswapPool') const calleeContractFactory = await ethers.getContractFactory('TestAtlantiswapCallee') const routerContractFactory = await ethers.getContractFactory('TestAtlantiswapRouter') const swapTargetCallee = (await calleeContractFactory.deploy()) as TestAtlantiswapCallee const swapTargetRouter = (await routerContractFactory.deploy()) as TestAtlantiswapRouter return { token0, token1, token2, factory, swapTargetCallee, swapTargetRouter, createPool: async (fee, tickSpacing, firstToken = token0, secondToken = token1) => { const mockTimePoolDeployer = (await MockTimeAtlantiswapPoolDeployerFactory.deploy()) as MockTimeAtlantiswapPoolDeployer const tx = await mockTimePoolDeployer.deploy( factory.address, firstToken.address, secondToken.address, fee, tickSpacing ) const receipt = await tx.wait() const poolAddress = receipt.events?.[0].args?.pool as string return MockTimeAtlantiswapPoolFactory.attach(poolAddress) as MockTimeAtlantiswapPool }, } }