import { ethers , run , ethereum } from "@nomiclabs/buidler" ; import { deployBalancerPool , deployBalancerFactory , linkArtifact , TimeTraveler } from "../utils" ; import { parseEther , BigNumber , bigNumberify } from "ethers/utils" ; import { Signer , Wallet , utils , constants , ContractTransaction } from "ethers" ; import chai from "chai" ; import { deployContract , solidity } from "ethereum-waffle" ; import { Ierc20Factory } from "../typechain/IERC20Factory" ; import { Ierc20 } from "../typechain/IERC20" ; import Pv2SmartPoolArtifact from "../artifacts/Pv2SmartPool.json" ; import MindfulProxyArtifact from "../artifacts/MindfulProxy.json" ; import PProxiedFactoryArtifact from "../artifacts/PProxiedFactory.json" ; import { MindfulProxyFactory } from "../typechain/MindfulProxyFactory" ; import { MindfulProxy } from "../typechain/MindfulProxy" ; import { PProxiedFactory } from "../typechain/PProxiedFactory" ; import { Pv2SmartPool } from "../typechain/PV2SmartPool" ; import { MockTokenFactory } from "@pie-dao/mock-contracts/dist/typechain/MockTokenFactory" ; import { MockToken } from "@pie-dao/mock-contracts/typechain/MockToken" ; import { Ipv2SmartPool } from "../typechain/Ipv2SmartPool" ; import { Ipv2SmartPoolFactory } from "../typechain/Ipv2SmartPoolFactory" ; chai . use ( solidity ) ; const { expect } = chai ; const PLACE_HOLDER_ADDRESS = "0x0000000000000000000000000000000000000001" ; const SMART_POOL_FACTORY = "0xed52D8E202401645eDAD1c0AA21e872498ce47D0" ; const WHALE_ACCOUNT = "0xF977814e90dA44bFA03b6295A0616a897441aceC" ; const BAT_TOKEN = "0x0d8775f648430679a709e98d2b0cb6250d2887ef" ; const UNI_TOKEN = "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984" ; const LINK_TOKEN = "0x514910771af9ca656af840dff83e8264ecf986ca" ; const NAME = "DeFi Energy Chakra" ; const SYMBOL = "DEC" ; const INITIAL_SUPPLY = constants . WeiPerEther ; const TOKENS = [ BAT_TOKEN , LINK_TOKEN , UNI_TOKEN ] ; const AMOUNTS = [ constants . WeiPerEther . mul ( 10 ) , constants . WeiPerEther . mul ( 10 ) , constants . WeiPerEther . mul ( 10 ) ] ; const WEIGHTS = [ constants . WeiPerEther . mul ( 3 ) , constants . WeiPerEther . mul ( 3 ) , constants . WeiPerEther . mul ( 3 ) ] ; const timeTraveler = new TimeTraveler ( ethereum ) ; describe ( "MAINNET TEST" , function ( ) { this . timeout ( 10000000 ) ; let signers ; let account ; let whaleSigner ; let mindfulProxy ; let pProxiedFactory ; let mindfulProxyWhaleSigner ; let smartpool ; let smartpoolProxy ; before ( async ( ) => { signers = await ethers . signers ( ) ; const provider = new ethers . providers . JsonRpcProvider ( ) ; whaleSigner = provider . getSigner ( WHALE_ACCOUNT ) ; console . log ( "whale address" , whaleSigner . getAddress ( ) ) ; account = await signers [ 0 ] . getAddress ( ) ; console . log ( "account" , account ) ; const mindfulProxyDeployer = new ethers . ContractFactory ( MindfulProxyArtifact . abi , MindfulProxyArtifact . bytecode , signers [ 0 ] ) ; mindfulProxy = await mindfulProxyDeployer . deploy ( ) ; console . log ( "deployed mindful proxy" , mindfulProxy . address ) ; const pProxiedDeployer = new ethers . ContractFactory ( PProxiedFactoryArtifact . abi , PProxiedFactoryArtifact . bytecode , signers [ 0 ] ) ; pProxiedFactory = await pProxiedDeployer . deploy ( ) ; mindfulProxyWhaleSigner = MindfulProxyFactory . connect ( mindfulProxy . address , whaleSigner ) ; const libraries = await run ( "deploy-libraries" ) ; console . log ( "Libs deployed" ) ; const linkedArtifact = linkArtifact ( Pv2SmartPoolArtifact , libraries ) ; const smartPoolDeployer = new ethers . ContractFactory ( linkedArtifact . abi , linkedArtifact . bytecode , signers [ 0 ] ) ; smartpool = await smartPoolDeployer . deploy ( ) ; console . log ( "smartpool deployed" , smartpool . address ) ; await smartpool . init ( PLACE_HOLDER_ADDRESS , "IMP" , "IMP" , 1337 ) ; console . log ( "Should get here" ) ; console . log ( "PProxiedFactory.address" , pProxiedFactory . address ) ; console . log ( "Creating balancerfactory" ) ; const balancerFactoryAddress = await deployBalancerFactory ( signers [ 0 ] ) ; await mindfulProxy . init ( pProxiedFactory . address , balancerFactoryAddress , smartpool . address ) ; console . log ( "end of setup" ) ; await timeTraveler . snapshot ( ) ; } ) ; beforeEach ( async ( ) => { await timeTraveler . snapshot ( ) ; } ) ; afterEach ( async ( ) => { await timeTraveler . revertSnapshot ( ) ; } ) ; it ( `Full execution lifecycle` , async ( ) => { for ( let i = 0 ; i < TOKENS . length ; i ++ ) { const token = Ierc20Factory . connect ( TOKENS [ i ] , whaleSigner ) ; console . log ( "token" , token . address ) ; console . log ( "balance" , ( await token . balanceOf ( WHALE_ACCOUNT ) ) . toString ( ) ) ; await token . approve ( pProxiedFactory . address , constants . MaxUint256 ) ; console . log ( "balance" , ( await token . balanceOf ( WHALE_ACCOUNT ) ) . toString ( ) ) ; } console . log ( "RIGHT BEFORE" ) ; console . log ( "mindfulProxyWhaleSigner" , mindfulProxyWhaleSigner ) ; console . log ( "isPaused" , await mindfulProxyWhaleSigner . isPaused ( ) ) ; let tx = await mindfulProxyWhaleSigner . deployChakra ( NAME , SYMBOL , INITIAL_SUPPLY , TOKENS , AMOUNTS , WEIGHTS , INITIAL_SUPPLY , { gasLimit : 100000000 } ) ; console . log ( "tx" , tx ) ; console . log ( "RIGHT AFTER" ) ; expect ( ( await mindfulProxy . getChakras ( ) ) . length ) . to . eq ( 1 ) ; smartpoolProxy = Ipv2SmartPoolFactory . connect ( await mindfulProxy . chakras ( 0 ) , whaleSigner ) ; console . log ( "chakras" , await mindfulProxy . getChakras ( ) ) ; } ) ; } ) ;