flipmeme-sdk 1.2.14 → 1.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -20,6 +20,7 @@ interface SolanaConfig {
20
20
  provider: AnchorProvider;
21
21
  wallet: PublicKey;
22
22
  sendTransaction: (transaction: Transaction | VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<TransactionSignature>;
23
+ signAllTransactions: (txs: Array<Transaction | VersionedTransaction>) => Promise<Array<Transaction | VersionedTransaction>>;
23
24
  }
24
25
  interface CollectionParams {
25
26
  sessionId: string;
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ interface SolanaConfig {
20
20
  provider: AnchorProvider;
21
21
  wallet: PublicKey;
22
22
  sendTransaction: (transaction: Transaction | VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<TransactionSignature>;
23
+ signAllTransactions: (txs: Array<Transaction | VersionedTransaction>) => Promise<Array<Transaction | VersionedTransaction>>;
23
24
  }
24
25
  interface CollectionParams {
25
26
  sessionId: string;
package/dist/index.js CHANGED
@@ -174,37 +174,6 @@ var flipmeme_default = {
174
174
  ]
175
175
  }
176
176
  },
177
- {
178
- name: "collection_nft",
179
- writable: true,
180
- pda: {
181
- seeds: [
182
- {
183
- kind: "const",
184
- value: [
185
- 99,
186
- 111,
187
- 108,
188
- 108,
189
- 101,
190
- 99,
191
- 116,
192
- 105,
193
- 111,
194
- 110,
195
- 95,
196
- 110,
197
- 102,
198
- 116
199
- ]
200
- },
201
- {
202
- kind: "account",
203
- path: "collection"
204
- }
205
- ]
206
- }
207
- },
208
177
  {
209
178
  name: "treasury",
210
179
  writable: true
@@ -1301,6 +1270,10 @@ var flipmeme_default = {
1301
1270
  {
1302
1271
  name: "base_uri",
1303
1272
  type: "string"
1273
+ },
1274
+ {
1275
+ name: "nonce",
1276
+ type: "u8"
1304
1277
  }
1305
1278
  ]
1306
1279
  },
@@ -2273,9 +2246,9 @@ var SOLANA_PUBKEYS = {
2273
2246
  RENT_TOKEN_ID: new import_web3.PublicKey(SOLANA.RENT_TOKEN_STR)
2274
2247
  };
2275
2248
  var SDK_SOLANA_CONFIG = {
2276
- MINT_CHUNK_SIZE: 4,
2277
- BUY_CHUNK_SIZE: 2,
2278
- SELL_CHUNK_SIZE: 2
2249
+ MINT_CHUNK_SIZE: 1,
2250
+ BUY_CHUNK_SIZE: 1,
2251
+ SELL_CHUNK_SIZE: 1
2279
2252
  };
2280
2253
  var VALID_SIZE_PAIR = {
2281
2254
  3: { maxBufferSize: 8, maxDepth: 3 },
@@ -2645,8 +2618,8 @@ var SolanaConnector = class {
2645
2618
  name,
2646
2619
  tokenUri,
2647
2620
  totalSupply,
2648
- new import_bn2.default(1e5),
2649
- new import_bn2.default(1e7)
2621
+ new import_bn2.default(1e7),
2622
+ new import_bn2.default(1e9)
2650
2623
  ).accountsStrict({
2651
2624
  state: SOLANA_PUBKEYS.STATE_ID,
2652
2625
  collection: collectionPda2,
@@ -2710,29 +2683,28 @@ var SolanaConnector = class {
2710
2683
  if (!reserveToken || ((_a = reserveToken.mintAndBuy) == null ? void 0 : _a.length) === 0 && ((_b = reserveToken.buy) == null ? void 0 : _b.length) === 0) {
2711
2684
  throw new Error("No available token to buy");
2712
2685
  }
2713
- const lookupTableAccounts = yield this.getLookupTableAccounts(SOLANA_PUBKEYS.LOOKUP_TABLE);
2714
- console.log("========lookup Tables", lookupTableAccounts);
2715
- const instructionsChunks = [];
2686
+ const lookupTableAccounts = yield this.getLookupTableAccounts(
2687
+ SOLANA_PUBKEYS.LOOKUP_TABLE
2688
+ );
2689
+ let transactions = [];
2716
2690
  if ((_c = reserveToken.buy) == null ? void 0 : _c.length) {
2717
2691
  let assets = yield getAssetsInfo(reserveToken.buy, merkleTree);
2718
2692
  const sellTokens = (0, import_lodash2.sampleSize)(assets, reserveToken.buy.length);
2719
- console.log("=========", sellTokens);
2720
2693
  try {
2721
- const buyInstructionsChunks = yield this.getBuyInstructions(
2694
+ const txs = yield this.getBuyInstructions(
2722
2695
  this.config.wallet,
2723
2696
  collectionId,
2724
2697
  merkleTree,
2725
2698
  sellTokens
2726
2699
  );
2727
- instructionsChunks.push(...buyInstructionsChunks);
2728
- console.log("=========", buyInstructionsChunks);
2700
+ transactions.push(...txs);
2729
2701
  } catch (error) {
2730
2702
  console.error("Failed to getBuyInstructions", { error });
2731
2703
  }
2732
2704
  }
2733
2705
  if ((_d = reserveToken.mintAndBuy) == null ? void 0 : _d.length) {
2734
2706
  try {
2735
- const mintAndBuyInstructionsChunks = yield this.getMintAndBuyInstructions(
2707
+ const txs = yield this.getMintAndBuyInstructions(
2736
2708
  this.config.wallet,
2737
2709
  collectionId,
2738
2710
  creatorAddress,
@@ -2740,37 +2712,21 @@ var SolanaConnector = class {
2740
2712
  baseUri,
2741
2713
  new import_web35.PublicKey(merkleTree)
2742
2714
  );
2743
- instructionsChunks.push(...mintAndBuyInstructionsChunks);
2715
+ transactions.push(...txs);
2744
2716
  } catch (error) {
2745
2717
  console.error("Failed to getMintAndBuyInstructions", { error });
2746
2718
  }
2747
2719
  }
2748
- console.log("===instruction chunks===", instructionsChunks);
2749
2720
  let buyResponse = [];
2750
- for (const [instructions] of instructionsChunks) {
2751
- try {
2752
- const { signature, latestBlockhash } = yield this.sendTxn(instructions, lookupTableAccounts);
2753
- const confirmResult = yield this.config.provider.connection.confirmTransaction({
2754
- blockhash: latestBlockhash.blockhash,
2755
- lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
2756
- signature
2757
- });
2758
- console.log("confirmResult", confirmResult);
2759
- let transactionData = yield this.config.provider.connection.getTransaction(signature, {
2760
- commitment: "confirmed",
2761
- maxSupportedTransactionVersion: 0
2762
- });
2763
- if (transactionData) {
2764
- let itemBuyResponse = yield analyzeBuyTransaction(
2765
- this.program,
2766
- transactionData
2767
- );
2768
- buyResponse.push(...itemBuyResponse);
2769
- }
2770
- } catch (e) {
2771
- console.error("Buy failed:", JSON.stringify(e));
2772
- throw e;
2773
- }
2721
+ try {
2722
+ const { signatures, latestBlockhash } = yield this.sendTxnForBatch(
2723
+ transactions,
2724
+ lookupTableAccounts
2725
+ );
2726
+ console.log("signatures", signatures);
2727
+ } catch (e) {
2728
+ console.error("Buy failed:", JSON.stringify(e));
2729
+ throw e;
2774
2730
  }
2775
2731
  return buyResponse;
2776
2732
  });
@@ -2782,46 +2738,33 @@ var SolanaConnector = class {
2782
2738
  throw new Error("Program not initialized");
2783
2739
  }
2784
2740
  const { collectionId, ownedTokens, merkleTree } = params;
2785
- const lookupTableAccounts = yield this.getLookupTableAccounts(SOLANA_PUBKEYS.LOOKUP_TABLE);
2741
+ const lookupTableAccounts = yield this.getLookupTableAccounts(
2742
+ SOLANA_PUBKEYS.LOOKUP_TABLE
2743
+ );
2786
2744
  let assets = yield getAssetsInfo(ownedTokens, merkleTree);
2787
- let instructionsChunks = [];
2788
2745
  const sellTokens = (0, import_lodash2.sampleSize)(assets, ownedTokens.length);
2746
+ let transactions = [];
2789
2747
  try {
2790
- instructionsChunks = yield this.getSellInstructions(
2748
+ const txs = yield this.getSellInstructions(
2791
2749
  this.config.wallet,
2792
2750
  collectionId,
2793
2751
  merkleTree,
2794
2752
  sellTokens
2795
2753
  );
2754
+ transactions.push(...txs);
2796
2755
  } catch (error) {
2797
2756
  console.error("Failed to getSellInstructions", { error });
2798
2757
  throw error;
2799
2758
  }
2800
2759
  let sellResponse = [];
2801
- for (const [instructions, items] of instructionsChunks) {
2802
- try {
2803
- const { signature, latestBlockhash } = yield this.sendTxn(instructions, lookupTableAccounts);
2804
- const confirmResult = yield this.config.provider.connection.confirmTransaction({
2805
- blockhash: latestBlockhash.blockhash,
2806
- lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
2807
- signature
2808
- });
2809
- console.log("confirmResult", confirmResult);
2810
- let transactionData = yield this.config.provider.connection.getTransaction(signature, {
2811
- commitment: "confirmed",
2812
- maxSupportedTransactionVersion: 0
2813
- });
2814
- if (transactionData) {
2815
- let itemSellResponse = yield analyzeSellTransaction(
2816
- this.program,
2817
- transactionData
2818
- );
2819
- sellResponse.push(...itemSellResponse);
2820
- }
2821
- } catch (e) {
2822
- console.error("Flip failed:", JSON.stringify(e), { items });
2823
- throw e;
2824
- }
2760
+ try {
2761
+ const { signatures, latestBlockhash } = yield this.sendTxnForBatch(
2762
+ transactions,
2763
+ lookupTableAccounts
2764
+ );
2765
+ } catch (e) {
2766
+ console.error("Flip failed:", JSON.stringify(e));
2767
+ throw e;
2825
2768
  }
2826
2769
  return sellResponse;
2827
2770
  });
@@ -2832,52 +2775,36 @@ var SolanaConnector = class {
2832
2775
  if (!this.program) {
2833
2776
  throw new Error("Program not initialized");
2834
2777
  }
2835
- let instructionsChunks = [];
2836
- const lookupTableAccounts = yield this.getLookupTableAccounts(SOLANA_PUBKEYS.LOOKUP_TABLE);
2778
+ let transactions = [];
2779
+ const lookupTableAccounts = yield this.getLookupTableAccounts(
2780
+ SOLANA_PUBKEYS.LOOKUP_TABLE
2781
+ );
2837
2782
  for (const collectionId in data.data) {
2838
2783
  const items = data.data[collectionId];
2839
2784
  try {
2840
- console.log("items", items);
2841
- console.log("collectionId", collectionId);
2842
2785
  let assets = yield getAssetsInfo(items.tokenIds, items.merkleTree);
2843
2786
  const sellTokens = (0, import_lodash2.sampleSize)(assets, items.tokenIds.length);
2844
- let instructionsChunksItem = yield this.getSellInstructions(
2787
+ const txs = yield this.getSellInstructions(
2845
2788
  this.config.wallet,
2846
2789
  collectionId,
2847
2790
  items.merkleTree,
2848
2791
  sellTokens
2849
2792
  );
2850
- instructionsChunks.push(...instructionsChunksItem);
2793
+ transactions.push(...txs);
2851
2794
  } catch (error) {
2852
2795
  console.error("Failed to getSellInstructions", { error });
2853
2796
  throw error;
2854
2797
  }
2855
2798
  }
2856
2799
  let sellResponse = [];
2857
- for (const [instructions, items] of instructionsChunks) {
2858
- try {
2859
- const { signature, latestBlockhash } = yield this.sendTxn(instructions, lookupTableAccounts);
2860
- const confirmResult = yield this.config.provider.connection.confirmTransaction({
2861
- blockhash: latestBlockhash.blockhash,
2862
- lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
2863
- signature
2864
- });
2865
- console.log("confirmResult", confirmResult);
2866
- let transactionData = yield this.config.provider.connection.getTransaction(signature, {
2867
- commitment: "confirmed",
2868
- maxSupportedTransactionVersion: 0
2869
- });
2870
- if (transactionData) {
2871
- let itemSellResponse = yield analyzeSellTransaction(
2872
- this.program,
2873
- transactionData
2874
- );
2875
- sellResponse.push(...itemSellResponse);
2876
- }
2877
- } catch (e) {
2878
- console.error("Flip failed:", JSON.stringify(e), { items });
2879
- throw e;
2880
- }
2800
+ try {
2801
+ const { signatures, latestBlockhash } = yield this.sendTxnForBatch(
2802
+ transactions,
2803
+ lookupTableAccounts
2804
+ );
2805
+ } catch (e) {
2806
+ console.error("Flip failed:", JSON.stringify(e));
2807
+ throw e;
2881
2808
  }
2882
2809
  return sellResponse;
2883
2810
  });
@@ -3198,7 +3125,9 @@ var SolanaConnector = class {
3198
3125
  payerKey: this.config.wallet,
3199
3126
  recentBlockhash: latestBlockhash.blockhash,
3200
3127
  instructions
3201
- }).compileToV0Message(lookupTableAccounts == null ? [] : [lookupTableAccounts]);
3128
+ }).compileToV0Message(
3129
+ lookupTableAccounts == null ? [] : [lookupTableAccounts]
3130
+ );
3202
3131
  const tx = new import_web35.VersionedTransaction(messageV0);
3203
3132
  const sim = yield this.config.provider.connection.simulateTransaction(tx);
3204
3133
  console.log("simulation result == ", sim);
@@ -3213,6 +3142,44 @@ var SolanaConnector = class {
3213
3142
  };
3214
3143
  });
3215
3144
  }
3145
+ //useSenTxn.ts
3146
+ sendTxnForBatch(transactions, lookupTableAccounts) {
3147
+ return __async(this, null, function* () {
3148
+ if (!this.program) {
3149
+ console.error("Trade NFT failed: Insufficient data");
3150
+ throw new Error("Trade NFT failed: Insufficient data");
3151
+ }
3152
+ const latestBlockhash = yield this.config.provider.connection.getLatestBlockhash("confirmed");
3153
+ const payerKey = this.config.wallet;
3154
+ const txs = transactions.map((tx) => {
3155
+ const messageV0 = new import_web35.TransactionMessage({
3156
+ payerKey,
3157
+ recentBlockhash: latestBlockhash.blockhash,
3158
+ instructions: tx.instructions
3159
+ }).compileToV0Message(
3160
+ lookupTableAccounts == null ? [] : [lookupTableAccounts]
3161
+ );
3162
+ return new import_web35.VersionedTransaction(messageV0);
3163
+ });
3164
+ const signedTxs = yield this.config.signAllTransactions(txs);
3165
+ let signatures = yield Promise.all(
3166
+ signedTxs.map((signedTx) => __async(this, null, function* () {
3167
+ if (signedTx instanceof import_web35.VersionedTransaction) {
3168
+ let signature = yield this.config.provider.connection.sendTransaction(
3169
+ signedTx,
3170
+ { skipPreflight: true, preflightCommitment: "confirmed" }
3171
+ );
3172
+ return signature;
3173
+ }
3174
+ }))
3175
+ );
3176
+ console.log("Promise signatures ===============", signatures);
3177
+ return {
3178
+ signatures,
3179
+ latestBlockhash
3180
+ };
3181
+ });
3182
+ }
3216
3183
  getBuyInstructions(userPublicKey, collectionId, merkleTree, tokens) {
3217
3184
  return __async(this, null, function* () {
3218
3185
  if (!this.program) {
@@ -3225,8 +3192,8 @@ var SolanaConnector = class {
3225
3192
  const canopyDepth = merkleTreeAcount.getCanopyDepth();
3226
3193
  const chunkSize = SDK_SOLANA_CONFIG.SELL_CHUNK_SIZE;
3227
3194
  const tokenChunks = getTokenChunks(tokens, chunkSize);
3228
- const allInstructionSets = [];
3229
- const { treeConfigPda: treeConfigPda2, collectionPda: collectionPda2, nftHolderPda: nftHolderPda2, collectionNftPda: collectionNftPda2 } = yield getTradingAccounts(
3195
+ const transactions = [];
3196
+ const { treeConfigPda: treeConfigPda2, collectionPda: collectionPda2, nftHolderPda: nftHolderPda2 } = yield getTradingAccounts(
3230
3197
  collectionId,
3231
3198
  userPublicKey,
3232
3199
  this.program.programId,
@@ -3235,9 +3202,7 @@ var SolanaConnector = class {
3235
3202
  );
3236
3203
  try {
3237
3204
  for (const chunk of tokenChunks) {
3238
- const instructions = yield this.setUpInstructions(
3239
- 25e4 * chunk.length
3240
- );
3205
+ let transaction = yield this.setUpInstructions(14e5);
3241
3206
  for (const token of chunk) {
3242
3207
  const { compression, proof, root } = token;
3243
3208
  const proofPath = proof.map((node) => ({
@@ -3259,7 +3224,6 @@ var SolanaConnector = class {
3259
3224
  merkleTreeConfig: treeConfigPda2,
3260
3225
  merkleTree: new import_web35.PublicKey(merkleTree),
3261
3226
  collection: collectionPda2,
3262
- collectionNft: collectionNftPda2,
3263
3227
  treasury: SOLANA_PUBKEYS.TREASURY_ID,
3264
3228
  nftHolder: nftHolderPda2,
3265
3229
  buyer: userPublicKey,
@@ -3271,11 +3235,11 @@ var SolanaConnector = class {
3271
3235
  program: this.program.programId,
3272
3236
  eventAuthority: eventAuthority(this.program.programId)
3273
3237
  }).remainingAccounts(proofPath).instruction();
3274
- instructions.push(instruction);
3238
+ transaction.add(instruction);
3275
3239
  }
3276
- allInstructionSets.push([instructions]);
3240
+ transactions.push(transaction);
3277
3241
  }
3278
- return allInstructionSets;
3242
+ return transactions;
3279
3243
  } catch (e) {
3280
3244
  console.log("ERRORR in getBuyInstructions", JSON.stringify(e));
3281
3245
  throw e;
@@ -3294,7 +3258,7 @@ var SolanaConnector = class {
3294
3258
  const canopyDepth = merkleTreeAcount.getCanopyDepth();
3295
3259
  const chunkSize = SDK_SOLANA_CONFIG.SELL_CHUNK_SIZE;
3296
3260
  const tokenChunks = getTokenChunks(tokens, chunkSize);
3297
- const allInstructionSets = [];
3261
+ const transactions = [];
3298
3262
  const { treeConfigPda: treeConfigPda2, collectionPda: collectionPda2, nftHolderPda: nftHolderPda2, collectionNftPda: collectionNftPda2 } = yield getTradingAccounts(
3299
3263
  collectionId,
3300
3264
  userPublicKey,
@@ -3304,9 +3268,7 @@ var SolanaConnector = class {
3304
3268
  );
3305
3269
  try {
3306
3270
  for (const chunk of tokenChunks) {
3307
- const instructions = yield this.setUpInstructions(
3308
- 25e4 * chunk.length
3309
- );
3271
+ let transaction = yield this.setUpInstructions(14e5);
3310
3272
  for (const token of chunk) {
3311
3273
  const { compression, proof, root } = token;
3312
3274
  const proofPath = proof.map((node) => ({
@@ -3339,11 +3301,11 @@ var SolanaConnector = class {
3339
3301
  program: this.program.programId,
3340
3302
  eventAuthority: eventAuthority(this.program.programId)
3341
3303
  }).remainingAccounts(proofPath).instruction();
3342
- instructions.push(instruction);
3304
+ transaction.add(instruction);
3343
3305
  }
3344
- allInstructionSets.push([instructions, chunk]);
3306
+ transactions.push(transaction);
3345
3307
  }
3346
- return allInstructionSets;
3308
+ return transactions;
3347
3309
  } catch (e) {
3348
3310
  console.log("ERRORR in getBuyInstructions", JSON.stringify(e));
3349
3311
  throw e;
@@ -3363,7 +3325,7 @@ var SolanaConnector = class {
3363
3325
  }
3364
3326
  const chunkSize = SDK_SOLANA_CONFIG.MINT_CHUNK_SIZE;
3365
3327
  const tokenChunks = getTokenChunks(tokens, chunkSize);
3366
- const allInstructionSets = [];
3328
+ const transactions = [];
3367
3329
  const {
3368
3330
  treeConfigPda: treeConfigPda2,
3369
3331
  treeCreator,
@@ -3382,9 +3344,12 @@ var SolanaConnector = class {
3382
3344
  creatorAddress
3383
3345
  );
3384
3346
  try {
3385
- for (const chunk of tokenChunks) {
3386
- const instructions = yield this.setUpInstructions(14e5);
3387
- const instruction = yield this.program.methods.mintAndBuy(chunk, baseUri).accountsStrict({
3347
+ for (let index in tokenChunks) {
3348
+ console.log("index value", index);
3349
+ let chunk = tokenChunks[index];
3350
+ let nounce = new Number(index);
3351
+ let transaction = yield this.setUpInstructions(14e5);
3352
+ const instruction = yield this.program.methods.mintAndBuy(chunk, baseUri, nounce.valueOf()).accountsStrict({
3388
3353
  state: SOLANA_PUBKEYS.STATE_ID,
3389
3354
  merkleTreeConfig: treeConfigPda2,
3390
3355
  treeCreatorOrDelegate: treeCreator,
@@ -3406,10 +3371,10 @@ var SolanaConnector = class {
3406
3371
  eventAuthority: eventAuthority(this.program.programId),
3407
3372
  program: this.program.programId
3408
3373
  }).instruction();
3409
- instructions.push(instruction);
3410
- allInstructionSets.push([instructions]);
3374
+ transaction.add(instruction);
3375
+ transactions.push(transaction);
3411
3376
  }
3412
- return allInstructionSets;
3377
+ return transactions;
3413
3378
  } catch (e) {
3414
3379
  console.log("ERRORR in getMintAndBuyInstructions", JSON.stringify(e));
3415
3380
  throw e;
@@ -3430,7 +3395,7 @@ var SolanaConnector = class {
3430
3395
  setUpInstructions(computeUnits) {
3431
3396
  return __async(this, null, function* () {
3432
3397
  const microLamports = yield this.getPriorityFee();
3433
- const instructions = [];
3398
+ let transaction;
3434
3399
  const modifyComputeUnits = import_web35.ComputeBudgetProgram.setComputeUnitLimit({
3435
3400
  units: computeUnits
3436
3401
  });
@@ -3438,8 +3403,8 @@ var SolanaConnector = class {
3438
3403
  microLamports
3439
3404
  // TODO: get value from Quicknote api
3440
3405
  });
3441
- instructions.push(modifyComputeUnits, addPriorityFee);
3442
- return instructions;
3406
+ transaction = new import_web35.Transaction().add(modifyComputeUnits).add(addPriorityFee);
3407
+ return transaction;
3443
3408
  });
3444
3409
  }
3445
3410
  /**