Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions governance/xc-admin/package-lock.json

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

1 change: 1 addition & 0 deletions governance/xc-admin/packages/crank-executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"format": "prettier --write \"src/**/*.ts\""
},
"dependencies": {
"@certusone/wormhole-sdk": "^0.9.9",
"@coral-xyz/anchor": "^0.26.0",
"@pythnetwork/client": "^2.9.0",
"@solana/web3.js": "^1.73.0",
Expand Down
51 changes: 49 additions & 2 deletions governance/xc-admin/packages/crank-executor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import {
AccountMeta,
Commitment,
Connection,
Keypair,
PublicKey,
SendTransactionError,
SystemProgram,
Transaction,
} from "@solana/web3.js";
import SquadsMesh, { DEFAULT_MULTISIG_PROGRAM_ID, getIxPDA } from "@sqds/mesh";
import * as fs from "fs";
import NodeWallet from "@project-serum/anchor/dist/cjs/nodewallet";
import { getProposals } from "xc-admin-common";
import {
getProposals,
MultisigParser,
WormholeMultisigInstruction,
} from "xc-admin-common";
import BN from "bn.js";
import { AnchorProvider } from "@project-serum/anchor";
import {
getPythClusterApiUrl,
PythCluster,
} from "@pythnetwork/client/lib/cluster";
import {
deriveFeeCollectorKey,
getWormholeBridgeData,
} from "@certusone/wormhole-sdk/lib/cjs/solana/wormhole";

export function envOrErr(env: string): string {
const val = process.env[env];
Expand All @@ -42,6 +52,15 @@ async function run() {
wallet: new NodeWallet(KEYPAIR),
multisigProgramId: DEFAULT_MULTISIG_PROGRAM_ID,
});
const multisigParser = MultisigParser.fromCluster(CLUSTER as PythCluster);
const wormholeFee = (
await getWormholeBridgeData(
squad.connection,
multisigParser.wormholeBridgeAddress!,
COMMITMENT
)
).config.fee;

const proposals = await getProposals(squad, VAULT, undefined, "executeReady");
for (const proposal of proposals) {
// If we have previously cancelled because the proposal was failing, don't attempt
Expand All @@ -51,7 +70,35 @@ async function run() {
i <= proposal.instructionIndex;
i++
) {
const transaction = new Transaction().add(
const instructionPda = getIxPDA(
proposal.publicKey,
new BN(i),
squad.multisigProgramId
)[0];
const instruction = await squad.getInstruction(instructionPda);
const parsedInstruction = multisigParser.parseInstruction({
programId: instruction.programId,
data: instruction.data as Buffer,
keys: instruction.keys as AccountMeta[],
});
const transaction = new Transaction();

if (
parsedInstruction instanceof WormholeMultisigInstruction &&
parsedInstruction.name == "postMessage"
) {
transaction.add(
SystemProgram.transfer({
lamports: wormholeFee,
toPubkey: deriveFeeCollectorKey(
multisigParser.wormholeBridgeAddress!
),
fromPubkey: squad.wallet.publicKey,
})
);
}

transaction.add(
await squad.buildExecuteInstruction(
proposal.publicKey,
getIxPDA(proposal.publicKey, new BN(i), squad.multisigProgramId)[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ export class MultisigParser {
}
}
}

export { WormholeMultisigInstruction } from "./WormholeMultisigInstruction";
export { PythMultisigInstruction } from "./PythMultisigInstruction";
36 changes: 26 additions & 10 deletions governance/xc-admin/packages/xc-admin-common/src/propose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import {
PublicKey,
Transaction,
TransactionInstruction,
SYSVAR_RENT_PUBKEY,
SYSVAR_CLOCK_PUBKEY,
SystemProgram,
} from "@solana/web3.js";
import { BN } from "bn.js";
import { AnchorProvider } from "@project-serum/anchor";
import {
createWormholeProgramInterface,
getPostMessageAccounts,
deriveWormholeBridgeDataKey,
deriveEmitterSequenceKey,
deriveFeeCollectorKey,
} from "@certusone/wormhole-sdk/lib/cjs/solana/wormhole";
import { ExecutePostedVaa } from "./governance_payload/ExecutePostedVaa";

Expand Down Expand Up @@ -36,7 +41,6 @@ export async function proposeInstructions(
): Promise<PublicKey> {
const msAccount = await squad.getMultisig(vault);
let txToSend: Transaction[] = [];

const createProposal = new Transaction().add(
await squad.buildCreateTransaction(
msAccount.publicKey,
Expand All @@ -61,7 +65,7 @@ export async function proposeInstructions(
vault,
newProposalAddress,
instructions[i],
i,
i + 1,
wormholeAddress
);
txToSend.push(
Expand Down Expand Up @@ -134,7 +138,7 @@ export async function wrapAsRemoteInstruction(
instructionIndex: number,
wormholeAddress: PublicKey
): Promise<SquadInstruction> {
const emitter = squad.getAuthorityPDA(vault, 0);
const emitter = squad.getAuthorityPDA(vault, 1);

const [messagePDA, messagePdaBump] = getIxAuthorityPDA(
proposalAddress,
Expand All @@ -156,12 +160,7 @@ export async function wrapAsRemoteInstruction(
instruction,
]).encode();

const accounts = getPostMessageAccounts(
wormholeAddress,
emitter,
emitter,
messagePDA
);
const accounts = getPostMessageAccounts(wormholeAddress, emitter, messagePDA);

return {
instruction: await wormholeProgram.methods
Expand All @@ -173,3 +172,20 @@ export async function wrapAsRemoteInstruction(
authorityType: "custom",
};
}
function getPostMessageAccounts(
wormholeAddress: PublicKey,
emitter: PublicKey,
message: PublicKey
) {
return {
bridge: deriveWormholeBridgeDataKey(wormholeAddress),
message,
emitter,
sequence: deriveEmitterSequenceKey(emitter, wormholeAddress),
payer: emitter,
feeCollector: deriveFeeCollectorKey(wormholeAddress),
clock: SYSVAR_CLOCK_PUBKEY,
rent: SYSVAR_RENT_PUBKEY,
systemProgram: SystemProgram.programId,
};
}