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.
Add
updateV2
which allows adding/removing an asset from collection (#…
…142) * Add ability to add/remove an asset from a collection * Regenerate clients * Add back check for V1 removing from collection * Validate permission to add to new collection * Update comments * Simplify condition * Kinobi default for updateV2 and initial tests * Add test changing collection using delegate * Add wrong collection tests and collection size checks * Additional change collection tests * More checks * Update JS SDK V1 to use updateV2 * Update updateV2 test to use SDK * Use SDK test helpers * Only increment num_minted on create * Add negative test cases * Reorder tests * Add more update delegate tests, rename tests, add asserts * Separate increment into two methods
- Loading branch information
Showing
17 changed files
with
2,386 additions
and
62 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
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,190 @@ | ||
/** | ||
* 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, | ||
Option, | ||
OptionOrNullable, | ||
Pda, | ||
PublicKey, | ||
Signer, | ||
TransactionBuilder, | ||
none, | ||
transactionBuilder, | ||
} from '@metaplex-foundation/umi'; | ||
import { | ||
Serializer, | ||
mapSerializer, | ||
option, | ||
string, | ||
struct, | ||
u8, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
import { | ||
ResolvedAccount, | ||
ResolvedAccountsWithIndices, | ||
getAccountMetasAndSigners, | ||
} from '../shared'; | ||
import { | ||
BaseUpdateAuthority, | ||
BaseUpdateAuthorityArgs, | ||
getBaseUpdateAuthoritySerializer, | ||
} from '../types'; | ||
|
||
// Accounts. | ||
export type UpdateV2InstructionAccounts = { | ||
/** The address of the asset */ | ||
asset: PublicKey | Pda; | ||
/** The collection to which the asset belongs */ | ||
collection?: PublicKey | Pda; | ||
/** The account paying for the storage fees */ | ||
payer?: Signer; | ||
/** The update authority or update authority delegate of the asset */ | ||
authority?: Signer; | ||
/** A new collection to which to move the asset */ | ||
newCollection?: PublicKey | Pda; | ||
/** The system program */ | ||
systemProgram?: PublicKey | Pda; | ||
/** The SPL Noop Program */ | ||
logWrapper?: PublicKey | Pda; | ||
}; | ||
|
||
// Data. | ||
export type UpdateV2InstructionData = { | ||
discriminator: number; | ||
newName: Option<string>; | ||
newUri: Option<string>; | ||
newUpdateAuthority: Option<BaseUpdateAuthority>; | ||
}; | ||
|
||
export type UpdateV2InstructionDataArgs = { | ||
newName?: OptionOrNullable<string>; | ||
newUri?: OptionOrNullable<string>; | ||
newUpdateAuthority?: OptionOrNullable<BaseUpdateAuthorityArgs>; | ||
}; | ||
|
||
export function getUpdateV2InstructionDataSerializer(): Serializer< | ||
UpdateV2InstructionDataArgs, | ||
UpdateV2InstructionData | ||
> { | ||
return mapSerializer< | ||
UpdateV2InstructionDataArgs, | ||
any, | ||
UpdateV2InstructionData | ||
>( | ||
struct<UpdateV2InstructionData>( | ||
[ | ||
['discriminator', u8()], | ||
['newName', option(string())], | ||
['newUri', option(string())], | ||
['newUpdateAuthority', option(getBaseUpdateAuthoritySerializer())], | ||
], | ||
{ description: 'UpdateV2InstructionData' } | ||
), | ||
(value) => ({ | ||
...value, | ||
discriminator: 30, | ||
newName: value.newName ?? none(), | ||
newUri: value.newUri ?? none(), | ||
newUpdateAuthority: value.newUpdateAuthority ?? none(), | ||
}) | ||
) as Serializer<UpdateV2InstructionDataArgs, UpdateV2InstructionData>; | ||
} | ||
|
||
// Args. | ||
export type UpdateV2InstructionArgs = UpdateV2InstructionDataArgs; | ||
|
||
// Instruction. | ||
export function updateV2( | ||
context: Pick<Context, 'payer' | 'programs'>, | ||
input: UpdateV2InstructionAccounts & UpdateV2InstructionArgs | ||
): TransactionBuilder { | ||
// Program ID. | ||
const programId = context.programs.getPublicKey( | ||
'mplCore', | ||
'CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d' | ||
); | ||
|
||
// Accounts. | ||
const resolvedAccounts = { | ||
asset: { | ||
index: 0, | ||
isWritable: true as boolean, | ||
value: input.asset ?? null, | ||
}, | ||
collection: { | ||
index: 1, | ||
isWritable: true as boolean, | ||
value: input.collection ?? null, | ||
}, | ||
payer: { | ||
index: 2, | ||
isWritable: true as boolean, | ||
value: input.payer ?? null, | ||
}, | ||
authority: { | ||
index: 3, | ||
isWritable: false as boolean, | ||
value: input.authority ?? null, | ||
}, | ||
newCollection: { | ||
index: 4, | ||
isWritable: true as boolean, | ||
value: input.newCollection ?? null, | ||
}, | ||
systemProgram: { | ||
index: 5, | ||
isWritable: false as boolean, | ||
value: input.systemProgram ?? null, | ||
}, | ||
logWrapper: { | ||
index: 6, | ||
isWritable: false as boolean, | ||
value: input.logWrapper ?? null, | ||
}, | ||
} satisfies ResolvedAccountsWithIndices; | ||
|
||
// Arguments. | ||
const resolvedArgs: UpdateV2InstructionArgs = { ...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 = getUpdateV2InstructionDataSerializer().serialize( | ||
resolvedArgs as UpdateV2InstructionDataArgs | ||
); | ||
|
||
// 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
Oops, something went wrong.