Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions contracts/test/SwapRouterInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Unlicensed

pragma solidity 0.7.6;

// For purpose of including perhiphery interfaces for during typechain generation
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
10 changes: 6 additions & 4 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import '@nomiclabs/hardhat-ethers'
import '@nomiclabs/hardhat-etherscan'
import '@nomiclabs/hardhat-waffle'
import '@typechain/hardhat'
import "@nomicfoundation/hardhat-toolbox"
import "@nomicfoundation/hardhat-chai-matchers"
import "hardhat-watcher"
import './scripts/copy-uniswap-v3-artifacts.ts'
import './tasks/hypervisor'
Expand Down Expand Up @@ -75,6 +73,10 @@ const config: HardhatUserConfig = {
// apiKey: process.env.ARBISCAN_APIKEY,
// apiKey: process.env.POLYGONSCAN_APIKEY,
},
typechain: {
outDir: "typechain",
target: "ethers-v5",
},
mocha: {
timeout: 2000000
}
Expand Down
55,175 changes: 17,698 additions & 37,477 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 10 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,25 @@
"@chainlink/contracts": "^0.1.9",
"@ethersproject/abstract-signer": "^5.3.0",
"@openzeppelin/contracts": "^3.4.1-solc-0.7-2",
"@uniswap/v3-core": "*",
"@uniswap/v3-periphery": "*",
"bignumber.js": "^9.0.1",
"prettier": "^2.2.1",
"prettier-plugin-solidity": "^1.0.0-beta.10",
"solhint-plugin-prettier": "0.0.5"
"@uniswap/v3-core": "^1.0.1",
"@uniswap/v3-periphery": "^1.4.3",
"bignumber.js": "^9.0.1"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^3.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@openzeppelin/test-helpers": "^0.5.10",
"@typechain/ethers-v5": "^7.0.0",
"@typechain/hardhat": "^2.1.0",
"@types/chai": "^4.2.16",
"@types/fs-extra": "^9.0.11",
"@types/mocha": "^8.2.2",
"chai": "^4.3.4",
"decimal.js": "^10.2.1",
"dotenv": "^8.2.0",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.1.3",
"fs-extra": "^7.0.1",
"hardhat": "^2.2.0",
"hardhat-gas-reporter": "^1.0.8",
"hardhat-typechain": "^0.3.5",
"hardhat-watcher": "^2.1.1",
"mocha": "^7.2.0",
"prettier": "^2.2.1",
"prettier-plugin-solidity": "*",
"hardhat-watcher": "^2.5.0",
"prettier": "^2.8.4",
"prettier-plugin-solidity": "^1.1.3",
"solc-0.7": "npm:solc@^0.7.6",
"solhint": "^3.3.4",
"solhint-plugin-prettier": "^0.0.5",
"ts-generator": "^0.1.1",
"ts-node": "^8.10.2",
"typechain": "^5.0.0",
"typescript": "^4.2.4"
"solhint-plugin-prettier": "^0.0.5"
}
}
28 changes: 16 additions & 12 deletions test/deposit_withdraw.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ethers, waffle } from 'hardhat'
import { ethers } from 'hardhat'
import { BigNumber, BigNumberish, constants } from 'ethers'
import chai from 'chai'
import { expect } from 'chai'
import { fixture, hypervisorTestFixture } from "./shared/fixtures"
import { solidity } from "ethereum-waffle"

chai.use(solidity)
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"

import {
FeeAmount,
Expand All @@ -25,11 +24,8 @@ import {
TestERC20
} from "../typechain"

const createFixtureLoader = waffle.createFixtureLoader

describe('Hypervisor', () => {
const [wallet, alice, bob, carol, other,
user0, user1, user2, user3, user4] = waffle.provider.getWallets()

let factory: IUniswapV3Factory
let router: ISwapRouter
Expand All @@ -39,13 +35,21 @@ describe('Hypervisor', () => {
let uniswapPool: IUniswapV3Pool
let hypervisorFactory: HypervisorFactory
let hypervisor: Hypervisor

let loadFixture: ReturnType<typeof createFixtureLoader>
before('create fixture loader', async () => {
loadFixture = createFixtureLoader([wallet, other])
})

// Wallets
let wallet: SignerWithAddress
let alice: SignerWithAddress
let bob: SignerWithAddress
let carol: SignerWithAddress
let other: SignerWithAddress
let user0: SignerWithAddress
let user1: SignerWithAddress
let user2: SignerWithAddress
let user3: SignerWithAddress
let user4: SignerWithAddress

beforeEach('deploy contracts', async () => {
[wallet, alice, bob, carol, other, user0, user1, user2, user3, user4] = await ethers.getSigners();
({ token0, token1, token2, factory, router, hypervisorFactory } = await loadFixture(hypervisorTestFixture))
await hypervisorFactory.createHypervisor(token0.address, token1.address, FeeAmount.MEDIUM,"Test Visor", "TVR");
const hypervisorAddress = await hypervisorFactory.getHypervisor(token0.address, token1.address, FeeAmount.MEDIUM)
Expand Down
22 changes: 15 additions & 7 deletions test/shared/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { BigNumber } from 'ethers'
import { ethers } from 'hardhat'

import {
abi as FACTORY_ABI,
bytecode as FACTORY_BYTECODE,
} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json'

import {
abi as SWAPROUTER_ABI,
bytecode as SWAPROUTER_BYTECODE,
} from '@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json'

import {
TestERC20,
IUniswapV3Factory,
Expand All @@ -10,21 +20,19 @@ import {
TokeHypervisorFactory
} from "../../typechain";

import { Fixture } from 'ethereum-waffle'

interface UniswapV3Fixture {
factory: IUniswapV3Factory
router: ISwapRouter
}

async function uniswapV3Fixture(): Promise<UniswapV3Fixture> {
const factoryFactory = await ethers.getContractFactory('UniswapV3Factory')
const factoryFactory = await ethers.getContractFactory(FACTORY_ABI, FACTORY_BYTECODE)
const factory = (await factoryFactory.deploy()) as IUniswapV3Factory

const tokenFactory = await ethers.getContractFactory('TestERC20')
const WETH = (await tokenFactory.deploy(BigNumber.from(2).pow(255))) as TestERC20 // TODO: change to real WETH

const routerFactory = await ethers.getContractFactory('SwapRouter')
const routerFactory = await ethers.getContractFactory(SWAPROUTER_ABI, SWAPROUTER_BYTECODE)
const router = (await routerFactory.deploy(factory.address, WETH.address)) as ISwapRouter
return { factory, router }
}
Expand Down Expand Up @@ -81,7 +89,7 @@ async function ourFactoryFixture(): Promise<OurFactoryFixture> {

type allContractsFixture = UniswapV3Fixture & TokensFixture & OurFactoryFixture

export const fixture: Fixture<allContractsFixture> = async function (): Promise<allContractsFixture> {
export async function fixture(): Promise<allContractsFixture> {
const { factory, router } = await uniswapV3Fixture()
const { token0, token1, token2 } = await tokensFixture()
const { ourFactory } = await ourFactoryFixture()
Expand All @@ -98,7 +106,7 @@ export const fixture: Fixture<allContractsFixture> = async function (): Promise<

type HypervisorTestFixture = UniswapV3Fixture & TokensFixture & HypervisorFactoryFixture

export const hypervisorTestFixture: Fixture<HypervisorTestFixture> = async function (): Promise<HypervisorTestFixture> {
export async function hypervisorTestFixture(): Promise<HypervisorTestFixture> {
const { factory, router } = await uniswapV3Fixture()
const { token0, token1, token2 } = await tokensFixture()
const { hypervisorFactory } = await hypervisorFactoryFixture(factory)
Expand All @@ -115,7 +123,7 @@ export const hypervisorTestFixture: Fixture<HypervisorTestFixture> = async funct

type TokeHypervisorTestFixture = UniswapV3Fixture & TokensFixture & TokeHypervisorFactoryFixture

export const tokeHypervisorTestFixture: Fixture<TokeHypervisorTestFixture> = async function (): Promise<TokeHypervisorTestFixture> {
export async function tokeHypervisorTestFixture(): Promise<TokeHypervisorTestFixture> {
const { factory, router } = await uniswapV3Fixture()
const { token0, token1, token2 } = await tokensFixture()
const { tokeHypervisorFactory } = await tokeHypervisorFactoryFixture(factory)
Expand Down
27 changes: 15 additions & 12 deletions test/tokemak.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ethers, waffle } from 'hardhat'
import { ethers } from 'hardhat'
import { BigNumber, BigNumberish, constants } from 'ethers'
import chai from 'chai'
import { expect } from 'chai'
import { fixture, tokeHypervisorTestFixture } from "./shared/fixtures"
import { solidity } from "ethereum-waffle"
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"

chai.use(solidity)

import {
FeeAmount,
Expand All @@ -25,12 +24,8 @@ import {
TestERC20
} from "../typechain"

const createFixtureLoader = waffle.createFixtureLoader

describe('Tokemak', () => {
const [wallet, alice, manager, carol, other,
user0, user1, user2, user3, user4] = waffle.provider.getWallets()

const minSqrtPrice = 4295128740;
const maxSqrtPrice = 1461446703485210103287273052203988822378723970341;

Expand All @@ -43,12 +38,20 @@ describe('Tokemak', () => {
let tokeHypervisorFactory: TokeHypervisorFactory
let tokeHypervisor: TokeHypervisor

let loadFixture: ReturnType<typeof createFixtureLoader>
before('create fixture loader', async () => {
loadFixture = createFixtureLoader([wallet, other])
})
// Wallets
let wallet: SignerWithAddress
let alice: SignerWithAddress
let manager: SignerWithAddress
let carol: SignerWithAddress
let other: SignerWithAddress
let user0: SignerWithAddress
let user1: SignerWithAddress
let user2: SignerWithAddress
let user3: SignerWithAddress
let user4: SignerWithAddress

beforeEach('deploy contracts', async () => {
[wallet, alice, manager, carol, other, user0, user1, user2, user3, user4] = await ethers.getSigners();
({ token0, token1, token2, factory, router, tokeHypervisorFactory } = await loadFixture(tokeHypervisorTestFixture))
await tokeHypervisorFactory.createHypervisor(token0.address, token1.address, FeeAmount.MEDIUM,"Test Visor", "TVR");
const tokeHypervisorAddress = await tokeHypervisorFactory.getHypervisor(token0.address, token1.address, FeeAmount.MEDIUM)
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"typeRoots": ["./typechain", "./node_modules/@types"],
"types": ["@nomiclabs/hardhat-ethers", "@nomiclabs/hardhat-waffle"]
"resolveJsonModule": true
},
"include": ["./scripts", "./test"],
"include": ["./scripts", "./test", "./typechain"],
"files": ["./hardhat.config.ts"]
}
Loading