MCPcopy Create free account
hub / github.com/across-protocol/relayer / run

Function run

scripts/sendTokens.ts:40–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38// \ --keys bot4
39
40export async function run(): Promise<void> {
41 console.log("Executing Token sender 💸");
42 if (!Object.keys(args).includes("token")) {
43 throw new Error("Define `token` as the address of the token to send");
44 }
45 if (!Object.keys(args).includes("amount")) {
46 throw new Error("Define `amount` as how much you want to send");
47 }
48 if (!Object.keys(args).includes("to")) {
49 throw new Error("Define `to` as where you want to send funds to");
50 }
51 if (!Object.keys(args).includes("chainId")) {
52 throw new Error("Define `chainId` as the chain you want to connect on");
53 }
54 const baseSigner = await retrieveSignerFromCLIArgs();
55 const signerAddr = await baseSigner.getAddress();
56 const connectedSigner = baseSigner.connect(await getProvider(Number(args.chainId)));
57 console.log("Connected to account", signerAddr);
58 const recipient = args.to;
59 const token = args.token;
60 if (!ethers.utils.isAddress(recipient)) {
61 throw new Error("invalid addresses");
62 }
63 const nonce = args.nonce ? Number(args.nonce) : undefined;
64 const maxFeePerGas = args.maxFeePerGas ? toGWei(args.maxFeePerGas) : undefined;
65 const maxPriorityFeePerGas = args.maxFeePerGas ? toGWei(args.maxFeePerGas) : undefined;
66 const { provider } = connectedSigner;
67 assert(isDefined(provider), "Connected signer must have a provider");
68 const gas =
69 maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : await getGasPrice(provider);
70 console.log(
71 `Submitting txn with maxFeePerGas ${gas.maxFeePerGas.toString()} and priority fee ${gas.maxPriorityFeePerGas.toString()} with overridden nonce ${nonce}`
72 );
73 const gasParams = LEGACY_TRANSACTION_CHAINS.includes(Number(args.chainId))
74 ? { gasPrice: gas.maxFeePerGas.add(gas.maxPriorityFeePerGas) }
75 : { ...gas };
76
77 // Send native token symbol
78 if (token === ZERO_ADDRESS || token === "0x") {
79 const nativeTokenSymbol = getNativeTokenSymbol(args.chainId);
80 const amountFromWei = ethers.utils.formatUnits(args.amount, 18);
81 console.log(
82 `Send ${nativeTokenSymbol} with amount ${amountFromWei} tokens to ${recipient} on chain ${args.chainId}`
83 );
84 if (!(await askYesNoQuestion("\nConfirm that you want to execute this transaction?"))) {
85 return;
86 }
87 console.log("sending...");
88 const tx = await connectedSigner.sendTransaction({ to: recipient, value: toBN(args.amount), nonce, ...gasParams });
89 const receipt = await tx.wait();
90 console.log("Transaction hash:", receipt.transactionHash);
91 }
92 // Send ERC20
93 else {
94 const erc20 = new ethers.Contract(token, ERC20.abi, connectedSigner);
95 const decimals = Number(await erc20.decimals());
96 const symbol = await erc20.symbol();
97 const amountFromWei = ethers.utils.formatUnits(args.amount, decimals);

Callers 1

sendTokens.tsFile · 0.70

Calls 6

getProviderFunction · 0.90
getGasPriceFunction · 0.90
askYesNoQuestionFunction · 0.90
addMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected