Skip to content

Commit

Permalink
initialize frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavorix committed Aug 9, 2022
1 parent 4581691 commit dd908c2
Show file tree
Hide file tree
Showing 19 changed files with 2,063 additions and 70 deletions.
12 changes: 5 additions & 7 deletions backend/deploy/01-deploy-dex.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module.exports = async function ({ getNamedAccounts, deployments }) {
? VERIFICATION_BLOCK_CONFIRMATIONS
: 1;

const chainId = network.config.chainId;

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

Expand Down Expand Up @@ -45,9 +43,9 @@ module.exports = async function ({ getNamedAccounts, deployments }) {
waitConfirmations: waitConfirmations,
});

// if (!developmentChains.includes(network.name)) {
// await verify(factory.address, args);
// await verify(router.address, [factory.address]);
// await verify(token.address, []);
// }
if (!developmentChains.includes(network.name)) {
await verify(factory.address, args);
await verify(router.address, [factory.address]);
await verify(token.address, []);
}
};
Empty file.
71 changes: 8 additions & 63 deletions backend/test/dex.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ describe("dex tests", function () {
// prettier-ignore
await wbtcToken.deployed({ "from": user });

const libraryContact = await ethers.getContractFactory("HelperLibrary");
library = await libraryContact.deploy();
// prettier-ignore
await library.deployed({ "from": user });
// const libraryContact = await ethers.getContractFactory("HelperLibrary");
// library = await libraryContact.deploy();
// // prettier-ignore
// await library.deployed({ "from": user });

const factoryContract = await ethers.getContractFactory("Factory");
factory = await factoryContract.deploy();
Expand Down Expand Up @@ -110,23 +110,16 @@ describe("dex tests", function () {
router.removeLiquidity(smallAmount1, wethTokenAddress, daiTokenAddress, 100)
).to.be.revertedWith("ROUTER: Pool doesn't exist");
});
it("removes liquidity and sends back liuidity", async function () {
it("removes liquidity and sends back assets", async function () {
const liquidityBeforeBal = await pool.balanceOf(user.address);
const wethBeforeBal = await wethToken.balanceOf(user.address);
const daiBeforeBal = await daiToken.balanceOf(user.address);
// console.log("wethBeforeBal", ethers.utils.formatEther(wethBeforeBal));

await router.removeLiquidity(smallAmount1, wethTokenAddress, daiTokenAddress, 30);
const liquidityAfterBal = await pool.balanceOf(user.address);
const wethAfterBal = await wethToken.balanceOf(user.address);
const daiAfterBal = await daiToken.balanceOf(user.address);

const poolBal = await pool.balanceOf(pool.address);
// console.log("daiBeforeBal", ethers.utils.formatEther(daiBeforeBal));
// console.log("wethAfterBal", ethers.utils.formatEther(wethAfterBal));
// console.log("daiAfterBal", ethers.utils.formatEther(daiAfterBal));
const totalSupply = await pool.totalSupply();
const reserves = await pool.getReserves();

await expect(liquidityBeforeBal).to.equal(liquidityAfterBal.add(smallAmount1));
assert(wethAfterBal > wethBeforeBal);
assert(daiAfterBal > daiBeforeBal);
Expand All @@ -135,11 +128,9 @@ describe("dex tests", function () {
describe("swap", async function () {
const swapAmount = ethers.utils.parseEther("1");
it("swaps tokens", async function () {
// const liquidityBeforeBal = await pool.balanceOf(user.address);
const wethBeforeBal = await wethToken.balanceOf(user.address);
const daiBeforeBal = await daiToken.balanceOf(user.address);
// console.log("wethBeforeBal", ethers.utils.formatEther(wethBeforeBal));
// const totalSupply = await pool.totalSupply();

const reserves = await pool.getReserves();

const amountInWithFee = swapAmount.mul((10000 - 30).toString());
Expand All @@ -150,32 +141,12 @@ describe("dex tests", function () {
await router._swap(swapAmount, [wethTokenAddress, daiTokenAddress], user.address);
const wethAfterBal = await wethToken.balanceOf(user.address);
const daiAfterBal = await daiToken.balanceOf(user.address);
// const txReceipt = await tx.wait(1);
// const gas = txReceipt.cumulativeGasUsed.mul(txReceipt.effectiveGasPrice);
// const liquidityAfterBal = await pool.balanceOf(user.address);

// const poolBal = await pool.balanceOf(pool.address);
// console.log("wethAfterBal", ethers.utils.formatEther(wethAfterBal));

// console.log(" daiBeforeBal", ethers.utils.formatEther(daiBeforeBal));
// console.log(" daiAfterBal", ethers.utils.formatEther(daiAfterBal));
// console.log(
// "expected amountOut",
// ethers.utils.formatEther(daiAfterBal.sub(daiBeforeBal))
// );
// console.log(" actual amountOut", ethers.utils.formatEther(amountOut));

// console.log(
// "totaldaiBeforeBal",
// ethers.utils.formatEther(daiBeforeBal.add(amountOut))
// );

expect(wethBeforeBal).to.equal(wethAfterBal.add(swapAmount));
expect(daiBeforeBal.add(amountOut)).to.equal(daiAfterBal);
});
it("swaps tokens even if particular pair not exists", async function () {
await router.addLiquidity(daiTokenAddress, usdcToken.address, amount2, amount2, 30);
// await router.addLiquidity(wethToken.address, usdcToken.address, amount1, amount2, 30);

const poolAddress = await factory.getPoolAddress(
daiTokenAddress,
Expand All @@ -186,8 +157,7 @@ describe("dex tests", function () {

const wethBeforeBal = await wethToken.balanceOf(user.address);
const usdcBeforeBal = await usdcToken.balanceOf(user.address);
// console.log("wethBeforeBal", ethers.utils.formatEther(wethBeforeBal));
// const totalSupply = await pool.totalSupply();

const reserves = await pool.getReserves();
const reserves2 = await usdcPool.getReserves();

Expand All @@ -201,10 +171,6 @@ describe("dex tests", function () {
denominator = reserves2._reserve1.mul("10000").add(amountInWithFee);
amountOut = numerator.div(denominator);

// numerator = reserves2._reserve2.mul(amountInWithFee);
// denominator = reserves2._reserve1.mul("10000").add(amountInWithFee);
// const amountOut2 = numerator.div(denominator);

await router._swap(
swapAmount,
[wethTokenAddress, daiTokenAddress, usdcToken.address], // we want weth --> usdc
Expand All @@ -213,27 +179,6 @@ describe("dex tests", function () {

const wethAfterBal = await wethToken.balanceOf(user.address);
const usdcAfterBal = await usdcToken.balanceOf(user.address);
// const txReceipt = await tx.wait(1);
// const gas = txReceipt.cumulativeGasUsed.mul(txReceipt.effectiveGasPrice);
// const liquidityAfterBal = await pool.balanceOf(user.address);

// const poolBal = await pool.balanceOf(pool.address);
// console.log("wethAfterBal", ethers.utils.formatEther(wethAfterBal));

console.log(" usdcBeforeBal", ethers.utils.formatEther(usdcBeforeBal));
console.log(" usdcAfterBal", ethers.utils.formatEther(usdcAfterBal));
console.log("expected amountOut", ethers.utils.formatEther(amountOut));

console.log(
" actual amountOut",
ethers.utils.formatEther(usdcAfterBal.sub(usdcBeforeBal))
);

console.log(
"totalusdcBeforeBal",
ethers.utils.formatEther(usdcBeforeBal.add(amountOut))
);

expect(wethBeforeBal).to.equal(wethAfterBal.add(swapAmount));
expect(usdcBeforeBal.add(amountOut)).to.equal(usdcAfterBal);
});
Expand Down
3 changes: 3 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/out/
/build
6 changes: 6 additions & 0 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
package.json
.env
.*
README.md
.next
6 changes: 6 additions & 0 deletions frontend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"printWidth": 99
}
3 changes: 3 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Frontend in progress....

I'm learning new things for frontend like typescript.
13 changes: 13 additions & 0 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.fallback.fs = false
}
return config
}
}

module.exports = nextConfig
20 changes: 20 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "12.2.4",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"eslint": "8.21.0",
"eslint-config-next": "12.2.4"
}
}
7 changes: 7 additions & 0 deletions frontend/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default MyApp
5 changes: 5 additions & 0 deletions frontend/pages/api/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction

export default function handler(req, res) {
res.status(200).json({ name: 'John Doe' })
}
69 changes: 69 additions & 0 deletions frontend/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'

export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>

<main className={styles.main}>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>

<p className={styles.description}>
Get started by editing{' '}
<code className={styles.code}>pages/index.js</code>
</p>

<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h2>Documentation &rarr;</h2>
<p>Find in-depth information about Next.js features and API.</p>
</a>

<a href="https://nextjs.org/learn" className={styles.card}>
<h2>Learn &rarr;</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>

<a
href="https://github.com/vercel/next.js/tree/canary/examples"
className={styles.card}
>
<h2>Examples &rarr;</h2>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>

<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
<h2>Deploy &rarr;</h2>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>

<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
</div>
)
}
6 changes: 6 additions & 0 deletions frontend/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
Binary file added frontend/public/favicon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions frontend/public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dd908c2

Please sign in to comment.