@solana/web3.js 1.47.4 → 1.48.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 +489 -206
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +487 -207
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +489 -206
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +311 -224
- package/lib/index.esm.js +487 -207
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +534 -251
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +489 -206
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- package/src/address-lookup-table-program.ts +433 -0
- package/src/index.ts +1 -0
- package/src/layout.ts +16 -4
package/lib/index.native.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');
|
|
@@ -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
|
-
|
|
2179
|
-
type.layout.fields.forEach(item => {
|
|
2166
|
+
const getItemAlloc = item => {
|
|
2180
2167
|
if (item.span >= 0) {
|
|
2181
|
-
|
|
2168
|
+
return item.span;
|
|
2182
2169
|
} else if (typeof item.alloc === 'function') {
|
|
2183
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
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
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
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');
|
|
@@ -3981,6 +3955,312 @@ class SystemProgram {
|
|
|
3981
3955
|
}
|
|
3982
3956
|
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
3983
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
|
|
4080
|
+
*/
|
|
4081
|
+
|
|
4082
|
+
|
|
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
|
+
}
|
|
4087
|
+
}
|
|
4088
|
+
|
|
4089
|
+
}
|
|
4090
|
+
class AddressLookupTableProgram {
|
|
4091
|
+
/**
|
|
4092
|
+
* @internal
|
|
4093
|
+
*/
|
|
4094
|
+
constructor() {}
|
|
4095
|
+
|
|
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;
|
|
4099
|
+
const data = encodeData(type, {
|
|
4100
|
+
recentSlot: BigInt(params.recentSlot),
|
|
4101
|
+
bumpSeed: bumpSeed
|
|
4102
|
+
});
|
|
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({
|
|
4121
|
+
programId: this.programId,
|
|
4122
|
+
keys: keys,
|
|
4123
|
+
data: data
|
|
4124
|
+
}), lookupTableAddress];
|
|
4125
|
+
}
|
|
4126
|
+
|
|
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
|
+
}];
|
|
4139
|
+
return new TransactionInstruction({
|
|
4140
|
+
programId: this.programId,
|
|
4141
|
+
keys: keys,
|
|
4142
|
+
data: data
|
|
4143
|
+
});
|
|
4144
|
+
}
|
|
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
|
+
}];
|
|
4160
|
+
|
|
4161
|
+
if (params.payer) {
|
|
4162
|
+
keys.push({
|
|
4163
|
+
pubkey: params.payer,
|
|
4164
|
+
isSigner: true,
|
|
4165
|
+
isWritable: true
|
|
4166
|
+
}, {
|
|
4167
|
+
pubkey: SystemProgram.programId,
|
|
4168
|
+
isSigner: false,
|
|
4169
|
+
isWritable: false
|
|
4170
|
+
});
|
|
4171
|
+
}
|
|
4172
|
+
|
|
4173
|
+
return new TransactionInstruction({
|
|
4174
|
+
programId: this.programId,
|
|
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
|
|
4219
|
+
});
|
|
4220
|
+
}
|
|
4221
|
+
|
|
4222
|
+
}
|
|
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
|
+
}
|
|
4263
|
+
|
|
3984
4264
|
// rest of the Transaction fields
|
|
3985
4265
|
//
|
|
3986
4266
|
// TODO: replace 300 with a proper constant for the size of the other
|
|
@@ -9966,6 +10246,8 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9966
10246
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9967
10247
|
|
|
9968
10248
|
exports.Account = Account;
|
|
10249
|
+
exports.AddressLookupTableInstruction = AddressLookupTableInstruction;
|
|
10250
|
+
exports.AddressLookupTableProgram = AddressLookupTableProgram;
|
|
9969
10251
|
exports.Authorized = Authorized;
|
|
9970
10252
|
exports.BLOCKHASH_CACHE_TIMEOUT_MS = BLOCKHASH_CACHE_TIMEOUT_MS;
|
|
9971
10253
|
exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
|
|
@@ -9981,6 +10263,7 @@ exports.EpochSchedule = EpochSchedule;
|
|
|
9981
10263
|
exports.FeeCalculatorLayout = FeeCalculatorLayout;
|
|
9982
10264
|
exports.Keypair = Keypair;
|
|
9983
10265
|
exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
|
|
10266
|
+
exports.LOOKUP_TABLE_INSTRUCTION_LAYOUTS = LOOKUP_TABLE_INSTRUCTION_LAYOUTS;
|
|
9984
10267
|
exports.Loader = Loader;
|
|
9985
10268
|
exports.Lockup = Lockup;
|
|
9986
10269
|
exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
|