From a227f3a90aea0a0f378e7a98565c90d393eaeadf Mon Sep 17 00:00:00 2001 From: rolaman Date: Tue, 24 Sep 2024 17:33:16 +0300 Subject: [PATCH] demo-task: completed for the demo --- tasks/core/demo.ts | 5 ++--- tasks/util/deploy.ts | 33 ++++++++++++++++----------------- tasks/util/math.ts | 17 ++++++++--------- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/tasks/core/demo.ts b/tasks/core/demo.ts index 9d682de..235d4b1 100644 --- a/tasks/core/demo.ts +++ b/tasks/core/demo.ts @@ -9,8 +9,8 @@ import type { UniswapV2Pair, } from "../../typechain-types"; import { createClient } from "../util/client"; -import {calculateOutputAmount} from "../util/math"; -import {deployNilContract} from "../util/deploy"; +import { deployNilContract } from "../util/deploy"; +import { calculateOutputAmount } from "../util/math"; task("demo", "Run demo for Uniswap Pairs and Factory").setAction( async (taskArgs, hre) => { @@ -345,4 +345,3 @@ task("demo", "Run demo for Uniswap Pairs and Factory").setAction( ); }, ); - diff --git a/tasks/util/deploy.ts b/tasks/util/deploy.ts index cbd4dc7..c6be9a8 100644 --- a/tasks/util/deploy.ts +++ b/tasks/util/deploy.ts @@ -1,24 +1,23 @@ -import type {HardhatRuntimeEnvironment} from "hardhat/types"; import assert from "node:assert"; - +import type { HardhatRuntimeEnvironment } from "hardhat/types"; export async function deployNilContract( - hre: HardhatRuntimeEnvironment, - name: string, - args: string[] = [], + hre: HardhatRuntimeEnvironment, + name: string, + args: string[] = [], ) { - const factory = await hre.ethers.getContractFactory(name); - assert.ok(factory.runner); - assert.ok(factory.runner.sendTransaction); + const factory = await hre.ethers.getContractFactory(name); + assert.ok(factory.runner); + assert.ok(factory.runner.sendTransaction); - const deployTx = await factory.getDeployTransaction(...args); - const sentTx = await factory.runner.sendTransaction(deployTx); - const txReceipt = await sentTx.wait(); + const deployTx = await factory.getDeployTransaction(...args); + const sentTx = await factory.runner.sendTransaction(deployTx); + const txReceipt = await sentTx.wait(); - if (!txReceipt || !txReceipt.contractAddress) { - throw new Error("Contract deployment failed"); - } + if (!txReceipt || !txReceipt.contractAddress) { + throw new Error("Contract deployment failed"); + } - const deployedContract = factory.attach(txReceipt.contractAddress); - return { deployedContract, contractAddress: txReceipt.contractAddress }; -} \ No newline at end of file + const deployedContract = factory.attach(txReceipt.contractAddress); + return { deployedContract, contractAddress: txReceipt.contractAddress }; +} diff --git a/tasks/util/math.ts b/tasks/util/math.ts index 655507e..055d7b9 100644 --- a/tasks/util/math.ts +++ b/tasks/util/math.ts @@ -1,11 +1,10 @@ - export function calculateOutputAmount( - amountIn: bigint, - reserveIn: bigint, - reserveOut: bigint, + amountIn: bigint, + reserveIn: bigint, + reserveOut: bigint, ): bigint { - const amountInWithFee = amountIn * BigInt(997); - const numerator = amountInWithFee * reserveOut; - const denominator = reserveIn * BigInt(1000) + amountInWithFee; - return numerator / denominator; -} \ No newline at end of file + const amountInWithFee = amountIn * BigInt(997); + const numerator = amountInWithFee * reserveOut; + const denominator = reserveIn * BigInt(1000) + amountInWithFee; + return numerator / denominator; +}