mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 00:44:06 +00:00
Script to deploy uniswap contracts locally for testing (#118)
* Initial setup with hardhat. * Deploy Factory contract. * Deploy tokens and create pool using factory contract. * Deploy contract to private network. * Implement separate scripts for deploying Factory, Token and Pool. Co-authored-by: nikugogoi <95nikass@gmail.com>
This commit is contained in:
co-authored by
nikugogoi
parent
b7ffb7c672
commit
da758aceaa
@@ -0,0 +1 @@
|
||||
ETH_RPC_URL=http://127.0.0.1:8545
|
||||
@@ -0,0 +1,8 @@
|
||||
node_modules
|
||||
|
||||
#Hardhat files
|
||||
cache
|
||||
artifacts
|
||||
|
||||
# Environment variables
|
||||
.env
|
||||
@@ -1,5 +1,39 @@
|
||||
# Uniswap
|
||||
|
||||
## Instructions
|
||||
|
||||
### Deploy contracts
|
||||
|
||||
```bash
|
||||
# Create .env.
|
||||
$ cp .env.example .env
|
||||
# Set ETH_RPC_URL variable to target chain network.
|
||||
|
||||
# Deploy contracts to private network specified by ETH_RPC_URL
|
||||
$ yarn deploy:factory
|
||||
# Factory deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
|
||||
|
||||
$ yarn deploy:token --name Token0 --symbol TK0
|
||||
# token TK0 deployed to: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
|
||||
|
||||
$ yarn deploy:token --name Token1 --symbol TK1
|
||||
# token TK1 deployed to: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
|
||||
|
||||
$ yarn create:pool --factory 0x5FbDB2315678afecb367f032d93F642f64180aa3 --token0 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --token1 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 --fee 500
|
||||
# Pool deployed to: 0x315244f2680ABa32F27004B67d83E53c8c88F5FE
|
||||
|
||||
|
||||
# For local development.
|
||||
# Start hardhat local network.
|
||||
$ yarn hardhat node
|
||||
|
||||
# Deploy contracts to local network.
|
||||
# Deploy contracts to private network specified by ETH_RPC_URL
|
||||
$ yarn deploy:factory --network localhost
|
||||
$ yarn deploy:token --network localhost --name Token0 --symbol TK0
|
||||
|
||||
```
|
||||
|
||||
## Scripts
|
||||
|
||||
* **generate:schema**
|
||||
@@ -13,6 +47,30 @@
|
||||
$ yarn lint:schema schema/frontend.graphql
|
||||
```
|
||||
|
||||
* **deploy:factory**
|
||||
|
||||
Deploy Factory contract.
|
||||
```bash
|
||||
$ yarn deploy:factory
|
||||
|
||||
# Deploy to hardhat local network.
|
||||
$ yarn deploy --network localhost
|
||||
```
|
||||
|
||||
* **deploy:token**
|
||||
|
||||
Deploy Token contract.
|
||||
```bash
|
||||
$ yarn deploy:token --name TokenName --symbol TKS
|
||||
```
|
||||
|
||||
* **create:pool**
|
||||
|
||||
Create pool with factory contract and tokens.
|
||||
```bash
|
||||
$ yarn create:pool --factory 0xFactoryAddress --token0 0xToken0Address --token1 0xToken1Address --fee 500
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* https://github.com/Uniswap/uniswap-v3-core
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
contract ERC20Token is ERC20 {
|
||||
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {
|
||||
_mint(msg.sender, 1000000000000000000000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'dotenv/config';
|
||||
import { HardhatUserConfig } from "hardhat/config";
|
||||
import "@nomiclabs/hardhat-waffle";
|
||||
|
||||
import './tasks/accounts'
|
||||
import './tasks/deploy-factory'
|
||||
import './tasks/deploy-token'
|
||||
import './tasks/create-pool'
|
||||
|
||||
const config: HardhatUserConfig = {
|
||||
solidity: "0.8.0",
|
||||
networks: {
|
||||
private: {
|
||||
url: process.env.ETH_RPC_URL
|
||||
}
|
||||
},
|
||||
defaultNetwork: 'private'
|
||||
};
|
||||
|
||||
// You need to export an object to set up your config
|
||||
// Go to https://hardhat.org/config/ to learn more
|
||||
export default config;
|
||||
@@ -5,10 +5,29 @@
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"generate:schema": "get-graphql-schema https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-alt > schema/full.graphql",
|
||||
"lint:schema": "graphql-schema-linter"
|
||||
"lint:schema": "graphql-schema-linter",
|
||||
"deploy:factory": "hardhat deploy-factory",
|
||||
"deploy:token": "hardhat deploy-token",
|
||||
"create:pool": "hardhat create-pool"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||
"@types/chai": "^4.2.18",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/node": "^15.14.0",
|
||||
"chai": "^4.3.4",
|
||||
"ethereum-waffle": "^3.3.0",
|
||||
"ethers": "^5.2.0",
|
||||
"get-graphql-schema": "^2.1.2",
|
||||
"graphql-schema-linter": "^2.0.1"
|
||||
"graphql-schema-linter": "^2.0.1",
|
||||
"hardhat": "^2.3.0",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.3.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@openzeppelin/contracts": "^4.2.0",
|
||||
"@uniswap/v3-core": "^1.0.0",
|
||||
"dotenv": "^10.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { task } from "hardhat/config";
|
||||
|
||||
// This is a sample Hardhat task. To learn how to create your own go to
|
||||
// https://hardhat.org/guides/create-task.html
|
||||
task("accounts", "Prints the list of accounts", async (args, hre) => {
|
||||
const accounts: SignerWithAddress[] = await hre.ethers.getSigners();
|
||||
|
||||
for (const account of accounts) {
|
||||
console.log(account.address);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import { task, types } from "hardhat/config";
|
||||
import {
|
||||
abi as FACTORY_ABI,
|
||||
} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json'
|
||||
import { ContractTransaction } from "ethers";
|
||||
|
||||
task("create-pool", "Creates pool using Factory contract")
|
||||
.addParam('factory', 'Address of factory contract', undefined, types.string)
|
||||
.addParam('token0', 'Address of first token contract', undefined, types.string)
|
||||
.addParam('token1', 'Address of second token contract', undefined, types.string)
|
||||
.addParam('fee', "The pool's fee", undefined, types.int)
|
||||
.setAction(async (args, hre) => {
|
||||
const { factory: factoryAddress, token0, token1, fee } = args
|
||||
const [signer] = await hre.ethers.getSigners();
|
||||
const factory = new hre.ethers.Contract(factoryAddress, FACTORY_ABI, signer);
|
||||
const transaction: ContractTransaction = await factory.createPool(token0, token1, fee)
|
||||
const receipt = await transaction.wait();
|
||||
|
||||
if (receipt.events) {
|
||||
const poolCreatedEvent = receipt.events.find(el => el.event === 'PoolCreated');
|
||||
|
||||
if (poolCreatedEvent && poolCreatedEvent.args) {
|
||||
const { pool } = poolCreatedEvent.args;
|
||||
console.log('Pool deployed to:', pool);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { task, types } from "hardhat/config";
|
||||
import {
|
||||
abi as FACTORY_ABI,
|
||||
bytecode as FACTORY_BYTECODE,
|
||||
} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json'
|
||||
|
||||
task("deploy-factory", "Deploys Factory contract")
|
||||
.setAction(async (_, hre) => {
|
||||
const [signer] = await hre.ethers.getSigners();
|
||||
const Factory = new hre.ethers.ContractFactory(FACTORY_ABI , FACTORY_BYTECODE, signer);
|
||||
const factory = await Factory.deploy();
|
||||
await factory.deployed();
|
||||
console.log("Factory deployed to:", factory.address);
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
import { task, types } from "hardhat/config";
|
||||
|
||||
task("deploy-token", "Deploys new token")
|
||||
.addParam('name', 'Name of the token', undefined, types.string)
|
||||
.addParam('symbol', 'Symbol of the token', undefined, types.string)
|
||||
.setAction(async (args, hre) => {
|
||||
const { name, symbol } = args
|
||||
const Token = await hre.ethers.getContractFactory('ERC20Token');
|
||||
const token = await Token.deploy(name, symbol);
|
||||
|
||||
console.log(`Token ${symbol} deployed to:`, token.address)
|
||||
return token;
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||
"lib": [ "ES2020" ], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["src/**/*.test.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user