@solana/web3-compat 0.0.0 → 0.0.2
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/README.md +112 -0
- package/dist/index.browser.cjs +449 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.mjs +419 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.native.mjs +419 -0
- package/dist/index.native.mjs.map +1 -0
- package/dist/index.node.cjs +449 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +419 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/types/bridges.d.ts +14 -0
- package/dist/types/bridges.d.ts.map +1 -0
- package/dist/types/connection.d.ts +60 -0
- package/dist/types/connection.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/programs/system-program.d.ts +12 -0
- package/dist/types/programs/system-program.d.ts.map +1 -0
- package/dist/types/utils.d.ts +10 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +74 -8
- package/.bash_logout +0 -7
- package/.bashrc +0 -113
- package/.npm/_logs/2025-11-24T16_37_30_908Z-debug-0.log +0 -16
- package/.npm/_logs/2025-11-24T16_37_35_916Z-debug-0.log +0 -38
- package/.npm/_logs/2025-11-24T16_37_55_789Z-debug-0.log +0 -26
- package/.npm/_logs/2025-11-24T16_39_55_944Z-debug-0.log +0 -13
- package/.npm/_update-notifier-last-checked +0 -0
- package/.profile +0 -27
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# `@solana/web3-compat`
|
|
2
|
+
|
|
3
|
+
Phase 0 of a backwards‑compatible surface that lets existing `@solana/web3.js`
|
|
4
|
+
code run on top of Kit primitives.
|
|
5
|
+
|
|
6
|
+
This package is designed to help migrate from web3.js to Kit.
|
|
7
|
+
|
|
8
|
+
The goal of this release is **zero breaking changes** for applications that only
|
|
9
|
+
touch the subset of web3.js APIs listed below. There will be future releases that slowly
|
|
10
|
+
implement breaking changes as they move over to Kit primitives and intuitions.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @solana/web3-compat
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Your project must also have valid Kit peer dependencies (`@solana/kit`,
|
|
19
|
+
`@solana/client`, etc.).
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
In Phase 0, you should be able to leave your web3.js code as-is.
|
|
24
|
+
|
|
25
|
+
The compatibility layer mirrors the web3.js entry points:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import {
|
|
29
|
+
Connection,
|
|
30
|
+
Keypair,
|
|
31
|
+
PublicKey,
|
|
32
|
+
SystemProgram,
|
|
33
|
+
sendAndConfirmTransaction,
|
|
34
|
+
} from "@solana/web3-compat";
|
|
35
|
+
|
|
36
|
+
const connection = new Connection(
|
|
37
|
+
"https://api.mainnet-beta.solana.com",
|
|
38
|
+
"confirmed"
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const payer = Keypair.generate();
|
|
42
|
+
const recipient = Keypair.generate().publicKey;
|
|
43
|
+
|
|
44
|
+
const transferIx = SystemProgram.transfer({
|
|
45
|
+
fromPubkey: payer.publicKey,
|
|
46
|
+
toPubkey: recipient,
|
|
47
|
+
lamports: 1_000_000,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const transaction = new Transaction().add(transferIx);
|
|
51
|
+
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
52
|
+
transaction.feePayer = payer.publicKey;
|
|
53
|
+
|
|
54
|
+
await sendAndConfirmTransaction(connection, transaction, [payer]);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Under the hood every RPC call goes through Kit via `@solana/client`, but currently
|
|
58
|
+
the surface area, return types, and error semantics stay aligned with
|
|
59
|
+
`@solana/web3.js`.
|
|
60
|
+
|
|
61
|
+
## Implemented in Phase 0
|
|
62
|
+
|
|
63
|
+
- `Connection` backed by Kit with support for:
|
|
64
|
+
- `getLatestBlockhash`
|
|
65
|
+
- `getBalance`
|
|
66
|
+
- `getAccountInfo`
|
|
67
|
+
- `getProgramAccounts`
|
|
68
|
+
- `getSignatureStatuses`
|
|
69
|
+
- `sendRawTransaction`
|
|
70
|
+
- `confirmTransaction`
|
|
71
|
+
- `simulateTransaction`
|
|
72
|
+
- Bridge helpers re-exported from `@solana/compat`:
|
|
73
|
+
- `toAddress`, `toPublicKey`, `toWeb3Instruction`, `toKitSigner`
|
|
74
|
+
- Programs:
|
|
75
|
+
- `SystemProgram.transfer` (manual u8/u64 little‑endian encoding)
|
|
76
|
+
- Utilities:
|
|
77
|
+
- `LAMPORTS_PER_SOL`
|
|
78
|
+
- `compileFromCompat`
|
|
79
|
+
- `sendAndConfirmTransaction`
|
|
80
|
+
- Re‑exports of all Web3 primitives (`PublicKey`, `Keypair`, `Transaction`,
|
|
81
|
+
`VersionedTransaction`, `TransactionInstruction`, etc)
|
|
82
|
+
|
|
83
|
+
## Running tests
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pnpm --filter @solana/web3-compat test
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Examples
|
|
90
|
+
|
|
91
|
+
We've included some examples that are directly taken from Solana project code (eg `explorer`). We'll keep
|
|
92
|
+
updating these throughout the phases.
|
|
93
|
+
|
|
94
|
+
## Known limitations & edge cases
|
|
95
|
+
|
|
96
|
+
Phase 0 does not fully replace web3.js. Notable gaps:
|
|
97
|
+
|
|
98
|
+
- Only the Connection methods listed above are implemented. Any other Web3 call
|
|
99
|
+
(e.g. `getTransaction`, subscriptions, `requestAirdrop`) still needs the
|
|
100
|
+
legacy connection for now
|
|
101
|
+
- `getProgramAccounts` currently returns just the value array even when
|
|
102
|
+
`withContext: true` is supplied
|
|
103
|
+
- Account data is decoded from `base64` only. Other encodings such as
|
|
104
|
+
`jsonParsed` or `base64+zstd` are passed through to Kit but not post‑processed
|
|
105
|
+
- Numeric fields are coerced to JavaScript `number`s to match Web3 behaviour,
|
|
106
|
+
which means values above `Number.MAX_SAFE_INTEGER` will lose precision (which is how it
|
|
107
|
+
currently works)
|
|
108
|
+
- The compatibility layer does not yet try to normalise websocket connection
|
|
109
|
+
options or retry policies that web3.js exposes
|
|
110
|
+
|
|
111
|
+
Future phases will expand coverage and introduce intentional
|
|
112
|
+
breaking changes once users have an easy migration path.
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var web3_js = require('@solana/web3.js');
|
|
4
|
+
var compat = require('@solana/compat');
|
|
5
|
+
var kit = require('@solana/kit');
|
|
6
|
+
var client = require('@solana/client');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
function toAddress(input) {
|
|
11
|
+
const pubkey = input instanceof web3_js.PublicKey ? input : new web3_js.PublicKey(input);
|
|
12
|
+
return compat.fromLegacyPublicKey(pubkey);
|
|
13
|
+
}
|
|
14
|
+
__name(toAddress, "toAddress");
|
|
15
|
+
function toPublicKey(input) {
|
|
16
|
+
if (input instanceof web3_js.PublicKey) {
|
|
17
|
+
return input;
|
|
18
|
+
}
|
|
19
|
+
if (typeof input === "string") {
|
|
20
|
+
return new web3_js.PublicKey(input);
|
|
21
|
+
}
|
|
22
|
+
return new web3_js.PublicKey(input);
|
|
23
|
+
}
|
|
24
|
+
__name(toPublicKey, "toPublicKey");
|
|
25
|
+
async function toKitSigner(keypair, config = {}) {
|
|
26
|
+
const secretKey = new Uint8Array(64);
|
|
27
|
+
secretKey.set(keypair.secretKey);
|
|
28
|
+
secretKey.set(keypair.publicKey.toBytes(), 32);
|
|
29
|
+
return await kit.createKeyPairSignerFromBytes(secretKey, config.extractable ?? false);
|
|
30
|
+
}
|
|
31
|
+
__name(toKitSigner, "toKitSigner");
|
|
32
|
+
function toWeb3Instruction(kitInstruction) {
|
|
33
|
+
const keys = kitInstruction.accounts?.map((account) => {
|
|
34
|
+
const role = account.role;
|
|
35
|
+
const isSigner = role === kit.AccountRole.READONLY_SIGNER || role === kit.AccountRole.WRITABLE_SIGNER;
|
|
36
|
+
const isWritable = role === kit.AccountRole.WRITABLE || role === kit.AccountRole.WRITABLE_SIGNER;
|
|
37
|
+
return {
|
|
38
|
+
isSigner,
|
|
39
|
+
isWritable,
|
|
40
|
+
pubkey: toPublicKey(account.address)
|
|
41
|
+
};
|
|
42
|
+
}) ?? [];
|
|
43
|
+
const data = kitInstruction.data ? Buffer.from(kitInstruction.data) : Buffer.alloc(0);
|
|
44
|
+
return new web3_js.TransactionInstruction({
|
|
45
|
+
data,
|
|
46
|
+
keys,
|
|
47
|
+
programId: toPublicKey(kitInstruction.programAddress)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
__name(toWeb3Instruction, "toWeb3Instruction");
|
|
51
|
+
function fromWeb3Instruction(legacyInstruction) {
|
|
52
|
+
return compat.fromLegacyTransactionInstruction(legacyInstruction);
|
|
53
|
+
}
|
|
54
|
+
__name(fromWeb3Instruction, "fromWeb3Instruction");
|
|
55
|
+
var DEFAULT_COMMITMENT = "confirmed";
|
|
56
|
+
var DEFAULT_SIMULATION_CONFIG = Object.freeze({
|
|
57
|
+
encoding: "base64",
|
|
58
|
+
replaceRecentBlockhash: true,
|
|
59
|
+
sigVerify: false
|
|
60
|
+
});
|
|
61
|
+
function normalizeCommitment(commitment) {
|
|
62
|
+
if (commitment === void 0 || commitment === null) {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
if (commitment === "recent") {
|
|
66
|
+
return "processed";
|
|
67
|
+
}
|
|
68
|
+
if (commitment === "singleGossip") {
|
|
69
|
+
return "processed";
|
|
70
|
+
}
|
|
71
|
+
if (commitment === "single") {
|
|
72
|
+
return "confirmed";
|
|
73
|
+
}
|
|
74
|
+
if (commitment === "max") {
|
|
75
|
+
return "finalized";
|
|
76
|
+
}
|
|
77
|
+
return commitment;
|
|
78
|
+
}
|
|
79
|
+
__name(normalizeCommitment, "normalizeCommitment");
|
|
80
|
+
function toBigInt(value) {
|
|
81
|
+
if (value === void 0) return void 0;
|
|
82
|
+
return typeof value === "bigint" ? value : BigInt(Math.trunc(value));
|
|
83
|
+
}
|
|
84
|
+
__name(toBigInt, "toBigInt");
|
|
85
|
+
function toAccountInfo(info, dataSlice) {
|
|
86
|
+
const { data, executable, lamports, owner, rentEpoch } = info;
|
|
87
|
+
const [content, encoding] = Array.isArray(data) ? data : [data, "base64"];
|
|
88
|
+
let buffer = encoding === "base64" ? Buffer.from(content, "base64") : Buffer.from(content);
|
|
89
|
+
if (dataSlice) {
|
|
90
|
+
const start = dataSlice.offset ?? 0;
|
|
91
|
+
const end = start + (dataSlice.length ?? buffer.length);
|
|
92
|
+
buffer = buffer.subarray(start, end);
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
data: buffer,
|
|
96
|
+
executable,
|
|
97
|
+
lamports: typeof lamports === "number" ? lamports : Number(lamports),
|
|
98
|
+
owner: new web3_js.PublicKey(owner),
|
|
99
|
+
rentEpoch: typeof rentEpoch === "number" ? rentEpoch : Number(rentEpoch)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
__name(toAccountInfo, "toAccountInfo");
|
|
103
|
+
function fromKitAccount(value) {
|
|
104
|
+
const account = value ?? {};
|
|
105
|
+
const data = account.data;
|
|
106
|
+
const lamports = account.lamports;
|
|
107
|
+
const ownerValue = account.owner;
|
|
108
|
+
const rentEpoch = account.rentEpoch;
|
|
109
|
+
const owner = typeof ownerValue === "string" ? ownerValue : ownerValue instanceof web3_js.PublicKey ? ownerValue.toBase58() : typeof ownerValue === "object" && ownerValue !== null && "toString" in ownerValue ? String(ownerValue) : "11111111111111111111111111111111";
|
|
110
|
+
return {
|
|
111
|
+
data: data ?? ["", "base64"],
|
|
112
|
+
executable: Boolean(account.executable),
|
|
113
|
+
lamports: lamports ?? 0,
|
|
114
|
+
owner,
|
|
115
|
+
rentEpoch: rentEpoch ?? 0
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
__name(fromKitAccount, "fromKitAccount");
|
|
119
|
+
function toKitAddressFromInput(input) {
|
|
120
|
+
return toAddress(input instanceof web3_js.PublicKey ? input : input);
|
|
121
|
+
}
|
|
122
|
+
__name(toKitAddressFromInput, "toKitAddressFromInput");
|
|
123
|
+
function toBase64WireTransaction(raw) {
|
|
124
|
+
if (raw instanceof web3_js.Transaction || raw instanceof web3_js.VersionedTransaction) {
|
|
125
|
+
const bytes = raw.serialize({
|
|
126
|
+
requireAllSignatures: false,
|
|
127
|
+
verifySignatures: false
|
|
128
|
+
});
|
|
129
|
+
return Buffer.from(bytes).toString("base64");
|
|
130
|
+
}
|
|
131
|
+
if (raw instanceof Uint8Array) {
|
|
132
|
+
return Buffer.from(raw).toString("base64");
|
|
133
|
+
}
|
|
134
|
+
if (raw instanceof Buffer) {
|
|
135
|
+
return raw.toString("base64");
|
|
136
|
+
}
|
|
137
|
+
const uint8 = Uint8Array.from(raw);
|
|
138
|
+
return Buffer.from(uint8).toString("base64");
|
|
139
|
+
}
|
|
140
|
+
__name(toBase64WireTransaction, "toBase64WireTransaction");
|
|
141
|
+
var Connection = class {
|
|
142
|
+
static {
|
|
143
|
+
__name(this, "Connection");
|
|
144
|
+
}
|
|
145
|
+
commitment;
|
|
146
|
+
rpcEndpoint;
|
|
147
|
+
#client;
|
|
148
|
+
constructor(endpoint, commitmentOrConfig) {
|
|
149
|
+
const commitment = typeof commitmentOrConfig === "string" ? normalizeCommitment(commitmentOrConfig) : normalizeCommitment(commitmentOrConfig?.commitment) ?? DEFAULT_COMMITMENT;
|
|
150
|
+
const websocketEndpoint = typeof commitmentOrConfig === "object" && commitmentOrConfig !== null ? commitmentOrConfig.wsEndpoint : void 0;
|
|
151
|
+
this.commitment = commitment;
|
|
152
|
+
this.rpcEndpoint = endpoint;
|
|
153
|
+
this.#client = client.createSolanaRpcClient({
|
|
154
|
+
endpoint,
|
|
155
|
+
websocketEndpoint,
|
|
156
|
+
commitment: commitment ?? DEFAULT_COMMITMENT
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
async getLatestBlockhash(commitmentOrConfig) {
|
|
160
|
+
const baseCommitment = typeof commitmentOrConfig === "string" ? commitmentOrConfig : commitmentOrConfig?.commitment;
|
|
161
|
+
const commitment = normalizeCommitment(baseCommitment) ?? this.commitment ?? DEFAULT_COMMITMENT;
|
|
162
|
+
const minContextSlot = typeof commitmentOrConfig === "object" ? toBigInt(commitmentOrConfig.minContextSlot) : void 0;
|
|
163
|
+
const requestOptions = {
|
|
164
|
+
commitment
|
|
165
|
+
};
|
|
166
|
+
if (minContextSlot !== void 0) {
|
|
167
|
+
requestOptions.minContextSlot = minContextSlot;
|
|
168
|
+
}
|
|
169
|
+
if (typeof commitmentOrConfig === "object" && commitmentOrConfig?.maxSupportedTransactionVersion !== void 0) {
|
|
170
|
+
requestOptions.maxSupportedTransactionVersion = commitmentOrConfig.maxSupportedTransactionVersion;
|
|
171
|
+
}
|
|
172
|
+
const response = await this.#client.rpc.getLatestBlockhash(requestOptions).send();
|
|
173
|
+
return {
|
|
174
|
+
blockhash: response.value.blockhash,
|
|
175
|
+
lastValidBlockHeight: Number(response.value.lastValidBlockHeight)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
async getBalance(publicKey, commitment) {
|
|
179
|
+
const address = toKitAddressFromInput(publicKey);
|
|
180
|
+
const chosenCommitment = normalizeCommitment(commitment) ?? this.commitment ?? DEFAULT_COMMITMENT;
|
|
181
|
+
const result = await this.#client.rpc.getBalance(address, { commitment: chosenCommitment }).send();
|
|
182
|
+
return typeof result.value === "number" ? result.value : Number(result.value);
|
|
183
|
+
}
|
|
184
|
+
async getAccountInfo(publicKey, commitmentOrConfig) {
|
|
185
|
+
const address = toKitAddressFromInput(publicKey);
|
|
186
|
+
let localCommitment;
|
|
187
|
+
let minContextSlot;
|
|
188
|
+
let dataSlice;
|
|
189
|
+
let encoding;
|
|
190
|
+
if (typeof commitmentOrConfig === "string") {
|
|
191
|
+
localCommitment = normalizeCommitment(commitmentOrConfig);
|
|
192
|
+
} else if (commitmentOrConfig) {
|
|
193
|
+
localCommitment = normalizeCommitment(commitmentOrConfig.commitment);
|
|
194
|
+
if (commitmentOrConfig.minContextSlot !== void 0) {
|
|
195
|
+
minContextSlot = toBigInt(commitmentOrConfig.minContextSlot);
|
|
196
|
+
}
|
|
197
|
+
dataSlice = commitmentOrConfig.dataSlice;
|
|
198
|
+
encoding = commitmentOrConfig.encoding;
|
|
199
|
+
}
|
|
200
|
+
const requestOptions = {
|
|
201
|
+
commitment: localCommitment ?? this.commitment ?? DEFAULT_COMMITMENT
|
|
202
|
+
};
|
|
203
|
+
if (minContextSlot !== void 0) {
|
|
204
|
+
requestOptions.minContextSlot = minContextSlot;
|
|
205
|
+
}
|
|
206
|
+
if (encoding) {
|
|
207
|
+
requestOptions.encoding = encoding;
|
|
208
|
+
}
|
|
209
|
+
if (dataSlice) {
|
|
210
|
+
requestOptions.dataSlice = {
|
|
211
|
+
length: dataSlice.length,
|
|
212
|
+
offset: dataSlice.offset
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const response = await this.#client.rpc.getAccountInfo(address, requestOptions).send();
|
|
216
|
+
if (!response.value) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
const accountInfo = toAccountInfo(fromKitAccount(response.value), dataSlice);
|
|
220
|
+
return accountInfo;
|
|
221
|
+
}
|
|
222
|
+
async getProgramAccounts(programId, commitmentOrConfig) {
|
|
223
|
+
const id = toKitAddressFromInput(programId);
|
|
224
|
+
let localCommitment;
|
|
225
|
+
let dataSlice;
|
|
226
|
+
let filters;
|
|
227
|
+
let encoding;
|
|
228
|
+
let minContextSlot;
|
|
229
|
+
let withContext = false;
|
|
230
|
+
if (typeof commitmentOrConfig === "string") {
|
|
231
|
+
localCommitment = normalizeCommitment(commitmentOrConfig);
|
|
232
|
+
} else if (commitmentOrConfig) {
|
|
233
|
+
localCommitment = normalizeCommitment(commitmentOrConfig.commitment);
|
|
234
|
+
dataSlice = commitmentOrConfig.dataSlice;
|
|
235
|
+
filters = commitmentOrConfig.filters;
|
|
236
|
+
encoding = commitmentOrConfig.encoding;
|
|
237
|
+
minContextSlot = toBigInt(commitmentOrConfig.minContextSlot);
|
|
238
|
+
withContext = Boolean(commitmentOrConfig.withContext);
|
|
239
|
+
}
|
|
240
|
+
const requestOptions = {
|
|
241
|
+
commitment: localCommitment ?? this.commitment ?? DEFAULT_COMMITMENT,
|
|
242
|
+
withContext
|
|
243
|
+
};
|
|
244
|
+
if (dataSlice) {
|
|
245
|
+
requestOptions.dataSlice = {
|
|
246
|
+
length: dataSlice.length,
|
|
247
|
+
offset: dataSlice.offset
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (encoding) {
|
|
251
|
+
requestOptions.encoding = encoding;
|
|
252
|
+
}
|
|
253
|
+
if (filters) {
|
|
254
|
+
requestOptions.filters = filters.map((filter) => filter);
|
|
255
|
+
}
|
|
256
|
+
if (minContextSlot !== void 0) {
|
|
257
|
+
requestOptions.minContextSlot = minContextSlot;
|
|
258
|
+
}
|
|
259
|
+
const result = await this.#client.rpc.getProgramAccounts(id, requestOptions).send();
|
|
260
|
+
const mapProgramAccount = /* @__PURE__ */ __name((entry) => {
|
|
261
|
+
const pubkey = new web3_js.PublicKey(entry.pubkey);
|
|
262
|
+
return {
|
|
263
|
+
account: toAccountInfo(fromKitAccount(entry.account), dataSlice),
|
|
264
|
+
pubkey
|
|
265
|
+
};
|
|
266
|
+
}, "mapProgramAccount");
|
|
267
|
+
if (withContext && typeof result.context !== "undefined") {
|
|
268
|
+
const contextual = result;
|
|
269
|
+
return {
|
|
270
|
+
context: {
|
|
271
|
+
apiVersion: contextual.context.apiVersion,
|
|
272
|
+
slot: Number(contextual.context.slot)
|
|
273
|
+
},
|
|
274
|
+
value: contextual.value.map(mapProgramAccount)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
return result.map(mapProgramAccount);
|
|
278
|
+
}
|
|
279
|
+
async getSignatureStatuses(signatures, config) {
|
|
280
|
+
const targetCommitment = normalizeCommitment(config?.commitment) ?? this.commitment ?? DEFAULT_COMMITMENT;
|
|
281
|
+
const kitSignatures = signatures.map((signature) => signature);
|
|
282
|
+
const response = await this.#client.rpc.getSignatureStatuses(kitSignatures, {
|
|
283
|
+
commitment: targetCommitment,
|
|
284
|
+
searchTransactionHistory: config?.searchTransactionHistory
|
|
285
|
+
}).send();
|
|
286
|
+
const context = response.context;
|
|
287
|
+
const normalizedContext = {
|
|
288
|
+
apiVersion: context?.apiVersion,
|
|
289
|
+
slot: typeof context?.slot === "bigint" ? Number(context.slot) : context?.slot ?? 0
|
|
290
|
+
};
|
|
291
|
+
const normalizedValues = response.value.map(
|
|
292
|
+
(status) => {
|
|
293
|
+
if (!status) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
const record = status;
|
|
297
|
+
const slot = record.slot;
|
|
298
|
+
const confirmations = record.confirmations;
|
|
299
|
+
const normalizedConfirmations = confirmations === null ? null : confirmations === void 0 ? null : typeof confirmations === "bigint" ? Number(confirmations) : confirmations;
|
|
300
|
+
return {
|
|
301
|
+
err: record.err ?? null,
|
|
302
|
+
confirmations: normalizedConfirmations,
|
|
303
|
+
confirmationStatus: record.confirmationStatus,
|
|
304
|
+
slot: slot === void 0 ? 0 : typeof slot === "bigint" ? Number(slot) : slot
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
return {
|
|
309
|
+
context: normalizedContext,
|
|
310
|
+
value: normalizedValues
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
async sendRawTransaction(rawTransaction, options) {
|
|
314
|
+
const wire = toBase64WireTransaction(rawTransaction);
|
|
315
|
+
const preflightCommitment = normalizeCommitment(
|
|
316
|
+
options?.preflightCommitment ?? options?.commitment
|
|
317
|
+
) ?? this.commitment ?? DEFAULT_COMMITMENT;
|
|
318
|
+
const maxRetries = options?.maxRetries === void 0 ? void 0 : toBigInt(options.maxRetries);
|
|
319
|
+
const minContextSlot = options?.minContextSlot === void 0 ? void 0 : toBigInt(options.minContextSlot);
|
|
320
|
+
const plan = this.#client.rpc.sendTransaction(wire, {
|
|
321
|
+
encoding: "base64",
|
|
322
|
+
maxRetries,
|
|
323
|
+
minContextSlot,
|
|
324
|
+
preflightCommitment,
|
|
325
|
+
skipPreflight: options?.skipPreflight
|
|
326
|
+
});
|
|
327
|
+
return await plan.send();
|
|
328
|
+
}
|
|
329
|
+
async confirmTransaction(signature, commitment) {
|
|
330
|
+
const normalizedCommitment = normalizeCommitment(commitment);
|
|
331
|
+
const response = await this.getSignatureStatuses([signature], {
|
|
332
|
+
commitment: normalizedCommitment ?? this.commitment ?? DEFAULT_COMMITMENT,
|
|
333
|
+
searchTransactionHistory: true
|
|
334
|
+
});
|
|
335
|
+
return {
|
|
336
|
+
context: response.context,
|
|
337
|
+
value: response.value[0] ?? null
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
async simulateTransaction(transaction, config) {
|
|
341
|
+
const wire = toBase64WireTransaction(transaction);
|
|
342
|
+
const commitment = normalizeCommitment(config?.commitment) ?? this.commitment ?? DEFAULT_COMMITMENT;
|
|
343
|
+
const baseConfig = {
|
|
344
|
+
...config ?? {},
|
|
345
|
+
commitment
|
|
346
|
+
};
|
|
347
|
+
const mergedConfig = {
|
|
348
|
+
...DEFAULT_SIMULATION_CONFIG,
|
|
349
|
+
...baseConfig,
|
|
350
|
+
commitment
|
|
351
|
+
};
|
|
352
|
+
const normalizedConfig = mergedConfig.sigVerify === true && mergedConfig.replaceRecentBlockhash !== false ? { ...mergedConfig, replaceRecentBlockhash: false } : mergedConfig;
|
|
353
|
+
const response = await this.#client.rpc.simulateTransaction(wire, normalizedConfig).send();
|
|
354
|
+
return {
|
|
355
|
+
context: {
|
|
356
|
+
apiVersion: response.context?.apiVersion,
|
|
357
|
+
slot: Number(response.context?.slot ?? 0)
|
|
358
|
+
},
|
|
359
|
+
value: response.value
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
var TRANSFER_INSTRUCTION_INDEX = 2;
|
|
364
|
+
var SystemProgram = Object.freeze({
|
|
365
|
+
...web3_js.SystemProgram,
|
|
366
|
+
transfer({ fromPubkey, toPubkey, lamports }) {
|
|
367
|
+
const data = Buffer.alloc(12);
|
|
368
|
+
data.writeUInt32LE(TRANSFER_INSTRUCTION_INDEX, 0);
|
|
369
|
+
data.writeBigUInt64LE(BigInt(lamports), 4);
|
|
370
|
+
return new web3_js.TransactionInstruction({
|
|
371
|
+
data,
|
|
372
|
+
keys: [
|
|
373
|
+
{ isSigner: true, isWritable: true, pubkey: fromPubkey },
|
|
374
|
+
{ isSigner: false, isWritable: true, pubkey: toPubkey }
|
|
375
|
+
],
|
|
376
|
+
programId: web3_js.SystemProgram.programId
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
var LAMPORTS_PER_SOL = web3_js.LAMPORTS_PER_SOL;
|
|
381
|
+
function serializeTransactionBytes(input) {
|
|
382
|
+
if (input instanceof web3_js.VersionedTransaction) {
|
|
383
|
+
return input.serialize();
|
|
384
|
+
}
|
|
385
|
+
return input.serialize({ requireAllSignatures: false });
|
|
386
|
+
}
|
|
387
|
+
__name(serializeTransactionBytes, "serializeTransactionBytes");
|
|
388
|
+
function compileFromCompat(transaction) {
|
|
389
|
+
const bytes = serializeTransactionBytes(transaction);
|
|
390
|
+
return Buffer.from(bytes).toString("base64");
|
|
391
|
+
}
|
|
392
|
+
__name(compileFromCompat, "compileFromCompat");
|
|
393
|
+
function applySigners(transaction, signers = []) {
|
|
394
|
+
if (!signers.length) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (transaction instanceof web3_js.VersionedTransaction) {
|
|
398
|
+
transaction.sign([...signers]);
|
|
399
|
+
} else {
|
|
400
|
+
transaction.partialSign(...signers);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
__name(applySigners, "applySigners");
|
|
404
|
+
async function sendAndConfirmTransaction(connection, transaction, signers = [], options = {}) {
|
|
405
|
+
applySigners(transaction, signers);
|
|
406
|
+
const serialized = compileFromCompat(transaction);
|
|
407
|
+
const raw = Buffer.from(serialized, "base64");
|
|
408
|
+
const signature = await connection.sendRawTransaction(raw, options);
|
|
409
|
+
const commitment = options.commitment ?? connection.commitment ?? "confirmed";
|
|
410
|
+
const confirmation = await connection.confirmTransaction(signature, commitment);
|
|
411
|
+
if (confirmation.value?.err) {
|
|
412
|
+
throw new Error("Transaction failed");
|
|
413
|
+
}
|
|
414
|
+
return signature;
|
|
415
|
+
}
|
|
416
|
+
__name(sendAndConfirmTransaction, "sendAndConfirmTransaction");
|
|
417
|
+
|
|
418
|
+
Object.defineProperty(exports, "Keypair", {
|
|
419
|
+
enumerable: true,
|
|
420
|
+
get: function () { return web3_js.Keypair; }
|
|
421
|
+
});
|
|
422
|
+
Object.defineProperty(exports, "PublicKey", {
|
|
423
|
+
enumerable: true,
|
|
424
|
+
get: function () { return web3_js.PublicKey; }
|
|
425
|
+
});
|
|
426
|
+
Object.defineProperty(exports, "Transaction", {
|
|
427
|
+
enumerable: true,
|
|
428
|
+
get: function () { return web3_js.Transaction; }
|
|
429
|
+
});
|
|
430
|
+
Object.defineProperty(exports, "TransactionInstruction", {
|
|
431
|
+
enumerable: true,
|
|
432
|
+
get: function () { return web3_js.TransactionInstruction; }
|
|
433
|
+
});
|
|
434
|
+
Object.defineProperty(exports, "VersionedTransaction", {
|
|
435
|
+
enumerable: true,
|
|
436
|
+
get: function () { return web3_js.VersionedTransaction; }
|
|
437
|
+
});
|
|
438
|
+
exports.Connection = Connection;
|
|
439
|
+
exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
|
|
440
|
+
exports.SystemProgram = SystemProgram;
|
|
441
|
+
exports.compileFromCompat = compileFromCompat;
|
|
442
|
+
exports.fromWeb3Instruction = fromWeb3Instruction;
|
|
443
|
+
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|
|
444
|
+
exports.toAddress = toAddress;
|
|
445
|
+
exports.toKitSigner = toKitSigner;
|
|
446
|
+
exports.toPublicKey = toPublicKey;
|
|
447
|
+
exports.toWeb3Instruction = toWeb3Instruction;
|
|
448
|
+
//# sourceMappingURL=index.browser.cjs.map
|
|
449
|
+
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bridges.ts","../src/connection.ts","../src/programs/system-program.ts","../src/utils.ts"],"names":["PublicKey","fromLegacyPublicKey","createKeyPairSignerFromBytes","AccountRole","TransactionInstruction","fromLegacyTransactionInstruction","Transaction","VersionedTransaction","createSolanaRpcClient","Web3SystemProgram","WEB3_LAMPORTS_PER_SOL","VersionedTransactionClass"],"mappings":";;;;;;;;;AAWO,SAAS,UAA4C,KAAA,EAAyD;AACpH,EAAA,MAAM,SAAS,KAAA,YAAiBA,iBAAA,GAAY,KAAA,GAAQ,IAAIA,kBAAU,KAAK,CAAA;AACvE,EAAA,OAAOC,2BAAoB,MAAM,CAAA;AAClC;AAHgB,MAAA,CAAA,SAAA,EAAA,WAAA,CAAA;AAKT,SAAS,YAAY,KAAA,EAA+C;AAC1E,EAAA,IAAI,iBAAiBD,iBAAA,EAAW;AAC/B,IAAA,OAAO,KAAA;AAAA,EACR;AACA,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC9B,IAAA,OAAO,IAAIA,kBAAU,KAAK,CAAA;AAAA,EAC3B;AACA,EAAA,OAAO,IAAIA,kBAAU,KAAK,CAAA;AAC3B;AARgB,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA;AAUhB,eAAsB,WAAA,CAAY,OAAA,EAAkB,MAAA,GAA4B,EAAC,EAA2B;AAC3G,EAAA,MAAM,SAAA,GAAY,IAAI,UAAA,CAAW,EAAE,CA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E,EAAA,IAAI,YAAA,CAAa,OAAO,GAAA,EAAK;AAC5B,IAAA,MAAM,IAAI,MAAM,oBAAoB,CAAA;AAAA,EACrC;AACA,EAAA,OAAO,SAAA;AACR;AAhBsB,MAAA,CAAA,yBAAA,EAAA,2BAAA,CAAA","file":"index.browser.cjs","sourcesContent":["import type { Address } from '@solana/addresses';\nimport { fromLegacyPublicKey, fromLegacyTransactionInstruction } from '@solana/compat';\nimport { AccountRole, createKeyPairSignerFromBytes, type Instruction, type KeyPairSigner } from '@solana/kit';\nimport { type Keypair, PublicKey, type PublicKeyInitData, TransactionInstruction } from '@solana/web3.js';\n\ntype WithOptionalExtractable = Readonly<{\n\textractable?: boolean;\n}>;\n\nexport type ToKitSignerConfig = WithOptionalExtractable;\n\nexport function toAddress<TAddress extends string = string>(input: PublicKey | PublicKeyInitData): Address<TAddress> {\n\tconst pubkey = input instanceof PublicKey ? input : new PublicKey(input);\n\treturn fromLegacyPublicKey(pubkey);\n}\n\nexport function toPublicKey(input: Address | PublicKeyInitData): PublicKey {\n\tif (input instanceof PublicKey) {\n\t\treturn input;\n\t}\n\tif (typeof input === 'string') {\n\t\treturn new PublicKey(input);\n\t}\n\treturn new PublicKey(input);\n}\n\nexport async function toKitSigner(keypair: Keypair, config: ToKitSignerConfig = {}): Promise<KeyPairSigner> {\n\tconst secretKey = new Uint8Array(64);\n\tsecretKey.set(keypair.secretKey);\n\tsecretKey.set(keypair.publicKey.toBytes(), 32);\n\treturn await createKeyPairSignerFromBytes(secretKey, config.extractable ?? false);\n}\n\nexport function toWeb3Instruction(kitInstruction: Instruction): TransactionInstruction {\n\tconst keys =\n\t\tkitInstruction.accounts?.map((account) => {\n\t\t\tconst role = account.role;\n\t\t\tconst isSigner = role === AccountRole.READONLY_SIGNER || role === AccountRole.WRITABLE_SIGNER;\n\t\t\tconst isWritable = role === AccountRole.WRITABLE || role === AccountRole.WRITABLE_SIGNER;\n\t\t\treturn {\n\t\t\t\tisSigner,\n\t\t\t\tisWritable,\n\t\t\t\tpubkey: toPublicKey(account.address),\n\t\t\t};\n\t\t}) ?? [];\n\n\tconst data = kitInstruction.data ? Buffer.from(kitInstruction.data) : Buffer.alloc(0);\n\treturn new TransactionInstruction({\n\t\tdata,\n\t\tkeys,\n\t\tprogramId: toPublicKey(kitInstruction.programAddress),\n\t});\n}\n\nexport function fromWeb3Instruction(legacyInstruction: TransactionInstruction): Instruction {\n\treturn fromLegacyTransactionInstruction(legacyInstruction);\n}\n","import type { Address } from '@solana/addresses';\nimport { createSolanaRpcClient, type SolanaRpcClient } from '@solana/client';\nimport type { Commitment as KitCommitment, Signature } from '@solana/kit';\nimport type { Base64EncodedWireTransaction } from '@solana/transactions';\nimport {\n\ttype AccountInfo,\n\ttype ConnectionConfig,\n\ttype DataSlice,\n\ttype Commitment as LegacyCommitment,\n\tPublicKey,\n\ttype SendOptions,\n\ttype SignatureStatus,\n\ttype SignatureStatusConfig,\n\ttype SimulatedTransactionResponse,\n\ttype SimulateTransactionConfig,\n\tTransaction,\n\ttype TransactionSignature,\n\tVersionedTransaction,\n} from '@solana/web3.js';\n\nimport { toAddress as toKitAddress } from './bridges';\n\ntype NormalizedCommitment = 'processed' | 'confirmed' | 'finalized';\n\ntype RpcContext = Readonly<{\n\tapiVersion?: string;\n\tslot: number;\n}>;\n\ntype AccountInfoConfig = Readonly<{\n\tcommitment?: LegacyCommitment;\n\tdataSlice?: DataSlice;\n\tencoding?: 'base64';\n\tminContextSlot?: number;\n}>;\n\ntype ProgramAccountsConfig = Readonly<{\n\tcommitment?: LegacyCommitment;\n\tdataSlice?: DataSlice;\n\tencoding?: 'base64' | 'base64+zstd';\n\tfilters?: ReadonlyArray<unknown>;\n\tminContextSlot?: number;\n\twithContext?: boolean;\n}>;\n\ntype ConnectionCommitmentInput =\n\t| LegacyCommitment\n\t| (ConnectionConfig & {\n\t\t\tcommitment?: LegacyCommitment;\n\t })\n\t| undefined;\n\ntype RpcResponseWithContext<T> = Readonly<{\n\tcontext: RpcContext;\n\tvalue: T;\n}>;\n\ntype RawTransactionInput = number[] | Uint8Array | Buffer | Transaction | VersionedTransaction;\n\ntype RpcAccount = Readonly<{\n\tdata: readonly [string, string] | string;\n\texecutable: boolean;\n\tlamports: number | bigint;\n\towner: string;\n\trentEpoch: number | bigint;\n}>;\n\ntype ProgramAccountWire = Readonly<{\n\taccount: RpcAccount;\n\tpubkey: string;\n}>;\n\ntype ProgramAccountsWithContext = Readonly<{\n\tcontext: Readonly<{\n\t\tapiVersion?: string;\n\t\tslot: number | bigint;\n\t}>;\n\tvalue: readonly ProgramAccountWire[];\n}>;\n\ntype SignatureStatusConfigWithCommitment = SignatureStatusConfig & {\n\tcommitment?: LegacyCommitment;\n};\n\nconst DEFAULT_COMMITMENT: NormalizedCommitment = 'confirmed';\n\nconst DEFAULT_SIMULATION_CONFIG = Object.freeze({\n\tencoding: 'base64' as const,\n\treplaceRecentBlockhash: true as const,\n\tsigVerify: false as const,\n});\n\nfunction normalizeCommitment(commitment?: LegacyCommitment | null): NormalizedCommitment | undefined {\n\tif (commitment === undefined || commitment === null) {\n\t\treturn undefined;\n\t}\n\tif (commitment === 'recent') {\n\t\treturn 'processed';\n\t}\n\tif (commitment === 'singleGossip') {\n\t\treturn 'processed';\n\t}\n\tif (commitment === 'single') {\n\t\treturn 'confirmed';\n\t}\n\tif (commitment === 'max') {\n\t\treturn 'finalized';\n\t}\n\treturn commitment as NormalizedCommitment;\n}\n\nfunction toBigInt(value: number | bigint | undefined): bigint | undefined {\n\tif (value === undefined) return undefined;\n\treturn typeof value === 'bigint' ? value : BigInt(Math.trunc(value));\n}\n\nfunction toAccountInfo(info: RpcAccount, dataSlice?: DataSlice): AccountInfo<Buffer> {\n\tconst { data, executable, lamports, owner, rentEpoch } = info;\n\tconst [content, encoding] = Array.isArray(data) ? data : [data, 'base64'];\n\tlet buffer = encoding === 'base64' ? Buffer.from(content, 'base64') : Buffer.from(content);\n\tif (dataSlice) {\n\t\tconst start = dataSlice.offset ?? 0;\n\t\tconst end = start + (dataSlice.length ?? buffer.length);\n\t\tbuffer = buffer.subarray(start, end);\n\t}\n\treturn {\n\t\tdata: buffer,\n\t\texecutable,\n\t\tlamports: typeof lamports === 'number' ? lamports : Number(lamports),\n\t\towner: new PublicKey(owner),\n\t\trentEpoch: typeof rentEpoch === 'number' ? rentEpoch : Number(rentEpoch),\n\t};\n}\n\nfunction fromKitAccount(value: unknown): RpcAccount {\n\tconst account = (value ?? {}) as Record<string, unknown>;\n\tconst data = account.data as string | readonly [string, string] | undefined;\n\tconst lamports = account.lamports as number | bigint | undefined;\n\tconst ownerValue = account.owner as unknown;\n\tconst rentEpoch = account.rentEpoch as number | bigint | undefined;\n\tconst owner =\n\t\ttypeof ownerValue === 'string'\n\t\t\t? ownerValue\n\t\t\t: ownerValue instanceof PublicKey\n\t\t\t\t? ownerValue.toBase58()\n\t\t\t\t: typeof ownerValue === 'object' && ownerValue !== null && 'toString' in ownerValue\n\t\t\t\t\t? String(ownerValue)\n\t\t\t\t\t: '11111111111111111111111111111111';\n\treturn {\n\t\tdata: data ?? ['', 'base64'],\n\t\texecutable: Boolean(account.executable),\n\t\tlamports: lamports ?? 0,\n\t\towner,\n\t\trentEpoch: rentEpoch ?? 0,\n\t};\n}\n\nfunction toKitAddressFromInput(input: PublicKey | string): Address<string> {\n\treturn toKitAddress(input instanceof PublicKey ? input : input);\n}\n\nfunction toBase64WireTransaction(raw: RawTransactionInput): Base64EncodedWireTransaction {\n\tif (raw instanceof Transaction || raw instanceof VersionedTransaction) {\n\t\tconst bytes = raw.serialize({\n\t\t\trequireAllSignatures: false,\n\t\t\tverifySignatures: false,\n\t\t});\n\t\treturn Buffer.from(bytes).toString('base64') as Base64EncodedWireTransaction;\n\t}\n\tif (raw instanceof Uint8Array) {\n\t\treturn Buffer.from(raw).toString('base64') as Base64EncodedWireTransaction;\n\t}\n\tif (raw instanceof Buffer) {\n\t\treturn raw.toString('base64') as Base64EncodedWireTransaction;\n\t}\n\tconst uint8 = Uint8Array.from(raw);\n\treturn Buffer.from(uint8).toString('base64') as Base64EncodedWireTransaction;\n}\n\nexport class Connection {\n\treadonly commitment?: NormalizedCommitment;\n\treadonly rpcEndpoint: string;\n\n\t#client: SolanaRpcClient;\n\n\tconstructor(endpoint: string, commitmentOrConfig?: ConnectionCommitmentInput) {\n\t\tconst commitment =\n\t\t\ttypeof commitmentOrConfig === 'string'\n\t\t\t\t? normalizeCommitment(commitmentOrConfig)\n\t\t\t\t: (normalizeCommitment(commitmentOrConfig?.commitment) ?? DEFAULT_COMMITMENT);\n\n\t\tconst websocketEndpoint =\n\t\t\ttypeof commitmentOrConfig === 'object' && commitmentOrConfig !== null\n\t\t\t\t? commitmentOrConfig.wsEndpoint\n\t\t\t\t: undefined;\n\n\t\tthis.commitment = commitment;\n\t\tthis.rpcEndpoint = endpoint;\n\t\tthis.#client = createSolanaRpcClient({\n\t\t\tendpoint,\n\t\t\twebsocketEndpoint,\n\t\t\tcommitment: (commitment ?? DEFAULT_COMMITMENT) as KitCommitment,\n\t\t});\n\t}\n\n\tasync getLatestBlockhash(\n\t\tcommitmentOrConfig?:\n\t\t\t| LegacyCommitment\n\t\t\t| {\n\t\t\t\t\tcommitment?: LegacyCommitment;\n\t\t\t\t\tmaxSupportedTransactionVersion?: number;\n\t\t\t\t\tminContextSlot?: number;\n\t\t\t },\n\t): Promise<{\n\t\tblockhash: string;\n\t\tlastValidBlockHeight: number;\n\t}> {\n\t\tconst baseCommitment =\n\t\t\ttypeof commitmentOrConfig === 'string' ? commitmentOrConfig : commitmentOrConfig?.commitment;\n\t\tconst commitment = normalizeCommitment(baseCommitment) ?? this.commitment ?? DEFAULT_COMMITMENT;\n\t\tconst minContextSlot =\n\t\t\ttypeof commitmentOrConfig === 'object' ? toBigInt(commitmentOrConfig.minContextSlot) : undefined;\n\t\tconst requestOptions: Record<string, unknown> = {\n\t\t\tcommitment: commitment as KitCommitment,\n\t\t};\n\t\tif (minContextSlot !== undefined) {\n\t\t\trequestOptions.minContextSlot = minContextSlot;\n\t\t}\n\t\tif (\n\t\t\ttypeof commitmentOrConfig === 'object' &&\n\t\t\tcommitmentOrConfig?.maxSupportedTransactionVersion !== undefined\n\t\t) {\n\t\t\trequestOptions.maxSupportedTransactionVersion = commitmentOrConfig.maxSupportedTransactionVersion;\n\t\t}\n\t\tconst response = await this.#client.rpc.getLatestBlockhash(requestOptions as never).send();\n\n\t\treturn {\n\t\t\tblockhash: response.value.blockhash,\n\t\t\tlastValidBlockHeight: Number(response.value.lastValidBlockHeight),\n\t\t};\n\t}\n\n\tasync getBalance(publicKey: PublicKey | string, commitment?: LegacyCommitment): Promise<number> {\n\t\tconst address = toKitAddressFromInput(publicKey);\n\t\tconst chosenCommitment = normalizeCommitment(commitment) ?? this.commitment ?? DEFAULT_COMMITMENT;\n\t\tconst result = await this.#client.rpc\n\t\t\t.getBalance(address, { commitment: chosenCommitment as KitCommitment })\n\t\t\t.send();\n\t\treturn typeof result.value === 'number' ? result.value : Number(result.value);\n\t}\n\n\tasync getAccountInfo<TAccountData = Buffer>(\n\t\tpublicKey: PublicKey | string,\n\t\tcommitmentOrConfig?: AccountInfoConfig | LegacyCommitment,\n\t): Promise<AccountInfo<TAccountData> | null> {\n\t\tconst address = toKitAddressFromInput(publicKey);\n\t\tlet localCommitment: NormalizedCommitment | undefined;\n\t\tlet minContextSlot: bigint | undefined;\n\t\tlet dataSlice: DataSlice | undefined;\n\t\tlet encoding: 'base64' | undefined;\n\t\tif (typeof commitmentOrConfig === 'string') {\n\t\t\tlocalCommitment = normalizeCommitment(commitmentOrConfig);\n\t\t} else if (commitmentOrConfig) {\n\t\t\tlocalCommitment = normalizeCommitment(commitmentOrConfig.commitment);\n\t\t\tif (commitmentOrConfig.minContextSlot !== undefined) {\n\t\t\t\tminContextSlot = toBigInt(commitmentOrConfig.minContextSlot);\n\t\t\t}\n\t\t\tdataSlice = commitmentOrConfig.dataSlice;\n\t\t\tencoding = commitmentOrConfig.encoding;\n\t\t}\n\n\t\tconst requestOptions: Record<string, unknown> = {\n\t\t\tcommitment: (localCommitment ?? this.commitment ?? DEFAULT_COMMITMENT) as KitCommitment,\n\t\t};\n\t\tif (minContextSlot !== undefined) {\n\t\t\trequestOptions.minContextSlot = minContextSlot;\n\t\t}\n\t\tif (encoding) {\n\t\t\trequestOptions.encoding = encoding;\n\t\t}\n\t\tif (dataSlice) {\n\t\t\trequestOptions.dataSlice = {\n\t\t\t\tlength: dataSlice.length,\n\t\t\t\toffset: dataSlice.offset,\n\t\t\t};\n\t\t}\n\n\t\tconst response = await this.#client.rpc.getAccountInfo(address, requestOptions as never).send();\n\n\t\tif (!response.value) {\n\t\t\treturn null;\n\t\t}\n\t\tconst accountInfo = toAccountInfo(fromKitAccount(response.value), dataSlice);\n\n\t\treturn accountInfo as AccountInfo<TAccountData>;\n\t}\n\n\tasync getProgramAccounts(\n\t\tprogramId: PublicKey | string,\n\t\tcommitmentOrConfig?: LegacyCommitment | ProgramAccountsConfig,\n\t): Promise<\n\t\t| Array<{\n\t\t\t\taccount: AccountInfo<Buffer | object>;\n\t\t\t\tpubkey: PublicKey;\n\t\t }>\n\t\t| RpcResponseWithContext<\n\t\t\t\tArray<{\n\t\t\t\t\taccount: AccountInfo<Buffer | object>;\n\t\t\t\t\tpubkey: PublicKey;\n\t\t\t\t}>\n\t\t >\n\t> {\n\t\tconst id = toKitAddressFromInput(programId);\n\t\tlet localCommitment: NormalizedCommitment | undefined;\n\t\tlet dataSlice: DataSlice | undefined;\n\t\tlet filters: ReadonlyArray<unknown> | undefined;\n\t\tlet encoding: 'base64' | 'base64+zstd' | undefined;\n\t\tlet minContextSlot: bigint | undefined;\n\t\tlet withContext = false;\n\t\tif (typeof commitmentOrConfig === 'string') {\n\t\t\tlocalCommitment = normalizeCommitment(commitmentOrConfig);\n\t\t} else if (commitmentOrConfig) {\n\t\t\tlocalCommitment = normalizeCommitment(commitmentOrConfig.commitment);\n\t\t\tdataSlice = commitmentOrConfig.dataSlice;\n\t\t\tfilters = commitmentOrConfig.filters;\n\t\t\tencoding = commitmentOrConfig.encoding;\n\t\t\tminContextSlot = toBigInt(commitmentOrConfig.minContextSlot);\n\t\t\twithContext = Boolean(commitmentOrConfig.withContext);\n\t\t}\n\n\t\tconst requestOptions: Record<string, unknown> = {\n\t\t\tcommitment: (localCommitment ?? this.commitment ?? DEFAULT_COMMITMENT) as KitCommitment,\n\t\t\twithContext,\n\t\t};\n\t\tif (dataSlice) {\n\t\t\trequestOptions.dataSlice = {\n\t\t\t\tlength: dataSlice.length,\n\t\t\t\toffset: dataSlice.offset,\n\t\t\t};\n\t\t}\n\t\tif (encoding) {\n\t\t\trequestOptions.encoding = encoding;\n\t\t}\n\t\tif (filters) {\n\t\t\trequestOptions.filters = filters.map((filter) => filter as never);\n\t\t}\n\t\tif (minContextSlot !== undefined) {\n\t\t\trequestOptions.minContextSlot = minContextSlot;\n\t\t}\n\n\t\tconst result = await this.#client.rpc.getProgramAccounts(id, requestOptions as never).send();\n\n\t\tconst mapProgramAccount = (entry: ProgramAccountWire) => {\n\t\t\tconst pubkey = new PublicKey(entry.pubkey);\n\t\t\treturn {\n\t\t\t\taccount: toAccountInfo(fromKitAccount(entry.account), dataSlice),\n\t\t\t\tpubkey,\n\t\t\t};\n\t\t};\n\n\t\tif (withContext && typeof (result as unknown as ProgramAccountsWithContext).context !== 'undefined') {\n\t\t\tconst contextual = result as unknown as ProgramAccountsWithContext;\n\t\t\treturn {\n\t\t\t\tcontext: {\n\t\t\t\t\tapiVersion: contextual.context.apiVersion,\n\t\t\t\t\tslot: Number(contextual.context.slot),\n\t\t\t\t},\n\t\t\t\tvalue: contextual.value.map(mapProgramAccount),\n\t\t\t};\n\t\t}\n\n\t\treturn (result as unknown as readonly ProgramAccountWire[]).map(mapProgramAccount);\n\t}\n\n\tasync getSignatureStatuses(\n\t\tsignatures: readonly TransactionSignature[],\n\t\tconfig?: SignatureStatusConfigWithCommitment,\n\t): Promise<RpcResponseWithContext<(SignatureStatus | null)[]>> {\n\t\tconst targetCommitment = normalizeCommitment(config?.commitment) ?? this.commitment ?? DEFAULT_COMMITMENT;\n\t\tconst kitSignatures = signatures.map((signature) => signature as unknown as Signature);\n\t\tconst response = await this.#client.rpc\n\t\t\t.getSignatureStatuses(kitSignatures, {\n\t\t\t\tcommitment: targetCommitment as KitCommitment,\n\t\t\t\tsearchTransactionHistory: config?.searchTransactionHistory,\n\t\t\t} as never)\n\t\t\t.send();\n\n\t\tconst context = response.context as { slot: number | bigint; apiVersion?: string };\n\t\tconst normalizedContext: RpcContext = {\n\t\t\tapiVersion: context?.apiVersion,\n\t\t\tslot: typeof context?.slot === 'bigint' ? Number(context.slot) : (context?.slot ?? 0),\n\t\t};\n\n\t\tconst normalizedValues = (response.value as readonly (SignatureStatus | null | Record<string, unknown>)[]).map(\n\t\t\t(status) => {\n\t\t\t\tif (!status) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tconst record = status as Record<string, unknown>;\n\t\t\t\tconst slot = record.slot as number | bigint | undefined;\n\t\t\t\tconst confirmations = record.confirmations as number | bigint | null | undefined;\n\t\t\t\tconst normalizedConfirmations =\n\t\t\t\t\tconfirmations === null\n\t\t\t\t\t\t? null\n\t\t\t\t\t\t: confirmations === undefined\n\t\t\t\t\t\t\t? null\n\t\t\t\t\t\t\t: typeof confirmations === 'bigint'\n\t\t\t\t\t\t\t\t? Number(confirmations)\n\t\t\t\t\t\t\t\t: confirmations;\n\t\t\t\treturn {\n\t\t\t\t\terr: (record.err ?? null) as SignatureStatus['err'],\n\t\t\t\t\tconfirmations: normalizedConfirmations,\n\t\t\t\t\tconfirmationStatus: record.confirmationStatus as SignatureStatus['confirmationStatus'],\n\t\t\t\t\tslot: slot === undefined ? 0 : typeof slot === 'bigint' ? Number(slot) : slot,\n\t\t\t\t} satisfies SignatureStatus;\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\tcontext: normalizedContext,\n\t\t\tvalue: normalizedValues as (SignatureStatus | null)[],\n\t\t};\n\t}\n\tasync sendRawTransaction(rawTransaction: RawTransactionInput, options?: SendOptions): Promise<string> {\n\t\tconst wire = toBase64WireTransaction(rawTransaction);\n\n\t\tconst preflightCommitment =\n\t\t\tnormalizeCommitment(\n\t\t\t\toptions?.preflightCommitment ??\n\t\t\t\t\t(options as (SendOptions & { commitment?: LegacyCommitment }) | undefined)?.commitment,\n\t\t\t) ??\n\t\t\tthis.commitment ??\n\t\t\tDEFAULT_COMMITMENT;\n\t\tconst maxRetries = options?.maxRetries === undefined ? undefined : toBigInt(options.maxRetries);\n\t\tconst minContextSlot = options?.minContextSlot === undefined ? undefined : toBigInt(options.minContextSlot);\n\t\tconst plan = this.#client.rpc.sendTransaction(wire, {\n\t\t\tencoding: 'base64',\n\t\t\tmaxRetries,\n\t\t\tminContextSlot,\n\t\t\tpreflightCommitment: preflightCommitment as KitCommitment,\n\t\t\tskipPreflight: options?.skipPreflight,\n\t\t});\n\n\t\treturn await plan.send();\n\t}\n\n\tasync confirmTransaction(\n\t\tsignature: TransactionSignature,\n\t\tcommitment?: LegacyCommitment,\n\t): Promise<RpcResponseWithContext<SignatureStatus | null>> {\n\t\tconst normalizedCommitment = normalizeCommitment(commitment);\n\t\tconst response = await this.getSignatureStatuses([signature], {\n\t\t\tcommitment: normalizedCommitment ?? this.commitment ?? DEFAULT_COMMITMENT,\n\t\t\tsearchTransactionHistory: true,\n\t\t});\n\n\t\treturn {\n\t\t\tcontext: response.context,\n\t\t\tvalue: response.value[0] ?? null,\n\t\t};\n\t}\n\n\tasync simulateTransaction(\n\t\ttransaction: RawTransactionInput,\n\t\tconfig?: SimulateTransactionConfig,\n\t): Promise<RpcResponseWithContext<SimulatedTransactionResponse>> {\n\t\tconst wire = toBase64WireTransaction(transaction);\n\t\tconst commitment = normalizeCommitment(config?.commitment) ?? this.commitment ?? DEFAULT_COMMITMENT;\n\t\tconst baseConfig = {\n\t\t\t...(config ?? {}),\n\t\t\tcommitment,\n\t\t};\n\t\tconst mergedConfig = {\n\t\t\t...DEFAULT_SIMULATION_CONFIG,\n\t\t\t...baseConfig,\n\t\t\tcommitment: commitment as KitCommitment,\n\t\t};\n\t\tconst normalizedConfig =\n\t\t\tmergedConfig.sigVerify === true && mergedConfig.replaceRecentBlockhash !== false\n\t\t\t\t? { ...mergedConfig, replaceRecentBlockhash: false }\n\t\t\t\t: mergedConfig;\n\n\t\tconst response = await this.#client.rpc.simulateTransaction(wire, normalizedConfig as never).send();\n\n\t\treturn {\n\t\t\tcontext: {\n\t\t\t\tapiVersion: (response.context as Record<string, unknown>)?.apiVersion as string | undefined,\n\t\t\t\tslot: Number((response.context as Record<string, unknown>)?.slot ?? 0),\n\t\t\t},\n\t\t\tvalue: response.value as unknown as SimulatedTransactionResponse,\n\t\t};\n\t}\n}\n","import { type PublicKey, TransactionInstruction, SystemProgram as Web3SystemProgram } from '@solana/web3.js';\n\ntype TransferParams = Readonly<{\n\tfromPubkey: PublicKey;\n\tlamports: number | bigint;\n\ttoPubkey: PublicKey;\n}>;\n\nconst TRANSFER_INSTRUCTION_INDEX = 2;\n\nexport const SystemProgram = Object.freeze({\n\t...Web3SystemProgram,\n\ttransfer({ fromPubkey, toPubkey, lamports }: TransferParams): TransactionInstruction {\n\t\tconst data = Buffer.alloc(12);\n\t\tdata.writeUInt32LE(TRANSFER_INSTRUCTION_INDEX, 0);\n\t\tdata.writeBigUInt64LE(BigInt(lamports), 4);\n\t\treturn new TransactionInstruction({\n\t\t\tdata,\n\t\t\tkeys: [\n\t\t\t\t{ isSigner: true, isWritable: true, pubkey: fromPubkey },\n\t\t\t\t{ isSigner: false, isWritable: true, pubkey: toPubkey },\n\t\t\t],\n\t\t\tprogramId: Web3SystemProgram.programId,\n\t\t});\n\t},\n});\n","import type {\n\tCommitment,\n\tTransaction as LegacyTransaction,\n\tVersionedTransaction as LegacyVersionedTransaction,\n\tSendOptions,\n\tSigner,\n} from '@solana/web3.js';\nimport {\n\tVersionedTransaction as VersionedTransactionClass,\n\tLAMPORTS_PER_SOL as WEB3_LAMPORTS_PER_SOL,\n} from '@solana/web3.js';\nimport type { Connection } from './connection';\n\nexport const LAMPORTS_PER_SOL = WEB3_LAMPORTS_PER_SOL;\n\ntype SendAndConfirmOptions = SendOptions & {\n\tcommitment?: Commitment;\n};\n\nfunction serializeTransactionBytes(input: LegacyTransaction | LegacyVersionedTransaction): Uint8Array {\n\tif (input instanceof VersionedTransactionClass) {\n\t\treturn input.serialize();\n\t}\n\treturn (input as LegacyTransaction).serialize({ requireAllSignatures: false });\n}\n\nexport function compileFromCompat(transaction: LegacyTransaction | LegacyVersionedTransaction): string {\n\tconst bytes = serializeTransactionBytes(transaction);\n\treturn Buffer.from(bytes).toString('base64');\n}\n\nfunction applySigners(\n\ttransaction: LegacyTransaction | LegacyVersionedTransaction,\n\tsigners: readonly Signer[] = [],\n): void {\n\tif (!signers.length) {\n\t\treturn;\n\t}\n\tif (transaction instanceof VersionedTransactionClass) {\n\t\ttransaction.sign([...signers]);\n\t} else {\n\t\t(transaction as LegacyTransaction).partialSign(...signers);\n\t}\n}\n\nexport async function sendAndConfirmTransaction(\n\tconnection: Connection,\n\ttransaction: LegacyTransaction | LegacyVersionedTransaction,\n\tsigners: readonly Signer[] = [],\n\toptions: SendAndConfirmOptions = {},\n): Promise<string> {\n\tapplySigners(transaction, signers);\n\tconst serialized = compileFromCompat(transaction);\n\tconst raw = Buffer.from(serialized, 'base64');\n\tconst signature = await connection.sendRawTransaction(raw, options);\n\tconst commitment = options.commitment ?? connection.commitment ?? 'confirmed';\n\tconst confirmation = await connection.confirmTransaction(signature, commitment);\n\tif (confirmation.value?.err) {\n\t\tthrow new Error('Transaction failed');\n\t}\n\treturn signature;\n}\n"]}
|