forked from ceptor-club/blockmagic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createAndFund.ts
36 lines (26 loc) · 1.62 KB
/
createAndFund.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
33
34
35
36
import { task } from "hardhat/config";
import { createSubscriptions } from "..";
import { scriptsToDeploy, upsertScripts } from "@/functions";
import { getConsumer, registerScripts } from "@/scripts/gateway";
task("upsert-gateway-requests", "Creates and optionally fund subscriptions for scripts. Register requests in Gateway.")
.addFlag("fund", "Fund subscriptions")
.setAction(async (params, hre) => {
const { deployer } = await hre.getNamedAccounts();
console.log(`Deployer: ${deployer} | `, params);
const chainId = await hre.getChainId();
const isLocal = chainId === hre.config.networks.hardhat.chainId.toString();
const fund = !isLocal && params.fund;
const consumer = await getConsumer(hre);
const consumerAddress = await consumer.getAddress();
const scripts = await scriptsToDeploy(chainId, consumerAddress, isLocal);
if (!scripts.length) return console.log("No scripts to deploy.");
console.log(`Creating ${scripts.length} subscriptions...`);
const scriptsToRegister = await createSubscriptions(hre, consumerAddress, scripts, fund, isLocal);
console.log(`Updating #${scriptsToRegister.length} registries in scripts map | Subscription ids`);
await upsertScripts(scriptsToRegister, chainId);
console.log("Registering scripts in Gateway to be used in the DON...");
const scriptsToUpsert = await registerScripts(scriptsToRegister, consumer);
console.log(`Updating #${scriptsToUpsert.length} registries in scripts map | Consumer ids`);
await upsertScripts(scriptsToUpsert, chainId);
console.log("Subscriptions created in DON and scripts registered in Gateway!");
});