@solana/web3.js 1.47.3 → 1.49.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;
@@ -3069,201 +3210,34 @@ class Transaction {
3069
3210
  transaction.feePayer = message.accountKeys[0];
3070
3211
  }
3071
3212
 
3072
- signatures.forEach((signature, index) => {
3073
- const sigPubkeyPair = {
3074
- signature: signature == bs58__default["default"].encode(DEFAULT_SIGNATURE) ? null : bs58__default["default"].decode(signature),
3075
- publicKey: message.accountKeys[index]
3076
- };
3077
- transaction.signatures.push(sigPubkeyPair);
3078
- });
3079
- message.instructions.forEach(instruction => {
3080
- const keys = instruction.accounts.map(account => {
3081
- const pubkey = message.accountKeys[account];
3082
- return {
3083
- pubkey,
3084
- isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
3085
- isWritable: message.isAccountWritable(account)
3086
- };
3087
- });
3088
- transaction.instructions.push(new TransactionInstruction({
3089
- keys,
3090
- programId: message.accountKeys[instruction.programIdIndex],
3091
- data: bs58__default["default"].decode(instruction.data)
3092
- }));
3093
- });
3094
- transaction._message = message;
3095
- transaction._json = transaction.toJSON();
3096
- return transaction;
3097
- }
3098
-
3099
- }
3100
-
3101
- const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3102
- const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3103
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
3104
- const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
3105
- const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
3106
- const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
3107
- const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
3108
- const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
3109
- const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
3110
-
3111
- /**
3112
- * Sign, send and confirm a transaction.
3113
- *
3114
- * If `commitment` option is not specified, defaults to 'max' commitment.
3115
- *
3116
- * @param {Connection} connection
3117
- * @param {Transaction} transaction
3118
- * @param {Array<Signer>} signers
3119
- * @param {ConfirmOptions} [options]
3120
- * @returns {Promise<TransactionSignature>}
3121
- */
3122
- async function sendAndConfirmTransaction(connection, transaction, signers, options) {
3123
- const sendOptions = options && {
3124
- skipPreflight: options.skipPreflight,
3125
- preflightCommitment: options.preflightCommitment || options.commitment,
3126
- maxRetries: options.maxRetries,
3127
- minContextSlot: options.minContextSlot
3128
- };
3129
- const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3130
- const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
3131
- signature: signature,
3132
- blockhash: transaction.recentBlockhash,
3133
- lastValidBlockHeight: transaction.lastValidBlockHeight
3134
- }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
3135
-
3136
- if (status.err) {
3137
- throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
3138
- }
3139
-
3140
- return signature;
3141
- }
3142
-
3143
- // zzz
3144
- function sleep(ms) {
3145
- return new Promise(resolve => setTimeout(resolve, ms));
3146
- }
3147
-
3148
- /**
3149
- * Populate a buffer of instruction data using an InstructionType
3150
- * @internal
3151
- */
3152
- function encodeData(type, fields) {
3153
- const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
3154
- const data = buffer.Buffer.alloc(allocLength);
3155
- const layoutFields = Object.assign({
3156
- instruction: type.index
3157
- }, fields);
3158
- type.layout.encode(layoutFields, data);
3159
- return data;
3160
- }
3161
- /**
3162
- * Decode instruction data buffer using an InstructionType
3163
- * @internal
3164
- */
3165
-
3166
- function decodeData(type, buffer) {
3167
- let data;
3168
-
3169
- try {
3170
- data = type.layout.decode(buffer);
3171
- } catch (err) {
3172
- throw new Error('invalid instruction; ' + err);
3173
- }
3174
-
3175
- if (data.instruction !== type.index) {
3176
- throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
3177
- }
3178
-
3179
- return data;
3180
- }
3181
-
3182
- /**
3183
- * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
3184
- *
3185
- * @internal
3186
- */
3187
-
3188
- const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
3189
- /**
3190
- * Calculator for transaction fees.
3191
- */
3192
-
3193
- /**
3194
- * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
3195
- *
3196
- * @internal
3197
- */
3198
-
3199
- const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
3200
- const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
3201
-
3202
- /**
3203
- * NonceAccount class
3204
- */
3205
- class NonceAccount {
3206
- /**
3207
- * @internal
3208
- */
3209
- constructor(args) {
3210
- this.authorizedPubkey = void 0;
3211
- this.nonce = void 0;
3212
- this.feeCalculator = void 0;
3213
- this.authorizedPubkey = args.authorizedPubkey;
3214
- this.nonce = args.nonce;
3215
- this.feeCalculator = args.feeCalculator;
3216
- }
3217
- /**
3218
- * Deserialize NonceAccount from the account data.
3219
- *
3220
- * @param buffer account data
3221
- * @return NonceAccount
3222
- */
3223
-
3224
-
3225
- static fromAccountData(buffer) {
3226
- const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
3227
- return new NonceAccount({
3228
- authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
3229
- nonce: new PublicKey(nonceAccount.nonce).toString(),
3230
- feeCalculator: nonceAccount.feeCalculator
3231
- });
3232
- }
3233
-
3234
- }
3235
-
3236
- const encodeDecode = layout => {
3237
- const decode = layout.decode.bind(layout);
3238
- const encode = layout.encode.bind(layout);
3239
- return {
3240
- decode,
3241
- encode
3242
- };
3243
- };
3244
-
3245
- const bigInt = length => property => {
3246
- const layout = BufferLayout.blob(length, property);
3247
- const {
3248
- encode,
3249
- decode
3250
- } = encodeDecode(layout);
3251
- const bigIntLayout = layout;
3252
-
3253
- bigIntLayout.decode = (buffer$1, offset) => {
3254
- const src = decode(buffer$1, offset);
3255
- return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
3256
- };
3257
-
3258
- bigIntLayout.encode = (bigInt, buffer, offset) => {
3259
- const src = bigintBuffer.toBufferLE(bigInt, length);
3260
- return encode(src, buffer, offset);
3261
- };
3262
-
3263
- return bigIntLayout;
3264
- };
3213
+ signatures.forEach((signature, index) => {
3214
+ const sigPubkeyPair = {
3215
+ signature: signature == bs58__default["default"].encode(DEFAULT_SIGNATURE) ? null : bs58__default["default"].decode(signature),
3216
+ publicKey: message.accountKeys[index]
3217
+ };
3218
+ transaction.signatures.push(sigPubkeyPair);
3219
+ });
3220
+ message.instructions.forEach(instruction => {
3221
+ const keys = instruction.accounts.map(account => {
3222
+ const pubkey = message.accountKeys[account];
3223
+ return {
3224
+ pubkey,
3225
+ isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
3226
+ isWritable: message.isAccountWritable(account)
3227
+ };
3228
+ });
3229
+ transaction.instructions.push(new TransactionInstruction({
3230
+ keys,
3231
+ programId: message.accountKeys[instruction.programIdIndex],
3232
+ data: bs58__default["default"].decode(instruction.data)
3233
+ }));
3234
+ });
3235
+ transaction._message = message;
3236
+ transaction._json = transaction.toJSON();
3237
+ return transaction;
3238
+ }
3265
3239
 
3266
- const u64 = bigInt(8);
3240
+ }
3267
3241
 
3268
3242
  /**
3269
3243
  * Create account system transaction params
@@ -3980,6 +3954,312 @@ class SystemProgram {
3980
3954
  }
3981
3955
  SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3982
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
+
3983
4263
  // rest of the Transaction fields
3984
4264
  //
3985
4265
  // TODO: replace 300 with a proper constant for the size of the other
@@ -4448,6 +4728,8 @@ var fastStableStringify = function(val) {
4448
4728
 
4449
4729
  var fastStableStringify$1 = fastStableStringify;
4450
4730
 
4731
+ const URL = globalThis.URL;
4732
+
4451
4733
  const MINIMUM_SLOT_PER_EPOCH = 32; // Returns the number of trailing zeros in the binary representation of self.
4452
4734
 
4453
4735
  function trailingZeros(n) {
@@ -4845,7 +5127,11 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(superstruct.t
4845
5127
  data: superstruct.array(superstruct.string()),
4846
5128
  rentEpoch: superstruct.optional(superstruct.number())
4847
5129
  }))))),
4848
- 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
+ })))
4849
5135
  }));
4850
5136
 
4851
5137
  /**
@@ -6725,8 +7011,15 @@ class Connection {
6725
7011
  */
6726
7012
 
6727
7013
 
6728
- async getBlock(slot, opts) {
6729
- const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
7014
+ async getBlock(slot, rawConfig) {
7015
+ const {
7016
+ commitment,
7017
+ config
7018
+ } = extractCommitmentFromConfig(rawConfig);
7019
+
7020
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined
7021
+ /* encoding */
7022
+ , config);
6730
7023
 
6731
7024
  const unsafeRes = await this._rpcRequest('getBlock', args);
6732
7025
  const res = superstruct.create(unsafeRes, GetBlockRpcResult);
@@ -6812,8 +7105,15 @@ class Connection {
6812
7105
  */
6813
7106
 
6814
7107
 
6815
- async getTransaction(signature, opts) {
6816
- const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
7108
+ async getTransaction(signature, rawConfig) {
7109
+ const {
7110
+ commitment,
7111
+ config
7112
+ } = extractCommitmentFromConfig(rawConfig);
7113
+
7114
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
7115
+ /* encoding */
7116
+ , config);
6817
7117
 
6818
7118
  const unsafeRes = await this._rpcRequest('getTransaction', args);
6819
7119
  const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
@@ -9961,6 +10261,8 @@ function clusterApiUrl(cluster, tls) {
9961
10261
  const LAMPORTS_PER_SOL = 1000000000;
9962
10262
 
9963
10263
  exports.Account = Account;
10264
+ exports.AddressLookupTableInstruction = AddressLookupTableInstruction;
10265
+ exports.AddressLookupTableProgram = AddressLookupTableProgram;
9964
10266
  exports.Authorized = Authorized;
9965
10267
  exports.BLOCKHASH_CACHE_TIMEOUT_MS = BLOCKHASH_CACHE_TIMEOUT_MS;
9966
10268
  exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
@@ -9976,6 +10278,7 @@ exports.EpochSchedule = EpochSchedule;
9976
10278
  exports.FeeCalculatorLayout = FeeCalculatorLayout;
9977
10279
  exports.Keypair = Keypair;
9978
10280
  exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
10281
+ exports.LOOKUP_TABLE_INSTRUCTION_LAYOUTS = LOOKUP_TABLE_INSTRUCTION_LAYOUTS;
9979
10282
  exports.Loader = Loader;
9980
10283
  exports.Lockup = Lockup;
9981
10284
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;