@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.
@@ -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');
@@ -2102,18 +2102,6 @@ class Account {
2102
2102
 
2103
2103
  }
2104
2104
 
2105
- const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
2106
-
2107
- /**
2108
- * Maximum over-the-wire size of a Transaction
2109
- *
2110
- * 1280 is IPv6 minimum MTU
2111
- * 40 bytes is the size of the IPv6 header
2112
- * 8 bytes is the size of the fragment header
2113
- */
2114
- const PACKET_DATA_SIZE = 1280 - 40 - 8;
2115
- const SIGNATURE_LENGTH_IN_BYTES = 64;
2116
-
2117
2105
  /**
2118
2106
  * Layout for a public key
2119
2107
  */
@@ -2175,17 +2163,170 @@ const voteInit = (property = 'voteInit') => {
2175
2163
  return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
2176
2164
  };
2177
2165
  function getAlloc(type, fields) {
2178
- let alloc = 0;
2179
- type.layout.fields.forEach(item => {
2166
+ const getItemAlloc = item => {
2180
2167
  if (item.span >= 0) {
2181
- alloc += item.span;
2168
+ return item.span;
2182
2169
  } else if (typeof item.alloc === 'function') {
2183
- alloc += item.alloc(fields[item.property]);
2184
- }
2170
+ return item.alloc(fields[item.property]);
2171
+ } else if ('count' in item && 'elementLayout' in item) {
2172
+ const field = fields[item.property];
2173
+
2174
+ if (Array.isArray(field)) {
2175
+ return field.length * getItemAlloc(item.elementLayout);
2176
+ }
2177
+ } // Couldn't determine allocated size of layout
2178
+
2179
+
2180
+ return 0;
2181
+ };
2182
+
2183
+ let alloc = 0;
2184
+ type.layout.fields.forEach(item => {
2185
+ alloc += getItemAlloc(item);
2185
2186
  });
2186
2187
  return alloc;
2187
2188
  }
2188
2189
 
2190
+ const encodeDecode = layout => {
2191
+ const decode = layout.decode.bind(layout);
2192
+ const encode = layout.encode.bind(layout);
2193
+ return {
2194
+ decode,
2195
+ encode
2196
+ };
2197
+ };
2198
+
2199
+ const bigInt = length => property => {
2200
+ const layout = BufferLayout.blob(length, property);
2201
+ const {
2202
+ encode,
2203
+ decode
2204
+ } = encodeDecode(layout);
2205
+ const bigIntLayout = layout;
2206
+
2207
+ bigIntLayout.decode = (buffer$1, offset) => {
2208
+ const src = decode(buffer$1, offset);
2209
+ return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
2210
+ };
2211
+
2212
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
2213
+ const src = bigintBuffer.toBufferLE(bigInt, length);
2214
+ return encode(src, buffer, offset);
2215
+ };
2216
+
2217
+ return bigIntLayout;
2218
+ };
2219
+
2220
+ const u64 = bigInt(8);
2221
+
2222
+ /**
2223
+ * Populate a buffer of instruction data using an InstructionType
2224
+ * @internal
2225
+ */
2226
+ function encodeData(type, fields) {
2227
+ const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
2228
+ const data = buffer.Buffer.alloc(allocLength);
2229
+ const layoutFields = Object.assign({
2230
+ instruction: type.index
2231
+ }, fields);
2232
+ type.layout.encode(layoutFields, data);
2233
+ return data;
2234
+ }
2235
+ /**
2236
+ * Decode instruction data buffer using an InstructionType
2237
+ * @internal
2238
+ */
2239
+
2240
+ function decodeData(type, buffer) {
2241
+ let data;
2242
+
2243
+ try {
2244
+ data = type.layout.decode(buffer);
2245
+ } catch (err) {
2246
+ throw new Error('invalid instruction; ' + err);
2247
+ }
2248
+
2249
+ if (data.instruction !== type.index) {
2250
+ throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
2251
+ }
2252
+
2253
+ return data;
2254
+ }
2255
+
2256
+ /**
2257
+ * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
2258
+ *
2259
+ * @internal
2260
+ */
2261
+
2262
+ const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
2263
+ /**
2264
+ * Calculator for transaction fees.
2265
+ */
2266
+
2267
+ /**
2268
+ * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
2269
+ *
2270
+ * @internal
2271
+ */
2272
+
2273
+ const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
2274
+ const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
2275
+
2276
+ /**
2277
+ * NonceAccount class
2278
+ */
2279
+ class NonceAccount {
2280
+ /**
2281
+ * @internal
2282
+ */
2283
+ constructor(args) {
2284
+ this.authorizedPubkey = void 0;
2285
+ this.nonce = void 0;
2286
+ this.feeCalculator = void 0;
2287
+ this.authorizedPubkey = args.authorizedPubkey;
2288
+ this.nonce = args.nonce;
2289
+ this.feeCalculator = args.feeCalculator;
2290
+ }
2291
+ /**
2292
+ * Deserialize NonceAccount from the account data.
2293
+ *
2294
+ * @param buffer account data
2295
+ * @return NonceAccount
2296
+ */
2297
+
2298
+
2299
+ static fromAccountData(buffer) {
2300
+ const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
2301
+ return new NonceAccount({
2302
+ authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
2303
+ nonce: new PublicKey(nonceAccount.nonce).toString(),
2304
+ feeCalculator: nonceAccount.feeCalculator
2305
+ });
2306
+ }
2307
+
2308
+ }
2309
+
2310
+ const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2311
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2312
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2313
+ const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2314
+ const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2315
+ const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2316
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2317
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2318
+ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2319
+
2320
+ /**
2321
+ * Maximum over-the-wire size of a Transaction
2322
+ *
2323
+ * 1280 is IPv6 minimum MTU
2324
+ * 40 bytes is the size of the IPv6 header
2325
+ * 8 bytes is the size of the fragment header
2326
+ */
2327
+ const PACKET_DATA_SIZE = 1280 - 40 - 8;
2328
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
2329
+
2189
2330
  function decodeLength(bytes) {
2190
2331
  let len = 0;
2191
2332
  let size = 0;
@@ -3099,202 +3240,35 @@ class Transaction {
3099
3240
 
3100
3241
  }
3101
3242
 
3102
- const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3103
- const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3104
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
3105
- const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
3106
- const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
3107
- const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
3108
- const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
3109
- const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
3110
- const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
3111
-
3112
3243
  /**
3113
- * Sign, send and confirm a transaction.
3114
- *
3115
- * If `commitment` option is not specified, defaults to 'max' commitment.
3116
- *
3117
- * @param {Connection} connection
3118
- * @param {Transaction} transaction
3119
- * @param {Array<Signer>} signers
3120
- * @param {ConfirmOptions} [options]
3121
- * @returns {Promise<TransactionSignature>}
3244
+ * Create account system transaction params
3122
3245
  */
3123
- async function sendAndConfirmTransaction(connection, transaction, signers, options) {
3124
- const sendOptions = options && {
3125
- skipPreflight: options.skipPreflight,
3126
- preflightCommitment: options.preflightCommitment || options.commitment,
3127
- maxRetries: options.maxRetries,
3128
- minContextSlot: options.minContextSlot
3129
- };
3130
- const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3131
- const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
3132
- signature: signature,
3133
- blockhash: transaction.recentBlockhash,
3134
- lastValidBlockHeight: transaction.lastValidBlockHeight
3135
- }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
3136
-
3137
- if (status.err) {
3138
- throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
3139
- }
3140
-
3141
- return signature;
3142
- }
3143
-
3144
- // zzz
3145
- function sleep(ms) {
3146
- return new Promise(resolve => setTimeout(resolve, ms));
3147
- }
3148
3246
 
3149
3247
  /**
3150
- * Populate a buffer of instruction data using an InstructionType
3151
- * @internal
3152
- */
3153
- function encodeData(type, fields) {
3154
- const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
3155
- const data = buffer.Buffer.alloc(allocLength);
3156
- const layoutFields = Object.assign({
3157
- instruction: type.index
3158
- }, fields);
3159
- type.layout.encode(layoutFields, data);
3160
- return data;
3161
- }
3162
- /**
3163
- * Decode instruction data buffer using an InstructionType
3164
- * @internal
3248
+ * System Instruction class
3165
3249
  */
3250
+ class SystemInstruction {
3251
+ /**
3252
+ * @internal
3253
+ */
3254
+ constructor() {}
3255
+ /**
3256
+ * Decode a system instruction and retrieve the instruction type.
3257
+ */
3166
3258
 
3167
- function decodeData(type, buffer) {
3168
- let data;
3169
3259
 
3170
- try {
3171
- data = type.layout.decode(buffer);
3172
- } catch (err) {
3173
- throw new Error('invalid instruction; ' + err);
3174
- }
3260
+ static decodeInstructionType(instruction) {
3261
+ this.checkProgramId(instruction.programId);
3262
+ const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
3263
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
3264
+ let type;
3175
3265
 
3176
- if (data.instruction !== type.index) {
3177
- throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
3178
- }
3179
-
3180
- return data;
3181
- }
3182
-
3183
- /**
3184
- * https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
3185
- *
3186
- * @internal
3187
- */
3188
-
3189
- const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
3190
- /**
3191
- * Calculator for transaction fees.
3192
- */
3193
-
3194
- /**
3195
- * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
3196
- *
3197
- * @internal
3198
- */
3199
-
3200
- const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
3201
- const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
3202
-
3203
- /**
3204
- * NonceAccount class
3205
- */
3206
- class NonceAccount {
3207
- /**
3208
- * @internal
3209
- */
3210
- constructor(args) {
3211
- this.authorizedPubkey = void 0;
3212
- this.nonce = void 0;
3213
- this.feeCalculator = void 0;
3214
- this.authorizedPubkey = args.authorizedPubkey;
3215
- this.nonce = args.nonce;
3216
- this.feeCalculator = args.feeCalculator;
3217
- }
3218
- /**
3219
- * Deserialize NonceAccount from the account data.
3220
- *
3221
- * @param buffer account data
3222
- * @return NonceAccount
3223
- */
3224
-
3225
-
3226
- static fromAccountData(buffer) {
3227
- const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
3228
- return new NonceAccount({
3229
- authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
3230
- nonce: new PublicKey(nonceAccount.nonce).toString(),
3231
- feeCalculator: nonceAccount.feeCalculator
3232
- });
3233
- }
3234
-
3235
- }
3236
-
3237
- const encodeDecode = layout => {
3238
- const decode = layout.decode.bind(layout);
3239
- const encode = layout.encode.bind(layout);
3240
- return {
3241
- decode,
3242
- encode
3243
- };
3244
- };
3245
-
3246
- const bigInt = length => property => {
3247
- const layout = BufferLayout.blob(length, property);
3248
- const {
3249
- encode,
3250
- decode
3251
- } = encodeDecode(layout);
3252
- const bigIntLayout = layout;
3253
-
3254
- bigIntLayout.decode = (buffer$1, offset) => {
3255
- const src = decode(buffer$1, offset);
3256
- return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
3257
- };
3258
-
3259
- bigIntLayout.encode = (bigInt, buffer, offset) => {
3260
- const src = bigintBuffer.toBufferLE(bigInt, length);
3261
- return encode(src, buffer, offset);
3262
- };
3263
-
3264
- return bigIntLayout;
3265
- };
3266
-
3267
- const u64 = bigInt(8);
3268
-
3269
- /**
3270
- * Create account system transaction params
3271
- */
3272
-
3273
- /**
3274
- * System Instruction class
3275
- */
3276
- class SystemInstruction {
3277
- /**
3278
- * @internal
3279
- */
3280
- constructor() {}
3281
- /**
3282
- * Decode a system instruction and retrieve the instruction type.
3283
- */
3284
-
3285
-
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;
3291
-
3292
- for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
3293
- if (layout.index == typeIndex) {
3294
- type = ixType;
3295
- break;
3296
- }
3297
- }
3266
+ for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
3267
+ if (layout.index == typeIndex) {
3268
+ type = ixType;
3269
+ break;
3270
+ }
3271
+ }
3298
3272
 
3299
3273
  if (!type) {
3300
3274
  throw new Error('Instruction type incorrect; not a SystemInstruction');
@@ -3846,140 +3820,446 @@ class SystemProgram {
3846
3820
  return new TransactionInstruction(instructionData);
3847
3821
  }
3848
3822
  /**
3849
- * Generate an instruction to advance the nonce in a Nonce account
3823
+ * Generate an instruction to advance the nonce in a Nonce account
3824
+ */
3825
+
3826
+
3827
+ static nonceAdvance(params) {
3828
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount;
3829
+ const data = encodeData(type);
3830
+ const instructionData = {
3831
+ keys: [{
3832
+ pubkey: params.noncePubkey,
3833
+ isSigner: false,
3834
+ isWritable: true
3835
+ }, {
3836
+ pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
3837
+ isSigner: false,
3838
+ isWritable: false
3839
+ }, {
3840
+ pubkey: params.authorizedPubkey,
3841
+ isSigner: true,
3842
+ isWritable: false
3843
+ }],
3844
+ programId: this.programId,
3845
+ data
3846
+ };
3847
+ return new TransactionInstruction(instructionData);
3848
+ }
3849
+ /**
3850
+ * Generate a transaction instruction that withdraws lamports from a Nonce account
3851
+ */
3852
+
3853
+
3854
+ static nonceWithdraw(params) {
3855
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount;
3856
+ const data = encodeData(type, {
3857
+ lamports: params.lamports
3858
+ });
3859
+ return new TransactionInstruction({
3860
+ keys: [{
3861
+ pubkey: params.noncePubkey,
3862
+ isSigner: false,
3863
+ isWritable: true
3864
+ }, {
3865
+ pubkey: params.toPubkey,
3866
+ isSigner: false,
3867
+ isWritable: true
3868
+ }, {
3869
+ pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
3870
+ isSigner: false,
3871
+ isWritable: false
3872
+ }, {
3873
+ pubkey: SYSVAR_RENT_PUBKEY,
3874
+ isSigner: false,
3875
+ isWritable: false
3876
+ }, {
3877
+ pubkey: params.authorizedPubkey,
3878
+ isSigner: true,
3879
+ isWritable: false
3880
+ }],
3881
+ programId: this.programId,
3882
+ data
3883
+ });
3884
+ }
3885
+ /**
3886
+ * Generate a transaction instruction that authorizes a new PublicKey as the authority
3887
+ * on a Nonce account.
3888
+ */
3889
+
3890
+
3891
+ static nonceAuthorize(params) {
3892
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount;
3893
+ const data = encodeData(type, {
3894
+ authorized: toBuffer(params.newAuthorizedPubkey.toBuffer())
3895
+ });
3896
+ return new TransactionInstruction({
3897
+ keys: [{
3898
+ pubkey: params.noncePubkey,
3899
+ isSigner: false,
3900
+ isWritable: true
3901
+ }, {
3902
+ pubkey: params.authorizedPubkey,
3903
+ isSigner: true,
3904
+ isWritable: false
3905
+ }],
3906
+ programId: this.programId,
3907
+ data
3908
+ });
3909
+ }
3910
+ /**
3911
+ * Generate a transaction instruction that allocates space in an account without funding
3912
+ */
3913
+
3914
+
3915
+ static allocate(params) {
3916
+ let data;
3917
+ let keys;
3918
+
3919
+ if ('basePubkey' in params) {
3920
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed;
3921
+ data = encodeData(type, {
3922
+ base: toBuffer(params.basePubkey.toBuffer()),
3923
+ seed: params.seed,
3924
+ space: params.space,
3925
+ programId: toBuffer(params.programId.toBuffer())
3926
+ });
3927
+ keys = [{
3928
+ pubkey: params.accountPubkey,
3929
+ isSigner: false,
3930
+ isWritable: true
3931
+ }, {
3932
+ pubkey: params.basePubkey,
3933
+ isSigner: true,
3934
+ isWritable: false
3935
+ }];
3936
+ } else {
3937
+ const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
3938
+ data = encodeData(type, {
3939
+ space: params.space
3940
+ });
3941
+ keys = [{
3942
+ pubkey: params.accountPubkey,
3943
+ isSigner: true,
3944
+ isWritable: true
3945
+ }];
3946
+ }
3947
+
3948
+ return new TransactionInstruction({
3949
+ keys,
3950
+ programId: this.programId,
3951
+ data
3952
+ });
3953
+ }
3954
+
3955
+ }
3956
+ SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
3957
+
3958
+ /**
3959
+ * An enumeration of valid address lookup table InstructionType's
3960
+ * @internal
3961
+ */
3962
+ const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
3963
+ CreateLookupTable: {
3964
+ index: 0,
3965
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('recentSlot'), BufferLayout__namespace.u8('bumpSeed')])
3966
+ },
3967
+ FreezeLookupTable: {
3968
+ index: 1,
3969
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
3970
+ },
3971
+ ExtendLookupTable: {
3972
+ index: 2,
3973
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64(), BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'addresses')])
3974
+ },
3975
+ DeactivateLookupTable: {
3976
+ index: 3,
3977
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
3978
+ },
3979
+ CloseLookupTable: {
3980
+ index: 4,
3981
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
3982
+ }
3983
+ });
3984
+ class AddressLookupTableInstruction {
3985
+ /**
3986
+ * @internal
3987
+ */
3988
+ constructor() {}
3989
+
3990
+ static decodeInstructionType(instruction) {
3991
+ this.checkProgramId(instruction.programId);
3992
+ const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
3993
+ const index = instructionTypeLayout.decode(instruction.data);
3994
+ let type;
3995
+
3996
+ for (const [layoutType, layout] of Object.entries(LOOKUP_TABLE_INSTRUCTION_LAYOUTS)) {
3997
+ if (layout.index == index) {
3998
+ type = layoutType;
3999
+ break;
4000
+ }
4001
+ }
4002
+
4003
+ if (!type) {
4004
+ throw new Error('Invalid Instruction. Should be a LookupTable Instruction');
4005
+ }
4006
+
4007
+ return type;
4008
+ }
4009
+
4010
+ static decodeCreateLookupTable(instruction) {
4011
+ this.checkProgramId(instruction.programId);
4012
+ this.checkKeysLength(instruction.keys, 4);
4013
+ const {
4014
+ recentSlot
4015
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable, instruction.data);
4016
+ return {
4017
+ authority: instruction.keys[1].pubkey,
4018
+ payer: instruction.keys[2].pubkey,
4019
+ recentSlot: Number(recentSlot)
4020
+ };
4021
+ }
4022
+
4023
+ static decodeExtendLookupTable(instruction) {
4024
+ this.checkProgramId(instruction.programId);
4025
+
4026
+ if (instruction.keys.length < 2) {
4027
+ throw new Error(`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`);
4028
+ }
4029
+
4030
+ const {
4031
+ addresses
4032
+ } = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable, instruction.data);
4033
+ return {
4034
+ lookupTable: instruction.keys[0].pubkey,
4035
+ authority: instruction.keys[1].pubkey,
4036
+ payer: instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
4037
+ addresses: addresses.map(buffer => new PublicKey(buffer))
4038
+ };
4039
+ }
4040
+
4041
+ static decodeCloseLookupTable(instruction) {
4042
+ this.checkProgramId(instruction.programId);
4043
+ this.checkKeysLength(instruction.keys, 3);
4044
+ return {
4045
+ lookupTable: instruction.keys[0].pubkey,
4046
+ authority: instruction.keys[1].pubkey,
4047
+ recipient: instruction.keys[2].pubkey
4048
+ };
4049
+ }
4050
+
4051
+ static decodeFreezeLookupTable(instruction) {
4052
+ this.checkProgramId(instruction.programId);
4053
+ this.checkKeysLength(instruction.keys, 2);
4054
+ return {
4055
+ lookupTable: instruction.keys[0].pubkey,
4056
+ authority: instruction.keys[1].pubkey
4057
+ };
4058
+ }
4059
+
4060
+ static decodeDeactivateLookupTable(instruction) {
4061
+ this.checkProgramId(instruction.programId);
4062
+ this.checkKeysLength(instruction.keys, 2);
4063
+ return {
4064
+ lookupTable: instruction.keys[0].pubkey,
4065
+ authority: instruction.keys[1].pubkey
4066
+ };
4067
+ }
4068
+ /**
4069
+ * @internal
4070
+ */
4071
+
4072
+
4073
+ static checkProgramId(programId) {
4074
+ if (!programId.equals(AddressLookupTableProgram.programId)) {
4075
+ throw new Error('invalid instruction; programId is not AddressLookupTable Program');
4076
+ }
4077
+ }
4078
+ /**
4079
+ * @internal
3850
4080
  */
3851
4081
 
3852
4082
 
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);
4083
+ static checkKeysLength(keys, expectedLength) {
4084
+ if (keys.length < expectedLength) {
4085
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
4086
+ }
3874
4087
  }
4088
+
4089
+ }
4090
+ class AddressLookupTableProgram {
3875
4091
  /**
3876
- * Generate a transaction instruction that withdraws lamports from a Nonce account
4092
+ * @internal
3877
4093
  */
4094
+ constructor() {}
3878
4095
 
3879
-
3880
- static nonceWithdraw(params) {
3881
- const type = SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount;
4096
+ static createLookupTable(params) {
4097
+ const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), bigintBuffer.toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
4098
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
3882
4099
  const data = encodeData(type, {
3883
- lamports: params.lamports
4100
+ recentSlot: BigInt(params.recentSlot),
4101
+ bumpSeed: bumpSeed
3884
4102
  });
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
- }],
4103
+ const keys = [{
4104
+ pubkey: lookupTableAddress,
4105
+ isSigner: false,
4106
+ isWritable: true
4107
+ }, {
4108
+ pubkey: params.authority,
4109
+ isSigner: true,
4110
+ isWritable: false
4111
+ }, {
4112
+ pubkey: params.payer,
4113
+ isSigner: true,
4114
+ isWritable: true
4115
+ }, {
4116
+ pubkey: SystemProgram.programId,
4117
+ isSigner: false,
4118
+ isWritable: false
4119
+ }];
4120
+ return [new TransactionInstruction({
3907
4121
  programId: this.programId,
3908
- data
3909
- });
4122
+ keys: keys,
4123
+ data: data
4124
+ }), lookupTableAddress];
3910
4125
  }
3911
- /**
3912
- * Generate a transaction instruction that authorizes a new PublicKey as the authority
3913
- * on a Nonce account.
3914
- */
3915
-
3916
4126
 
3917
- static nonceAuthorize(params) {
3918
- const type = SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount;
3919
- const data = encodeData(type, {
3920
- authorized: toBuffer(params.newAuthorizedPubkey.toBuffer())
3921
- });
4127
+ static freezeLookupTable(params) {
4128
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
4129
+ const data = encodeData(type);
4130
+ const keys = [{
4131
+ pubkey: params.lookupTable,
4132
+ isSigner: false,
4133
+ isWritable: true
4134
+ }, {
4135
+ pubkey: params.authority,
4136
+ isSigner: true,
4137
+ isWritable: false
4138
+ }];
3922
4139
  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
4140
  programId: this.programId,
3933
- data
4141
+ keys: keys,
4142
+ data: data
3934
4143
  });
3935
4144
  }
3936
- /**
3937
- * Generate a transaction instruction that allocates space in an account without funding
3938
- */
3939
4145
 
4146
+ static extendLookupTable(params) {
4147
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
4148
+ const data = encodeData(type, {
4149
+ addresses: params.addresses.map(addr => addr.toBytes())
4150
+ });
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
+ }];
3940
4160
 
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,
4161
+ if (params.payer) {
4162
+ keys.push({
4163
+ pubkey: params.payer,
4164
+ isSigner: true,
3956
4165
  isWritable: true
3957
4166
  }, {
3958
- pubkey: params.basePubkey,
3959
- isSigner: true,
4167
+ pubkey: SystemProgram.programId,
4168
+ isSigner: false,
3960
4169
  isWritable: false
3961
- }];
3962
- } else {
3963
- const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
3964
- data = encodeData(type, {
3965
- space: params.space
3966
4170
  });
3967
- keys = [{
3968
- pubkey: params.accountPubkey,
3969
- isSigner: true,
3970
- isWritable: true
3971
- }];
3972
4171
  }
3973
4172
 
3974
4173
  return new TransactionInstruction({
3975
- keys,
3976
4174
  programId: this.programId,
3977
- data
4175
+ keys: keys,
4176
+ data: data
4177
+ });
4178
+ }
4179
+
4180
+ static deactivateLookupTable(params) {
4181
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
4182
+ const data = encodeData(type);
4183
+ const keys = [{
4184
+ pubkey: params.lookupTable,
4185
+ isSigner: false,
4186
+ isWritable: true
4187
+ }, {
4188
+ pubkey: params.authority,
4189
+ isSigner: true,
4190
+ isWritable: false
4191
+ }];
4192
+ return new TransactionInstruction({
4193
+ programId: this.programId,
4194
+ keys: keys,
4195
+ data: data
4196
+ });
4197
+ }
4198
+
4199
+ static closeLookupTable(params) {
4200
+ const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
4201
+ const data = encodeData(type);
4202
+ const keys = [{
4203
+ pubkey: params.lookupTable,
4204
+ isSigner: false,
4205
+ isWritable: true
4206
+ }, {
4207
+ pubkey: params.authority,
4208
+ isSigner: true,
4209
+ isWritable: false
4210
+ }, {
4211
+ pubkey: params.recipient,
4212
+ isSigner: false,
4213
+ isWritable: true
4214
+ }];
4215
+ return new TransactionInstruction({
4216
+ programId: this.programId,
4217
+ keys: keys,
4218
+ data: data
3978
4219
  });
3979
4220
  }
3980
4221
 
3981
4222
  }
3982
- SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
4223
+ AddressLookupTableProgram.programId = new PublicKey('AddressLookupTab1e1111111111111111111111111');
4224
+
4225
+ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
4226
+
4227
+ /**
4228
+ * Sign, send and confirm a transaction.
4229
+ *
4230
+ * If `commitment` option is not specified, defaults to 'max' commitment.
4231
+ *
4232
+ * @param {Connection} connection
4233
+ * @param {Transaction} transaction
4234
+ * @param {Array<Signer>} signers
4235
+ * @param {ConfirmOptions} [options]
4236
+ * @returns {Promise<TransactionSignature>}
4237
+ */
4238
+ async function sendAndConfirmTransaction(connection, transaction, signers, options) {
4239
+ const sendOptions = options && {
4240
+ skipPreflight: options.skipPreflight,
4241
+ preflightCommitment: options.preflightCommitment || options.commitment,
4242
+ maxRetries: options.maxRetries,
4243
+ minContextSlot: options.minContextSlot
4244
+ };
4245
+ const signature = await connection.sendTransaction(transaction, signers, sendOptions);
4246
+ const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
4247
+ signature: signature,
4248
+ blockhash: transaction.recentBlockhash,
4249
+ lastValidBlockHeight: transaction.lastValidBlockHeight
4250
+ }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
4251
+
4252
+ if (status.err) {
4253
+ throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
4254
+ }
4255
+
4256
+ return signature;
4257
+ }
4258
+
4259
+ // zzz
4260
+ function sleep(ms) {
4261
+ return new Promise(resolve => setTimeout(resolve, ms));
4262
+ }
3983
4263
 
3984
4264
  // rest of the Transaction fields
3985
4265
  //
@@ -6730,8 +7010,15 @@ class Connection {
6730
7010
  */
6731
7011
 
6732
7012
 
6733
- async getBlock(slot, opts) {
6734
- const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
7013
+ async getBlock(slot, rawConfig) {
7014
+ const {
7015
+ commitment,
7016
+ config
7017
+ } = extractCommitmentFromConfig(rawConfig);
7018
+
7019
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined
7020
+ /* encoding */
7021
+ , config);
6735
7022
 
6736
7023
  const unsafeRes = await this._rpcRequest('getBlock', args);
6737
7024
  const res = superstruct.create(unsafeRes, GetBlockRpcResult);
@@ -6817,8 +7104,15 @@ class Connection {
6817
7104
  */
6818
7105
 
6819
7106
 
6820
- async getTransaction(signature, opts) {
6821
- const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
7107
+ async getTransaction(signature, rawConfig) {
7108
+ const {
7109
+ commitment,
7110
+ config
7111
+ } = extractCommitmentFromConfig(rawConfig);
7112
+
7113
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
7114
+ /* encoding */
7115
+ , config);
6822
7116
 
6823
7117
  const unsafeRes = await this._rpcRequest('getTransaction', args);
6824
7118
  const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
@@ -6840,8 +7134,13 @@ class Connection {
6840
7134
  */
6841
7135
 
6842
7136
 
6843
- async getParsedTransaction(signature, commitment) {
6844
- const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
7137
+ async getParsedTransaction(signature, commitmentOrConfig) {
7138
+ const {
7139
+ commitment,
7140
+ config
7141
+ } = extractCommitmentFromConfig(commitmentOrConfig);
7142
+
7143
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed', config);
6845
7144
 
6846
7145
  const unsafeRes = await this._rpcRequest('getTransaction', args);
6847
7146
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
@@ -6857,9 +7156,13 @@ class Connection {
6857
7156
  */
6858
7157
 
6859
7158
 
6860
- async getParsedTransactions(signatures, commitment) {
7159
+ async getParsedTransactions(signatures, commitmentOrConfig) {
7160
+ const {
7161
+ commitment,
7162
+ config
7163
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6861
7164
  const batch = signatures.map(signature => {
6862
- const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
7165
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed', config);
6863
7166
 
6864
7167
  return {
6865
7168
  methodName: 'getTransaction',
@@ -6884,9 +7187,15 @@ class Connection {
6884
7187
  */
6885
7188
 
6886
7189
 
6887
- async getTransactions(signatures, commitment) {
7190
+ async getTransactions(signatures, commitmentOrConfig) {
7191
+ const {
7192
+ commitment,
7193
+ config
7194
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6888
7195
  const batch = signatures.map(signature => {
6889
- const args = this._buildArgsAtLeastConfirmed([signature], commitment);
7196
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
7197
+ /* encoding */
7198
+ , config);
6890
7199
 
6891
7200
  return {
6892
7201
  methodName: 'getTransaction',
@@ -7328,6 +7637,28 @@ class Connection {
7328
7637
  this._pollingBlockhash = false;
7329
7638
  }
7330
7639
  }
7640
+ /**
7641
+ * get the stake minimum delegation
7642
+ */
7643
+
7644
+
7645
+ async getStakeMinimumDelegation(config) {
7646
+ const {
7647
+ commitment,
7648
+ config: configArg
7649
+ } = extractCommitmentFromConfig(config);
7650
+
7651
+ const args = this._buildArgs([], commitment, 'base64', configArg);
7652
+
7653
+ const unsafeRes = await this._rpcRequest('getStakeMinimumDelegation', args);
7654
+ const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.number()));
7655
+
7656
+ if ('error' in res) {
7657
+ throw new SolanaJSONRPCError(res.error, `failed to get stake minimum delegation`);
7658
+ }
7659
+
7660
+ return res.result;
7661
+ }
7331
7662
  /**
7332
7663
  * Simulate a transaction
7333
7664
  */
@@ -9966,6 +10297,8 @@ function clusterApiUrl(cluster, tls) {
9966
10297
  const LAMPORTS_PER_SOL = 1000000000;
9967
10298
 
9968
10299
  exports.Account = Account;
10300
+ exports.AddressLookupTableInstruction = AddressLookupTableInstruction;
10301
+ exports.AddressLookupTableProgram = AddressLookupTableProgram;
9969
10302
  exports.Authorized = Authorized;
9970
10303
  exports.BLOCKHASH_CACHE_TIMEOUT_MS = BLOCKHASH_CACHE_TIMEOUT_MS;
9971
10304
  exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
@@ -9981,6 +10314,7 @@ exports.EpochSchedule = EpochSchedule;
9981
10314
  exports.FeeCalculatorLayout = FeeCalculatorLayout;
9982
10315
  exports.Keypair = Keypair;
9983
10316
  exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
10317
+ exports.LOOKUP_TABLE_INSTRUCTION_LAYOUTS = LOOKUP_TABLE_INSTRUCTION_LAYOUTS;
9984
10318
  exports.Loader = Loader;
9985
10319
  exports.Lockup = Lockup;
9986
10320
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;