Skip to content

Commit 273d6d3

Browse files
committed
chore: fmt!:js
1 parent aa41abe commit 273d6d3

18 files changed

Lines changed: 173 additions & 167 deletions

scripts/postinstall.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env node
2-
const exec = require("node:child_process").execSync;
2+
const _exec = require("node:child_process").execSync;
33
const fs = require("node:fs");
44
if (!fs.existsSync(".no-postinstall") && !fs.existsSync(`${process.env.INIT_CWD}/.env_witnet`)) {
55
console.info(`Copying .env_witnet file from ${process.env.INIT_CWD}...`);

src/bin/bots/randomizer.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async function main() {
8484

8585
program.parse();
8686

87-
const { host, maxGasPrice, minBalance, network, port, schedule, scheduleOverlap, scheduleTimezone, signer,target } =
87+
const { host, maxGasPrice, minBalance, network, port, schedule, scheduleOverlap, scheduleTimezone, signer, target } =
8888
program.opts();
8989

9090
traceHeader(`@WITNET/SOLIDITY RANDOMIZER BOT v${require("../../../package.json").version}`, colors.white);

src/bin/cli/framework.cjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ module.exports = async (flags = {}, params = []) => {
3535
if (flags?.modals) {
3636
const dict = utils.flattenRadonModals(assets);
3737
if (Object.keys(dict).length > 0 && deployables.modals[network]) {
38-
artifacts.push(...Object.entries(deployables.modals[network])
39-
.filter(([key]) => dict[key] !== undefined)
40-
.map(([key, address]) => [key, { address }])
38+
artifacts.push(
39+
...Object.entries(deployables.modals[network])
40+
.filter(([key]) => dict[key] !== undefined)
41+
.map(([key, address]) => [key, { address }]),
4142
);
4243
}
4344
}

src/bin/cli/priceFeeds.cjs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ module.exports = async (options = {}, args = []) => {
1616
let { target } = options;
1717
let chosen = false;
1818
if (!target) {
19-
const { apps } = utils.getEvmNetworkAddresses(network)
20-
const targets = Object.entries(apps || {}).filter(([key, address]) => (
21-
key.startsWith("WitPriceFeeds")
22-
&& key.indexOf("Upgradable") === -1
23-
&& key.indexOf("Trustable") === -1
24-
&& address !== "0x0000000000000000000000000000000000000000"
25-
)).map(([, address]) => address);
19+
const { apps } = utils.getEvmNetworkAddresses(network);
20+
const targets = Object.entries(apps || {})
21+
.filter(
22+
([key, address]) =>
23+
key.startsWith("WitPriceFeeds") &&
24+
key.indexOf("Upgradable") === -1 &&
25+
key.indexOf("Trustable") === -1 &&
26+
address !== "0x0000000000000000000000000000000000000000",
27+
)
28+
.map(([, address]) => address);
2629
if (targets.length === 1) {
2730
target = targets[0];
2831
} else {
@@ -51,17 +54,21 @@ module.exports = async (options = {}, args = []) => {
5154
}
5255
}
5356

54-
let { client: priceFeedClient, legacy: isLegacy } = await helpers.prompter(_resolvePriceFeeds(target)).catch((err) => {
55-
console.error(helpers.colors.mred(`Fatal: unable to initialize PriceFeeds wrapper: ${err.message || err}`));
56-
process.exit(0);
57-
});
57+
let { client: priceFeedClient, legacy: isLegacy } = await helpers
58+
.prompter(_resolvePriceFeeds(target))
59+
.catch((err) => {
60+
console.error(helpers.colors.mred(`Fatal: unable to initialize PriceFeeds wrapper: ${err.message || err}`));
61+
process.exit(0);
62+
});
5863

5964
let artifact = await priceFeedClient.getEvmImplClass();
6065
// if the implementation class reports legacy but we already have a
6166
// modern client, switch over to the fully-baked legacy helper.
6267
if (artifact.includes("Legacy") && !isLegacy) {
6368
priceFeedClient = await helpers.prompter(witOracle._getWitPriceFeedsLegacy(target)).catch((err) => {
64-
console.error(helpers.colors.mred(`Fatal: unable to initialize legacy PriceFeeds wrapper: ${err.message || err}`));
69+
console.error(
70+
helpers.colors.mred(`Fatal: unable to initialize legacy PriceFeeds wrapper: ${err.message || err}`),
71+
);
6572
process.exit(0);
6673
});
6774
artifact = await priceFeedClient.getEvmImplClass();
@@ -80,7 +87,7 @@ module.exports = async (options = {}, args = []) => {
8087
priceFeeds = (await priceFeedClient.lookupPriceFeeds()).sort((a, b) => a.symbol.localeCompare(b.symbol));
8188
} catch (err) {
8289
throw new Error(`Failed to lookup price feeds: ${err.message}`);
83-
}
90+
}
8491

8592
if (!options["trace-back"]) {
8693
const registry = await witOracle._getWitOracleRadonRegistry();

src/bin/cli/queries.cjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ module.exports = async (options = {}, args = []) => {
7070
// apply limit/offset filter
7171
logs =
7272
!since || BigInt(since) < 0n
73-
? logs
74-
.slice(offset || 0)
75-
.slice(0, limit || DEFAULT_LIMIT) // oldest first
73+
? logs.slice(offset || 0).slice(0, limit || DEFAULT_LIMIT) // oldest first
7674
: logs
7775
.reverse()
7876
.slice(offset || 0)

src/bin/cli/randomness.cjs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ module.exports = async (options = {}, args = []) => {
1515

1616
const { network, provider } = witOracle;
1717
helpers.traceHeader(`${network.toUpperCase()}`, helpers.colors.lcyan);
18-
18+
1919
let { target } = options;
2020
let chosen = false;
2121
if (!target) {
22-
const { apps } = utils.getEvmNetworkAddresses(network)
23-
const targets = Object.entries(apps || {}).filter(([key, address]) => (
24-
key.startsWith("WitRandomness")
25-
&& address !== "0x0000000000000000000000000000000000000000"
26-
)).map(([, address]) => address);
22+
const { apps } = utils.getEvmNetworkAddresses(network);
23+
const targets = Object.entries(apps || {})
24+
.filter(
25+
([key, address]) => key.startsWith("WitRandomness") && address !== "0x0000000000000000000000000000000000000000",
26+
)
27+
.map(([, address]) => address);
2728
if (targets.length === 1) {
2829
target = targets[0];
2930
} else {
@@ -39,7 +40,7 @@ module.exports = async (options = {}, args = []) => {
3940
chosen = true;
4041
}
4142
}
42-
43+
4344
const randomizer = await helpers.prompter(witOracle._getWitRandomness(target)).catch((err) => {
4445
console.error(colors.mred(`Fatal: unable to initialize WitRandomness wrapper: ${err.message || err}`));
4546
process.exit(0);
@@ -184,9 +185,7 @@ module.exports = async (options = {}, args = []) => {
184185
// apply limit/offset filter
185186
logs =
186187
!since || BigInt(since) < 0n
187-
? logs
188-
.slice(offset || 0)
189-
.slice(0, limit || DEFAULT_LIMIT) // oldest first
188+
? logs.slice(offset || 0).slice(0, limit || DEFAULT_LIMIT) // oldest first
190189
: logs
191190
.reverse()
192191
.slice(offset || 0)

src/bin/cli/reports.cjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ module.exports = async (options = {}, args = []) => {
123123
// apply limit/offset filter
124124
logs =
125125
!since || BigInt(since) < 0n
126-
? logs
127-
.slice(offset || 0)
128-
.slice(0, limit || DEFAULT_LIMIT) // oldest first
126+
? logs.slice(offset || 0).slice(0, limit || DEFAULT_LIMIT) // oldest first
129127
: logs
130128
.reverse()
131129
.slice(offset || 0)

src/lib/utils.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Witnet } from "@witnet/sdk";
22

33
import { default as cbor } from "cbor";
44

5-
import { AbiCoder, Contract, JsonRpcApiProvider, type JsonRpcProvider, solidityPackedKeccak256 } from "ethers";
5+
import { AbiCoder, Contract, type JsonRpcApiProvider, type JsonRpcProvider, solidityPackedKeccak256 } from "ethers";
66
import { default as merge } from "lodash.merge";
77
import { default as helpers } from "../bin/helpers.cjs";
88
import { ABIs } from "../index.js";
@@ -52,11 +52,11 @@ export async function fetchWitOracleFramework(
5252
.filter(([key, address]) => {
5353
const base = _findBase(contracts, key);
5454
return (
55-
address
56-
&& address !== "0x0000000000000000000000000000000000000000"
57-
&& targets.includes(key)
58-
&& !exclusions.includes(base)
59-
&& (ABIs[key] || ABIs[base])
55+
address &&
56+
address !== "0x0000000000000000000000000000000000000000" &&
57+
targets.includes(key) &&
58+
!exclusions.includes(base) &&
59+
(ABIs[key] || ABIs[base])
6060
);
6161
})
6262
.map(async ([key, address]) => {
@@ -169,7 +169,9 @@ function _versionLastCommitOf(version?: string) {
169169
}
170170
}
171171

172-
export async function fetchEvmNetworkFromProvider(provider: JsonRpcApiProvider): Promise<{ name: string; id: number } | undefined> {
172+
export async function fetchEvmNetworkFromProvider(
173+
provider: JsonRpcApiProvider,
174+
): Promise<{ name: string; id: number } | undefined> {
173175
return provider.getNetwork().then((value) => {
174176
const network = getEvmNetworkByChainId(Number(value.chainId));
175177
if (network) {

src/lib/wrappers/ContractWrapper.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
AbiCoder,
3-
Contract,
43
type Addressable,
4+
Contract,
55
type ContractRunner,
66
type Interface,
77
type InterfaceAbi,
@@ -10,7 +10,6 @@ import {
1010
} from "ethers";
1111

1212
export abstract class ContractWrapper {
13-
1413
constructor(target: string | Addressable, abi: Interface | InterfaceAbi, runner: ContractRunner) {
1514
this.abi = abi;
1615
this._address = target;
@@ -40,14 +39,14 @@ export abstract class ContractWrapper {
4039
* @example
4140
* // Assuming `contractWrapper` is an instance of a class that extends ContractWrapper:
4241
* const provider = contractWrapper.provider; // Get the provider
43-
* const signer = contractWrapper.signer; // Get the signer (if available)
42+
* const signer = contractWrapper.signer; // Get the signer (if available)
4443
*/
4544
protected _getProviderAndSignerFromContractRunner(runner: ContractRunner): any[] {
4645
if ("provider" in runner) {
4746
return [
4847
runner.provider as JsonRpcApiProvider,
4948
// ...this._getNetworkFromProvider(runner.provider as JsonRpcApiProvider),
50-
runner instanceof JsonRpcSigner ? runner as JsonRpcSigner : undefined
49+
runner instanceof JsonRpcSigner ? (runner as JsonRpcSigner) : undefined,
5150
];
5251
} else {
5352
throw new Error(`${this.constructor.name}: ContractRunner does not have provider property`);
@@ -78,7 +77,7 @@ export abstract class ContractWrapper {
7877
*/
7978
protected async connect(runner: ContractRunner): Promise<ContractWrapper> {
8079
[this._provider, this._signer] = this._getProviderAndSignerFromContractRunner(runner);
81-
this._contract = this._contract.connect(runner) as Contract
80+
this._contract = this._contract.connect(runner) as Contract;
8281
this._runner = runner;
8382
return this;
8483
}

src/lib/wrappers/WitAppliance.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import type { Addressable, Interface, InterfaceAbi } from "ethers";
22
import { ABIs } from "../../index.js";
33
import { getEvmNetworkAddresses } from "../utils.js";
4-
import type { WitOracle } from "./WitOracle.js";
54
import { WitArtifact } from "./WitArtifact.js";
5+
import type { WitOracle } from "./WitOracle.js";
66

77
export abstract class WitAppliance extends WitArtifact {
8-
98
public readonly witOracle: WitOracle;
109

1110
constructor(specs: {
12-
artifact: string,
13-
target?: string | Addressable,
14-
witOracle: WitOracle,
11+
artifact: string;
12+
target?: string | Addressable;
13+
witOracle: WitOracle;
1514
}) {
1615
const { artifact, target: at, witOracle } = specs;
1716
const abis: Record<string, Interface | InterfaceAbi> = ABIs;
@@ -31,18 +30,23 @@ export abstract class WitAppliance extends WitArtifact {
3130
*/
3231
public async attach(target: string | Addressable): Promise<WitAppliance> {
3332
const contract = this._contract.attach(target);
34-
return contract.getFunction("witOracle()")
33+
return contract
34+
.getFunction("witOracle()")
3535
.staticCall()
3636
.then((witOracleAddress) => {
3737
if (witOracleAddress.toLowerCase() !== this.witOracle.address.toString().toLowerCase()) {
38-
throw new Error(`${this.constructor.name}: Target address ${target} in EVM network ${this.witOracle.network} bound to a different WitOracle (${witOracleAddress}).`);
38+
throw new Error(
39+
`${this.constructor.name}: Target address ${target} in EVM network ${this.witOracle.network} bound to a different WitOracle (${witOracleAddress}).`,
40+
);
3941
} else {
4042
super.attach(target);
4143
return this;
4244
}
4345
})
4446
.catch((error) => {
45-
throw new Error(`${this.constructor.name}: Failed to attach to address ${target} in EVM network ${this.witOracle.network}: ${error.message}`);
47+
throw new Error(
48+
`${this.constructor.name}: Failed to attach to address ${target} in EVM network ${this.witOracle.network}: ${error.message}`,
49+
);
4650
});
4751
}
4852
}

0 commit comments

Comments
 (0)