Skip to content

Commit

Permalink
deploy: a few fixes for the initialize matching engine script
Browse files Browse the repository at this point in the history
  • Loading branch information
scnale committed Jul 26, 2024
1 parent 2626572 commit db47f93
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
7 changes: 4 additions & 3 deletions deployment/helpers/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export async function runOnSolana(scriptName: string, cb: SolanaScriptCb) {
const log = (...args: any[]) => console.log(`[${chain.chainId}]`, ...args);
const signer = await getSigner();
// TODO: encode in base58
log(`Starting script. Signer: ${(await signer.getAddress()).toString("hex")}`);
const signerPubkey = new PublicKey(await signer.getAddress()).toBase58();
log(`Starting script. Signer: ${signerPubkey}`);

try {
await cb(chain, signer, log);
Expand Down Expand Up @@ -95,15 +96,15 @@ async function addLedgerSignature(tx: Transaction, signer: SolanaLedgerSigner, s
}

export function getMatchingEngineProgram(connection: Connection) {
const matchingEngineId = getContractAddress("MatchingEngine", toChainId("Solana")) as MatchingEngineProgramId;
const matchingEngineId = getContractAddress("MatchingEngineProxy", toChainId("Solana")) as MatchingEngineProgramId;
const network = env === "mainnet" ? "Mainnet" : "Testnet";

const usdcMint = new PublicKey(circle.usdcContract(network, "Solana"));
return new MatchingEngineProgram(connection, matchingEngineId, usdcMint);
};

export function getTokenRouterProgram(connection: Connection) {
const tokenRouterId = getContractAddress("TokenRouter", toChainId("Solana")) as TokenRouterProgramId;
const tokenRouterId = getContractAddress("TokenRouterProxy", toChainId("Solana")) as TokenRouterProgramId;
const network = env === "mainnet" ? "Mainnet" : "Testnet";

const usdcMint = new PublicKey(circle.usdcContract(network, "Solana"));
Expand Down
2 changes: 1 addition & 1 deletion deployment/scripts/evm/TokenRouter/upgrade-token-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function checkImmutables(tokenRouter: TokenRouter, chain: ChainInfo, match
tokenRouter.matchingEngineAddress(),
]);

const localMatchingEngineAddress = getContractAddress("MatchingEngine", matchingEngineChain);
const localMatchingEngineAddress = getContractAddress("MatchingEngineProxy", matchingEngineChain);
const matchingEngineAddress = toUniversal("Solana", localMatchingEngineAddress).toString();
const tokenAddress = getDependencyAddress("token", chain.chainId);

Expand Down
2 changes: 1 addition & 1 deletion deployment/scripts/evm/TokenRouter/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function deployImplementation(signer: ethers.Signer, config: TokenR
const tokenMessenger = getDependencyAddress("tokenMessenger", config.chainId);

const matchingEngineAddress = toUniversal("Solana", (getContractAddress(
"MatchingEngine",
"MatchingEngineProxy",
matchingEngineChain
))).toString();

Expand Down
9 changes: 5 additions & 4 deletions deployment/scripts/solana/initializeMatchingEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { circle } from "@wormhole-foundation/sdk-base";

solana.runOnSolana("deploy-matching-engine", async (chain, signer, log) => {
const config = await getChainConfig<MatchingEngineConfiguration>("matching-engine", chain.chainId);
const matchingEngineId = getContractAddress("MatchingEngine", chain.chainId) as ProgramId;
const matchingEngineId = getContractAddress("MatchingEngineProxy", chain.chainId) as ProgramId;

const env = "Mainnet";
const usdcMint = new PublicKey(circle.usdcContract(env, "Solana"));
Expand Down Expand Up @@ -50,11 +50,12 @@ async function initialize(matchingEngine: MatchingEngineProgram, signer: SolanaL
}
const initializeInstructions = [];
const priorityFee = ComputeBudgetProgram.setComputeUnitPrice({ microLamports: solana.priorityMicrolamports });
const feeRecipient = new PublicKey(config.feeRecipient);
initializeInstructions.push(await matchingEngine.initializeIx(
{
owner: signerPubkey,
ownerAssistant: new PublicKey(config.ownerAssistant),
feeRecipient: new PublicKey(config.feeRecipient),
feeRecipient,
},
auctionParams
));
Expand All @@ -63,9 +64,9 @@ async function initialize(matchingEngine: MatchingEngineProgram, signer: SolanaL
// TODO: this doesn't check if the ATA already exists
const splToken = await import("@solana/spl-token");
const assocciatedTokenProgramId = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
const associatedToken = splToken.getAssociatedTokenAddressSync(usdcMint, signerPubkey, undefined, usdcMint, assocciatedTokenProgramId);
const associatedToken = splToken.getAssociatedTokenAddressSync(usdcMint, feeRecipient, undefined, usdcMint, assocciatedTokenProgramId);
const createAtaInstructions = [];
createAtaInstructions.push(splToken.createAssociatedTokenAccountInstruction(signerPubkey, associatedToken, signerPubkey, usdcMint));
createAtaInstructions.push(splToken.createAssociatedTokenAccountInstruction(signerPubkey, associatedToken, feeRecipient, usdcMint));
createAtaInstructions.push(priorityFee);

const createAtaTxid = await solana.ledgerSignAndSend(connection, createAtaInstructions, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { TokenRouterProgram } from "@wormhole-foundation/example-liquidity-layer


solana.runOnSolana("register-routers-matching-engine", async (chain, signer, log) => {
const matchingEngineId = getContractAddress("MatchingEngine", chain.chainId) as ProgramId;
const matchingEngineId = getContractAddress("MatchingEngineProxy", chain.chainId) as ProgramId;

if (chain.network === "Devnet")
throw new Error("Devnet is not supported by USDC. Use Mainnet or Testnet.");
Expand Down

0 comments on commit db47f93

Please sign in to comment.