@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.
@@ -3,9 +3,9 @@ import { Buffer } from 'buffer';
3
3
  import BN from 'bn.js';
4
4
  import bs58 from 'bs58';
5
5
  import { serialize, deserialize, deserializeUnchecked } from 'borsh';
6
+ import { toBigIntLE, toBufferLE } from 'bigint-buffer';
6
7
  import * as BufferLayout from '@solana/buffer-layout';
7
8
  import { blob } from '@solana/buffer-layout';
8
- import { toBigIntLE, toBufferLE } from 'bigint-buffer';
9
9
  import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$7 } from 'superstruct';
10
10
  import { Client } from 'rpc-websockets';
11
11
  import RpcClient from 'jayson/lib/client/browser';
@@ -2070,18 +2070,6 @@ class Account {
2070
2070
 
2071
2071
  }
2072
2072
 
2073
- const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
2074
-
2075
- /**
2076
- * Maximum over-the-wire size of a Transaction
2077
- *
2078
- * 1280 is IPv6 minimum MTU
2079
- * 40 bytes is the size of the IPv6 header
2080
- * 8 bytes is the size of the fragment header
2081
- */
2082
- const PACKET_DATA_SIZE = 1280 - 40 - 8;
2083
- const SIGNATURE_LENGTH_IN_BYTES = 64;
2084
-
2085
2073
  /**
2086
2074
  * Layout for a public key
2087
2075
  */
@@ -2143,17 +2131,170 @@ const voteInit = (property = 'voteInit') => {
2143
2131
  return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
2144
2132
  };
2145
2133
  function getAlloc(type, fields) {
2146
- let alloc = 0;
2147
- type.layout.fields.forEach(item => {
2134
+ const getItemAlloc = item => {
2148
2135
  if (item.span >= 0) {
2149
- alloc += item.span;
2136
+ return item.span;
2150
2137
  } else if (typeof item.alloc === 'function') {
2151
- alloc += item.alloc(fields[item.property]);
2152
- }
2138
+ return item.alloc(fields[item.property]);
2139
+ } else if ('count' in item && 'elementLayout' in item) {
2140
+ const field = fields[item.property];
2141
+
2142
+ if (Array.isArray(field)) {
2143
+ return field.length * getItemAlloc(item.elementLayout);
2144
+ }
2145
+ } // Couldn't determine allocated size of layout
2146
+
2147
+
2148
+ return 0;
2149
+ };
2150
+
2151
+ let alloc = 0;
2152
+ type.layout.fields.forEach(item => {
2153
+ alloc += getItemAlloc(item);
2153
2154
  });
2154
2155
  return alloc;
2155
2156
  }
2156
2157
 
2158
+ const encodeDecode = layout => {
2159
+ const decode = layout.decode.bind(layout);
2160
+ const encode = layout.encode.bind(layout);
2161
+ return {
2162
+ decode,
2163
+ encode
2164
+ };
2165
+ };
2166
+
2167
+ const bigInt = length => property => {
2168
+ const layout = blob(length, property);
2169
+ const {
2170
+ encode,
2171
+ decode
2172
+ } = encodeDecode(layout);
2173
+ const bigIntLayout = layout;
2174
+
2175
+ bigIntLayout.decode = (buffer, offset) => {
2176
+ const src = decode(buffer, offset);
2177
+ return toBigIntLE(Buffer.from(src));
2178
+ };
2179
+
2180
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
2181
+ const src = toBufferLE(bigInt, length);
2182
+ return encode(src, buffer, offset);
2183
+ };
2184
+
2185
+ return bigIntLayout;
2186
+ };
2187
+
2188
+ const u64 = bigInt(8);
2189
+
2190
+ /**
2191
+ * Populate a buffer of instruction data using an InstructionType
2192
+ * @internal
2193
+ */
2194
+ function encodeData(type, fields) {
2195
+ const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
2196
+ const data = Buffer.alloc(allocLength);
2197
+ const layoutFields = Object.assign({
2198
+ instruction: type.index
2199
+ }, fields);
2200
+ type.layout.encode(layoutFields, data);
2201
+ return data;
2202
+ }
2203
+ /**
2204
+ * Decode instruction data buffer using an InstructionType
2205
+ * @internal
2206
+ */
2207
+
2208
+ function decodeData(type, buffer) {
2209
+ let data;
2210
+
2211
+ try {
2212
+ data = type.layout.decode(buffer);
2213
+ } catch (err) {
2214
+ throw new Error('invalid instruction; ' + err);
2215
+ }
2216
+
2217
+ if (data.instruction !== type.index) {
2218
+ throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
2219
+ }
2220
+
2221
+ return data;
2222
+ }
2223
+
2224
+ /**
2225
+ * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
2226
+ *
2227
+ * @internal
2228
+ */
2229
+
2230
+ const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
2231
+ /**
2232
+ * Calculator for transaction fees.
2233
+ */
2234
+
2235
+ /**
2236
+ * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
2237
+ *
2238
+ * @internal
2239
+ */
2240
+
2241
+ const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
2242
+ const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
2243
+
2244
+ /**
2245
+ * NonceAccount class
2246
+ */
2247
+ class NonceAccount {
2248
+ /**
2249
+ * @internal
2250
+ */
2251
+ constructor(args) {
2252
+ this.authorizedPubkey = void 0;
2253
+ this.nonce = void 0;
2254
+ this.feeCalculator = void 0;
2255
+ this.authorizedPubkey = args.authorizedPubkey;
2256
+ this.nonce = args.nonce;
2257
+ this.feeCalculator = args.feeCalculator;
2258
+ }
2259
+ /**
2260
+ * Deserialize NonceAccount from the account data.
2261
+ *
2262
+ * @param buffer account data
2263
+ * @return NonceAccount
2264
+ */
2265
+
2266
+
2267
+ static fromAccountData(buffer) {
2268
+ const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
2269
+ return new NonceAccount({
2270
+ authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
2271
+ nonce: new PublicKey(nonceAccount.nonce).toString(),
2272
+ feeCalculator: nonceAccount.feeCalculator
2273
+ });
2274
+ }
2275
+
2276
+ }
2277
+
2278
+ const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2279
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2280
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2281
+ const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2282
+ const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2283
+ const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2284
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2285
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2286
+ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2287
+
2288
+ /**
2289
+ * Maximum over-the-wire size of a Transaction
2290
+ *
2291
+ * 1280 is IPv6 minimum MTU
2292
+ * 40 bytes is the size of the IPv6 header
2293
+ * 8 bytes is the size of the fragment header
2294
+ */
2295
+ const PACKET_DATA_SIZE = 1280 - 40 - 8;
2296
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
2297
+
2157
2298
  function decodeLength(bytes) {
2158
2299
  let len = 0;
2159
2300
  let size = 0;
@@ -2447,15 +2588,34 @@ class Transaction {
2447
2588
 
2448
2589
  if (!opts) {
2449
2590
  return;
2450
- } else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
2451
- const newOpts = opts;
2452
- Object.assign(this, newOpts);
2453
- this.recentBlockhash = newOpts.blockhash;
2454
- this.lastValidBlockHeight = newOpts.lastValidBlockHeight;
2591
+ }
2592
+
2593
+ if (opts.feePayer) {
2594
+ this.feePayer = opts.feePayer;
2595
+ }
2596
+
2597
+ if (opts.signatures) {
2598
+ this.signatures = opts.signatures;
2599
+ }
2600
+
2601
+ if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
2602
+ const {
2603
+ blockhash,
2604
+ lastValidBlockHeight
2605
+ } = opts;
2606
+ this.recentBlockhash = blockhash;
2607
+ this.lastValidBlockHeight = lastValidBlockHeight;
2455
2608
  } else {
2456
- const oldOpts = opts;
2457
- Object.assign(this, oldOpts);
2458
- this.recentBlockhash = oldOpts.recentBlockhash;
2609
+ const {
2610
+ recentBlockhash,
2611
+ nonceInfo
2612
+ } = opts;
2613
+
2614
+ if (nonceInfo) {
2615
+ this.nonceInfo = nonceInfo;
2616
+ }
2617
+
2618
+ this.recentBlockhash = recentBlockhash;
2459
2619
  }
2460
2620
  }
2461
2621
  /**
@@ -3048,188 +3208,21 @@ class Transaction {
3048
3208
 
3049
3209
  }
3050
3210
 
3051
- const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3052
- const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3053
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
3054
- const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
3055
- const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
3056
- const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
3057
- const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
3058
- const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
3059
- const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
3060
-
3061
3211
  /**
3062
- * Sign, send and confirm a transaction.
3063
- *
3064
- * If `commitment` option is not specified, defaults to 'max' commitment.
3065
- *
3066
- * @param {Connection} connection
3067
- * @param {Transaction} transaction
3068
- * @param {Array<Signer>} signers
3069
- * @param {ConfirmOptions} [options]
3070
- * @returns {Promise<TransactionSignature>}
3212
+ * Create account system transaction params
3071
3213
  */
3072
- async function sendAndConfirmTransaction(connection, transaction, signers, options) {
3073
- const sendOptions = options && {
3074
- skipPreflight: options.skipPreflight,
3075
- preflightCommitment: options.preflightCommitment || options.commitment,
3076
- maxRetries: options.maxRetries,
3077
- minContextSlot: options.minContextSlot
3078
- };
3079
- const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3080
- const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
3081
- signature: signature,
3082
- blockhash: transaction.recentBlockhash,
3083
- lastValidBlockHeight: transaction.lastValidBlockHeight
3084
- }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
3085
-
3086
- if (status.err) {
3087
- throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
3088
- }
3089
-
3090
- return signature;
3091
- }
3092
3214
 
3093
- // zzz
3094
- function sleep(ms) {
3095
- return new Promise(resolve => setTimeout(resolve, ms));
3096
- }
3097
-
3098
- /**
3099
- * Populate a buffer of instruction data using an InstructionType
3100
- * @internal
3101
- */
3102
- function encodeData(type, fields) {
3103
- const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
3104
- const data = Buffer.alloc(allocLength);
3105
- const layoutFields = Object.assign({
3106
- instruction: type.index
3107
- }, fields);
3108
- type.layout.encode(layoutFields, data);
3109
- return data;
3110
- }
3111
3215
  /**
3112
- * Decode instruction data buffer using an InstructionType
3113
- * @internal
3216
+ * System Instruction class
3114
3217
  */
3115
-
3116
- function decodeData(type, buffer) {
3117
- let data;
3118
-
3119
- try {
3120
- data = type.layout.decode(buffer);
3121
- } catch (err) {
3122
- throw new Error('invalid instruction; ' + err);
3123
- }
3124
-
3125
- if (data.instruction !== type.index) {
3126
- throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
3127
- }
3128
-
3129
- return data;
3130
- }
3131
-
3132
- /**
3133
- * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
3134
- *
3135
- * @internal
3136
- */
3137
-
3138
- const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
3139
- /**
3140
- * Calculator for transaction fees.
3141
- */
3142
-
3143
- /**
3144
- * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
3145
- *
3146
- * @internal
3147
- */
3148
-
3149
- const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
3150
- const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
3151
-
3152
- /**
3153
- * NonceAccount class
3154
- */
3155
- class NonceAccount {
3156
- /**
3157
- * @internal
3158
- */
3159
- constructor(args) {
3160
- this.authorizedPubkey = void 0;
3161
- this.nonce = void 0;
3162
- this.feeCalculator = void 0;
3163
- this.authorizedPubkey = args.authorizedPubkey;
3164
- this.nonce = args.nonce;
3165
- this.feeCalculator = args.feeCalculator;
3166
- }
3167
- /**
3168
- * Deserialize NonceAccount from the account data.
3169
- *
3170
- * @param buffer account data
3171
- * @return NonceAccount
3172
- */
3173
-
3174
-
3175
- static fromAccountData(buffer) {
3176
- const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
3177
- return new NonceAccount({
3178
- authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
3179
- nonce: new PublicKey(nonceAccount.nonce).toString(),
3180
- feeCalculator: nonceAccount.feeCalculator
3181
- });
3182
- }
3183
-
3184
- }
3185
-
3186
- const encodeDecode = layout => {
3187
- const decode = layout.decode.bind(layout);
3188
- const encode = layout.encode.bind(layout);
3189
- return {
3190
- decode,
3191
- encode
3192
- };
3193
- };
3194
-
3195
- const bigInt = length => property => {
3196
- const layout = blob(length, property);
3197
- const {
3198
- encode,
3199
- decode
3200
- } = encodeDecode(layout);
3201
- const bigIntLayout = layout;
3202
-
3203
- bigIntLayout.decode = (buffer, offset) => {
3204
- const src = decode(buffer, offset);
3205
- return toBigIntLE(Buffer.from(src));
3206
- };
3207
-
3208
- bigIntLayout.encode = (bigInt, buffer, offset) => {
3209
- const src = toBufferLE(bigInt, length);
3210
- return encode(src, buffer, offset);
3211
- };
3212
-
3213
- return bigIntLayout;
3214
- };
3215
-
3216
- const u64 = bigInt(8);
3217
-
3218
- /**
3219
- * Create account system transaction params
3220
- */
3221
-
3222
- /**
3223
- * System Instruction class
3224
- */
3225
- class SystemInstruction {
3226
- /**
3227
- * @internal
3228
- */
3229
- constructor() {}
3230
- /**
3231
- * Decode a system instruction and retrieve the instruction type.
3232
- */
3218
+ class SystemInstruction {
3219
+ /**
3220
+ * @internal
3221
+ */
3222
+ constructor() {}
3223
+ /**
3224
+ * Decode a system instruction and retrieve the instruction type.
3225
+ */
3233
3226
 
3234
3227
 
3235
3228
  static decodeInstructionType(instruction) {
@@ -3930,6 +3923,312 @@ class SystemProgram {
3930
3923
  }
3931
3924
  SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3932
3925
 
3926
+ /**
3927
+ * An enumeration of valid address lookup table InstructionType's
3928
+ * @internal
3929
+ */
3930
+ const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
3931
+ CreateLookupTable: {
3932
+ index: 0,
3933
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64('recentSlot'), BufferLayout.u8('bumpSeed')])
3934
+ },
3935
+ FreezeLookupTable: {
3936
+ index: 1,
3937
+ layout: BufferLayout.struct([BufferLayout.u32('instruction')])
3938
+ },
3939
+ ExtendLookupTable: {
3940
+ index: 2,
3941
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64(), BufferLayout.seq(publicKey(), BufferLayout.offset(BufferLayout.u32(), -8), 'addresses')])
3942
+ },
3943
+ DeactivateLookupTable: {
3944
+ index: 3,
3945
+ layout: BufferLayout.struct([BufferLayout.u32('instruction')])
3946
+ },
3947
+ CloseLookupTable: {
3948
+ index: 4,
3949
+ layout: BufferLayout.struct([BufferLayout.u32('instruction')])
3950
+ }
3951
+ });
3952
+ class AddressLookupTableInstruction {
3953
+ /**
3954
+ * @internal
3955
+ */
3956
+ constructor() {}
3957
+
3958
+ static decodeInstructionType(instruction) {
3959
+ this.checkProgramId(instruction.programId);
3960
+ const instructionTypeLayout = BufferLayout.u32('instruction');
3961
+ const index = instructionTypeLayout.decode(instruction.data);
3962
+ let type;
3963
+
3964
+ for (const [layoutType, layout] of Object.entries(LOOKUP_TABLE_INSTRUCTION_LAYOUTS)) {
3965
+ if (layout.index == index) {
3966
+ type = layoutType;
3967
+ break;
3968
+ }
3969
+ }
3970
+
3971
+ if (!type) {
3972
+ throw new Error('Invalid Instruction. Should be a LookupTable Instruction');
3973
+ }
3974
+
3975
+ return type;
3976
+ }
3977
+
3978
+ static decodeCreateLookupTable(instruction) {
3979
+ this.checkProgramId(instruction.programId);
3980
+ this.checkKeysLength(instruction.keys, 4);
3981
+ const {
3982
+ recentSlot
3983
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable, instruction.data);
3984
+ return {
3985
+ authority: instruction.keys[1].pubkey,
3986
+ payer: instruction.keys[2].pubkey,
3987
+ recentSlot: Number(recentSlot)
3988
+ };
3989
+ }
3990
+
3991
+ static decodeExtendLookupTable(instruction) {
3992
+ this.checkProgramId(instruction.programId);
3993
+
3994
+ if (instruction.keys.length < 2) {
3995
+ throw new Error(`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`);
3996
+ }
3997
+
3998
+ const {
3999
+ addresses
4000
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable, instruction.data);
4001
+ return {
4002
+ lookupTable: instruction.keys[0].pubkey,
4003
+ authority: instruction.keys[1].pubkey,
4004
+ payer: instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
4005
+ addresses: addresses.map(buffer => new PublicKey(buffer))
4006
+ };
4007
+ }
4008
+
4009
+ static decodeCloseLookupTable(instruction) {
4010
+ this.checkProgramId(instruction.programId);
4011
+ this.checkKeysLength(instruction.keys, 3);
4012
+ return {
4013
+ lookupTable: instruction.keys[0].pubkey,
4014
+ authority: instruction.keys[1].pubkey,
4015
+ recipient: instruction.keys[2].pubkey
4016
+ };
4017
+ }
4018
+
4019
+ static decodeFreezeLookupTable(instruction) {
4020
+ this.checkProgramId(instruction.programId);
4021
+ this.checkKeysLength(instruction.keys, 2);
4022
+ return {
4023
+ lookupTable: instruction.keys[0].pubkey,
4024
+ authority: instruction.keys[1].pubkey
4025
+ };
4026
+ }
4027
+
4028
+ static decodeDeactivateLookupTable(instruction) {
4029
+ this.checkProgramId(instruction.programId);
4030
+ this.checkKeysLength(instruction.keys, 2);
4031
+ return {
4032
+ lookupTable: instruction.keys[0].pubkey,
4033
+ authority: instruction.keys[1].pubkey
4034
+ };
4035
+ }
4036
+ /**
4037
+ * @internal
4038
+ */
4039
+
4040
+
4041
+ static checkProgramId(programId) {
4042
+ if (!programId.equals(AddressLookupTableProgram.programId)) {
4043
+ throw new Error('invalid instruction; programId is not AddressLookupTable Program');
4044
+ }
4045
+ }
4046
+ /**
4047
+ * @internal
4048
+ */
4049
+
4050
+
4051
+ static checkKeysLength(keys, expectedLength) {
4052
+ if (keys.length < expectedLength) {
4053
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
4054
+ }
4055
+ }
4056
+
4057
+ }
4058
+ class AddressLookupTableProgram {
4059
+ /**
4060
+ * @internal
4061
+ */
4062
+ constructor() {}
4063
+
4064
+ static createLookupTable(params) {
4065
+ const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
4066
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
4067
+ const data = encodeData(type, {
4068
+ recentSlot: BigInt(params.recentSlot),
4069
+ bumpSeed: bumpSeed
4070
+ });
4071
+ const keys = [{
4072
+ pubkey: lookupTableAddress,
4073
+ isSigner: false,
4074
+ isWritable: true
4075
+ }, {
4076
+ pubkey: params.authority,
4077
+ isSigner: true,
4078
+ isWritable: false
4079
+ }, {
4080
+ pubkey: params.payer,
4081
+ isSigner: true,
4082
+ isWritable: true
4083
+ }, {
4084
+ pubkey: SystemProgram.programId,
4085
+ isSigner: false,
4086
+ isWritable: false
4087
+ }];
4088
+ return [new TransactionInstruction({
4089
+ programId: this.programId,
4090
+ keys: keys,
4091
+ data: data
4092
+ }), lookupTableAddress];
4093
+ }
4094
+
4095
+ static freezeLookupTable(params) {
4096
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
4097
+ const data = encodeData(type);
4098
+ const keys = [{
4099
+ pubkey: params.lookupTable,
4100
+ isSigner: false,
4101
+ isWritable: true
4102
+ }, {
4103
+ pubkey: params.authority,
4104
+ isSigner: true,
4105
+ isWritable: false
4106
+ }];
4107
+ return new TransactionInstruction({
4108
+ programId: this.programId,
4109
+ keys: keys,
4110
+ data: data
4111
+ });
4112
+ }
4113
+
4114
+ static extendLookupTable(params) {
4115
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
4116
+ const data = encodeData(type, {
4117
+ addresses: params.addresses.map(addr => addr.toBytes())
4118
+ });
4119
+ const keys = [{
4120
+ pubkey: params.lookupTable,
4121
+ isSigner: false,
4122
+ isWritable: true
4123
+ }, {
4124
+ pubkey: params.authority,
4125
+ isSigner: true,
4126
+ isWritable: false
4127
+ }];
4128
+
4129
+ if (params.payer) {
4130
+ keys.push({
4131
+ pubkey: params.payer,
4132
+ isSigner: true,
4133
+ isWritable: true
4134
+ }, {
4135
+ pubkey: SystemProgram.programId,
4136
+ isSigner: false,
4137
+ isWritable: false
4138
+ });
4139
+ }
4140
+
4141
+ return new TransactionInstruction({
4142
+ programId: this.programId,
4143
+ keys: keys,
4144
+ data: data
4145
+ });
4146
+ }
4147
+
4148
+ static deactivateLookupTable(params) {
4149
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
4150
+ const data = encodeData(type);
4151
+ const keys = [{
4152
+ pubkey: params.lookupTable,
4153
+ isSigner: false,
4154
+ isWritable: true
4155
+ }, {
4156
+ pubkey: params.authority,
4157
+ isSigner: true,
4158
+ isWritable: false
4159
+ }];
4160
+ return new TransactionInstruction({
4161
+ programId: this.programId,
4162
+ keys: keys,
4163
+ data: data
4164
+ });
4165
+ }
4166
+
4167
+ static closeLookupTable(params) {
4168
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
4169
+ const data = encodeData(type);
4170
+ const keys = [{
4171
+ pubkey: params.lookupTable,
4172
+ isSigner: false,
4173
+ isWritable: true
4174
+ }, {
4175
+ pubkey: params.authority,
4176
+ isSigner: true,
4177
+ isWritable: false
4178
+ }, {
4179
+ pubkey: params.recipient,
4180
+ isSigner: false,
4181
+ isWritable: true
4182
+ }];
4183
+ return new TransactionInstruction({
4184
+ programId: this.programId,
4185
+ keys: keys,
4186
+ data: data
4187
+ });
4188
+ }
4189
+
4190
+ }
4191
+ AddressLookupTableProgram.programId = new PublicKey('AddressLookupTab1e1111111111111111111111111');
4192
+
4193
+ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
4194
+
4195
+ /**
4196
+ * Sign, send and confirm a transaction.
4197
+ *
4198
+ * If `commitment` option is not specified, defaults to 'max' commitment.
4199
+ *
4200
+ * @param {Connection} connection
4201
+ * @param {Transaction} transaction
4202
+ * @param {Array<Signer>} signers
4203
+ * @param {ConfirmOptions} [options]
4204
+ * @returns {Promise<TransactionSignature>}
4205
+ */
4206
+ async function sendAndConfirmTransaction(connection, transaction, signers, options) {
4207
+ const sendOptions = options && {
4208
+ skipPreflight: options.skipPreflight,
4209
+ preflightCommitment: options.preflightCommitment || options.commitment,
4210
+ maxRetries: options.maxRetries,
4211
+ minContextSlot: options.minContextSlot
4212
+ };
4213
+ const signature = await connection.sendTransaction(transaction, signers, sendOptions);
4214
+ const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
4215
+ signature: signature,
4216
+ blockhash: transaction.recentBlockhash,
4217
+ lastValidBlockHeight: transaction.lastValidBlockHeight
4218
+ }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
4219
+
4220
+ if (status.err) {
4221
+ throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
4222
+ }
4223
+
4224
+ return signature;
4225
+ }
4226
+
4227
+ // zzz
4228
+ function sleep(ms) {
4229
+ return new Promise(resolve => setTimeout(resolve, ms));
4230
+ }
4231
+
3933
4232
  // rest of the Transaction fields
3934
4233
  //
3935
4234
  // TODO: replace 300 with a proper constant for the size of the other
@@ -4398,6 +4697,8 @@ var fastStableStringify = function(val) {
4398
4697
 
4399
4698
  var fastStableStringify$1 = fastStableStringify;
4400
4699
 
4700
+ const URL = globalThis.URL;
4701
+
4401
4702
  const MINIMUM_SLOT_PER_EPOCH = 32; // Returns the number of trailing zeros in the binary representation of self.
4402
4703
 
4403
4704
  function trailingZeros(n) {
@@ -4795,7 +5096,11 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
4795
5096
  data: array(string()),
4796
5097
  rentEpoch: optional(number())
4797
5098
  }))))),
4798
- unitsConsumed: optional(number())
5099
+ unitsConsumed: optional(number()),
5100
+ returnData: optional(nullable(type({
5101
+ programId: string(),
5102
+ data: tuple([string(), literal('base64')])
5103
+ })))
4799
5104
  }));
4800
5105
 
4801
5106
  /**
@@ -6132,16 +6437,6 @@ class Connection {
6132
6437
  reject(err);
6133
6438
  }
6134
6439
  });
6135
-
6136
- const checkBlockHeight = async () => {
6137
- try {
6138
- const blockHeight = await this.getBlockHeight(commitment);
6139
- return blockHeight;
6140
- } catch (_e) {
6141
- return -1;
6142
- }
6143
- };
6144
-
6145
6440
  const expiryPromise = new Promise(resolve => {
6146
6441
  if (typeof strategy === 'string') {
6147
6442
  let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
@@ -6165,6 +6460,15 @@ class Connection {
6165
6460
  } else {
6166
6461
  let config = strategy;
6167
6462
 
6463
+ const checkBlockHeight = async () => {
6464
+ try {
6465
+ const blockHeight = await this.getBlockHeight(commitment);
6466
+ return blockHeight;
6467
+ } catch (_e) {
6468
+ return -1;
6469
+ }
6470
+ };
6471
+
6168
6472
  (async () => {
6169
6473
  let currentBlockHeight = await checkBlockHeight();
6170
6474
  if (done) return;
@@ -9911,5 +10215,5 @@ function clusterApiUrl(cluster, tls) {
9911
10215
 
9912
10216
  const LAMPORTS_PER_SOL = 1000000000;
9913
10217
 
9914
- export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
10218
+ export { Account, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9915
10219
  //# sourceMappingURL=index.browser.esm.js.map