Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bshevchenko committed May 27, 2024
1 parent ae2da84 commit f6947f8
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 257 deletions.
1 change: 1 addition & 0 deletions packages/hardhat/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"rules": {
"@typescript-eslint/no-unused-vars": ["error"],
"@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/no-var-requires": ["off"],
"prettier/prettier": [
"warn",
{
Expand Down
8 changes: 7 additions & 1 deletion packages/hardhat/deploy/01_core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn

await deploy("upDevAccountNFT", {
from: deployer,
args: [process.env.DON_ROUTER, process.env.DON_ID, process.env.LSP8_FORCE, process.env.DON_GAS_LIMIT, process.env.DON_SUB_ID],
args: [
process.env.DON_ROUTER,
process.env.DON_ID,
process.env.LSP8_FORCE,
process.env.DON_GAS_LIMIT,
process.env.DON_SUB_ID,
],
log: true,
autoMine: true,
});
Expand Down
109 changes: 55 additions & 54 deletions packages/hardhat/deploy/02_indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,71 @@ import { DeployFunction } from "hardhat-deploy/types";
import Moralis from "moralis";

function getEventABI(abi: any, name: string) {
return abi.find((item: any) => item.type === 'event' && item.name === name);
return abi.find((item: any) => item.type === "event" && item.name === name);
}

const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();

const { chainId } = await hre.network.config;
if (!chainId) {
throw Error("chainId is undefined");
}
const _chainId = "0x" + chainId.toString(16);
const { deployer } = await hre.getNamedAccounts();

const { chainId } = await hre.network.config;
if (!chainId) {
throw Error("chainId is undefined");
}
const _chainId = "0x" + chainId.toString(16);

await Moralis.start({
apiKey: process.env.MORALIS_API_KEY
});
await Moralis.start({
apiKey: process.env.MORALIS_API_KEY,
});

const { raw: { result: streams } } = await Moralis.Streams.getAll({
limit: 100
});
const {
raw: { result: streams },
} = await Moralis.Streams.getAll({
limit: 100,
});

let promises = [];
for (let stream of streams) {
promises.push(
Moralis.Streams.delete({
id: stream.id,
})
);
}
await Promise.all(promises);
console.log(`${promises.length} streams removed`);
const promises = [];
for (const stream of streams) {
promises.push(
Moralis.Streams.delete({
id: stream.id,
}),
);
}
await Promise.all(promises);
console.log(`${promises.length} streams removed`);

const events = {
"upDevAccountNFT": [
"NewSource(string,string)",
"Requested(bytes32,address,bytes32,string,string,string)",
"Fulfilled(bytes32,address,bytes32,bool)",
"Claimed(bytes32,address,bytes32,bytes)"
],
};
const events = {
upDevAccountNFT: [
"NewSource(string,string)",
"Requested(bytes32,address,bytes32,string,string,string)",
"Fulfilled(bytes32,address,bytes32,bool)",
"Claimed(bytes32,address,bytes32,bytes)",
],
};

for (let contract in events) {
const _contract = await hre.ethers.getContract(contract, deployer);
const { abi } = require(`../artifacts/contracts/${contract}.sol/${contract}.json`); // @ts-ignore
for (let event of events[contract]) {
const [name] = event.split("(");
const description = contract + "/" + name;
const stream = await Moralis.Streams.add({
webhookUrl: process.env.MORALIS_WEBHOOK_URL + "/" + description,
description,
tag: contract,
chains: [_chainId],
topic0: [event],
abi: [getEventABI(abi, name)],
includeContractLogs: true
});
const { id } = stream.toJSON();
await Moralis.Streams.addAddress({
id,
address: _contract.address,
});
console.log(`Added stream for ${description}`);
}
for (const contract in events) {
const _contract = await hre.ethers.getContract(contract, deployer);
const { abi } = require(`../artifacts/contracts/${contract}.sol/${contract}.json`);
for (const event of events[contract as keyof typeof events]) {
const [name] = event.split("(");
const description = contract + "/" + name;
const stream = await Moralis.Streams.add({
webhookUrl: process.env.MORALIS_WEBHOOK_URL + "/" + description,
description,
tag: contract,
chains: [_chainId],
topic0: [event],
abi: [getEventABI(abi, name)],
includeContractLogs: true,
});
const { id } = stream.toJSON();
await Moralis.Streams.addAddress({
id,
address: _contract.address,
});
console.log(`Added stream for ${description}`);
}
}
};

export default deployYourContract;
Expand Down
13 changes: 6 additions & 7 deletions packages/hardhat/deploy/03_sources.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getSource from "../sources/get";
import getLatestVersions from "../sources/latest.js";
import getLatestVersions from "../sources/latest.ts";

const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
Expand All @@ -16,13 +16,12 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn
} catch (e) {
console.log(`Source ${source.name} already added`);
}
}
};

await addSource("github", "1.0");
// const latest = await getLatestVersions();
// for (let key in latest) {
// await addSource(key, latest[key]);
// }
const latest = await getLatestVersions();
for (const key in latest) {
await addSource(key, latest[key]);
}
};

export default deployYourContract;
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const config: HardhatUserConfig = {
sepolia: {
url: `https://eth-sepolia.g.alchemy.com/v2/${providerApiKey}`,
accounts,
chainId: 11155111
chainId: 11155111,
},
polygonMumbai: {
url: `https://polygon-mumbai.g.alchemy.com/v2/${providerApiKey}`,
Expand Down
35 changes: 0 additions & 35 deletions packages/hardhat/sources/latest.js

This file was deleted.

36 changes: 36 additions & 0 deletions packages/hardhat/sources/latest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const fs = require("fs");

const latestVersions = () => {
return new Promise((resolve, reject) => {
fs.readdir(__dirname, (err: any, files: any) => {
if (err) {
reject("Unable to scan directory: " + err);
return;
}
const providers: any = {};
files.forEach((file: any) => {
const match = file.match(/^(.+?)@([\d\.]+)\.js$/);
if (match) {
const provider = match[1];
const version: any = match[2];

// Check and update the latest version
if (
!providers[provider as keyof typeof providers] ||
parseFloat(providers[provider as keyof typeof providers]) < parseFloat(version)
) {
providers[provider as keyof typeof providers] = version;
}
}
});
fs.writeFile(__dirname + "/../../nextjs/latest.json", JSON.stringify(providers, null, 4), err => {
if (err) {
console.error("An error occurred:", err);
}
});
resolve(providers);
});
});
};

export default latestVersions;
18 changes: 2 additions & 16 deletions packages/hardhat/test/upDevAccountNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,7 @@ describe("upDevAccountNFT", () => {
resolve(requests[0]);
});
console.log("Sending request...");
let tx = await nft.sendRequest(
owner.address,
0,
source.provider,
source.version,
accountId,
ipfsHash,
);
let tx = await nft.sendRequest(owner.address, 0, source.provider, source.version, accountId, ipfsHash);
await tx.wait();
console.log("Request sent and now being fulfilled by DON...");

Expand Down Expand Up @@ -244,14 +237,7 @@ describe("upDevAccountNFT", () => {
};
nft.on("Fulfilled", eventHandler);
console.log("Sending request...");
let tx = await nft.sendRequest(
owner.address,
0,
errorSource.provider,
errorSource.version,
accountId,
ipfsHash,
);
let tx = await nft.sendRequest(owner.address, 0, errorSource.provider, errorSource.version, accountId, ipfsHash);
await tx.wait();
console.log("Request sent and now being fulfilled by DON...");

Expand Down
Loading

0 comments on commit f6947f8

Please sign in to comment.