@pooflabs/core 0.0.13 → 0.0.15
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/client/config.d.ts +6 -0
- package/dist/index.js +53 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/client/config.d.ts
CHANGED
|
@@ -17,6 +17,12 @@ export interface ClientConfig {
|
|
|
17
17
|
appId: string;
|
|
18
18
|
config: any;
|
|
19
19
|
};
|
|
20
|
+
phantomConfig?: {
|
|
21
|
+
appId?: string;
|
|
22
|
+
providers?: Array<'injected' | 'google' | 'apple' | 'deeplink'>;
|
|
23
|
+
redirectUrl?: string;
|
|
24
|
+
autoConnect?: boolean;
|
|
25
|
+
};
|
|
20
26
|
mockAuth?: boolean;
|
|
21
27
|
}
|
|
22
28
|
export declare let clientConfig: ClientConfig;
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ var axios = require('axios');
|
|
|
4
4
|
var web3_js = require('@solana/web3.js');
|
|
5
5
|
var nacl = require('tweetnacl');
|
|
6
6
|
var anchor = require('@coral-xyz/anchor');
|
|
7
|
-
var helpers = require('@solana-developers/helpers');
|
|
8
7
|
var BN = require('bn.js');
|
|
9
8
|
var ReconnectingWebSocket = require('reconnecting-websocket');
|
|
10
9
|
|
|
@@ -2805,6 +2804,57 @@ function requireBs58 () {
|
|
|
2805
2804
|
var bs58Exports = requireBs58();
|
|
2806
2805
|
var bs58 = /*@__PURE__*/getDefaultExportFromCjs(bs58Exports);
|
|
2807
2806
|
|
|
2807
|
+
// ─────────────────────────────────────────────────────────────
|
|
2808
|
+
// Local implementation of getSimulationComputeUnits
|
|
2809
|
+
// (Replaces @solana-developers/helpers to avoid Wallet import issue in browser/ESM builds)
|
|
2810
|
+
// Source: https://github.com/solana-developers/helpers/blob/main/src/lib/transaction.ts
|
|
2811
|
+
// ─────────────────────────────────────────────────────────────
|
|
2812
|
+
/**
|
|
2813
|
+
* Check if a given instruction is a SetComputeUnitLimit instruction
|
|
2814
|
+
* See https://github.com/solana-program/compute-budget/blob/main/clients/js/src/generated/programs/computeBudget.ts#L29
|
|
2815
|
+
*/
|
|
2816
|
+
function isSetComputeLimitInstruction(ix) {
|
|
2817
|
+
return (ix.programId.equals(web3_js.ComputeBudgetProgram.programId) &&
|
|
2818
|
+
ix.data[0] === 2 // opcode for setComputeUnitLimit is 2
|
|
2819
|
+
);
|
|
2820
|
+
}
|
|
2821
|
+
/**
|
|
2822
|
+
* Get the compute units required for a set of instructions via simulation.
|
|
2823
|
+
* Credit https://twitter.com/stegabob, originally from https://x.com/stegaBOB/status/1766662289392889920
|
|
2824
|
+
*/
|
|
2825
|
+
async function getSimulationComputeUnits(connection, instructions, payer, lookupTables, commitment = "confirmed") {
|
|
2826
|
+
var _a, _b, _c;
|
|
2827
|
+
const simulationInstructions = [...instructions];
|
|
2828
|
+
// Replace or add compute limit instruction
|
|
2829
|
+
const computeLimitIndex = simulationInstructions.findIndex(isSetComputeLimitInstruction);
|
|
2830
|
+
const simulationLimitIx = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2831
|
+
units: 1400000,
|
|
2832
|
+
});
|
|
2833
|
+
if (computeLimitIndex >= 0) {
|
|
2834
|
+
simulationInstructions[computeLimitIndex] = simulationLimitIx;
|
|
2835
|
+
}
|
|
2836
|
+
else {
|
|
2837
|
+
simulationInstructions.unshift(simulationLimitIx);
|
|
2838
|
+
}
|
|
2839
|
+
const testTransaction = new web3_js.VersionedTransaction(new web3_js.TransactionMessage({
|
|
2840
|
+
instructions: simulationInstructions,
|
|
2841
|
+
payerKey: payer,
|
|
2842
|
+
// RecentBlockhash can by any public key during simulation
|
|
2843
|
+
// since 'replaceRecentBlockhash' is set to 'true' below
|
|
2844
|
+
recentBlockhash: web3_js.PublicKey.default.toString(),
|
|
2845
|
+
}).compileToV0Message(lookupTables));
|
|
2846
|
+
const rpcResponse = await connection.simulateTransaction(testTransaction, {
|
|
2847
|
+
replaceRecentBlockhash: true,
|
|
2848
|
+
sigVerify: false,
|
|
2849
|
+
commitment,
|
|
2850
|
+
});
|
|
2851
|
+
if ((_a = rpcResponse === null || rpcResponse === void 0 ? void 0 : rpcResponse.value) === null || _a === void 0 ? void 0 : _a.err) {
|
|
2852
|
+
const logs = ((_b = rpcResponse.value.logs) === null || _b === void 0 ? void 0 : _b.join("\n • ")) || "No logs available";
|
|
2853
|
+
throw new Error(`Transaction simulation failed:\n •${logs}` +
|
|
2854
|
+
JSON.stringify((_c = rpcResponse === null || rpcResponse === void 0 ? void 0 : rpcResponse.value) === null || _c === void 0 ? void 0 : _c.err));
|
|
2855
|
+
}
|
|
2856
|
+
return rpcResponse.value.unitsConsumed || null;
|
|
2857
|
+
}
|
|
2808
2858
|
/* ------------------------------------------------------------------ */
|
|
2809
2859
|
/* RFC-4501 message */
|
|
2810
2860
|
/* ------------------------------------------------------------------ */
|
|
@@ -2952,7 +3002,7 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
|
|
|
2952
3002
|
tx.recentBlockhash = blockhash;
|
|
2953
3003
|
if (lutKey == null) {
|
|
2954
3004
|
const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
|
|
2955
|
-
const computeUnits = isSurfnet ? 1400000 : await
|
|
3005
|
+
const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, []);
|
|
2956
3006
|
const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2957
3007
|
units: computeUnits ? computeUnits * 1.2 : 1400000,
|
|
2958
3008
|
}); // 20% buffer
|
|
@@ -2963,7 +3013,7 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
|
|
|
2963
3013
|
if (!table)
|
|
2964
3014
|
throw new Error('LUT not found after creation/extend');
|
|
2965
3015
|
const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
|
|
2966
|
-
const computeUnits = isSurfnet ? 1400000 : await
|
|
3016
|
+
const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, [table]);
|
|
2967
3017
|
const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2968
3018
|
units: computeUnits ? computeUnits * 1.2 : 1400000,
|
|
2969
3019
|
}); // 20% buffer
|
|
@@ -3120,7 +3170,6 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
3120
3170
|
// Signal to backend that client supports offchain transaction signing
|
|
3121
3171
|
if (typeof window !== "undefined" &&
|
|
3122
3172
|
window.TAROBASE_SUPPORTS_OFFCHAIN_SIGNING) {
|
|
3123
|
-
console.log("X-Supports-Offchain-Signing", "true");
|
|
3124
3173
|
headers["X-Supports-Offchain-Signing"] = "true";
|
|
3125
3174
|
}
|
|
3126
3175
|
const requestConfig = {
|