@solana/web3.js 1.47.2 → 1.48.0

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/lib/index.esm.js CHANGED
@@ -3,9 +3,9 @@ import { Buffer } from 'buffer';
3
3
  import BN from 'bn.js';
4
4
  import bs58 from 'bs58';
5
5
  import { serialize, deserialize, deserializeUnchecked } from 'borsh';
6
+ import { toBigIntLE, toBufferLE } from 'bigint-buffer';
6
7
  import * as BufferLayout from '@solana/buffer-layout';
7
8
  import { blob } from '@solana/buffer-layout';
8
- import { toBigIntLE, toBufferLE } from 'bigint-buffer';
9
9
  import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$7 } from 'superstruct';
10
10
  import { Client } from 'rpc-websockets';
11
11
  import RpcClient from 'jayson/lib/client/browser';
@@ -2094,18 +2094,6 @@ class Account {
2094
2094
 
2095
2095
  }
2096
2096
 
2097
- const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
2098
-
2099
- /**
2100
- * Maximum over-the-wire size of a Transaction
2101
- *
2102
- * 1280 is IPv6 minimum MTU
2103
- * 40 bytes is the size of the IPv6 header
2104
- * 8 bytes is the size of the fragment header
2105
- */
2106
- const PACKET_DATA_SIZE = 1280 - 40 - 8;
2107
- const SIGNATURE_LENGTH_IN_BYTES = 64;
2108
-
2109
2097
  /**
2110
2098
  * Layout for a public key
2111
2099
  */
@@ -2167,17 +2155,170 @@ const voteInit = (property = 'voteInit') => {
2167
2155
  return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
2168
2156
  };
2169
2157
  function getAlloc(type, fields) {
2170
- let alloc = 0;
2171
- type.layout.fields.forEach(item => {
2158
+ const getItemAlloc = item => {
2172
2159
  if (item.span >= 0) {
2173
- alloc += item.span;
2160
+ return item.span;
2174
2161
  } else if (typeof item.alloc === 'function') {
2175
- alloc += item.alloc(fields[item.property]);
2176
- }
2162
+ return item.alloc(fields[item.property]);
2163
+ } else if ('count' in item && 'elementLayout' in item) {
2164
+ const field = fields[item.property];
2165
+
2166
+ if (Array.isArray(field)) {
2167
+ return field.length * getItemAlloc(item.elementLayout);
2168
+ }
2169
+ } // Couldn't determine allocated size of layout
2170
+
2171
+
2172
+ return 0;
2173
+ };
2174
+
2175
+ let alloc = 0;
2176
+ type.layout.fields.forEach(item => {
2177
+ alloc += getItemAlloc(item);
2177
2178
  });
2178
2179
  return alloc;
2179
2180
  }
2180
2181
 
2182
+ const encodeDecode = layout => {
2183
+ const decode = layout.decode.bind(layout);
2184
+ const encode = layout.encode.bind(layout);
2185
+ return {
2186
+ decode,
2187
+ encode
2188
+ };
2189
+ };
2190
+
2191
+ const bigInt = length => property => {
2192
+ const layout = blob(length, property);
2193
+ const {
2194
+ encode,
2195
+ decode
2196
+ } = encodeDecode(layout);
2197
+ const bigIntLayout = layout;
2198
+
2199
+ bigIntLayout.decode = (buffer, offset) => {
2200
+ const src = decode(buffer, offset);
2201
+ return toBigIntLE(Buffer.from(src));
2202
+ };
2203
+
2204
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
2205
+ const src = toBufferLE(bigInt, length);
2206
+ return encode(src, buffer, offset);
2207
+ };
2208
+
2209
+ return bigIntLayout;
2210
+ };
2211
+
2212
+ const u64 = bigInt(8);
2213
+
2214
+ /**
2215
+ * Populate a buffer of instruction data using an InstructionType
2216
+ * @internal
2217
+ */
2218
+ function encodeData(type, fields) {
2219
+ const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
2220
+ const data = Buffer.alloc(allocLength);
2221
+ const layoutFields = Object.assign({
2222
+ instruction: type.index
2223
+ }, fields);
2224
+ type.layout.encode(layoutFields, data);
2225
+ return data;
2226
+ }
2227
+ /**
2228
+ * Decode instruction data buffer using an InstructionType
2229
+ * @internal
2230
+ */
2231
+
2232
+ function decodeData(type, buffer) {
2233
+ let data;
2234
+
2235
+ try {
2236
+ data = type.layout.decode(buffer);
2237
+ } catch (err) {
2238
+ throw new Error('invalid instruction; ' + err);
2239
+ }
2240
+
2241
+ if (data.instruction !== type.index) {
2242
+ throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
2243
+ }
2244
+
2245
+ return data;
2246
+ }
2247
+
2248
+ /**
2249
+ * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
2250
+ *
2251
+ * @internal
2252
+ */
2253
+
2254
+ const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
2255
+ /**
2256
+ * Calculator for transaction fees.
2257
+ */
2258
+
2259
+ /**
2260
+ * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
2261
+ *
2262
+ * @internal
2263
+ */
2264
+
2265
+ const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
2266
+ const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
2267
+
2268
+ /**
2269
+ * NonceAccount class
2270
+ */
2271
+ class NonceAccount {
2272
+ /**
2273
+ * @internal
2274
+ */
2275
+ constructor(args) {
2276
+ this.authorizedPubkey = void 0;
2277
+ this.nonce = void 0;
2278
+ this.feeCalculator = void 0;
2279
+ this.authorizedPubkey = args.authorizedPubkey;
2280
+ this.nonce = args.nonce;
2281
+ this.feeCalculator = args.feeCalculator;
2282
+ }
2283
+ /**
2284
+ * Deserialize NonceAccount from the account data.
2285
+ *
2286
+ * @param buffer account data
2287
+ * @return NonceAccount
2288
+ */
2289
+
2290
+
2291
+ static fromAccountData(buffer) {
2292
+ const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
2293
+ return new NonceAccount({
2294
+ authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
2295
+ nonce: new PublicKey(nonceAccount.nonce).toString(),
2296
+ feeCalculator: nonceAccount.feeCalculator
2297
+ });
2298
+ }
2299
+
2300
+ }
2301
+
2302
+ const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2303
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2304
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2305
+ const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2306
+ const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2307
+ const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2308
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2309
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2310
+ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2311
+
2312
+ /**
2313
+ * Maximum over-the-wire size of a Transaction
2314
+ *
2315
+ * 1280 is IPv6 minimum MTU
2316
+ * 40 bytes is the size of the IPv6 header
2317
+ * 8 bytes is the size of the fragment header
2318
+ */
2319
+ const PACKET_DATA_SIZE = 1280 - 40 - 8;
2320
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
2321
+
2181
2322
  function decodeLength(bytes) {
2182
2323
  let len = 0;
2183
2324
  let size = 0;
@@ -2471,15 +2612,34 @@ class Transaction {
2471
2612
 
2472
2613
  if (!opts) {
2473
2614
  return;
2474
- } else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
2475
- const newOpts = opts;
2476
- Object.assign(this, newOpts);
2477
- this.recentBlockhash = newOpts.blockhash;
2478
- this.lastValidBlockHeight = newOpts.lastValidBlockHeight;
2615
+ }
2616
+
2617
+ if (opts.feePayer) {
2618
+ this.feePayer = opts.feePayer;
2619
+ }
2620
+
2621
+ if (opts.signatures) {
2622
+ this.signatures = opts.signatures;
2623
+ }
2624
+
2625
+ if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
2626
+ const {
2627
+ blockhash,
2628
+ lastValidBlockHeight
2629
+ } = opts;
2630
+ this.recentBlockhash = blockhash;
2631
+ this.lastValidBlockHeight = lastValidBlockHeight;
2479
2632
  } else {
2480
- const oldOpts = opts;
2481
- Object.assign(this, oldOpts);
2482
- this.recentBlockhash = oldOpts.recentBlockhash;
2633
+ const {
2634
+ recentBlockhash,
2635
+ nonceInfo
2636
+ } = opts;
2637
+
2638
+ if (nonceInfo) {
2639
+ this.nonceInfo = nonceInfo;
2640
+ }
2641
+
2642
+ this.recentBlockhash = recentBlockhash;
2483
2643
  }
2484
2644
  }
2485
2645
  /**
@@ -3072,188 +3232,21 @@ class Transaction {
3072
3232
 
3073
3233
  }
3074
3234
 
3075
- const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3076
- const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3077
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
3078
- const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
3079
- const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
3080
- const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
3081
- const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
3082
- const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
3083
- const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
3084
-
3085
3235
  /**
3086
- * Sign, send and confirm a transaction.
3087
- *
3088
- * If `commitment` option is not specified, defaults to 'max' commitment.
3089
- *
3090
- * @param {Connection} connection
3091
- * @param {Transaction} transaction
3092
- * @param {Array<Signer>} signers
3093
- * @param {ConfirmOptions} [options]
3094
- * @returns {Promise<TransactionSignature>}
3236
+ * Create account system transaction params
3095
3237
  */
3096
- async function sendAndConfirmTransaction(connection, transaction, signers, options) {
3097
- const sendOptions = options && {
3098
- skipPreflight: options.skipPreflight,
3099
- preflightCommitment: options.preflightCommitment || options.commitment,
3100
- maxRetries: options.maxRetries,
3101
- minContextSlot: options.minContextSlot
3102
- };
3103
- const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3104
- const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
3105
- signature: signature,
3106
- blockhash: transaction.recentBlockhash,
3107
- lastValidBlockHeight: transaction.lastValidBlockHeight
3108
- }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
3109
-
3110
- if (status.err) {
3111
- throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
3112
- }
3113
-
3114
- return signature;
3115
- }
3116
3238
 
3117
- // zzz
3118
- function sleep(ms) {
3119
- return new Promise(resolve => setTimeout(resolve, ms));
3120
- }
3121
-
3122
- /**
3123
- * Populate a buffer of instruction data using an InstructionType
3124
- * @internal
3125
- */
3126
- function encodeData(type, fields) {
3127
- const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
3128
- const data = Buffer.alloc(allocLength);
3129
- const layoutFields = Object.assign({
3130
- instruction: type.index
3131
- }, fields);
3132
- type.layout.encode(layoutFields, data);
3133
- return data;
3134
- }
3135
3239
  /**
3136
- * Decode instruction data buffer using an InstructionType
3137
- * @internal
3240
+ * System Instruction class
3138
3241
  */
3139
-
3140
- function decodeData(type, buffer) {
3141
- let data;
3142
-
3143
- try {
3144
- data = type.layout.decode(buffer);
3145
- } catch (err) {
3146
- throw new Error('invalid instruction; ' + err);
3147
- }
3148
-
3149
- if (data.instruction !== type.index) {
3150
- throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
3151
- }
3152
-
3153
- return data;
3154
- }
3155
-
3156
- /**
3157
- * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
3158
- *
3159
- * @internal
3160
- */
3161
-
3162
- const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
3163
- /**
3164
- * Calculator for transaction fees.
3165
- */
3166
-
3167
- /**
3168
- * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
3169
- *
3170
- * @internal
3171
- */
3172
-
3173
- const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
3174
- const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
3175
-
3176
- /**
3177
- * NonceAccount class
3178
- */
3179
- class NonceAccount {
3180
- /**
3181
- * @internal
3182
- */
3183
- constructor(args) {
3184
- this.authorizedPubkey = void 0;
3185
- this.nonce = void 0;
3186
- this.feeCalculator = void 0;
3187
- this.authorizedPubkey = args.authorizedPubkey;
3188
- this.nonce = args.nonce;
3189
- this.feeCalculator = args.feeCalculator;
3190
- }
3191
- /**
3192
- * Deserialize NonceAccount from the account data.
3193
- *
3194
- * @param buffer account data
3195
- * @return NonceAccount
3196
- */
3197
-
3198
-
3199
- static fromAccountData(buffer) {
3200
- const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
3201
- return new NonceAccount({
3202
- authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
3203
- nonce: new PublicKey(nonceAccount.nonce).toString(),
3204
- feeCalculator: nonceAccount.feeCalculator
3205
- });
3206
- }
3207
-
3208
- }
3209
-
3210
- const encodeDecode = layout => {
3211
- const decode = layout.decode.bind(layout);
3212
- const encode = layout.encode.bind(layout);
3213
- return {
3214
- decode,
3215
- encode
3216
- };
3217
- };
3218
-
3219
- const bigInt = length => property => {
3220
- const layout = blob(length, property);
3221
- const {
3222
- encode,
3223
- decode
3224
- } = encodeDecode(layout);
3225
- const bigIntLayout = layout;
3226
-
3227
- bigIntLayout.decode = (buffer, offset) => {
3228
- const src = decode(buffer, offset);
3229
- return toBigIntLE(Buffer.from(src));
3230
- };
3231
-
3232
- bigIntLayout.encode = (bigInt, buffer, offset) => {
3233
- const src = toBufferLE(bigInt, length);
3234
- return encode(src, buffer, offset);
3235
- };
3236
-
3237
- return bigIntLayout;
3238
- };
3239
-
3240
- const u64 = bigInt(8);
3241
-
3242
- /**
3243
- * Create account system transaction params
3244
- */
3245
-
3246
- /**
3247
- * System Instruction class
3248
- */
3249
- class SystemInstruction {
3250
- /**
3251
- * @internal
3252
- */
3253
- constructor() {}
3254
- /**
3255
- * Decode a system instruction and retrieve the instruction type.
3256
- */
3242
+ class SystemInstruction {
3243
+ /**
3244
+ * @internal
3245
+ */
3246
+ constructor() {}
3247
+ /**
3248
+ * Decode a system instruction and retrieve the instruction type.
3249
+ */
3257
3250
 
3258
3251
 
3259
3252
  static decodeInstructionType(instruction) {
@@ -3954,6 +3947,312 @@ class SystemProgram {
3954
3947
  }
3955
3948
  SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3956
3949
 
3950
+ /**
3951
+ * An enumeration of valid address lookup table InstructionType's
3952
+ * @internal
3953
+ */
3954
+ const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
3955
+ CreateLookupTable: {
3956
+ index: 0,
3957
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64('recentSlot'), BufferLayout.u8('bumpSeed')])
3958
+ },
3959
+ FreezeLookupTable: {
3960
+ index: 1,
3961
+ layout: BufferLayout.struct([BufferLayout.u32('instruction')])
3962
+ },
3963
+ ExtendLookupTable: {
3964
+ index: 2,
3965
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64(), BufferLayout.seq(publicKey(), BufferLayout.offset(BufferLayout.u32(), -8), 'addresses')])
3966
+ },
3967
+ DeactivateLookupTable: {
3968
+ index: 3,
3969
+ layout: BufferLayout.struct([BufferLayout.u32('instruction')])
3970
+ },
3971
+ CloseLookupTable: {
3972
+ index: 4,
3973
+ layout: BufferLayout.struct([BufferLayout.u32('instruction')])
3974
+ }
3975
+ });
3976
+ class AddressLookupTableInstruction {
3977
+ /**
3978
+ * @internal
3979
+ */
3980
+ constructor() {}
3981
+
3982
+ static decodeInstructionType(instruction) {
3983
+ this.checkProgramId(instruction.programId);
3984
+ const instructionTypeLayout = BufferLayout.u32('instruction');
3985
+ const index = instructionTypeLayout.decode(instruction.data);
3986
+ let type;
3987
+
3988
+ for (const [layoutType, layout] of Object.entries(LOOKUP_TABLE_INSTRUCTION_LAYOUTS)) {
3989
+ if (layout.index == index) {
3990
+ type = layoutType;
3991
+ break;
3992
+ }
3993
+ }
3994
+
3995
+ if (!type) {
3996
+ throw new Error('Invalid Instruction. Should be a LookupTable Instruction');
3997
+ }
3998
+
3999
+ return type;
4000
+ }
4001
+
4002
+ static decodeCreateLookupTable(instruction) {
4003
+ this.checkProgramId(instruction.programId);
4004
+ this.checkKeysLength(instruction.keys, 4);
4005
+ const {
4006
+ recentSlot
4007
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable, instruction.data);
4008
+ return {
4009
+ authority: instruction.keys[1].pubkey,
4010
+ payer: instruction.keys[2].pubkey,
4011
+ recentSlot: Number(recentSlot)
4012
+ };
4013
+ }
4014
+
4015
+ static decodeExtendLookupTable(instruction) {
4016
+ this.checkProgramId(instruction.programId);
4017
+
4018
+ if (instruction.keys.length < 2) {
4019
+ throw new Error(`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`);
4020
+ }
4021
+
4022
+ const {
4023
+ addresses
4024
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable, instruction.data);
4025
+ return {
4026
+ lookupTable: instruction.keys[0].pubkey,
4027
+ authority: instruction.keys[1].pubkey,
4028
+ payer: instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
4029
+ addresses: addresses.map(buffer => new PublicKey(buffer))
4030
+ };
4031
+ }
4032
+
4033
+ static decodeCloseLookupTable(instruction) {
4034
+ this.checkProgramId(instruction.programId);
4035
+ this.checkKeysLength(instruction.keys, 3);
4036
+ return {
4037
+ lookupTable: instruction.keys[0].pubkey,
4038
+ authority: instruction.keys[1].pubkey,
4039
+ recipient: instruction.keys[2].pubkey
4040
+ };
4041
+ }
4042
+
4043
+ static decodeFreezeLookupTable(instruction) {
4044
+ this.checkProgramId(instruction.programId);
4045
+ this.checkKeysLength(instruction.keys, 2);
4046
+ return {
4047
+ lookupTable: instruction.keys[0].pubkey,
4048
+ authority: instruction.keys[1].pubkey
4049
+ };
4050
+ }
4051
+
4052
+ static decodeDeactivateLookupTable(instruction) {
4053
+ this.checkProgramId(instruction.programId);
4054
+ this.checkKeysLength(instruction.keys, 2);
4055
+ return {
4056
+ lookupTable: instruction.keys[0].pubkey,
4057
+ authority: instruction.keys[1].pubkey
4058
+ };
4059
+ }
4060
+ /**
4061
+ * @internal
4062
+ */
4063
+
4064
+
4065
+ static checkProgramId(programId) {
4066
+ if (!programId.equals(AddressLookupTableProgram.programId)) {
4067
+ throw new Error('invalid instruction; programId is not AddressLookupTable Program');
4068
+ }
4069
+ }
4070
+ /**
4071
+ * @internal
4072
+ */
4073
+
4074
+
4075
+ static checkKeysLength(keys, expectedLength) {
4076
+ if (keys.length < expectedLength) {
4077
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
4078
+ }
4079
+ }
4080
+
4081
+ }
4082
+ class AddressLookupTableProgram {
4083
+ /**
4084
+ * @internal
4085
+ */
4086
+ constructor() {}
4087
+
4088
+ static createLookupTable(params) {
4089
+ const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
4090
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
4091
+ const data = encodeData(type, {
4092
+ recentSlot: BigInt(params.recentSlot),
4093
+ bumpSeed: bumpSeed
4094
+ });
4095
+ const keys = [{
4096
+ pubkey: lookupTableAddress,
4097
+ isSigner: false,
4098
+ isWritable: true
4099
+ }, {
4100
+ pubkey: params.authority,
4101
+ isSigner: true,
4102
+ isWritable: false
4103
+ }, {
4104
+ pubkey: params.payer,
4105
+ isSigner: true,
4106
+ isWritable: true
4107
+ }, {
4108
+ pubkey: SystemProgram.programId,
4109
+ isSigner: false,
4110
+ isWritable: false
4111
+ }];
4112
+ return [new TransactionInstruction({
4113
+ programId: this.programId,
4114
+ keys: keys,
4115
+ data: data
4116
+ }), lookupTableAddress];
4117
+ }
4118
+
4119
+ static freezeLookupTable(params) {
4120
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
4121
+ const data = encodeData(type);
4122
+ const keys = [{
4123
+ pubkey: params.lookupTable,
4124
+ isSigner: false,
4125
+ isWritable: true
4126
+ }, {
4127
+ pubkey: params.authority,
4128
+ isSigner: true,
4129
+ isWritable: false
4130
+ }];
4131
+ return new TransactionInstruction({
4132
+ programId: this.programId,
4133
+ keys: keys,
4134
+ data: data
4135
+ });
4136
+ }
4137
+
4138
+ static extendLookupTable(params) {
4139
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
4140
+ const data = encodeData(type, {
4141
+ addresses: params.addresses.map(addr => addr.toBytes())
4142
+ });
4143
+ const keys = [{
4144
+ pubkey: params.lookupTable,
4145
+ isSigner: false,
4146
+ isWritable: true
4147
+ }, {
4148
+ pubkey: params.authority,
4149
+ isSigner: true,
4150
+ isWritable: false
4151
+ }];
4152
+
4153
+ if (params.payer) {
4154
+ keys.push({
4155
+ pubkey: params.payer,
4156
+ isSigner: true,
4157
+ isWritable: true
4158
+ }, {
4159
+ pubkey: SystemProgram.programId,
4160
+ isSigner: false,
4161
+ isWritable: false
4162
+ });
4163
+ }
4164
+
4165
+ return new TransactionInstruction({
4166
+ programId: this.programId,
4167
+ keys: keys,
4168
+ data: data
4169
+ });
4170
+ }
4171
+
4172
+ static deactivateLookupTable(params) {
4173
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
4174
+ const data = encodeData(type);
4175
+ const keys = [{
4176
+ pubkey: params.lookupTable,
4177
+ isSigner: false,
4178
+ isWritable: true
4179
+ }, {
4180
+ pubkey: params.authority,
4181
+ isSigner: true,
4182
+ isWritable: false
4183
+ }];
4184
+ return new TransactionInstruction({
4185
+ programId: this.programId,
4186
+ keys: keys,
4187
+ data: data
4188
+ });
4189
+ }
4190
+
4191
+ static closeLookupTable(params) {
4192
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
4193
+ const data = encodeData(type);
4194
+ const keys = [{
4195
+ pubkey: params.lookupTable,
4196
+ isSigner: false,
4197
+ isWritable: true
4198
+ }, {
4199
+ pubkey: params.authority,
4200
+ isSigner: true,
4201
+ isWritable: false
4202
+ }, {
4203
+ pubkey: params.recipient,
4204
+ isSigner: false,
4205
+ isWritable: true
4206
+ }];
4207
+ return new TransactionInstruction({
4208
+ programId: this.programId,
4209
+ keys: keys,
4210
+ data: data
4211
+ });
4212
+ }
4213
+
4214
+ }
4215
+ AddressLookupTableProgram.programId = new PublicKey('AddressLookupTab1e1111111111111111111111111');
4216
+
4217
+ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
4218
+
4219
+ /**
4220
+ * Sign, send and confirm a transaction.
4221
+ *
4222
+ * If `commitment` option is not specified, defaults to 'max' commitment.
4223
+ *
4224
+ * @param {Connection} connection
4225
+ * @param {Transaction} transaction
4226
+ * @param {Array<Signer>} signers
4227
+ * @param {ConfirmOptions} [options]
4228
+ * @returns {Promise<TransactionSignature>}
4229
+ */
4230
+ async function sendAndConfirmTransaction(connection, transaction, signers, options) {
4231
+ const sendOptions = options && {
4232
+ skipPreflight: options.skipPreflight,
4233
+ preflightCommitment: options.preflightCommitment || options.commitment,
4234
+ maxRetries: options.maxRetries,
4235
+ minContextSlot: options.minContextSlot
4236
+ };
4237
+ const signature = await connection.sendTransaction(transaction, signers, sendOptions);
4238
+ const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
4239
+ signature: signature,
4240
+ blockhash: transaction.recentBlockhash,
4241
+ lastValidBlockHeight: transaction.lastValidBlockHeight
4242
+ }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
4243
+
4244
+ if (status.err) {
4245
+ throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
4246
+ }
4247
+
4248
+ return signature;
4249
+ }
4250
+
4251
+ // zzz
4252
+ function sleep(ms) {
4253
+ return new Promise(resolve => setTimeout(resolve, ms));
4254
+ }
4255
+
3957
4256
  // rest of the Transaction fields
3958
4257
  //
3959
4258
  // TODO: replace 300 with a proper constant for the size of the other
@@ -4422,6 +4721,8 @@ var fastStableStringify = function(val) {
4422
4721
 
4423
4722
  var fastStableStringify$1 = fastStableStringify;
4424
4723
 
4724
+ const URL = globalThis.URL;
4725
+
4425
4726
  const DESTROY_TIMEOUT_MS = 5000;
4426
4727
  class AgentManager {
4427
4728
  static _newAgent(useHttps) {
@@ -4871,7 +5172,11 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
4871
5172
  data: array(string()),
4872
5173
  rentEpoch: optional(number())
4873
5174
  }))))),
4874
- unitsConsumed: optional(number())
5175
+ unitsConsumed: optional(number()),
5176
+ returnData: optional(nullable(type({
5177
+ programId: string(),
5178
+ data: tuple([string(), literal('base64')])
5179
+ })))
4875
5180
  }));
4876
5181
 
4877
5182
  /**
@@ -6214,16 +6519,6 @@ class Connection {
6214
6519
  reject(err);
6215
6520
  }
6216
6521
  });
6217
-
6218
- const checkBlockHeight = async () => {
6219
- try {
6220
- const blockHeight = await this.getBlockHeight(commitment);
6221
- return blockHeight;
6222
- } catch (_e) {
6223
- return -1;
6224
- }
6225
- };
6226
-
6227
6522
  const expiryPromise = new Promise(resolve => {
6228
6523
  if (typeof strategy === 'string') {
6229
6524
  let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
@@ -6247,6 +6542,15 @@ class Connection {
6247
6542
  } else {
6248
6543
  let config = strategy;
6249
6544
 
6545
+ const checkBlockHeight = async () => {
6546
+ try {
6547
+ const blockHeight = await this.getBlockHeight(commitment);
6548
+ return blockHeight;
6549
+ } catch (_e) {
6550
+ return -1;
6551
+ }
6552
+ };
6553
+
6250
6554
  (async () => {
6251
6555
  let currentBlockHeight = await checkBlockHeight();
6252
6556
  if (done) return;
@@ -9993,5 +10297,5 @@ function clusterApiUrl(cluster, tls) {
9993
10297
 
9994
10298
  const LAMPORTS_PER_SOL = 1000000000;
9995
10299
 
9996
- export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
10300
+ export { Account, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9997
10301
  //# sourceMappingURL=index.esm.js.map