Skip to content

Commit 845b378

Browse files
committed
v0.1.13: fixed up some of the helper fns.
1 parent 27f1fcf commit 845b378

File tree

6 files changed

+136
-6
lines changed

6 files changed

+136
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tensor-hq/tensor-tests-common",
3-
"version": "0.1.7",
3+
"version": "0.1.13",
44
"description": "Common TEST utility methods used by Tensor.",
55
"sideEffects": false,
66
"module": "./dist/esm/index.js",

src/ata.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
MintInstructionArgs,
99
TokenStandard,
1010
VerificationArgs,
11+
createSetCollectionSizeInstruction,
1112
} from '@metaplex-foundation/mpl-token-metadata';
1213
import {
1314
ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -29,6 +30,7 @@ import {
2930
findMasterEditionPda,
3031
findMetadataPda,
3132
findTokenRecordPda,
33+
isNullLike,
3234
} from '@tensor-hq/tensor-common';
3335
import { buildAndSendTx, createFundedWallet } from './txs';
3436

@@ -75,6 +77,7 @@ export const createNft = async ({
7577
tokenStandard,
7678
royaltyBps,
7779
creators,
80+
setCollSize,
7881
collection,
7982
collectionVerified = true,
8083
ruleSet = null,
@@ -86,6 +89,7 @@ export const createNft = async ({
8689
tokenStandard: TokenStandard;
8790
royaltyBps?: number;
8891
creators?: CreatorInput[];
92+
setCollSize?: number;
8993
collection?: Keypair;
9094
collectionVerified?: boolean;
9195
ruleSet?: PublicKey | null;
@@ -226,12 +230,33 @@ export const createNft = async ({
226230
}) ?? [],
227231
);
228232

233+
const collSizeIxs = isNullLike(setCollSize)
234+
? []
235+
: [
236+
createSetCollectionSizeInstruction(
237+
{
238+
collectionMetadata: metadata,
239+
collectionAuthority: owner.publicKey,
240+
collectionMint: mint.publicKey,
241+
},
242+
{
243+
setCollectionSizeArgs: { size: setCollSize },
244+
},
245+
),
246+
];
247+
229248
// --------------------------------------- send
230249

231250
await buildAndSendTx({
232251
conn,
233252
payer,
234-
ixs: [createIx, mintIx, ...verifyCollIxs, ...verifyCreatorIxs],
253+
ixs: [
254+
createIx,
255+
mintIx,
256+
...verifyCollIxs,
257+
...verifyCreatorIxs,
258+
...collSizeIxs,
259+
],
235260
extraSigners: dedupeList(
236261
filterNullLike([
237262
owner,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './ata';
22
export * from './constants';
33
export * from './nfts';
4+
export * from './tensorswap';
45
export * from './txs';
56
export * from './utils';
67
export * from './whitelist';

src/nfts.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
createCreateMasterEditionV3Instruction,
1919
createCreateMetadataAccountV3Instruction,
2020
createSetCollectionSizeInstruction,
21+
TokenStandard,
2122
} from '@metaplex-foundation/mpl-token-metadata';
2223
import {
2324
ConcurrentMerkleTreeAccount,
@@ -38,7 +39,7 @@ import {
3839
prependComputeIxs,
3940
TMETA_PROG_ID,
4041
} from '@tensor-hq/tensor-common';
41-
import { makeMintTwoAta } from './ata';
42+
import { createNft, makeMintTwoAta } from './ata';
4243
import { buildAndSendTx, makeNTraders } from './txs';
4344

4445
export const DEFAULT_DEPTH_SIZE: ValidDepthSizePair = {
@@ -494,7 +495,7 @@ export const verifyCNftCreator = async ({
494495
return { metadata, leaf, assetId };
495496
};
496497

497-
export const makeNfts = async ({
498+
export const makeTestNfts = async ({
498499
conn,
499500
payer,
500501
cnftMints = 0,
@@ -558,6 +559,18 @@ export const makeNfts = async ({
558559
share: 100 / nrCreators,
559560
}));
560561

562+
// --------------------------------------- create collection
563+
564+
await createNft({
565+
conn,
566+
payer,
567+
owner: treeOwner,
568+
mint: collection,
569+
tokenStandard: TokenStandard.NonFungible,
570+
royaltyBps: sellerFeeBasisPoints,
571+
setCollSize: 50,
572+
});
573+
561574
// --------------------------------------- pnfts
562575

563576
const traderAPnfts: Awaited<ReturnType<typeof makeMintTwoAta>>[] = [];
@@ -574,6 +587,7 @@ export const makeNfts = async ({
574587
creators,
575588
collection,
576589
collectionVerified: false,
590+
createCollection: false,
577591
programmable: true, // pnfts cannot verify currently
578592
ruleSetAddr,
579593
}),
@@ -591,13 +605,14 @@ export const makeNfts = async ({
591605
creators,
592606
collection,
593607
collectionVerified: false, // pnfts cannot verify currently
608+
createCollection: false,
594609
programmable: true,
595610
ruleSetAddr,
596611
}),
597612
);
598613
}
599614

600-
// --------------------------------------- cnfts (must come after collection mint created above)
615+
// --------------------------------------- cnfts
601616

602617
//has to be sequential to ensure index is correct
603618
let leaves: {

src/tensorswap.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { Connection, Keypair } from '@solana/web3.js';
2+
import {
3+
TensorSwapSDK,
4+
TensorWhitelistSDK,
5+
TSWAP_TAKER_FEE_BPS,
6+
} from '@tensor-hq/tensorswap-ts';
7+
import { expect } from 'chai';
8+
import { buildAndSendTx } from './txs';
9+
export { TensorSwapSDK, TensorWhitelistSDK } from '@tensor-hq/tensorswap-ts';
10+
11+
export const testInitWLAuthority = async ({
12+
conn,
13+
cosigner,
14+
owner,
15+
wlSdk,
16+
}: {
17+
conn: Connection;
18+
cosigner: Keypair;
19+
owner: Keypair;
20+
wlSdk: TensorWhitelistSDK;
21+
}) => {
22+
const {
23+
tx: { ixs },
24+
authPda,
25+
} = await wlSdk.initUpdateAuthority({
26+
cosigner: cosigner.publicKey,
27+
owner: owner.publicKey,
28+
newCosigner: cosigner.publicKey,
29+
newOwner: owner.publicKey,
30+
});
31+
32+
await buildAndSendTx({
33+
conn,
34+
payer: owner,
35+
ixs,
36+
extraSigners: [cosigner],
37+
});
38+
39+
let authAcc = await wlSdk.fetchAuthority(authPda);
40+
expect(authAcc.cosigner.toBase58()).to.eq(cosigner.publicKey.toBase58());
41+
expect(authAcc.owner.toBase58()).to.eq(owner.publicKey.toBase58());
42+
43+
return { authPda, owner };
44+
};
45+
46+
export const testInitTSwap = async ({
47+
wlSdk,
48+
swapSdk,
49+
conn,
50+
cosigner,
51+
owner,
52+
}: {
53+
wlSdk: TensorWhitelistSDK;
54+
swapSdk: TensorSwapSDK;
55+
conn: Connection;
56+
cosigner: Keypair;
57+
owner: Keypair;
58+
}) => {
59+
// WL authority
60+
await testInitWLAuthority({ wlSdk, conn, cosigner, owner });
61+
62+
// Tswap
63+
const {
64+
tx: { ixs },
65+
tswapPda,
66+
} = await swapSdk.initUpdateTSwap({
67+
owner: owner.publicKey,
68+
newOwner: owner.publicKey,
69+
config: {
70+
feeBps: TSWAP_TAKER_FEE_BPS,
71+
},
72+
cosigner: cosigner.publicKey,
73+
});
74+
75+
await buildAndSendTx({
76+
conn,
77+
payer: owner,
78+
ixs,
79+
extraSigners: [cosigner],
80+
});
81+
82+
const swapAcc = await swapSdk.fetchTSwap(tswapPda);
83+
expect(swapAcc.version).eq(1);
84+
expect(swapAcc.owner.toBase58()).eq(owner.publicKey.toBase58());
85+
expect(swapAcc.cosigner.toBase58()).eq(cosigner.publicKey.toBase58());
86+
expect(swapAcc.feeVault.toBase58()).eq(tswapPda.toBase58());
87+
expect(swapAcc.config.feeBps).eq(TSWAP_TAKER_FEE_BPS);
88+
89+
return { tswapPda };
90+
};

src/whitelist.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { TensorWhitelistSDK } from '@tensor-hq/tensorswap-ts';
33
import { keccak256 } from 'js-sha3';
44
import { MerkleTree } from 'merkletreejs';
55
import { buildAndSendTx } from './txs';
6-
export { TensorWhitelistSDK } from '@tensor-hq/tensorswap-ts';
76

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

0 commit comments

Comments
 (0)