@solana/web3.js 1.47.4 → 1.50.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.cjs.js CHANGED
@@ -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');
@@ -2128,18 +2128,6 @@ class Account {
2128
2128
 
2129
2129
  }
2130
2130
 
2131
- const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
2132
-
2133
- /**
2134
- * Maximum over-the-wire size of a Transaction
2135
- *
2136
- * 1280 is IPv6 minimum MTU
2137
- * 40 bytes is the size of the IPv6 header
2138
- * 8 bytes is the size of the fragment header
2139
- */
2140
- const PACKET_DATA_SIZE = 1280 - 40 - 8;
2141
- const SIGNATURE_LENGTH_IN_BYTES = 64;
2142
-
2143
2131
  /**
2144
2132
  * Layout for a public key
2145
2133
  */
@@ -2201,17 +2189,170 @@ const voteInit = (property = 'voteInit') => {
2201
2189
  return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
2202
2190
  };
2203
2191
  function getAlloc(type, fields) {
2204
- let alloc = 0;
2205
- type.layout.fields.forEach(item => {
2192
+ const getItemAlloc = item => {
2206
2193
  if (item.span >= 0) {
2207
- alloc += item.span;
2194
+ return item.span;
2208
2195
  } else if (typeof item.alloc === 'function') {
2209
- alloc += item.alloc(fields[item.property]);
2210
- }
2196
+ return item.alloc(fields[item.property]);
2197
+ } else if ('count' in item && 'elementLayout' in item) {
2198
+ const field = fields[item.property];
2199
+
2200
+ if (Array.isArray(field)) {
2201
+ return field.length * getItemAlloc(item.elementLayout);
2202
+ }
2203
+ } // Couldn't determine allocated size of layout
2204
+
2205
+
2206
+ return 0;
2207
+ };
2208
+
2209
+ let alloc = 0;
2210
+ type.layout.fields.forEach(item => {
2211
+ alloc += getItemAlloc(item);
2211
2212
  });
2212
2213
  return alloc;
2213
2214
  }
2214
2215
 
2216
+ const encodeDecode = layout => {
2217
+ const decode = layout.decode.bind(layout);
2218
+ const encode = layout.encode.bind(layout);
2219
+ return {
2220
+ decode,
2221
+ encode
2222
+ };
2223
+ };
2224
+
2225
+ const bigInt = length => property => {
2226
+ const layout = BufferLayout.blob(length, property);
2227
+ const {
2228
+ encode,
2229
+ decode
2230
+ } = encodeDecode(layout);
2231
+ const bigIntLayout = layout;
2232
+
2233
+ bigIntLayout.decode = (buffer$1, offset) => {
2234
+ const src = decode(buffer$1, offset);
2235
+ return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
2236
+ };
2237
+
2238
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
2239
+ const src = bigintBuffer.toBufferLE(bigInt, length);
2240
+ return encode(src, buffer, offset);
2241
+ };
2242
+
2243
+ return bigIntLayout;
2244
+ };
2245
+
2246
+ const u64 = bigInt(8);
2247
+
2248
+ /**
2249
+ * Populate a buffer of instruction data using an InstructionType
2250
+ * @internal
2251
+ */
2252
+ function encodeData(type, fields) {
2253
+ const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
2254
+ const data = buffer.Buffer.alloc(allocLength);
2255
+ const layoutFields = Object.assign({
2256
+ instruction: type.index
2257
+ }, fields);
2258
+ type.layout.encode(layoutFields, data);
2259
+ return data;
2260
+ }
2261
+ /**
2262
+ * Decode instruction data buffer using an InstructionType
2263
+ * @internal
2264
+ */
2265
+
2266
+ function decodeData(type, buffer) {
2267
+ let data;
2268
+
2269
+ try {
2270
+ data = type.layout.decode(buffer);
2271
+ } catch (err) {
2272
+ throw new Error('invalid instruction; ' + err);
2273
+ }
2274
+
2275
+ if (data.instruction !== type.index) {
2276
+ throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
2277
+ }
2278
+
2279
+ return data;
2280
+ }
2281
+
2282
+ /**
2283
+ * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
2284
+ *
2285
+ * @internal
2286
+ */
2287
+
2288
+ const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
2289
+ /**
2290
+ * Calculator for transaction fees.
2291
+ */
2292
+
2293
+ /**
2294
+ * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
2295
+ *
2296
+ * @internal
2297
+ */
2298
+
2299
+ const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
2300
+ const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
2301
+
2302
+ /**
2303
+ * NonceAccount class
2304
+ */
2305
+ class NonceAccount {
2306
+ /**
2307
+ * @internal
2308
+ */
2309
+ constructor(args) {
2310
+ this.authorizedPubkey = void 0;
2311
+ this.nonce = void 0;
2312
+ this.feeCalculator = void 0;
2313
+ this.authorizedPubkey = args.authorizedPubkey;
2314
+ this.nonce = args.nonce;
2315
+ this.feeCalculator = args.feeCalculator;
2316
+ }
2317
+ /**
2318
+ * Deserialize NonceAccount from the account data.
2319
+ *
2320
+ * @param buffer account data
2321
+ * @return NonceAccount
2322
+ */
2323
+
2324
+
2325
+ static fromAccountData(buffer) {
2326
+ const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
2327
+ return new NonceAccount({
2328
+ authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
2329
+ nonce: new PublicKey(nonceAccount.nonce).toString(),
2330
+ feeCalculator: nonceAccount.feeCalculator
2331
+ });
2332
+ }
2333
+
2334
+ }
2335
+
2336
+ const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2337
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2338
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2339
+ const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2340
+ const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2341
+ const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2342
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2343
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2344
+ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2345
+
2346
+ /**
2347
+ * Maximum over-the-wire size of a Transaction
2348
+ *
2349
+ * 1280 is IPv6 minimum MTU
2350
+ * 40 bytes is the size of the IPv6 header
2351
+ * 8 bytes is the size of the fragment header
2352
+ */
2353
+ const PACKET_DATA_SIZE = 1280 - 40 - 8;
2354
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
2355
+
2215
2356
  function decodeLength(bytes) {
2216
2357
  let len = 0;
2217
2358
  let size = 0;
@@ -3125,202 +3266,35 @@ class Transaction {
3125
3266
 
3126
3267
  }
3127
3268
 
3128
- const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3129
- const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3130
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
3131
- const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
3132
- const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
3133
- const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
3134
- const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
3135
- const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
3136
- const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
3137
-
3138
3269
  /**
3139
- * Sign, send and confirm a transaction.
3140
- *
3141
- * If `commitment` option is not specified, defaults to 'max' commitment.
3142
- *
3143
- * @param {Connection} connection
3144
- * @param {Transaction} transaction
3145
- * @param {Array<Signer>} signers
3146
- * @param {ConfirmOptions} [options]
3147
- * @returns {Promise<TransactionSignature>}
3270
+ * Create account system transaction params
3148
3271
  */
3149
- async function sendAndConfirmTransaction(connection, transaction, signers, options) {
3150
- const sendOptions = options && {
3151
- skipPreflight: options.skipPreflight,
3152
- preflightCommitment: options.preflightCommitment || options.commitment,
3153
- maxRetries: options.maxRetries,
3154
- minContextSlot: options.minContextSlot
3155
- };
3156
- const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3157
- const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
3158
- signature: signature,
3159
- blockhash: transaction.recentBlockhash,
3160
- lastValidBlockHeight: transaction.lastValidBlockHeight
3161
- }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
3162
-
3163
- if (status.err) {
3164
- throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
3165
- }
3166
-
3167
- return signature;
3168
- }
3169
-
3170
- // zzz
3171
- function sleep(ms) {
3172
- return new Promise(resolve => setTimeout(resolve, ms));
3173
- }
3174
3272
 
3175
3273
  /**
3176
- * Populate a buffer of instruction data using an InstructionType
3177
- * @internal
3178
- */
3179
- function encodeData(type, fields) {
3180
- const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
3181
- const data = buffer.Buffer.alloc(allocLength);
3182
- const layoutFields = Object.assign({
3183
- instruction: type.index
3184
- }, fields);
3185
- type.layout.encode(layoutFields, data);
3186
- return data;
3187
- }
3188
- /**
3189
- * Decode instruction data buffer using an InstructionType
3190
- * @internal
3274
+ * System Instruction class
3191
3275
  */
3276
+ class SystemInstruction {
3277
+ /**
3278
+ * @internal
3279
+ */
3280
+ constructor() {}
3281
+ /**
3282
+ * Decode a system instruction and retrieve the instruction type.
3283
+ */
3192
3284
 
3193
- function decodeData(type, buffer) {
3194
- let data;
3195
3285
 
3196
- try {
3197
- data = type.layout.decode(buffer);
3198
- } catch (err) {
3199
- throw new Error('invalid instruction; ' + err);
3200
- }
3286
+ static decodeInstructionType(instruction) {
3287
+ this.checkProgramId(instruction.programId);
3288
+ const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
3289
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
3290
+ let type;
3201
3291
 
3202
- if (data.instruction !== type.index) {
3203
- throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
3204
- }
3205
-
3206
- return data;
3207
- }
3208
-
3209
- /**
3210
- * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
3211
- *
3212
- * @internal
3213
- */
3214
-
3215
- const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
3216
- /**
3217
- * Calculator for transaction fees.
3218
- */
3219
-
3220
- /**
3221
- * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
3222
- *
3223
- * @internal
3224
- */
3225
-
3226
- const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
3227
- const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
3228
-
3229
- /**
3230
- * NonceAccount class
3231
- */
3232
- class NonceAccount {
3233
- /**
3234
- * @internal
3235
- */
3236
- constructor(args) {
3237
- this.authorizedPubkey = void 0;
3238
- this.nonce = void 0;
3239
- this.feeCalculator = void 0;
3240
- this.authorizedPubkey = args.authorizedPubkey;
3241
- this.nonce = args.nonce;
3242
- this.feeCalculator = args.feeCalculator;
3243
- }
3244
- /**
3245
- * Deserialize NonceAccount from the account data.
3246
- *
3247
- * @param buffer account data
3248
- * @return NonceAccount
3249
- */
3250
-
3251
-
3252
- static fromAccountData(buffer) {
3253
- const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
3254
- return new NonceAccount({
3255
- authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
3256
- nonce: new PublicKey(nonceAccount.nonce).toString(),
3257
- feeCalculator: nonceAccount.feeCalculator
3258
- });
3259
- }
3260
-
3261
- }
3262
-
3263
- const encodeDecode = layout => {
3264
- const decode = layout.decode.bind(layout);
3265
- const encode = layout.encode.bind(layout);
3266
- return {
3267
- decode,
3268
- encode
3269
- };
3270
- };
3271
-
3272
- const bigInt = length => property => {
3273
- const layout = BufferLayout.blob(length, property);
3274
- const {
3275
- encode,
3276
- decode
3277
- } = encodeDecode(layout);
3278
- const bigIntLayout = layout;
3279
-
3280
- bigIntLayout.decode = (buffer$1, offset) => {
3281
- const src = decode(buffer$1, offset);
3282
- return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
3283
- };
3284
-
3285
- bigIntLayout.encode = (bigInt, buffer, offset) => {
3286
- const src = bigintBuffer.toBufferLE(bigInt, length);
3287
- return encode(src, buffer, offset);
3288
- };
3289
-
3290
- return bigIntLayout;
3291
- };
3292
-
3293
- const u64 = bigInt(8);
3294
-
3295
- /**
3296
- * Create account system transaction params
3297
- */
3298
-
3299
- /**
3300
- * System Instruction class
3301
- */
3302
- class SystemInstruction {
3303
- /**
3304
- * @internal
3305
- */
3306
- constructor() {}
3307
- /**
3308
- * Decode a system instruction and retrieve the instruction type.
3309
- */
3310
-
3311
-
3312
- static decodeInstructionType(instruction) {
3313
- this.checkProgramId(instruction.programId);
3314
- const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
3315
- const typeIndex = instructionTypeLayout.decode(instruction.data);
3316
- let type;
3317
-
3318
- for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
3319
- if (layout.index == typeIndex) {
3320
- type = ixType;
3321
- break;
3322
- }
3323
- }
3292
+ for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
3293
+ if (layout.index == typeIndex) {
3294
+ type = ixType;
3295
+ break;
3296
+ }
3297
+ }
3324
3298
 
3325
3299
  if (!type) {
3326
3300
  throw new Error('Instruction type incorrect; not a SystemInstruction');
@@ -3872,140 +3846,446 @@ class SystemProgram {
3872
3846
  return new TransactionInstruction(instructionData);
3873
3847
  }
3874
3848
  /**
3875
- * Generate an instruction to advance the nonce in a Nonce account
3849
+ * Generate an instruction to advance the nonce in a Nonce account
3850
+ */
3851
+
3852
+
3853
+ static nonceAdvance(params) {
3854
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount;
3855
+ const data = encodeData(type);
3856
+ const instructionData = {
3857
+ keys: [{
3858
+ pubkey: params.noncePubkey,
3859
+ isSigner: false,
3860
+ isWritable: true
3861
+ }, {
3862
+ pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
3863
+ isSigner: false,
3864
+ isWritable: false
3865
+ }, {
3866
+ pubkey: params.authorizedPubkey,
3867
+ isSigner: true,
3868
+ isWritable: false
3869
+ }],
3870
+ programId: this.programId,
3871
+ data
3872
+ };
3873
+ return new TransactionInstruction(instructionData);
3874
+ }
3875
+ /**
3876
+ * Generate a transaction instruction that withdraws lamports from a Nonce account
3877
+ */
3878
+
3879
+
3880
+ static nonceWithdraw(params) {
3881
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount;
3882
+ const data = encodeData(type, {
3883
+ lamports: params.lamports
3884
+ });
3885
+ return new TransactionInstruction({
3886
+ keys: [{
3887
+ pubkey: params.noncePubkey,
3888
+ isSigner: false,
3889
+ isWritable: true
3890
+ }, {
3891
+ pubkey: params.toPubkey,
3892
+ isSigner: false,
3893
+ isWritable: true
3894
+ }, {
3895
+ pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
3896
+ isSigner: false,
3897
+ isWritable: false
3898
+ }, {
3899
+ pubkey: SYSVAR_RENT_PUBKEY,
3900
+ isSigner: false,
3901
+ isWritable: false
3902
+ }, {
3903
+ pubkey: params.authorizedPubkey,
3904
+ isSigner: true,
3905
+ isWritable: false
3906
+ }],
3907
+ programId: this.programId,
3908
+ data
3909
+ });
3910
+ }
3911
+ /**
3912
+ * Generate a transaction instruction that authorizes a new PublicKey as the authority
3913
+ * on a Nonce account.
3914
+ */
3915
+
3916
+
3917
+ static nonceAuthorize(params) {
3918
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount;
3919
+ const data = encodeData(type, {
3920
+ authorized: toBuffer(params.newAuthorizedPubkey.toBuffer())
3921
+ });
3922
+ return new TransactionInstruction({
3923
+ keys: [{
3924
+ pubkey: params.noncePubkey,
3925
+ isSigner: false,
3926
+ isWritable: true
3927
+ }, {
3928
+ pubkey: params.authorizedPubkey,
3929
+ isSigner: true,
3930
+ isWritable: false
3931
+ }],
3932
+ programId: this.programId,
3933
+ data
3934
+ });
3935
+ }
3936
+ /**
3937
+ * Generate a transaction instruction that allocates space in an account without funding
3938
+ */
3939
+
3940
+
3941
+ static allocate(params) {
3942
+ let data;
3943
+ let keys;
3944
+
3945
+ if ('basePubkey' in params) {
3946
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed;
3947
+ data = encodeData(type, {
3948
+ base: toBuffer(params.basePubkey.toBuffer()),
3949
+ seed: params.seed,
3950
+ space: params.space,
3951
+ programId: toBuffer(params.programId.toBuffer())
3952
+ });
3953
+ keys = [{
3954
+ pubkey: params.accountPubkey,
3955
+ isSigner: false,
3956
+ isWritable: true
3957
+ }, {
3958
+ pubkey: params.basePubkey,
3959
+ isSigner: true,
3960
+ isWritable: false
3961
+ }];
3962
+ } else {
3963
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
3964
+ data = encodeData(type, {
3965
+ space: params.space
3966
+ });
3967
+ keys = [{
3968
+ pubkey: params.accountPubkey,
3969
+ isSigner: true,
3970
+ isWritable: true
3971
+ }];
3972
+ }
3973
+
3974
+ return new TransactionInstruction({
3975
+ keys,
3976
+ programId: this.programId,
3977
+ data
3978
+ });
3979
+ }
3980
+
3981
+ }
3982
+ SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3983
+
3984
+ /**
3985
+ * An enumeration of valid address lookup table InstructionType's
3986
+ * @internal
3987
+ */
3988
+ const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
3989
+ CreateLookupTable: {
3990
+ index: 0,
3991
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('recentSlot'), BufferLayout__namespace.u8('bumpSeed')])
3992
+ },
3993
+ FreezeLookupTable: {
3994
+ index: 1,
3995
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
3996
+ },
3997
+ ExtendLookupTable: {
3998
+ index: 2,
3999
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64(), BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'addresses')])
4000
+ },
4001
+ DeactivateLookupTable: {
4002
+ index: 3,
4003
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
4004
+ },
4005
+ CloseLookupTable: {
4006
+ index: 4,
4007
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
4008
+ }
4009
+ });
4010
+ class AddressLookupTableInstruction {
4011
+ /**
4012
+ * @internal
4013
+ */
4014
+ constructor() {}
4015
+
4016
+ static decodeInstructionType(instruction) {
4017
+ this.checkProgramId(instruction.programId);
4018
+ const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
4019
+ const index = instructionTypeLayout.decode(instruction.data);
4020
+ let type;
4021
+
4022
+ for (const [layoutType, layout] of Object.entries(LOOKUP_TABLE_INSTRUCTION_LAYOUTS)) {
4023
+ if (layout.index == index) {
4024
+ type = layoutType;
4025
+ break;
4026
+ }
4027
+ }
4028
+
4029
+ if (!type) {
4030
+ throw new Error('Invalid Instruction. Should be a LookupTable Instruction');
4031
+ }
4032
+
4033
+ return type;
4034
+ }
4035
+
4036
+ static decodeCreateLookupTable(instruction) {
4037
+ this.checkProgramId(instruction.programId);
4038
+ this.checkKeysLength(instruction.keys, 4);
4039
+ const {
4040
+ recentSlot
4041
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable, instruction.data);
4042
+ return {
4043
+ authority: instruction.keys[1].pubkey,
4044
+ payer: instruction.keys[2].pubkey,
4045
+ recentSlot: Number(recentSlot)
4046
+ };
4047
+ }
4048
+
4049
+ static decodeExtendLookupTable(instruction) {
4050
+ this.checkProgramId(instruction.programId);
4051
+
4052
+ if (instruction.keys.length < 2) {
4053
+ throw new Error(`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`);
4054
+ }
4055
+
4056
+ const {
4057
+ addresses
4058
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable, instruction.data);
4059
+ return {
4060
+ lookupTable: instruction.keys[0].pubkey,
4061
+ authority: instruction.keys[1].pubkey,
4062
+ payer: instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
4063
+ addresses: addresses.map(buffer => new PublicKey(buffer))
4064
+ };
4065
+ }
4066
+
4067
+ static decodeCloseLookupTable(instruction) {
4068
+ this.checkProgramId(instruction.programId);
4069
+ this.checkKeysLength(instruction.keys, 3);
4070
+ return {
4071
+ lookupTable: instruction.keys[0].pubkey,
4072
+ authority: instruction.keys[1].pubkey,
4073
+ recipient: instruction.keys[2].pubkey
4074
+ };
4075
+ }
4076
+
4077
+ static decodeFreezeLookupTable(instruction) {
4078
+ this.checkProgramId(instruction.programId);
4079
+ this.checkKeysLength(instruction.keys, 2);
4080
+ return {
4081
+ lookupTable: instruction.keys[0].pubkey,
4082
+ authority: instruction.keys[1].pubkey
4083
+ };
4084
+ }
4085
+
4086
+ static decodeDeactivateLookupTable(instruction) {
4087
+ this.checkProgramId(instruction.programId);
4088
+ this.checkKeysLength(instruction.keys, 2);
4089
+ return {
4090
+ lookupTable: instruction.keys[0].pubkey,
4091
+ authority: instruction.keys[1].pubkey
4092
+ };
4093
+ }
4094
+ /**
4095
+ * @internal
4096
+ */
4097
+
4098
+
4099
+ static checkProgramId(programId) {
4100
+ if (!programId.equals(AddressLookupTableProgram.programId)) {
4101
+ throw new Error('invalid instruction; programId is not AddressLookupTable Program');
4102
+ }
4103
+ }
4104
+ /**
4105
+ * @internal
3876
4106
  */
3877
4107
 
3878
4108
 
3879
- static nonceAdvance(params) {
3880
- const type = SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount;
3881
- const data = encodeData(type);
3882
- const instructionData = {
3883
- keys: [{
3884
- pubkey: params.noncePubkey,
3885
- isSigner: false,
3886
- isWritable: true
3887
- }, {
3888
- pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
3889
- isSigner: false,
3890
- isWritable: false
3891
- }, {
3892
- pubkey: params.authorizedPubkey,
3893
- isSigner: true,
3894
- isWritable: false
3895
- }],
3896
- programId: this.programId,
3897
- data
3898
- };
3899
- return new TransactionInstruction(instructionData);
4109
+ static checkKeysLength(keys, expectedLength) {
4110
+ if (keys.length < expectedLength) {
4111
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
4112
+ }
3900
4113
  }
4114
+
4115
+ }
4116
+ class AddressLookupTableProgram {
3901
4117
  /**
3902
- * Generate a transaction instruction that withdraws lamports from a Nonce account
4118
+ * @internal
3903
4119
  */
4120
+ constructor() {}
3904
4121
 
3905
-
3906
- static nonceWithdraw(params) {
3907
- const type = SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount;
4122
+ static createLookupTable(params) {
4123
+ const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), bigintBuffer.toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
4124
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
3908
4125
  const data = encodeData(type, {
3909
- lamports: params.lamports
4126
+ recentSlot: BigInt(params.recentSlot),
4127
+ bumpSeed: bumpSeed
3910
4128
  });
3911
- return new TransactionInstruction({
3912
- keys: [{
3913
- pubkey: params.noncePubkey,
3914
- isSigner: false,
3915
- isWritable: true
3916
- }, {
3917
- pubkey: params.toPubkey,
3918
- isSigner: false,
3919
- isWritable: true
3920
- }, {
3921
- pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
3922
- isSigner: false,
3923
- isWritable: false
3924
- }, {
3925
- pubkey: SYSVAR_RENT_PUBKEY,
3926
- isSigner: false,
3927
- isWritable: false
3928
- }, {
3929
- pubkey: params.authorizedPubkey,
3930
- isSigner: true,
3931
- isWritable: false
3932
- }],
4129
+ const keys = [{
4130
+ pubkey: lookupTableAddress,
4131
+ isSigner: false,
4132
+ isWritable: true
4133
+ }, {
4134
+ pubkey: params.authority,
4135
+ isSigner: true,
4136
+ isWritable: false
4137
+ }, {
4138
+ pubkey: params.payer,
4139
+ isSigner: true,
4140
+ isWritable: true
4141
+ }, {
4142
+ pubkey: SystemProgram.programId,
4143
+ isSigner: false,
4144
+ isWritable: false
4145
+ }];
4146
+ return [new TransactionInstruction({
3933
4147
  programId: this.programId,
3934
- data
3935
- });
4148
+ keys: keys,
4149
+ data: data
4150
+ }), lookupTableAddress];
3936
4151
  }
3937
- /**
3938
- * Generate a transaction instruction that authorizes a new PublicKey as the authority
3939
- * on a Nonce account.
3940
- */
3941
-
3942
4152
 
3943
- static nonceAuthorize(params) {
3944
- const type = SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount;
3945
- const data = encodeData(type, {
3946
- authorized: toBuffer(params.newAuthorizedPubkey.toBuffer())
3947
- });
4153
+ static freezeLookupTable(params) {
4154
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
4155
+ const data = encodeData(type);
4156
+ const keys = [{
4157
+ pubkey: params.lookupTable,
4158
+ isSigner: false,
4159
+ isWritable: true
4160
+ }, {
4161
+ pubkey: params.authority,
4162
+ isSigner: true,
4163
+ isWritable: false
4164
+ }];
3948
4165
  return new TransactionInstruction({
3949
- keys: [{
3950
- pubkey: params.noncePubkey,
3951
- isSigner: false,
3952
- isWritable: true
3953
- }, {
3954
- pubkey: params.authorizedPubkey,
3955
- isSigner: true,
3956
- isWritable: false
3957
- }],
3958
4166
  programId: this.programId,
3959
- data
4167
+ keys: keys,
4168
+ data: data
3960
4169
  });
3961
4170
  }
3962
- /**
3963
- * Generate a transaction instruction that allocates space in an account without funding
3964
- */
3965
4171
 
4172
+ static extendLookupTable(params) {
4173
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
4174
+ const data = encodeData(type, {
4175
+ addresses: params.addresses.map(addr => addr.toBytes())
4176
+ });
4177
+ const keys = [{
4178
+ pubkey: params.lookupTable,
4179
+ isSigner: false,
4180
+ isWritable: true
4181
+ }, {
4182
+ pubkey: params.authority,
4183
+ isSigner: true,
4184
+ isWritable: false
4185
+ }];
3966
4186
 
3967
- static allocate(params) {
3968
- let data;
3969
- let keys;
3970
-
3971
- if ('basePubkey' in params) {
3972
- const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed;
3973
- data = encodeData(type, {
3974
- base: toBuffer(params.basePubkey.toBuffer()),
3975
- seed: params.seed,
3976
- space: params.space,
3977
- programId: toBuffer(params.programId.toBuffer())
3978
- });
3979
- keys = [{
3980
- pubkey: params.accountPubkey,
3981
- isSigner: false,
4187
+ if (params.payer) {
4188
+ keys.push({
4189
+ pubkey: params.payer,
4190
+ isSigner: true,
3982
4191
  isWritable: true
3983
4192
  }, {
3984
- pubkey: params.basePubkey,
3985
- isSigner: true,
4193
+ pubkey: SystemProgram.programId,
4194
+ isSigner: false,
3986
4195
  isWritable: false
3987
- }];
3988
- } else {
3989
- const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
3990
- data = encodeData(type, {
3991
- space: params.space
3992
4196
  });
3993
- keys = [{
3994
- pubkey: params.accountPubkey,
3995
- isSigner: true,
3996
- isWritable: true
3997
- }];
3998
4197
  }
3999
4198
 
4000
4199
  return new TransactionInstruction({
4001
- keys,
4002
4200
  programId: this.programId,
4003
- data
4201
+ keys: keys,
4202
+ data: data
4203
+ });
4204
+ }
4205
+
4206
+ static deactivateLookupTable(params) {
4207
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
4208
+ const data = encodeData(type);
4209
+ const keys = [{
4210
+ pubkey: params.lookupTable,
4211
+ isSigner: false,
4212
+ isWritable: true
4213
+ }, {
4214
+ pubkey: params.authority,
4215
+ isSigner: true,
4216
+ isWritable: false
4217
+ }];
4218
+ return new TransactionInstruction({
4219
+ programId: this.programId,
4220
+ keys: keys,
4221
+ data: data
4222
+ });
4223
+ }
4224
+
4225
+ static closeLookupTable(params) {
4226
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
4227
+ const data = encodeData(type);
4228
+ const keys = [{
4229
+ pubkey: params.lookupTable,
4230
+ isSigner: false,
4231
+ isWritable: true
4232
+ }, {
4233
+ pubkey: params.authority,
4234
+ isSigner: true,
4235
+ isWritable: false
4236
+ }, {
4237
+ pubkey: params.recipient,
4238
+ isSigner: false,
4239
+ isWritable: true
4240
+ }];
4241
+ return new TransactionInstruction({
4242
+ programId: this.programId,
4243
+ keys: keys,
4244
+ data: data
4004
4245
  });
4005
4246
  }
4006
4247
 
4007
4248
  }
4008
- SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
4249
+ AddressLookupTableProgram.programId = new PublicKey('AddressLookupTab1e1111111111111111111111111');
4250
+
4251
+ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
4252
+
4253
+ /**
4254
+ * Sign, send and confirm a transaction.
4255
+ *
4256
+ * If `commitment` option is not specified, defaults to 'max' commitment.
4257
+ *
4258
+ * @param {Connection} connection
4259
+ * @param {Transaction} transaction
4260
+ * @param {Array<Signer>} signers
4261
+ * @param {ConfirmOptions} [options]
4262
+ * @returns {Promise<TransactionSignature>}
4263
+ */
4264
+ async function sendAndConfirmTransaction(connection, transaction, signers, options) {
4265
+ const sendOptions = options && {
4266
+ skipPreflight: options.skipPreflight,
4267
+ preflightCommitment: options.preflightCommitment || options.commitment,
4268
+ maxRetries: options.maxRetries,
4269
+ minContextSlot: options.minContextSlot
4270
+ };
4271
+ const signature = await connection.sendTransaction(transaction, signers, sendOptions);
4272
+ const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
4273
+ signature: signature,
4274
+ blockhash: transaction.recentBlockhash,
4275
+ lastValidBlockHeight: transaction.lastValidBlockHeight
4276
+ }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
4277
+
4278
+ if (status.err) {
4279
+ throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
4280
+ }
4281
+
4282
+ return signature;
4283
+ }
4284
+
4285
+ // zzz
4286
+ function sleep(ms) {
4287
+ return new Promise(resolve => setTimeout(resolve, ms));
4288
+ }
4009
4289
 
4010
4290
  // rest of the Transaction fields
4011
4291
  //
@@ -6816,8 +7096,15 @@ class Connection {
6816
7096
  */
6817
7097
 
6818
7098
 
6819
- async getBlock(slot, opts) {
6820
- const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
7099
+ async getBlock(slot, rawConfig) {
7100
+ const {
7101
+ commitment,
7102
+ config
7103
+ } = extractCommitmentFromConfig(rawConfig);
7104
+
7105
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined
7106
+ /* encoding */
7107
+ , config);
6821
7108
 
6822
7109
  const unsafeRes = await this._rpcRequest('getBlock', args);
6823
7110
  const res = superstruct.create(unsafeRes, GetBlockRpcResult);
@@ -6903,8 +7190,15 @@ class Connection {
6903
7190
  */
6904
7191
 
6905
7192
 
6906
- async getTransaction(signature, opts) {
6907
- const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
7193
+ async getTransaction(signature, rawConfig) {
7194
+ const {
7195
+ commitment,
7196
+ config
7197
+ } = extractCommitmentFromConfig(rawConfig);
7198
+
7199
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
7200
+ /* encoding */
7201
+ , config);
6908
7202
 
6909
7203
  const unsafeRes = await this._rpcRequest('getTransaction', args);
6910
7204
  const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
@@ -6926,8 +7220,13 @@ class Connection {
6926
7220
  */
6927
7221
 
6928
7222
 
6929
- async getParsedTransaction(signature, commitment) {
6930
- const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
7223
+ async getParsedTransaction(signature, commitmentOrConfig) {
7224
+ const {
7225
+ commitment,
7226
+ config
7227
+ } = extractCommitmentFromConfig(commitmentOrConfig);
7228
+
7229
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed', config);
6931
7230
 
6932
7231
  const unsafeRes = await this._rpcRequest('getTransaction', args);
6933
7232
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
@@ -6943,9 +7242,13 @@ class Connection {
6943
7242
  */
6944
7243
 
6945
7244
 
6946
- async getParsedTransactions(signatures, commitment) {
7245
+ async getParsedTransactions(signatures, commitmentOrConfig) {
7246
+ const {
7247
+ commitment,
7248
+ config
7249
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6947
7250
  const batch = signatures.map(signature => {
6948
- const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
7251
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed', config);
6949
7252
 
6950
7253
  return {
6951
7254
  methodName: 'getTransaction',
@@ -6970,9 +7273,15 @@ class Connection {
6970
7273
  */
6971
7274
 
6972
7275
 
6973
- async getTransactions(signatures, commitment) {
7276
+ async getTransactions(signatures, commitmentOrConfig) {
7277
+ const {
7278
+ commitment,
7279
+ config
7280
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6974
7281
  const batch = signatures.map(signature => {
6975
- const args = this._buildArgsAtLeastConfirmed([signature], commitment);
7282
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
7283
+ /* encoding */
7284
+ , config);
6976
7285
 
6977
7286
  return {
6978
7287
  methodName: 'getTransaction',
@@ -7414,6 +7723,28 @@ class Connection {
7414
7723
  this._pollingBlockhash = false;
7415
7724
  }
7416
7725
  }
7726
+ /**
7727
+ * get the stake minimum delegation
7728
+ */
7729
+
7730
+
7731
+ async getStakeMinimumDelegation(config) {
7732
+ const {
7733
+ commitment,
7734
+ config: configArg
7735
+ } = extractCommitmentFromConfig(config);
7736
+
7737
+ const args = this._buildArgs([], commitment, 'base64', configArg);
7738
+
7739
+ const unsafeRes = await this._rpcRequest('getStakeMinimumDelegation', args);
7740
+ const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.number()));
7741
+
7742
+ if ('error' in res) {
7743
+ throw new SolanaJSONRPCError(res.error, `failed to get stake minimum delegation`);
7744
+ }
7745
+
7746
+ return res.result;
7747
+ }
7417
7748
  /**
7418
7749
  * Simulate a transaction
7419
7750
  */
@@ -10052,6 +10383,8 @@ function clusterApiUrl(cluster, tls) {
10052
10383
  const LAMPORTS_PER_SOL = 1000000000;
10053
10384
 
10054
10385
  exports.Account = Account;
10386
+ exports.AddressLookupTableInstruction = AddressLookupTableInstruction;
10387
+ exports.AddressLookupTableProgram = AddressLookupTableProgram;
10055
10388
  exports.Authorized = Authorized;
10056
10389
  exports.BLOCKHASH_CACHE_TIMEOUT_MS = BLOCKHASH_CACHE_TIMEOUT_MS;
10057
10390
  exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
@@ -10067,6 +10400,7 @@ exports.EpochSchedule = EpochSchedule;
10067
10400
  exports.FeeCalculatorLayout = FeeCalculatorLayout;
10068
10401
  exports.Keypair = Keypair;
10069
10402
  exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
10403
+ exports.LOOKUP_TABLE_INSTRUCTION_LAYOUTS = LOOKUP_TABLE_INSTRUCTION_LAYOUTS;
10070
10404
  exports.Loader = Loader;
10071
10405
  exports.Lockup = Lockup;
10072
10406
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;