Skip to content

Commit ddbe2fc

Browse files
authored
feat(svm): reorganize remaining svm tools (#816)
* feat(svm): reorganize remaining svm tools Signed-off-by: Pablo Maldonado <[email protected]> * feat: validate cctp api response Signed-off-by: Pablo Maldonado <[email protected]> * feat: move type check cctp Signed-off-by: Pablo Maldonado <[email protected]> --------- Signed-off-by: Pablo Maldonado <[email protected]>
1 parent ab4b762 commit ddbe2fc

17 files changed

+205
-117
lines changed

scripts/svm/bridgeLiabilityToHubPool.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,21 @@ import { SvmSpoke } from "../../target/types/svm_spoke";
3434
import {
3535
CIRCLE_IRIS_API_URL_DEVNET,
3636
CIRCLE_IRIS_API_URL_MAINNET,
37+
getMessages,
38+
isSolanaDevnet,
3739
MAINNET_CCTP_MESSAGE_TRANSMITTER_ADDRESS,
3840
SEPOLIA_CCTP_MESSAGE_TRANSMITTER_ADDRESS,
3941
SOLANA_SPOKE_STATE_SEED,
4042
SOLANA_USDC_DEVNET,
4143
SOLANA_USDC_MAINNET,
42-
} from "./utils/constants";
44+
} from "../../src/svm";
4345

4446
import { TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
4547
import { getNodeUrl } from "@uma/common";
4648
import { BigNumber, ethers } from "ethers";
4749
import { TokenMessengerMinter } from "../../target/types/token_messenger_minter";
48-
import { getMessages } from "../../test/svm/cctpHelpers";
4950
import { BondToken__factory } from "../../typechain";
50-
import { formatUsdc, requireEnv, isSolanaDevnet } from "./utils/helpers";
51+
import { formatUsdc, requireEnv } from "./utils/helpers";
5152

5253
// Set up Solana provider.
5354
const provider = AnchorProvider.env();

scripts/svm/executeRebalanceToHubPool.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,27 @@ import { SvmSpoke } from "../../target/types/svm_spoke";
4848
import { CHAIN_IDs } from "../../utils/constants";
4949
// eslint-disable-next-line camelcase
5050
import { HubPool__factory } from "../../typechain";
51-
import {
52-
CIRCLE_IRIS_API_URL_DEVNET,
53-
CIRCLE_IRIS_API_URL_MAINNET,
54-
SOLANA_SPOKE_STATE_SEED,
55-
SOLANA_USDC_DEVNET,
56-
SOLANA_USDC_MAINNET,
57-
} from "./utils/constants";
5851
import {
5952
constructEmptyPoolRebalanceTree,
6053
constructSimpleRebalanceTreeToHubPool,
6154
formatUsdc,
62-
getSolanaChainId,
6355
requireEnv,
64-
isSolanaDevnet,
6556
} from "./utils/helpers";
6657

6758
import { getNodeUrl, MerkleTree } from "@uma/common";
68-
import { decodeMessageHeader, getMessages } from "../../test/svm/cctpHelpers";
59+
import {
60+
CIRCLE_IRIS_API_URL_DEVNET,
61+
CIRCLE_IRIS_API_URL_MAINNET,
62+
decodeMessageHeader,
63+
getMessages,
64+
getSolanaChainId,
65+
isSolanaDevnet,
66+
loadExecuteRelayerRefundLeafParams,
67+
SOLANA_SPOKE_STATE_SEED,
68+
SOLANA_USDC_DEVNET,
69+
SOLANA_USDC_MAINNET,
70+
} from "../../src/svm";
6971
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../src/types/svm";
70-
import { loadExecuteRelayerRefundLeafParams } from "../../src/svm";
7172

7273
// Set up Solana provider.
7374
const provider = AnchorProvider.env();

scripts/svm/executeRebalanceToSpokePool.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../../utils/constants";
1313
import { SvmSpoke } from "../../target/types/svm_spoke";
1414
import yargs from "yargs";
1515
import { hideBin } from "yargs/helpers";
16-
import { evmAddressToPublicKey } from "../../src/svm";
17-
import { MessageTransmitter } from "../../target/types/message_transmitter";
18-
import { TokenMessengerMinter } from "../../target/types/token_messenger_minter";
19-
import { ethers, BigNumber } from "ethers";
20-
// eslint-disable-next-line camelcase
21-
import { HubPool__factory } from "../../typechain";
2216
import {
2317
CIRCLE_IRIS_API_URL_DEVNET,
2418
CIRCLE_IRIS_API_URL_MAINNET,
19+
decodeMessageHeader,
20+
evmAddressToPublicKey,
21+
getMessages,
22+
getSolanaChainId,
23+
isSolanaDevnet,
2524
SOLANA_USDC_DEVNET,
2625
SOLANA_USDC_MAINNET,
27-
} from "./utils/constants";
26+
} from "../../src/svm";
27+
import { MessageTransmitter } from "../../target/types/message_transmitter";
28+
import { TokenMessengerMinter } from "../../target/types/token_messenger_minter";
29+
import { ethers, BigNumber } from "ethers";
30+
// eslint-disable-next-line camelcase
31+
import { HubPool__factory } from "../../typechain";
2832
import { constructSimpleRebalanceTree } from "./utils/poolRebalanceTree";
29-
import { decodeMessageHeader, getMessages } from "../../test/svm/cctpHelpers";
30-
import { getSolanaChainId, isSolanaDevnet, requireEnv } from "./utils/helpers";
33+
import { requireEnv } from "./utils/helpers";
3134

3235
// Set up Solana provider.
3336
const provider = AnchorProvider.env();

scripts/svm/proposeRebalanceToHubPool.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ import { getNodeUrl } from "@uma/common";
3030
import { BigNumber, ethers } from "ethers";
3131
import yargs from "yargs";
3232
import { hideBin } from "yargs/helpers";
33+
import { getSolanaChainId, SOLANA_USDC_DEVNET, SOLANA_USDC_MAINNET } from "../../src/svm";
3334
import { BondToken__factory, HubPool__factory } from "../../typechain";
3435
import { CHAIN_IDs } from "../../utils/constants";
35-
import { SOLANA_USDC_DEVNET, SOLANA_USDC_MAINNET } from "./utils/constants";
3636
import {
3737
constructEmptyPoolRebalanceTree,
3838
constructSimpleRebalanceTreeToHubPool,
3939
formatUsdc,
40-
getSolanaChainId,
4140
requireEnv,
4241
} from "./utils/helpers";
4342

scripts/svm/proposeRebalanceToSpokePool.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
// - NODE_URL_11155111: Ethereum RPC URL for Sepolia (ignored if TESTNET=false).
88

99
// eslint-disable-next-line camelcase
10-
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../../utils/constants";
10+
import { getNodeUrl } from "@uma/common";
11+
import { BigNumber, ethers } from "ethers";
1112
import yargs from "yargs";
1213
import { hideBin } from "yargs/helpers";
13-
import { ethers, BigNumber } from "ethers";
14-
import { getNodeUrl } from "@uma/common";
14+
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../../utils/constants";
1515
// eslint-disable-next-line camelcase
16+
import { getSolanaChainId } from "../../src/svm";
1617
import { BondToken__factory, HubPool__factory } from "../../typechain";
18+
import { requireEnv } from "./utils/helpers";
1719
import { constructSimpleRebalanceTree } from "./utils/poolRebalanceTree";
18-
import { getSolanaChainId, requireEnv } from "./utils/helpers";
1920

2021
// Set up Ethereum provider.
2122
const nodeURL = process.env.TESTNET === "true" ? getNodeUrl("sepolia", true) : getNodeUrl("mainnet", true);

scripts/svm/remoteHubPoolPauseDeposits.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66
import * as anchor from "@coral-xyz/anchor";
77
import { AnchorProvider, BN, Program, web3 } from "@coral-xyz/anchor";
88
import { AccountMeta, PublicKey } from "@solana/web3.js";
9+
import { getNodeUrl } from "@uma/common";
910
import "dotenv/config";
1011
import { ethers } from "ethers";
1112
import yargs from "yargs";
1213
import { hideBin } from "yargs/helpers";
13-
import { getNodeUrl } from "@uma/common";
14+
import {
15+
CIRCLE_IRIS_API_URL_DEVNET,
16+
CIRCLE_IRIS_API_URL_MAINNET,
17+
decodeMessageHeader,
18+
getMessages,
19+
isSolanaDevnet,
20+
} from "../../src/svm";
1421
import { MessageTransmitter } from "../../target/types/message_transmitter";
1522
import { SvmSpoke } from "../../target/types/svm_spoke";
16-
import { decodeMessageHeader, getMessages } from "../../test/svm/cctpHelpers";
1723
import { HubPool__factory } from "../../typechain";
18-
import { CIRCLE_IRIS_API_URL_DEVNET, CIRCLE_IRIS_API_URL_MAINNET } from "./utils/constants";
19-
import { isSolanaDevnet, requireEnv } from "./utils/helpers";
24+
import { requireEnv } from "./utils/helpers";
2025

2126
// Set up Solana provider.
2227
const provider = AnchorProvider.env();

scripts/svm/remoteHubPoolSetDepositRoute.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@
33
// - MNEMONIC: Mnemonic of the wallet that will sign the sending transaction on Ethereum
44
// - HUB_POOL_ADDRESS: Hub Pool address
55

6-
import "dotenv/config";
76
import * as anchor from "@coral-xyz/anchor";
8-
import { BN, Program, AnchorProvider, web3 } from "@coral-xyz/anchor";
7+
import { AnchorProvider, BN, Program, web3 } from "@coral-xyz/anchor";
8+
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
99
import { AccountMeta, PublicKey, SystemProgram } from "@solana/web3.js";
10-
import { SvmSpoke } from "../../target/types/svm_spoke";
10+
import { getNodeUrl } from "@uma/common";
11+
import "dotenv/config";
12+
import { ethers } from "ethers";
1113
import yargs from "yargs";
1214
import { hideBin } from "yargs/helpers";
13-
import { ethers } from "ethers";
14-
import { getNodeUrl } from "@uma/common";
15-
import { MessageTransmitter } from "../../target/types/message_transmitter";
16-
import { decodeMessageHeader, getMessages } from "../../test/svm/cctpHelpers";
17-
import { HubPool__factory } from "../../typechain";
18-
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
1915
import {
2016
CIRCLE_IRIS_API_URL_DEVNET,
2117
CIRCLE_IRIS_API_URL_MAINNET,
18+
decodeMessageHeader,
19+
fromBase58ToBytes32,
20+
fromBytes32ToAddress,
21+
getMessages,
22+
isSolanaDevnet,
2223
SOLANA_USDC_DEVNET,
2324
SOLANA_USDC_MAINNET,
24-
} from "./utils/constants";
25-
import { fromBase58ToBytes32, fromBytes32ToAddress, isSolanaDevnet, requireEnv } from "./utils/helpers";
25+
} from "../../src/svm";
26+
import { MessageTransmitter } from "../../target/types/message_transmitter";
27+
import { SvmSpoke } from "../../target/types/svm_spoke";
28+
import { HubPool__factory } from "../../typechain";
2629
import { CHAIN_IDs } from "../../utils/constants";
30+
import { requireEnv } from "./utils/helpers";
2731

2832
// Set up Solana provider.
2933
const provider = AnchorProvider.env();

scripts/svm/remotePauseDeposits.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22
// - NODE_URL_${CHAIN_ID}: Ethereum RPC URL (must point to the Mainnet or Sepolia depending on Solana cluster).
33
// - MNEMONIC: Mnemonic of the wallet that will sign the sending transaction on Ethereum
44

5-
import "dotenv/config";
65
import * as anchor from "@coral-xyz/anchor";
7-
import { BN, Program, AnchorProvider, web3 } from "@coral-xyz/anchor";
6+
import { AnchorProvider, BN, Program, web3 } from "@coral-xyz/anchor";
87
import { AccountMeta, PublicKey } from "@solana/web3.js";
9-
import { SvmSpoke } from "../../target/types/svm_spoke";
8+
import { getNodeUrl } from "@uma/common";
9+
import "dotenv/config";
10+
import { ethers } from "ethers";
1011
import yargs from "yargs";
1112
import { hideBin } from "yargs/helpers";
12-
import { ethers } from "ethers";
13-
import { getNodeUrl } from "@uma/common";
14-
import { MessageTransmitter } from "../../target/types/message_transmitter";
15-
import { decodeMessageHeader, getMessages } from "../../test/svm/cctpHelpers";
16-
import { isSolanaDevnet, requireEnv } from "./utils/helpers";
1713
import {
1814
CIRCLE_IRIS_API_URL_DEVNET,
1915
CIRCLE_IRIS_API_URL_MAINNET,
16+
decodeMessageHeader,
17+
getMessages,
18+
isSolanaDevnet,
2019
MAINNET_CCTP_MESSAGE_TRANSMITTER_ADDRESS,
2120
SEPOLIA_CCTP_MESSAGE_TRANSMITTER_ADDRESS,
22-
} from "./utils/constants";
21+
} from "../../src/svm";
22+
import { MessageTransmitter } from "../../target/types/message_transmitter";
23+
import { SvmSpoke } from "../../target/types/svm_spoke";
2324
import { CHAIN_IDs } from "../../utils/constants";
25+
import { requireEnv } from "./utils/helpers";
2426

2527
// Set up Solana provider.
2628
const provider = AnchorProvider.env();

scripts/svm/utils/helpers.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,19 @@
1-
import { utils as anchorUtils, BN, AnchorProvider } from "@coral-xyz/anchor";
2-
import { BigNumber, ethers } from "ethers";
1+
import { BN } from "@coral-xyz/anchor";
32
import { PublicKey } from "@solana/web3.js";
43
import { MerkleTree } from "@uma/common";
5-
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../../src/types/svm";
4+
import { BigNumber, ethers } from "ethers";
65
import { relayerRefundHashFn } from "../../../src/svm";
6+
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../../src/types/svm";
77

88
export const requireEnv = (name: string): string => {
99
if (!process.env[name]) throw new Error(`Environment variable ${name} is not set`);
1010
return process.env[name];
1111
};
1212

13-
export const getSolanaChainId = (cluster: "devnet" | "mainnet"): BigNumber => {
14-
return BigNumber.from(
15-
BigInt(ethers.utils.keccak256(ethers.utils.toUtf8Bytes(`solana-${cluster}`))) & BigInt("0xFFFFFFFFFFFFFFFF")
16-
);
17-
};
18-
19-
export const isSolanaDevnet = (provider: AnchorProvider): boolean => {
20-
const solanaRpcEndpoint = provider.connection.rpcEndpoint;
21-
if (solanaRpcEndpoint.includes("devnet")) return true;
22-
else if (solanaRpcEndpoint.includes("mainnet")) return false;
23-
else throw new Error(`Unsupported solanaCluster endpoint: ${solanaRpcEndpoint}`);
24-
};
25-
2613
export const formatUsdc = (amount: BigNumber): string => {
2714
return ethers.utils.formatUnits(amount, 6);
2815
};
2916

30-
export const fromBase58ToBytes32 = (input: string): string => {
31-
const decodedBytes = anchorUtils.bytes.bs58.decode(input);
32-
return "0x" + Buffer.from(decodedBytes).toString("hex");
33-
};
34-
35-
export const fromBytes32ToAddress = (input: string): string => {
36-
// Remove the '0x' prefix if present
37-
const hexString = input.startsWith("0x") ? input.slice(2) : input;
38-
39-
// Ensure the input is 64 characters long (32 bytes)
40-
if (hexString.length !== 64) {
41-
throw new Error("Invalid bytes32 string");
42-
}
43-
44-
// Get the last 40 characters (20 bytes) for the address
45-
const address = hexString.slice(-40);
46-
47-
return "0x" + address;
48-
};
49-
5017
export function constructEmptyPoolRebalanceTree(chainId: BigNumber, groupIndex: number) {
5118
const poolRebalanceLeaf = {
5219
chainId,

0 commit comments

Comments
 (0)