import { Wallet , Contract } from 'ethers' ; import { Web3Provider } from 'ethers/providers' ; import { deployContract } from 'ethereum-waffle' ; import { expandTo18Decimals } from './utilities' ; import PancakeFactory from '@uniswap/v2-core/build/PancakeFactory.json' ; import IPancakePair from '@uniswap/v2-core/build/IPancakePair.json' ; import ERC20 from '../../build/ERC20.json' ; import WETH9 from '../../build/WETH9.json' ; import UniswapV1Exchange from '../../build/UniswapV1Exchange.json' ; import UniswapV1Factory from '../../build/UniswapV1Factory.json' ; import PancakeRouter01 from '../../build/PancakeRouter01.json' ; import PancakeMigrator from '../../build/PancakeMigrator.json' ; import PancakeRouter02 from '../../build/PancakeRouter02.json' ; import RouterEventEmitter from '../../build/RouterEventEmitter.json' ; const overrides = { gasLimit : 9999999 } ; interface V2Fixture { token0 : Contract ; token1 : Contract ; WETH : Contract ; WETHPartner : Contract ; factoryV1 : Contract ; factoryV2 : Contract ; router01 : Contract ; router02 : Contract ; routerEventEmitter : Contract ; router : Contract ; migrator : Contract ; WETHExchangeV1 : Contract ; pair : Contract ; WETHPair : Contract ; } export async function v2Fixture ( provider , [ wallet ] ) { const tokenA = await deployContract ( wallet , ERC20 , [ expandTo18Decimals ( 10000 ) ] ) ; const tokenB = await deployContract ( wallet , ERC20 , [ expandTo18Decimals ( 10000 ) ] ) ; const WETH = await deployContract ( wallet , WETH9 ) ; const WETHPartner = await deployContract ( wallet , ERC20 , [ expandTo18Decimals ( 10000 ) ] ) ; const factoryV1 = await deployContract ( wallet , UniswapV1Factory , [ ] ) ; await factoryV1 . initializeFactory ( ( await deployContract ( wallet , UniswapV1Exchange , [ ] ) ) . address ) ; const factoryV2 = await deployContract ( wallet , PancakeFactory , [ wallet . address ] ) ; const router01 = await deployContract ( wallet , PancakeRouter01 , [ factoryV2 . address , WETH . address ] , overrides ) ; const router02 = await deployContract ( wallet , PancakeRouter02 , [ factoryV2 . address , WETH . address ] , overrides ) ; const routerEventEmitter = await deployContract ( wallet , RouterEventEmitter , [ ] ) ; const migrator = await deployContract ( wallet , PancakeMigrator , [ factoryV1 . address , router01 . address ] , overrides ) ; await factoryV1 . createExchange ( WETHPartner . address , overrides ) ; const WETHExchangeV1Address = await factoryV1 . getExchange ( WETHPartner . address ) ; const WETHExchangeV1 = new Contract ( WETHExchangeV1Address , JSON . stringify ( UniswapV1Exchange . abi ) , provider ) . connect ( wallet ) ; await factoryV2 . createPair ( tokenA . address , tokenB . address ) ; const pairAddress = await factoryV2 . getPair ( tokenA . address , tokenB . address ) ; const pair = new Contract ( pairAddress , JSON . stringify ( IPancakePair . abi ) , provider ) . connect ( wallet ) ; const token0Address = await pair . token0 ( ) ; const token0 = tokenA . address === token0Address ? tokenA : tokenB ; const token1 = tokenA . address === token0Address ? tokenB : tokenA ; await factoryV2 . createPair ( WETH . address , WETHPartner . address ) ; const WETHPairAddress = await factoryV2 . getPair ( WETH . address , WETHPartner . address ) ; const WETHPair = new Contract ( WETHPairAddress , JSON . stringify ( IPancakePair . abi ) , provider ) . connect ( wallet ) ; return { token0 , token1 , WETH , WETHPartner , factoryV1 , factoryV2 , router01 , router02 , router : router02 , routerEventEmitter , migrator , WETHExchangeV1 , pair , WETHPair } ; }