@solana/web3-compat 0.0.9 → 0.0.11

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.
@@ -1,506 +1,2 @@
1
- import { SystemProgram as SystemProgram$1, TransactionInstruction, PublicKey, Transaction, VersionedTransaction, LAMPORTS_PER_SOL as LAMPORTS_PER_SOL$1 } from '@solana/web3.js';
2
- export { Keypair, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
3
- import { fromLegacyPublicKey, fromLegacyTransactionInstruction } from '@solana/compat';
4
- import { createSolanaRpc, createSolanaRpcSubscriptions, getBase64EncodedWireTransaction, createKeyPairSignerFromBytes, AccountRole } from '@solana/kit';
5
- import { createBlockHeightExceedencePromiseFactory, createRecentSignatureConfirmationPromiseFactory, waitForRecentTransactionConfirmation } from '@solana/transaction-confirmation';
6
-
7
- var __defProp = Object.defineProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- function toAddress(input) {
10
- const pubkey = input instanceof PublicKey ? input : new PublicKey(input);
11
- return fromLegacyPublicKey(pubkey);
12
- }
13
- __name(toAddress, "toAddress");
14
- function toPublicKey(input) {
15
- if (input instanceof PublicKey) {
16
- return input;
17
- }
18
- if (typeof input === "string") {
19
- return new PublicKey(input);
20
- }
21
- return new PublicKey(input);
22
- }
23
- __name(toPublicKey, "toPublicKey");
24
- async function toKitSigner(keypair, config = {}) {
25
- const secretKey = new Uint8Array(64);
26
- secretKey.set(keypair.secretKey);
27
- secretKey.set(keypair.publicKey.toBytes(), 32);
28
- return await createKeyPairSignerFromBytes(secretKey, config.extractable ?? false);
29
- }
30
- __name(toKitSigner, "toKitSigner");
31
- function toWeb3Instruction(kitInstruction) {
32
- const keys = kitInstruction.accounts?.map((account) => {
33
- const role = account.role;
34
- const isSigner = role === AccountRole.READONLY_SIGNER || role === AccountRole.WRITABLE_SIGNER;
35
- const isWritable = role === AccountRole.WRITABLE || role === AccountRole.WRITABLE_SIGNER;
36
- return {
37
- isSigner,
38
- isWritable,
39
- pubkey: toPublicKey(account.address)
40
- };
41
- }) ?? [];
42
- const data = kitInstruction.data ? Buffer.from(kitInstruction.data) : Buffer.alloc(0);
43
- return new TransactionInstruction({
44
- data,
45
- keys,
46
- programId: toPublicKey(kitInstruction.programAddress)
47
- });
48
- }
49
- __name(toWeb3Instruction, "toWeb3Instruction");
50
- function fromWeb3Instruction(legacyInstruction) {
51
- return fromLegacyTransactionInstruction(legacyInstruction);
52
- }
53
- __name(fromWeb3Instruction, "fromWeb3Instruction");
54
- function createChainedAbortController(parent) {
55
- const controller = new AbortController();
56
- if (!parent) {
57
- return controller;
58
- }
59
- if (parent.aborted) {
60
- controller.abort(parent.reason);
61
- return controller;
62
- }
63
- const onAbort = /* @__PURE__ */ __name(() => {
64
- controller.abort(parent.reason);
65
- parent.removeEventListener("abort", onAbort);
66
- }, "onAbort");
67
- parent.addEventListener("abort", onAbort, { once: true });
68
- return controller;
69
- }
70
- __name(createChainedAbortController, "createChainedAbortController");
71
- function toBigint(value) {
72
- if (value === void 0) {
73
- return void 0;
74
- }
75
- return typeof value === "bigint" ? value : BigInt(Math.floor(value));
76
- }
77
- __name(toBigint, "toBigint");
78
- var DEFAULT_SIMULATION_CONFIG = Object.freeze({
79
- encoding: "base64",
80
- replaceRecentBlockhash: true,
81
- sigVerify: false
82
- });
83
- function createSolanaRpcClient(config) {
84
- const endpoint = config.endpoint;
85
- const websocketEndpoint = config.websocketEndpoint ?? endpoint;
86
- const commitment = config.commitment ?? "confirmed";
87
- const rpc = createSolanaRpc(endpoint, config.rpcConfig);
88
- const rpcSubscriptions = createSolanaRpcSubscriptions(websocketEndpoint, config.rpcSubscriptionsConfig);
89
- async function sendAndConfirmTransaction2(transaction, options = {}) {
90
- const abortController = createChainedAbortController(options.abortSignal);
91
- const targetCommitment = options.commitment ?? commitment;
92
- const wireTransaction = getBase64EncodedWireTransaction(transaction);
93
- const response = await rpc.sendTransaction(wireTransaction, {
94
- encoding: "base64",
95
- maxRetries: toBigint(options.maxRetries),
96
- minContextSlot: toBigint(options.minContextSlot),
97
- preflightCommitment: targetCommitment,
98
- skipPreflight: options.skipPreflight
99
- }).send({ abortSignal: abortController.signal });
100
- const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
101
- rpc,
102
- rpcSubscriptions
103
- });
104
- const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({
105
- rpc,
106
- rpcSubscriptions
107
- });
108
- await waitForRecentTransactionConfirmation({
109
- abortSignal: abortController.signal,
110
- commitment: targetCommitment,
111
- getBlockHeightExceedencePromise,
112
- getRecentSignatureConfirmationPromise,
113
- transaction
114
- });
115
- return response;
116
- }
117
- __name(sendAndConfirmTransaction2, "sendAndConfirmTransaction");
118
- async function simulateTransaction(transaction, options = {}) {
119
- const wireTransaction = getBase64EncodedWireTransaction(transaction);
120
- const baseConfig = options.config ?? {};
121
- const mergedConfig = {
122
- ...DEFAULT_SIMULATION_CONFIG,
123
- ...baseConfig,
124
- commitment: baseConfig.commitment ?? options.commitment ?? commitment
125
- };
126
- const normalizedConfig = mergedConfig.sigVerify === true && mergedConfig.replaceRecentBlockhash !== false ? { ...mergedConfig, replaceRecentBlockhash: false } : mergedConfig;
127
- return rpc.simulateTransaction(wireTransaction, normalizedConfig).send({ abortSignal: options.abortSignal });
128
- }
129
- __name(simulateTransaction, "simulateTransaction");
130
- return {
131
- commitment,
132
- endpoint,
133
- rpc,
134
- rpcSubscriptions,
135
- sendAndConfirmTransaction: sendAndConfirmTransaction2,
136
- simulateTransaction,
137
- websocketEndpoint
138
- };
139
- }
140
- __name(createSolanaRpcClient, "createSolanaRpcClient");
141
- var DEFAULT_COMMITMENT = "confirmed";
142
- var DEFAULT_SIMULATION_CONFIG2 = Object.freeze({
143
- encoding: "base64",
144
- replaceRecentBlockhash: true,
145
- sigVerify: false
146
- });
147
- function normalizeCommitment(commitment) {
148
- if (commitment === void 0 || commitment === null) {
149
- return void 0;
150
- }
151
- if (commitment === "recent") {
152
- return "processed";
153
- }
154
- if (commitment === "singleGossip") {
155
- return "processed";
156
- }
157
- if (commitment === "single") {
158
- return "confirmed";
159
- }
160
- if (commitment === "max") {
161
- return "finalized";
162
- }
163
- return commitment;
164
- }
165
- __name(normalizeCommitment, "normalizeCommitment");
166
- function toBigInt(value) {
167
- if (value === void 0) return void 0;
168
- return typeof value === "bigint" ? value : BigInt(Math.trunc(value));
169
- }
170
- __name(toBigInt, "toBigInt");
171
- function toAccountInfo(info, dataSlice) {
172
- const { data, executable, lamports, owner, rentEpoch } = info;
173
- const [content, encoding] = Array.isArray(data) ? data : [data, "base64"];
174
- let buffer = encoding === "base64" ? Buffer.from(content, "base64") : Buffer.from(content);
175
- if (dataSlice) {
176
- const start = dataSlice.offset ?? 0;
177
- const end = start + (dataSlice.length ?? buffer.length);
178
- buffer = buffer.subarray(start, end);
179
- }
180
- return {
181
- data: buffer,
182
- executable,
183
- lamports: typeof lamports === "number" ? lamports : Number(lamports),
184
- owner: new PublicKey(owner),
185
- rentEpoch: typeof rentEpoch === "number" ? rentEpoch : Number(rentEpoch)
186
- };
187
- }
188
- __name(toAccountInfo, "toAccountInfo");
189
- function fromKitAccount(value) {
190
- const account = value ?? {};
191
- const data = account.data;
192
- const lamports = account.lamports;
193
- const ownerValue = account.owner;
194
- const rentEpoch = account.rentEpoch;
195
- const owner = typeof ownerValue === "string" ? ownerValue : ownerValue instanceof PublicKey ? ownerValue.toBase58() : typeof ownerValue === "object" && ownerValue !== null && "toString" in ownerValue ? String(ownerValue) : "11111111111111111111111111111111";
196
- return {
197
- data: data ?? ["", "base64"],
198
- executable: Boolean(account.executable),
199
- lamports: lamports ?? 0,
200
- owner,
201
- rentEpoch: rentEpoch ?? 0
202
- };
203
- }
204
- __name(fromKitAccount, "fromKitAccount");
205
- function toKitAddressFromInput(input) {
206
- return toAddress(input instanceof PublicKey ? input : input);
207
- }
208
- __name(toKitAddressFromInput, "toKitAddressFromInput");
209
- function toBase64WireTransaction(raw) {
210
- if (raw instanceof Transaction || raw instanceof VersionedTransaction) {
211
- const bytes = raw.serialize({
212
- requireAllSignatures: false,
213
- verifySignatures: false
214
- });
215
- return Buffer.from(bytes).toString("base64");
216
- }
217
- if (raw instanceof Uint8Array) {
218
- return Buffer.from(raw).toString("base64");
219
- }
220
- if (raw instanceof Buffer) {
221
- return raw.toString("base64");
222
- }
223
- const uint8 = Uint8Array.from(raw);
224
- return Buffer.from(uint8).toString("base64");
225
- }
226
- __name(toBase64WireTransaction, "toBase64WireTransaction");
227
- var Connection = class {
228
- static {
229
- __name(this, "Connection");
230
- }
231
- commitment;
232
- rpcEndpoint;
233
- #client;
234
- constructor(endpoint, commitmentOrConfig) {
235
- const commitment = typeof commitmentOrConfig === "string" ? normalizeCommitment(commitmentOrConfig) : normalizeCommitment(commitmentOrConfig?.commitment) ?? DEFAULT_COMMITMENT;
236
- const websocketEndpoint = typeof commitmentOrConfig === "object" && commitmentOrConfig !== null ? commitmentOrConfig.wsEndpoint : void 0;
237
- this.commitment = commitment;
238
- this.rpcEndpoint = endpoint;
239
- this.#client = createSolanaRpcClient({
240
- endpoint,
241
- websocketEndpoint,
242
- commitment: commitment ?? DEFAULT_COMMITMENT
243
- });
244
- }
245
- async getLatestBlockhash(commitmentOrConfig) {
246
- const baseCommitment = typeof commitmentOrConfig === "string" ? commitmentOrConfig : commitmentOrConfig?.commitment;
247
- const commitment = normalizeCommitment(baseCommitment) ?? this.commitment ?? DEFAULT_COMMITMENT;
248
- const minContextSlot = typeof commitmentOrConfig === "object" ? toBigInt(commitmentOrConfig.minContextSlot) : void 0;
249
- const requestOptions = {
250
- commitment
251
- };
252
- if (minContextSlot !== void 0) {
253
- requestOptions.minContextSlot = minContextSlot;
254
- }
255
- if (typeof commitmentOrConfig === "object" && commitmentOrConfig?.maxSupportedTransactionVersion !== void 0) {
256
- requestOptions.maxSupportedTransactionVersion = commitmentOrConfig.maxSupportedTransactionVersion;
257
- }
258
- const response = await this.#client.rpc.getLatestBlockhash(requestOptions).send();
259
- return {
260
- blockhash: response.value.blockhash,
261
- lastValidBlockHeight: Number(response.value.lastValidBlockHeight)
262
- };
263
- }
264
- async getBalance(publicKey, commitment) {
265
- const address = toKitAddressFromInput(publicKey);
266
- const chosenCommitment = normalizeCommitment(commitment) ?? this.commitment ?? DEFAULT_COMMITMENT;
267
- const result = await this.#client.rpc.getBalance(address, { commitment: chosenCommitment }).send();
268
- return typeof result.value === "number" ? result.value : Number(result.value);
269
- }
270
- async getAccountInfo(publicKey, commitmentOrConfig) {
271
- const address = toKitAddressFromInput(publicKey);
272
- let localCommitment;
273
- let minContextSlot;
274
- let dataSlice;
275
- let encoding;
276
- if (typeof commitmentOrConfig === "string") {
277
- localCommitment = normalizeCommitment(commitmentOrConfig);
278
- } else if (commitmentOrConfig) {
279
- localCommitment = normalizeCommitment(commitmentOrConfig.commitment);
280
- if (commitmentOrConfig.minContextSlot !== void 0) {
281
- minContextSlot = toBigInt(commitmentOrConfig.minContextSlot);
282
- }
283
- dataSlice = commitmentOrConfig.dataSlice;
284
- encoding = commitmentOrConfig.encoding;
285
- }
286
- const requestOptions = {
287
- commitment: localCommitment ?? this.commitment ?? DEFAULT_COMMITMENT
288
- };
289
- if (minContextSlot !== void 0) {
290
- requestOptions.minContextSlot = minContextSlot;
291
- }
292
- if (encoding) {
293
- requestOptions.encoding = encoding;
294
- }
295
- if (dataSlice) {
296
- requestOptions.dataSlice = {
297
- length: dataSlice.length,
298
- offset: dataSlice.offset
299
- };
300
- }
301
- const response = await this.#client.rpc.getAccountInfo(address, requestOptions).send();
302
- if (!response.value) {
303
- return null;
304
- }
305
- const accountInfo = toAccountInfo(fromKitAccount(response.value), dataSlice);
306
- return accountInfo;
307
- }
308
- async getProgramAccounts(programId, commitmentOrConfig) {
309
- const id = toKitAddressFromInput(programId);
310
- let localCommitment;
311
- let dataSlice;
312
- let filters;
313
- let encoding;
314
- let minContextSlot;
315
- let withContext = false;
316
- if (typeof commitmentOrConfig === "string") {
317
- localCommitment = normalizeCommitment(commitmentOrConfig);
318
- } else if (commitmentOrConfig) {
319
- localCommitment = normalizeCommitment(commitmentOrConfig.commitment);
320
- dataSlice = commitmentOrConfig.dataSlice;
321
- filters = commitmentOrConfig.filters;
322
- encoding = commitmentOrConfig.encoding;
323
- minContextSlot = toBigInt(commitmentOrConfig.minContextSlot);
324
- withContext = Boolean(commitmentOrConfig.withContext);
325
- }
326
- const requestOptions = {
327
- commitment: localCommitment ?? this.commitment ?? DEFAULT_COMMITMENT,
328
- withContext
329
- };
330
- if (dataSlice) {
331
- requestOptions.dataSlice = {
332
- length: dataSlice.length,
333
- offset: dataSlice.offset
334
- };
335
- }
336
- if (encoding) {
337
- requestOptions.encoding = encoding;
338
- }
339
- if (filters) {
340
- requestOptions.filters = filters.map((filter) => filter);
341
- }
342
- if (minContextSlot !== void 0) {
343
- requestOptions.minContextSlot = minContextSlot;
344
- }
345
- const result = await this.#client.rpc.getProgramAccounts(id, requestOptions).send();
346
- const mapProgramAccount = /* @__PURE__ */ __name((entry) => {
347
- const pubkey = new PublicKey(entry.pubkey);
348
- return {
349
- account: toAccountInfo(fromKitAccount(entry.account), dataSlice),
350
- pubkey
351
- };
352
- }, "mapProgramAccount");
353
- if (withContext && typeof result.context !== "undefined") {
354
- const contextual = result;
355
- return {
356
- context: {
357
- apiVersion: contextual.context.apiVersion,
358
- slot: Number(contextual.context.slot)
359
- },
360
- value: contextual.value.map(mapProgramAccount)
361
- };
362
- }
363
- return result.map(mapProgramAccount);
364
- }
365
- async getSignatureStatuses(signatures, config) {
366
- const targetCommitment = normalizeCommitment(config?.commitment) ?? this.commitment ?? DEFAULT_COMMITMENT;
367
- const kitSignatures = signatures.map((signature) => signature);
368
- const response = await this.#client.rpc.getSignatureStatuses(kitSignatures, {
369
- commitment: targetCommitment,
370
- searchTransactionHistory: config?.searchTransactionHistory
371
- }).send();
372
- const context = response.context;
373
- const normalizedContext = {
374
- apiVersion: context?.apiVersion,
375
- slot: typeof context?.slot === "bigint" ? Number(context.slot) : context?.slot ?? 0
376
- };
377
- const normalizedValues = response.value.map(
378
- (status) => {
379
- if (!status) {
380
- return null;
381
- }
382
- const record = status;
383
- const slot = record.slot;
384
- const confirmations = record.confirmations;
385
- const normalizedConfirmations = confirmations === null ? null : confirmations === void 0 ? null : typeof confirmations === "bigint" ? Number(confirmations) : confirmations;
386
- return {
387
- err: record.err ?? null,
388
- confirmations: normalizedConfirmations,
389
- confirmationStatus: record.confirmationStatus,
390
- slot: slot === void 0 ? 0 : typeof slot === "bigint" ? Number(slot) : slot
391
- };
392
- }
393
- );
394
- return {
395
- context: normalizedContext,
396
- value: normalizedValues
397
- };
398
- }
399
- async sendRawTransaction(rawTransaction, options) {
400
- const wire = toBase64WireTransaction(rawTransaction);
401
- const preflightCommitment = normalizeCommitment(
402
- options?.preflightCommitment ?? options?.commitment
403
- ) ?? this.commitment ?? DEFAULT_COMMITMENT;
404
- const maxRetries = options?.maxRetries === void 0 ? void 0 : toBigInt(options.maxRetries);
405
- const minContextSlot = options?.minContextSlot === void 0 ? void 0 : toBigInt(options.minContextSlot);
406
- const plan = this.#client.rpc.sendTransaction(wire, {
407
- encoding: "base64",
408
- maxRetries,
409
- minContextSlot,
410
- preflightCommitment,
411
- skipPreflight: options?.skipPreflight
412
- });
413
- return await plan.send();
414
- }
415
- async confirmTransaction(signature, commitment) {
416
- const normalizedCommitment = normalizeCommitment(commitment);
417
- const response = await this.getSignatureStatuses([signature], {
418
- commitment: normalizedCommitment ?? this.commitment ?? DEFAULT_COMMITMENT,
419
- searchTransactionHistory: true
420
- });
421
- return {
422
- context: response.context,
423
- value: response.value[0] ?? null
424
- };
425
- }
426
- async simulateTransaction(transaction, config) {
427
- const wire = toBase64WireTransaction(transaction);
428
- const commitment = normalizeCommitment(config?.commitment) ?? this.commitment ?? DEFAULT_COMMITMENT;
429
- const baseConfig = {
430
- ...config ?? {},
431
- commitment
432
- };
433
- const mergedConfig = {
434
- ...DEFAULT_SIMULATION_CONFIG2,
435
- ...baseConfig,
436
- commitment
437
- };
438
- const normalizedConfig = mergedConfig.sigVerify === true && mergedConfig.replaceRecentBlockhash !== false ? { ...mergedConfig, replaceRecentBlockhash: false } : mergedConfig;
439
- const response = await this.#client.rpc.simulateTransaction(wire, normalizedConfig).send();
440
- return {
441
- context: {
442
- apiVersion: response.context?.apiVersion,
443
- slot: Number(response.context?.slot ?? 0)
444
- },
445
- value: response.value
446
- };
447
- }
448
- };
449
- var TRANSFER_INSTRUCTION_INDEX = 2;
450
- var SystemProgram = Object.freeze({
451
- ...SystemProgram$1,
452
- transfer({ fromPubkey, toPubkey, lamports }) {
453
- const data = Buffer.alloc(12);
454
- data.writeUInt32LE(TRANSFER_INSTRUCTION_INDEX, 0);
455
- data.writeBigUInt64LE(BigInt(lamports), 4);
456
- return new TransactionInstruction({
457
- data,
458
- keys: [
459
- { isSigner: true, isWritable: true, pubkey: fromPubkey },
460
- { isSigner: false, isWritable: true, pubkey: toPubkey }
461
- ],
462
- programId: SystemProgram$1.programId
463
- });
464
- }
465
- });
466
- var LAMPORTS_PER_SOL = LAMPORTS_PER_SOL$1;
467
- function serializeTransactionBytes(input) {
468
- if (input instanceof VersionedTransaction) {
469
- return input.serialize();
470
- }
471
- return input.serialize({ requireAllSignatures: false });
472
- }
473
- __name(serializeTransactionBytes, "serializeTransactionBytes");
474
- function compileFromCompat(transaction) {
475
- const bytes = serializeTransactionBytes(transaction);
476
- return Buffer.from(bytes).toString("base64");
477
- }
478
- __name(compileFromCompat, "compileFromCompat");
479
- function applySigners(transaction, signers = []) {
480
- if (!signers.length) {
481
- return;
482
- }
483
- if (transaction instanceof VersionedTransaction) {
484
- transaction.sign([...signers]);
485
- } else {
486
- transaction.partialSign(...signers);
487
- }
488
- }
489
- __name(applySigners, "applySigners");
490
- async function sendAndConfirmTransaction(connection, transaction, signers = [], options = {}) {
491
- applySigners(transaction, signers);
492
- const serialized = compileFromCompat(transaction);
493
- const raw = Buffer.from(serialized, "base64");
494
- const signature = await connection.sendRawTransaction(raw, options);
495
- const commitment = options.commitment ?? connection.commitment ?? "confirmed";
496
- const confirmation = await connection.confirmTransaction(signature, commitment);
497
- if (confirmation.value?.err) {
498
- throw new Error("Transaction failed");
499
- }
500
- return signature;
501
- }
502
- __name(sendAndConfirmTransaction, "sendAndConfirmTransaction");
503
-
504
- export { Connection, LAMPORTS_PER_SOL, SystemProgram, compileFromCompat, fromWeb3Instruction, sendAndConfirmTransaction, toAddress, toKitSigner, toPublicKey, toWeb3Instruction };
505
- //# sourceMappingURL=index.browser.mjs.map
1
+ import {SystemProgram,TransactionInstruction,PublicKey,Transaction,VersionedTransaction,LAMPORTS_PER_SOL}from'@solana/web3.js';export{Keypair,PublicKey,Transaction,TransactionInstruction,VersionedTransaction}from'@solana/web3.js';import {fromLegacyPublicKey,fromLegacyTransactionInstruction}from'@solana/compat';import {createSolanaRpc,createSolanaRpcSubscriptions,getBase64EncodedWireTransaction,createKeyPairSignerFromBytes,AccountRole}from'@solana/kit';import {createBlockHeightExceedencePromiseFactory,createRecentSignatureConfirmationPromiseFactory,waitForRecentTransactionConfirmation}from'@solana/transaction-confirmation';var z=Object.defineProperty;var s=(e,n)=>z(e,"name",{value:n,configurable:true});function x(e){let n=e instanceof PublicKey?e:new PublicKey(e);return fromLegacyPublicKey(n)}s(x,"toAddress");function h(e){return e instanceof PublicKey?e:typeof e=="string"?new PublicKey(e):new PublicKey(e)}s(h,"toPublicKey");async function U(e,n={}){let t=new Uint8Array(64);return t.set(e.secretKey),t.set(e.publicKey.toBytes(),32),await createKeyPairSignerFromBytes(t,n.extractable??false)}s(U,"toKitSigner");function _(e){let n=e.accounts?.map(a=>{let o=a.role,i=o===AccountRole.READONLY_SIGNER||o===AccountRole.WRITABLE_SIGNER,r=o===AccountRole.WRITABLE||o===AccountRole.WRITABLE_SIGNER;return {isSigner:i,isWritable:r,pubkey:h(a.address)}})??[],t=e.data?Buffer.from(e.data):Buffer.alloc(0);return new TransactionInstruction({data:t,keys:n,programId:h(e.programAddress)})}s(_,"toWeb3Instruction");function H(e){return fromLegacyTransactionInstruction(e)}s(H,"fromWeb3Instruction");function X(e){let n=new AbortController;if(!e)return n;if(e.aborted)return n.abort(e.reason),n;let t=s(()=>{n.abort(e.reason),e.removeEventListener("abort",t);},"onAbort");return e.addEventListener("abort",t,{once:true}),n}s(X,"createChainedAbortController");function w(e){if(e!==void 0)return typeof e=="bigint"?e:BigInt(Math.floor(e))}s(w,"toBigint");var Y=Object.freeze({encoding:"base64",replaceRecentBlockhash:true,sigVerify:false});function A(e){let n=e.endpoint,t=e.websocketEndpoint??n,a=e.commitment??"confirmed",o=createSolanaRpc(n,e.rpcConfig),i=createSolanaRpcSubscriptions(t,e.rpcSubscriptionsConfig);async function r(l,c={}){let p=X(c.abortSignal),u=c.commitment??a,f=getBase64EncodedWireTransaction(l),d=await o.sendTransaction(f,{encoding:"base64",maxRetries:w(c.maxRetries),minContextSlot:w(c.minContextSlot),preflightCommitment:u,skipPreflight:c.skipPreflight}).send({abortSignal:p.signal}),R=createBlockHeightExceedencePromiseFactory({rpc:o,rpcSubscriptions:i}),V=createRecentSignatureConfirmationPromiseFactory({rpc:o,rpcSubscriptions:i});return await waitForRecentTransactionConfirmation({abortSignal:p.signal,commitment:u,getBlockHeightExceedencePromise:R,getRecentSignatureConfirmationPromise:V,transaction:l}),d}s(r,"sendAndConfirmTransaction");async function m(l,c={}){let p=getBase64EncodedWireTransaction(l),u=c.config??{},f={...Y,...u,commitment:u.commitment??c.commitment??a},d=f.sigVerify===true&&f.replaceRecentBlockhash!==false?{...f,replaceRecentBlockhash:false}:f;return o.simulateTransaction(p,d).send({abortSignal:c.abortSignal})}return s(m,"simulateTransaction"),{commitment:a,endpoint:n,rpc:o,rpcSubscriptions:i,sendAndConfirmTransaction:r,simulateTransaction:m,websocketEndpoint:t}}s(A,"createSolanaRpcClient");var S="confirmed",$=Object.freeze({encoding:"base64",replaceRecentBlockhash:true,sigVerify:false});function y(e){if(e!=null)return e==="recent"||e==="singleGossip"?"processed":e==="single"?"confirmed":e==="max"?"finalized":e}s(y,"normalizeCommitment");function C(e){if(e!==void 0)return typeof e=="bigint"?e:BigInt(Math.trunc(e))}s(C,"toBigInt");function B(e,n){let{data:t,executable:a,lamports:o,owner:i,rentEpoch:r}=e,[m,l]=Array.isArray(t)?t:[t,"base64"],c=l==="base64"?Buffer.from(m,"base64"):Buffer.from(m);if(n){let p=n.offset??0,u=p+(n.length??c.length);c=c.subarray(p,u);}return {data:c,executable:a,lamports:typeof o=="number"?o:Number(o),owner:new PublicKey(i),rentEpoch:typeof r=="number"?r:Number(r)}}s(B,"toAccountInfo");function L(e){let n=e??{},t=n.data,a=n.lamports,o=n.owner,i=n.rentEpoch,r=typeof o=="string"?o:o instanceof PublicKey?o.toBase58():typeof o=="object"&&o!==null&&"toString"in o?String(o):"11111111111111111111111111111111";return {data:t??["","base64"],executable:!!n.executable,lamports:a??0,owner:r,rentEpoch:i??0}}s(L,"fromKitAccount");function P(e){return x((e))}s(P,"toKitAddressFromInput");function W(e){if(e instanceof Transaction||e instanceof VersionedTransaction){let t=e.serialize({requireAllSignatures:false,verifySignatures:false});return Buffer.from(t).toString("base64")}if(e instanceof Uint8Array)return Buffer.from(e).toString("base64");if(e instanceof Buffer)return e.toString("base64");let n=Uint8Array.from(e);return Buffer.from(n).toString("base64")}s(W,"toBase64WireTransaction");var k=class{static{s(this,"Connection");}commitment;rpcEndpoint;#e;constructor(n,t){let a=typeof t=="string"?y(t):y(t?.commitment)??S,o=typeof t=="object"&&t!==null?t.wsEndpoint:void 0;this.commitment=a,this.rpcEndpoint=n,this.#e=A({endpoint:n,websocketEndpoint:o,commitment:a??S});}async getLatestBlockhash(n){let t=typeof n=="string"?n:n?.commitment,a=y(t)??this.commitment??S,o=typeof n=="object"?C(n.minContextSlot):void 0,i={commitment:a};o!==void 0&&(i.minContextSlot=o),typeof n=="object"&&n?.maxSupportedTransactionVersion!==void 0&&(i.maxSupportedTransactionVersion=n.maxSupportedTransactionVersion);let r=await this.#e.rpc.getLatestBlockhash(i).send();return {blockhash:r.value.blockhash,lastValidBlockHeight:Number(r.value.lastValidBlockHeight)}}async getBalance(n,t){let a=P(n),o=y(t)??this.commitment??S,i=await this.#e.rpc.getBalance(a,{commitment:o}).send();return typeof i.value=="number"?i.value:Number(i.value)}async getAccountInfo(n,t){let a=P(n),o,i,r,m;typeof t=="string"?o=y(t):t&&(o=y(t.commitment),t.minContextSlot!==void 0&&(i=C(t.minContextSlot)),r=t.dataSlice,m=t.encoding);let l={commitment:o??this.commitment??S};i!==void 0&&(l.minContextSlot=i),m&&(l.encoding=m),r&&(l.dataSlice={length:r.length,offset:r.offset});let c=await this.#e.rpc.getAccountInfo(a,l).send();return c.value?B(L(c.value),r):null}async getProgramAccounts(n,t){let a=P(n),o,i,r,m,l,c=false;typeof t=="string"?o=y(t):t&&(o=y(t.commitment),i=t.dataSlice,r=t.filters,m=t.encoding,l=C(t.minContextSlot),c=!!t.withContext);let p={commitment:o??this.commitment??S,withContext:c};i&&(p.dataSlice={length:i.length,offset:i.offset}),m&&(p.encoding=m),r&&(p.filters=r.map(d=>d)),l!==void 0&&(p.minContextSlot=l);let u=await this.#e.rpc.getProgramAccounts(a,p).send(),f=s(d=>{let R=new PublicKey(d.pubkey);return {account:B(L(d.account),i),pubkey:R}},"mapProgramAccount");if(c&&typeof u.context<"u"){let d=u;return {context:{apiVersion:d.context.apiVersion,slot:Number(d.context.slot)},value:d.value.map(f)}}return u.map(f)}async getSignatureStatuses(n,t){let a=y(t?.commitment)??this.commitment??S,o=n.map(c=>c),i=await this.#e.rpc.getSignatureStatuses(o,{commitment:a,searchTransactionHistory:t?.searchTransactionHistory}).send(),r=i.context,m={apiVersion:r?.apiVersion,slot:typeof r?.slot=="bigint"?Number(r.slot):r?.slot??0},l=i.value.map(c=>{if(!c)return null;let p=c,u=p.slot,f=p.confirmations,d=f===null||f===void 0?null:typeof f=="bigint"?Number(f):f;return {err:p.err??null,confirmations:d,confirmationStatus:p.confirmationStatus,slot:u===void 0?0:typeof u=="bigint"?Number(u):u}});return {context:m,value:l}}async sendRawTransaction(n,t){let a=W(n),o=y(t?.preflightCommitment??t?.commitment)??this.commitment??S,i=t?.maxRetries===void 0?void 0:C(t.maxRetries),r=t?.minContextSlot===void 0?void 0:C(t.minContextSlot);return await this.#e.rpc.sendTransaction(a,{encoding:"base64",maxRetries:i,minContextSlot:r,preflightCommitment:o,skipPreflight:t?.skipPreflight}).send()}async confirmTransaction(n,t){let a=y(t),o=await this.getSignatureStatuses([n],{commitment:a??this.commitment??S,searchTransactionHistory:true});return {context:o.context,value:o.value[0]??null}}async simulateTransaction(n,t){let a=W(n),o=y(t?.commitment)??this.commitment??S,i={...t??{},commitment:o},r={...$,...i,commitment:o},m=r.sigVerify===true&&r.replaceRecentBlockhash!==false?{...r,replaceRecentBlockhash:false}:r,l=await this.#e.rpc.simulateTransaction(a,m).send();return {context:{apiVersion:l.context?.apiVersion,slot:Number(l.context?.slot??0)},value:l.value}}};var te=2,ne=Object.freeze({...SystemProgram,transfer({fromPubkey:e,toPubkey:n,lamports:t}){let a=Buffer.alloc(12);return a.writeUInt32LE(te,0),a.writeBigUInt64LE(BigInt(t),4),new TransactionInstruction({data:a,keys:[{isSigner:true,isWritable:true,pubkey:e},{isSigner:false,isWritable:true,pubkey:n}],programId:SystemProgram.programId})}});var re=LAMPORTS_PER_SOL;function ae(e){return e instanceof VersionedTransaction?e.serialize():e.serialize({requireAllSignatures:false})}s(ae,"serializeTransactionBytes");function N(e){let n=ae(e);return Buffer.from(n).toString("base64")}s(N,"compileFromCompat");function ie(e,n=[]){n.length&&(e instanceof VersionedTransaction?e.sign([...n]):e.partialSign(...n));}s(ie,"applySigners");async function se(e,n,t=[],a={}){ie(n,t);let o=N(n),i=Buffer.from(o,"base64"),r=await e.sendRawTransaction(i,a),m=a.commitment??e.commitment??"confirmed";if((await e.confirmTransaction(r,m)).value?.err)throw new Error("Transaction failed");return r}s(se,"sendAndConfirmTransaction");export{k as Connection,re as LAMPORTS_PER_SOL,ne as SystemProgram,N as compileFromCompat,H as fromWeb3Instruction,se as sendAndConfirmTransaction,x as toAddress,U as toKitSigner,h as toPublicKey,_ as toWeb3Instruction};//# sourceMappingURL=index.browser.mjs.map
506
2
  //# sourceMappingURL=index.browser.mjs.map