generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Showing
18 changed files
with
650 additions
and
27 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,88 @@ | ||
/** | ||
* 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, | ||
TransactionBuilder, | ||
transactionBuilder, | ||
} from '@metaplex-foundation/umi'; | ||
import { | ||
Serializer, | ||
mapSerializer, | ||
struct, | ||
u8, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
import { | ||
ResolvedAccount, | ||
ResolvedAccountsWithIndices, | ||
getAccountMetasAndSigners, | ||
} from '../shared'; | ||
|
||
// Accounts. | ||
export type CollectInstructionAccounts = { | ||
/** The address of the recipient */ | ||
recipient: PublicKey | Pda; | ||
}; | ||
|
||
// Data. | ||
export type CollectInstructionData = { discriminator: number }; | ||
|
||
export type CollectInstructionDataArgs = {}; | ||
|
||
export function getCollectInstructionDataSerializer(): Serializer< | ||
CollectInstructionDataArgs, | ||
CollectInstructionData | ||
> { | ||
return mapSerializer<CollectInstructionDataArgs, any, CollectInstructionData>( | ||
struct<CollectInstructionData>([['discriminator', u8()]], { | ||
description: 'CollectInstructionData', | ||
}), | ||
(value) => ({ ...value, discriminator: 19 }) | ||
) as Serializer<CollectInstructionDataArgs, CollectInstructionData>; | ||
} | ||
|
||
// Instruction. | ||
export function collect( | ||
context: Pick<Context, 'programs'>, | ||
input: CollectInstructionAccounts | ||
): TransactionBuilder { | ||
// Program ID. | ||
const programId = context.programs.getPublicKey( | ||
'mplCore', | ||
'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL' | ||
); | ||
|
||
// Accounts. | ||
const resolvedAccounts: ResolvedAccountsWithIndices = { | ||
recipient: { index: 0, isWritable: true, value: input.recipient ?? null }, | ||
}; | ||
|
||
// 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 = getCollectInstructionDataSerializer().serialize({}); | ||
|
||
// 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { PublicKey, Umi, generateSigner, sol } from '@metaplex-foundation/umi'; | ||
import test from 'ava'; | ||
|
||
import { | ||
AssetWithPlugins, | ||
DataState, | ||
PluginType, | ||
addPlugin, | ||
create, | ||
fetchAssetWithPlugins, | ||
plugin, | ||
removePlugin, | ||
updateAuthority, | ||
} from '../src'; | ||
import { createUmi } from './_setup'; | ||
|
||
const hasCollectAmount = async (umi: Umi, address: PublicKey) => { | ||
const account = await umi.rpc.getAccount(address); | ||
if (account.exists) { | ||
const rent = await umi.rpc.getRent(account.data.length) | ||
const diff = account.lamports.basisPoints - rent.basisPoints | ||
return diff === sol(0.0015).basisPoints | ||
} | ||
return false | ||
} | ||
|
||
test('it can create a new asset with collect amount', async (t) => { | ||
// Given a Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const assetAddress = generateSigner(umi); | ||
|
||
// When we create a new account. | ||
await create(umi, { | ||
dataState: DataState.AccountState, | ||
asset: assetAddress, | ||
name: 'Test Bread', | ||
uri: 'https://example.com/bread', | ||
plugins: [] | ||
}).sendAndConfirm(umi); | ||
|
||
// Then an account was created with the correct data. | ||
const asset = await fetchAssetWithPlugins(umi, assetAddress.publicKey); | ||
// console.log("Account State:", asset); | ||
t.like(asset, <AssetWithPlugins>{ | ||
publicKey: assetAddress.publicKey, | ||
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), | ||
owner: umi.identity.publicKey, | ||
name: 'Test Bread', | ||
uri: 'https://example.com/bread', | ||
}); | ||
|
||
t.assert(await hasCollectAmount(umi, assetAddress.publicKey), 'Collect amount not found') | ||
}); | ||
|
||
test('it can add asset plugin with collect amount', async (t) => { | ||
// Given a Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const assetAddress = generateSigner(umi); | ||
|
||
// When we create a new account. | ||
await create(umi, { | ||
dataState: DataState.AccountState, | ||
asset: assetAddress, | ||
name: 'Test Bread', | ||
uri: 'https://example.com/bread', | ||
plugins: [] | ||
}).sendAndConfirm(umi); | ||
|
||
await addPlugin(umi, { | ||
asset: assetAddress.publicKey, | ||
addPluginArgs: { plugin: plugin('Freeze', [{ frozen: true }]) } | ||
}).sendAndConfirm(umi); | ||
|
||
t.assert(await hasCollectAmount(umi, assetAddress.publicKey), 'Collect amount not found') | ||
}); | ||
|
||
test('it can add remove asset plugin with collect amount', async (t) => { | ||
// Given a Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const assetAddress = generateSigner(umi); | ||
|
||
// When we create a new account. | ||
await create(umi, { | ||
dataState: DataState.AccountState, | ||
asset: assetAddress, | ||
name: 'Test Bread', | ||
uri: 'https://example.com/bread', | ||
plugins: [ | ||
plugin('Freeze', [{ frozen: false }]) | ||
] | ||
}).sendAndConfirm(umi); | ||
t.assert(await hasCollectAmount(umi, assetAddress.publicKey), 'Collect amount not found') | ||
|
||
await removePlugin(umi, { | ||
asset: assetAddress.publicKey, | ||
removePluginArgs: { pluginType: PluginType.Freeze, } | ||
}).sendAndConfirm(umi); | ||
t.assert(await hasCollectAmount(umi, assetAddress.publicKey), 'Collect amount not found') | ||
}); |
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.