Skip to content

Commit 6260895

Browse files
authored
improve: Support testing chain adapters w/o token defs (#799)
1 parent 7f0cedb commit 6260895

File tree

6 files changed

+57
-58
lines changed

6 files changed

+57
-58
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@across-protocol/contracts",
3-
"version": "3.0.17",
3+
"version": "3.0.18",
44
"author": "UMA Team",
55
"license": "AGPL-3.0-only",
66
"repository": {
@@ -39,7 +39,7 @@
3939
"pre-commit-hook": "sh scripts/preCommitHook.sh"
4040
},
4141
"dependencies": {
42-
"@across-protocol/constants": "^3.1.21",
42+
"@across-protocol/constants": "^3.1.22",
4343
"@coral-xyz/anchor": "^0.30.1",
4444
"@defi-wonderland/smock": "^2.3.4",
4545
"@eth-optimism/contracts": "^0.5.40",

tasks/enableL1TokenAcrossEcosystem.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
11
import { task } from "hardhat/config";
22
import assert from "assert";
3-
import { askYesNoQuestion, minimalSpokePoolInterface } from "./utils";
43
import { CHAIN_IDs, MAINNET_CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../utils/constants";
5-
6-
type TokenSymbol = keyof typeof TOKEN_SYMBOLS_MAP;
7-
8-
/**
9-
* Given a token symbol, determine whether it is a valid key for the TOKEN_SYMBOLS_MAP object.
10-
*/
11-
function isTokenSymbol(symbol: unknown): symbol is TokenSymbol {
12-
return TOKEN_SYMBOLS_MAP[symbol as TokenSymbol] !== undefined;
13-
}
14-
15-
/**
16-
* Given a token symbol from the HubPool chain and a remote chain ID, resolve the relevant token symbol and address.
17-
*/
18-
function resolveTokenOnChain(
19-
mainnetSymbol: string,
20-
chainId: number
21-
): { symbol: TokenSymbol; address: string } | undefined {
22-
assert(isTokenSymbol(mainnetSymbol), `Unrecognised token symbol (${mainnetSymbol})`);
23-
let symbol = mainnetSymbol as TokenSymbol;
24-
25-
// Handle USDC special case where L1 USDC is mapped to different token symbols on L2s.
26-
if (mainnetSymbol === "USDC") {
27-
const symbols = ["USDC", "USDC.e", "USDbC", "USDzC"] as TokenSymbol[];
28-
const tokenSymbol = symbols.find((symbol) => TOKEN_SYMBOLS_MAP[symbol]?.addresses[chainId]);
29-
if (!isTokenSymbol(tokenSymbol)) {
30-
return;
31-
}
32-
symbol = tokenSymbol;
33-
} else if (symbol === "DAI" && chainId === CHAIN_IDs.BLAST) {
34-
symbol = "USDB";
35-
}
36-
37-
const address = TOKEN_SYMBOLS_MAP[symbol].addresses[chainId];
38-
if (!address) {
39-
return;
40-
}
41-
42-
return { symbol, address };
43-
}
4+
import { askYesNoQuestion, resolveTokenOnChain, isTokenSymbol, minimalSpokePoolInterface } from "./utils";
5+
import { TokenSymbol } from "./types";
446

457
const { ARBITRUM, OPTIMISM } = CHAIN_IDs;
468
const NO_SYMBOL = "----";

tasks/testChainAdapter.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getMnemonic } from "@uma/common";
33
import { task } from "hardhat/config";
44
import { HardhatRuntimeEnvironment } from "hardhat/types";
55
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../utils/constants";
6-
import { askYesNoQuestion } from "./utils";
6+
import { askYesNoQuestion, resolveTokenOnChain } from "./utils";
77

88
// Chain adapter names are not 1:1 consistent with chain names, so some overrides are needed.
99
const chains = {
@@ -23,8 +23,6 @@ task("testChainAdapter", "Verify a chain adapter")
2323
const signer = new ethers.Wallet.fromMnemonic(getMnemonic()).connect(provider);
2424

2525
const hubChainId = await getChainId();
26-
const { address: hubPoolAddress, abi: hubPoolAbi } = await deployments.get("HubPool");
27-
const hubPool = new ethers.Contract(hubPoolAddress, hubPoolAbi, provider);
2826
const spokeChainId = parseInt(args.chain);
2927

3028
const [spokeName] = Object.entries(CHAIN_IDs).find(([, chainId]) => chainId === spokeChainId) ?? [];
@@ -38,15 +36,10 @@ task("testChainAdapter", "Verify a chain adapter")
3836
const tokenAddress = TOKEN_SYMBOLS_MAP[tokenSymbol].addresses[hubChainId];
3937

4038
// For USDC this will resolve to native USDC on CCTP-enabled chains.
41-
const l2Token = await hubPool.poolRebalanceRoute(spokeChainId, tokenAddress);
42-
if (l2Token === ethers.constants.AddressZero) {
43-
const proceed = await askYesNoQuestion(
44-
`\t\nWARNING: ${tokenSymbol} maps to address ${l2Token} on chain ${spokeChainId}\n\t\nProceed ?`
45-
);
46-
if (!proceed) process.exit(0);
47-
} else {
48-
console.log(`Resolved ${tokenSymbol} l2 token address on chain ${spokeChainId}: ${l2Token}.`);
49-
}
39+
const _l2Token = resolveTokenOnChain(tokenSymbol, spokeChainId);
40+
assert(_l2Token !== undefined, `Token ${tokenSymbol} is not known on chain ${spokeChainId}`);
41+
const l2Token = _l2Token.address;
42+
console.log(`Resolved ${tokenSymbol} l2 token address on chain ${spokeChainId}: ${l2Token}.`);
5043

5144
const erc20 = (await ethers.getContractFactory("ExpandedERC20")).attach(tokenAddress);
5245
let balance = await erc20.balanceOf(adapterAddress);

tasks/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { TOKEN_SYMBOLS_MAP } from "../utils/constants";
2+
3+
export type TokenSymbol = keyof typeof TOKEN_SYMBOLS_MAP;

tasks/utils.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import assert from "assert";
12
import { ethers } from "ethers";
23
import readline from "readline";
4+
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../utils/constants";
5+
import { TokenSymbol } from "./types";
6+
37
export const zeroAddress = ethers.constants.AddressZero;
48

59
export const minimalSpokePoolInterface = [
@@ -160,3 +164,40 @@ export async function askYesNoQuestion(query: string): Promise<boolean> {
160164
if (ans.toLowerCase() === "n") return false;
161165
return askYesNoQuestion(query);
162166
}
167+
168+
/**
169+
* Given a token symbol from the HubPool chain and a remote chain ID, resolve the relevant token symbol and address.
170+
*/
171+
export function resolveTokenOnChain(
172+
mainnetSymbol: string,
173+
chainId: number
174+
): { symbol: TokenSymbol; address: string } | undefined {
175+
assert(isTokenSymbol(mainnetSymbol), `Unrecognised token symbol (${mainnetSymbol})`);
176+
let symbol = mainnetSymbol as TokenSymbol;
177+
178+
// Handle USDC special case where L1 USDC is mapped to different token symbols on L2s.
179+
if (mainnetSymbol === "USDC") {
180+
const symbols = ["USDC", "USDC.e", "USDbC", "USDzC"] as TokenSymbol[];
181+
const tokenSymbol = symbols.find((symbol) => TOKEN_SYMBOLS_MAP[symbol]?.addresses[chainId]);
182+
if (!isTokenSymbol(tokenSymbol)) {
183+
return;
184+
}
185+
symbol = tokenSymbol;
186+
} else if (symbol === "DAI" && chainId === CHAIN_IDs.BLAST) {
187+
symbol = "USDB";
188+
}
189+
190+
const address = TOKEN_SYMBOLS_MAP[symbol].addresses[chainId];
191+
if (!address) {
192+
return;
193+
}
194+
195+
return { symbol, address };
196+
}
197+
198+
/**
199+
* Given a token symbol, determine whether it is a valid key for the TOKEN_SYMBOLS_MAP object.
200+
*/
201+
export function isTokenSymbol(symbol: unknown): symbol is TokenSymbol {
202+
return TOKEN_SYMBOLS_MAP[symbol as TokenSymbol] !== undefined;
203+
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# yarn lockfile v1
33

44

5-
"@across-protocol/constants@^3.1.21":
6-
version "3.1.21"
7-
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.21.tgz#e5852daa51b4e1a215a32672c252287fea593256"
8-
integrity sha512-ajDGLpsbmse3XYPFKsih98RO/CSzpRj4iiPIzfOUvmslBfm3vIYj5nVdLKahgPumsQ+Yq2W3+PF+ZSr6Ac3tRg==
5+
"@across-protocol/constants@^3.1.22":
6+
version "3.1.22"
7+
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.22.tgz#888fb6852b9781aa9f872ac44e888d7bf2a643c7"
8+
integrity sha512-l9CteL0FGHPPIbLaAztANpm/uNk8jV7hmDuecAToZdqAgqcN9E9Hfi44Fflr6H882uVsNlTU0/h1oWkTeifUnA==
99

1010
"@across-protocol/contracts@^0.1.4":
1111
version "0.1.4"

0 commit comments

Comments
 (0)