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

improve(unwrapWeth): load WETH addresses from constants #1840

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 11 additions & 13 deletions scripts/unwrapWeth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { ethers, retrieveSignerFromCLIArgs, getProvider, WETH9, toBN, isKeyOf, getNetworkName } from "../src/utils";
import {
ethers,
retrieveSignerFromCLIArgs,
getProvider,
WETH9,
toBN,
getNetworkName,
TOKEN_SYMBOLS_MAP,
} from "../src/utils";
import { askYesNoQuestion } from "./utils";
import minimist from "minimist";

Expand All @@ -15,16 +23,6 @@ const args = minimist(process.argv.slice(2), {
// \ --wallet gckms
// \ --keys bot1

const WETH_ADDRESSES = {
1: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
10: "0x4200000000000000000000000000000000000006",
42161: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
137: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",
288: "0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000",
324: "0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91",
8453: "0x4200000000000000000000000000000000000006",
};

export async function run(): Promise<void> {
if (!Object.keys(args).includes("chainId")) {
throw new Error("Define `chainId` as the chain you want to connect on");
Expand All @@ -36,10 +34,10 @@ export async function run(): Promise<void> {
const signerAddr = await baseSigner.getAddress();
const chainId = Number(args.chainId);
const connectedSigner = baseSigner.connect(await getProvider(chainId));
if (!isKeyOf(chainId, WETH_ADDRESSES)) {
if (!TOKEN_SYMBOLS_MAP.WETH.addresses[chainId]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we convert this to an assert( )

throw new Error("chainId does not have a defined WETH address");
}
const token = WETH_ADDRESSES[chainId];
const token = TOKEN_SYMBOLS_MAP.WETH.addresses[chainId];
const weth = new ethers.Contract(token, WETH9.abi, connectedSigner);
const decimals = 18;
const amountFromWei = ethers.utils.formatUnits(args.amount, decimals);
Expand Down