Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 2 additions & 3 deletions scripts/refillUsdcToSpecificChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
CHAIN_IDs,
TOKEN_SYMBOLS_MAP,
createFormatFunction,
formatUnits,
toBNWei,
ERC20,
Contract,
Expand Down Expand Up @@ -198,7 +197,7 @@ async function run(): Promise<void> {
chainName: sourceChainName,
chainId: sourceChainId,
balance: balanceFormatted,
threshold: formatUnits(MIN_BALANCE_THRESHOLD_USDC, sourceUsdcTokenInfo.decimals),
threshold: MIN_BALANCE_THRESHOLD_USDC_DECIMAL,
});

// Construct transaction to send entire balance to destination chain
Expand Down Expand Up @@ -239,7 +238,7 @@ async function run(): Promise<void> {
chainName: sourceChainName,
chainId: sourceChainId,
balance: balanceFormatted,
threshold: formatUnits(MIN_BALANCE_THRESHOLD_USDC, sourceUsdcTokenInfo.decimals),
threshold: MIN_BALANCE_THRESHOLD_USDC_DECIMAL,
});
}
} catch (error) {
Expand Down
44 changes: 1 addition & 43 deletions src/clients/bridges/utils.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import { Contract } from "ethers";
import { Log } from "../../interfaces";
import { TOKEN_APPROVALS_TO_FIRST_ZERO } from "../../common";
import {
BigNumber,
MAX_SAFE_ALLOWANCE,
blockExplorerLink,
bnZero,
getNetworkName,
getRedisCache,
runTransaction,
toBN,
winston,
mapAsync,
EvmAddress,
} from "../../utils";
import { BigNumber, getRedisCache, toBN, EvmAddress } from "../../utils";

/**
* @notice This function is designed to be used in L2 chain adapters when identifying "finalized" cross
Expand Down Expand Up @@ -116,31 +102,3 @@ export async function setL2TokenAllowanceInCache(
const key = getL2AllowanceCacheKey(l2ChainId, l2Token, userAddress, contractAddress);
await redis?.set(key, allowance.toString());
}

// @TODO: It looks like this function is not used anywhere. We have similar function in adapter/utils.ts. Delete this?
export async function approveTokens(
tokens: { token: Contract; bridge: EvmAddress }[],
chainId: number,
hubChainId: number,
logger: winston.Logger
): Promise<string> {
const approvalMarkdwn = await mapAsync(tokens, async ({ token: l1Token, bridge }) => {
const txs = [];
if (TOKEN_APPROVALS_TO_FIRST_ZERO[hubChainId]?.includes(l1Token.address)) {
txs.push(await runTransaction(logger, l1Token, "approve", [bridge.toNative(), bnZero]));
}
txs.push(await runTransaction(logger, l1Token, "approve", [bridge.toNative(), MAX_SAFE_ALLOWANCE]));
const receipts = await Promise.all(txs.map((tx) => tx.wait()));
const hubNetwork = getNetworkName(hubChainId);
const spokeNetwork = getNetworkName(chainId);
let internalMrkdwn =
` - Approved canonical ${spokeNetwork} token bridge ${blockExplorerLink(bridge.toNative(), hubChainId)} ` +
`to spend ${await l1Token.symbol()} ${blockExplorerLink(l1Token.address, hubChainId)} on ${hubNetwork}.` +
`tx: ${blockExplorerLink(receipts[receipts.length - 1].txnRef, hubChainId)}`;
if (receipts.length > 1) {
internalMrkdwn += ` tx (to zero approval first): ${blockExplorerLink(receipts[0].txnRef, hubChainId)}`;
}
return internalMrkdwn;
});
return ["*Approval transactions:*", ...approvalMarkdwn].join("\n");
}