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

Open
wants to merge 10 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 Dec 4, 2024 9:31pm

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
@joeysqds joeysqds marked this pull request as ready for review October 22, 2024 17:44
@joeysqds joeysqds requested review from ogmedia and 0xRigel October 22, 2024 17:44
@0xRigel
Copy link
Contributor

0xRigel commented Oct 30, 2024

Looks great 🙌 Love the detailed docs above the individual functions, we should adopt this across the rest of the SDK as well 🔥

Copy link

@palmaswell-squads palmaswell-squads left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK - nice work 👌

protected args: Omit<U, keyof BaseBuilderArgs>;
private built: boolean = false;
// Use this as an indicator to clear all instructions?
private sent: boolean = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have already considered this, but if you want methods and properties to be "truly" private, meaning they can't be accessed with trickery, I recommend using the native JS private properties #send: boolean = false.

In case you're curious: MDN: Private Properties

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.

3 participants