Skip to content

Commit

Permalink
feat: set whitelisted tx & minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vecheslav committed Sep 20, 2021
1 parent 1ebd19e commit 17f592f
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 3 deletions.
9 changes: 9 additions & 0 deletions api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -8,4 +16,5 @@ export default {
diagnostics: false,
},
},
moduleNameMapper: pathsToModuleNameMapper(paths, { prefix: '<rootDir>/' }),
};
1 change: 1 addition & 0 deletions api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const config = {
metadata: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s',
metaplex: 'p1exdMJcjVao65QdewkaZRUnU6VPSXhus9n2GzWfh98',
vault: 'vau1zxA2LbssAUEF7Gpw91zMM1LvXrvpzJtmZ58rPsn',
packs: 'BNRmGgciUJuyznkYHnmitA9an1BcDDiU9JmjEQwvBYVR',
// External
memo: 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr',
},
Expand Down
82 changes: 82 additions & 0 deletions api/src/programs/metaplex/transactions/SetWhitelistedCreator.ts
Original file line number Diff line number Diff line change
@@ -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<SetWhitelistedCreatorArgs>([
['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,
}),
);
}
}
3 changes: 2 additions & 1 deletion api/src/programs/nft-packs/NFTPacksProgram.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PublicKey } from '@solana/web3.js';
import { config } from '../../config';
import { Program } from '../../Program';

export enum NFTPacksAccountType {
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion api/test/metaplex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 37 additions & 0 deletions api/test/transactions/metaplex.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
PayForFiles,
CreateMint,
CreateAssociatedTokenAccount,
} from '../src';
} from '../../src';

describe.skip('Mint NFT', () => {
let connection: Connection;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 17f592f

Please sign in to comment.