@solana/web3.js 1.47.4 → 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;
@@ -3098,202 +3239,35 @@ class Transaction {
3098
3239
 
3099
3240
  }
3100
3241
 
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
3242
  /**
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>}
3243
+ * Create account system transaction params
3121
3244
  */
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
3245
 
3148
3246
  /**
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
3247
+ * System Instruction class
3164
3248
  */
3249
+ class SystemInstruction {
3250
+ /**
3251
+ * @internal
3252
+ */
3253
+ constructor() {}
3254
+ /**
3255
+ * Decode a system instruction and retrieve the instruction type.
3256
+ */
3165
3257
 
3166
- function decodeData(type, buffer) {
3167
- let data;
3168
3258
 
3169
- try {
3170
- data = type.layout.decode(buffer);
3171
- } catch (err) {
3172
- throw new Error('invalid instruction; ' + err);
3173
- }
3259
+ static decodeInstructionType(instruction) {
3260
+ this.checkProgramId(instruction.programId);
3261
+ const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
3262
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
3263
+ let type;
3174
3264
 
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
- };
3265
-
3266
- const u64 = bigInt(8);
3267
-
3268
- /**
3269
- * Create account system transaction params
3270
- */
3271
-
3272
- /**
3273
- * System Instruction class
3274
- */
3275
- class SystemInstruction {
3276
- /**
3277
- * @internal
3278
- */
3279
- constructor() {}
3280
- /**
3281
- * Decode a system instruction and retrieve the instruction type.
3282
- */
3283
-
3284
-
3285
- static decodeInstructionType(instruction) {
3286
- this.checkProgramId(instruction.programId);
3287
- const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
3288
- const typeIndex = instructionTypeLayout.decode(instruction.data);
3289
- let type;
3290
-
3291
- for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
3292
- if (layout.index == typeIndex) {
3293
- type = ixType;
3294
- break;
3295
- }
3296
- }
3265
+ for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
3266
+ if (layout.index == typeIndex) {
3267
+ type = ixType;
3268
+ break;
3269
+ }
3270
+ }
3297
3271
 
3298
3272
  if (!type) {
3299
3273
  throw new Error('Instruction type incorrect; not a SystemInstruction');
@@ -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
@@ -9967,6 +10247,8 @@ function clusterApiUrl(cluster, tls) {
9967
10247
  const LAMPORTS_PER_SOL = 1000000000;
9968
10248
 
9969
10249
  exports.Account = Account;
10250
+ exports.AddressLookupTableInstruction = AddressLookupTableInstruction;
10251
+ exports.AddressLookupTableProgram = AddressLookupTableProgram;
9970
10252
  exports.Authorized = Authorized;
9971
10253
  exports.BLOCKHASH_CACHE_TIMEOUT_MS = BLOCKHASH_CACHE_TIMEOUT_MS;
9972
10254
  exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
@@ -9982,6 +10264,7 @@ exports.EpochSchedule = EpochSchedule;
9982
10264
  exports.FeeCalculatorLayout = FeeCalculatorLayout;
9983
10265
  exports.Keypair = Keypair;
9984
10266
  exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
10267
+ exports.LOOKUP_TABLE_INSTRUCTION_LAYOUTS = LOOKUP_TABLE_INSTRUCTION_LAYOUTS;
9985
10268
  exports.Loader = Loader;
9986
10269
  exports.Lockup = Lockup;
9987
10270
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;