Skip to content

Commit

Permalink
backend ts init
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavorix committed Aug 10, 2022
1 parent 856f86f commit ea6ff48
Show file tree
Hide file tree
Showing 18 changed files with 958 additions and 323 deletions.
30 changes: 24 additions & 6 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
node_modules
.env
# vscode
.vscode

# hardhat
artifacts
cache
.vscode
deployments
gas-report.txt
node_modules
coverage
.notes.md
coverage.json
coverage.json

# don't push the environment vars!
.env

# Generated files
bin/
gen/
out/
build/

# Log Files
*.log

typechain
typechain-types

# gas
gas-report.txt
3 changes: 3 additions & 0 deletions backend/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hardhat.config.ts
scripts
test
5 changes: 1 addition & 4 deletions backend/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
node_modules
artifacts
cache
coverage*
gasReporterOutput.json
package.json
img
.env
.*
README.md
coverage.json
deployments
.next
deployments
8 changes: 4 additions & 4 deletions backend/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"printWidth": 99
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"printWidth": 99
}
7 changes: 5 additions & 2 deletions backend/contracts/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ contract Pool is ReentrancyGuard, LiquidityToken {
) external nonReentrant returns (uint256 amountOut) {
(uint120 _reserve1, uint120 _reserve2, ) = getReserves(); // gas savings
require(_amountOut1 > 0 || _amountOut2 > 0, "POOL: SWAP_INSUFFICIENT_AMOUNT");
require(_amountOut1 < _reserve1 && _amountOut2 < _reserve2, "POOL: SWAP_INSUFFICIENT_LIQUIDITY");
require(
_amountOut1 < _reserve1 && _amountOut2 < _reserve2,
"POOL: SWAP_INSUFFICIENT_LIQUIDITY"
);

(address _token1, address _token2) = getTokens(); // gas savings
if (_amountOut1 > 0) HelperLibrary._safeTranfer(_token1, _to, _amountOut1);
Expand All @@ -131,7 +134,7 @@ contract Pool is ReentrancyGuard, LiquidityToken {
? (_reserve1, _reserve2)
: (_reserve2, _reserve1);

uint256 amountInWithFee = _amountIn * (10000 - fee);
uint256 amountInWithFee = _amountIn * (10000 - _fee);
uint256 numerator = (reserveOut * amountInWithFee);
uint256 denominator = (reserveIn * 10000) + amountInWithFee;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
const { network } = require("hardhat");
const {
import { DeployFunction } from "hardhat-deploy/types";
import { network } from "hardhat";
import {
networkConfig,
developmentChains,
VERIFICATION_BLOCK_CONFIRMATIONS,
networkConfig,
} = require("../helper-hardhat-config");
const { verify } = require("../utils/verify");
} from "../helper-hardhat-config";
import { verify } from "../utils/verify";

const deployFunction: DeployFunction = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;

module.exports = async function ({ getNamedAccounts, deployments }) {
const { deployer } = await getNamedAccounts();
const { log, deploy } = deployments;
const waitConfirmations = !developmentChains.includes(network.name)
? VERIFICATION_BLOCK_CONFIRMATIONS
: 1;
const chainId: number | undefined = network.config.chainId;
if (!chainId) return;

const waitConfirmations: number = developmentChains.includes(network.name)
? 1
: VERIFICATION_BLOCK_CONFIRMATIONS;

log("-----------------------------------------------------------");
log("deploying factory......");
Expand Down Expand Up @@ -44,8 +49,11 @@ module.exports = async function ({ getNamedAccounts, deployments }) {
});

if (!developmentChains.includes(network.name)) {
await verify(factory.address, args);
await verify(factory.address, []);
await verify(router.address, [factory.address]);
await verify(token.address, []);
}
};

export default deployFunction;
deployFunction.tags = ["all", "main"];
60 changes: 60 additions & 0 deletions backend/deploy/02_Deploy_Tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { DeployFunction } from "hardhat-deploy/types";
import { network } from "hardhat";
import {
networkConfig,
developmentChains,
VERIFICATION_BLOCK_CONFIRMATIONS,
} from "../helper-hardhat-config";
import { verify } from "../utils/verify";

const deployFunction: DeployFunction = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;

const { deployer } = await getNamedAccounts();
const chainId: number | undefined = network.config.chainId;
if (!chainId) return;

const waitConfirmations: number = developmentChains.includes(network.name)
? 1
: VERIFICATION_BLOCK_CONFIRMATIONS;

log("-----------------------------------------------------------");
log("deploying factory......");

const weth = await deploy("WETH", {
from: deployer,
log: true,
args: [],
waitConfirmations: waitConfirmations,
});

log("-----------------------------------------------------------");
log("Deploying Router....");

const wbtc = await deploy("WBTC", {
from: deployer,
log: true,
args: [],
waitConfirmations: waitConfirmations,
});

log("-----------------------------------------------------------");
log("Deploying liquidity token....");

const usdc = await deploy("USDC", {
from: deployer,
log: true,
args: [],
waitConfirmations: waitConfirmations,
});

const dai = await deploy("DAI", {
from: deployer,
log: true,
args: [],
waitConfirmations: waitConfirmations,
});
};

export default deployFunction;
deployFunction.tags = ["all", "tokens"];
Empty file.
55 changes: 31 additions & 24 deletions backend/hardhat.config.js → backend/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-etherscan");
require("hardhat-deploy");
require("solidity-coverage");
require("hardhat-gas-reporter");
require("hardhat-contract-sizer");
require("dotenv").config();
require("@nomiclabs/hardhat-ganache");
import * as dotenv from "dotenv";

/**
* @type import('hardhat/config').HardhatUserConfig
*/
import type { HardhatUserConfig } from "hardhat/config";
import "@nomiclabs/hardhat-waffle";
import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan";
import "@typechain/hardhat";
import "hardhat-deploy";
import "solidity-coverage";
import "hardhat-gas-reporter";
import "hardhat-contract-sizer";

dotenv.config();

const MUMBAI_RPC_URL = process.env.MUMBAI_RPC_URL;
const ROPSTEN_RPC_URL = process.env.ROPSTEN_RPC_URL;
Expand All @@ -22,47 +23,44 @@ const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
const POLYGONSCAN_API_KEY = process.env.POLYGONSCAN_API_KEY;
const REPORT_GAS = process.env.REPORT_GAS || false;

module.exports = {
const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 31337,
forking: {
url: MUMBAI_RPC_URL,
url: MUMBAI_RPC_URL!,
enabled: true,
},
chainId: 31337,
},
localhost: {
chainId: 31337,
},
rinkeby: {
url: RINKEBY_RPC_URL,
accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
saveDeployments: true,
chainId: 4,
},
mumbai: {
url: MUMBAI_RPC_URL,
accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
saveDeployments: true,
chainId: 80001,
},
ropsten: {
url: ROPSTEN_RPC_URL,
accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
chainId: 3,
},
},
etherscan: {
apiKey: {
rinkeby: ETHERSCAN_API_KEY,
ropsten: ETHERSCAN_API_KEY,
polygonMumbai: POLYGONSCAN_API_KEY,
rinkeby: ETHERSCAN_API_KEY!,
kovan: ETHERSCAN_API_KEY!,
polygon: POLYGONSCAN_API_KEY!,
},
},
gasReporter: {
enabled: REPORT_GAS,
enabled: process.env.REPORT_GAS !== undefined,
currency: "USD",
outputFile: "gas-report.txt",
noColors: true,
// coinmarketcap: process.env.COINMARKETCAP_API_KEY,
},
namedAccounts: {
deployer: {
Expand All @@ -78,6 +76,9 @@ module.exports = {
{
version: "0.8.7",
},
{
version: "0.6.6",
},
{
version: "0.4.24",
},
Expand All @@ -86,4 +87,10 @@ module.exports = {
mocha: {
timeout: 200000, // 200 seconds max for running tests
},
typechain: {
outDir: "typechain",
target: "ethers-v5",
},
};

export default config;
Loading

0 comments on commit ea6ff48

Please sign in to comment.