Skip to content

Commit 18d7a34

Browse files
solana: add new IDs (#192)
Co-authored-by: A5 Pickle <a5-pickle@users.noreply.github.com> Co-authored-by: Abhishek Rajput <abhi@qwestive.io>
1 parent b1593e0 commit 18d7a34

File tree

21 files changed

+240
-75
lines changed

21 files changed

+240
-75
lines changed

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

solana/Anchor.toml

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ token_router = "tD8RmtdcV7bzBeuFgyrFc8wvayj988ChccEzRQzo6md"
2323
matching_engine = "mPydpGUWxzERTNpyvTKdvS7v8kvw5sgwfiP8WQFrXVS"
2424
upgrade_manager = "ucdP9ktgrXgEUnn6roqD2SfdGMR2JSiWHUKv23oXwxt"
2525

26+
[programs.mainnet]
27+
token_router = "28topqjtJzMnPaGFmmZk68tzGmj9W9aMntaEK3QkgtRe"
28+
matching_engine = "HtkeCDdYY4i9ncAxXKjYTx8Uu3WM8JbtiLRYjtHwaVXb"
29+
upgrade_manager = "4jyJ7EEsYa72REdD8ZMBvHFTXZ4VYGQPUHaJTajsK8SN"
30+
2631
[registry]
2732
url = "https://api.apr.dev"
2833

solana/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ cargo-test:
3030
cargo-test-all:
3131
NETWORK=localnet $(MAKE) cargo-test
3232
NETWORK=testnet $(MAKE) cargo-test
33+
NETWORK=mainnet $(MAKE) cargo-test
3334

3435
.PHONY: build
3536
build:
@@ -79,6 +80,7 @@ lint:
7980
cargo fmt --check
8081
NETWORK=localnet $(MAKE) clippy
8182
NETWORK=testnet $(MAKE) clippy
83+
NETWORK=mainnet $(MAKE) clippy
8284

8385
ts/tests/artifacts:
8486
mkdir ts/tests/artifacts

solana/modules/common/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ repository.workspace = true
1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

1212
[features]
13+
mainnet = ["wormhole-solana-consts/mainnet", "wormhole-cctp-solana/mainnet"]
1314
testnet = ["wormhole-solana-consts/testnet", "wormhole-cctp-solana/testnet"]
1415
localnet = ["wormhole-solana-consts/mainnet", "wormhole-cctp-solana/mainnet"]
1516
idl-build = ["localnet", "anchor-lang/idl-build"]

solana/modules/common/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ pub use wormhole_solana_consts::USDC_MINT;
1717
use solana_program::{pubkey, pubkey::Pubkey};
1818

1919
cfg_if::cfg_if! {
20-
if #[cfg(feature = "testnet")] {
20+
if #[cfg(feature = "mainnet")] {
21+
pub const UPGRADE_MANAGER_PROGRAM_ID: Pubkey = pubkey!("4jyJ7EEsYa72REdD8ZMBvHFTXZ4VYGQPUHaJTajsK8SN");
22+
pub const UPGRADE_MANAGER_AUTHORITY: Pubkey = pubkey!("Ag7BnUJ6C3mFXTaJfL2v9eJM2QbQ7GNLsDyewdCCLY8r");
23+
} else if #[cfg(feature = "testnet")] {
2124
pub const UPGRADE_MANAGER_PROGRAM_ID: Pubkey = pubkey!("ucdP9ktgrXgEUnn6roqD2SfdGMR2JSiWHUKv23oXwxt");
2225
pub const UPGRADE_MANAGER_AUTHORITY: Pubkey = pubkey!("2sxpm9pvWmNWFzhgWtmxkMsdWk2uSNT9MoKvww53po1M");
2326
} else if #[cfg(feature = "localnet")] {

solana/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@wormhole-foundation/example-liquidity-layer-definitions": "0.0.1",
4040
"@wormhole-foundation/sdk-base": "^0.7.0-beta.6",
4141
"@wormhole-foundation/sdk-definitions": "^0.7.0-beta.6",
42+
"@wormhole-foundation/sdk-evm": "^0.7.0-beta.6",
4243
"@wormhole-foundation/sdk-solana": "^0.7.0-beta.6",
4344
"@wormhole-foundation/sdk-solana-core": "^0.7.0-beta.6",
4445
"anchor-0.29.0": "npm:@coral-xyz/anchor@^0.29.0",

solana/programs/matching-engine/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ no-entrypoint = []
1717
no-idl = []
1818
no-log-ix-name = []
1919
cpi = ["no-entrypoint"]
20+
mainnet = ["common/mainnet"]
2021
testnet = ["common/testnet"]
2122
localnet = ["common/localnet"]
2223
integration-test = ["localnet"]

solana/programs/matching-engine/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ pub use utils::admin::AddCctpRouterEndpointArgs;
1818
use anchor_lang::{prelude::*, solana_program::pubkey};
1919

2020
cfg_if::cfg_if! {
21-
if #[cfg(feature = "testnet")] {
21+
if #[cfg(feature = "mainnet")] {
22+
declare_id!("HtkeCDdYY4i9ncAxXKjYTx8Uu3WM8JbtiLRYjtHwaVXb");
23+
24+
const CUSTODIAN_BUMP: u8 = 254;
25+
const CCTP_MINT_RECIPIENT: Pubkey = pubkey!("HUXc7MBf55vWrrkevVbmJN8HAyfFtjLcPLBt9yWngKzm");
26+
} else if #[cfg(feature = "testnet")] {
2227
declare_id!("mPydpGUWxzERTNpyvTKdvS7v8kvw5sgwfiP8WQFrXVS");
2328

2429
const CUSTODIAN_BUMP: u8 = 254;

solana/programs/matching-engine/src/processor/admin/initialize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub struct Initialize<'info> {
8686
program_data.upgrade_authority_address.is_some()
8787
} @ MatchingEngineError::ImmutableProgram
8888
)]
89-
program_data: Account<'info, ProgramData>,
89+
program_data: Box<Account<'info, ProgramData>>,
9090

9191
/// CHECK: This program PDA will be the upgrade authority for the Token Router program.
9292
#[account(address = common::UPGRADE_MANAGER_AUTHORITY)]
@@ -110,7 +110,7 @@ pub struct InitializeArgs {
110110
}
111111

112112
pub fn initialize(ctx: Context<Initialize>, args: InitializeArgs) -> Result<()> {
113-
let owner: Pubkey = ctx.accounts.owner.key();
113+
let owner = ctx.accounts.owner.key();
114114
let auction_config_id = 0;
115115

116116
// We need to check that the upgrade authority is the owner passed into the account context.

solana/programs/token-router/Cargo.toml

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ no-entrypoint = []
1717
no-idl = []
1818
no-log-ix-name = []
1919
cpi = ["no-entrypoint"]
20-
testnet = ["common/testnet", "matching-engine/testnet"]
21-
localnet = ["common/localnet", "matching-engine/localnet"]
20+
mainnet = [
21+
"common/mainnet",
22+
"matching-engine/mainnet"
23+
]
24+
testnet = [
25+
"common/testnet",
26+
"matching-engine/testnet"
27+
]
28+
localnet = [
29+
"common/localnet",
30+
"matching-engine/localnet"
31+
]
2232
integration-test = ["localnet"]
2333
idl-build = [
2434
"localnet",

solana/programs/token-router/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ pub mod state;
1414
use anchor_lang::{prelude::*, solana_program::pubkey};
1515

1616
cfg_if::cfg_if! {
17-
if #[cfg(feature = "testnet")] {
17+
if #[cfg(feature = "mainnet")] {
18+
declare_id!("28topqjtJzMnPaGFmmZk68tzGmj9W9aMntaEK3QkgtRe");
19+
20+
const CUSTODIAN_BUMP: u8 = 255;
21+
const CCTP_MINT_RECIPIENT: Pubkey = pubkey!("J9jEttqjYkWWaWDvwuo69fLPEA9fHEUQqE62WjBCf55P");
22+
} else if #[cfg(feature = "testnet")] {
1823
declare_id!("tD8RmtdcV7bzBeuFgyrFc8wvayj988ChccEzRQzo6md");
1924

2025
const CUSTODIAN_BUMP: u8 = 255;

solana/programs/upgrade-manager/Cargo.toml

+15-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ no-entrypoint = []
1717
no-idl = []
1818
no-log-ix-name = []
1919
cpi = ["no-entrypoint"]
20-
testnet = ["common/testnet", "matching-engine/testnet", "token-router/testnet"]
21-
localnet = ["common/localnet", "matching-engine/localnet", "token-router/localnet"]
20+
mainnet = [
21+
"common/mainnet",
22+
"matching-engine/mainnet",
23+
"token-router/mainnet"
24+
]
25+
testnet = [
26+
"common/testnet",
27+
"matching-engine/testnet",
28+
"token-router/testnet"
29+
]
30+
localnet = [
31+
"common/localnet",
32+
"matching-engine/localnet",
33+
"token-router/localnet"
34+
]
2235
integration-test = ["localnet"]
2336
idl-build = [
2437
"localnet",

solana/programs/upgrade-manager/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use anchor_lang::prelude::*;
1717
declare_id!(common::UPGRADE_MANAGER_PROGRAM_ID);
1818

1919
cfg_if::cfg_if! {
20-
if #[cfg(feature = "testnet")] {
20+
if #[cfg(feature = "mainnet")] {
21+
const UPGRADE_AUTHORITY_BUMP: u8 = 255;
22+
} else if #[cfg(feature = "testnet")] {
2123
const UPGRADE_AUTHORITY_BUMP: u8 = 255;
2224
} else if #[cfg(feature = "localnet")] {
2325
const UPGRADE_AUTHORITY_BUMP: u8 = 255;

solana/ts/scripts/getMainnetInfo.ts

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { Connection, PublicKey } from "@solana/web3.js";
2+
import { Chain, toChainId } from "@wormhole-foundation/sdk-base";
3+
import { toUniversal } from "@wormhole-foundation/sdk-definitions";
4+
import "@wormhole-foundation/sdk-evm/address";
5+
import * as matchingEngineSdk from "../src/matchingEngine";
6+
import * as tokenRouterSdk from "../src/tokenRouter";
7+
8+
const USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
9+
10+
const CHAINS: Chain[] = ["Arbitrum", "Base"];
11+
12+
// Here we go.
13+
main();
14+
15+
// impl
16+
17+
async function main() {
18+
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");
19+
20+
console.log("Collecting Solana Matching Engine and Token Router Info...");
21+
console.log();
22+
{
23+
const matchingEngine = new matchingEngineSdk.MatchingEngineProgram(
24+
connection,
25+
matchingEngineSdk.mainnet(),
26+
USDC_MINT,
27+
);
28+
29+
const custodian = matchingEngine.custodianAddress();
30+
console.log("Matching Engine");
31+
console.log(" Custodian (NOTE: The Custodian's address is the program's emitter):");
32+
console.log(` Native: ${custodian.toString()}`);
33+
console.log(` Universal: ${custodian.toBuffer().toString("hex")}`);
34+
console.log();
35+
36+
const cctpMintRecipient = matchingEngine.cctpMintRecipientAddress();
37+
console.log(" Mint Recipient:");
38+
console.log(` Native: ${cctpMintRecipient.toString()}`);
39+
console.log(` Universal: ${cctpMintRecipient.toBuffer().toString("hex")}`);
40+
console.log();
41+
42+
const custodianData = await matchingEngine.fetchCustodian();
43+
console.log("Custodian Data");
44+
console.log(JSON.stringify(custodianData, null, 2));
45+
console.log();
46+
47+
const auctionConfig = await matchingEngine.fetchAuctionConfig(
48+
custodianData.auctionConfigId,
49+
);
50+
console.log("Auction Config Data");
51+
console.log(JSON.stringify(auctionConfig, null, 2));
52+
console.log();
53+
54+
for (const chainName of CHAINS) {
55+
await matchingEngine
56+
.fetchRouterEndpointInfo(toChainId(chainName))
57+
.then((endpointData) => {
58+
console.log(
59+
`Registered Endpoint (${chainName}): ${stringifyEndpoint(
60+
chainName,
61+
endpointData,
62+
)}`,
63+
);
64+
})
65+
.catch((err) => {
66+
console.log(`Not Registered: ${chainName}`);
67+
});
68+
console.log();
69+
}
70+
}
71+
72+
{
73+
const tokenRouter = new tokenRouterSdk.TokenRouterProgram(
74+
connection,
75+
tokenRouterSdk.mainnet(),
76+
USDC_MINT,
77+
);
78+
79+
const custodian = tokenRouter.custodianAddress();
80+
console.log(`Token Router`);
81+
console.log(" Custodian (NOTE: The Custodian's address is the program's emitter):");
82+
console.log(` Native: ${custodian.toString()}`);
83+
console.log(` Universal: ${custodian.toBuffer().toString("hex")}`);
84+
console.log();
85+
86+
const cctpMintRecipient = tokenRouter.cctpMintRecipientAddress();
87+
console.log(" Mint Recipient:");
88+
console.log(` Native: ${cctpMintRecipient.toString()}`);
89+
console.log(` Universal: ${cctpMintRecipient.toBuffer().toString("hex")}`);
90+
console.log();
91+
}
92+
}
93+
94+
function stringifyEndpoint(chain: Chain, endpoint: matchingEngineSdk.EndpointInfo) {
95+
const out = {
96+
address: toUniversal(chain, Uint8Array.from(endpoint.address)).toNative(chain).toString(),
97+
mintRecipient: toUniversal(chain, Uint8Array.from(endpoint.mintRecipient))
98+
.toNative(chain)
99+
.toString(),
100+
protocol: endpoint.protocol,
101+
};
102+
return JSON.stringify(out, null, 2);
103+
}

solana/ts/scripts/getTestnetInfo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as tokenRouterSdk from "../src/tokenRouter";
66

77
const USDC_MINT = new PublicKey("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU");
88

9-
const CHAINS: Chain[] = [
9+
export const CHAINS: Chain[] = [
1010
"Sepolia",
1111
"Avalanche",
1212
"OptimismSepolia",

solana/ts/scripts/setUpMatchingEngineLut.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
} from "@solana/web3.js";
99
import "dotenv/config";
1010
import { MatchingEngineProgram } from "../src/matchingEngine";
11+
import { CHAINS } from "./getTestnetInfo";
12+
import { toChainId } from "@wormhole-foundation/sdk-base";
1113

1214
const PROGRAM_ID = "mPydpGUWxzERTNpyvTKdvS7v8kvw5sgwfiP8WQFrXVS";
1315
const USDC_MINT = new PublicKey("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU");
@@ -39,16 +41,44 @@ async function main() {
3941
// ]);
4042
// console.log("createTx", createTx);
4143

42-
const lookupTable = new PublicKey("pGTATFy5xgzdxu6XpiCzCu1uE3Ur473gGUD2pZykahf");
44+
const lookupTable = new PublicKey("DaZU4eDFxq8hAHf78HLUyhWe8G2tszyaNUJoFgDCqqs8");
4345

4446
const usdcCommonAccounts = await matchingEngine.commonAccounts();
4547

48+
const addresses = [
49+
...Object.values(usdcCommonAccounts).filter((key) => key !== undefined),
50+
payer.publicKey,
51+
];
52+
53+
const uniqueAddresses = new Map<string, PublicKey>();
54+
55+
for (const chainName of CHAINS) {
56+
const { protocol } = await matchingEngine.fetchRouterEndpointInfo(toChainId(chainName));
57+
58+
if (protocol.cctp?.domain === undefined) {
59+
console.warn(`Couldn't find cctp domain for ${chainName}`);
60+
continue;
61+
}
62+
const { remoteTokenMessenger, tokenMessengerMinterEventAuthority } = await matchingEngine
63+
.tokenMessengerMinterProgram()
64+
.depositForBurnWithCallerAccounts(matchingEngine.mint, protocol.cctp?.domain);
65+
66+
uniqueAddresses.set(remoteTokenMessenger.toBase58(), remoteTokenMessenger);
67+
// Note: Some of the tokenMessengerMinterEventAuthority addresses are the same across cctp domains.
68+
uniqueAddresses.set(
69+
tokenMessengerMinterEventAuthority.toBase58(),
70+
tokenMessengerMinterEventAuthority,
71+
);
72+
}
73+
74+
addresses.push(...Array.from(uniqueAddresses.values()));
75+
4676
// Extend.
4777
const extendIx = AddressLookupTableProgram.extendLookupTable({
4878
payer: payer.publicKey,
4979
authority: payer.publicKey,
5080
lookupTable,
51-
addresses: Object.values(usdcCommonAccounts).filter((key) => key !== undefined),
81+
addresses,
5282
});
5383

5484
const extendTx = await sendAndConfirmTransaction(

solana/ts/src/cctp/messageTransmitter/index.ts

+2-26
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class MessageTransmitterProgram {
3333
program: Program<MessageTransmitter>;
3434

3535
constructor(connection: Connection, programId?: ProgramId) {
36-
this._programId = programId ?? testnet();
36+
this._programId = programId ?? PROGRAM_IDS[0];
3737
this.program = new Program(IDL, new PublicKey(this._programId), {
3838
connection,
3939
});
@@ -71,23 +71,7 @@ export class MessageTransmitterProgram {
7171
}
7272

7373
tokenMessengerMinterProgram(): TokenMessengerMinterProgram {
74-
switch (this._programId) {
75-
case testnet(): {
76-
return new TokenMessengerMinterProgram(
77-
this.program.provider.connection,
78-
"CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3",
79-
);
80-
}
81-
case mainnet(): {
82-
return new TokenMessengerMinterProgram(
83-
this.program.provider.connection,
84-
"CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3",
85-
);
86-
}
87-
default: {
88-
throw new Error("unsupported network");
89-
}
90-
}
74+
return new TokenMessengerMinterProgram(this.program.provider.connection);
9175
}
9276

9377
receiveTokenMessengerMinterMessageAccounts(
@@ -133,11 +117,3 @@ export class MessageTransmitterProgram {
133117
.instruction();
134118
}
135119
}
136-
137-
export function mainnet(): ProgramId {
138-
return "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd";
139-
}
140-
141-
export function testnet(): ProgramId {
142-
return "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd";
143-
}

0 commit comments

Comments
 (0)