Skip to content

Commit

Permalink
solana: add new IDs (#192)
Browse files Browse the repository at this point in the history
Co-authored-by: A5 Pickle <[email protected]>
Co-authored-by: Abhishek Rajput <[email protected]>
  • Loading branch information
3 people authored Oct 7, 2024
1 parent b1593e0 commit 18d7a34
Show file tree
Hide file tree
Showing 21 changed files with 240 additions and 75 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions solana/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ token_router = "tD8RmtdcV7bzBeuFgyrFc8wvayj988ChccEzRQzo6md"
matching_engine = "mPydpGUWxzERTNpyvTKdvS7v8kvw5sgwfiP8WQFrXVS"
upgrade_manager = "ucdP9ktgrXgEUnn6roqD2SfdGMR2JSiWHUKv23oXwxt"

[programs.mainnet]
token_router = "28topqjtJzMnPaGFmmZk68tzGmj9W9aMntaEK3QkgtRe"
matching_engine = "HtkeCDdYY4i9ncAxXKjYTx8Uu3WM8JbtiLRYjtHwaVXb"
upgrade_manager = "4jyJ7EEsYa72REdD8ZMBvHFTXZ4VYGQPUHaJTajsK8SN"

[registry]
url = "https://api.apr.dev"

Expand Down
2 changes: 2 additions & 0 deletions solana/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cargo-test:
cargo-test-all:
NETWORK=localnet $(MAKE) cargo-test
NETWORK=testnet $(MAKE) cargo-test
NETWORK=mainnet $(MAKE) cargo-test

.PHONY: build
build:
Expand Down Expand Up @@ -79,6 +80,7 @@ lint:
cargo fmt --check
NETWORK=localnet $(MAKE) clippy
NETWORK=testnet $(MAKE) clippy
NETWORK=mainnet $(MAKE) clippy

ts/tests/artifacts:
mkdir ts/tests/artifacts
Expand Down
1 change: 1 addition & 0 deletions solana/modules/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
mainnet = ["wormhole-solana-consts/mainnet", "wormhole-cctp-solana/mainnet"]
testnet = ["wormhole-solana-consts/testnet", "wormhole-cctp-solana/testnet"]
localnet = ["wormhole-solana-consts/mainnet", "wormhole-cctp-solana/mainnet"]
idl-build = ["localnet", "anchor-lang/idl-build"]
Expand Down
5 changes: 4 additions & 1 deletion solana/modules/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pub use wormhole_solana_consts::USDC_MINT;
use solana_program::{pubkey, pubkey::Pubkey};

cfg_if::cfg_if! {
if #[cfg(feature = "testnet")] {
if #[cfg(feature = "mainnet")] {
pub const UPGRADE_MANAGER_PROGRAM_ID: Pubkey = pubkey!("4jyJ7EEsYa72REdD8ZMBvHFTXZ4VYGQPUHaJTajsK8SN");
pub const UPGRADE_MANAGER_AUTHORITY: Pubkey = pubkey!("Ag7BnUJ6C3mFXTaJfL2v9eJM2QbQ7GNLsDyewdCCLY8r");
} else if #[cfg(feature = "testnet")] {
pub const UPGRADE_MANAGER_PROGRAM_ID: Pubkey = pubkey!("ucdP9ktgrXgEUnn6roqD2SfdGMR2JSiWHUKv23oXwxt");
pub const UPGRADE_MANAGER_AUTHORITY: Pubkey = pubkey!("2sxpm9pvWmNWFzhgWtmxkMsdWk2uSNT9MoKvww53po1M");
} else if #[cfg(feature = "localnet")] {
Expand Down
1 change: 1 addition & 0 deletions solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@wormhole-foundation/example-liquidity-layer-definitions": "0.0.1",
"@wormhole-foundation/sdk-base": "^0.7.0-beta.6",
"@wormhole-foundation/sdk-definitions": "^0.7.0-beta.6",
"@wormhole-foundation/sdk-evm": "^0.7.0-beta.6",
"@wormhole-foundation/sdk-solana": "^0.7.0-beta.6",
"@wormhole-foundation/sdk-solana-core": "^0.7.0-beta.6",
"anchor-0.29.0": "npm:@coral-xyz/anchor@^0.29.0",
Expand Down
1 change: 1 addition & 0 deletions solana/programs/matching-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
mainnet = ["common/mainnet"]
testnet = ["common/testnet"]
localnet = ["common/localnet"]
integration-test = ["localnet"]
Expand Down
7 changes: 6 additions & 1 deletion solana/programs/matching-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ pub use utils::admin::AddCctpRouterEndpointArgs;
use anchor_lang::{prelude::*, solana_program::pubkey};

cfg_if::cfg_if! {
if #[cfg(feature = "testnet")] {
if #[cfg(feature = "mainnet")] {
declare_id!("HtkeCDdYY4i9ncAxXKjYTx8Uu3WM8JbtiLRYjtHwaVXb");

const CUSTODIAN_BUMP: u8 = 254;
const CCTP_MINT_RECIPIENT: Pubkey = pubkey!("HUXc7MBf55vWrrkevVbmJN8HAyfFtjLcPLBt9yWngKzm");
} else if #[cfg(feature = "testnet")] {
declare_id!("mPydpGUWxzERTNpyvTKdvS7v8kvw5sgwfiP8WQFrXVS");

const CUSTODIAN_BUMP: u8 = 254;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct Initialize<'info> {
program_data.upgrade_authority_address.is_some()
} @ MatchingEngineError::ImmutableProgram
)]
program_data: Account<'info, ProgramData>,
program_data: Box<Account<'info, ProgramData>>,

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

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

// We need to check that the upgrade authority is the owner passed into the account context.
Expand Down
14 changes: 12 additions & 2 deletions solana/programs/token-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
testnet = ["common/testnet", "matching-engine/testnet"]
localnet = ["common/localnet", "matching-engine/localnet"]
mainnet = [
"common/mainnet",
"matching-engine/mainnet"
]
testnet = [
"common/testnet",
"matching-engine/testnet"
]
localnet = [
"common/localnet",
"matching-engine/localnet"
]
integration-test = ["localnet"]
idl-build = [
"localnet",
Expand Down
7 changes: 6 additions & 1 deletion solana/programs/token-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ pub mod state;
use anchor_lang::{prelude::*, solana_program::pubkey};

cfg_if::cfg_if! {
if #[cfg(feature = "testnet")] {
if #[cfg(feature = "mainnet")] {
declare_id!("28topqjtJzMnPaGFmmZk68tzGmj9W9aMntaEK3QkgtRe");

const CUSTODIAN_BUMP: u8 = 255;
const CCTP_MINT_RECIPIENT: Pubkey = pubkey!("J9jEttqjYkWWaWDvwuo69fLPEA9fHEUQqE62WjBCf55P");
} else if #[cfg(feature = "testnet")] {
declare_id!("tD8RmtdcV7bzBeuFgyrFc8wvayj988ChccEzRQzo6md");

const CUSTODIAN_BUMP: u8 = 255;
Expand Down
17 changes: 15 additions & 2 deletions solana/programs/upgrade-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
testnet = ["common/testnet", "matching-engine/testnet", "token-router/testnet"]
localnet = ["common/localnet", "matching-engine/localnet", "token-router/localnet"]
mainnet = [
"common/mainnet",
"matching-engine/mainnet",
"token-router/mainnet"
]
testnet = [
"common/testnet",
"matching-engine/testnet",
"token-router/testnet"
]
localnet = [
"common/localnet",
"matching-engine/localnet",
"token-router/localnet"
]
integration-test = ["localnet"]
idl-build = [
"localnet",
Expand Down
4 changes: 3 additions & 1 deletion solana/programs/upgrade-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use anchor_lang::prelude::*;
declare_id!(common::UPGRADE_MANAGER_PROGRAM_ID);

cfg_if::cfg_if! {
if #[cfg(feature = "testnet")] {
if #[cfg(feature = "mainnet")] {
const UPGRADE_AUTHORITY_BUMP: u8 = 255;
} else if #[cfg(feature = "testnet")] {
const UPGRADE_AUTHORITY_BUMP: u8 = 255;
} else if #[cfg(feature = "localnet")] {
const UPGRADE_AUTHORITY_BUMP: u8 = 255;
Expand Down
103 changes: 103 additions & 0 deletions solana/ts/scripts/getMainnetInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Connection, PublicKey } from "@solana/web3.js";
import { Chain, toChainId } from "@wormhole-foundation/sdk-base";
import { toUniversal } from "@wormhole-foundation/sdk-definitions";
import "@wormhole-foundation/sdk-evm/address";
import * as matchingEngineSdk from "../src/matchingEngine";
import * as tokenRouterSdk from "../src/tokenRouter";

const USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");

const CHAINS: Chain[] = ["Arbitrum", "Base"];

// Here we go.
main();

// impl

async function main() {
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");

console.log("Collecting Solana Matching Engine and Token Router Info...");
console.log();
{
const matchingEngine = new matchingEngineSdk.MatchingEngineProgram(
connection,
matchingEngineSdk.mainnet(),
USDC_MINT,
);

const custodian = matchingEngine.custodianAddress();
console.log("Matching Engine");
console.log(" Custodian (NOTE: The Custodian's address is the program's emitter):");
console.log(` Native: ${custodian.toString()}`);
console.log(` Universal: ${custodian.toBuffer().toString("hex")}`);
console.log();

const cctpMintRecipient = matchingEngine.cctpMintRecipientAddress();
console.log(" Mint Recipient:");
console.log(` Native: ${cctpMintRecipient.toString()}`);
console.log(` Universal: ${cctpMintRecipient.toBuffer().toString("hex")}`);
console.log();

const custodianData = await matchingEngine.fetchCustodian();
console.log("Custodian Data");
console.log(JSON.stringify(custodianData, null, 2));
console.log();

const auctionConfig = await matchingEngine.fetchAuctionConfig(
custodianData.auctionConfigId,
);
console.log("Auction Config Data");
console.log(JSON.stringify(auctionConfig, null, 2));
console.log();

for (const chainName of CHAINS) {
await matchingEngine
.fetchRouterEndpointInfo(toChainId(chainName))
.then((endpointData) => {
console.log(
`Registered Endpoint (${chainName}): ${stringifyEndpoint(
chainName,
endpointData,
)}`,
);
})
.catch((err) => {
console.log(`Not Registered: ${chainName}`);
});
console.log();
}
}

{
const tokenRouter = new tokenRouterSdk.TokenRouterProgram(
connection,
tokenRouterSdk.mainnet(),
USDC_MINT,
);

const custodian = tokenRouter.custodianAddress();
console.log(`Token Router`);
console.log(" Custodian (NOTE: The Custodian's address is the program's emitter):");
console.log(` Native: ${custodian.toString()}`);
console.log(` Universal: ${custodian.toBuffer().toString("hex")}`);
console.log();

const cctpMintRecipient = tokenRouter.cctpMintRecipientAddress();
console.log(" Mint Recipient:");
console.log(` Native: ${cctpMintRecipient.toString()}`);
console.log(` Universal: ${cctpMintRecipient.toBuffer().toString("hex")}`);
console.log();
}
}

function stringifyEndpoint(chain: Chain, endpoint: matchingEngineSdk.EndpointInfo) {
const out = {
address: toUniversal(chain, Uint8Array.from(endpoint.address)).toNative(chain).toString(),
mintRecipient: toUniversal(chain, Uint8Array.from(endpoint.mintRecipient))
.toNative(chain)
.toString(),
protocol: endpoint.protocol,
};
return JSON.stringify(out, null, 2);
}
2 changes: 1 addition & 1 deletion solana/ts/scripts/getTestnetInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as tokenRouterSdk from "../src/tokenRouter";

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

const CHAINS: Chain[] = [
export const CHAINS: Chain[] = [
"Sepolia",
"Avalanche",
"OptimismSepolia",
Expand Down
34 changes: 32 additions & 2 deletions solana/ts/scripts/setUpMatchingEngineLut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "@solana/web3.js";
import "dotenv/config";
import { MatchingEngineProgram } from "../src/matchingEngine";
import { CHAINS } from "./getTestnetInfo";
import { toChainId } from "@wormhole-foundation/sdk-base";

const PROGRAM_ID = "mPydpGUWxzERTNpyvTKdvS7v8kvw5sgwfiP8WQFrXVS";
const USDC_MINT = new PublicKey("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU");
Expand Down Expand Up @@ -39,16 +41,44 @@ async function main() {
// ]);
// console.log("createTx", createTx);

const lookupTable = new PublicKey("pGTATFy5xgzdxu6XpiCzCu1uE3Ur473gGUD2pZykahf");
const lookupTable = new PublicKey("DaZU4eDFxq8hAHf78HLUyhWe8G2tszyaNUJoFgDCqqs8");

const usdcCommonAccounts = await matchingEngine.commonAccounts();

const addresses = [
...Object.values(usdcCommonAccounts).filter((key) => key !== undefined),
payer.publicKey,
];

const uniqueAddresses = new Map<string, PublicKey>();

for (const chainName of CHAINS) {
const { protocol } = await matchingEngine.fetchRouterEndpointInfo(toChainId(chainName));

if (protocol.cctp?.domain === undefined) {
console.warn(`Couldn't find cctp domain for ${chainName}`);
continue;
}
const { remoteTokenMessenger, tokenMessengerMinterEventAuthority } = await matchingEngine
.tokenMessengerMinterProgram()
.depositForBurnWithCallerAccounts(matchingEngine.mint, protocol.cctp?.domain);

uniqueAddresses.set(remoteTokenMessenger.toBase58(), remoteTokenMessenger);
// Note: Some of the tokenMessengerMinterEventAuthority addresses are the same across cctp domains.
uniqueAddresses.set(
tokenMessengerMinterEventAuthority.toBase58(),
tokenMessengerMinterEventAuthority,
);
}

addresses.push(...Array.from(uniqueAddresses.values()));

// Extend.
const extendIx = AddressLookupTableProgram.extendLookupTable({
payer: payer.publicKey,
authority: payer.publicKey,
lookupTable,
addresses: Object.values(usdcCommonAccounts).filter((key) => key !== undefined),
addresses,
});

const extendTx = await sendAndConfirmTransaction(
Expand Down
28 changes: 2 additions & 26 deletions solana/ts/src/cctp/messageTransmitter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class MessageTransmitterProgram {
program: Program<MessageTransmitter>;

constructor(connection: Connection, programId?: ProgramId) {
this._programId = programId ?? testnet();
this._programId = programId ?? PROGRAM_IDS[0];
this.program = new Program(IDL, new PublicKey(this._programId), {
connection,
});
Expand Down Expand Up @@ -71,23 +71,7 @@ export class MessageTransmitterProgram {
}

tokenMessengerMinterProgram(): TokenMessengerMinterProgram {
switch (this._programId) {
case testnet(): {
return new TokenMessengerMinterProgram(
this.program.provider.connection,
"CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3",
);
}
case mainnet(): {
return new TokenMessengerMinterProgram(
this.program.provider.connection,
"CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3",
);
}
default: {
throw new Error("unsupported network");
}
}
return new TokenMessengerMinterProgram(this.program.provider.connection);
}

receiveTokenMessengerMinterMessageAccounts(
Expand Down Expand Up @@ -133,11 +117,3 @@ export class MessageTransmitterProgram {
.instruction();
}
}

export function mainnet(): ProgramId {
return "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd";
}

export function testnet(): ProgramId {
return "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd";
}
Loading

0 comments on commit 18d7a34

Please sign in to comment.