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(associated token pda search): add tokenProgramId param #12

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist
.amman
.crates
.bin
.idea
1 change: 1 addition & 0 deletions clients/js/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vercel
docs
.idea
2 changes: 1 addition & 1 deletion clients/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metaplex-foundation/mpl-toolbox",
"version": "0.9.2",
"version": "0.9.3",
blockiosaurus marked this conversation as resolved.
Show resolved Hide resolved
"description": "Auto-generated essential Solana and Metaplex programs",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
15 changes: 8 additions & 7 deletions clients/js/src/generated/instructions/createAssociatedToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ export function createAssociatedToken(
if (!resolvedAccounts.owner.value) {
resolvedAccounts.owner.value = context.identity.publicKey;
}
if (!resolvedAccounts.tokenProgram.value) {
resolvedAccounts.tokenProgram.value = context.programs.getPublicKey(
'splToken',
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
resolvedAccounts.tokenProgram.isWritable = false;
}
if (!resolvedAccounts.ata.value) {
resolvedAccounts.ata.value = findAssociatedTokenPda(context, {
owner: expectPublicKey(resolvedAccounts.owner.value),
mint: expectPublicKey(resolvedAccounts.mint.value),
tokenProgramId: expectPublicKey(resolvedAccounts.tokenProgram.value),
});
}
if (!resolvedAccounts.systemProgram.value) {
Expand All @@ -83,13 +91,6 @@ export function createAssociatedToken(
);
resolvedAccounts.systemProgram.isWritable = false;
}
if (!resolvedAccounts.tokenProgram.value) {
resolvedAccounts.tokenProgram.value = context.programs.getPublicKey(
'splToken',
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
resolvedAccounts.tokenProgram.isWritable = false;
}

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
Expand Down
15 changes: 8 additions & 7 deletions clients/js/src/generated/instructions/createTokenIfMissing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,18 @@ export function createTokenIfMissing(
if (!resolvedAccounts.owner.value) {
resolvedAccounts.owner.value = context.identity.publicKey;
}
if (!resolvedAccounts.tokenProgram.value) {
resolvedAccounts.tokenProgram.value = context.programs.getPublicKey(
'splToken',
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
resolvedAccounts.tokenProgram.isWritable = false;
}
if (!resolvedAccounts.ata.value) {
resolvedAccounts.ata.value = findAssociatedTokenPda(context, {
owner: expectPublicKey(resolvedAccounts.owner.value),
mint: expectPublicKey(resolvedAccounts.mint.value),
tokenProgramId: expectPublicKey(resolvedAccounts.tokenProgram.value),
});
}
if (!resolvedAccounts.token.value) {
Expand All @@ -131,13 +139,6 @@ export function createTokenIfMissing(
);
resolvedAccounts.systemProgram.isWritable = false;
}
if (!resolvedAccounts.tokenProgram.value) {
resolvedAccounts.tokenProgram.value = context.programs.getPublicKey(
'splToken',
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
resolvedAccounts.tokenProgram.isWritable = false;
}
if (!resolvedAccounts.ataProgram.value) {
resolvedAccounts.ataProgram.value = context.programs.getPublicKey(
'splAssociatedToken',
Expand Down
7 changes: 5 additions & 2 deletions clients/js/src/hooked/AssociatedToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ export function findAssociatedTokenPda(
mint: PublicKey;
/** The owner of the token account */
owner: PublicKey;
/** The Token or Token2022 Program id */
blockiosaurus marked this conversation as resolved.
Show resolved Hide resolved
tokenProgramId?: PublicKey;
}
): Pda {
const associatedTokenProgramId =
context.programs.getPublicKey('splAssociatedToken');
const tokenProgramId = context.programs.getPublicKey('splToken');
const tokenProgramIdResolved =
seeds.tokenProgramId ?? context.programs.getPublicKey('splToken');
return context.eddsa.findPda(associatedTokenProgramId, [
publicKey().serialize(seeds.owner),
publicKey().serialize(tokenProgramId),
publicKey().serialize(tokenProgramIdResolved),
publicKey().serialize(seeds.mint),
]);
}
6 changes: 5 additions & 1 deletion configs/kinobi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ kinobi.update(
// Update instructions.
const ataPdaDefaults = k.pdaDefault("AssociatedToken", {
importFrom: "hooked",
seeds: { owner: k.accountDefault("owner"), mint: k.accountDefault("mint") },
seeds: {
owner: k.accountDefault("owner"),
mint: k.accountDefault("mint"),
tokenProgramId: k.accountDefault("tokenProgram")
},
});
kinobi.update(
new k.UpdateInstructionsVisitor({
Expand Down
1 change: 1 addition & 0 deletions pnpm-lock.yaml

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

Loading