|
| 1 | +import { PublicKey } from "@solana/web3.js"; |
| 2 | +import { getAuthorityPDA, DEFAULT_MULTISIG_PROGRAM_ID } from "@sqds/sdk"; |
| 3 | +import BN from "bn.js"; |
| 4 | +import { |
| 5 | + parseArgs, |
| 6 | + createWallet, |
| 7 | + initEscrowProgram, |
| 8 | + parseMultisig, |
| 9 | + executeOrPropose, |
| 10 | +} from "./helpers"; |
| 11 | + |
| 12 | +const BPF_UPGRADABLE_LOADER = new PublicKey( |
| 13 | + "BPFLoaderUpgradeab1e11111111111111111111111" |
| 14 | +); |
| 15 | + |
| 16 | +async function main() { |
| 17 | + const args = parseArgs(); |
| 18 | + const wallet = await createWallet(args); |
| 19 | + const { connection, program, programId } = initEscrowProgram(args, wallet); |
| 20 | + const multisigAddress = parseMultisig(args); |
| 21 | + |
| 22 | + const programToTransfer = new PublicKey(args.program); |
| 23 | + const currentAuthority = new PublicKey(args.authority); |
| 24 | + |
| 25 | + const programData = PublicKey.findProgramAddressSync( |
| 26 | + [programToTransfer.toBuffer()], |
| 27 | + BPF_UPGRADABLE_LOADER |
| 28 | + )[0]; |
| 29 | + |
| 30 | + // In multisig mode, the vault becomes the new authority |
| 31 | + let newAuthority: PublicKey; |
| 32 | + if (multisigAddress) { |
| 33 | + [newAuthority] = getAuthorityPDA( |
| 34 | + multisigAddress, |
| 35 | + new BN(1), |
| 36 | + DEFAULT_MULTISIG_PROGRAM_ID |
| 37 | + ); |
| 38 | + } else { |
| 39 | + newAuthority = wallet.publicKey; |
| 40 | + } |
| 41 | + |
| 42 | + const escrowAuthority = PublicKey.findProgramAddressSync( |
| 43 | + [currentAuthority.toBuffer(), newAuthority.toBuffer()], |
| 44 | + programId |
| 45 | + )[0]; |
| 46 | + |
| 47 | + console.log("Accepting program authority transfer..."); |
| 48 | + console.log(` Wallet: ${wallet.publicKey.toBase58()}`); |
| 49 | + console.log(` Program: ${programToTransfer.toBase58()}`); |
| 50 | + console.log(` Current Authority: ${currentAuthority.toBase58()}`); |
| 51 | + console.log(` New Authority: ${newAuthority.toBase58()}`); |
| 52 | + console.log(` Escrow Authority: ${escrowAuthority.toBase58()}`); |
| 53 | + |
| 54 | + if (multisigAddress) { |
| 55 | + console.log(` Multisig: ${multisigAddress.toBase58()}`); |
| 56 | + } |
| 57 | + |
| 58 | + const instruction = await program.methods |
| 59 | + .accept() |
| 60 | + .accounts({ |
| 61 | + currentAuthority: currentAuthority, |
| 62 | + newAuthority: newAuthority, |
| 63 | + programAccount: programToTransfer, |
| 64 | + }) |
| 65 | + .accountsPartial({ |
| 66 | + escrowAuthority: escrowAuthority, |
| 67 | + programData: programData, |
| 68 | + }) |
| 69 | + .instruction(); |
| 70 | + |
| 71 | + await executeOrPropose(connection, wallet, multisigAddress, instruction); |
| 72 | +} |
| 73 | + |
| 74 | +main().catch((err) => { |
| 75 | + console.error(err); |
| 76 | + process.exit(1); |
| 77 | +}); |
0 commit comments