Skip to content

Commit

Permalink
Merge pull request #8 from adm-metaex/feature/finalize-tree-with-coll…
Browse files Browse the repository at this point in the history
…ection

[MTG-294] feat: finalize tree with root and collection
  • Loading branch information
RequescoS authored Jul 16, 2024
2 parents 809fb9b + b369e2f commit 9869189
Show file tree
Hide file tree
Showing 18 changed files with 1,836 additions and 73 deletions.
17 changes: 10 additions & 7 deletions clients/js/src/generated/instructions/finalizeTreeWithRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type FinalizeTreeWithRootInstructionAccounts = {
treeConfig?: PublicKey | Pda;
merkleTree: PublicKey | Pda;
payer?: Signer;
incomingTreeDelegate: Signer;
treeCreatorOrDelegate?: Signer;
staker: Signer;
registrar: PublicKey | Pda;
voter: PublicKey | Pda;
Expand All @@ -50,15 +50,15 @@ export type FinalizeTreeWithRootInstructionAccounts = {
// Data.
export type FinalizeTreeWithRootInstructionData = {
discriminator: Array<number>;
rightmostRoot: Uint8Array;
root: Uint8Array;
rightmostLeaf: Uint8Array;
rightmostIndex: number;
metadataUrl: string;
metadataHash: string;
};

export type FinalizeTreeWithRootInstructionDataArgs = {
rightmostRoot: Uint8Array;
root: Uint8Array;
rightmostLeaf: Uint8Array;
rightmostIndex: number;
metadataUrl: string;
Expand All @@ -77,7 +77,7 @@ export function getFinalizeTreeWithRootInstructionDataSerializer(): Serializer<
struct<FinalizeTreeWithRootInstructionData>(
[
['discriminator', array(u8(), { size: 8 })],
['rightmostRoot', bytes({ size: 32 })],
['root', bytes({ size: 32 })],
['rightmostLeaf', bytes({ size: 32 })],
['rightmostIndex', u32()],
['metadataUrl', string()],
Expand All @@ -101,7 +101,7 @@ export type FinalizeTreeWithRootInstructionArgs =

// Instruction.
export function finalizeTreeWithRoot(
context: Pick<Context, 'eddsa' | 'payer' | 'programs'>,
context: Pick<Context, 'eddsa' | 'identity' | 'payer' | 'programs'>,
input: FinalizeTreeWithRootInstructionAccounts &
FinalizeTreeWithRootInstructionArgs
): TransactionBuilder {
Expand All @@ -116,10 +116,10 @@ export function finalizeTreeWithRoot(
treeConfig: { index: 0, isWritable: true, value: input.treeConfig ?? null },
merkleTree: { index: 1, isWritable: true, value: input.merkleTree ?? null },
payer: { index: 2, isWritable: true, value: input.payer ?? null },
incomingTreeDelegate: {
treeCreatorOrDelegate: {
index: 3,
isWritable: false,
value: input.incomingTreeDelegate ?? null,
value: input.treeCreatorOrDelegate ?? null,
},
staker: { index: 4, isWritable: false, value: input.staker ?? null },
registrar: { index: 5, isWritable: false, value: input.registrar ?? null },
Expand Down Expand Up @@ -158,6 +158,9 @@ export function finalizeTreeWithRoot(
if (!resolvedAccounts.payer.value) {
resolvedAccounts.payer.value = context.payer;
}
if (!resolvedAccounts.treeCreatorOrDelegate.value) {
resolvedAccounts.treeCreatorOrDelegate.value = context.identity;
}
if (!resolvedAccounts.logWrapper.value) {
resolvedAccounts.logWrapper.value = context.programs.getPublicKey(
'splNoop',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
/**
* This code was AUTOGENERATED using the kinobi library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun kinobi to update it.
*
* @see https://github.com/metaplex-foundation/kinobi
*/

import {
findMasterEditionPda,
findMetadataPda,
} from '@metaplex-foundation/mpl-token-metadata';
import {
Context,
Pda,
PublicKey,
Signer,
TransactionBuilder,
transactionBuilder,
} from '@metaplex-foundation/umi';
import {
Serializer,
array,
bytes,
mapSerializer,
string,
struct,
u32,
u8,
} from '@metaplex-foundation/umi/serializers';
import { findTreeConfigPda } from '../accounts';
import {
ResolvedAccount,
ResolvedAccountsWithIndices,
expectPublicKey,
getAccountMetasAndSigners,
} from '../shared';

// Accounts.
export type FinalizeTreeWithRootAndCollectionInstructionAccounts = {
treeConfig?: PublicKey | Pda;
merkleTree: PublicKey | Pda;
payer?: Signer;
treeCreatorOrDelegate?: Signer;
staker: Signer;
collectionAuthority?: Signer;
registrar: PublicKey | Pda;
voter: PublicKey | Pda;
feeReceiver: PublicKey | Pda;
/**
* If there is no collecton authority record PDA then
* this must be the Bubblegum program address.
*/

collectionAuthorityRecordPda?: PublicKey | Pda;
collectionMint: PublicKey | Pda;
collectionMetadata?: PublicKey | Pda;
collectionEdition?: PublicKey | Pda;
logWrapper?: PublicKey | Pda;
compressionProgram?: PublicKey | Pda;
systemProgram?: PublicKey | Pda;
};

// Data.
export type FinalizeTreeWithRootAndCollectionInstructionData = {
discriminator: Array<number>;
root: Uint8Array;
rightmostLeaf: Uint8Array;
rightmostIndex: number;
metadataUrl: string;
metadataHash: string;
};

export type FinalizeTreeWithRootAndCollectionInstructionDataArgs = {
root: Uint8Array;
rightmostLeaf: Uint8Array;
rightmostIndex: number;
metadataUrl: string;
metadataHash: string;
};

export function getFinalizeTreeWithRootAndCollectionInstructionDataSerializer(): Serializer<
FinalizeTreeWithRootAndCollectionInstructionDataArgs,
FinalizeTreeWithRootAndCollectionInstructionData
> {
return mapSerializer<
FinalizeTreeWithRootAndCollectionInstructionDataArgs,
any,
FinalizeTreeWithRootAndCollectionInstructionData
>(
struct<FinalizeTreeWithRootAndCollectionInstructionData>(
[
['discriminator', array(u8(), { size: 8 })],
['root', bytes({ size: 32 })],
['rightmostLeaf', bytes({ size: 32 })],
['rightmostIndex', u32()],
['metadataUrl', string()],
['metadataHash', string()],
],
{ description: 'FinalizeTreeWithRootAndCollectionInstructionData' }
),
(value) => ({
...value,
discriminator: [194, 98, 45, 168, 183, 72, 67, 155],
})
) as Serializer<
FinalizeTreeWithRootAndCollectionInstructionDataArgs,
FinalizeTreeWithRootAndCollectionInstructionData
>;
}

// Args.
export type FinalizeTreeWithRootAndCollectionInstructionArgs =
FinalizeTreeWithRootAndCollectionInstructionDataArgs;

// Instruction.
export function finalizeTreeWithRootAndCollection(
context: Pick<Context, 'eddsa' | 'identity' | 'payer' | 'programs'>,
input: FinalizeTreeWithRootAndCollectionInstructionAccounts &
FinalizeTreeWithRootAndCollectionInstructionArgs
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
'mplBubblegum',
'BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY'
);

// Accounts.
const resolvedAccounts: ResolvedAccountsWithIndices = {
treeConfig: { index: 0, isWritable: true, value: input.treeConfig ?? null },
merkleTree: { index: 1, isWritable: true, value: input.merkleTree ?? null },
payer: { index: 2, isWritable: true, value: input.payer ?? null },
treeCreatorOrDelegate: {
index: 3,
isWritable: false,
value: input.treeCreatorOrDelegate ?? null,
},
staker: { index: 4, isWritable: false, value: input.staker ?? null },
collectionAuthority: {
index: 5,
isWritable: false,
value: input.collectionAuthority ?? null,
},
registrar: { index: 6, isWritable: false, value: input.registrar ?? null },
voter: { index: 7, isWritable: false, value: input.voter ?? null },
feeReceiver: {
index: 8,
isWritable: true,
value: input.feeReceiver ?? null,
},
collectionAuthorityRecordPda: {
index: 9,
isWritable: false,
value: input.collectionAuthorityRecordPda ?? null,
},
collectionMint: {
index: 10,
isWritable: false,
value: input.collectionMint ?? null,
},
collectionMetadata: {
index: 11,
isWritable: true,
value: input.collectionMetadata ?? null,
},
collectionEdition: {
index: 12,
isWritable: false,
value: input.collectionEdition ?? null,
},
logWrapper: {
index: 13,
isWritable: false,
value: input.logWrapper ?? null,
},
compressionProgram: {
index: 14,
isWritable: false,
value: input.compressionProgram ?? null,
},
systemProgram: {
index: 15,
isWritable: false,
value: input.systemProgram ?? null,
},
};

// Arguments.
const resolvedArgs: FinalizeTreeWithRootAndCollectionInstructionArgs = {
...input,
};

// Default values.
if (!resolvedAccounts.treeConfig.value) {
resolvedAccounts.treeConfig.value = findTreeConfigPda(context, {
merkleTree: expectPublicKey(resolvedAccounts.merkleTree.value),
});
}
if (!resolvedAccounts.payer.value) {
resolvedAccounts.payer.value = context.payer;
}
if (!resolvedAccounts.treeCreatorOrDelegate.value) {
resolvedAccounts.treeCreatorOrDelegate.value = context.identity;
}
if (!resolvedAccounts.collectionAuthority.value) {
resolvedAccounts.collectionAuthority.value = context.identity;
}
if (!resolvedAccounts.collectionMetadata.value) {
resolvedAccounts.collectionMetadata.value = findMetadataPda(context, {
mint: expectPublicKey(resolvedAccounts.collectionMint.value),
});
}
if (!resolvedAccounts.collectionEdition.value) {
resolvedAccounts.collectionEdition.value = findMasterEditionPda(context, {
mint: expectPublicKey(resolvedAccounts.collectionMint.value),
});
}
if (!resolvedAccounts.logWrapper.value) {
resolvedAccounts.logWrapper.value = context.programs.getPublicKey(
'splNoop',
'noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV'
);
resolvedAccounts.logWrapper.isWritable = false;
}
if (!resolvedAccounts.compressionProgram.value) {
resolvedAccounts.compressionProgram.value = context.programs.getPublicKey(
'splAccountCompression',
'cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK'
);
resolvedAccounts.compressionProgram.isWritable = false;
}
if (!resolvedAccounts.systemProgram.value) {
resolvedAccounts.systemProgram.value = context.programs.getPublicKey(
'splSystem',
'11111111111111111111111111111111'
);
resolvedAccounts.systemProgram.isWritable = false;
}

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
resolvedAccounts
).sort((a, b) => a.index - b.index);

// Keys and Signers.
const [keys, signers] = getAccountMetasAndSigners(
orderedAccounts,
'programId',
programId
);

// Data.
const data =
getFinalizeTreeWithRootAndCollectionInstructionDataSerializer().serialize(
resolvedArgs as FinalizeTreeWithRootAndCollectionInstructionDataArgs
);

// Bytes Created On Chain.
const bytesCreatedOnChain = 0;

return transactionBuilder([
{ instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
]);
}
1 change: 1 addition & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from './createTreeConfig';
export * from './decompressV1';
export * from './delegate';
export * from './finalizeTreeWithRoot';
export * from './finalizeTreeWithRootAndCollection';
export * from './mintToCollectionV1';
export * from './mintV1';
export * from './prepareTree';
Expand Down
10 changes: 5 additions & 5 deletions clients/rust/Cargo.lock

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

Loading

0 comments on commit 9869189

Please sign in to comment.