Skip to content

Commit 1f2c01f

Browse files
committed
fixes-and-improvements
1 parent e847ef9 commit 1f2c01f

File tree

8 files changed

+244
-33
lines changed

8 files changed

+244
-33
lines changed

ccip/cct/hardhat/config/networks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const networks: Networks = {
2626
nonce: undefined,
2727
accounts,
2828
},
29-
[EVMChains.sepolia]: {
29+
[EVMChains.ethereumSepolia]: {
3030
type: "http",
3131
...configData.ethereumSepolia,
3232
url: process.env.ETHEREUM_SEPOLIA_RPC_URL || "https://UNSET-PLEASE-SET-ETHEREUM_SEPOLIA_RPC_URL",

ccip/cct/hardhat/config/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface EVMChainConfig {
4040
export enum Chains {
4141
avalancheFuji = "avalancheFuji",
4242
arbitrumSepolia = "arbitrumSepolia",
43-
sepolia = "sepolia",
43+
ethereumSepolia = "ethereumSepolia",
4444
baseSepolia = "baseSepolia",
4545
solanaDevnet = "solanaDevnet",
4646
polygonAmoy = "polygonAmoy",
@@ -50,7 +50,7 @@ export enum Chains {
5050
export enum EVMChains {
5151
avalancheFuji = "avalancheFuji",
5252
arbitrumSepolia = "arbitrumSepolia",
53-
sepolia = "sepolia",
53+
ethereumSepolia = "ethereumSepolia",
5454
baseSepolia = "baseSepolia",
5555
polygonAmoy = "polygonAmoy",
5656
}
@@ -93,6 +93,7 @@ export interface EtherscanConfig {
9393

9494
export enum TokenContractName {
9595
BurnMintERC20 = "BurnMintERC20",
96+
ERC20 = "ERC20",
9697
}
9798

9899
export enum TokenPoolContractName {
@@ -107,6 +108,8 @@ export enum CCIPContractName {
107108
Router = "IRouterClient",
108109
OnRamp = "OnRamp",
109110
OwnerIsCreator = "OwnerIsCreator",
111+
RateLimiter = "RateLimiter",
112+
Client = "Client",
110113
}
111114

112115
export enum PoolType {

ccip/cct/hardhat/tasks/applyChainUpdates.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,8 @@ export const applyChainUpdates = task(
182182
.split(",")
183183
.map((addr) => addr.trim());
184184

185-
console.log(remotePoolAddresses)
186-
187185
try {
188186
for (const addr of remotePoolAddresses) {
189-
console.log(addr, remoteChainFamily);
190187
validateChainAddressOrThrow(addr, remoteChainFamily);
191188
}
192189

@@ -260,7 +257,7 @@ export const applyChainUpdates = task(
260257
[[], [chainUpdate]],
261258
{ account: wallet.account.address }
262259
);
263-
logger.info(` TX sent: ${txHash}`);
260+
logger.info(`📤 TX sent: ${txHash}`);
264261

265262
const { confirmations } = networkConfig;
266263
if (confirmations === undefined)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { task } from "hardhat/config";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types/hre";
3+
import { isAddress, formatUnits } from "viem";
4+
import {
5+
Chains,
6+
TokenContractName,
7+
logger,
8+
getEVMNetworkConfig,
9+
} from "../config";
10+
11+
/**
12+
* Checks the token balance of the wallet.
13+
*
14+
* Example:
15+
* npx hardhat checkTokenBalance \
16+
* --tokenaddress 0xYourTokenAddress \
17+
* --network sepolia
18+
*/
19+
export const checkTokenBalance = task(
20+
"checkTokenBalance",
21+
"Checks the token balance of the wallet"
22+
)
23+
.addOption({
24+
name: "tokenaddress",
25+
description: "The token address",
26+
defaultValue: "",
27+
})
28+
.setAction(async () => ({
29+
default: async (
30+
{
31+
tokenaddress,
32+
}: {
33+
tokenaddress: string;
34+
},
35+
hre: HardhatRuntimeEnvironment
36+
) => {
37+
// Validate token address is provided
38+
if (!tokenaddress) {
39+
throw new Error("Token address is required (--tokenaddress)");
40+
}
41+
42+
// Connect to network first
43+
const networkConnection = await hre.network.connect();
44+
const { viem } = networkConnection;
45+
const networkName = networkConnection.networkName as Chains;
46+
47+
const networkConfig = getEVMNetworkConfig(networkName);
48+
if (!networkConfig)
49+
throw new Error(`Network ${networkName} not found in config`);
50+
51+
// Validate token address format
52+
if (!isAddress(tokenaddress))
53+
throw new Error(`Invalid token address: ${tokenaddress}`);
54+
55+
const [wallet] = await viem.getWalletClients();
56+
57+
try {
58+
// Connect to token contract
59+
const token = await viem.getContractAt(
60+
TokenContractName.BurnMintERC20,
61+
tokenaddress as `0x${string}`
62+
);
63+
64+
const symbol = await token.read.symbol();
65+
const decimals = await token.read.decimals();
66+
const balance = await token.read.balanceOf([wallet.account.address]);
67+
68+
logger.info(`🔍 Token Balance Check`);
69+
logger.info(` Token Address: ${tokenaddress}`);
70+
logger.info(` Token Symbol: ${symbol}`);
71+
logger.info(` Wallet Address: ${wallet.account.address}`);
72+
logger.info(` Balance: ${balance.toString()} (${formatUnits(balance, Number(decimals))} ${symbol})`);
73+
} catch (error) {
74+
logger.error("❌ Failed to check token balance:", error);
75+
throw error;
76+
}
77+
},
78+
}))
79+
.build();

ccip/cct/hardhat/tasks/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { deployToken } from "./deployToken";
22
import { deployTokenPool } from "./deployTokenPool";
33
import { mintTokens } from "./mintTokens";
4+
import { checkTokenBalance } from "./checkTokenBalance";
45
import {claimAdmin} from "./claimAdmin";
56
import {acceptAdminRole} from "./acceptAdminRole";
67
import { transferTokenAdminRole } from "./transferTokenAdminRole";
@@ -20,6 +21,7 @@ export const tasks = [
2021
deployToken,
2122
deployTokenPool,
2223
mintTokens,
24+
checkTokenBalance,
2325
claimAdmin,
2426
acceptAdminRole,
2527
transferTokenAdminRole,
@@ -44,7 +46,10 @@ export const npmFilesToBuild = [
4446
"@chainlink/contracts-ccip/contracts/tokenAdminRegistry/RegistryModuleOwnerCustom.sol",
4547
"@chainlink/contracts-ccip/contracts/tokenAdminRegistry/TokenAdminRegistry.sol",
4648
"@chainlink/contracts-ccip/contracts/interfaces/IRouterClient.sol",
47-
"@chainlink/contracts/src/v0.8/shared/access/OwnerIsCreator.sol"
49+
"@chainlink/contracts/src/v0.8/shared/access/OwnerIsCreator.sol",
50+
"@chainlink/contracts-ccip/contracts/libraries/RateLimiter.sol",
51+
"@chainlink/contracts-ccip/contracts/libraries/Client.sol",
52+
"@openzeppelin/contracts/token/ERC20/ERC20.sol",
4853
];
4954

5055
console.log("✅ Tasks loaded from /tasks/index.ts");

ccip/cct/hardhat/tasks/safe-multisig/deploySafe.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const deploySafe = task("deploySafe", "Deploys a new Safe multisig contra
102102
logger.info(` Salt nonce: ${saltNonce}`);
103103
logger.info(` Deploying Safe contract...`);
104104

105-
// ✅ Deploy the Safe using Safe.init() with predictedSafe configuration
105+
// ✅ Initialize Safe with predictedSafe configuration
106106
const protocolKit = await SafeDefault.init({
107107
provider: rpcUrl,
108108
signer: privateKey,
@@ -117,11 +117,39 @@ export const deploySafe = task("deploySafe", "Deploys a new Safe multisig contra
117117
},
118118
});
119119

120-
const safeAddress = await protocolKit.getAddress();
120+
const predictedAddress = await protocolKit.getAddress();
121+
logger.info(` Predicted Safe address: ${predictedAddress}`);
121122

122-
logger.info(`✅ Safe deployed successfully`);
123-
logger.info(` Safe address: ${safeAddress}`);
124-
logger.info(` Network: ${networkName}`);
123+
// Check if Safe is already deployed
124+
const isSafeDeployed = await protocolKit.isSafeDeployed();
125+
126+
if (isSafeDeployed) {
127+
logger.info(`ℹ️ Safe already deployed at ${predictedAddress}`);
128+
logger.info(` Network: ${networkName}`);
129+
} else {
130+
logger.info(` Deploying Safe contract on-chain...`);
131+
132+
// Actually deploy the Safe using viem wallet client
133+
const deploymentTransaction = await protocolKit.createSafeDeploymentTransaction();
134+
const [wallet] = await viem.getWalletClients();
135+
const publicClient = await viem.getPublicClient();
136+
137+
const txHash = await wallet.sendTransaction({
138+
to: deploymentTransaction.to as `0x${string}`,
139+
value: BigInt(deploymentTransaction.value),
140+
data: deploymentTransaction.data as `0x${string}`,
141+
});
142+
143+
logger.info(` Deployment transaction: ${txHash}`);
144+
logger.info(` Waiting for confirmation...`);
145+
146+
// Wait for transaction confirmation
147+
await publicClient.waitForTransactionReceipt({ hash: txHash });
148+
149+
logger.info(`✅ Safe deployed successfully`);
150+
logger.info(` Safe address: ${predictedAddress}`);
151+
logger.info(` Network: ${networkName}`);
152+
}
125153

126154
} catch (error) {
127155
logger.error("❌ Safe deployment failed:", error);

0 commit comments

Comments
 (0)