Skip to content

Commit 80fdfed

Browse files
committed
cli: query token decimals outside of forge script
This works around and edge case when the token contract is compiled against a different EVM version than what the forge script is running in (london currently).
1 parent 1d17ca8 commit 80fdfed

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

cli/src/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type { EvmNtt, EvmNttWormholeTranceiver } from "@wormhole-foundation/sdk-
3131
import type { EvmChains } from "@wormhole-foundation/sdk-evm";
3232
import { getAvailableVersions, getGitTagName } from "./tag";
3333
import * as configuration from "./configuration";
34+
import { ethers } from "ethers";
3435

3536
// TODO: contract upgrades on solana
3637
// TODO: set special relaying?
@@ -947,8 +948,13 @@ async function deployEvm<N extends Network, C extends Chain>(
947948
const rpc = ch.config.rpc;
948949
const specialRelayer = "0x63BE47835c7D66c4aA5B2C688Dc6ed9771c94C74"; // TODO: how to configure this?
949950

951+
const provider = new ethers.JsonRpcProvider(rpc);
952+
const abi = ["function decimals() external view returns (uint8)"];
953+
const tokenContract = new ethers.Contract(token, abi, provider);
954+
const decimals: number = await tokenContract.decimals();
955+
950956
// TODO: should actually make these ENV variables.
951-
const sig = "run(address,address,address,address,uint8)";
957+
const sig = "run(address,address,address,address,uint8,uint8)";
952958
const modeUint = mode === "locking" ? 0 : 1;
953959
const signer = await getSigner(ch, signerType);
954960
const signerArgs = forgeSignerArgs(signer.source);
@@ -975,7 +981,7 @@ async function deployEvm<N extends Network, C extends Chain>(
975981
execSync(`
976982
forge script --via-ir script/DeployWormholeNtt.s.sol \
977983
--rpc-url ${rpc} \
978-
--sig "${sig}" ${wormhole} ${token} ${relayer} ${specialRelayer} ${modeUint} \
984+
--sig "${sig}" ${wormhole} ${token} ${relayer} ${specialRelayer} ${decimals} ${modeUint} \
979985
--broadcast ${verifyArgs.join(' ')} ${signerArgs} | tee last-run.stdout`, {
980986
cwd: `${pwd}/evm`,
981987
encoding: 'utf8',

evm/script/DeployWormholeNtt.s.sol

+18-6
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,36 @@ contract DeployWormholeNtt is Script, DeployWormholeNttBase {
1919
address token,
2020
address wormholeRelayer,
2121
address specialRelayer,
22+
uint8 decimals,
2223
IManagerBase.Mode mode
2324
) public {
2425
vm.startBroadcast();
2526

2627
console.log("Deploying Wormhole Ntt...");
2728
IWormhole wh = IWormhole(wormhole);
2829

30+
// sanity check decimals
2931
(bool success, bytes memory queriedDecimals) =
3032
token.staticcall(abi.encodeWithSignature("decimals()"));
3133

32-
if (!success) {
33-
console.log("Failed to query token decimals");
34-
vm.stopBroadcast();
35-
return;
34+
if (success) {
35+
uint8 queriedDecimals = abi.decode(queriedDecimals, (uint8));
36+
if (queriedDecimals != decimals) {
37+
console.log("Decimals mismatch: ", queriedDecimals, " != ", decimals);
38+
vm.stopBroadcast();
39+
return;
40+
}
41+
} else {
42+
// NOTE: this might not be a critical error. It could just mean that
43+
// the token contract was compiled against a different EVM version than what the forge script is running on.
44+
// In this case, it's the responsibility of the caller to ensure that the provided decimals are correct
45+
// and that the token contract is valid.
46+
// The best way to ensure that is by calling this script with the queried token decimals (which is what the NTT CLI does).
47+
console.log(
48+
"Failed to query token decimals. Proceeding with provided decimals.", decimals
49+
);
3650
}
3751

38-
uint8 decimals = abi.decode(queriedDecimals, (uint8));
39-
4052
uint16 chainId = wh.chainId();
4153

4254
console.log("Chain ID: ", chainId);

0 commit comments

Comments
 (0)