-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
37 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type {HardhatRuntimeEnvironment} from "hardhat/types"; | ||
import assert from "node:assert"; | ||
|
||
|
||
export async function deployNilContract( | ||
hre: HardhatRuntimeEnvironment, | ||
name: string, | ||
args: string[] = [], | ||
) { | ||
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(); | ||
|
||
if (!txReceipt || !txReceipt.contractAddress) { | ||
throw new Error("Contract deployment failed"); | ||
} | ||
|
||
const deployedContract = factory.attach(txReceipt.contractAddress); | ||
return { deployedContract, contractAddress: txReceipt.contractAddress }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
export function calculateOutputAmount( | ||
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; | ||
} |