@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.
package/lib/index.esm.js CHANGED
@@ -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';
@@ -2094,18 +2094,6 @@ class Account {
2094
2094
 
2095
2095
  }
2096
2096
 
2097
- const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
2098
-
2099
- /**
2100
- * Maximum over-the-wire size of a Transaction
2101
- *
2102
- * 1280 is IPv6 minimum MTU
2103
- * 40 bytes is the size of the IPv6 header
2104
- * 8 bytes is the size of the fragment header
2105
- */
2106
- const PACKET_DATA_SIZE = 1280 - 40 - 8;
2107
- const SIGNATURE_LENGTH_IN_BYTES = 64;
2108
-
2109
2097
  /**
2110
2098
  * Layout for a public key
2111
2099
  */
@@ -2167,17 +2155,170 @@ const voteInit = (property = 'voteInit') => {
2167
2155
  return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
2168
2156
  };
2169
2157
  function getAlloc(type, fields) {
2170
- let alloc = 0;
2171
- type.layout.fields.forEach(item => {
2158
+ const getItemAlloc = item => {
2172
2159
  if (item.span >= 0) {
2173
- alloc += item.span;
2160
+ return item.span;
2174
2161
  } else if (typeof item.alloc === 'function') {
2175
- alloc += item.alloc(fields[item.property]);
2176
- }
2162
+ return item.alloc(fields[item.property]);
2163
+ } else if ('count' in item && 'elementLayout' in item) {
2164
+ const field = fields[item.property];
2165
+
2166
+ if (Array.isArray(field)) {
2167
+ return field.length * getItemAlloc(item.elementLayout);
2168
+ }
2169
+ } // Couldn't determine allocated size of layout
2170
+
2171
+
2172
+ return 0;
2173
+ };
2174
+
2175
+ let alloc = 0;
2176
+ type.layout.fields.forEach(item => {
2177
+ alloc += getItemAlloc(item);
2177
2178
  });
2178
2179
  return alloc;
2179
2180
  }
2180
2181
 
2182
+ const encodeDecode = layout => {
2183
+ const decode = layout.decode.bind(layout);
2184
+ const encode = layout.encode.bind(layout);
2185
+ return {
2186
+ decode,
2187
+ encode
2188
+ };
2189
+ };
2190
+
2191
+ const bigInt = length => property => {
2192
+ const layout = blob(length, property);
2193
+ const {
2194
+ encode,
2195
+ decode
2196
+ } = encodeDecode(layout);
2197
+ const bigIntLayout = layout;
2198
+
2199
+ bigIntLayout.decode = (buffer, offset) => {
2200
+ const src = decode(buffer, offset);
2201
+ return toBigIntLE(Buffer.from(src));
2202
+ };
2203
+
2204
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
2205
+ const src = toBufferLE(bigInt, length);
2206
+ return encode(src, buffer, offset);
2207
+ };
2208
+
2209
+ return bigIntLayout;
2210
+ };
2211
+
2212
+ const u64 = bigInt(8);
2213
+
2214
+ /**
2215
+ * Populate a buffer of instruction data using an InstructionType
2216
+ * @internal
2217
+ */
2218
+ function encodeData(type, fields) {
2219
+ const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
2220
+ const data = Buffer.alloc(allocLength);
2221
+ const layoutFields = Object.assign({
2222
+ instruction: type.index
2223
+ }, fields);
2224
+ type.layout.encode(layoutFields, data);
2225
+ return data;
2226
+ }
2227
+ /**
2228
+ * Decode instruction data buffer using an InstructionType
2229
+ * @internal
2230
+ */
2231
+
2232
+ function decodeData(type, buffer) {
2233
+ let data;
2234
+
2235
+ try {
2236
+ data = type.layout.decode(buffer);
2237
+ } catch (err) {
2238
+ throw new Error('invalid instruction; ' + err);
2239
+ }
2240
+
2241
+ if (data.instruction !== type.index) {
2242
+ throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
2243
+ }
2244
+
2245
+ return data;
2246
+ }
2247
+
2248
+ /**
2249
+ * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
2250
+ *
2251
+ * @internal
2252
+ */
2253
+
2254
+ const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
2255
+ /**
2256
+ * Calculator for transaction fees.
2257
+ */
2258
+
2259
+ /**
2260
+ * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
2261
+ *
2262
+ * @internal
2263
+ */
2264
+
2265
+ const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
2266
+ const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
2267
+
2268
+ /**
2269
+ * NonceAccount class
2270
+ */
2271
+ class NonceAccount {
2272
+ /**
2273
+ * @internal
2274
+ */
2275
+ constructor(args) {
2276
+ this.authorizedPubkey = void 0;
2277
+ this.nonce = void 0;
2278
+ this.feeCalculator = void 0;
2279
+ this.authorizedPubkey = args.authorizedPubkey;
2280
+ this.nonce = args.nonce;
2281
+ this.feeCalculator = args.feeCalculator;
2282
+ }
2283
+ /**
2284
+ * Deserialize NonceAccount from the account data.
2285
+ *
2286
+ * @param buffer account data
2287
+ * @return NonceAccount
2288
+ */
2289
+
2290
+
2291
+ static fromAccountData(buffer) {
2292
+ const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
2293
+ return new NonceAccount({
2294
+ authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
2295
+ nonce: new PublicKey(nonceAccount.nonce).toString(),
2296
+ feeCalculator: nonceAccount.feeCalculator
2297
+ });
2298
+ }
2299
+
2300
+ }
2301
+
2302
+ const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2303
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2304
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2305
+ const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2306
+ const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2307
+ const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2308
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2309
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2310
+ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2311
+
2312
+ /**
2313
+ * Maximum over-the-wire size of a Transaction
2314
+ *
2315
+ * 1280 is IPv6 minimum MTU
2316
+ * 40 bytes is the size of the IPv6 header
2317
+ * 8 bytes is the size of the fragment header
2318
+ */
2319
+ const PACKET_DATA_SIZE = 1280 - 40 - 8;
2320
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
2321
+
2181
2322
  function decodeLength(bytes) {
2182
2323
  let len = 0;
2183
2324
  let size = 0;
@@ -3062,201 +3203,34 @@ class Transaction {
3062
3203
  transaction.feePayer = message.accountKeys[0];
3063
3204
  }
3064
3205
 
3065
- signatures.forEach((signature, index) => {
3066
- const sigPubkeyPair = {
3067
- signature: signature == bs58.encode(DEFAULT_SIGNATURE) ? null : bs58.decode(signature),
3068
- publicKey: message.accountKeys[index]
3069
- };
3070
- transaction.signatures.push(sigPubkeyPair);
3071
- });
3072
- message.instructions.forEach(instruction => {
3073
- const keys = instruction.accounts.map(account => {
3074
- const pubkey = message.accountKeys[account];
3075
- return {
3076
- pubkey,
3077
- isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
3078
- isWritable: message.isAccountWritable(account)
3079
- };
3080
- });
3081
- transaction.instructions.push(new TransactionInstruction({
3082
- keys,
3083
- programId: message.accountKeys[instruction.programIdIndex],
3084
- data: bs58.decode(instruction.data)
3085
- }));
3086
- });
3087
- transaction._message = message;
3088
- transaction._json = transaction.toJSON();
3089
- return transaction;
3090
- }
3091
-
3092
- }
3093
-
3094
- const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3095
- const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3096
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
3097
- const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
3098
- const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
3099
- const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
3100
- const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
3101
- const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
3102
- const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
3103
-
3104
- /**
3105
- * Sign, send and confirm a transaction.
3106
- *
3107
- * If `commitment` option is not specified, defaults to 'max' commitment.
3108
- *
3109
- * @param {Connection} connection
3110
- * @param {Transaction} transaction
3111
- * @param {Array<Signer>} signers
3112
- * @param {ConfirmOptions} [options]
3113
- * @returns {Promise<TransactionSignature>}
3114
- */
3115
- async function sendAndConfirmTransaction(connection, transaction, signers, options) {
3116
- const sendOptions = options && {
3117
- skipPreflight: options.skipPreflight,
3118
- preflightCommitment: options.preflightCommitment || options.commitment,
3119
- maxRetries: options.maxRetries,
3120
- minContextSlot: options.minContextSlot
3121
- };
3122
- const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3123
- const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
3124
- signature: signature,
3125
- blockhash: transaction.recentBlockhash,
3126
- lastValidBlockHeight: transaction.lastValidBlockHeight
3127
- }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
3128
-
3129
- if (status.err) {
3130
- throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
3131
- }
3132
-
3133
- return signature;
3134
- }
3135
-
3136
- // zzz
3137
- function sleep(ms) {
3138
- return new Promise(resolve => setTimeout(resolve, ms));
3139
- }
3140
-
3141
- /**
3142
- * Populate a buffer of instruction data using an InstructionType
3143
- * @internal
3144
- */
3145
- function encodeData(type, fields) {
3146
- const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
3147
- const data = Buffer.alloc(allocLength);
3148
- const layoutFields = Object.assign({
3149
- instruction: type.index
3150
- }, fields);
3151
- type.layout.encode(layoutFields, data);
3152
- return data;
3153
- }
3154
- /**
3155
- * Decode instruction data buffer using an InstructionType
3156
- * @internal
3157
- */
3158
-
3159
- function decodeData(type, buffer) {
3160
- let data;
3161
-
3162
- try {
3163
- data = type.layout.decode(buffer);
3164
- } catch (err) {
3165
- throw new Error('invalid instruction; ' + err);
3166
- }
3167
-
3168
- if (data.instruction !== type.index) {
3169
- throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
3170
- }
3171
-
3172
- return data;
3173
- }
3174
-
3175
- /**
3176
- * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
3177
- *
3178
- * @internal
3179
- */
3180
-
3181
- const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
3182
- /**
3183
- * Calculator for transaction fees.
3184
- */
3185
-
3186
- /**
3187
- * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
3188
- *
3189
- * @internal
3190
- */
3191
-
3192
- const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
3193
- const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
3194
-
3195
- /**
3196
- * NonceAccount class
3197
- */
3198
- class NonceAccount {
3199
- /**
3200
- * @internal
3201
- */
3202
- constructor(args) {
3203
- this.authorizedPubkey = void 0;
3204
- this.nonce = void 0;
3205
- this.feeCalculator = void 0;
3206
- this.authorizedPubkey = args.authorizedPubkey;
3207
- this.nonce = args.nonce;
3208
- this.feeCalculator = args.feeCalculator;
3209
- }
3210
- /**
3211
- * Deserialize NonceAccount from the account data.
3212
- *
3213
- * @param buffer account data
3214
- * @return NonceAccount
3215
- */
3216
-
3217
-
3218
- static fromAccountData(buffer) {
3219
- const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
3220
- return new NonceAccount({
3221
- authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
3222
- nonce: new PublicKey(nonceAccount.nonce).toString(),
3223
- feeCalculator: nonceAccount.feeCalculator
3224
- });
3225
- }
3226
-
3227
- }
3228
-
3229
- const encodeDecode = layout => {
3230
- const decode = layout.decode.bind(layout);
3231
- const encode = layout.encode.bind(layout);
3232
- return {
3233
- decode,
3234
- encode
3235
- };
3236
- };
3237
-
3238
- const bigInt = length => property => {
3239
- const layout = blob(length, property);
3240
- const {
3241
- encode,
3242
- decode
3243
- } = encodeDecode(layout);
3244
- const bigIntLayout = layout;
3245
-
3246
- bigIntLayout.decode = (buffer, offset) => {
3247
- const src = decode(buffer, offset);
3248
- return toBigIntLE(Buffer.from(src));
3249
- };
3250
-
3251
- bigIntLayout.encode = (bigInt, buffer, offset) => {
3252
- const src = toBufferLE(bigInt, length);
3253
- return encode(src, buffer, offset);
3254
- };
3255
-
3256
- return bigIntLayout;
3257
- };
3206
+ signatures.forEach((signature, index) => {
3207
+ const sigPubkeyPair = {
3208
+ signature: signature == bs58.encode(DEFAULT_SIGNATURE) ? null : bs58.decode(signature),
3209
+ publicKey: message.accountKeys[index]
3210
+ };
3211
+ transaction.signatures.push(sigPubkeyPair);
3212
+ });
3213
+ message.instructions.forEach(instruction => {
3214
+ const keys = instruction.accounts.map(account => {
3215
+ const pubkey = message.accountKeys[account];
3216
+ return {
3217
+ pubkey,
3218
+ isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
3219
+ isWritable: message.isAccountWritable(account)
3220
+ };
3221
+ });
3222
+ transaction.instructions.push(new TransactionInstruction({
3223
+ keys,
3224
+ programId: message.accountKeys[instruction.programIdIndex],
3225
+ data: bs58.decode(instruction.data)
3226
+ }));
3227
+ });
3228
+ transaction._message = message;
3229
+ transaction._json = transaction.toJSON();
3230
+ return transaction;
3231
+ }
3258
3232
 
3259
- const u64 = bigInt(8);
3233
+ }
3260
3234
 
3261
3235
  /**
3262
3236
  * Create account system transaction params
@@ -3973,6 +3947,312 @@ class SystemProgram {
3973
3947
  }
3974
3948
  SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3975
3949
 
3950
+ /**
3951
+ * An enumeration of valid address lookup table InstructionType's
3952
+ * @internal
3953
+ */
3954
+ const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
3955
+ CreateLookupTable: {
3956
+ index: 0,
3957
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64('recentSlot'), BufferLayout.u8('bumpSeed')])
3958
+ },
3959
+ FreezeLookupTable: {
3960
+ index: 1,
3961
+ layout: BufferLayout.struct([BufferLayout.u32('instruction')])
3962
+ },
3963
+ ExtendLookupTable: {
3964
+ index: 2,
3965
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64(), BufferLayout.seq(publicKey(), BufferLayout.offset(BufferLayout.u32(), -8), 'addresses')])
3966
+ },
3967
+ DeactivateLookupTable: {
3968
+ index: 3,
3969
+ layout: BufferLayout.struct([BufferLayout.u32('instruction')])
3970
+ },
3971
+ CloseLookupTable: {
3972
+ index: 4,
3973
+ layout: BufferLayout.struct([BufferLayout.u32('instruction')])
3974
+ }
3975
+ });
3976
+ class AddressLookupTableInstruction {
3977
+ /**
3978
+ * @internal
3979
+ */
3980
+ constructor() {}
3981
+
3982
+ static decodeInstructionType(instruction) {
3983
+ this.checkProgramId(instruction.programId);
3984
+ const instructionTypeLayout = BufferLayout.u32('instruction');
3985
+ const index = instructionTypeLayout.decode(instruction.data);
3986
+ let type;
3987
+
3988
+ for (const [layoutType, layout] of Object.entries(LOOKUP_TABLE_INSTRUCTION_LAYOUTS)) {
3989
+ if (layout.index == index) {
3990
+ type = layoutType;
3991
+ break;
3992
+ }
3993
+ }
3994
+
3995
+ if (!type) {
3996
+ throw new Error('Invalid Instruction. Should be a LookupTable Instruction');
3997
+ }
3998
+
3999
+ return type;
4000
+ }
4001
+
4002
+ static decodeCreateLookupTable(instruction) {
4003
+ this.checkProgramId(instruction.programId);
4004
+ this.checkKeysLength(instruction.keys, 4);
4005
+ const {
4006
+ recentSlot
4007
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable, instruction.data);
4008
+ return {
4009
+ authority: instruction.keys[1].pubkey,
4010
+ payer: instruction.keys[2].pubkey,
4011
+ recentSlot: Number(recentSlot)
4012
+ };
4013
+ }
4014
+
4015
+ static decodeExtendLookupTable(instruction) {
4016
+ this.checkProgramId(instruction.programId);
4017
+
4018
+ if (instruction.keys.length < 2) {
4019
+ throw new Error(`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`);
4020
+ }
4021
+
4022
+ const {
4023
+ addresses
4024
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable, instruction.data);
4025
+ return {
4026
+ lookupTable: instruction.keys[0].pubkey,
4027
+ authority: instruction.keys[1].pubkey,
4028
+ payer: instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
4029
+ addresses: addresses.map(buffer => new PublicKey(buffer))
4030
+ };
4031
+ }
4032
+
4033
+ static decodeCloseLookupTable(instruction) {
4034
+ this.checkProgramId(instruction.programId);
4035
+ this.checkKeysLength(instruction.keys, 3);
4036
+ return {
4037
+ lookupTable: instruction.keys[0].pubkey,
4038
+ authority: instruction.keys[1].pubkey,
4039
+ recipient: instruction.keys[2].pubkey
4040
+ };
4041
+ }
4042
+
4043
+ static decodeFreezeLookupTable(instruction) {
4044
+ this.checkProgramId(instruction.programId);
4045
+ this.checkKeysLength(instruction.keys, 2);
4046
+ return {
4047
+ lookupTable: instruction.keys[0].pubkey,
4048
+ authority: instruction.keys[1].pubkey
4049
+ };
4050
+ }
4051
+
4052
+ static decodeDeactivateLookupTable(instruction) {
4053
+ this.checkProgramId(instruction.programId);
4054
+ this.checkKeysLength(instruction.keys, 2);
4055
+ return {
4056
+ lookupTable: instruction.keys[0].pubkey,
4057
+ authority: instruction.keys[1].pubkey
4058
+ };
4059
+ }
4060
+ /**
4061
+ * @internal
4062
+ */
4063
+
4064
+
4065
+ static checkProgramId(programId) {
4066
+ if (!programId.equals(AddressLookupTableProgram.programId)) {
4067
+ throw new Error('invalid instruction; programId is not AddressLookupTable Program');
4068
+ }
4069
+ }
4070
+ /**
4071
+ * @internal
4072
+ */
4073
+
4074
+
4075
+ static checkKeysLength(keys, expectedLength) {
4076
+ if (keys.length < expectedLength) {
4077
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
4078
+ }
4079
+ }
4080
+
4081
+ }
4082
+ class AddressLookupTableProgram {
4083
+ /**
4084
+ * @internal
4085
+ */
4086
+ constructor() {}
4087
+
4088
+ static createLookupTable(params) {
4089
+ const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
4090
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
4091
+ const data = encodeData(type, {
4092
+ recentSlot: BigInt(params.recentSlot),
4093
+ bumpSeed: bumpSeed
4094
+ });
4095
+ const keys = [{
4096
+ pubkey: lookupTableAddress,
4097
+ isSigner: false,
4098
+ isWritable: true
4099
+ }, {
4100
+ pubkey: params.authority,
4101
+ isSigner: true,
4102
+ isWritable: false
4103
+ }, {
4104
+ pubkey: params.payer,
4105
+ isSigner: true,
4106
+ isWritable: true
4107
+ }, {
4108
+ pubkey: SystemProgram.programId,
4109
+ isSigner: false,
4110
+ isWritable: false
4111
+ }];
4112
+ return [new TransactionInstruction({
4113
+ programId: this.programId,
4114
+ keys: keys,
4115
+ data: data
4116
+ }), lookupTableAddress];
4117
+ }
4118
+
4119
+ static freezeLookupTable(params) {
4120
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
4121
+ const data = encodeData(type);
4122
+ const keys = [{
4123
+ pubkey: params.lookupTable,
4124
+ isSigner: false,
4125
+ isWritable: true
4126
+ }, {
4127
+ pubkey: params.authority,
4128
+ isSigner: true,
4129
+ isWritable: false
4130
+ }];
4131
+ return new TransactionInstruction({
4132
+ programId: this.programId,
4133
+ keys: keys,
4134
+ data: data
4135
+ });
4136
+ }
4137
+
4138
+ static extendLookupTable(params) {
4139
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
4140
+ const data = encodeData(type, {
4141
+ addresses: params.addresses.map(addr => addr.toBytes())
4142
+ });
4143
+ const keys = [{
4144
+ pubkey: params.lookupTable,
4145
+ isSigner: false,
4146
+ isWritable: true
4147
+ }, {
4148
+ pubkey: params.authority,
4149
+ isSigner: true,
4150
+ isWritable: false
4151
+ }];
4152
+
4153
+ if (params.payer) {
4154
+ keys.push({
4155
+ pubkey: params.payer,
4156
+ isSigner: true,
4157
+ isWritable: true
4158
+ }, {
4159
+ pubkey: SystemProgram.programId,
4160
+ isSigner: false,
4161
+ isWritable: false
4162
+ });
4163
+ }
4164
+
4165
+ return new TransactionInstruction({
4166
+ programId: this.programId,
4167
+ keys: keys,
4168
+ data: data
4169
+ });
4170
+ }
4171
+
4172
+ static deactivateLookupTable(params) {
4173
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
4174
+ const data = encodeData(type);
4175
+ const keys = [{
4176
+ pubkey: params.lookupTable,
4177
+ isSigner: false,
4178
+ isWritable: true
4179
+ }, {
4180
+ pubkey: params.authority,
4181
+ isSigner: true,
4182
+ isWritable: false
4183
+ }];
4184
+ return new TransactionInstruction({
4185
+ programId: this.programId,
4186
+ keys: keys,
4187
+ data: data
4188
+ });
4189
+ }
4190
+
4191
+ static closeLookupTable(params) {
4192
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
4193
+ const data = encodeData(type);
4194
+ const keys = [{
4195
+ pubkey: params.lookupTable,
4196
+ isSigner: false,
4197
+ isWritable: true
4198
+ }, {
4199
+ pubkey: params.authority,
4200
+ isSigner: true,
4201
+ isWritable: false
4202
+ }, {
4203
+ pubkey: params.recipient,
4204
+ isSigner: false,
4205
+ isWritable: true
4206
+ }];
4207
+ return new TransactionInstruction({
4208
+ programId: this.programId,
4209
+ keys: keys,
4210
+ data: data
4211
+ });
4212
+ }
4213
+
4214
+ }
4215
+ AddressLookupTableProgram.programId = new PublicKey('AddressLookupTab1e1111111111111111111111111');
4216
+
4217
+ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
4218
+
4219
+ /**
4220
+ * Sign, send and confirm a transaction.
4221
+ *
4222
+ * If `commitment` option is not specified, defaults to 'max' commitment.
4223
+ *
4224
+ * @param {Connection} connection
4225
+ * @param {Transaction} transaction
4226
+ * @param {Array<Signer>} signers
4227
+ * @param {ConfirmOptions} [options]
4228
+ * @returns {Promise<TransactionSignature>}
4229
+ */
4230
+ async function sendAndConfirmTransaction(connection, transaction, signers, options) {
4231
+ const sendOptions = options && {
4232
+ skipPreflight: options.skipPreflight,
4233
+ preflightCommitment: options.preflightCommitment || options.commitment,
4234
+ maxRetries: options.maxRetries,
4235
+ minContextSlot: options.minContextSlot
4236
+ };
4237
+ const signature = await connection.sendTransaction(transaction, signers, sendOptions);
4238
+ const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
4239
+ signature: signature,
4240
+ blockhash: transaction.recentBlockhash,
4241
+ lastValidBlockHeight: transaction.lastValidBlockHeight
4242
+ }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
4243
+
4244
+ if (status.err) {
4245
+ throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
4246
+ }
4247
+
4248
+ return signature;
4249
+ }
4250
+
4251
+ // zzz
4252
+ function sleep(ms) {
4253
+ return new Promise(resolve => setTimeout(resolve, ms));
4254
+ }
4255
+
3976
4256
  // rest of the Transaction fields
3977
4257
  //
3978
4258
  // TODO: replace 300 with a proper constant for the size of the other
@@ -4441,6 +4721,8 @@ var fastStableStringify = function(val) {
4441
4721
 
4442
4722
  var fastStableStringify$1 = fastStableStringify;
4443
4723
 
4724
+ const URL = globalThis.URL;
4725
+
4444
4726
  const DESTROY_TIMEOUT_MS = 5000;
4445
4727
  class AgentManager {
4446
4728
  static _newAgent(useHttps) {
@@ -4890,7 +5172,11 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
4890
5172
  data: array(string()),
4891
5173
  rentEpoch: optional(number())
4892
5174
  }))))),
4893
- unitsConsumed: optional(number())
5175
+ unitsConsumed: optional(number()),
5176
+ returnData: optional(nullable(type({
5177
+ programId: string(),
5178
+ data: tuple([string(), literal('base64')])
5179
+ })))
4894
5180
  }));
4895
5181
 
4896
5182
  /**
@@ -6776,8 +7062,15 @@ class Connection {
6776
7062
  */
6777
7063
 
6778
7064
 
6779
- async getBlock(slot, opts) {
6780
- const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
7065
+ async getBlock(slot, rawConfig) {
7066
+ const {
7067
+ commitment,
7068
+ config
7069
+ } = extractCommitmentFromConfig(rawConfig);
7070
+
7071
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined
7072
+ /* encoding */
7073
+ , config);
6781
7074
 
6782
7075
  const unsafeRes = await this._rpcRequest('getBlock', args);
6783
7076
  const res = create(unsafeRes, GetBlockRpcResult);
@@ -6863,8 +7156,15 @@ class Connection {
6863
7156
  */
6864
7157
 
6865
7158
 
6866
- async getTransaction(signature, opts) {
6867
- const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
7159
+ async getTransaction(signature, rawConfig) {
7160
+ const {
7161
+ commitment,
7162
+ config
7163
+ } = extractCommitmentFromConfig(rawConfig);
7164
+
7165
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
7166
+ /* encoding */
7167
+ , config);
6868
7168
 
6869
7169
  const unsafeRes = await this._rpcRequest('getTransaction', args);
6870
7170
  const res = create(unsafeRes, GetTransactionRpcResult);
@@ -10011,5 +10311,5 @@ function clusterApiUrl(cluster, tls) {
10011
10311
 
10012
10312
  const LAMPORTS_PER_SOL = 1000000000;
10013
10313
 
10014
- 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 };
10314
+ 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 };
10015
10315
  //# sourceMappingURL=index.esm.js.map