Skip to content

Commit

Permalink
feat(programs): Add support to get program out from Squad
Browse files Browse the repository at this point in the history
  • Loading branch information
bguillaumat committed Nov 20, 2023
1 parent 474b624 commit a872a5d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sqds/cli",
"version": "2.3.14",
"version": "2.3.15",
"description": "",
"main": "bin/index.js",
"scripts": {
Expand Down
43 changes: 39 additions & 4 deletions src/lib/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ class Menu{

program = async (ms: any) => {
this.header();
const [vault] = await getAuthorityPDA(ms.publicKey, new BN(1), this.api.programId);
const {programId} = await promptProgramId();
if (programId.length < 1) {
this.multisig(ms);
Expand All @@ -645,12 +646,15 @@ class Menu{
const programAuthority = await this.api.getProgramDataAuthority(new anchor.web3.PublicKey(programId));
chalk.blue("Current program data authority: " + programAuthority);
status.stop();
if (programAuthority !== this.wallet.publicKey.toBase58()) {
await inquirer.prompt({default: false, name: 'action', type: 'input', message: `Connected wallet does not have authority over this program - Enter to continue`});
this.program(ms);
}else{
if (programAuthority === this.wallet.publicKey.toBase58()) {
this.programAuthority(ms, programAuthority, programId);
}
if (programAuthority === vault.toBase58()) {
this.programAuthorityOut(ms, programAuthority, programId);
}else{
await inquirer.prompt({default: false, name: 'action', type: 'input', message: `Neither the connected wallet nor this Squad have authority over this program - Enter to continue`});
this.program(ms);
}
}catch(e){
console.log(e);
status.stop();
Expand Down Expand Up @@ -692,6 +696,37 @@ class Menu{
}
}

programAuthorityOut = async (ms: any, currentAuthority: PublicKey, programId: string) => {
const [vault] = await getAuthorityPDA(ms.publicKey, new BN(1), this.api.programId);
this.header(vault);
console.log(`This will create a safe upgrade authority transfer transaction of ${programId} out of the Squad vault`);
console.log("Program Address: " + chalk.blue(`${programId}`));
console.log(`Multisig Address: ` + chalk.white(`${ms.publicKey.toBase58()}`));
console.log(`Current Program Authority: ` + chalk.white(`${currentAuthority}`));
console.log(`New Program Upgrade Authority: ` + chalk.green(this.wallet.publicKey.toBase58()) + chalk.white(` (Your connected wallet)`));
const {action} = await inquirer.prompt({default: false, name: 'action', type: 'confirm', message: `Continue?`});
if (action) {
const status = new Spinner('Creating transaction...');
status.start();
try {
const tx = await this.api.createSafeAuthorityTx(ms.publicKey, new PublicKey(programId), new PublicKey(currentAuthority), this.wallet.publicKey);
status.stop();
console.log(chalk.green("Transaction created!"));
console.log(chalk.blue("Transaction ID: ") + chalk.white(tx));
await continueInq();
this.multisig(ms);
}catch(e){
console.log(e);
status.stop();
console.log(`Transaction creation failed - Enter to continue`);
await continueInq();
this.program(ms);
}
}else{
this.program(ms);
}
}

create = async () => {
this.header();
let initKey = anchor.web3.Keypair.generate().publicKey.toBase58();
Expand Down

0 comments on commit a872a5d

Please sign in to comment.