@pooflabs/core 0.0.13 → 0.0.14

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.mjs CHANGED
@@ -1,9 +1,8 @@
1
1
  import axios from 'axios';
2
- import { ComputeBudgetProgram, PublicKey, Keypair, SystemProgram, TransactionInstruction } from '@solana/web3.js';
2
+ import { ComputeBudgetProgram, PublicKey, VersionedTransaction, TransactionMessage, Keypair, SystemProgram, TransactionInstruction } from '@solana/web3.js';
3
3
  import nacl from 'tweetnacl';
4
4
  import * as anchor from '@coral-xyz/anchor';
5
5
  import { Program } from '@coral-xyz/anchor';
6
- import { getSimulationComputeUnits } from '@solana-developers/helpers';
7
6
  import BN from 'bn.js';
8
7
  import ReconnectingWebSocket from 'reconnecting-websocket';
9
8
 
@@ -2785,6 +2784,57 @@ function requireBs58 () {
2785
2784
  var bs58Exports = requireBs58();
2786
2785
  var bs58 = /*@__PURE__*/getDefaultExportFromCjs(bs58Exports);
2787
2786
 
2787
+ // ─────────────────────────────────────────────────────────────
2788
+ // Local implementation of getSimulationComputeUnits
2789
+ // (Replaces @solana-developers/helpers to avoid Wallet import issue in browser/ESM builds)
2790
+ // Source: https://github.com/solana-developers/helpers/blob/main/src/lib/transaction.ts
2791
+ // ─────────────────────────────────────────────────────────────
2792
+ /**
2793
+ * Check if a given instruction is a SetComputeUnitLimit instruction
2794
+ * See https://github.com/solana-program/compute-budget/blob/main/clients/js/src/generated/programs/computeBudget.ts#L29
2795
+ */
2796
+ function isSetComputeLimitInstruction(ix) {
2797
+ return (ix.programId.equals(ComputeBudgetProgram.programId) &&
2798
+ ix.data[0] === 2 // opcode for setComputeUnitLimit is 2
2799
+ );
2800
+ }
2801
+ /**
2802
+ * Get the compute units required for a set of instructions via simulation.
2803
+ * Credit https://twitter.com/stegabob, originally from https://x.com/stegaBOB/status/1766662289392889920
2804
+ */
2805
+ async function getSimulationComputeUnits(connection, instructions, payer, lookupTables, commitment = "confirmed") {
2806
+ var _a, _b, _c;
2807
+ const simulationInstructions = [...instructions];
2808
+ // Replace or add compute limit instruction
2809
+ const computeLimitIndex = simulationInstructions.findIndex(isSetComputeLimitInstruction);
2810
+ const simulationLimitIx = ComputeBudgetProgram.setComputeUnitLimit({
2811
+ units: 1400000,
2812
+ });
2813
+ if (computeLimitIndex >= 0) {
2814
+ simulationInstructions[computeLimitIndex] = simulationLimitIx;
2815
+ }
2816
+ else {
2817
+ simulationInstructions.unshift(simulationLimitIx);
2818
+ }
2819
+ const testTransaction = new VersionedTransaction(new TransactionMessage({
2820
+ instructions: simulationInstructions,
2821
+ payerKey: payer,
2822
+ // RecentBlockhash can by any public key during simulation
2823
+ // since 'replaceRecentBlockhash' is set to 'true' below
2824
+ recentBlockhash: PublicKey.default.toString(),
2825
+ }).compileToV0Message(lookupTables));
2826
+ const rpcResponse = await connection.simulateTransaction(testTransaction, {
2827
+ replaceRecentBlockhash: true,
2828
+ sigVerify: false,
2829
+ commitment,
2830
+ });
2831
+ if ((_a = rpcResponse === null || rpcResponse === void 0 ? void 0 : rpcResponse.value) === null || _a === void 0 ? void 0 : _a.err) {
2832
+ const logs = ((_b = rpcResponse.value.logs) === null || _b === void 0 ? void 0 : _b.join("\n • ")) || "No logs available";
2833
+ throw new Error(`Transaction simulation failed:\n •${logs}` +
2834
+ JSON.stringify((_c = rpcResponse === null || rpcResponse === void 0 ? void 0 : rpcResponse.value) === null || _c === void 0 ? void 0 : _c.err));
2835
+ }
2836
+ return rpcResponse.value.unitsConsumed || null;
2837
+ }
2788
2838
  /* ------------------------------------------------------------------ */
2789
2839
  /* RFC-4501 message */
2790
2840
  /* ------------------------------------------------------------------ */
@@ -3100,7 +3150,6 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
3100
3150
  // Signal to backend that client supports offchain transaction signing
3101
3151
  if (typeof window !== "undefined" &&
3102
3152
  window.TAROBASE_SUPPORTS_OFFCHAIN_SIGNING) {
3103
- console.log("X-Supports-Offchain-Signing", "true");
3104
3153
  headers["X-Supports-Offchain-Signing"] = "true";
3105
3154
  }
3106
3155
  const requestConfig = {