Skip to content

Commit d63f933

Browse files
authored
feat(xc_admin_cli): support idl upgrades (#1935)
* go * go * fix: ts-node to devdependencies
1 parent 88f0e18 commit d63f933

File tree

6 files changed

+111
-25
lines changed

6 files changed

+111
-25
lines changed

governance/xc_admin/packages/xc_admin_cli/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@
3232
"@sqds/mesh": "^1.0.6",
3333
"commander": "^9.5.0",
3434
"typescript": "^4.9.4"
35+
},
36+
"dev-dependencies": {
37+
"ts-node": "^10.9.2"
3538
}
3639
}

governance/xc_admin/packages/xc_admin_cli/src/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
findDetermisticStakeAccountAddress,
4545
getMultisigCluster,
4646
getProposalInstructions,
47+
idlSetBuffer,
4748
isPriceStorePublisherInitialized,
4849
} from "@pythnetwork/xc-admin-common";
4950

@@ -284,6 +285,30 @@ multisigCommand("upgrade-program", "Upgrade a program from a buffer")
284285
);
285286
});
286287

288+
multisigCommand("upgrade-idl", "Upgrade an Anchor Idl from a bufffer")
289+
.requiredOption(
290+
"-p, --program-id <pubkey>",
291+
"program whose idl you want to upgrade"
292+
)
293+
.requiredOption("-b, --buffer <pubkey>", "buffer account")
294+
.action(async (options: any) => {
295+
const vault = await loadVaultFromOptions(options);
296+
const cluster: PythCluster = options.cluster;
297+
const programId: PublicKey = new PublicKey(options.programId);
298+
const buffer: PublicKey = new PublicKey(options.buffer);
299+
300+
const proposalInstruction: TransactionInstruction = await idlSetBuffer(
301+
programId,
302+
buffer,
303+
await vault.getVaultAuthorityPDA(cluster)
304+
);
305+
306+
await vault.proposeInstructions(
307+
[proposalInstruction],
308+
cluster,
309+
DEFAULT_PRIORITY_FEE_CONFIG
310+
);
311+
});
287312
async function closeProgramOrBuffer(
288313
vault: MultisigVault,
289314
cluster: PythCluster,

governance/xc_admin/packages/xc_admin_common/src/multisig_transaction/MessageBufferMultisigInstruction.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import {
44
UNRECOGNIZED_INSTRUCTION,
55
UnrecognizedProgram,
66
} from ".";
7-
import { AnchorAccounts, resolveAccountNames } from "./anchor";
7+
import {
8+
AnchorAccounts,
9+
IDL_SET_BUFFER_DISCRIMINATOR,
10+
resolveAccountNames,
11+
} from "./anchor";
812
import messageBufferIdl from "message_buffer/idl/message_buffer.json";
913
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
1014
import { Idl, BorshCoder } from "@coral-xyz/anchor";
@@ -66,6 +70,23 @@ export class AnchorMultisigInstruction implements MultisigInstruction {
6670
default:
6771
return UnrecognizedProgram.fromTransactionInstruction(instruction);
6872
}
73+
74+
/// Special case for IDL instructions that all programs have
75+
if (instruction.data.equals(IDL_SET_BUFFER_DISCRIMINATOR)) {
76+
return new AnchorMultisigInstruction(
77+
program,
78+
"IdlSetBuffer",
79+
{},
80+
{
81+
named: {
82+
buffer: instruction.keys[0],
83+
idlAccount: instruction.keys[1],
84+
idlAuthority: instruction.keys[2],
85+
},
86+
remaining: instruction.keys.slice(3),
87+
}
88+
);
89+
}
6990
const instructionCoder = new BorshCoder(idl).instruction;
7091

7192
const deserializedData = instructionCoder.decode(instruction.data);

governance/xc_admin/packages/xc_admin_common/src/multisig_transaction/anchor.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { Idl } from "@coral-xyz/anchor";
2-
import { AccountMeta, TransactionInstruction } from "@solana/web3.js";
2+
import {
3+
AccountMeta,
4+
PublicKey,
5+
TransactionInstruction,
6+
} from "@solana/web3.js";
37

48
type NamedAccounts = Record<string, AccountMeta>;
59
type RemainingAccounts = AccountMeta[];
@@ -28,3 +32,34 @@ export function resolveAccountNames(
2832
});
2933
return { named, remaining };
3034
}
35+
36+
export const IDL_SET_BUFFER_DISCRIMINATOR = Buffer.from(
37+
"40f4bc78a7e9690a03",
38+
"hex"
39+
);
40+
41+
async function getIdlAddress(programId: PublicKey): Promise<PublicKey> {
42+
const programSigner = PublicKey.findProgramAddressSync([], programId)[0];
43+
return PublicKey.createWithSeed(programSigner, "anchor:idl", programId);
44+
}
45+
46+
export async function idlSetBuffer(
47+
programId: PublicKey,
48+
buffer: PublicKey,
49+
idlAuthority: PublicKey
50+
): Promise<TransactionInstruction> {
51+
let idlAddress = await getIdlAddress(programId);
52+
return {
53+
programId,
54+
data: IDL_SET_BUFFER_DISCRIMINATOR,
55+
keys: [
56+
{ pubkey: buffer, isSigner: false, isWritable: true },
57+
{ pubkey: idlAddress, isSigner: false, isWritable: true },
58+
{
59+
pubkey: idlAuthority,
60+
isSigner: true,
61+
isWritable: true,
62+
},
63+
],
64+
};
65+
}

governance/xc_admin/packages/xc_admin_common/src/multisig_transaction/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export class MultisigParser {
167167
}
168168
}
169169

170+
export { idlSetBuffer } from "./anchor";
170171
export { WormholeMultisigInstruction } from "./WormholeMultisigInstruction";
171172
export { PythMultisigInstruction } from "./PythMultisigInstruction";
172173
export { AnchorMultisigInstruction } from "./MessageBufferMultisigInstruction";

pnpm-lock.yaml

Lines changed: 24 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)