Skip to content

Commit

Permalink
Adding v2 tests, minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Nov 18, 2024
1 parent 90d5eae commit c3b8144
Show file tree
Hide file tree
Showing 29 changed files with 1,330 additions and 158 deletions.
33 changes: 33 additions & 0 deletions clients/js/src/generated/accounts/escrowV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,36 @@ export function getEscrowV1GpaBuilder(
.deserializeUsing<EscrowV1>((account) => deserializeEscrowV1(account))
.whereField('discriminator', [26, 90, 193, 218, 188, 251, 139, 211]);
}

export function findEscrowV1Pda(
context: Pick<Context, 'eddsa' | 'programs'>,
seeds: {
/** The address of the collection */
collection: PublicKey;
}
): Pda {
const programId = context.programs.getPublicKey(
'mplHybrid',
'MPL4o4wMzndgh8T1NVDxELQCj5UQfYTYEkabX3wNKtb'
);
return context.eddsa.findPda(programId, [
string({ size: 'variable' }).serialize('escrow'),
publicKeySerializer().serialize(seeds.collection),
]);
}

export async function fetchEscrowV1FromSeeds(
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>,
seeds: Parameters<typeof findEscrowV1Pda>[1],
options?: RpcGetAccountOptions
): Promise<EscrowV1> {
return fetchEscrowV1(context, findEscrowV1Pda(context, seeds), options);
}

export async function safeFetchEscrowV1FromSeeds(
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>,
seeds: Parameters<typeof findEscrowV1Pda>[1],
options?: RpcGetAccountOptions
): Promise<EscrowV1 | null> {
return safeFetchEscrowV1(context, findEscrowV1Pda(context, seeds), options);
}
34 changes: 34 additions & 0 deletions clients/js/src/generated/accounts/escrowV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
array,
mapSerializer,
publicKey as publicKeySerializer,
string,
struct,
u8,
} from '@metaplex-foundation/umi/serializers';
Expand Down Expand Up @@ -140,3 +141,36 @@ export function getEscrowV2GpaBuilder(
export function getEscrowV2Size(): number {
return 41;
}

export function findEscrowV2Pda(
context: Pick<Context, 'eddsa' | 'programs'>,
seeds: {
/** The address of the authority */
authority: PublicKey;
}
): Pda {
const programId = context.programs.getPublicKey(
'mplHybrid',
'MPL4o4wMzndgh8T1NVDxELQCj5UQfYTYEkabX3wNKtb'
);
return context.eddsa.findPda(programId, [
string({ size: 'variable' }).serialize('escrow'),
publicKeySerializer().serialize(seeds.authority),
]);
}

export async function fetchEscrowV2FromSeeds(
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>,
seeds: Parameters<typeof findEscrowV2Pda>[1],
options?: RpcGetAccountOptions
): Promise<EscrowV2> {
return fetchEscrowV2(context, findEscrowV2Pda(context, seeds), options);
}

export async function safeFetchEscrowV2FromSeeds(
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>,
seeds: Parameters<typeof findEscrowV2Pda>[1],
options?: RpcGetAccountOptions
): Promise<EscrowV2 | null> {
return safeFetchEscrowV2(context, findEscrowV2Pda(context, seeds), options);
}
33 changes: 33 additions & 0 deletions clients/js/src/generated/accounts/recipeV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,36 @@ export function getRecipeV1GpaBuilder(
.deserializeUsing<RecipeV1>((account) => deserializeRecipeV1(account))
.whereField('discriminator', [137, 249, 37, 80, 19, 50, 78, 169]);
}

export function findRecipeV1Pda(
context: Pick<Context, 'eddsa' | 'programs'>,
seeds: {
/** The address of the collection */
collection: PublicKey;
}
): Pda {
const programId = context.programs.getPublicKey(
'mplHybrid',
'MPL4o4wMzndgh8T1NVDxELQCj5UQfYTYEkabX3wNKtb'
);
return context.eddsa.findPda(programId, [
string({ size: 'variable' }).serialize('recipe'),
publicKeySerializer().serialize(seeds.collection),
]);
}

export async function fetchRecipeV1FromSeeds(
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>,
seeds: Parameters<typeof findRecipeV1Pda>[1],
options?: RpcGetAccountOptions
): Promise<RecipeV1> {
return fetchRecipeV1(context, findRecipeV1Pda(context, seeds), options);
}

export async function safeFetchRecipeV1FromSeeds(
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>,
seeds: Parameters<typeof findRecipeV1Pda>[1],
options?: RpcGetAccountOptions
): Promise<RecipeV1 | null> {
return safeFetchRecipeV1(context, findRecipeV1Pda(context, seeds), options);
}
62 changes: 53 additions & 9 deletions clients/js/src/generated/instructions/captureV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
* @see https://github.com/metaplex-foundation/kinobi
*/

import { findAssociatedTokenPda } from '@metaplex-foundation/mpl-toolbox';
import {
Context,
Pda,
PublicKey,
Signer,
TransactionBuilder,
publicKey,
transactionBuilder,
} from '@metaplex-foundation/umi';
import {
Expand All @@ -24,28 +26,29 @@ import {
import {
ResolvedAccount,
ResolvedAccountsWithIndices,
expectPublicKey,
getAccountMetasAndSigners,
} from '../shared';

// Accounts.
export type CaptureV2InstructionAccounts = {
owner: Signer;
authority?: Signer;
authority?: PublicKey | Pda | Signer;
recipe: PublicKey | Pda;
escrow: PublicKey | Pda;
asset: PublicKey | Pda;
collection: PublicKey | Pda;
userTokenAccount: PublicKey | Pda;
escrowTokenAccount: PublicKey | Pda;
userTokenAccount?: PublicKey | Pda;
escrowTokenAccount?: PublicKey | Pda;
token: PublicKey | Pda;
feeTokenAccount: PublicKey | Pda;
feeSolAccount: PublicKey | Pda;
feeTokenAccount?: PublicKey | Pda;
feeSolAccount?: PublicKey | Pda;
feeProjectAccount: PublicKey | Pda;
recentBlockhashes: PublicKey | Pda;
mplCore: PublicKey | Pda;
recentBlockhashes?: PublicKey | Pda;
mplCore?: PublicKey | Pda;
systemProgram?: PublicKey | Pda;
tokenProgram?: PublicKey | Pda;
associatedTokenProgram: PublicKey | Pda;
associatedTokenProgram?: PublicKey | Pda;
};

// Data.
Expand Down Expand Up @@ -75,7 +78,7 @@ export function getCaptureV2InstructionDataSerializer(): Serializer<

// Instruction.
export function captureV2(
context: Pick<Context, 'identity' | 'programs'>,
context: Pick<Context, 'eddsa' | 'identity' | 'programs'>,
input: CaptureV2InstructionAccounts
): TransactionBuilder {
// Program ID.
Expand Down Expand Up @@ -177,6 +180,42 @@ export function captureV2(
if (!resolvedAccounts.authority.value) {
resolvedAccounts.authority.value = context.identity;
}
if (!resolvedAccounts.userTokenAccount.value) {
resolvedAccounts.userTokenAccount.value = findAssociatedTokenPda(context, {
mint: expectPublicKey(resolvedAccounts.token.value),
owner: expectPublicKey(resolvedAccounts.owner.value),
});
}
if (!resolvedAccounts.escrowTokenAccount.value) {
resolvedAccounts.escrowTokenAccount.value = findAssociatedTokenPda(
context,
{
mint: expectPublicKey(resolvedAccounts.token.value),
owner: expectPublicKey(resolvedAccounts.escrow.value),
}
);
}
if (!resolvedAccounts.feeTokenAccount.value) {
resolvedAccounts.feeTokenAccount.value = findAssociatedTokenPda(context, {
mint: expectPublicKey(resolvedAccounts.token.value),
owner: expectPublicKey(resolvedAccounts.feeProjectAccount.value),
});
}
if (!resolvedAccounts.feeSolAccount.value) {
resolvedAccounts.feeSolAccount.value = publicKey(
'GjF4LqmEhV33riVyAwHwiEeAHx4XXFn2yMY3fmMigoP3'
);
}
if (!resolvedAccounts.recentBlockhashes.value) {
resolvedAccounts.recentBlockhashes.value = publicKey(
'SysvarS1otHashes111111111111111111111111111'
);
}
if (!resolvedAccounts.mplCore.value) {
resolvedAccounts.mplCore.value = publicKey(
'CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d'
);
}
if (!resolvedAccounts.systemProgram.value) {
resolvedAccounts.systemProgram.value = context.programs.getPublicKey(
'splSystem',
Expand All @@ -191,6 +230,11 @@ export function captureV2(
);
resolvedAccounts.tokenProgram.isWritable = false;
}
if (!resolvedAccounts.associatedTokenProgram.value) {
resolvedAccounts.associatedTokenProgram.value = publicKey(
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'
);
}

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export * from './captureV2';
export * from './initEscrowV1';
export * from './initEscrowV2';
export * from './initNftDataV1';
export * from './initRecipe';
export * from './initRecipeV1';
export * from './migrateNftV1';
export * from './migrateTokensV1';
export * from './releaseV1';
Expand Down
11 changes: 9 additions & 2 deletions clients/js/src/generated/instructions/initEscrowV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ import {
struct,
u8,
} from '@metaplex-foundation/umi/serializers';
import { findEscrowV2Pda } from '../accounts';
import {
ResolvedAccount,
ResolvedAccountsWithIndices,
expectPublicKey,
getAccountMetasAndSigners,
} from '../shared';

// Accounts.
export type InitEscrowV2InstructionAccounts = {
escrow: PublicKey | Pda;
escrow?: PublicKey | Pda;
authority?: Signer;
systemProgram?: PublicKey | Pda;
};
Expand Down Expand Up @@ -61,7 +63,7 @@ export function getInitEscrowV2InstructionDataSerializer(): Serializer<

// Instruction.
export function initEscrowV2(
context: Pick<Context, 'identity' | 'programs'>,
context: Pick<Context, 'eddsa' | 'identity' | 'programs'>,
input: InitEscrowV2InstructionAccounts
): TransactionBuilder {
// Program ID.
Expand Down Expand Up @@ -93,6 +95,11 @@ export function initEscrowV2(
if (!resolvedAccounts.authority.value) {
resolvedAccounts.authority.value = context.identity;
}
if (!resolvedAccounts.escrow.value) {
resolvedAccounts.escrow.value = findEscrowV2Pda(context, {
authority: expectPublicKey(resolvedAccounts.authority.value),
});
}
if (!resolvedAccounts.systemProgram.value) {
resolvedAccounts.systemProgram.value = context.programs.getPublicKey(
'splSystem',
Expand Down
Loading

0 comments on commit c3b8144

Please sign in to comment.