@pooflabs/core 0.0.12 → 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.js +66 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -7
- package/dist/index.mjs.map +1 -1
- package/dist/utils/api.d.ts +1 -0
- package/package.json +1 -2
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
|
|
@@ -3105,8 +3155,9 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
3105
3155
|
const config = await getConfig();
|
|
3106
3156
|
async function executeRequest() {
|
|
3107
3157
|
const authHeader = await createAuthHeader(config.isServer);
|
|
3108
|
-
const headers = Object.assign({
|
|
3109
|
-
if (typeof window !==
|
|
3158
|
+
const headers = Object.assign({ "Content-Type": "application/json", "X-Public-App-Id": config.appId, "X-App-Id": config.appId }, authHeader);
|
|
3159
|
+
if (typeof window !== "undefined" &&
|
|
3160
|
+
window.CUSTOM_TAROBASE_APP_ID_HEADER) {
|
|
3110
3161
|
const customAppId = window.CUSTOM_TAROBASE_APP_ID_HEADER;
|
|
3111
3162
|
if (customAppId) {
|
|
3112
3163
|
headers["X-App-Id"] = customAppId;
|
|
@@ -3116,12 +3167,17 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
3116
3167
|
if (_overrides === null || _overrides === void 0 ? void 0 : _overrides.headers) {
|
|
3117
3168
|
Object.assign(headers, _overrides.headers);
|
|
3118
3169
|
}
|
|
3170
|
+
// Signal to backend that client supports offchain transaction signing
|
|
3171
|
+
if (typeof window !== "undefined" &&
|
|
3172
|
+
window.TAROBASE_SUPPORTS_OFFCHAIN_SIGNING) {
|
|
3173
|
+
headers["X-Supports-Offchain-Signing"] = "true";
|
|
3174
|
+
}
|
|
3119
3175
|
const requestConfig = {
|
|
3120
3176
|
method,
|
|
3121
|
-
url: `${config.apiUrl}${urlPath.startsWith(
|
|
3177
|
+
url: `${config.apiUrl}${urlPath.startsWith("/") ? urlPath : `/${urlPath}`}`,
|
|
3122
3178
|
headers,
|
|
3123
3179
|
};
|
|
3124
|
-
if (method !==
|
|
3180
|
+
if (method !== "GET" && method !== "get") {
|
|
3125
3181
|
requestConfig.data = data ? JSON.stringify(data) : {};
|
|
3126
3182
|
}
|
|
3127
3183
|
const response = await axios(requestConfig);
|
|
@@ -3138,7 +3194,9 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
3138
3194
|
throw new Error("No refresh token found");
|
|
3139
3195
|
}
|
|
3140
3196
|
const refreshData = await refreshSession(refreshToken);
|
|
3141
|
-
if (refreshData &&
|
|
3197
|
+
if (refreshData &&
|
|
3198
|
+
refreshData.idToken &&
|
|
3199
|
+
refreshData.accessToken) {
|
|
3142
3200
|
updateIdTokenAndAccessToken(refreshData.idToken, refreshData.accessToken);
|
|
3143
3201
|
}
|
|
3144
3202
|
return await executeRequest();
|