Skip to content

Commit

Permalink
feat(sdk): use classic TokenProgram for SpendingLimits by default
Browse files Browse the repository at this point in the history
  • Loading branch information
vovacodes committed Jul 3, 2023
1 parent c2e81e1 commit dd0f478
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
12 changes: 6 additions & 6 deletions sdk/multisig/src/instructions/spendingLimitUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "@solana/web3.js";
import {
getAssociatedTokenAddressSync,
TOKEN_2022_PROGRAM_ID,
TOKEN_PROGRAM_ID,
ASSOCIATED_TOKEN_PROGRAM_ID,
} from "@solana/spl-token";
import { createSpendingLimitUseInstruction } from "../generated";
Expand All @@ -20,6 +20,7 @@ export function spendingLimitUse({
amount,
decimals,
destination,
tokenProgram = TOKEN_PROGRAM_ID,
memo,
}: {
multisigPda: PublicKey;
Expand All @@ -31,6 +32,7 @@ export function spendingLimitUse({
amount: number;
decimals: number;
destination: PublicKey;
tokenProgram?: PublicKey;
memo?: string;
}): TransactionInstruction {
const [vaultPda] = getVaultPda({ multisigPda, index: vaultIndex });
Expand All @@ -41,7 +43,7 @@ export function spendingLimitUse({
mint,
vaultPda,
true,
TOKEN_2022_PROGRAM_ID,
tokenProgram,
ASSOCIATED_TOKEN_PROGRAM_ID
);

Expand All @@ -51,12 +53,10 @@ export function spendingLimitUse({
mint,
destination,
true,
TOKEN_2022_PROGRAM_ID,
tokenProgram,
ASSOCIATED_TOKEN_PROGRAM_ID
);

const tokenProgram = mint ? TOKEN_2022_PROGRAM_ID : undefined;

return createSpendingLimitUseInstruction(
{
multisig: multisigPda,
Expand All @@ -68,7 +68,7 @@ export function spendingLimitUse({
mint,
vaultTokenAccount,
destinationTokenAccount,
tokenProgram,
tokenProgram: mint ? tokenProgram : undefined,
},
{ args: { amount, decimals, memo: memo ?? null } }
);
Expand Down
3 changes: 3 additions & 0 deletions sdk/multisig/src/rpc/spendingLimitUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function spendingLimitUse({
amount,
decimals,
destination,
tokenProgram,
memo,
sendOptions,
}: {
Expand All @@ -33,6 +34,7 @@ export async function spendingLimitUse({
amount: number;
decimals: number;
destination: PublicKey;
tokenProgram?: PublicKey;
memo?: string;
sendOptions?: SendOptions;
}): Promise<TransactionSignature> {
Expand All @@ -49,6 +51,7 @@ export async function spendingLimitUse({
amount,
decimals,
destination,
tokenProgram,
memo,
});

Expand Down
3 changes: 3 additions & 0 deletions sdk/multisig/src/transactions/spendingLimitUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function spendingLimitUse({
amount,
decimals,
destination,
tokenProgram,
memo,
}: {
blockhash: string;
Expand All @@ -33,6 +34,7 @@ export function spendingLimitUse({
amount: number;
decimals: number;
destination: PublicKey;
tokenProgram?: PublicKey;
memo?: string;
}): VersionedTransaction {
const message = new TransactionMessage({
Expand All @@ -48,6 +50,7 @@ export function spendingLimitUse({
amount,
decimals,
destination,
tokenProgram,
memo,
}),
],
Expand Down
14 changes: 8 additions & 6 deletions tests/suites/examples/spending-limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
createMint,
getAssociatedTokenAddressSync,
mintTo,
TOKEN_2022_PROGRAM_ID,
TOKEN_PROGRAM_ID,
createAssociatedTokenAccountInstruction,
createAssociatedTokenAccount,
} from "@solana/spl-token";
Expand Down Expand Up @@ -85,7 +85,7 @@ describe("Examples / Spending Limits", () => {
mintDecimals,
undefined,
undefined,
TOKEN_2022_PROGRAM_ID
TOKEN_PROGRAM_ID
);

splSpendingLimitParams = {
Expand All @@ -106,7 +106,7 @@ describe("Examples / Spending Limits", () => {
splMint,
vaultPda,
true,
TOKEN_2022_PROGRAM_ID,
TOKEN_PROGRAM_ID,
ASSOCIATED_TOKEN_PROGRAM_ID
);
const message = new TransactionMessage({
Expand All @@ -118,7 +118,7 @@ describe("Examples / Spending Limits", () => {
vaultTokenAccount,
vaultPda,
splMint,
TOKEN_2022_PROGRAM_ID,
TOKEN_PROGRAM_ID,
ASSOCIATED_TOKEN_PROGRAM_ID
),
],
Expand All @@ -137,7 +137,7 @@ describe("Examples / Spending Limits", () => {
100 * 10 ** mintDecimals,
undefined,
undefined,
TOKEN_2022_PROGRAM_ID
TOKEN_PROGRAM_ID
);
});

Expand Down Expand Up @@ -341,7 +341,7 @@ describe("Examples / Spending Limits", () => {
splMint,
destination,
undefined,
TOKEN_2022_PROGRAM_ID,
TOKEN_PROGRAM_ID,
ASSOCIATED_TOKEN_PROGRAM_ID
);

Expand All @@ -366,6 +366,7 @@ describe("Examples / Spending Limits", () => {
decimals: 6,
// Transfer tokens to one of the allowed destinations.
destination,
tokenProgram: TOKEN_PROGRAM_ID,
// You can optionally add a memo.
memo: "Using my allowance!",
})
Expand Down Expand Up @@ -398,6 +399,7 @@ describe("Examples / Spending Limits", () => {
amount: 1,
decimals: 6,
destination,
tokenProgram: TOKEN_PROGRAM_ID,
}),
/Spending limit exceeded/
);
Expand Down

0 comments on commit dd0f478

Please sign in to comment.