Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-worms-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kinobi-so/renderers-js': patch
---

Add an optional programAddress override to instruction builders
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export async function getCreateGuardInstructionAsync<
TAccountAssociatedTokenProgram extends string,
TAccountTokenProgram extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
>(
input: CreateGuardAsyncInput<
TAccountGuard,
Expand All @@ -234,10 +235,11 @@ export async function getCreateGuardInstructionAsync<
TAccountAssociatedTokenProgram,
TAccountTokenProgram,
TAccountSystemProgram
>
>,
config?: { programAddress?: TProgramAddress }
): Promise<
CreateGuardInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountGuard,
TAccountMint,
TAccountMintTokenAccount,
Expand All @@ -249,7 +251,8 @@ export async function getCreateGuardInstructionAsync<
>
> {
// Program address.
const programAddress = WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;
const programAddress =
config?.programAddress ?? WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
Expand Down Expand Up @@ -336,7 +339,7 @@ export async function getCreateGuardInstructionAsync<
args as CreateGuardInstructionDataArgs
),
} as CreateGuardInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountGuard,
TAccountMint,
TAccountMintTokenAccount,
Expand Down Expand Up @@ -385,6 +388,7 @@ export function getCreateGuardInstruction<
TAccountAssociatedTokenProgram extends string,
TAccountTokenProgram extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
>(
input: CreateGuardInput<
TAccountGuard,
Expand All @@ -395,9 +399,10 @@ export function getCreateGuardInstruction<
TAccountAssociatedTokenProgram,
TAccountTokenProgram,
TAccountSystemProgram
>
>,
config?: { programAddress?: TProgramAddress }
): CreateGuardInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountGuard,
TAccountMint,
TAccountMintTokenAccount,
Expand All @@ -408,7 +413,8 @@ export function getCreateGuardInstruction<
TAccountSystemProgram
> {
// Program address.
const programAddress = WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;
const programAddress =
config?.programAddress ?? WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
Expand Down Expand Up @@ -466,7 +472,7 @@ export function getCreateGuardInstruction<
args as CreateGuardInstructionDataArgs
),
} as CreateGuardInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountGuard,
TAccountMint,
TAccountMintTokenAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export async function getExecuteInstructionAsync<
TAccountExtraMetasAccount extends string,
TAccountGuard extends string,
TAccountInstructionSysvarAccount extends string,
TProgramAddress extends Address = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
>(
input: ExecuteAsyncInput<
TAccountSourceAccount,
Expand All @@ -156,10 +157,11 @@ export async function getExecuteInstructionAsync<
TAccountExtraMetasAccount,
TAccountGuard,
TAccountInstructionSysvarAccount
>
>,
config?: { programAddress?: TProgramAddress }
): Promise<
ExecuteInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountSourceAccount,
TAccountMint,
TAccountDestinationAccount,
Expand All @@ -170,7 +172,8 @@ export async function getExecuteInstructionAsync<
>
> {
// Program address.
const programAddress = WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;
const programAddress =
config?.programAddress ?? WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
Expand Down Expand Up @@ -235,7 +238,7 @@ export async function getExecuteInstructionAsync<
args as ExecuteInstructionDataArgs
),
} as ExecuteInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountSourceAccount,
TAccountMint,
TAccountDestinationAccount,
Expand Down Expand Up @@ -275,6 +278,7 @@ export function getExecuteInstruction<
TAccountExtraMetasAccount extends string,
TAccountGuard extends string,
TAccountInstructionSysvarAccount extends string,
TProgramAddress extends Address = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
>(
input: ExecuteInput<
TAccountSourceAccount,
Expand All @@ -284,9 +288,10 @@ export function getExecuteInstruction<
TAccountExtraMetasAccount,
TAccountGuard,
TAccountInstructionSysvarAccount
>
>,
config?: { programAddress?: TProgramAddress }
): ExecuteInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountSourceAccount,
TAccountMint,
TAccountDestinationAccount,
Expand All @@ -296,7 +301,8 @@ export function getExecuteInstruction<
TAccountInstructionSysvarAccount
> {
// Program address.
const programAddress = WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;
const programAddress =
config?.programAddress ?? WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
Expand Down Expand Up @@ -347,7 +353,7 @@ export function getExecuteInstruction<
args as ExecuteInstructionDataArgs
),
} as ExecuteInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountSourceAccount,
TAccountMint,
TAccountDestinationAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export async function getInitializeInstructionAsync<
TAccountTransferHookAuthority extends string,
TAccountSystemProgram extends string,
TAccountPayer extends string,
TProgramAddress extends Address = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
>(
input: InitializeAsyncInput<
TAccountExtraMetasAccount,
Expand All @@ -144,10 +145,11 @@ export async function getInitializeInstructionAsync<
TAccountTransferHookAuthority,
TAccountSystemProgram,
TAccountPayer
>
>,
config?: { programAddress?: TProgramAddress }
): Promise<
InitializeInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountExtraMetasAccount,
TAccountGuard,
TAccountMint,
Expand All @@ -157,7 +159,8 @@ export async function getInitializeInstructionAsync<
>
> {
// Program address.
const programAddress = WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;
const programAddress =
config?.programAddress ?? WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
Expand Down Expand Up @@ -212,7 +215,7 @@ export async function getInitializeInstructionAsync<
programAddress,
data: getInitializeInstructionDataEncoder().encode({}),
} as InitializeInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountExtraMetasAccount,
TAccountGuard,
TAccountMint,
Expand Down Expand Up @@ -247,6 +250,7 @@ export function getInitializeInstruction<
TAccountTransferHookAuthority extends string,
TAccountSystemProgram extends string,
TAccountPayer extends string,
TProgramAddress extends Address = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
>(
input: InitializeInput<
TAccountExtraMetasAccount,
Expand All @@ -255,9 +259,10 @@ export function getInitializeInstruction<
TAccountTransferHookAuthority,
TAccountSystemProgram,
TAccountPayer
>
>,
config?: { programAddress?: TProgramAddress }
): InitializeInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountExtraMetasAccount,
TAccountGuard,
TAccountMint,
Expand All @@ -266,7 +271,8 @@ export function getInitializeInstruction<
TAccountPayer
> {
// Program address.
const programAddress = WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;
const programAddress =
config?.programAddress ?? WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
Expand Down Expand Up @@ -307,7 +313,7 @@ export function getInitializeInstruction<
programAddress,
data: getInitializeInstructionDataEncoder().encode({}),
} as InitializeInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountExtraMetasAccount,
TAccountGuard,
TAccountMint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export async function getUpdateGuardInstructionAsync<
TAccountGuardAuthority extends string,
TAccountTokenProgram extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
>(
input: UpdateGuardAsyncInput<
TAccountGuard,
Expand All @@ -193,10 +194,11 @@ export async function getUpdateGuardInstructionAsync<
TAccountGuardAuthority,
TAccountTokenProgram,
TAccountSystemProgram
>
>,
config?: { programAddress?: TProgramAddress }
): Promise<
UpdateGuardInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountGuard,
TAccountMint,
TAccountTokenAccount,
Expand All @@ -206,7 +208,8 @@ export async function getUpdateGuardInstructionAsync<
>
> {
// Program address.
const programAddress = WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;
const programAddress =
config?.programAddress ?? WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
Expand Down Expand Up @@ -279,7 +282,7 @@ export async function getUpdateGuardInstructionAsync<
args as UpdateGuardInstructionDataArgs
),
} as UpdateGuardInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountGuard,
TAccountMint,
TAccountTokenAccount,
Expand Down Expand Up @@ -317,6 +320,7 @@ export function getUpdateGuardInstruction<
TAccountGuardAuthority extends string,
TAccountTokenProgram extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
>(
input: UpdateGuardInput<
TAccountGuard,
Expand All @@ -325,9 +329,10 @@ export function getUpdateGuardInstruction<
TAccountGuardAuthority,
TAccountTokenProgram,
TAccountSystemProgram
>
>,
config?: { programAddress?: TProgramAddress }
): UpdateGuardInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountGuard,
TAccountMint,
TAccountTokenAccount,
Expand All @@ -336,7 +341,8 @@ export function getUpdateGuardInstruction<
TAccountSystemProgram
> {
// Program address.
const programAddress = WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;
const programAddress =
config?.programAddress ?? WEN_TRANSFER_GUARD_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
Expand Down Expand Up @@ -380,7 +386,7 @@ export function getUpdateGuardInstruction<
args as UpdateGuardInstructionDataArgs
),
} as UpdateGuardInstruction<
typeof WEN_TRANSFER_GUARD_PROGRAM_ADDRESS,
TProgramAddress,
TAccountGuard,
TAccountMint,
TAccountTokenAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ export type AddMemoInput = {
signers?: Array<TransactionSigner>;
};

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

// Original args.
const args = { ...input };
Expand All @@ -83,7 +86,7 @@ export function getAddMemoInstruction(
data: getAddMemoInstructionDataEncoder().encode(
args as AddMemoInstructionDataArgs
),
} as AddMemoInstruction<typeof MEMO_PROGRAM_ADDRESS>;
} as AddMemoInstruction<TProgramAddress>;

return instruction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,22 @@ export function getAdvanceNonceAccountInstruction<
TAccountNonceAccount extends string,
TAccountRecentBlockhashesSysvar extends string,
TAccountNonceAuthority extends string,
TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
>(
input: AdvanceNonceAccountInput<
TAccountNonceAccount,
TAccountRecentBlockhashesSysvar,
TAccountNonceAuthority
>
>,
config?: { programAddress?: TProgramAddress }
): AdvanceNonceAccountInstruction<
typeof SYSTEM_PROGRAM_ADDRESS,
TProgramAddress,
TAccountNonceAccount,
TAccountRecentBlockhashesSysvar,
TAccountNonceAuthority
> {
// Program address.
const programAddress = SYSTEM_PROGRAM_ADDRESS;
const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
Expand Down Expand Up @@ -149,7 +151,7 @@ export function getAdvanceNonceAccountInstruction<
programAddress,
data: getAdvanceNonceAccountInstructionDataEncoder().encode({}),
} as AdvanceNonceAccountInstruction<
typeof SYSTEM_PROGRAM_ADDRESS,
TProgramAddress,
TAccountNonceAccount,
TAccountRecentBlockhashesSysvar,
TAccountNonceAuthority
Expand Down
Loading