Skip to content

Commit

Permalink
vendor in spl memo (#49)
Browse files Browse the repository at this point in the history
* refactor: relocate shared

* refactor: vendor in memo

* chore: changeset
  • Loading branch information
nickfrosty authored Feb 23, 2025
1 parent e18fc1b commit 64d138a
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-mayflies-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gill": patch
---

vendor in spl memo
8 changes: 8 additions & 0 deletions examples/get-started/src/basic-compare.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* The purpose of this script is to compare some of the differences
* of using `gill` as a single entrypoint vs `@solana/web3.js`
* (and the various `@solana-program/*` packages).
*
* This script is the `@solana/web3.js` version of the comparison.
* See the `gill` version in the ./basic.ts file
*/
import { readFileSync } from "node:fs";
import { homedir } from "node:os";
import { resolve } from "node:path";
Expand Down
8 changes: 8 additions & 0 deletions examples/get-started/src/basic.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* The purpose of this script is to compare some of the differences
* of using `gill` as a single entrypoint vs `@solana/web3.js`
* (and the various `@solana-program/*` packages).
*
* This script is the `gill` version of the comparison.
* See the `@solana/web3.js` version in the ./basic-compare.ts file
*/
import {
getExplorerLink,
createTransaction,
Expand Down
1 change: 0 additions & 1 deletion packages/gill/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"dependencies": {
"@solana-program/address-lookup-table": "^0.6.1",
"@solana-program/compute-budget": "^0.6.1",
"@solana-program/memo": "^0.6.1",
"@solana-program/system": "^0.6.2",
"@solana-program/token-2022": "^0.3.4",
"@solana/accounts": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/gill/src/programs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

export * from "@solana-program/system";
export * from "@solana-program/memo";

export * from "@solana-program/address-lookup-table";
export * from "@solana-program/compute-budget";
Expand All @@ -13,4 +12,5 @@ export * from "./compute-budget";
* Codama generated clients, stored internally in this package
* (and associated helpers for them)
*/
export * from "./memo"; // vendored in from @solana-program/memo
export * from "./token-metadata";
10 changes: 10 additions & 0 deletions packages/gill/src/programs/memo/generated/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This code was AUTOGENERATED using the codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun codama to update it.
*
* @see https://github.com/codama-idl/codama
*/

export * from './instructions';
export * from './programs';
101 changes: 101 additions & 0 deletions packages/gill/src/programs/memo/generated/instructions/addMemo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* This code was AUTOGENERATED using the codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun codama to update it.
*
* @see https://github.com/codama-idl/codama
*/

import {
combineCodec,
getStructDecoder,
getStructEncoder,
getUtf8Decoder,
getUtf8Encoder,
type Codec,
type Decoder,
type Encoder,
} from "@solana/codecs";
import { type Address } from "@solana/addresses";
import {
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type IAccountMeta,
AccountRole,
} from "@solana/instructions";
import { type TransactionSigner } from "@solana/signers";
import { MEMO_PROGRAM_ADDRESS } from "../programs";

export type AddMemoInstruction<
TProgram extends string = typeof MEMO_PROGRAM_ADDRESS,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<TRemainingAccounts>;

export type AddMemoInstructionData = { memo: string };

export type AddMemoInstructionDataArgs = AddMemoInstructionData;

export function getAddMemoInstructionDataEncoder(): Encoder<AddMemoInstructionDataArgs> {
return getStructEncoder([["memo", getUtf8Encoder()]]);
}

export function getAddMemoInstructionDataDecoder(): Decoder<AddMemoInstructionData> {
return getStructDecoder([["memo", getUtf8Decoder()]]);
}

export function getAddMemoInstructionDataCodec(): Codec<
AddMemoInstructionDataArgs,
AddMemoInstructionData
> {
return combineCodec(getAddMemoInstructionDataEncoder(), getAddMemoInstructionDataDecoder());
}

export type AddMemoInput = {
memo: AddMemoInstructionDataArgs["memo"];
signers?: Array<TransactionSigner>;
};

export function getAddMemoInstruction<
TProgramAddress extends Address = typeof MEMO_PROGRAM_ADDRESS,
>(
input: AddMemoInput,
config?: { programAddress?: TProgramAddress },
): AddMemoInstruction<TProgramAddress> {
// Program address.
const programAddress = config?.programAddress ?? MEMO_PROGRAM_ADDRESS;

// Original args.
const args = { ...input };

// Remaining accounts.
const remainingAccounts: IAccountMeta[] = (args.signers ?? []).map((signer) => ({
address: signer.address,
role: AccountRole.READONLY_SIGNER,
signer,
}));

const instruction = {
accounts: remainingAccounts,
programAddress,
data: getAddMemoInstructionDataEncoder().encode(args as AddMemoInstructionDataArgs),
} as AddMemoInstruction<TProgramAddress>;

return instruction;
}

export type ParsedAddMemoInstruction<TProgram extends string = typeof MEMO_PROGRAM_ADDRESS> = {
programAddress: Address<TProgram>;
data: AddMemoInstructionData;
};

export function parseAddMemoInstruction<TProgram extends string>(
instruction: IInstruction<TProgram> & IInstructionWithData<Uint8Array>,
): ParsedAddMemoInstruction<TProgram> {
return {
programAddress: instruction.programAddress,
data: getAddMemoInstructionDataDecoder().decode(instruction.data),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* This code was AUTOGENERATED using the codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun codama to update it.
*
* @see https://github.com/codama-idl/codama
*/

export * from './addMemo';
9 changes: 9 additions & 0 deletions packages/gill/src/programs/memo/generated/programs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* This code was AUTOGENERATED using the codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun codama to update it.
*
* @see https://github.com/codama-idl/codama
*/

export * from './memo';
23 changes: 23 additions & 0 deletions packages/gill/src/programs/memo/generated/programs/memo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* This code was AUTOGENERATED using the codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun codama to update it.
*
* @see https://github.com/codama-idl/codama
*/

import { type Address } from "@solana/addresses";
import { type ParsedAddMemoInstruction } from "../instructions";

export const MEMO_PROGRAM_ADDRESS =
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" as Address<"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr">;

export enum MemoInstruction {
AddMemo,
}

export type ParsedMemoInstruction<
TProgram extends string = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",
> = {
instructionType: MemoInstruction.AddMemo;
} & ParsedAddMemoInstruction<TProgram>;
1 change: 1 addition & 0 deletions packages/gill/src/programs/memo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./generated";
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This code was AUTOGENERATED using the codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun codama to update it.
* And vendored in from various codama generated client to help
* minimize redundancy and bundle sizes
*
* @see https://github.com/codama-idl/codama
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import type {
} from "@solana/instructions";
import { type IAccountSignerMeta, type TransactionSigner } from "@solana/signers";

import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
import { getAccountMetaFactory, type ResolvedAccount } from "../../../shared";
import {
getCollectionDetailsDecoder,
getCollectionDetailsEncoder,
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 64d138a

Please sign in to comment.