Skip to content

Commit

Permalink
v0.1.13: fixed up some of the helper fns.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwu committed Nov 19, 2023
1 parent 27f1fcf commit 845b378
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tensor-hq/tensor-tests-common",
"version": "0.1.7",
"version": "0.1.13",
"description": "Common TEST utility methods used by Tensor.",
"sideEffects": false,
"module": "./dist/esm/index.js",
Expand Down
27 changes: 26 additions & 1 deletion src/ata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
MintInstructionArgs,
TokenStandard,
VerificationArgs,
createSetCollectionSizeInstruction,
} from '@metaplex-foundation/mpl-token-metadata';
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
Expand All @@ -29,6 +30,7 @@ import {
findMasterEditionPda,
findMetadataPda,
findTokenRecordPda,
isNullLike,
} from '@tensor-hq/tensor-common';
import { buildAndSendTx, createFundedWallet } from './txs';

Expand Down Expand Up @@ -75,6 +77,7 @@ export const createNft = async ({
tokenStandard,
royaltyBps,
creators,
setCollSize,
collection,
collectionVerified = true,
ruleSet = null,
Expand All @@ -86,6 +89,7 @@ export const createNft = async ({
tokenStandard: TokenStandard;
royaltyBps?: number;
creators?: CreatorInput[];
setCollSize?: number;
collection?: Keypair;
collectionVerified?: boolean;
ruleSet?: PublicKey | null;
Expand Down Expand Up @@ -226,12 +230,33 @@ export const createNft = async ({
}) ?? [],
);

const collSizeIxs = isNullLike(setCollSize)
? []
: [
createSetCollectionSizeInstruction(
{
collectionMetadata: metadata,
collectionAuthority: owner.publicKey,
collectionMint: mint.publicKey,
},
{
setCollectionSizeArgs: { size: setCollSize },
},
),
];

// --------------------------------------- send

await buildAndSendTx({
conn,
payer,
ixs: [createIx, mintIx, ...verifyCollIxs, ...verifyCreatorIxs],
ixs: [
createIx,
mintIx,
...verifyCollIxs,
...verifyCreatorIxs,
...collSizeIxs,
],
extraSigners: dedupeList(
filterNullLike([
owner,
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './ata';
export * from './constants';
export * from './nfts';
export * from './tensorswap';
export * from './txs';
export * from './utils';
export * from './whitelist';
21 changes: 18 additions & 3 deletions src/nfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
createCreateMasterEditionV3Instruction,
createCreateMetadataAccountV3Instruction,
createSetCollectionSizeInstruction,
TokenStandard,
} from '@metaplex-foundation/mpl-token-metadata';
import {
ConcurrentMerkleTreeAccount,
Expand All @@ -38,7 +39,7 @@ import {
prependComputeIxs,
TMETA_PROG_ID,
} from '@tensor-hq/tensor-common';
import { makeMintTwoAta } from './ata';
import { createNft, makeMintTwoAta } from './ata';
import { buildAndSendTx, makeNTraders } from './txs';

export const DEFAULT_DEPTH_SIZE: ValidDepthSizePair = {
Expand Down Expand Up @@ -494,7 +495,7 @@ export const verifyCNftCreator = async ({
return { metadata, leaf, assetId };
};

export const makeNfts = async ({
export const makeTestNfts = async ({
conn,
payer,
cnftMints = 0,
Expand Down Expand Up @@ -558,6 +559,18 @@ export const makeNfts = async ({
share: 100 / nrCreators,
}));

// --------------------------------------- create collection

await createNft({
conn,
payer,
owner: treeOwner,
mint: collection,
tokenStandard: TokenStandard.NonFungible,
royaltyBps: sellerFeeBasisPoints,
setCollSize: 50,
});

// --------------------------------------- pnfts

const traderAPnfts: Awaited<ReturnType<typeof makeMintTwoAta>>[] = [];
Expand All @@ -574,6 +587,7 @@ export const makeNfts = async ({
creators,
collection,
collectionVerified: false,
createCollection: false,
programmable: true, // pnfts cannot verify currently
ruleSetAddr,
}),
Expand All @@ -591,13 +605,14 @@ export const makeNfts = async ({
creators,
collection,
collectionVerified: false, // pnfts cannot verify currently
createCollection: false,
programmable: true,
ruleSetAddr,
}),
);
}

// --------------------------------------- cnfts (must come after collection mint created above)
// --------------------------------------- cnfts

//has to be sequential to ensure index is correct
let leaves: {
Expand Down
90 changes: 90 additions & 0 deletions src/tensorswap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Connection, Keypair } from '@solana/web3.js';
import {
TensorSwapSDK,
TensorWhitelistSDK,
TSWAP_TAKER_FEE_BPS,
} from '@tensor-hq/tensorswap-ts';
import { expect } from 'chai';
import { buildAndSendTx } from './txs';
export { TensorSwapSDK, TensorWhitelistSDK } from '@tensor-hq/tensorswap-ts';

export const testInitWLAuthority = async ({
conn,
cosigner,
owner,
wlSdk,
}: {
conn: Connection;
cosigner: Keypair;
owner: Keypair;
wlSdk: TensorWhitelistSDK;
}) => {
const {
tx: { ixs },
authPda,
} = await wlSdk.initUpdateAuthority({
cosigner: cosigner.publicKey,
owner: owner.publicKey,
newCosigner: cosigner.publicKey,
newOwner: owner.publicKey,
});

await buildAndSendTx({
conn,
payer: owner,
ixs,
extraSigners: [cosigner],
});

let authAcc = await wlSdk.fetchAuthority(authPda);
expect(authAcc.cosigner.toBase58()).to.eq(cosigner.publicKey.toBase58());
expect(authAcc.owner.toBase58()).to.eq(owner.publicKey.toBase58());

return { authPda, owner };
};

export const testInitTSwap = async ({
wlSdk,
swapSdk,
conn,
cosigner,
owner,
}: {
wlSdk: TensorWhitelistSDK;
swapSdk: TensorSwapSDK;
conn: Connection;
cosigner: Keypair;
owner: Keypair;
}) => {
// WL authority
await testInitWLAuthority({ wlSdk, conn, cosigner, owner });

// Tswap
const {
tx: { ixs },
tswapPda,
} = await swapSdk.initUpdateTSwap({
owner: owner.publicKey,
newOwner: owner.publicKey,
config: {
feeBps: TSWAP_TAKER_FEE_BPS,
},
cosigner: cosigner.publicKey,
});

await buildAndSendTx({
conn,
payer: owner,
ixs,
extraSigners: [cosigner],
});

const swapAcc = await swapSdk.fetchTSwap(tswapPda);
expect(swapAcc.version).eq(1);
expect(swapAcc.owner.toBase58()).eq(owner.publicKey.toBase58());
expect(swapAcc.cosigner.toBase58()).eq(cosigner.publicKey.toBase58());
expect(swapAcc.feeVault.toBase58()).eq(tswapPda.toBase58());
expect(swapAcc.config.feeBps).eq(TSWAP_TAKER_FEE_BPS);

return { tswapPda };
};
1 change: 0 additions & 1 deletion src/whitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { TensorWhitelistSDK } from '@tensor-hq/tensorswap-ts';
import { keccak256 } from 'js-sha3';
import { MerkleTree } from 'merkletreejs';
import { buildAndSendTx } from './txs';
export { TensorWhitelistSDK } from '@tensor-hq/tensorswap-ts';

export const generateTreeOfSize = (size: number, targetMints: PublicKey[]) => {
const leaves = targetMints.map((m) => m.toBuffer());
Expand Down

0 comments on commit 845b378

Please sign in to comment.