Skip to content

Instantly share code, notes, and snippets.

@jtremback
Created February 7, 2021 17:24
Show Gist options
  • Save jtremback/e6878cbfa521690bbd2460a78eba2bd4 to your computer and use it in GitHub Desktop.
Save jtremback/e6878cbfa521690bbd2460a78eba2bd4 to your computer and use it in GitHub Desktop.
import { expect } from "chai"
import {readFileSync} from 'fs'
import { ethers } from "hardhat";
import { Signer } from "ethers";
import { UniswapV2Factory } from "../typechain/UniswapV2Factory";
import { UniswapV2Router02 } from "../typechain/UniswapV2Router02";
import { WETH9 } from "../typechain/WETH9";
import { PSI } from "../typechain/PSI";
import { ChainId, Token, WETH, Fetcher, Route, Router } from '@uniswap/sdk'
let UniswapV2FactoryArtifact = JSON.parse(readFileSync('./node_modules/@uniswap/v2-core/build/UniswapV2Factory.json').toString());
let WETH9Artifact = JSON.parse(readFileSync('./node_modules/@uniswap/v2-periphery/build/WETH9.json').toString());
let UniswapV2Router02Artifact = JSON.parse(readFileSync('./node_modules/@uniswap/v2-periphery/build/UniswapV2Router02.json').toString());
const fe = ethers.utils.formatEther
const pe = ethers.utils.parseEther
describe("Greeter", function() {
it.only("loads uniswap", async function() {
const signers = await ethers.getSigners();
const PSIContract = await ethers.getContractFactory("PSI")
const psi = await PSIContract.deploy() as PSI
const UniswapFactoryContract = ethers.ContractFactory.fromSolidity(UniswapV2FactoryArtifact, signers[0])
const factory = await UniswapFactoryContract.deploy(signers[0].address) as UniswapV2Factory
const WETH9Contract = ethers.ContractFactory.fromSolidity(WETH9Artifact, signers[0])
const weth = await WETH9Contract.deploy() as WETH9
const UniswapRouterContract = ethers.ContractFactory.fromSolidity(UniswapV2Router02Artifact, signers[0])
const router = await UniswapRouterContract.deploy(factory.address, weth.address) as UniswapV2Router02
// --
await factory.createPair(psi.address, weth.address)
await psi.approve(router.address, pe('1001'))
console.log(signers[0].address)
console.log("signer 0 psi balance", (await psi.balanceOf(signers[0].address)).toString())
console.log("signer 0 eth balance", (await signers[0].provider.getBalance(signers[0].address)).toString())
console.log(pe('1000').toString())
await router.addLiquidityETH(psi.address,
pe('1000'), pe('1000'), pe('1'), "0x0000000000000000000000000000000000000000", 253402300800, { value: pe('2') })
const PSI = new Token(ChainId.MAINNET, psi.address, 18)
const pair = await Fetcher.fetchPairData(PSI, WETH[PSI.chainId])
// --
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment