generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c98251c
commit 5dd5cba
Showing
44 changed files
with
1,597 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/** | ||
* 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 { | ||
Account, | ||
Context, | ||
Pda, | ||
PublicKey, | ||
RpcAccount, | ||
RpcGetAccountOptions, | ||
RpcGetAccountsOptions, | ||
assertAccountExists, | ||
deserializeAccount, | ||
gpaBuilder, | ||
publicKey as toPublicKey, | ||
} from '@metaplex-foundation/umi'; | ||
import { | ||
Serializer, | ||
publicKey as publicKeySerializer, | ||
string, | ||
struct, | ||
u32, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
import { Key, KeyArgs, getKeySerializer } from '../types'; | ||
|
||
export type CollectionData = Account<CollectionDataAccountData>; | ||
|
||
export type CollectionDataAccountData = { | ||
key: Key; | ||
updateAuthority: PublicKey; | ||
name: string; | ||
uri: string; | ||
numMinted: number; | ||
currentSize: number; | ||
}; | ||
|
||
export type CollectionDataAccountDataArgs = { | ||
key: KeyArgs; | ||
updateAuthority: PublicKey; | ||
name: string; | ||
uri: string; | ||
numMinted: number; | ||
currentSize: number; | ||
}; | ||
|
||
export function getCollectionDataAccountDataSerializer(): Serializer< | ||
CollectionDataAccountDataArgs, | ||
CollectionDataAccountData | ||
> { | ||
return struct<CollectionDataAccountData>( | ||
[ | ||
['key', getKeySerializer()], | ||
['updateAuthority', publicKeySerializer()], | ||
['name', string()], | ||
['uri', string()], | ||
['numMinted', u32()], | ||
['currentSize', u32()], | ||
], | ||
{ description: 'CollectionDataAccountData' } | ||
) as Serializer<CollectionDataAccountDataArgs, CollectionDataAccountData>; | ||
} | ||
|
||
export function deserializeCollectionData( | ||
rawAccount: RpcAccount | ||
): CollectionData { | ||
return deserializeAccount( | ||
rawAccount, | ||
getCollectionDataAccountDataSerializer() | ||
); | ||
} | ||
|
||
export async function fetchCollectionData( | ||
context: Pick<Context, 'rpc'>, | ||
publicKey: PublicKey | Pda, | ||
options?: RpcGetAccountOptions | ||
): Promise<CollectionData> { | ||
const maybeAccount = await context.rpc.getAccount( | ||
toPublicKey(publicKey, false), | ||
options | ||
); | ||
assertAccountExists(maybeAccount, 'CollectionData'); | ||
return deserializeCollectionData(maybeAccount); | ||
} | ||
|
||
export async function safeFetchCollectionData( | ||
context: Pick<Context, 'rpc'>, | ||
publicKey: PublicKey | Pda, | ||
options?: RpcGetAccountOptions | ||
): Promise<CollectionData | null> { | ||
const maybeAccount = await context.rpc.getAccount( | ||
toPublicKey(publicKey, false), | ||
options | ||
); | ||
return maybeAccount.exists ? deserializeCollectionData(maybeAccount) : null; | ||
} | ||
|
||
export async function fetchAllCollectionData( | ||
context: Pick<Context, 'rpc'>, | ||
publicKeys: Array<PublicKey | Pda>, | ||
options?: RpcGetAccountsOptions | ||
): Promise<CollectionData[]> { | ||
const maybeAccounts = await context.rpc.getAccounts( | ||
publicKeys.map((key) => toPublicKey(key, false)), | ||
options | ||
); | ||
return maybeAccounts.map((maybeAccount) => { | ||
assertAccountExists(maybeAccount, 'CollectionData'); | ||
return deserializeCollectionData(maybeAccount); | ||
}); | ||
} | ||
|
||
export async function safeFetchAllCollectionData( | ||
context: Pick<Context, 'rpc'>, | ||
publicKeys: Array<PublicKey | Pda>, | ||
options?: RpcGetAccountsOptions | ||
): Promise<CollectionData[]> { | ||
const maybeAccounts = await context.rpc.getAccounts( | ||
publicKeys.map((key) => toPublicKey(key, false)), | ||
options | ||
); | ||
return maybeAccounts | ||
.filter((maybeAccount) => maybeAccount.exists) | ||
.map((maybeAccount) => | ||
deserializeCollectionData(maybeAccount as RpcAccount) | ||
); | ||
} | ||
|
||
export function getCollectionDataGpaBuilder( | ||
context: Pick<Context, 'rpc' | 'programs'> | ||
) { | ||
const programId = context.programs.getPublicKey( | ||
'mplCoreProgram', | ||
'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL' | ||
); | ||
return gpaBuilder(context, programId) | ||
.registerFields<{ | ||
key: KeyArgs; | ||
updateAuthority: PublicKey; | ||
name: string; | ||
uri: string; | ||
numMinted: number; | ||
currentSize: number; | ||
}>({ | ||
key: [0, getKeySerializer()], | ||
updateAuthority: [1, publicKeySerializer()], | ||
name: [33, string()], | ||
uri: [null, string()], | ||
numMinted: [null, u32()], | ||
currentSize: [null, u32()], | ||
}) | ||
.deserializeUsing<CollectionData>((account) => | ||
deserializeCollectionData(account) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
clients/js/src/generated/instructions/createCollection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/** | ||
* 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 { | ||
Context, | ||
Pda, | ||
PublicKey, | ||
Signer, | ||
TransactionBuilder, | ||
transactionBuilder, | ||
} from '@metaplex-foundation/umi'; | ||
import { | ||
Serializer, | ||
array, | ||
mapSerializer, | ||
string, | ||
struct, | ||
u8, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
import { | ||
ResolvedAccount, | ||
ResolvedAccountsWithIndices, | ||
getAccountMetasAndSigners, | ||
} from '../shared'; | ||
import { Plugin, PluginArgs, getPluginSerializer } from '../types'; | ||
|
||
// Accounts. | ||
export type CreateCollectionInstructionAccounts = { | ||
/** The address of the new asset */ | ||
collectionAddress: Signer; | ||
/** The authority of the new asset */ | ||
updateAuthority?: PublicKey | Pda; | ||
/** The account paying for the storage fees */ | ||
payer?: Signer; | ||
/** The owner of the new asset. Defaults to the authority if not present. */ | ||
owner?: PublicKey | Pda; | ||
/** The system program */ | ||
systemProgram?: PublicKey | Pda; | ||
}; | ||
|
||
// Data. | ||
export type CreateCollectionInstructionData = { | ||
discriminator: number; | ||
name: string; | ||
uri: string; | ||
plugins: Array<Plugin>; | ||
}; | ||
|
||
export type CreateCollectionInstructionDataArgs = { | ||
name: string; | ||
uri: string; | ||
plugins: Array<PluginArgs>; | ||
}; | ||
|
||
export function getCreateCollectionInstructionDataSerializer(): Serializer< | ||
CreateCollectionInstructionDataArgs, | ||
CreateCollectionInstructionData | ||
> { | ||
return mapSerializer< | ||
CreateCollectionInstructionDataArgs, | ||
any, | ||
CreateCollectionInstructionData | ||
>( | ||
struct<CreateCollectionInstructionData>( | ||
[ | ||
['discriminator', u8()], | ||
['name', string()], | ||
['uri', string()], | ||
['plugins', array(getPluginSerializer())], | ||
], | ||
{ description: 'CreateCollectionInstructionData' } | ||
), | ||
(value) => ({ ...value, discriminator: 1 }) | ||
) as Serializer< | ||
CreateCollectionInstructionDataArgs, | ||
CreateCollectionInstructionData | ||
>; | ||
} | ||
|
||
// Args. | ||
export type CreateCollectionInstructionArgs = | ||
CreateCollectionInstructionDataArgs; | ||
|
||
// Instruction. | ||
export function createCollection( | ||
context: Pick<Context, 'payer' | 'programs'>, | ||
input: CreateCollectionInstructionAccounts & CreateCollectionInstructionArgs | ||
): TransactionBuilder { | ||
// Program ID. | ||
const programId = context.programs.getPublicKey( | ||
'mplCoreProgram', | ||
'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL' | ||
); | ||
|
||
// Accounts. | ||
const resolvedAccounts: ResolvedAccountsWithIndices = { | ||
collectionAddress: { | ||
index: 0, | ||
isWritable: true, | ||
value: input.collectionAddress ?? null, | ||
}, | ||
updateAuthority: { | ||
index: 1, | ||
isWritable: false, | ||
value: input.updateAuthority ?? null, | ||
}, | ||
payer: { index: 2, isWritable: true, value: input.payer ?? null }, | ||
owner: { index: 3, isWritable: false, value: input.owner ?? null }, | ||
systemProgram: { | ||
index: 4, | ||
isWritable: false, | ||
value: input.systemProgram ?? null, | ||
}, | ||
}; | ||
|
||
// Arguments. | ||
const resolvedArgs: CreateCollectionInstructionArgs = { ...input }; | ||
|
||
// Default values. | ||
if (!resolvedAccounts.payer.value) { | ||
resolvedAccounts.payer.value = context.payer; | ||
} | ||
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 = getCreateCollectionInstructionDataSerializer().serialize( | ||
resolvedArgs as CreateCollectionInstructionDataArgs | ||
); | ||
|
||
// Bytes Created On Chain. | ||
const bytesCreatedOnChain = 0; | ||
|
||
return transactionBuilder([ | ||
{ instruction: { keys, programId, data }, signers, bytesCreatedOnChain }, | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.