diff --git a/api/jest.config.ts b/api/jest.config.ts index eb0d98d..0fe59b0 100644 --- a/api/jest.config.ts +++ b/api/jest.config.ts @@ -1,3 +1,11 @@ +import { pathsToModuleNameMapper } from 'ts-jest/utils'; + +const paths = { + '@metaplex/utils': ['./src/utils'], + '@metaplex/types': ['./src/types'], + '@metaplex/errors': ['./src/errors'], +}; + export default { preset: 'ts-jest', testEnvironment: 'node', @@ -8,4 +16,5 @@ export default { diagnostics: false, }, }, + moduleNameMapper: pathsToModuleNameMapper(paths, { prefix: '/' }), }; diff --git a/api/src/config.ts b/api/src/config.ts index 794e0de..2352422 100644 --- a/api/src/config.ts +++ b/api/src/config.ts @@ -7,6 +7,7 @@ export const config = { metadata: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', metaplex: 'p1exdMJcjVao65QdewkaZRUnU6VPSXhus9n2GzWfh98', vault: 'vau1zxA2LbssAUEF7Gpw91zMM1LvXrvpzJtmZ58rPsn', + packs: 'BNRmGgciUJuyznkYHnmitA9an1BcDDiU9JmjEQwvBYVR', // External memo: 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr', }, diff --git a/api/src/programs/metaplex/transactions/SetWhitelistedCreator.ts b/api/src/programs/metaplex/transactions/SetWhitelistedCreator.ts new file mode 100644 index 0000000..5a10842 --- /dev/null +++ b/api/src/programs/metaplex/transactions/SetWhitelistedCreator.ts @@ -0,0 +1,82 @@ +import { borsh } from '@metaplex/utils'; +import { + PublicKey, + SystemProgram, + SYSVAR_RENT_PUBKEY, + TransactionCtorFields, + TransactionInstruction, +} from '@solana/web3.js'; +import { Transaction } from '../../../Transaction'; +import { MetaplexProgram } from '../MetaplexProgram'; + +export interface SetWhitelistedCreatorArgs { + instruction: number; + activated: boolean; +} + +const setWhitelistedCreatorStruct = borsh.struct([ + ['instruction', 'u8'], + ['activated', 'u8'], +]); + +type SetWhitelistedCreatorParams = { + store: PublicKey; + admin: PublicKey; + whitelistedCreatorPDA: PublicKey; + creator: PublicKey; + activated: boolean; +}; + +export class SetWhitelistedCreator extends Transaction { + constructor(options: TransactionCtorFields, params: SetWhitelistedCreatorParams) { + super(options); + const { feePayer } = options; + const { admin, whitelistedCreatorPDA, store, creator, activated } = params; + + const data = setWhitelistedCreatorStruct.serialize({ instruction: 8, activated }); + + this.add( + new TransactionInstruction({ + keys: [ + { + pubkey: whitelistedCreatorPDA, + isSigner: false, + isWritable: true, + }, + { + pubkey: admin, + isSigner: true, + isWritable: false, + }, + { + pubkey: feePayer, + isSigner: true, + isWritable: false, + }, + { + pubkey: creator, + isSigner: false, + isWritable: false, + }, + { + pubkey: store, + isSigner: false, + isWritable: false, + }, + { + pubkey: SystemProgram.programId, + isSigner: false, + isWritable: false, + }, + { + pubkey: SYSVAR_RENT_PUBKEY, + isSigner: false, + isWritable: false, + }, + ], + programId: MetaplexProgram.PUBKEY, + data, + }), + ); + } +} diff --git a/api/src/programs/nft-packs/NFTPacksProgram.ts b/api/src/programs/nft-packs/NFTPacksProgram.ts index 48f4e97..0ed9790 100644 --- a/api/src/programs/nft-packs/NFTPacksProgram.ts +++ b/api/src/programs/nft-packs/NFTPacksProgram.ts @@ -1,4 +1,5 @@ import { PublicKey } from '@solana/web3.js'; +import { config } from '../../config'; import { Program } from '../../Program'; export enum NFTPacksAccountType { @@ -11,5 +12,5 @@ export enum NFTPacksAccountType { export class NFTPacksProgram extends Program { static readonly PREFIX = 'packs'; - static readonly PUBKEY = new PublicKey('BNRmGgciUJuyznkYHnmitA9an1BcDDiU9JmjEQwvBYVR'); + static readonly PUBKEY = new PublicKey(config.programs.packs); } diff --git a/api/test/metaplex.test.ts b/api/test/metaplex.test.ts index 8cc4770..3108197 100644 --- a/api/test/metaplex.test.ts +++ b/api/test/metaplex.test.ts @@ -49,7 +49,7 @@ describe('Metaplex', () => { expect(auctionManagers[0].data.store).toEqual(STORE_PUBKEY.toString()); }); - test('setStore', async () => { + test.skip('setStore', async () => { const storeId = await Store.getPDA(owner.publicKey); const setStoreTx = new SetStore( diff --git a/api/test/transactions/metaplex.test.ts b/api/test/transactions/metaplex.test.ts new file mode 100644 index 0000000..372f431 --- /dev/null +++ b/api/test/transactions/metaplex.test.ts @@ -0,0 +1,37 @@ +import { jest } from '@jest/globals'; +import { Keypair, sendAndConfirmTransaction } from '@solana/web3.js'; +import { Connection, SetStore, Store } from '../../src'; +import { FEE_PAYER } from '../utils'; + +describe('Metaplex transactions', () => { + let connection: Connection; + let owner: Keypair; + + jest.setTimeout(80000); + + beforeAll(() => { + connection = new Connection('devnet'); + owner = Keypair.generate(); + }); + + test.skip('setStore', async () => { + const storeId = await Store.getPDA(owner.publicKey); + + const setStoreTx = new SetStore( + { + feePayer: FEE_PAYER.publicKey, + }, + { + admin: owner.publicKey, + store: storeId, + isPublic: true, + }, + ); + + const txid = await sendAndConfirmTransaction(connection, setStoreTx, [FEE_PAYER, owner], { + commitment: 'confirmed', + }); + + // console.log(txid); + }); +}); diff --git a/api/test/mint.test.ts b/api/test/transactions/mint.test.ts similarity index 99% rename from api/test/mint.test.ts rename to api/test/transactions/mint.test.ts index 2069fcd..2306f6b 100644 --- a/api/test/mint.test.ts +++ b/api/test/transactions/mint.test.ts @@ -13,7 +13,7 @@ import { PayForFiles, CreateMint, CreateAssociatedTokenAccount, -} from '../src'; +} from '../../src'; describe.skip('Mint NFT', () => { let connection: Connection; diff --git a/package.json b/package.json index 614e4d9..ddd17ac 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dev": "yarn workspace @metaplex/js run dev", "build:docs": "yarn workspace @metaplex/js run build:docs", "build": "yarn workspace @metaplex/js run build", + "test": "yarn workspace @metaplex/js run test", "example:web": "yarn workspace example-web run start", "example:iife": "yarn workspace example-iife run start", "example:node": "yarn workspace example-node run start",