Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): add action builders #134

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

joeymeere
Copy link
Contributor

Adds another export in the TS SDK called actions, containing builders for various common actions in the SDK. These are optimized for quick succession with as few lines of code as possible.

A developer using these would simply initialize the builder (createThing) with minimal arguments, only covering what's required by the underlying instruction, with the ability to add-on more if needed for additional customization. From there, they can call it synchronously to chain methods for things like returning relevant inferred data (i.e transaction index), adding more complimentary instructions (like creating & voting on proposals), as well as returning a transaction or sending one like the base SDK.

Actions include:

  • Creating a multisig
  • Creating a vault transaction, proposal, voting, and executing
  • Creating a config transaction, proposal, voting, and executing
  • Creating a buffer from a transaction, initializing account, slicing / uploading, and converting to a vault transaction
  • Creating a batch, proposal, adding transactions and executing

Examples:

async function ExampleOne() {
  const connection = new Connection("...");
  const feePayer = Keypair.generate();
  
  const signature = await createMultisig({
    connection,
    members: createMembers([
      { key: PublicKey.default, permissions: SquadPermissions.All },
    ]),
    creator: PublicKey.default,
    threshold: 1,
  }).sendAndConfirm(feePayer);

  console.log("Signature:", signature);
}
async function ExampleTwo() {
  const connection = new Connection("...");
  
  const multisig = createMultisig({
    connection,
    members: createMembers([
      { key: PublicKey.default, permissions: SquadPermissions.All },
    ]),
    creator: PublicKey.default,
    threshold: 1,
  });

  // Returns instructions
  const a = await multisig.getInstructions();
  // Returns PDA
  const b = multisig.getMultisigKey();
  // Returns deserialized account data
  const c = await multisig.getMultisigAccount(b!);

  console.log(c.members);
}

Copy link

vercel bot commented Oct 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
v4-sdk-typedoc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 20, 2024 1:13am

someone shouldn't be able to call `txBuilder.withProposal().withApproval().withProposal()`, Typescript should stop them
ex: `buildFromVaultTransaction` takes a key for a `VaultTransaction` account, deserializes it, and creates a builder instance from it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant