@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.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
|
/* ------------------------------------------------------------------ */
|
|
@@ -3085,8 +3135,9 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
3085
3135
|
const config = await getConfig();
|
|
3086
3136
|
async function executeRequest() {
|
|
3087
3137
|
const authHeader = await createAuthHeader(config.isServer);
|
|
3088
|
-
const headers = Object.assign({
|
|
3089
|
-
if (typeof window !==
|
|
3138
|
+
const headers = Object.assign({ "Content-Type": "application/json", "X-Public-App-Id": config.appId, "X-App-Id": config.appId }, authHeader);
|
|
3139
|
+
if (typeof window !== "undefined" &&
|
|
3140
|
+
window.CUSTOM_TAROBASE_APP_ID_HEADER) {
|
|
3090
3141
|
const customAppId = window.CUSTOM_TAROBASE_APP_ID_HEADER;
|
|
3091
3142
|
if (customAppId) {
|
|
3092
3143
|
headers["X-App-Id"] = customAppId;
|
|
@@ -3096,12 +3147,17 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
3096
3147
|
if (_overrides === null || _overrides === void 0 ? void 0 : _overrides.headers) {
|
|
3097
3148
|
Object.assign(headers, _overrides.headers);
|
|
3098
3149
|
}
|
|
3150
|
+
// Signal to backend that client supports offchain transaction signing
|
|
3151
|
+
if (typeof window !== "undefined" &&
|
|
3152
|
+
window.TAROBASE_SUPPORTS_OFFCHAIN_SIGNING) {
|
|
3153
|
+
headers["X-Supports-Offchain-Signing"] = "true";
|
|
3154
|
+
}
|
|
3099
3155
|
const requestConfig = {
|
|
3100
3156
|
method,
|
|
3101
|
-
url: `${config.apiUrl}${urlPath.startsWith(
|
|
3157
|
+
url: `${config.apiUrl}${urlPath.startsWith("/") ? urlPath : `/${urlPath}`}`,
|
|
3102
3158
|
headers,
|
|
3103
3159
|
};
|
|
3104
|
-
if (method !==
|
|
3160
|
+
if (method !== "GET" && method !== "get") {
|
|
3105
3161
|
requestConfig.data = data ? JSON.stringify(data) : {};
|
|
3106
3162
|
}
|
|
3107
3163
|
const response = await axios(requestConfig);
|
|
@@ -3118,7 +3174,9 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
3118
3174
|
throw new Error("No refresh token found");
|
|
3119
3175
|
}
|
|
3120
3176
|
const refreshData = await refreshSession(refreshToken);
|
|
3121
|
-
if (refreshData &&
|
|
3177
|
+
if (refreshData &&
|
|
3178
|
+
refreshData.idToken &&
|
|
3179
|
+
refreshData.accessToken) {
|
|
3122
3180
|
updateIdTokenAndAccessToken(refreshData.idToken, refreshData.accessToken);
|
|
3123
3181
|
}
|
|
3124
3182
|
return await executeRequest();
|