Skip to content

Commit 3c40c26

Browse files
authored
chore: run formatter on project (#168)
1 parent 9f697d6 commit 3c40c26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1438
-586
lines changed

src/commands/bridge/command.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import Program from "../../program.js";
22

3-
export default Program.command("bridge").description("Bridge operations (e.g. deposit, withdraw)");
3+
export default Program.command("bridge").description(
4+
"Bridge operations (e.g. deposit, withdraw)"
5+
);

src/commands/bridge/deposit.ts

+47-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import inquirer from "inquirer";
22
import ora from "ora";
33

4-
import Program from "./command.js";
54
import {
65
amountOptionCreate,
76
chainWithL1Option,
@@ -24,9 +23,14 @@ import {
2423
} from "../../utils/helpers.js";
2524
import Logger from "../../utils/logger.js";
2625
import { getBalance, getTokenInfo } from "../../utils/token.js";
27-
import { isDecimalAmount, isAddress, isPrivateKey } from "../../utils/validators.js";
26+
import {
27+
isAddress,
28+
isDecimalAmount,
29+
isPrivateKey,
30+
} from "../../utils/validators.js";
2831
import zeek from "../../utils/zeek.js";
2932
import { getChains } from "../config/chains.js";
33+
import Program from "./command.js";
3034

3135
import type { DefaultTransferOptions } from "../../common/options.js";
3236

@@ -39,7 +43,10 @@ export const handler = async (options: DepositOptions) => {
3943
try {
4044
Logger.debug(
4145
`Initial deposit options: ${JSON.stringify(
42-
{ ...options, ...(options.privateKey ? { privateKey: "<hidden>" } : {}) },
46+
{
47+
...options,
48+
...(options.privateKey ? { privateKey: "<hidden>" } : {}),
49+
},
4350
null,
4451
2
4552
)}`
@@ -52,7 +59,9 @@ export const handler = async (options: DepositOptions) => {
5259
message: chainWithL1Option.description,
5360
name: optionNameToParam(chainWithL1Option.long!),
5461
type: "list",
55-
choices: chains.filter((e) => e.l1Chain).map((e) => ({ name: e.name, value: e.network })),
62+
choices: chains
63+
.filter((e) => e.l1Chain)
64+
.map((e) => ({ name: e.name, value: e.network })),
5665
required: true,
5766
when(answers: DepositOptions) {
5867
if (answers.l1Rpc && answers.rpc) {
@@ -94,24 +103,42 @@ export const handler = async (options: DepositOptions) => {
94103
...answers,
95104
};
96105

97-
Logger.debug(`Final deposit options: ${JSON.stringify({ ...options, privateKey: "<hidden>" }, null, 2)}`);
106+
Logger.debug(
107+
`Final deposit options: ${JSON.stringify({ ...options, privateKey: "<hidden>" }, null, 2)}`
108+
);
98109

99110
const fromChain = chains.find((e) => e.network === options.chain)?.l1Chain;
100-
const fromChainLabel = fromChain && !options.l1Rpc ? fromChain.name : (options.l1Rpc ?? "Unknown chain");
111+
const fromChainLabel =
112+
fromChain && !options.l1Rpc
113+
? fromChain.name
114+
: (options.l1Rpc ?? "Unknown chain");
101115
const toChain = chains.find((e) => e.network === options.chain);
102-
const toChainLabel = toChain && !options.rpc ? toChain.name : (options.rpc ?? "Unknown chain");
116+
const toChainLabel =
117+
toChain && !options.rpc ? toChain.name : (options.rpc ?? "Unknown chain");
103118

104119
const l1Provider = getL1Provider(options.l1Rpc ?? fromChain!.rpcUrl);
105120
const l2Provider = getL2Provider(options.rpc ?? toChain!.rpcUrl);
106-
const senderWallet = getL2Wallet(options.privateKey, l2Provider, l1Provider);
107-
const token = options.token ? await getTokenInfo(options.token!, l2Provider, l1Provider) : ETH_TOKEN;
108-
const { decimalToBigNumber, bigNumberToDecimal } = useDecimals(token.decimals);
121+
const senderWallet = getL2Wallet(
122+
options.privateKey,
123+
l2Provider,
124+
l1Provider
125+
);
126+
const token = options.token
127+
? await getTokenInfo(options.token!, l2Provider, l1Provider)
128+
: ETH_TOKEN;
129+
const { decimalToBigNumber, bigNumberToDecimal } = useDecimals(
130+
token.decimals
131+
);
109132
if (!token.l1Address) {
110-
throw new Error(`Token ${token.symbol} doesn't exist on ${fromChainLabel} therefore it cannot be deposited`);
133+
throw new Error(
134+
`Token ${token.symbol} doesn't exist on ${fromChainLabel} therefore it cannot be deposited`
135+
);
111136
}
112137

113138
Logger.info("\nDeposit:");
114-
Logger.info(` From: ${getAddressFromPrivateKey(answers.privateKey)} (${fromChainLabel})`);
139+
Logger.info(
140+
` From: ${getAddressFromPrivateKey(answers.privateKey)} (${fromChainLabel})`
141+
);
115142
Logger.info(` To: ${options.recipient} (${toChainLabel})`);
116143
Logger.info(
117144
` Amount: ${bigNumberToDecimal(decimalToBigNumber(options.amount))} ${token.symbol} ${
@@ -133,10 +160,16 @@ export const handler = async (options: DepositOptions) => {
133160
Logger.info("\nDeposit sent:");
134161
Logger.info(` Transaction hash: ${depositHandle.hash}`);
135162
if (fromChain?.explorerUrl) {
136-
Logger.info(` Transaction link: ${fromChain.explorerUrl}/tx/${depositHandle.hash}`);
163+
Logger.info(
164+
` Transaction link: ${fromChain.explorerUrl}/tx/${depositHandle.hash}`
165+
);
137166
}
138167

139-
const senderBalance = await getBalance(token.l1Address, senderWallet.address, l1Provider);
168+
const senderBalance = await getBalance(
169+
token.l1Address,
170+
senderWallet.address,
171+
l1Provider
172+
);
140173
Logger.info(
141174
`\nSender L1 balance after transaction: ${bigNumberToDecimal(senderBalance)} ${token.symbol} ${
142175
token.name ? `(${token.name})` : ""

src/commands/bridge/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import "./deposit.js";
22
import "./withdraw.js";
33
import "./withdraw-finalize.js";
4-
54
import "./command.js"; // registers all the commands above

src/commands/bridge/withdraw-finalize.ts

+48-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Option } from "commander";
22
import inquirer from "inquirer";
33

4-
import Program from "./command.js";
54
import {
65
chainWithL1Option,
76
l1RpcUrlOption,
@@ -24,10 +23,14 @@ import { getBalance } from "../../utils/token.js";
2423
import { isPrivateKey, isTransactionHash } from "../../utils/validators.js";
2524
import zeek from "../../utils/zeek.js";
2625
import { getChains } from "../config/chains.js";
26+
import Program from "./command.js";
2727

2828
import type { DefaultTransactionOptions } from "../../common/options.js";
2929

30-
const transactionHashOption = new Option("--hash <transaction_hash>", "L2 withdrawal transaction hash to finalize");
30+
const transactionHashOption = new Option(
31+
"--hash <transaction_hash>",
32+
"L2 withdrawal transaction hash to finalize"
33+
);
3134

3235
type WithdrawFinalizeOptions = DefaultTransactionOptions & {
3336
hash: string;
@@ -37,7 +40,10 @@ export const handler = async (options: WithdrawFinalizeOptions) => {
3740
try {
3841
Logger.debug(
3942
`Initial withdraw-finalize options: ${JSON.stringify(
40-
{ ...options, ...(options.privateKey ? { privateKey: "<hidden>" } : {}) },
43+
{
44+
...options,
45+
...(options.privateKey ? { privateKey: "<hidden>" } : {}),
46+
},
4147
null,
4248
2
4349
)}`
@@ -50,7 +56,9 @@ export const handler = async (options: WithdrawFinalizeOptions) => {
5056
message: chainWithL1Option.description,
5157
name: optionNameToParam(chainWithL1Option.long!),
5258
type: "list",
53-
choices: chains.filter((e) => e.l1Chain).map((e) => ({ name: e.name, value: e.network })),
59+
choices: chains
60+
.filter((e) => e.l1Chain)
61+
.map((e) => ({ name: e.name, value: e.network })),
5462
required: true,
5563
when(answers: WithdrawFinalizeOptions) {
5664
if (answers.l1Rpc && answers.rpc) {
@@ -82,22 +90,36 @@ export const handler = async (options: WithdrawFinalizeOptions) => {
8290
...answers,
8391
};
8492

85-
Logger.debug(`Final withdraw-finalize options: ${JSON.stringify({ ...options, privateKey: "<hidden>" }, null, 2)}`);
93+
Logger.debug(
94+
`Final withdraw-finalize options: ${JSON.stringify({ ...options, privateKey: "<hidden>" }, null, 2)}`
95+
);
8696

8797
const fromChain = chains.find((e) => e.network === options.chain);
88-
const fromChainLabel = fromChain && !options.rpc ? fromChain.name : (options.rpc ?? "Unknown chain");
98+
const fromChainLabel =
99+
fromChain && !options.rpc
100+
? fromChain.name
101+
: (options.rpc ?? "Unknown chain");
89102
const toChain = chains.find((e) => e.network === options.chain)?.l1Chain;
90-
const toChainLabel = toChain && !options.l1Rpc ? toChain.name : (options.l1Rpc ?? "Unknown chain");
103+
const toChainLabel =
104+
toChain && !options.l1Rpc
105+
? toChain.name
106+
: (options.l1Rpc ?? "Unknown chain");
91107

92108
Logger.info("\nWithdraw finalize:");
93109
Logger.info(` From chain: ${fromChainLabel}`);
94110
Logger.info(` To chain: ${toChainLabel}`);
95111
Logger.info(` Withdrawal transaction (L2): ${options.hash}`);
96-
Logger.info(` Finalizer address (L1): ${getAddressFromPrivateKey(answers.privateKey)}`);
112+
Logger.info(
113+
` Finalizer address (L1): ${getAddressFromPrivateKey(answers.privateKey)}`
114+
);
97115

98116
const l1Provider = getL1Provider(options.l1Rpc ?? toChain!.rpcUrl);
99117
const l2Provider = getL2Provider(options.rpc ?? fromChain!.rpcUrl);
100-
const senderWallet = getL2Wallet(options.privateKey, l2Provider, l1Provider);
118+
const senderWallet = getL2Wallet(
119+
options.privateKey,
120+
l2Provider,
121+
l1Provider
122+
);
101123

102124
Logger.info("\nChecking status of the transaction...");
103125
const l2Details = await l2Provider.getTransactionDetails(options.hash);
@@ -109,26 +131,38 @@ export const handler = async (options: WithdrawFinalizeOptions) => {
109131
Logger.error(
110132
`\nTransaction is still being processed on ${fromChainLabel}, please try again when the ethExecuteTxHash has been computed`
111133
);
112-
Logger.info(`L2 Transaction Details: ${JSON.stringify(l2Details, null, 2)}`);
134+
Logger.info(
135+
`L2 Transaction Details: ${JSON.stringify(l2Details, null, 2)}`
136+
);
113137
return;
114138
}
115139
Logger.info("Transaction is ready to be finalized");
116140

117141
Logger.info("\nSending finalization transaction...");
118-
const finalizationHandle = await senderWallet.finalizeWithdrawal(options.hash);
142+
const finalizationHandle = await senderWallet.finalizeWithdrawal(
143+
options.hash
144+
);
119145
Logger.info("\nWithdrawal finalized:");
120146
Logger.info(` Finalization transaction hash: ${finalizationHandle.hash}`);
121147
if (toChain?.explorerUrl) {
122-
Logger.info(` Transaction link: ${toChain.explorerUrl}/tx/${finalizationHandle.hash}`);
148+
Logger.info(
149+
` Transaction link: ${toChain.explorerUrl}/tx/${finalizationHandle.hash}`
150+
);
123151
}
124152

125153
Logger.info("\nWaiting for finalization transaction to be mined...");
126154
const receipt = await finalizationHandle.wait();
127-
Logger.info(` Finalization transaction was mined in block ${receipt.blockNumber}`);
155+
Logger.info(
156+
` Finalization transaction was mined in block ${receipt.blockNumber}`
157+
);
128158

129159
const token = ETH_TOKEN;
130160
const { bigNumberToDecimal } = useDecimals(token.decimals);
131-
const senderBalance = await getBalance(token.l1Address, senderWallet.address, l1Provider);
161+
const senderBalance = await getBalance(
162+
token.l1Address,
163+
senderWallet.address,
164+
l1Provider
165+
);
132166
Logger.info(
133167
`\nSender L1 balance after transaction: ${bigNumberToDecimal(senderBalance)} ${token.symbol} ${
134168
token.name ? `(${token.name})` : ""

src/commands/bridge/withdraw.ts

+56-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import inquirer from "inquirer";
22
import ora from "ora";
33

4-
import Program from "./command.js";
54
import {
65
amountOptionCreate,
76
chainWithL1Option,
@@ -24,9 +23,14 @@ import {
2423
} from "../../utils/helpers.js";
2524
import Logger from "../../utils/logger.js";
2625
import { getBalance, getTokenInfo } from "../../utils/token.js";
27-
import { isDecimalAmount, isAddress, isPrivateKey } from "../../utils/validators.js";
26+
import {
27+
isAddress,
28+
isDecimalAmount,
29+
isPrivateKey,
30+
} from "../../utils/validators.js";
2831
import zeek from "../../utils/zeek.js";
2932
import { getChains } from "../config/chains.js";
33+
import Program from "./command.js";
3034

3135
import type { DefaultTransferOptions } from "../../common/options.js";
3236

@@ -39,7 +43,10 @@ export const handler = async (options: WithdrawOptions) => {
3943
try {
4044
Logger.debug(
4145
`Initial withdraw options: ${JSON.stringify(
42-
{ ...options, ...(options.privateKey ? { privateKey: "<hidden>" } : {}) },
46+
{
47+
...options,
48+
...(options.privateKey ? { privateKey: "<hidden>" } : {}),
49+
},
4350
null,
4451
2
4552
)}`
@@ -52,7 +59,9 @@ export const handler = async (options: WithdrawOptions) => {
5259
message: chainWithL1Option.description,
5360
name: optionNameToParam(chainWithL1Option.long!),
5461
type: "list",
55-
choices: chains.filter((e) => e.l1Chain).map((e) => ({ name: e.name, value: e.network })),
62+
choices: chains
63+
.filter((e) => e.l1Chain)
64+
.map((e) => ({ name: e.name, value: e.network })),
5665
required: true,
5766
when(answers: WithdrawOptions) {
5867
if (answers.l1Rpc && answers.rpc) {
@@ -94,27 +103,49 @@ export const handler = async (options: WithdrawOptions) => {
94103
...answers,
95104
};
96105

97-
Logger.debug(`Final withdraw options: ${JSON.stringify({ ...options, privateKey: "<hidden>" }, null, 2)}`);
106+
Logger.debug(
107+
`Final withdraw options: ${JSON.stringify({ ...options, privateKey: "<hidden>" }, null, 2)}`
108+
);
98109

99110
const fromChain = chains.find((e) => e.network === options.chain);
100-
const fromChainLabel = fromChain && !options.rpc ? fromChain.name : (options.rpc ?? "Unknown chain");
111+
const fromChainLabel =
112+
fromChain && !options.rpc
113+
? fromChain.name
114+
: (options.rpc ?? "Unknown chain");
101115
const toChain = chains.find((e) => e.network === options.chain)?.l1Chain;
102-
const toChainLabel = toChain && !options.l1Rpc ? toChain.name : (options.l1Rpc ?? "Unknown chain");
116+
const toChainLabel =
117+
toChain && !options.l1Rpc
118+
? toChain.name
119+
: (options.l1Rpc ?? "Unknown chain");
103120

104121
const l1Provider = getL1Provider(options.l1Rpc ?? toChain!.rpcUrl);
105122
const l2Provider = getL2Provider(options.rpc ?? fromChain!.rpcUrl);
106-
const senderWallet = getL2Wallet(options.privateKey, l2Provider, l1Provider);
107-
const token = options.token ? await getTokenInfo(options.token!, l2Provider, l1Provider) : ETH_TOKEN;
108-
const { decimalToBigNumber, bigNumberToDecimal } = useDecimals(token.decimals);
123+
const senderWallet = getL2Wallet(
124+
options.privateKey,
125+
l2Provider,
126+
l1Provider
127+
);
128+
const token = options.token
129+
? await getTokenInfo(options.token!, l2Provider, l1Provider)
130+
: ETH_TOKEN;
131+
const { decimalToBigNumber, bigNumberToDecimal } = useDecimals(
132+
token.decimals
133+
);
109134
if (!token.l1Address) {
110-
throw new Error(`Token ${token.symbol} doesn't exist on ${toChainLabel} therefore it cannot be withdrawn`);
135+
throw new Error(
136+
`Token ${token.symbol} doesn't exist on ${toChainLabel} therefore it cannot be withdrawn`
137+
);
111138
}
112139
if (!token.address) {
113-
throw new Error(`Token ${token.symbol} does not exist on ${fromChain?.name}`);
140+
throw new Error(
141+
`Token ${token.symbol} does not exist on ${fromChain?.name}`
142+
);
114143
}
115144

116145
Logger.info("\nWithdraw:");
117-
Logger.info(` From: ${getAddressFromPrivateKey(answers.privateKey)} (${fromChainLabel})`);
146+
Logger.info(
147+
` From: ${getAddressFromPrivateKey(answers.privateKey)} (${fromChainLabel})`
148+
);
118149
Logger.info(` To: ${options.recipient} (${toChainLabel})`);
119150
Logger.info(
120151
` Amount: ${bigNumberToDecimal(decimalToBigNumber(options.amount))} ${token.symbol} ${
@@ -126,18 +157,27 @@ export const handler = async (options: WithdrawOptions) => {
126157
try {
127158
const withdrawHandle = await senderWallet.withdraw({
128159
to: options.recipient,
129-
token: token.address === ETH_TOKEN.address ? token.l1Address : token.address!,
160+
token:
161+
token.address === ETH_TOKEN.address
162+
? token.l1Address
163+
: token.address!,
130164
amount: decimalToBigNumber(options.amount),
131165
});
132166
await withdrawHandle.wait();
133167
spinner.stop();
134168
Logger.info("\nWithdraw sent:");
135169
Logger.info(` Transaction hash: ${withdrawHandle.hash}`);
136170
if (fromChain?.explorerUrl) {
137-
Logger.info(` Transaction link: ${fromChain.explorerUrl}/tx/${withdrawHandle.hash}`);
171+
Logger.info(
172+
` Transaction link: ${fromChain.explorerUrl}/tx/${withdrawHandle.hash}`
173+
);
138174
}
139175

140-
const senderBalance = await getBalance(token.address, senderWallet.address, l2Provider);
176+
const senderBalance = await getBalance(
177+
token.address,
178+
senderWallet.address,
179+
l2Provider
180+
);
141181
Logger.info(
142182
`\nSender L2 balance after transaction: ${bigNumberToDecimal(senderBalance)} ${token.symbol} ${
143183
token.name ? `(${token.name})` : ""

0 commit comments

Comments
 (0)