@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.browser.cjs.js +654 -320
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +652 -321
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +654 -320
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +347 -233
- package/lib/index.esm.js +652 -321
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +699 -365
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +654 -320
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- package/src/address-lookup-table-program.ts +433 -0
- package/src/connection.ts +76 -10
- package/src/index.ts +1 -0
- package/src/layout.ts +16 -4
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
|
-
|
|
2171
|
-
type.layout.fields.forEach(item => {
|
|
2158
|
+
const getItemAlloc = item => {
|
|
2172
2159
|
if (item.span >= 0) {
|
|
2173
|
-
|
|
2160
|
+
return item.span;
|
|
2174
2161
|
} else if (typeof item.alloc === 'function') {
|
|
2175
|
-
|
|
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;
|
|
@@ -3091,202 +3232,35 @@ class Transaction {
|
|
|
3091
3232
|
|
|
3092
3233
|
}
|
|
3093
3234
|
|
|
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
3235
|
/**
|
|
3105
|
-
*
|
|
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>}
|
|
3236
|
+
* Create account system transaction params
|
|
3114
3237
|
*/
|
|
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
3238
|
|
|
3141
3239
|
/**
|
|
3142
|
-
*
|
|
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
|
|
3240
|
+
* System Instruction class
|
|
3157
3241
|
*/
|
|
3242
|
+
class SystemInstruction {
|
|
3243
|
+
/**
|
|
3244
|
+
* @internal
|
|
3245
|
+
*/
|
|
3246
|
+
constructor() {}
|
|
3247
|
+
/**
|
|
3248
|
+
* Decode a system instruction and retrieve the instruction type.
|
|
3249
|
+
*/
|
|
3158
3250
|
|
|
3159
|
-
function decodeData(type, buffer) {
|
|
3160
|
-
let data;
|
|
3161
3251
|
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3252
|
+
static decodeInstructionType(instruction) {
|
|
3253
|
+
this.checkProgramId(instruction.programId);
|
|
3254
|
+
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
3255
|
+
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
3256
|
+
let type;
|
|
3167
3257
|
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
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
|
-
};
|
|
3258
|
-
|
|
3259
|
-
const u64 = bigInt(8);
|
|
3260
|
-
|
|
3261
|
-
/**
|
|
3262
|
-
* Create account system transaction params
|
|
3263
|
-
*/
|
|
3264
|
-
|
|
3265
|
-
/**
|
|
3266
|
-
* System Instruction class
|
|
3267
|
-
*/
|
|
3268
|
-
class SystemInstruction {
|
|
3269
|
-
/**
|
|
3270
|
-
* @internal
|
|
3271
|
-
*/
|
|
3272
|
-
constructor() {}
|
|
3273
|
-
/**
|
|
3274
|
-
* Decode a system instruction and retrieve the instruction type.
|
|
3275
|
-
*/
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
static decodeInstructionType(instruction) {
|
|
3279
|
-
this.checkProgramId(instruction.programId);
|
|
3280
|
-
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
3281
|
-
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
3282
|
-
let type;
|
|
3283
|
-
|
|
3284
|
-
for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
|
|
3285
|
-
if (layout.index == typeIndex) {
|
|
3286
|
-
type = ixType;
|
|
3287
|
-
break;
|
|
3288
|
-
}
|
|
3289
|
-
}
|
|
3258
|
+
for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
|
|
3259
|
+
if (layout.index == typeIndex) {
|
|
3260
|
+
type = ixType;
|
|
3261
|
+
break;
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3290
3264
|
|
|
3291
3265
|
if (!type) {
|
|
3292
3266
|
throw new Error('Instruction type incorrect; not a SystemInstruction');
|
|
@@ -3838,140 +3812,446 @@ class SystemProgram {
|
|
|
3838
3812
|
return new TransactionInstruction(instructionData);
|
|
3839
3813
|
}
|
|
3840
3814
|
/**
|
|
3841
|
-
* Generate an instruction to advance the nonce in a Nonce account
|
|
3815
|
+
* Generate an instruction to advance the nonce in a Nonce account
|
|
3816
|
+
*/
|
|
3817
|
+
|
|
3818
|
+
|
|
3819
|
+
static nonceAdvance(params) {
|
|
3820
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount;
|
|
3821
|
+
const data = encodeData(type);
|
|
3822
|
+
const instructionData = {
|
|
3823
|
+
keys: [{
|
|
3824
|
+
pubkey: params.noncePubkey,
|
|
3825
|
+
isSigner: false,
|
|
3826
|
+
isWritable: true
|
|
3827
|
+
}, {
|
|
3828
|
+
pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
3829
|
+
isSigner: false,
|
|
3830
|
+
isWritable: false
|
|
3831
|
+
}, {
|
|
3832
|
+
pubkey: params.authorizedPubkey,
|
|
3833
|
+
isSigner: true,
|
|
3834
|
+
isWritable: false
|
|
3835
|
+
}],
|
|
3836
|
+
programId: this.programId,
|
|
3837
|
+
data
|
|
3838
|
+
};
|
|
3839
|
+
return new TransactionInstruction(instructionData);
|
|
3840
|
+
}
|
|
3841
|
+
/**
|
|
3842
|
+
* Generate a transaction instruction that withdraws lamports from a Nonce account
|
|
3843
|
+
*/
|
|
3844
|
+
|
|
3845
|
+
|
|
3846
|
+
static nonceWithdraw(params) {
|
|
3847
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount;
|
|
3848
|
+
const data = encodeData(type, {
|
|
3849
|
+
lamports: params.lamports
|
|
3850
|
+
});
|
|
3851
|
+
return new TransactionInstruction({
|
|
3852
|
+
keys: [{
|
|
3853
|
+
pubkey: params.noncePubkey,
|
|
3854
|
+
isSigner: false,
|
|
3855
|
+
isWritable: true
|
|
3856
|
+
}, {
|
|
3857
|
+
pubkey: params.toPubkey,
|
|
3858
|
+
isSigner: false,
|
|
3859
|
+
isWritable: true
|
|
3860
|
+
}, {
|
|
3861
|
+
pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
3862
|
+
isSigner: false,
|
|
3863
|
+
isWritable: false
|
|
3864
|
+
}, {
|
|
3865
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
3866
|
+
isSigner: false,
|
|
3867
|
+
isWritable: false
|
|
3868
|
+
}, {
|
|
3869
|
+
pubkey: params.authorizedPubkey,
|
|
3870
|
+
isSigner: true,
|
|
3871
|
+
isWritable: false
|
|
3872
|
+
}],
|
|
3873
|
+
programId: this.programId,
|
|
3874
|
+
data
|
|
3875
|
+
});
|
|
3876
|
+
}
|
|
3877
|
+
/**
|
|
3878
|
+
* Generate a transaction instruction that authorizes a new PublicKey as the authority
|
|
3879
|
+
* on a Nonce account.
|
|
3880
|
+
*/
|
|
3881
|
+
|
|
3882
|
+
|
|
3883
|
+
static nonceAuthorize(params) {
|
|
3884
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount;
|
|
3885
|
+
const data = encodeData(type, {
|
|
3886
|
+
authorized: toBuffer(params.newAuthorizedPubkey.toBuffer())
|
|
3887
|
+
});
|
|
3888
|
+
return new TransactionInstruction({
|
|
3889
|
+
keys: [{
|
|
3890
|
+
pubkey: params.noncePubkey,
|
|
3891
|
+
isSigner: false,
|
|
3892
|
+
isWritable: true
|
|
3893
|
+
}, {
|
|
3894
|
+
pubkey: params.authorizedPubkey,
|
|
3895
|
+
isSigner: true,
|
|
3896
|
+
isWritable: false
|
|
3897
|
+
}],
|
|
3898
|
+
programId: this.programId,
|
|
3899
|
+
data
|
|
3900
|
+
});
|
|
3901
|
+
}
|
|
3902
|
+
/**
|
|
3903
|
+
* Generate a transaction instruction that allocates space in an account without funding
|
|
3904
|
+
*/
|
|
3905
|
+
|
|
3906
|
+
|
|
3907
|
+
static allocate(params) {
|
|
3908
|
+
let data;
|
|
3909
|
+
let keys;
|
|
3910
|
+
|
|
3911
|
+
if ('basePubkey' in params) {
|
|
3912
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed;
|
|
3913
|
+
data = encodeData(type, {
|
|
3914
|
+
base: toBuffer(params.basePubkey.toBuffer()),
|
|
3915
|
+
seed: params.seed,
|
|
3916
|
+
space: params.space,
|
|
3917
|
+
programId: toBuffer(params.programId.toBuffer())
|
|
3918
|
+
});
|
|
3919
|
+
keys = [{
|
|
3920
|
+
pubkey: params.accountPubkey,
|
|
3921
|
+
isSigner: false,
|
|
3922
|
+
isWritable: true
|
|
3923
|
+
}, {
|
|
3924
|
+
pubkey: params.basePubkey,
|
|
3925
|
+
isSigner: true,
|
|
3926
|
+
isWritable: false
|
|
3927
|
+
}];
|
|
3928
|
+
} else {
|
|
3929
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
|
|
3930
|
+
data = encodeData(type, {
|
|
3931
|
+
space: params.space
|
|
3932
|
+
});
|
|
3933
|
+
keys = [{
|
|
3934
|
+
pubkey: params.accountPubkey,
|
|
3935
|
+
isSigner: true,
|
|
3936
|
+
isWritable: true
|
|
3937
|
+
}];
|
|
3938
|
+
}
|
|
3939
|
+
|
|
3940
|
+
return new TransactionInstruction({
|
|
3941
|
+
keys,
|
|
3942
|
+
programId: this.programId,
|
|
3943
|
+
data
|
|
3944
|
+
});
|
|
3945
|
+
}
|
|
3946
|
+
|
|
3947
|
+
}
|
|
3948
|
+
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
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
|
|
3842
4072
|
*/
|
|
3843
4073
|
|
|
3844
4074
|
|
|
3845
|
-
static
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
keys: [{
|
|
3850
|
-
pubkey: params.noncePubkey,
|
|
3851
|
-
isSigner: false,
|
|
3852
|
-
isWritable: true
|
|
3853
|
-
}, {
|
|
3854
|
-
pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
3855
|
-
isSigner: false,
|
|
3856
|
-
isWritable: false
|
|
3857
|
-
}, {
|
|
3858
|
-
pubkey: params.authorizedPubkey,
|
|
3859
|
-
isSigner: true,
|
|
3860
|
-
isWritable: false
|
|
3861
|
-
}],
|
|
3862
|
-
programId: this.programId,
|
|
3863
|
-
data
|
|
3864
|
-
};
|
|
3865
|
-
return new TransactionInstruction(instructionData);
|
|
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
|
+
}
|
|
3866
4079
|
}
|
|
4080
|
+
|
|
4081
|
+
}
|
|
4082
|
+
class AddressLookupTableProgram {
|
|
3867
4083
|
/**
|
|
3868
|
-
*
|
|
4084
|
+
* @internal
|
|
3869
4085
|
*/
|
|
4086
|
+
constructor() {}
|
|
3870
4087
|
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
const type =
|
|
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;
|
|
3874
4091
|
const data = encodeData(type, {
|
|
3875
|
-
|
|
4092
|
+
recentSlot: BigInt(params.recentSlot),
|
|
4093
|
+
bumpSeed: bumpSeed
|
|
3876
4094
|
});
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
pubkey: params.authorizedPubkey,
|
|
3896
|
-
isSigner: true,
|
|
3897
|
-
isWritable: false
|
|
3898
|
-
}],
|
|
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({
|
|
3899
4113
|
programId: this.programId,
|
|
3900
|
-
|
|
3901
|
-
|
|
4114
|
+
keys: keys,
|
|
4115
|
+
data: data
|
|
4116
|
+
}), lookupTableAddress];
|
|
3902
4117
|
}
|
|
3903
|
-
/**
|
|
3904
|
-
* Generate a transaction instruction that authorizes a new PublicKey as the authority
|
|
3905
|
-
* on a Nonce account.
|
|
3906
|
-
*/
|
|
3907
|
-
|
|
3908
4118
|
|
|
3909
|
-
static
|
|
3910
|
-
const type =
|
|
3911
|
-
const data = encodeData(type
|
|
3912
|
-
|
|
3913
|
-
|
|
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
|
+
}];
|
|
3914
4131
|
return new TransactionInstruction({
|
|
3915
|
-
keys: [{
|
|
3916
|
-
pubkey: params.noncePubkey,
|
|
3917
|
-
isSigner: false,
|
|
3918
|
-
isWritable: true
|
|
3919
|
-
}, {
|
|
3920
|
-
pubkey: params.authorizedPubkey,
|
|
3921
|
-
isSigner: true,
|
|
3922
|
-
isWritable: false
|
|
3923
|
-
}],
|
|
3924
4132
|
programId: this.programId,
|
|
3925
|
-
|
|
4133
|
+
keys: keys,
|
|
4134
|
+
data: data
|
|
3926
4135
|
});
|
|
3927
4136
|
}
|
|
3928
|
-
/**
|
|
3929
|
-
* Generate a transaction instruction that allocates space in an account without funding
|
|
3930
|
-
*/
|
|
3931
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
|
+
}];
|
|
3932
4152
|
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
if ('basePubkey' in params) {
|
|
3938
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed;
|
|
3939
|
-
data = encodeData(type, {
|
|
3940
|
-
base: toBuffer(params.basePubkey.toBuffer()),
|
|
3941
|
-
seed: params.seed,
|
|
3942
|
-
space: params.space,
|
|
3943
|
-
programId: toBuffer(params.programId.toBuffer())
|
|
3944
|
-
});
|
|
3945
|
-
keys = [{
|
|
3946
|
-
pubkey: params.accountPubkey,
|
|
3947
|
-
isSigner: false,
|
|
4153
|
+
if (params.payer) {
|
|
4154
|
+
keys.push({
|
|
4155
|
+
pubkey: params.payer,
|
|
4156
|
+
isSigner: true,
|
|
3948
4157
|
isWritable: true
|
|
3949
4158
|
}, {
|
|
3950
|
-
pubkey:
|
|
3951
|
-
isSigner:
|
|
4159
|
+
pubkey: SystemProgram.programId,
|
|
4160
|
+
isSigner: false,
|
|
3952
4161
|
isWritable: false
|
|
3953
|
-
}];
|
|
3954
|
-
} else {
|
|
3955
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
|
|
3956
|
-
data = encodeData(type, {
|
|
3957
|
-
space: params.space
|
|
3958
4162
|
});
|
|
3959
|
-
keys = [{
|
|
3960
|
-
pubkey: params.accountPubkey,
|
|
3961
|
-
isSigner: true,
|
|
3962
|
-
isWritable: true
|
|
3963
|
-
}];
|
|
3964
4163
|
}
|
|
3965
4164
|
|
|
3966
4165
|
return new TransactionInstruction({
|
|
3967
|
-
keys,
|
|
3968
4166
|
programId: this.programId,
|
|
3969
|
-
|
|
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
|
|
3970
4211
|
});
|
|
3971
4212
|
}
|
|
3972
4213
|
|
|
3973
4214
|
}
|
|
3974
|
-
|
|
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
|
+
}
|
|
3975
4255
|
|
|
3976
4256
|
// rest of the Transaction fields
|
|
3977
4257
|
//
|
|
@@ -6782,8 +7062,15 @@ class Connection {
|
|
|
6782
7062
|
*/
|
|
6783
7063
|
|
|
6784
7064
|
|
|
6785
|
-
async getBlock(slot,
|
|
6786
|
-
const
|
|
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);
|
|
6787
7074
|
|
|
6788
7075
|
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6789
7076
|
const res = create(unsafeRes, GetBlockRpcResult);
|
|
@@ -6869,8 +7156,15 @@ class Connection {
|
|
|
6869
7156
|
*/
|
|
6870
7157
|
|
|
6871
7158
|
|
|
6872
|
-
async getTransaction(signature,
|
|
6873
|
-
const
|
|
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);
|
|
6874
7168
|
|
|
6875
7169
|
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6876
7170
|
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
@@ -6892,8 +7186,13 @@ class Connection {
|
|
|
6892
7186
|
*/
|
|
6893
7187
|
|
|
6894
7188
|
|
|
6895
|
-
async getParsedTransaction(signature,
|
|
6896
|
-
const
|
|
7189
|
+
async getParsedTransaction(signature, commitmentOrConfig) {
|
|
7190
|
+
const {
|
|
7191
|
+
commitment,
|
|
7192
|
+
config
|
|
7193
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
7194
|
+
|
|
7195
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed', config);
|
|
6897
7196
|
|
|
6898
7197
|
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6899
7198
|
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
@@ -6909,9 +7208,13 @@ class Connection {
|
|
|
6909
7208
|
*/
|
|
6910
7209
|
|
|
6911
7210
|
|
|
6912
|
-
async getParsedTransactions(signatures,
|
|
7211
|
+
async getParsedTransactions(signatures, commitmentOrConfig) {
|
|
7212
|
+
const {
|
|
7213
|
+
commitment,
|
|
7214
|
+
config
|
|
7215
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6913
7216
|
const batch = signatures.map(signature => {
|
|
6914
|
-
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
7217
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed', config);
|
|
6915
7218
|
|
|
6916
7219
|
return {
|
|
6917
7220
|
methodName: 'getTransaction',
|
|
@@ -6936,9 +7239,15 @@ class Connection {
|
|
|
6936
7239
|
*/
|
|
6937
7240
|
|
|
6938
7241
|
|
|
6939
|
-
async getTransactions(signatures,
|
|
7242
|
+
async getTransactions(signatures, commitmentOrConfig) {
|
|
7243
|
+
const {
|
|
7244
|
+
commitment,
|
|
7245
|
+
config
|
|
7246
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6940
7247
|
const batch = signatures.map(signature => {
|
|
6941
|
-
const args = this._buildArgsAtLeastConfirmed([signature], commitment
|
|
7248
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
|
|
7249
|
+
/* encoding */
|
|
7250
|
+
, config);
|
|
6942
7251
|
|
|
6943
7252
|
return {
|
|
6944
7253
|
methodName: 'getTransaction',
|
|
@@ -7380,6 +7689,28 @@ class Connection {
|
|
|
7380
7689
|
this._pollingBlockhash = false;
|
|
7381
7690
|
}
|
|
7382
7691
|
}
|
|
7692
|
+
/**
|
|
7693
|
+
* get the stake minimum delegation
|
|
7694
|
+
*/
|
|
7695
|
+
|
|
7696
|
+
|
|
7697
|
+
async getStakeMinimumDelegation(config) {
|
|
7698
|
+
const {
|
|
7699
|
+
commitment,
|
|
7700
|
+
config: configArg
|
|
7701
|
+
} = extractCommitmentFromConfig(config);
|
|
7702
|
+
|
|
7703
|
+
const args = this._buildArgs([], commitment, 'base64', configArg);
|
|
7704
|
+
|
|
7705
|
+
const unsafeRes = await this._rpcRequest('getStakeMinimumDelegation', args);
|
|
7706
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(number()));
|
|
7707
|
+
|
|
7708
|
+
if ('error' in res) {
|
|
7709
|
+
throw new SolanaJSONRPCError(res.error, `failed to get stake minimum delegation`);
|
|
7710
|
+
}
|
|
7711
|
+
|
|
7712
|
+
return res.result;
|
|
7713
|
+
}
|
|
7383
7714
|
/**
|
|
7384
7715
|
* Simulate a transaction
|
|
7385
7716
|
*/
|
|
@@ -10017,5 +10348,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
10017
10348
|
|
|
10018
10349
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
10019
10350
|
|
|
10020
|
-
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 };
|
|
10351
|
+
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 };
|
|
10021
10352
|
//# sourceMappingURL=index.esm.js.map
|