forked from pot4e/FHE-contract-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
32 lines (29 loc) · 1.07 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { ContractMethodArgs, Typed } from "ethers";
// import { ethers } from "hardhat";
import { TypedContractMethod } from "../types/common";
export const waitForBlock = (blockNumber: bigint, ethers: any) => {
return new Promise((resolve, reject) => {
const waitBlock = async (currentBlock: number) => {
// console.log(`Block ${currentBlock} reached! Waiting ${blockNumber}...`);
if (blockNumber <= BigInt(currentBlock)) {
// console.log(`Block ${currentBlock} reached!`);
await ethers.provider.off("block", waitBlock);
resolve(blockNumber);
}
};
ethers.provider.on("block", waitBlock).catch((err: any) => {
reject(err);
});
});
};
export const createTransaction = async <A extends [...{ [I in keyof A]-?: A[I] | Typed }]>(
method: TypedContractMethod<A>,
...params: A
) => {
const gasLimit = await method.estimateGas(...params);
const updatedParams: ContractMethodArgs<A> = [
...params,
{ gasLimit: Math.min(Math.round(+gasLimit.toString() * 1.2), 10000000) },
];
return method(...updatedParams);
};