@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.cjs.js CHANGED
@@ -7,8 +7,8 @@ var buffer = require('buffer');
7
7
  var BN = require('bn.js');
8
8
  var bs58 = require('bs58');
9
9
  var borsh = require('borsh');
10
- var BufferLayout = require('@solana/buffer-layout');
11
10
  var bigintBuffer = require('bigint-buffer');
11
+ var BufferLayout = require('@solana/buffer-layout');
12
12
  var superstruct = require('superstruct');
13
13
  var rpcWebsockets = require('rpc-websockets');
14
14
  var RpcClient = require('jayson/lib/client/browser');
@@ -2128,18 +2128,6 @@ class Account {
2128
2128
 
2129
2129
  }
2130
2130
 
2131
- const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
2132
-
2133
- /**
2134
- * Maximum over-the-wire size of a Transaction
2135
- *
2136
- * 1280 is IPv6 minimum MTU
2137
- * 40 bytes is the size of the IPv6 header
2138
- * 8 bytes is the size of the fragment header
2139
- */
2140
- const PACKET_DATA_SIZE = 1280 - 40 - 8;
2141
- const SIGNATURE_LENGTH_IN_BYTES = 64;
2142
-
2143
2131
  /**
2144
2132
  * Layout for a public key
2145
2133
  */
@@ -2201,17 +2189,170 @@ const voteInit = (property = 'voteInit') => {
2201
2189
  return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
2202
2190
  };
2203
2191
  function getAlloc(type, fields) {
2204
- let alloc = 0;
2205
- type.layout.fields.forEach(item => {
2192
+ const getItemAlloc = item => {
2206
2193
  if (item.span >= 0) {
2207
- alloc += item.span;
2194
+ return item.span;
2208
2195
  } else if (typeof item.alloc === 'function') {
2209
- alloc += item.alloc(fields[item.property]);
2210
- }
2196
+ return item.alloc(fields[item.property]);
2197
+ } else if ('count' in item && 'elementLayout' in item) {
2198
+ const field = fields[item.property];
2199
+
2200
+ if (Array.isArray(field)) {
2201
+ return field.length * getItemAlloc(item.elementLayout);
2202
+ }
2203
+ } // Couldn't determine allocated size of layout
2204
+
2205
+
2206
+ return 0;
2207
+ };
2208
+
2209
+ let alloc = 0;
2210
+ type.layout.fields.forEach(item => {
2211
+ alloc += getItemAlloc(item);
2211
2212
  });
2212
2213
  return alloc;
2213
2214
  }
2214
2215
 
2216
+ const encodeDecode = layout => {
2217
+ const decode = layout.decode.bind(layout);
2218
+ const encode = layout.encode.bind(layout);
2219
+ return {
2220
+ decode,
2221
+ encode
2222
+ };
2223
+ };
2224
+
2225
+ const bigInt = length => property => {
2226
+ const layout = BufferLayout.blob(length, property);
2227
+ const {
2228
+ encode,
2229
+ decode
2230
+ } = encodeDecode(layout);
2231
+ const bigIntLayout = layout;
2232
+
2233
+ bigIntLayout.decode = (buffer$1, offset) => {
2234
+ const src = decode(buffer$1, offset);
2235
+ return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
2236
+ };
2237
+
2238
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
2239
+ const src = bigintBuffer.toBufferLE(bigInt, length);
2240
+ return encode(src, buffer, offset);
2241
+ };
2242
+
2243
+ return bigIntLayout;
2244
+ };
2245
+
2246
+ const u64 = bigInt(8);
2247
+
2248
+ /**
2249
+ * Populate a buffer of instruction data using an InstructionType
2250
+ * @internal
2251
+ */
2252
+ function encodeData(type, fields) {
2253
+ const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
2254
+ const data = buffer.Buffer.alloc(allocLength);
2255
+ const layoutFields = Object.assign({
2256
+ instruction: type.index
2257
+ }, fields);
2258
+ type.layout.encode(layoutFields, data);
2259
+ return data;
2260
+ }
2261
+ /**
2262
+ * Decode instruction data buffer using an InstructionType
2263
+ * @internal
2264
+ */
2265
+
2266
+ function decodeData(type, buffer) {
2267
+ let data;
2268
+
2269
+ try {
2270
+ data = type.layout.decode(buffer);
2271
+ } catch (err) {
2272
+ throw new Error('invalid instruction; ' + err);
2273
+ }
2274
+
2275
+ if (data.instruction !== type.index) {
2276
+ throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
2277
+ }
2278
+
2279
+ return data;
2280
+ }
2281
+
2282
+ /**
2283
+ * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
2284
+ *
2285
+ * @internal
2286
+ */
2287
+
2288
+ const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
2289
+ /**
2290
+ * Calculator for transaction fees.
2291
+ */
2292
+
2293
+ /**
2294
+ * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
2295
+ *
2296
+ * @internal
2297
+ */
2298
+
2299
+ const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
2300
+ const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
2301
+
2302
+ /**
2303
+ * NonceAccount class
2304
+ */
2305
+ class NonceAccount {
2306
+ /**
2307
+ * @internal
2308
+ */
2309
+ constructor(args) {
2310
+ this.authorizedPubkey = void 0;
2311
+ this.nonce = void 0;
2312
+ this.feeCalculator = void 0;
2313
+ this.authorizedPubkey = args.authorizedPubkey;
2314
+ this.nonce = args.nonce;
2315
+ this.feeCalculator = args.feeCalculator;
2316
+ }
2317
+ /**
2318
+ * Deserialize NonceAccount from the account data.
2319
+ *
2320
+ * @param buffer account data
2321
+ * @return NonceAccount
2322
+ */
2323
+
2324
+
2325
+ static fromAccountData(buffer) {
2326
+ const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
2327
+ return new NonceAccount({
2328
+ authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
2329
+ nonce: new PublicKey(nonceAccount.nonce).toString(),
2330
+ feeCalculator: nonceAccount.feeCalculator
2331
+ });
2332
+ }
2333
+
2334
+ }
2335
+
2336
+ const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2337
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2338
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2339
+ const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2340
+ const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2341
+ const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2342
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2343
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2344
+ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2345
+
2346
+ /**
2347
+ * Maximum over-the-wire size of a Transaction
2348
+ *
2349
+ * 1280 is IPv6 minimum MTU
2350
+ * 40 bytes is the size of the IPv6 header
2351
+ * 8 bytes is the size of the fragment header
2352
+ */
2353
+ const PACKET_DATA_SIZE = 1280 - 40 - 8;
2354
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
2355
+
2215
2356
  function decodeLength(bytes) {
2216
2357
  let len = 0;
2217
2358
  let size = 0;
@@ -2505,15 +2646,34 @@ class Transaction {
2505
2646
 
2506
2647
  if (!opts) {
2507
2648
  return;
2508
- } else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
2509
- const newOpts = opts;
2510
- Object.assign(this, newOpts);
2511
- this.recentBlockhash = newOpts.blockhash;
2512
- this.lastValidBlockHeight = newOpts.lastValidBlockHeight;
2649
+ }
2650
+
2651
+ if (opts.feePayer) {
2652
+ this.feePayer = opts.feePayer;
2653
+ }
2654
+
2655
+ if (opts.signatures) {
2656
+ this.signatures = opts.signatures;
2657
+ }
2658
+
2659
+ if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
2660
+ const {
2661
+ blockhash,
2662
+ lastValidBlockHeight
2663
+ } = opts;
2664
+ this.recentBlockhash = blockhash;
2665
+ this.lastValidBlockHeight = lastValidBlockHeight;
2513
2666
  } else {
2514
- const oldOpts = opts;
2515
- Object.assign(this, oldOpts);
2516
- this.recentBlockhash = oldOpts.recentBlockhash;
2667
+ const {
2668
+ recentBlockhash,
2669
+ nonceInfo
2670
+ } = opts;
2671
+
2672
+ if (nonceInfo) {
2673
+ this.nonceInfo = nonceInfo;
2674
+ }
2675
+
2676
+ this.recentBlockhash = recentBlockhash;
2517
2677
  }
2518
2678
  }
2519
2679
  /**
@@ -3106,188 +3266,21 @@ class Transaction {
3106
3266
 
3107
3267
  }
3108
3268
 
3109
- const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3110
- const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3111
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
3112
- const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
3113
- const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
3114
- const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
3115
- const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
3116
- const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
3117
- const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
3118
-
3119
3269
  /**
3120
- * Sign, send and confirm a transaction.
3121
- *
3122
- * If `commitment` option is not specified, defaults to 'max' commitment.
3123
- *
3124
- * @param {Connection} connection
3125
- * @param {Transaction} transaction
3126
- * @param {Array<Signer>} signers
3127
- * @param {ConfirmOptions} [options]
3128
- * @returns {Promise<TransactionSignature>}
3270
+ * Create account system transaction params
3129
3271
  */
3130
- async function sendAndConfirmTransaction(connection, transaction, signers, options) {
3131
- const sendOptions = options && {
3132
- skipPreflight: options.skipPreflight,
3133
- preflightCommitment: options.preflightCommitment || options.commitment,
3134
- maxRetries: options.maxRetries,
3135
- minContextSlot: options.minContextSlot
3136
- };
3137
- const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3138
- const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
3139
- signature: signature,
3140
- blockhash: transaction.recentBlockhash,
3141
- lastValidBlockHeight: transaction.lastValidBlockHeight
3142
- }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
3143
-
3144
- if (status.err) {
3145
- throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
3146
- }
3147
-
3148
- return signature;
3149
- }
3150
3272
 
3151
- // zzz
3152
- function sleep(ms) {
3153
- return new Promise(resolve => setTimeout(resolve, ms));
3154
- }
3155
-
3156
- /**
3157
- * Populate a buffer of instruction data using an InstructionType
3158
- * @internal
3159
- */
3160
- function encodeData(type, fields) {
3161
- const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
3162
- const data = buffer.Buffer.alloc(allocLength);
3163
- const layoutFields = Object.assign({
3164
- instruction: type.index
3165
- }, fields);
3166
- type.layout.encode(layoutFields, data);
3167
- return data;
3168
- }
3169
3273
  /**
3170
- * Decode instruction data buffer using an InstructionType
3171
- * @internal
3274
+ * System Instruction class
3172
3275
  */
3173
-
3174
- function decodeData(type, buffer) {
3175
- let data;
3176
-
3177
- try {
3178
- data = type.layout.decode(buffer);
3179
- } catch (err) {
3180
- throw new Error('invalid instruction; ' + err);
3181
- }
3182
-
3183
- if (data.instruction !== type.index) {
3184
- throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
3185
- }
3186
-
3187
- return data;
3188
- }
3189
-
3190
- /**
3191
- * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
3192
- *
3193
- * @internal
3194
- */
3195
-
3196
- const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
3197
- /**
3198
- * Calculator for transaction fees.
3199
- */
3200
-
3201
- /**
3202
- * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
3203
- *
3204
- * @internal
3205
- */
3206
-
3207
- const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
3208
- const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
3209
-
3210
- /**
3211
- * NonceAccount class
3212
- */
3213
- class NonceAccount {
3214
- /**
3215
- * @internal
3216
- */
3217
- constructor(args) {
3218
- this.authorizedPubkey = void 0;
3219
- this.nonce = void 0;
3220
- this.feeCalculator = void 0;
3221
- this.authorizedPubkey = args.authorizedPubkey;
3222
- this.nonce = args.nonce;
3223
- this.feeCalculator = args.feeCalculator;
3224
- }
3225
- /**
3226
- * Deserialize NonceAccount from the account data.
3227
- *
3228
- * @param buffer account data
3229
- * @return NonceAccount
3230
- */
3231
-
3232
-
3233
- static fromAccountData(buffer) {
3234
- const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
3235
- return new NonceAccount({
3236
- authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
3237
- nonce: new PublicKey(nonceAccount.nonce).toString(),
3238
- feeCalculator: nonceAccount.feeCalculator
3239
- });
3240
- }
3241
-
3242
- }
3243
-
3244
- const encodeDecode = layout => {
3245
- const decode = layout.decode.bind(layout);
3246
- const encode = layout.encode.bind(layout);
3247
- return {
3248
- decode,
3249
- encode
3250
- };
3251
- };
3252
-
3253
- const bigInt = length => property => {
3254
- const layout = BufferLayout.blob(length, property);
3255
- const {
3256
- encode,
3257
- decode
3258
- } = encodeDecode(layout);
3259
- const bigIntLayout = layout;
3260
-
3261
- bigIntLayout.decode = (buffer$1, offset) => {
3262
- const src = decode(buffer$1, offset);
3263
- return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
3264
- };
3265
-
3266
- bigIntLayout.encode = (bigInt, buffer, offset) => {
3267
- const src = bigintBuffer.toBufferLE(bigInt, length);
3268
- return encode(src, buffer, offset);
3269
- };
3270
-
3271
- return bigIntLayout;
3272
- };
3273
-
3274
- const u64 = bigInt(8);
3275
-
3276
- /**
3277
- * Create account system transaction params
3278
- */
3279
-
3280
- /**
3281
- * System Instruction class
3282
- */
3283
- class SystemInstruction {
3284
- /**
3285
- * @internal
3286
- */
3287
- constructor() {}
3288
- /**
3289
- * Decode a system instruction and retrieve the instruction type.
3290
- */
3276
+ class SystemInstruction {
3277
+ /**
3278
+ * @internal
3279
+ */
3280
+ constructor() {}
3281
+ /**
3282
+ * Decode a system instruction and retrieve the instruction type.
3283
+ */
3291
3284
 
3292
3285
 
3293
3286
  static decodeInstructionType(instruction) {
@@ -3988,6 +3981,312 @@ class SystemProgram {
3988
3981
  }
3989
3982
  SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3990
3983
 
3984
+ /**
3985
+ * An enumeration of valid address lookup table InstructionType's
3986
+ * @internal
3987
+ */
3988
+ const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
3989
+ CreateLookupTable: {
3990
+ index: 0,
3991
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('recentSlot'), BufferLayout__namespace.u8('bumpSeed')])
3992
+ },
3993
+ FreezeLookupTable: {
3994
+ index: 1,
3995
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
3996
+ },
3997
+ ExtendLookupTable: {
3998
+ index: 2,
3999
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64(), BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'addresses')])
4000
+ },
4001
+ DeactivateLookupTable: {
4002
+ index: 3,
4003
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
4004
+ },
4005
+ CloseLookupTable: {
4006
+ index: 4,
4007
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
4008
+ }
4009
+ });
4010
+ class AddressLookupTableInstruction {
4011
+ /**
4012
+ * @internal
4013
+ */
4014
+ constructor() {}
4015
+
4016
+ static decodeInstructionType(instruction) {
4017
+ this.checkProgramId(instruction.programId);
4018
+ const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
4019
+ const index = instructionTypeLayout.decode(instruction.data);
4020
+ let type;
4021
+
4022
+ for (const [layoutType, layout] of Object.entries(LOOKUP_TABLE_INSTRUCTION_LAYOUTS)) {
4023
+ if (layout.index == index) {
4024
+ type = layoutType;
4025
+ break;
4026
+ }
4027
+ }
4028
+
4029
+ if (!type) {
4030
+ throw new Error('Invalid Instruction. Should be a LookupTable Instruction');
4031
+ }
4032
+
4033
+ return type;
4034
+ }
4035
+
4036
+ static decodeCreateLookupTable(instruction) {
4037
+ this.checkProgramId(instruction.programId);
4038
+ this.checkKeysLength(instruction.keys, 4);
4039
+ const {
4040
+ recentSlot
4041
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable, instruction.data);
4042
+ return {
4043
+ authority: instruction.keys[1].pubkey,
4044
+ payer: instruction.keys[2].pubkey,
4045
+ recentSlot: Number(recentSlot)
4046
+ };
4047
+ }
4048
+
4049
+ static decodeExtendLookupTable(instruction) {
4050
+ this.checkProgramId(instruction.programId);
4051
+
4052
+ if (instruction.keys.length < 2) {
4053
+ throw new Error(`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`);
4054
+ }
4055
+
4056
+ const {
4057
+ addresses
4058
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable, instruction.data);
4059
+ return {
4060
+ lookupTable: instruction.keys[0].pubkey,
4061
+ authority: instruction.keys[1].pubkey,
4062
+ payer: instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
4063
+ addresses: addresses.map(buffer => new PublicKey(buffer))
4064
+ };
4065
+ }
4066
+
4067
+ static decodeCloseLookupTable(instruction) {
4068
+ this.checkProgramId(instruction.programId);
4069
+ this.checkKeysLength(instruction.keys, 3);
4070
+ return {
4071
+ lookupTable: instruction.keys[0].pubkey,
4072
+ authority: instruction.keys[1].pubkey,
4073
+ recipient: instruction.keys[2].pubkey
4074
+ };
4075
+ }
4076
+
4077
+ static decodeFreezeLookupTable(instruction) {
4078
+ this.checkProgramId(instruction.programId);
4079
+ this.checkKeysLength(instruction.keys, 2);
4080
+ return {
4081
+ lookupTable: instruction.keys[0].pubkey,
4082
+ authority: instruction.keys[1].pubkey
4083
+ };
4084
+ }
4085
+
4086
+ static decodeDeactivateLookupTable(instruction) {
4087
+ this.checkProgramId(instruction.programId);
4088
+ this.checkKeysLength(instruction.keys, 2);
4089
+ return {
4090
+ lookupTable: instruction.keys[0].pubkey,
4091
+ authority: instruction.keys[1].pubkey
4092
+ };
4093
+ }
4094
+ /**
4095
+ * @internal
4096
+ */
4097
+
4098
+
4099
+ static checkProgramId(programId) {
4100
+ if (!programId.equals(AddressLookupTableProgram.programId)) {
4101
+ throw new Error('invalid instruction; programId is not AddressLookupTable Program');
4102
+ }
4103
+ }
4104
+ /**
4105
+ * @internal
4106
+ */
4107
+
4108
+
4109
+ static checkKeysLength(keys, expectedLength) {
4110
+ if (keys.length < expectedLength) {
4111
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
4112
+ }
4113
+ }
4114
+
4115
+ }
4116
+ class AddressLookupTableProgram {
4117
+ /**
4118
+ * @internal
4119
+ */
4120
+ constructor() {}
4121
+
4122
+ static createLookupTable(params) {
4123
+ const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), bigintBuffer.toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
4124
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
4125
+ const data = encodeData(type, {
4126
+ recentSlot: BigInt(params.recentSlot),
4127
+ bumpSeed: bumpSeed
4128
+ });
4129
+ const keys = [{
4130
+ pubkey: lookupTableAddress,
4131
+ isSigner: false,
4132
+ isWritable: true
4133
+ }, {
4134
+ pubkey: params.authority,
4135
+ isSigner: true,
4136
+ isWritable: false
4137
+ }, {
4138
+ pubkey: params.payer,
4139
+ isSigner: true,
4140
+ isWritable: true
4141
+ }, {
4142
+ pubkey: SystemProgram.programId,
4143
+ isSigner: false,
4144
+ isWritable: false
4145
+ }];
4146
+ return [new TransactionInstruction({
4147
+ programId: this.programId,
4148
+ keys: keys,
4149
+ data: data
4150
+ }), lookupTableAddress];
4151
+ }
4152
+
4153
+ static freezeLookupTable(params) {
4154
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
4155
+ const data = encodeData(type);
4156
+ const keys = [{
4157
+ pubkey: params.lookupTable,
4158
+ isSigner: false,
4159
+ isWritable: true
4160
+ }, {
4161
+ pubkey: params.authority,
4162
+ isSigner: true,
4163
+ isWritable: false
4164
+ }];
4165
+ return new TransactionInstruction({
4166
+ programId: this.programId,
4167
+ keys: keys,
4168
+ data: data
4169
+ });
4170
+ }
4171
+
4172
+ static extendLookupTable(params) {
4173
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
4174
+ const data = encodeData(type, {
4175
+ addresses: params.addresses.map(addr => addr.toBytes())
4176
+ });
4177
+ const keys = [{
4178
+ pubkey: params.lookupTable,
4179
+ isSigner: false,
4180
+ isWritable: true
4181
+ }, {
4182
+ pubkey: params.authority,
4183
+ isSigner: true,
4184
+ isWritable: false
4185
+ }];
4186
+
4187
+ if (params.payer) {
4188
+ keys.push({
4189
+ pubkey: params.payer,
4190
+ isSigner: true,
4191
+ isWritable: true
4192
+ }, {
4193
+ pubkey: SystemProgram.programId,
4194
+ isSigner: false,
4195
+ isWritable: false
4196
+ });
4197
+ }
4198
+
4199
+ return new TransactionInstruction({
4200
+ programId: this.programId,
4201
+ keys: keys,
4202
+ data: data
4203
+ });
4204
+ }
4205
+
4206
+ static deactivateLookupTable(params) {
4207
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
4208
+ const data = encodeData(type);
4209
+ const keys = [{
4210
+ pubkey: params.lookupTable,
4211
+ isSigner: false,
4212
+ isWritable: true
4213
+ }, {
4214
+ pubkey: params.authority,
4215
+ isSigner: true,
4216
+ isWritable: false
4217
+ }];
4218
+ return new TransactionInstruction({
4219
+ programId: this.programId,
4220
+ keys: keys,
4221
+ data: data
4222
+ });
4223
+ }
4224
+
4225
+ static closeLookupTable(params) {
4226
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
4227
+ const data = encodeData(type);
4228
+ const keys = [{
4229
+ pubkey: params.lookupTable,
4230
+ isSigner: false,
4231
+ isWritable: true
4232
+ }, {
4233
+ pubkey: params.authority,
4234
+ isSigner: true,
4235
+ isWritable: false
4236
+ }, {
4237
+ pubkey: params.recipient,
4238
+ isSigner: false,
4239
+ isWritable: true
4240
+ }];
4241
+ return new TransactionInstruction({
4242
+ programId: this.programId,
4243
+ keys: keys,
4244
+ data: data
4245
+ });
4246
+ }
4247
+
4248
+ }
4249
+ AddressLookupTableProgram.programId = new PublicKey('AddressLookupTab1e1111111111111111111111111');
4250
+
4251
+ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
4252
+
4253
+ /**
4254
+ * Sign, send and confirm a transaction.
4255
+ *
4256
+ * If `commitment` option is not specified, defaults to 'max' commitment.
4257
+ *
4258
+ * @param {Connection} connection
4259
+ * @param {Transaction} transaction
4260
+ * @param {Array<Signer>} signers
4261
+ * @param {ConfirmOptions} [options]
4262
+ * @returns {Promise<TransactionSignature>}
4263
+ */
4264
+ async function sendAndConfirmTransaction(connection, transaction, signers, options) {
4265
+ const sendOptions = options && {
4266
+ skipPreflight: options.skipPreflight,
4267
+ preflightCommitment: options.preflightCommitment || options.commitment,
4268
+ maxRetries: options.maxRetries,
4269
+ minContextSlot: options.minContextSlot
4270
+ };
4271
+ const signature = await connection.sendTransaction(transaction, signers, sendOptions);
4272
+ const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
4273
+ signature: signature,
4274
+ blockhash: transaction.recentBlockhash,
4275
+ lastValidBlockHeight: transaction.lastValidBlockHeight
4276
+ }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
4277
+
4278
+ if (status.err) {
4279
+ throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
4280
+ }
4281
+
4282
+ return signature;
4283
+ }
4284
+
4285
+ // zzz
4286
+ function sleep(ms) {
4287
+ return new Promise(resolve => setTimeout(resolve, ms));
4288
+ }
4289
+
3991
4290
  // rest of the Transaction fields
3992
4291
  //
3993
4292
  // TODO: replace 300 with a proper constant for the size of the other
@@ -4456,6 +4755,8 @@ var fastStableStringify = function(val) {
4456
4755
 
4457
4756
  var fastStableStringify$1 = fastStableStringify;
4458
4757
 
4758
+ const URL = globalThis.URL;
4759
+
4459
4760
  const DESTROY_TIMEOUT_MS = 5000;
4460
4761
  class AgentManager {
4461
4762
  static _newAgent(useHttps) {
@@ -4905,7 +5206,11 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(superstruct.t
4905
5206
  data: superstruct.array(superstruct.string()),
4906
5207
  rentEpoch: superstruct.optional(superstruct.number())
4907
5208
  }))))),
4908
- unitsConsumed: superstruct.optional(superstruct.number())
5209
+ unitsConsumed: superstruct.optional(superstruct.number()),
5210
+ returnData: superstruct.optional(superstruct.nullable(superstruct.type({
5211
+ programId: superstruct.string(),
5212
+ data: superstruct.tuple([superstruct.string(), superstruct.literal('base64')])
5213
+ })))
4909
5214
  }));
4910
5215
 
4911
5216
  /**
@@ -6248,16 +6553,6 @@ class Connection {
6248
6553
  reject(err);
6249
6554
  }
6250
6555
  });
6251
-
6252
- const checkBlockHeight = async () => {
6253
- try {
6254
- const blockHeight = await this.getBlockHeight(commitment);
6255
- return blockHeight;
6256
- } catch (_e) {
6257
- return -1;
6258
- }
6259
- };
6260
-
6261
6556
  const expiryPromise = new Promise(resolve => {
6262
6557
  if (typeof strategy === 'string') {
6263
6558
  let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
@@ -6281,6 +6576,15 @@ class Connection {
6281
6576
  } else {
6282
6577
  let config = strategy;
6283
6578
 
6579
+ const checkBlockHeight = async () => {
6580
+ try {
6581
+ const blockHeight = await this.getBlockHeight(commitment);
6582
+ return blockHeight;
6583
+ } catch (_e) {
6584
+ return -1;
6585
+ }
6586
+ };
6587
+
6284
6588
  (async () => {
6285
6589
  let currentBlockHeight = await checkBlockHeight();
6286
6590
  if (done) return;
@@ -10028,6 +10332,8 @@ function clusterApiUrl(cluster, tls) {
10028
10332
  const LAMPORTS_PER_SOL = 1000000000;
10029
10333
 
10030
10334
  exports.Account = Account;
10335
+ exports.AddressLookupTableInstruction = AddressLookupTableInstruction;
10336
+ exports.AddressLookupTableProgram = AddressLookupTableProgram;
10031
10337
  exports.Authorized = Authorized;
10032
10338
  exports.BLOCKHASH_CACHE_TIMEOUT_MS = BLOCKHASH_CACHE_TIMEOUT_MS;
10033
10339
  exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
@@ -10043,6 +10349,7 @@ exports.EpochSchedule = EpochSchedule;
10043
10349
  exports.FeeCalculatorLayout = FeeCalculatorLayout;
10044
10350
  exports.Keypair = Keypair;
10045
10351
  exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
10352
+ exports.LOOKUP_TABLE_INSTRUCTION_LAYOUTS = LOOKUP_TABLE_INSTRUCTION_LAYOUTS;
10046
10353
  exports.Loader = Loader;
10047
10354
  exports.Lockup = Lockup;
10048
10355
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;