Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: linting #99

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 129 additions & 49 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-verify";
import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-waffle";
import { getSingletonFactoryInfo } from "@safe-global/safe-singleton-factory";
import "@typechain/hardhat";
import "hardhat-deploy";

Expand All @@ -17,7 +16,6 @@ import * as dotenv from "dotenv";
dotenv.config({ path: __dirname + "/.env" });

// Libraries
import { BigNumber } from "@ethersproject/bignumber";
import assert from "assert";

// Process Env Variables
Expand All @@ -27,33 +25,12 @@ assert.ok(ALCHEMY_ID, "no Alchemy ID in process.env");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY;

// Deterministic deployment using Safe's system
const deterministicDeployment = (
network: string
): DeterministicDeploymentInfo => {
const info = getSingletonFactoryInfo(parseInt(network));
if (!info) {
throw new Error(`
Safe factory not found for network ${network}. You can request a new deployment at https://github.com/safe-global/safe-singleton-factory.
For more information, see https://github.com/safe-global/safe-contracts#replay-protection-eip-155
`);
}
return {
factory: info.address,
deployer: info.signerAddress,
funding: BigNumber.from(info.gasLimit)
.mul(BigNumber.from(info.gasPrice))
.toString(),
signedTx: info.transaction,
};
};

// ================================= CONFIG =========================================
const config: HardhatUserConfig = {
w3f: {
rootDir: "./web3-functions",
debug: false,
networks: ["polygon", "mumbai", "goerli", "baseGoerli", "blastsepolia"], //(multiChainProvider) injects provider for these networks
networks: ["sepolia"], //(multiChainProvider) injects provider for these networks
},

namedAccounts: {
Expand All @@ -78,44 +55,94 @@ const config: HardhatUserConfig = {
},

// Prod
arbitrum: {
url: `https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`,
chainId: 42161,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
astarzkevm: {
url: "https://rpc.astar-zkevm.gelato.digital",
chainId: 3776,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
avalanche: {
url: "https://api.avax.network/ext/bc/C/rpc",
chainId: 43114,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
arbitrum: {
chainId: 42161,
url: "https://arb1.arbitrum.io/rpc",
base: {
url: `https://mainnet.base.org`,
chainId: 8453,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
baseGoerli: {
chainId: 84531,
url: "https://goerli.base.org",
blast: {
url: `https://blastl2-mainnet.public.blastapi.io`,
chainId: 81457,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
bsc: {
chainId: 56,
url: "https://bsc-dataseed.binance.org/",
chainId: 56,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
fantom: {
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
chainId: 250,
url: `https://rpcapi.fantom.network/`,
},
ethereum: {
gnosis: {
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
chainId: 100,
url: `https://gnosis-mainnet.public.blastapi.io`,
},
linea: {
url: `https://linea.blockpi.network/v1/rpc/public`,
chainId: 59144,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
mainnet: {
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
chainId: 1,
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
},
metis: {
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
chainId: 1088,
url: "https://metis-mainnet.public.blastapi.io",
},
fantom: {
chainId: 250,
url: `https://rpcapi.fantom.network/`,
mode: {
url: `https://mainnet.mode.network`,
chainId: 34443,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
optimism: {
url: `https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`,
chainId: 10,
url: "https://mainnet.optimism.io",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
playblock: {
url: `https://rpc.playblock.io`,
chainId: 1829,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
polygon: {
url: `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`,
chainId: 137,
url: "https://rpc-mainnet.maticvigil.com",
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
polygonzk: {
url: "https://zkevm-rpc.com",
chainId: 1101,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
real: {
url: "https://rpc.realforreal.gelato.digital/",
chainId: 111188,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
reyanetwork: {
url: "https://rpc.reya.network",
chainId: 1729,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
zksync: {
Expand All @@ -128,30 +155,83 @@ const config: HardhatUserConfig = {
},

// Staging
arbgoerli: {
chainId: 421613,
url: `https://arb-goerli.g.alchemy.com/v2/${ALCHEMY_ID}`,
amoy: {
url: `https://rpc-amoy.polygon.technology`,
chainId: 80002,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
goerli: {
chainId: 5,
url: `https://eth-goerli.g.alchemy.com/v2/${ALCHEMY_ID}`,
arbsepolia: {
url: `https://sepolia-rollup.arbitrum.io/rpc`,
chainId: 421614,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
mumbai: {
chainId: 80001,
url: `https://polygon-mumbai.g.alchemy.com/v2/${ALCHEMY_ID}`,
astarzkyoto: {
url: `https://rpc.zkyoto.gelato.digital`,
chainId: 6038361,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
basesepolia: {
url: `https://sepolia.base.org`,
chainId: 84532,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
blackberry: {
url: `https://rpc.polygon-blackberry.gelato.digital`,
chainId: 94204209,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
blastsepolia: {
chainId: 168587773,
url: `https://sepolia.blast.io`,
chainId: 168587773,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
raspberry: {
url: `https://rpc.op-celestia-testnet.gelato.digital`,
chainId: 123420111,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
blueberry: {
url: `https://rpc.arb-blueberry.gelato.digital`,
chainId: 88153591557,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
lisksepolia: {
url: `https://rpc.lisk-sepolia-testnet.gelato.digital`,
chainId: 4202,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
mumbai: {
url: `https://polygon-mumbai.g.alchemy.com/v2/${ALCHEMY_ID}`,
chainId: 80001,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
osepolia: {
url: `https://sepolia.optimism.io`,
chainId: 11155420,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
reyacronos: {
url: `https://rpc.reya-cronos.gelato.digital`,
chainId: 89346161,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
sepolia: {
url: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_ID}`,
chainId: 11155111,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
unrealorbit: {
url: `https://rpc.unreal-orbit.gelato.digital`,
chainId: 18233,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
zkatana: {
url: "https://rpc.zkatana.gelato.digital",
chainId: 1261120,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
},

deterministicDeployment,

verify: {
etherscan: {
apiKey: ETHERSCAN_KEY ? ETHERSCAN_KEY : "",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"private": false,
"scripts": {
"build": "yarn clean && yarn install && yarn compile && npx tsc",
"run:vrf-event-trigger": "npx hardhat w3f-run vrf-event-trigger --network sepolia --logs --debug",
"run:vrf-fallback": "npx hardhat w3f-run vrf-fallback --network sepolia --logs --debug",
"compile": "npx hardhat compile --force",
"clean": "rm -rf dist",
"deploy": "npx hardhat deploy",
Expand Down
4 changes: 2 additions & 2 deletions src/drand_info/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainInfo } from "drand-client";
import * as _quicknet from "./assets/quicknet.json" assert { type: "json" };
import * as _quicknet from "./assets/quicknet.json";

export const quicknet: ChainInfo = _quicknet.default;
export const quicknet: ChainInfo = _quicknet;
5 changes: 3 additions & 2 deletions src/drand_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ChainOptions,
HttpCachingChain,
HttpChainClient,
RandomnessBeacon,
fetchBeacon,
roundTime,
} from "drand-client";
Expand Down Expand Up @@ -72,8 +73,8 @@ async function fetchDrandResponseWithCaching(round: number) {
async function fetchBeaconWithTimeout(
client: HttpChainClient,
round: number,
timeout: number = 5_000
) {
timeout = 5_000
): Promise<RandomnessBeacon> {
return new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => reject(new Error(`Timeout`)), timeout);
fetchBeacon(client, round)
Expand Down
7 changes: 4 additions & 3 deletions test/cl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { MockCLVRFConsumer, VRFCoordinatorV2Adapter } from "../typechain";
const { deployments, w3f, ethers } = hre;

import fetch from "node-fetch";
global.fetch = fetch;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).fetch = fetch;

const DRAND_OPTIONS: ChainOptions = {
disableBeaconVerification: false,
Expand Down Expand Up @@ -91,7 +92,7 @@ describe("Chainlink Adapter Test Suite", function () {
await mockConsumer.connect(user).requestRandomWords(numWords);
const requestId = await mockConsumer.requestId();

const exec = await vrf.run({ userArgs });
const exec = await vrf.run("onRun", { userArgs });
const res = exec.result as Web3FunctionResultV2;
const round = roundAt(Date.now(), quicknet);

Expand Down Expand Up @@ -125,7 +126,7 @@ describe("Chainlink Adapter Test Suite", function () {
});

it("Doesn't execute if no event was emitted", async () => {
const exec = await vrf.run({ userArgs });
const exec = await vrf.run("onRun", { userArgs });
const res = exec.result as Web3FunctionResultV2;

if (!res.canExec) assert.fail(res.message);
Expand Down
8 changes: 5 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import { MockVRFConsumer } from "../typechain";
const { deployments, w3f, ethers } = hre;

import { sleep } from "drand-client/util";

import fetch from "node-fetch";
global.fetch = fetch;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).fetch = fetch;

const DRAND_OPTIONS: ChainOptions = {
disableBeaconVerification: false,
Expand Down Expand Up @@ -94,7 +96,7 @@ describe("GelatoVRFConsumerBase Test Suite", function () {
const timeOfRound = round * quicknet.period + quicknet.genesis_time;
await sleep((timeOfRound - timeNowSec) * 1000);

const exec = await vrf.run({ userArgs });
const exec = await vrf.run("onRun", { userArgs });
const res = exec.result as Web3FunctionResultV2;

if (!res.canExec) assert.fail(res.message);
Expand Down Expand Up @@ -127,7 +129,7 @@ describe("GelatoVRFConsumerBase Test Suite", function () {
});

it("Doesn't execute if no event was emitted", async () => {
const exec = await vrf.run({ userArgs });
const exec = await vrf.run("onRun", { userArgs });
const res = exec.result as Web3FunctionResultV2;

if (!res.canExec) assert.fail(res.message);
Expand Down
10 changes: 6 additions & 4 deletions test/upgradeable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import { quicknet } from "../src/drand_info";
const { deployments, w3f, ethers } = hre;

import { sleep } from "drand-client/util";
import fetch from "node-fetch";
import { MockVRFConsumerUpgradeable } from "../typechain/contracts/mocks/MockVRFConsumerUpgradeable.sol";
global.fetch = fetch;

import fetch from "node-fetch";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).fetch = fetch;

const DRAND_OPTIONS: ChainOptions = {
disableBeaconVerification: false,
Expand Down Expand Up @@ -86,7 +88,7 @@ describe("GelatoVRFConsumerBase Test Suite", function () {
const timeOfRound = round * quicknet.period + quicknet.genesis_time;
await sleep((timeOfRound - timeNowSec) * 1000);

const exec = await vrf.run({ userArgs });
const exec = await vrf.run("onRun", { userArgs });
const res = exec.result as Web3FunctionResultV2;

if (!res.canExec) assert.fail(res.message);
Expand Down Expand Up @@ -121,7 +123,7 @@ describe("GelatoVRFConsumerBase Test Suite", function () {
});

it("Doesn't execute if no event was emitted", async () => {
const exec = await vrf.run({ userArgs });
const exec = await vrf.run("onRun", { userArgs });
const res = exec.result as Web3FunctionResultV2;

if (!res.canExec) assert.fail(res.message);
Expand Down
15 changes: 9 additions & 6 deletions web3-functions/vrf-event-trigger/log.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"blockNumber": 48758053,
"blockHash": "0xa72052e57ec15e498e1b8cf1e059a730a49a60a6b9a6911ddbc159cb138fb6b6",
"address": "0xb74de3F91e04d0920ff26Ac28956272E8d67404D",
"data": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000007c000000000000000000000000000000000000000000000000000000006538b1440000000000000000000000000000000000000000000000000000000002ed91ea",
"blockNumber": 5621060,
"blockHash": "0xe3f40774570594a1b12fe2521dd8bcbd203da7ba6c2ac0486835cbed27ec8733",
"transactionIndex": 70,
"removed": false,
"address": "0x5f65D1273F6c2B6cc3caB5F164d3B0c47b66f9fD",
"data": "0x0000000000000000000000000000000000000000000000000000000000626bd500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000",
"topics": [
"0x4ef1ecf757b1446f4fb5521fe0fe95f303e965ea741f07127b118b017fc3ba33"
"0xd91fc3685b930310b008ec37d2334870cab88a023ed8cc628a2e2ccd4e55d202"
],
"transactionHash": "0x2ac28a3c1646ab838d5a32021dc14967406ef5f96632e9b7021f8eb2a98b7667"
"transactionHash": "0x1443c032abee040562c708d0157a5468038974c2cb265bf24287cbcc34a0e34d",
"logIndex": 125
}
Loading
Loading