Last active
December 17, 2023 16:30
-
-
Save staccDOTsol/52e7cc5051f0df6790c03ef4d19198dc to your computer and use it in GitHub Desktop.
multisig expand program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as multisig from "@sqds/multisig"; | |
import { | |
AddressLookupTableAccount, | |
AddressLookupTableProgram, | |
LAMPORTS_PER_SOL, | |
PublicKey, | |
SystemProgram, | |
TransactionInstruction, | |
TransactionMessage, | |
VersionedTransaction, | |
} from "@solana/web3.js"; | |
import assert from "assert"; | |
import { | |
createAutonomousMultisig, | |
createLocalhostConnection, | |
createTestTransferInstruction, | |
generateFundedKeypair, | |
generateMultisigMembers, | |
getTestProgramId, | |
range, | |
TestMembers, | |
} from "../../utils"; | |
import { getMultisigPda } from "../../../sdk/multisig/src"; | |
import BN from "bn.js"; | |
const { Multisig, Proposal } = multisig.accounts; | |
const programId = getTestProgramId(); | |
describe("Examples / Batch SOL Transfer", () => { | |
const connection = createLocalhostConnection(); | |
let members: TestMembers; | |
before(async () => { | |
members = await generateMultisigMembers(connection); | |
}); | |
it("create and execute batch transaction containing multiple SOL transfers", async () => { | |
let multisigPubkey: PublicKey; | |
const [multisigPda] = await getMultisigPda(programId, multisigPubkey); | |
let multisigAccount = await Multisig.fromAccountAddress( | |
connection, | |
multisigPda | |
); | |
const vaultIndex = 0; | |
const batchIndex = | |
multisig.utils.toBigInt(multisigAccount.transactionIndex) + 1n; | |
const { | |
value: { blockhash }, | |
context: { slot }, | |
} = await connection.getLatestBlockhashAndContext("finalized"); | |
const testTransactionMessages = [] as { | |
message: TransactionMessage; | |
addressLookupTableAccounts: AddressLookupTableAccount[]; | |
}[]; | |
const programDataAccount: PublicKey; | |
const programAccount: PublicKey; | |
const additionalBytes: BN = new BN(50 * 1024); | |
let buffer = Buffer.alloc(0); | |
buffer = Buffer.concat([buffer, Buffer.from([143, 117, 164, 255, 235, 226, 17, 239])]); | |
buffer = Buffer.concat([buffer, additionalBytes.toBuffer("le")]); | |
const ix: TransactionInstruction = { | |
keys: [ | |
{ pubkey: programDataAccount, isSigner: false, isWritable: true }, | |
{ pubkey: programAccount, isSigner: false, isWritable: true }, | |
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, | |
], | |
programId: programId, | |
data: buffer | |
}; | |
testTransactionMessages.push({ | |
message: new TransactionMessage({ | |
payerKey: vaultPda, | |
recentBlockhash: blockhash, | |
instructions: [ix], | |
}), | |
addressLookupTableAccounts: [], | |
}); | |
// Create a batch account. | |
let signature = await multisig.rpc.batchCreate({ | |
connection, | |
feePayer: members.proposer, | |
multisigPda, | |
creator: members.proposer, | |
batchIndex, | |
vaultIndex, | |
memo: "Expand program data account", | |
programId, | |
}); | |
await connection.confirmTransaction(signature); | |
// Initialize the proposal for the batch. | |
signature = await multisig.rpc.proposalCreate({ | |
connection, | |
feePayer: members.proposer, | |
multisigPda, | |
transactionIndex: batchIndex, | |
creator: members.proposer, | |
isDraft: true, | |
programId, | |
}); | |
await connection.confirmTransaction(signature); | |
// Add transactions to the batch. | |
for (const [ | |
index, | |
{ message, addressLookupTableAccounts }, | |
] of testTransactionMessages.entries()) { | |
signature = await multisig.rpc.batchAddTransaction({ | |
connection, | |
feePayer: members.proposer, | |
multisigPda, | |
member: members.proposer, | |
vaultIndex: 0, | |
batchIndex, | |
// Batch transaction indices start at 1. | |
transactionIndex: index + 1, | |
ephemeralSigners: 0, | |
transactionMessage: message, | |
addressLookupTableAccounts, | |
programId, | |
}); | |
await connection.confirmTransaction(signature); | |
} | |
// Activate the proposal (finalize the batch). | |
signature = await multisig.rpc.proposalActivate({ | |
connection, | |
feePayer: members.proposer, | |
multisigPda, | |
member: members.proposer, | |
transactionIndex: batchIndex, | |
programId, | |
}); | |
await connection.confirmTransaction(signature); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment