@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.
@@ -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');
@@ -2101,18 +2101,6 @@ class Account {
2101
2101
 
2102
2102
  }
2103
2103
 
2104
- const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
2105
-
2106
- /**
2107
- * Maximum over-the-wire size of a Transaction
2108
- *
2109
- * 1280 is IPv6 minimum MTU
2110
- * 40 bytes is the size of the IPv6 header
2111
- * 8 bytes is the size of the fragment header
2112
- */
2113
- const PACKET_DATA_SIZE = 1280 - 40 - 8;
2114
- const SIGNATURE_LENGTH_IN_BYTES = 64;
2115
-
2116
2104
  /**
2117
2105
  * Layout for a public key
2118
2106
  */
@@ -2174,17 +2162,170 @@ const voteInit = (property = 'voteInit') => {
2174
2162
  return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
2175
2163
  };
2176
2164
  function getAlloc(type, fields) {
2177
- let alloc = 0;
2178
- type.layout.fields.forEach(item => {
2165
+ const getItemAlloc = item => {
2179
2166
  if (item.span >= 0) {
2180
- alloc += item.span;
2167
+ return item.span;
2181
2168
  } else if (typeof item.alloc === 'function') {
2182
- alloc += item.alloc(fields[item.property]);
2183
- }
2169
+ return item.alloc(fields[item.property]);
2170
+ } else if ('count' in item && 'elementLayout' in item) {
2171
+ const field = fields[item.property];
2172
+
2173
+ if (Array.isArray(field)) {
2174
+ return field.length * getItemAlloc(item.elementLayout);
2175
+ }
2176
+ } // Couldn't determine allocated size of layout
2177
+
2178
+
2179
+ return 0;
2180
+ };
2181
+
2182
+ let alloc = 0;
2183
+ type.layout.fields.forEach(item => {
2184
+ alloc += getItemAlloc(item);
2184
2185
  });
2185
2186
  return alloc;
2186
2187
  }
2187
2188
 
2189
+ const encodeDecode = layout => {
2190
+ const decode = layout.decode.bind(layout);
2191
+ const encode = layout.encode.bind(layout);
2192
+ return {
2193
+ decode,
2194
+ encode
2195
+ };
2196
+ };
2197
+
2198
+ const bigInt = length => property => {
2199
+ const layout = BufferLayout.blob(length, property);
2200
+ const {
2201
+ encode,
2202
+ decode
2203
+ } = encodeDecode(layout);
2204
+ const bigIntLayout = layout;
2205
+
2206
+ bigIntLayout.decode = (buffer$1, offset) => {
2207
+ const src = decode(buffer$1, offset);
2208
+ return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
2209
+ };
2210
+
2211
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
2212
+ const src = bigintBuffer.toBufferLE(bigInt, length);
2213
+ return encode(src, buffer, offset);
2214
+ };
2215
+
2216
+ return bigIntLayout;
2217
+ };
2218
+
2219
+ const u64 = bigInt(8);
2220
+
2221
+ /**
2222
+ * Populate a buffer of instruction data using an InstructionType
2223
+ * @internal
2224
+ */
2225
+ function encodeData(type, fields) {
2226
+ const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
2227
+ const data = buffer.Buffer.alloc(allocLength);
2228
+ const layoutFields = Object.assign({
2229
+ instruction: type.index
2230
+ }, fields);
2231
+ type.layout.encode(layoutFields, data);
2232
+ return data;
2233
+ }
2234
+ /**
2235
+ * Decode instruction data buffer using an InstructionType
2236
+ * @internal
2237
+ */
2238
+
2239
+ function decodeData(type, buffer) {
2240
+ let data;
2241
+
2242
+ try {
2243
+ data = type.layout.decode(buffer);
2244
+ } catch (err) {
2245
+ throw new Error('invalid instruction; ' + err);
2246
+ }
2247
+
2248
+ if (data.instruction !== type.index) {
2249
+ throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
2250
+ }
2251
+
2252
+ return data;
2253
+ }
2254
+
2255
+ /**
2256
+ * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
2257
+ *
2258
+ * @internal
2259
+ */
2260
+
2261
+ const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
2262
+ /**
2263
+ * Calculator for transaction fees.
2264
+ */
2265
+
2266
+ /**
2267
+ * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
2268
+ *
2269
+ * @internal
2270
+ */
2271
+
2272
+ const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
2273
+ const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
2274
+
2275
+ /**
2276
+ * NonceAccount class
2277
+ */
2278
+ class NonceAccount {
2279
+ /**
2280
+ * @internal
2281
+ */
2282
+ constructor(args) {
2283
+ this.authorizedPubkey = void 0;
2284
+ this.nonce = void 0;
2285
+ this.feeCalculator = void 0;
2286
+ this.authorizedPubkey = args.authorizedPubkey;
2287
+ this.nonce = args.nonce;
2288
+ this.feeCalculator = args.feeCalculator;
2289
+ }
2290
+ /**
2291
+ * Deserialize NonceAccount from the account data.
2292
+ *
2293
+ * @param buffer account data
2294
+ * @return NonceAccount
2295
+ */
2296
+
2297
+
2298
+ static fromAccountData(buffer) {
2299
+ const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
2300
+ return new NonceAccount({
2301
+ authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
2302
+ nonce: new PublicKey(nonceAccount.nonce).toString(),
2303
+ feeCalculator: nonceAccount.feeCalculator
2304
+ });
2305
+ }
2306
+
2307
+ }
2308
+
2309
+ const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2310
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2311
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2312
+ const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2313
+ const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2314
+ const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2315
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2316
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2317
+ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2318
+
2319
+ /**
2320
+ * Maximum over-the-wire size of a Transaction
2321
+ *
2322
+ * 1280 is IPv6 minimum MTU
2323
+ * 40 bytes is the size of the IPv6 header
2324
+ * 8 bytes is the size of the fragment header
2325
+ */
2326
+ const PACKET_DATA_SIZE = 1280 - 40 - 8;
2327
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
2328
+
2188
2329
  function decodeLength(bytes) {
2189
2330
  let len = 0;
2190
2331
  let size = 0;
@@ -2478,15 +2619,34 @@ class Transaction {
2478
2619
 
2479
2620
  if (!opts) {
2480
2621
  return;
2481
- } else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
2482
- const newOpts = opts;
2483
- Object.assign(this, newOpts);
2484
- this.recentBlockhash = newOpts.blockhash;
2485
- this.lastValidBlockHeight = newOpts.lastValidBlockHeight;
2622
+ }
2623
+
2624
+ if (opts.feePayer) {
2625
+ this.feePayer = opts.feePayer;
2626
+ }
2627
+
2628
+ if (opts.signatures) {
2629
+ this.signatures = opts.signatures;
2630
+ }
2631
+
2632
+ if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
2633
+ const {
2634
+ blockhash,
2635
+ lastValidBlockHeight
2636
+ } = opts;
2637
+ this.recentBlockhash = blockhash;
2638
+ this.lastValidBlockHeight = lastValidBlockHeight;
2486
2639
  } else {
2487
- const oldOpts = opts;
2488
- Object.assign(this, oldOpts);
2489
- this.recentBlockhash = oldOpts.recentBlockhash;
2640
+ const {
2641
+ recentBlockhash,
2642
+ nonceInfo
2643
+ } = opts;
2644
+
2645
+ if (nonceInfo) {
2646
+ this.nonceInfo = nonceInfo;
2647
+ }
2648
+
2649
+ this.recentBlockhash = recentBlockhash;
2490
2650
  }
2491
2651
  }
2492
2652
  /**
@@ -3079,188 +3239,21 @@ class Transaction {
3079
3239
 
3080
3240
  }
3081
3241
 
3082
- const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3083
- const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3084
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
3085
- const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
3086
- const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
3087
- const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
3088
- const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
3089
- const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
3090
- const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
3091
-
3092
3242
  /**
3093
- * Sign, send and confirm a transaction.
3094
- *
3095
- * If `commitment` option is not specified, defaults to 'max' commitment.
3096
- *
3097
- * @param {Connection} connection
3098
- * @param {Transaction} transaction
3099
- * @param {Array<Signer>} signers
3100
- * @param {ConfirmOptions} [options]
3101
- * @returns {Promise<TransactionSignature>}
3243
+ * Create account system transaction params
3102
3244
  */
3103
- async function sendAndConfirmTransaction(connection, transaction, signers, options) {
3104
- const sendOptions = options && {
3105
- skipPreflight: options.skipPreflight,
3106
- preflightCommitment: options.preflightCommitment || options.commitment,
3107
- maxRetries: options.maxRetries,
3108
- minContextSlot: options.minContextSlot
3109
- };
3110
- const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3111
- const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
3112
- signature: signature,
3113
- blockhash: transaction.recentBlockhash,
3114
- lastValidBlockHeight: transaction.lastValidBlockHeight
3115
- }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
3116
-
3117
- if (status.err) {
3118
- throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
3119
- }
3120
-
3121
- return signature;
3122
- }
3123
3245
 
3124
- // zzz
3125
- function sleep(ms) {
3126
- return new Promise(resolve => setTimeout(resolve, ms));
3127
- }
3128
-
3129
- /**
3130
- * Populate a buffer of instruction data using an InstructionType
3131
- * @internal
3132
- */
3133
- function encodeData(type, fields) {
3134
- const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
3135
- const data = buffer.Buffer.alloc(allocLength);
3136
- const layoutFields = Object.assign({
3137
- instruction: type.index
3138
- }, fields);
3139
- type.layout.encode(layoutFields, data);
3140
- return data;
3141
- }
3142
3246
  /**
3143
- * Decode instruction data buffer using an InstructionType
3144
- * @internal
3247
+ * System Instruction class
3145
3248
  */
3146
-
3147
- function decodeData(type, buffer) {
3148
- let data;
3149
-
3150
- try {
3151
- data = type.layout.decode(buffer);
3152
- } catch (err) {
3153
- throw new Error('invalid instruction; ' + err);
3154
- }
3155
-
3156
- if (data.instruction !== type.index) {
3157
- throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
3158
- }
3159
-
3160
- return data;
3161
- }
3162
-
3163
- /**
3164
- * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
3165
- *
3166
- * @internal
3167
- */
3168
-
3169
- const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
3170
- /**
3171
- * Calculator for transaction fees.
3172
- */
3173
-
3174
- /**
3175
- * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
3176
- *
3177
- * @internal
3178
- */
3179
-
3180
- const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
3181
- const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
3182
-
3183
- /**
3184
- * NonceAccount class
3185
- */
3186
- class NonceAccount {
3187
- /**
3188
- * @internal
3189
- */
3190
- constructor(args) {
3191
- this.authorizedPubkey = void 0;
3192
- this.nonce = void 0;
3193
- this.feeCalculator = void 0;
3194
- this.authorizedPubkey = args.authorizedPubkey;
3195
- this.nonce = args.nonce;
3196
- this.feeCalculator = args.feeCalculator;
3197
- }
3198
- /**
3199
- * Deserialize NonceAccount from the account data.
3200
- *
3201
- * @param buffer account data
3202
- * @return NonceAccount
3203
- */
3204
-
3205
-
3206
- static fromAccountData(buffer) {
3207
- const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
3208
- return new NonceAccount({
3209
- authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
3210
- nonce: new PublicKey(nonceAccount.nonce).toString(),
3211
- feeCalculator: nonceAccount.feeCalculator
3212
- });
3213
- }
3214
-
3215
- }
3216
-
3217
- const encodeDecode = layout => {
3218
- const decode = layout.decode.bind(layout);
3219
- const encode = layout.encode.bind(layout);
3220
- return {
3221
- decode,
3222
- encode
3223
- };
3224
- };
3225
-
3226
- const bigInt = length => property => {
3227
- const layout = BufferLayout.blob(length, property);
3228
- const {
3229
- encode,
3230
- decode
3231
- } = encodeDecode(layout);
3232
- const bigIntLayout = layout;
3233
-
3234
- bigIntLayout.decode = (buffer$1, offset) => {
3235
- const src = decode(buffer$1, offset);
3236
- return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
3237
- };
3238
-
3239
- bigIntLayout.encode = (bigInt, buffer, offset) => {
3240
- const src = bigintBuffer.toBufferLE(bigInt, length);
3241
- return encode(src, buffer, offset);
3242
- };
3243
-
3244
- return bigIntLayout;
3245
- };
3246
-
3247
- const u64 = bigInt(8);
3248
-
3249
- /**
3250
- * Create account system transaction params
3251
- */
3252
-
3253
- /**
3254
- * System Instruction class
3255
- */
3256
- class SystemInstruction {
3257
- /**
3258
- * @internal
3259
- */
3260
- constructor() {}
3261
- /**
3262
- * Decode a system instruction and retrieve the instruction type.
3263
- */
3249
+ class SystemInstruction {
3250
+ /**
3251
+ * @internal
3252
+ */
3253
+ constructor() {}
3254
+ /**
3255
+ * Decode a system instruction and retrieve the instruction type.
3256
+ */
3264
3257
 
3265
3258
 
3266
3259
  static decodeInstructionType(instruction) {
@@ -3961,6 +3954,312 @@ class SystemProgram {
3961
3954
  }
3962
3955
  SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3963
3956
 
3957
+ /**
3958
+ * An enumeration of valid address lookup table InstructionType's
3959
+ * @internal
3960
+ */
3961
+ const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
3962
+ CreateLookupTable: {
3963
+ index: 0,
3964
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('recentSlot'), BufferLayout__namespace.u8('bumpSeed')])
3965
+ },
3966
+ FreezeLookupTable: {
3967
+ index: 1,
3968
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
3969
+ },
3970
+ ExtendLookupTable: {
3971
+ index: 2,
3972
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64(), BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'addresses')])
3973
+ },
3974
+ DeactivateLookupTable: {
3975
+ index: 3,
3976
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
3977
+ },
3978
+ CloseLookupTable: {
3979
+ index: 4,
3980
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
3981
+ }
3982
+ });
3983
+ class AddressLookupTableInstruction {
3984
+ /**
3985
+ * @internal
3986
+ */
3987
+ constructor() {}
3988
+
3989
+ static decodeInstructionType(instruction) {
3990
+ this.checkProgramId(instruction.programId);
3991
+ const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
3992
+ const index = instructionTypeLayout.decode(instruction.data);
3993
+ let type;
3994
+
3995
+ for (const [layoutType, layout] of Object.entries(LOOKUP_TABLE_INSTRUCTION_LAYOUTS)) {
3996
+ if (layout.index == index) {
3997
+ type = layoutType;
3998
+ break;
3999
+ }
4000
+ }
4001
+
4002
+ if (!type) {
4003
+ throw new Error('Invalid Instruction. Should be a LookupTable Instruction');
4004
+ }
4005
+
4006
+ return type;
4007
+ }
4008
+
4009
+ static decodeCreateLookupTable(instruction) {
4010
+ this.checkProgramId(instruction.programId);
4011
+ this.checkKeysLength(instruction.keys, 4);
4012
+ const {
4013
+ recentSlot
4014
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable, instruction.data);
4015
+ return {
4016
+ authority: instruction.keys[1].pubkey,
4017
+ payer: instruction.keys[2].pubkey,
4018
+ recentSlot: Number(recentSlot)
4019
+ };
4020
+ }
4021
+
4022
+ static decodeExtendLookupTable(instruction) {
4023
+ this.checkProgramId(instruction.programId);
4024
+
4025
+ if (instruction.keys.length < 2) {
4026
+ throw new Error(`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`);
4027
+ }
4028
+
4029
+ const {
4030
+ addresses
4031
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable, instruction.data);
4032
+ return {
4033
+ lookupTable: instruction.keys[0].pubkey,
4034
+ authority: instruction.keys[1].pubkey,
4035
+ payer: instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
4036
+ addresses: addresses.map(buffer => new PublicKey(buffer))
4037
+ };
4038
+ }
4039
+
4040
+ static decodeCloseLookupTable(instruction) {
4041
+ this.checkProgramId(instruction.programId);
4042
+ this.checkKeysLength(instruction.keys, 3);
4043
+ return {
4044
+ lookupTable: instruction.keys[0].pubkey,
4045
+ authority: instruction.keys[1].pubkey,
4046
+ recipient: instruction.keys[2].pubkey
4047
+ };
4048
+ }
4049
+
4050
+ static decodeFreezeLookupTable(instruction) {
4051
+ this.checkProgramId(instruction.programId);
4052
+ this.checkKeysLength(instruction.keys, 2);
4053
+ return {
4054
+ lookupTable: instruction.keys[0].pubkey,
4055
+ authority: instruction.keys[1].pubkey
4056
+ };
4057
+ }
4058
+
4059
+ static decodeDeactivateLookupTable(instruction) {
4060
+ this.checkProgramId(instruction.programId);
4061
+ this.checkKeysLength(instruction.keys, 2);
4062
+ return {
4063
+ lookupTable: instruction.keys[0].pubkey,
4064
+ authority: instruction.keys[1].pubkey
4065
+ };
4066
+ }
4067
+ /**
4068
+ * @internal
4069
+ */
4070
+
4071
+
4072
+ static checkProgramId(programId) {
4073
+ if (!programId.equals(AddressLookupTableProgram.programId)) {
4074
+ throw new Error('invalid instruction; programId is not AddressLookupTable Program');
4075
+ }
4076
+ }
4077
+ /**
4078
+ * @internal
4079
+ */
4080
+
4081
+
4082
+ static checkKeysLength(keys, expectedLength) {
4083
+ if (keys.length < expectedLength) {
4084
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
4085
+ }
4086
+ }
4087
+
4088
+ }
4089
+ class AddressLookupTableProgram {
4090
+ /**
4091
+ * @internal
4092
+ */
4093
+ constructor() {}
4094
+
4095
+ static createLookupTable(params) {
4096
+ const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), bigintBuffer.toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
4097
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
4098
+ const data = encodeData(type, {
4099
+ recentSlot: BigInt(params.recentSlot),
4100
+ bumpSeed: bumpSeed
4101
+ });
4102
+ const keys = [{
4103
+ pubkey: lookupTableAddress,
4104
+ isSigner: false,
4105
+ isWritable: true
4106
+ }, {
4107
+ pubkey: params.authority,
4108
+ isSigner: true,
4109
+ isWritable: false
4110
+ }, {
4111
+ pubkey: params.payer,
4112
+ isSigner: true,
4113
+ isWritable: true
4114
+ }, {
4115
+ pubkey: SystemProgram.programId,
4116
+ isSigner: false,
4117
+ isWritable: false
4118
+ }];
4119
+ return [new TransactionInstruction({
4120
+ programId: this.programId,
4121
+ keys: keys,
4122
+ data: data
4123
+ }), lookupTableAddress];
4124
+ }
4125
+
4126
+ static freezeLookupTable(params) {
4127
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
4128
+ const data = encodeData(type);
4129
+ const keys = [{
4130
+ pubkey: params.lookupTable,
4131
+ isSigner: false,
4132
+ isWritable: true
4133
+ }, {
4134
+ pubkey: params.authority,
4135
+ isSigner: true,
4136
+ isWritable: false
4137
+ }];
4138
+ return new TransactionInstruction({
4139
+ programId: this.programId,
4140
+ keys: keys,
4141
+ data: data
4142
+ });
4143
+ }
4144
+
4145
+ static extendLookupTable(params) {
4146
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
4147
+ const data = encodeData(type, {
4148
+ addresses: params.addresses.map(addr => addr.toBytes())
4149
+ });
4150
+ const keys = [{
4151
+ pubkey: params.lookupTable,
4152
+ isSigner: false,
4153
+ isWritable: true
4154
+ }, {
4155
+ pubkey: params.authority,
4156
+ isSigner: true,
4157
+ isWritable: false
4158
+ }];
4159
+
4160
+ if (params.payer) {
4161
+ keys.push({
4162
+ pubkey: params.payer,
4163
+ isSigner: true,
4164
+ isWritable: true
4165
+ }, {
4166
+ pubkey: SystemProgram.programId,
4167
+ isSigner: false,
4168
+ isWritable: false
4169
+ });
4170
+ }
4171
+
4172
+ return new TransactionInstruction({
4173
+ programId: this.programId,
4174
+ keys: keys,
4175
+ data: data
4176
+ });
4177
+ }
4178
+
4179
+ static deactivateLookupTable(params) {
4180
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
4181
+ const data = encodeData(type);
4182
+ const keys = [{
4183
+ pubkey: params.lookupTable,
4184
+ isSigner: false,
4185
+ isWritable: true
4186
+ }, {
4187
+ pubkey: params.authority,
4188
+ isSigner: true,
4189
+ isWritable: false
4190
+ }];
4191
+ return new TransactionInstruction({
4192
+ programId: this.programId,
4193
+ keys: keys,
4194
+ data: data
4195
+ });
4196
+ }
4197
+
4198
+ static closeLookupTable(params) {
4199
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
4200
+ const data = encodeData(type);
4201
+ const keys = [{
4202
+ pubkey: params.lookupTable,
4203
+ isSigner: false,
4204
+ isWritable: true
4205
+ }, {
4206
+ pubkey: params.authority,
4207
+ isSigner: true,
4208
+ isWritable: false
4209
+ }, {
4210
+ pubkey: params.recipient,
4211
+ isSigner: false,
4212
+ isWritable: true
4213
+ }];
4214
+ return new TransactionInstruction({
4215
+ programId: this.programId,
4216
+ keys: keys,
4217
+ data: data
4218
+ });
4219
+ }
4220
+
4221
+ }
4222
+ AddressLookupTableProgram.programId = new PublicKey('AddressLookupTab1e1111111111111111111111111');
4223
+
4224
+ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
4225
+
4226
+ /**
4227
+ * Sign, send and confirm a transaction.
4228
+ *
4229
+ * If `commitment` option is not specified, defaults to 'max' commitment.
4230
+ *
4231
+ * @param {Connection} connection
4232
+ * @param {Transaction} transaction
4233
+ * @param {Array<Signer>} signers
4234
+ * @param {ConfirmOptions} [options]
4235
+ * @returns {Promise<TransactionSignature>}
4236
+ */
4237
+ async function sendAndConfirmTransaction(connection, transaction, signers, options) {
4238
+ const sendOptions = options && {
4239
+ skipPreflight: options.skipPreflight,
4240
+ preflightCommitment: options.preflightCommitment || options.commitment,
4241
+ maxRetries: options.maxRetries,
4242
+ minContextSlot: options.minContextSlot
4243
+ };
4244
+ const signature = await connection.sendTransaction(transaction, signers, sendOptions);
4245
+ const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
4246
+ signature: signature,
4247
+ blockhash: transaction.recentBlockhash,
4248
+ lastValidBlockHeight: transaction.lastValidBlockHeight
4249
+ }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
4250
+
4251
+ if (status.err) {
4252
+ throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
4253
+ }
4254
+
4255
+ return signature;
4256
+ }
4257
+
4258
+ // zzz
4259
+ function sleep(ms) {
4260
+ return new Promise(resolve => setTimeout(resolve, ms));
4261
+ }
4262
+
3964
4263
  // rest of the Transaction fields
3965
4264
  //
3966
4265
  // TODO: replace 300 with a proper constant for the size of the other
@@ -4429,6 +4728,8 @@ var fastStableStringify = function(val) {
4429
4728
 
4430
4729
  var fastStableStringify$1 = fastStableStringify;
4431
4730
 
4731
+ const URL = globalThis.URL;
4732
+
4432
4733
  const MINIMUM_SLOT_PER_EPOCH = 32; // Returns the number of trailing zeros in the binary representation of self.
4433
4734
 
4434
4735
  function trailingZeros(n) {
@@ -4826,7 +5127,11 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(superstruct.t
4826
5127
  data: superstruct.array(superstruct.string()),
4827
5128
  rentEpoch: superstruct.optional(superstruct.number())
4828
5129
  }))))),
4829
- unitsConsumed: superstruct.optional(superstruct.number())
5130
+ unitsConsumed: superstruct.optional(superstruct.number()),
5131
+ returnData: superstruct.optional(superstruct.nullable(superstruct.type({
5132
+ programId: superstruct.string(),
5133
+ data: superstruct.tuple([superstruct.string(), superstruct.literal('base64')])
5134
+ })))
4830
5135
  }));
4831
5136
 
4832
5137
  /**
@@ -6163,16 +6468,6 @@ class Connection {
6163
6468
  reject(err);
6164
6469
  }
6165
6470
  });
6166
-
6167
- const checkBlockHeight = async () => {
6168
- try {
6169
- const blockHeight = await this.getBlockHeight(commitment);
6170
- return blockHeight;
6171
- } catch (_e) {
6172
- return -1;
6173
- }
6174
- };
6175
-
6176
6471
  const expiryPromise = new Promise(resolve => {
6177
6472
  if (typeof strategy === 'string') {
6178
6473
  let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
@@ -6196,6 +6491,15 @@ class Connection {
6196
6491
  } else {
6197
6492
  let config = strategy;
6198
6493
 
6494
+ const checkBlockHeight = async () => {
6495
+ try {
6496
+ const blockHeight = await this.getBlockHeight(commitment);
6497
+ return blockHeight;
6498
+ } catch (_e) {
6499
+ return -1;
6500
+ }
6501
+ };
6502
+
6199
6503
  (async () => {
6200
6504
  let currentBlockHeight = await checkBlockHeight();
6201
6505
  if (done) return;
@@ -9943,6 +10247,8 @@ function clusterApiUrl(cluster, tls) {
9943
10247
  const LAMPORTS_PER_SOL = 1000000000;
9944
10248
 
9945
10249
  exports.Account = Account;
10250
+ exports.AddressLookupTableInstruction = AddressLookupTableInstruction;
10251
+ exports.AddressLookupTableProgram = AddressLookupTableProgram;
9946
10252
  exports.Authorized = Authorized;
9947
10253
  exports.BLOCKHASH_CACHE_TIMEOUT_MS = BLOCKHASH_CACHE_TIMEOUT_MS;
9948
10254
  exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
@@ -9958,6 +10264,7 @@ exports.EpochSchedule = EpochSchedule;
9958
10264
  exports.FeeCalculatorLayout = FeeCalculatorLayout;
9959
10265
  exports.Keypair = Keypair;
9960
10266
  exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
10267
+ exports.LOOKUP_TABLE_INSTRUCTION_LAYOUTS = LOOKUP_TABLE_INSTRUCTION_LAYOUTS;
9961
10268
  exports.Loader = Loader;
9962
10269
  exports.Lockup = Lockup;
9963
10270
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;