Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
33 changes: 20 additions & 13 deletions governance/xc_admin/packages/xc_admin_cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
PROGRAM_AUTHORITY_ESCROW,
createDetermisticPriceStoreInitializePublisherInstruction,
createPriceStoreInstruction,
fetchStakeAccounts,
findDetermisticStakeAccountAddress,
getMultisigCluster,
getProposalInstructions,
Expand All @@ -59,6 +60,7 @@ import {
DEFAULT_PRIORITY_FEE_CONFIG,
TransactionBuilder,
} from "@pythnetwork/solana-utils";
import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";

export async function loadHotWalletOrLedger(
wallet: string,
Expand Down Expand Up @@ -389,8 +391,8 @@ multisigCommand(
"Deactivate the delegated stake from the account"
)
.requiredOption(
"-s, --stake-accounts <comma_separated_stake_account>",
"stake accounts to be deactivated"
"-d, --vote-pubkeys <comma_separated_voter_pubkeys>",
"vote account unstake from"
)
.action(async (options: any) => {
const vault = await loadVaultFromOptions(options);
Expand All @@ -399,20 +401,25 @@ multisigCommand(
cluster
);

const stakeAccounts = options.stakeAccounts
? options.stakeAccounts.split(",").map((m: string) => new PublicKey(m))
const voteAccounts: PublicKey[] = options.votePubkeys
? options.votePubkeys.split(",").map((m: string) => new PublicKey(m))
: [];

const instructions = stakeAccounts.reduce(
(instructions: TransactionInstruction[], stakeAccount: PublicKey) => {
const transaction = StakeProgram.deactivate({
stakePubkey: stakeAccount,
authorizedPubkey,
});
const stakeAccounts = (
await Promise.all(
voteAccounts.map((voteAccount: PublicKey) =>
fetchStakeAccounts(
new Connection(getPythClusterApiUrl(cluster)),
voteAccount
)
)
)
).flat();

return instructions.concat(transaction.instructions);
},
[]
const instructions = stakeAccounts.flatMap(
(stakeAccount) =>
StakeProgram.deactivate({ stakePubkey: stakeAccount, authorizedPubkey })
.instructions
);

await vault.proposeInstructions(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { TransactionInstruction } from "@solana/web3.js";
import {
Connection,
PublicKey,
StakeProgram,
TransactionInstruction,
} from "@solana/web3.js";
import {
MultisigInstruction,
MultisigInstructionProgram,
UNRECOGNIZED_INSTRUCTION,
} from ".";
import { AnchorAccounts } from "./anchor";
import { StakeInstruction } from "@solana/web3.js";
import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";

export class SolanaStakingMultisigInstruction implements MultisigInstruction {
readonly program = MultisigInstructionProgram.SolanaStakingProgram;
Expand Down Expand Up @@ -115,3 +121,31 @@ export class SolanaStakingMultisigInstruction implements MultisigInstruction {
}
}
}

export async function fetchStakeAccounts(
connection: Connection,
voterAccount: PublicKey
) {
const stakeAccounts = await connection.getProgramAccounts(
StakeProgram.programId,
{
encoding: "base64",
filters: [
{
memcmp: {
offset: 0,
bytes: bs58.encode(Buffer.from([2, 0, 0, 0])),
},
},
{
memcmp: {
offset: 124,
bytes: voterAccount.toBase58(),
},
},
],
}
);

return stakeAccounts.map((account) => account.pubkey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@ export { PythMultisigInstruction } from "./PythMultisigInstruction";
export { AnchorMultisigInstruction } from "./MessageBufferMultisigInstruction";
export { SystemProgramMultisigInstruction } from "./SystemProgramInstruction";
export { BpfUpgradableLoaderInstruction } from "./BpfUpgradableLoaderMultisigInstruction";
export { SolanaStakingMultisigInstruction } from "./SolanaStakingMultisigInstruction";
export {
SolanaStakingMultisigInstruction,
fetchStakeAccounts,
} from "./SolanaStakingMultisigInstruction";
Loading