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