@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.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';
|
|
@@ -2070,18 +2070,6 @@ class Account {
|
|
|
2070
2070
|
|
|
2071
2071
|
}
|
|
2072
2072
|
|
|
2073
|
-
const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
|
|
2074
|
-
|
|
2075
|
-
/**
|
|
2076
|
-
* Maximum over-the-wire size of a Transaction
|
|
2077
|
-
*
|
|
2078
|
-
* 1280 is IPv6 minimum MTU
|
|
2079
|
-
* 40 bytes is the size of the IPv6 header
|
|
2080
|
-
* 8 bytes is the size of the fragment header
|
|
2081
|
-
*/
|
|
2082
|
-
const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|
2083
|
-
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
2084
|
-
|
|
2085
2073
|
/**
|
|
2086
2074
|
* Layout for a public key
|
|
2087
2075
|
*/
|
|
@@ -2143,17 +2131,170 @@ const voteInit = (property = 'voteInit') => {
|
|
|
2143
2131
|
return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
|
|
2144
2132
|
};
|
|
2145
2133
|
function getAlloc(type, fields) {
|
|
2146
|
-
|
|
2147
|
-
type.layout.fields.forEach(item => {
|
|
2134
|
+
const getItemAlloc = item => {
|
|
2148
2135
|
if (item.span >= 0) {
|
|
2149
|
-
|
|
2136
|
+
return item.span;
|
|
2150
2137
|
} else if (typeof item.alloc === 'function') {
|
|
2151
|
-
|
|
2152
|
-
}
|
|
2138
|
+
return item.alloc(fields[item.property]);
|
|
2139
|
+
} else if ('count' in item && 'elementLayout' in item) {
|
|
2140
|
+
const field = fields[item.property];
|
|
2141
|
+
|
|
2142
|
+
if (Array.isArray(field)) {
|
|
2143
|
+
return field.length * getItemAlloc(item.elementLayout);
|
|
2144
|
+
}
|
|
2145
|
+
} // Couldn't determine allocated size of layout
|
|
2146
|
+
|
|
2147
|
+
|
|
2148
|
+
return 0;
|
|
2149
|
+
};
|
|
2150
|
+
|
|
2151
|
+
let alloc = 0;
|
|
2152
|
+
type.layout.fields.forEach(item => {
|
|
2153
|
+
alloc += getItemAlloc(item);
|
|
2153
2154
|
});
|
|
2154
2155
|
return alloc;
|
|
2155
2156
|
}
|
|
2156
2157
|
|
|
2158
|
+
const encodeDecode = layout => {
|
|
2159
|
+
const decode = layout.decode.bind(layout);
|
|
2160
|
+
const encode = layout.encode.bind(layout);
|
|
2161
|
+
return {
|
|
2162
|
+
decode,
|
|
2163
|
+
encode
|
|
2164
|
+
};
|
|
2165
|
+
};
|
|
2166
|
+
|
|
2167
|
+
const bigInt = length => property => {
|
|
2168
|
+
const layout = blob(length, property);
|
|
2169
|
+
const {
|
|
2170
|
+
encode,
|
|
2171
|
+
decode
|
|
2172
|
+
} = encodeDecode(layout);
|
|
2173
|
+
const bigIntLayout = layout;
|
|
2174
|
+
|
|
2175
|
+
bigIntLayout.decode = (buffer, offset) => {
|
|
2176
|
+
const src = decode(buffer, offset);
|
|
2177
|
+
return toBigIntLE(Buffer.from(src));
|
|
2178
|
+
};
|
|
2179
|
+
|
|
2180
|
+
bigIntLayout.encode = (bigInt, buffer, offset) => {
|
|
2181
|
+
const src = toBufferLE(bigInt, length);
|
|
2182
|
+
return encode(src, buffer, offset);
|
|
2183
|
+
};
|
|
2184
|
+
|
|
2185
|
+
return bigIntLayout;
|
|
2186
|
+
};
|
|
2187
|
+
|
|
2188
|
+
const u64 = bigInt(8);
|
|
2189
|
+
|
|
2190
|
+
/**
|
|
2191
|
+
* Populate a buffer of instruction data using an InstructionType
|
|
2192
|
+
* @internal
|
|
2193
|
+
*/
|
|
2194
|
+
function encodeData(type, fields) {
|
|
2195
|
+
const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
|
|
2196
|
+
const data = Buffer.alloc(allocLength);
|
|
2197
|
+
const layoutFields = Object.assign({
|
|
2198
|
+
instruction: type.index
|
|
2199
|
+
}, fields);
|
|
2200
|
+
type.layout.encode(layoutFields, data);
|
|
2201
|
+
return data;
|
|
2202
|
+
}
|
|
2203
|
+
/**
|
|
2204
|
+
* Decode instruction data buffer using an InstructionType
|
|
2205
|
+
* @internal
|
|
2206
|
+
*/
|
|
2207
|
+
|
|
2208
|
+
function decodeData(type, buffer) {
|
|
2209
|
+
let data;
|
|
2210
|
+
|
|
2211
|
+
try {
|
|
2212
|
+
data = type.layout.decode(buffer);
|
|
2213
|
+
} catch (err) {
|
|
2214
|
+
throw new Error('invalid instruction; ' + err);
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
if (data.instruction !== type.index) {
|
|
2218
|
+
throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
return data;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
/**
|
|
2225
|
+
* https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
|
|
2226
|
+
*
|
|
2227
|
+
* @internal
|
|
2228
|
+
*/
|
|
2229
|
+
|
|
2230
|
+
const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
|
|
2231
|
+
/**
|
|
2232
|
+
* Calculator for transaction fees.
|
|
2233
|
+
*/
|
|
2234
|
+
|
|
2235
|
+
/**
|
|
2236
|
+
* See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
|
|
2237
|
+
*
|
|
2238
|
+
* @internal
|
|
2239
|
+
*/
|
|
2240
|
+
|
|
2241
|
+
const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
2242
|
+
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
2243
|
+
|
|
2244
|
+
/**
|
|
2245
|
+
* NonceAccount class
|
|
2246
|
+
*/
|
|
2247
|
+
class NonceAccount {
|
|
2248
|
+
/**
|
|
2249
|
+
* @internal
|
|
2250
|
+
*/
|
|
2251
|
+
constructor(args) {
|
|
2252
|
+
this.authorizedPubkey = void 0;
|
|
2253
|
+
this.nonce = void 0;
|
|
2254
|
+
this.feeCalculator = void 0;
|
|
2255
|
+
this.authorizedPubkey = args.authorizedPubkey;
|
|
2256
|
+
this.nonce = args.nonce;
|
|
2257
|
+
this.feeCalculator = args.feeCalculator;
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2260
|
+
* Deserialize NonceAccount from the account data.
|
|
2261
|
+
*
|
|
2262
|
+
* @param buffer account data
|
|
2263
|
+
* @return NonceAccount
|
|
2264
|
+
*/
|
|
2265
|
+
|
|
2266
|
+
|
|
2267
|
+
static fromAccountData(buffer) {
|
|
2268
|
+
const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
|
|
2269
|
+
return new NonceAccount({
|
|
2270
|
+
authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
|
|
2271
|
+
nonce: new PublicKey(nonceAccount.nonce).toString(),
|
|
2272
|
+
feeCalculator: nonceAccount.feeCalculator
|
|
2273
|
+
});
|
|
2274
|
+
}
|
|
2275
|
+
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
2279
|
+
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
2280
|
+
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2281
|
+
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
2282
|
+
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
2283
|
+
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
2284
|
+
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
2285
|
+
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2286
|
+
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2287
|
+
|
|
2288
|
+
/**
|
|
2289
|
+
* Maximum over-the-wire size of a Transaction
|
|
2290
|
+
*
|
|
2291
|
+
* 1280 is IPv6 minimum MTU
|
|
2292
|
+
* 40 bytes is the size of the IPv6 header
|
|
2293
|
+
* 8 bytes is the size of the fragment header
|
|
2294
|
+
*/
|
|
2295
|
+
const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|
2296
|
+
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
2297
|
+
|
|
2157
2298
|
function decodeLength(bytes) {
|
|
2158
2299
|
let len = 0;
|
|
2159
2300
|
let size = 0;
|
|
@@ -3067,202 +3208,35 @@ class Transaction {
|
|
|
3067
3208
|
|
|
3068
3209
|
}
|
|
3069
3210
|
|
|
3070
|
-
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
3071
|
-
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
3072
|
-
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
3073
|
-
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
3074
|
-
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
3075
|
-
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
3076
|
-
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
3077
|
-
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
3078
|
-
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
3079
|
-
|
|
3080
3211
|
/**
|
|
3081
|
-
*
|
|
3082
|
-
*
|
|
3083
|
-
* If `commitment` option is not specified, defaults to 'max' commitment.
|
|
3084
|
-
*
|
|
3085
|
-
* @param {Connection} connection
|
|
3086
|
-
* @param {Transaction} transaction
|
|
3087
|
-
* @param {Array<Signer>} signers
|
|
3088
|
-
* @param {ConfirmOptions} [options]
|
|
3089
|
-
* @returns {Promise<TransactionSignature>}
|
|
3212
|
+
* Create account system transaction params
|
|
3090
3213
|
*/
|
|
3091
|
-
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
3092
|
-
const sendOptions = options && {
|
|
3093
|
-
skipPreflight: options.skipPreflight,
|
|
3094
|
-
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
3095
|
-
maxRetries: options.maxRetries,
|
|
3096
|
-
minContextSlot: options.minContextSlot
|
|
3097
|
-
};
|
|
3098
|
-
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
3099
|
-
const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
|
|
3100
|
-
signature: signature,
|
|
3101
|
-
blockhash: transaction.recentBlockhash,
|
|
3102
|
-
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
3103
|
-
}, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
3104
|
-
|
|
3105
|
-
if (status.err) {
|
|
3106
|
-
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
3107
|
-
}
|
|
3108
|
-
|
|
3109
|
-
return signature;
|
|
3110
|
-
}
|
|
3111
|
-
|
|
3112
|
-
// zzz
|
|
3113
|
-
function sleep(ms) {
|
|
3114
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
3115
|
-
}
|
|
3116
3214
|
|
|
3117
3215
|
/**
|
|
3118
|
-
*
|
|
3119
|
-
* @internal
|
|
3120
|
-
*/
|
|
3121
|
-
function encodeData(type, fields) {
|
|
3122
|
-
const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
|
|
3123
|
-
const data = Buffer.alloc(allocLength);
|
|
3124
|
-
const layoutFields = Object.assign({
|
|
3125
|
-
instruction: type.index
|
|
3126
|
-
}, fields);
|
|
3127
|
-
type.layout.encode(layoutFields, data);
|
|
3128
|
-
return data;
|
|
3129
|
-
}
|
|
3130
|
-
/**
|
|
3131
|
-
* Decode instruction data buffer using an InstructionType
|
|
3132
|
-
* @internal
|
|
3216
|
+
* System Instruction class
|
|
3133
3217
|
*/
|
|
3218
|
+
class SystemInstruction {
|
|
3219
|
+
/**
|
|
3220
|
+
* @internal
|
|
3221
|
+
*/
|
|
3222
|
+
constructor() {}
|
|
3223
|
+
/**
|
|
3224
|
+
* Decode a system instruction and retrieve the instruction type.
|
|
3225
|
+
*/
|
|
3134
3226
|
|
|
3135
|
-
function decodeData(type, buffer) {
|
|
3136
|
-
let data;
|
|
3137
3227
|
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3228
|
+
static decodeInstructionType(instruction) {
|
|
3229
|
+
this.checkProgramId(instruction.programId);
|
|
3230
|
+
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
3231
|
+
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
3232
|
+
let type;
|
|
3143
3233
|
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
}
|
|
3150
|
-
|
|
3151
|
-
/**
|
|
3152
|
-
* https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
|
|
3153
|
-
*
|
|
3154
|
-
* @internal
|
|
3155
|
-
*/
|
|
3156
|
-
|
|
3157
|
-
const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
|
|
3158
|
-
/**
|
|
3159
|
-
* Calculator for transaction fees.
|
|
3160
|
-
*/
|
|
3161
|
-
|
|
3162
|
-
/**
|
|
3163
|
-
* See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
|
|
3164
|
-
*
|
|
3165
|
-
* @internal
|
|
3166
|
-
*/
|
|
3167
|
-
|
|
3168
|
-
const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
3169
|
-
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
3170
|
-
|
|
3171
|
-
/**
|
|
3172
|
-
* NonceAccount class
|
|
3173
|
-
*/
|
|
3174
|
-
class NonceAccount {
|
|
3175
|
-
/**
|
|
3176
|
-
* @internal
|
|
3177
|
-
*/
|
|
3178
|
-
constructor(args) {
|
|
3179
|
-
this.authorizedPubkey = void 0;
|
|
3180
|
-
this.nonce = void 0;
|
|
3181
|
-
this.feeCalculator = void 0;
|
|
3182
|
-
this.authorizedPubkey = args.authorizedPubkey;
|
|
3183
|
-
this.nonce = args.nonce;
|
|
3184
|
-
this.feeCalculator = args.feeCalculator;
|
|
3185
|
-
}
|
|
3186
|
-
/**
|
|
3187
|
-
* Deserialize NonceAccount from the account data.
|
|
3188
|
-
*
|
|
3189
|
-
* @param buffer account data
|
|
3190
|
-
* @return NonceAccount
|
|
3191
|
-
*/
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
static fromAccountData(buffer) {
|
|
3195
|
-
const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
|
|
3196
|
-
return new NonceAccount({
|
|
3197
|
-
authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
|
|
3198
|
-
nonce: new PublicKey(nonceAccount.nonce).toString(),
|
|
3199
|
-
feeCalculator: nonceAccount.feeCalculator
|
|
3200
|
-
});
|
|
3201
|
-
}
|
|
3202
|
-
|
|
3203
|
-
}
|
|
3204
|
-
|
|
3205
|
-
const encodeDecode = layout => {
|
|
3206
|
-
const decode = layout.decode.bind(layout);
|
|
3207
|
-
const encode = layout.encode.bind(layout);
|
|
3208
|
-
return {
|
|
3209
|
-
decode,
|
|
3210
|
-
encode
|
|
3211
|
-
};
|
|
3212
|
-
};
|
|
3213
|
-
|
|
3214
|
-
const bigInt = length => property => {
|
|
3215
|
-
const layout = blob(length, property);
|
|
3216
|
-
const {
|
|
3217
|
-
encode,
|
|
3218
|
-
decode
|
|
3219
|
-
} = encodeDecode(layout);
|
|
3220
|
-
const bigIntLayout = layout;
|
|
3221
|
-
|
|
3222
|
-
bigIntLayout.decode = (buffer, offset) => {
|
|
3223
|
-
const src = decode(buffer, offset);
|
|
3224
|
-
return toBigIntLE(Buffer.from(src));
|
|
3225
|
-
};
|
|
3226
|
-
|
|
3227
|
-
bigIntLayout.encode = (bigInt, buffer, offset) => {
|
|
3228
|
-
const src = toBufferLE(bigInt, length);
|
|
3229
|
-
return encode(src, buffer, offset);
|
|
3230
|
-
};
|
|
3231
|
-
|
|
3232
|
-
return bigIntLayout;
|
|
3233
|
-
};
|
|
3234
|
-
|
|
3235
|
-
const u64 = bigInt(8);
|
|
3236
|
-
|
|
3237
|
-
/**
|
|
3238
|
-
* Create account system transaction params
|
|
3239
|
-
*/
|
|
3240
|
-
|
|
3241
|
-
/**
|
|
3242
|
-
* System Instruction class
|
|
3243
|
-
*/
|
|
3244
|
-
class SystemInstruction {
|
|
3245
|
-
/**
|
|
3246
|
-
* @internal
|
|
3247
|
-
*/
|
|
3248
|
-
constructor() {}
|
|
3249
|
-
/**
|
|
3250
|
-
* Decode a system instruction and retrieve the instruction type.
|
|
3251
|
-
*/
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
static decodeInstructionType(instruction) {
|
|
3255
|
-
this.checkProgramId(instruction.programId);
|
|
3256
|
-
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
3257
|
-
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
3258
|
-
let type;
|
|
3259
|
-
|
|
3260
|
-
for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
|
|
3261
|
-
if (layout.index == typeIndex) {
|
|
3262
|
-
type = ixType;
|
|
3263
|
-
break;
|
|
3264
|
-
}
|
|
3265
|
-
}
|
|
3234
|
+
for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
|
|
3235
|
+
if (layout.index == typeIndex) {
|
|
3236
|
+
type = ixType;
|
|
3237
|
+
break;
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3266
3240
|
|
|
3267
3241
|
if (!type) {
|
|
3268
3242
|
throw new Error('Instruction type incorrect; not a SystemInstruction');
|
|
@@ -3814,140 +3788,446 @@ class SystemProgram {
|
|
|
3814
3788
|
return new TransactionInstruction(instructionData);
|
|
3815
3789
|
}
|
|
3816
3790
|
/**
|
|
3817
|
-
* Generate an instruction to advance the nonce in a Nonce account
|
|
3791
|
+
* Generate an instruction to advance the nonce in a Nonce account
|
|
3792
|
+
*/
|
|
3793
|
+
|
|
3794
|
+
|
|
3795
|
+
static nonceAdvance(params) {
|
|
3796
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount;
|
|
3797
|
+
const data = encodeData(type);
|
|
3798
|
+
const instructionData = {
|
|
3799
|
+
keys: [{
|
|
3800
|
+
pubkey: params.noncePubkey,
|
|
3801
|
+
isSigner: false,
|
|
3802
|
+
isWritable: true
|
|
3803
|
+
}, {
|
|
3804
|
+
pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
3805
|
+
isSigner: false,
|
|
3806
|
+
isWritable: false
|
|
3807
|
+
}, {
|
|
3808
|
+
pubkey: params.authorizedPubkey,
|
|
3809
|
+
isSigner: true,
|
|
3810
|
+
isWritable: false
|
|
3811
|
+
}],
|
|
3812
|
+
programId: this.programId,
|
|
3813
|
+
data
|
|
3814
|
+
};
|
|
3815
|
+
return new TransactionInstruction(instructionData);
|
|
3816
|
+
}
|
|
3817
|
+
/**
|
|
3818
|
+
* Generate a transaction instruction that withdraws lamports from a Nonce account
|
|
3819
|
+
*/
|
|
3820
|
+
|
|
3821
|
+
|
|
3822
|
+
static nonceWithdraw(params) {
|
|
3823
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount;
|
|
3824
|
+
const data = encodeData(type, {
|
|
3825
|
+
lamports: params.lamports
|
|
3826
|
+
});
|
|
3827
|
+
return new TransactionInstruction({
|
|
3828
|
+
keys: [{
|
|
3829
|
+
pubkey: params.noncePubkey,
|
|
3830
|
+
isSigner: false,
|
|
3831
|
+
isWritable: true
|
|
3832
|
+
}, {
|
|
3833
|
+
pubkey: params.toPubkey,
|
|
3834
|
+
isSigner: false,
|
|
3835
|
+
isWritable: true
|
|
3836
|
+
}, {
|
|
3837
|
+
pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
3838
|
+
isSigner: false,
|
|
3839
|
+
isWritable: false
|
|
3840
|
+
}, {
|
|
3841
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
3842
|
+
isSigner: false,
|
|
3843
|
+
isWritable: false
|
|
3844
|
+
}, {
|
|
3845
|
+
pubkey: params.authorizedPubkey,
|
|
3846
|
+
isSigner: true,
|
|
3847
|
+
isWritable: false
|
|
3848
|
+
}],
|
|
3849
|
+
programId: this.programId,
|
|
3850
|
+
data
|
|
3851
|
+
});
|
|
3852
|
+
}
|
|
3853
|
+
/**
|
|
3854
|
+
* Generate a transaction instruction that authorizes a new PublicKey as the authority
|
|
3855
|
+
* on a Nonce account.
|
|
3856
|
+
*/
|
|
3857
|
+
|
|
3858
|
+
|
|
3859
|
+
static nonceAuthorize(params) {
|
|
3860
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount;
|
|
3861
|
+
const data = encodeData(type, {
|
|
3862
|
+
authorized: toBuffer(params.newAuthorizedPubkey.toBuffer())
|
|
3863
|
+
});
|
|
3864
|
+
return new TransactionInstruction({
|
|
3865
|
+
keys: [{
|
|
3866
|
+
pubkey: params.noncePubkey,
|
|
3867
|
+
isSigner: false,
|
|
3868
|
+
isWritable: true
|
|
3869
|
+
}, {
|
|
3870
|
+
pubkey: params.authorizedPubkey,
|
|
3871
|
+
isSigner: true,
|
|
3872
|
+
isWritable: false
|
|
3873
|
+
}],
|
|
3874
|
+
programId: this.programId,
|
|
3875
|
+
data
|
|
3876
|
+
});
|
|
3877
|
+
}
|
|
3878
|
+
/**
|
|
3879
|
+
* Generate a transaction instruction that allocates space in an account without funding
|
|
3880
|
+
*/
|
|
3881
|
+
|
|
3882
|
+
|
|
3883
|
+
static allocate(params) {
|
|
3884
|
+
let data;
|
|
3885
|
+
let keys;
|
|
3886
|
+
|
|
3887
|
+
if ('basePubkey' in params) {
|
|
3888
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed;
|
|
3889
|
+
data = encodeData(type, {
|
|
3890
|
+
base: toBuffer(params.basePubkey.toBuffer()),
|
|
3891
|
+
seed: params.seed,
|
|
3892
|
+
space: params.space,
|
|
3893
|
+
programId: toBuffer(params.programId.toBuffer())
|
|
3894
|
+
});
|
|
3895
|
+
keys = [{
|
|
3896
|
+
pubkey: params.accountPubkey,
|
|
3897
|
+
isSigner: false,
|
|
3898
|
+
isWritable: true
|
|
3899
|
+
}, {
|
|
3900
|
+
pubkey: params.basePubkey,
|
|
3901
|
+
isSigner: true,
|
|
3902
|
+
isWritable: false
|
|
3903
|
+
}];
|
|
3904
|
+
} else {
|
|
3905
|
+
const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
|
|
3906
|
+
data = encodeData(type, {
|
|
3907
|
+
space: params.space
|
|
3908
|
+
});
|
|
3909
|
+
keys = [{
|
|
3910
|
+
pubkey: params.accountPubkey,
|
|
3911
|
+
isSigner: true,
|
|
3912
|
+
isWritable: true
|
|
3913
|
+
}];
|
|
3914
|
+
}
|
|
3915
|
+
|
|
3916
|
+
return new TransactionInstruction({
|
|
3917
|
+
keys,
|
|
3918
|
+
programId: this.programId,
|
|
3919
|
+
data
|
|
3920
|
+
});
|
|
3921
|
+
}
|
|
3922
|
+
|
|
3923
|
+
}
|
|
3924
|
+
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
3925
|
+
|
|
3926
|
+
/**
|
|
3927
|
+
* An enumeration of valid address lookup table InstructionType's
|
|
3928
|
+
* @internal
|
|
3929
|
+
*/
|
|
3930
|
+
const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
3931
|
+
CreateLookupTable: {
|
|
3932
|
+
index: 0,
|
|
3933
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64('recentSlot'), BufferLayout.u8('bumpSeed')])
|
|
3934
|
+
},
|
|
3935
|
+
FreezeLookupTable: {
|
|
3936
|
+
index: 1,
|
|
3937
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction')])
|
|
3938
|
+
},
|
|
3939
|
+
ExtendLookupTable: {
|
|
3940
|
+
index: 2,
|
|
3941
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64(), BufferLayout.seq(publicKey(), BufferLayout.offset(BufferLayout.u32(), -8), 'addresses')])
|
|
3942
|
+
},
|
|
3943
|
+
DeactivateLookupTable: {
|
|
3944
|
+
index: 3,
|
|
3945
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction')])
|
|
3946
|
+
},
|
|
3947
|
+
CloseLookupTable: {
|
|
3948
|
+
index: 4,
|
|
3949
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction')])
|
|
3950
|
+
}
|
|
3951
|
+
});
|
|
3952
|
+
class AddressLookupTableInstruction {
|
|
3953
|
+
/**
|
|
3954
|
+
* @internal
|
|
3955
|
+
*/
|
|
3956
|
+
constructor() {}
|
|
3957
|
+
|
|
3958
|
+
static decodeInstructionType(instruction) {
|
|
3959
|
+
this.checkProgramId(instruction.programId);
|
|
3960
|
+
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
3961
|
+
const index = instructionTypeLayout.decode(instruction.data);
|
|
3962
|
+
let type;
|
|
3963
|
+
|
|
3964
|
+
for (const [layoutType, layout] of Object.entries(LOOKUP_TABLE_INSTRUCTION_LAYOUTS)) {
|
|
3965
|
+
if (layout.index == index) {
|
|
3966
|
+
type = layoutType;
|
|
3967
|
+
break;
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
|
|
3971
|
+
if (!type) {
|
|
3972
|
+
throw new Error('Invalid Instruction. Should be a LookupTable Instruction');
|
|
3973
|
+
}
|
|
3974
|
+
|
|
3975
|
+
return type;
|
|
3976
|
+
}
|
|
3977
|
+
|
|
3978
|
+
static decodeCreateLookupTable(instruction) {
|
|
3979
|
+
this.checkProgramId(instruction.programId);
|
|
3980
|
+
this.checkKeysLength(instruction.keys, 4);
|
|
3981
|
+
const {
|
|
3982
|
+
recentSlot
|
|
3983
|
+
} = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable, instruction.data);
|
|
3984
|
+
return {
|
|
3985
|
+
authority: instruction.keys[1].pubkey,
|
|
3986
|
+
payer: instruction.keys[2].pubkey,
|
|
3987
|
+
recentSlot: Number(recentSlot)
|
|
3988
|
+
};
|
|
3989
|
+
}
|
|
3990
|
+
|
|
3991
|
+
static decodeExtendLookupTable(instruction) {
|
|
3992
|
+
this.checkProgramId(instruction.programId);
|
|
3993
|
+
|
|
3994
|
+
if (instruction.keys.length < 2) {
|
|
3995
|
+
throw new Error(`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`);
|
|
3996
|
+
}
|
|
3997
|
+
|
|
3998
|
+
const {
|
|
3999
|
+
addresses
|
|
4000
|
+
} = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable, instruction.data);
|
|
4001
|
+
return {
|
|
4002
|
+
lookupTable: instruction.keys[0].pubkey,
|
|
4003
|
+
authority: instruction.keys[1].pubkey,
|
|
4004
|
+
payer: instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
|
|
4005
|
+
addresses: addresses.map(buffer => new PublicKey(buffer))
|
|
4006
|
+
};
|
|
4007
|
+
}
|
|
4008
|
+
|
|
4009
|
+
static decodeCloseLookupTable(instruction) {
|
|
4010
|
+
this.checkProgramId(instruction.programId);
|
|
4011
|
+
this.checkKeysLength(instruction.keys, 3);
|
|
4012
|
+
return {
|
|
4013
|
+
lookupTable: instruction.keys[0].pubkey,
|
|
4014
|
+
authority: instruction.keys[1].pubkey,
|
|
4015
|
+
recipient: instruction.keys[2].pubkey
|
|
4016
|
+
};
|
|
4017
|
+
}
|
|
4018
|
+
|
|
4019
|
+
static decodeFreezeLookupTable(instruction) {
|
|
4020
|
+
this.checkProgramId(instruction.programId);
|
|
4021
|
+
this.checkKeysLength(instruction.keys, 2);
|
|
4022
|
+
return {
|
|
4023
|
+
lookupTable: instruction.keys[0].pubkey,
|
|
4024
|
+
authority: instruction.keys[1].pubkey
|
|
4025
|
+
};
|
|
4026
|
+
}
|
|
4027
|
+
|
|
4028
|
+
static decodeDeactivateLookupTable(instruction) {
|
|
4029
|
+
this.checkProgramId(instruction.programId);
|
|
4030
|
+
this.checkKeysLength(instruction.keys, 2);
|
|
4031
|
+
return {
|
|
4032
|
+
lookupTable: instruction.keys[0].pubkey,
|
|
4033
|
+
authority: instruction.keys[1].pubkey
|
|
4034
|
+
};
|
|
4035
|
+
}
|
|
4036
|
+
/**
|
|
4037
|
+
* @internal
|
|
4038
|
+
*/
|
|
4039
|
+
|
|
4040
|
+
|
|
4041
|
+
static checkProgramId(programId) {
|
|
4042
|
+
if (!programId.equals(AddressLookupTableProgram.programId)) {
|
|
4043
|
+
throw new Error('invalid instruction; programId is not AddressLookupTable Program');
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
/**
|
|
4047
|
+
* @internal
|
|
3818
4048
|
*/
|
|
3819
4049
|
|
|
3820
4050
|
|
|
3821
|
-
static
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
keys: [{
|
|
3826
|
-
pubkey: params.noncePubkey,
|
|
3827
|
-
isSigner: false,
|
|
3828
|
-
isWritable: true
|
|
3829
|
-
}, {
|
|
3830
|
-
pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
3831
|
-
isSigner: false,
|
|
3832
|
-
isWritable: false
|
|
3833
|
-
}, {
|
|
3834
|
-
pubkey: params.authorizedPubkey,
|
|
3835
|
-
isSigner: true,
|
|
3836
|
-
isWritable: false
|
|
3837
|
-
}],
|
|
3838
|
-
programId: this.programId,
|
|
3839
|
-
data
|
|
3840
|
-
};
|
|
3841
|
-
return new TransactionInstruction(instructionData);
|
|
4051
|
+
static checkKeysLength(keys, expectedLength) {
|
|
4052
|
+
if (keys.length < expectedLength) {
|
|
4053
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
4054
|
+
}
|
|
3842
4055
|
}
|
|
4056
|
+
|
|
4057
|
+
}
|
|
4058
|
+
class AddressLookupTableProgram {
|
|
3843
4059
|
/**
|
|
3844
|
-
*
|
|
4060
|
+
* @internal
|
|
3845
4061
|
*/
|
|
4062
|
+
constructor() {}
|
|
3846
4063
|
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
const type =
|
|
4064
|
+
static createLookupTable(params) {
|
|
4065
|
+
const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
|
|
4066
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
|
|
3850
4067
|
const data = encodeData(type, {
|
|
3851
|
-
|
|
4068
|
+
recentSlot: BigInt(params.recentSlot),
|
|
4069
|
+
bumpSeed: bumpSeed
|
|
3852
4070
|
});
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
pubkey: params.authorizedPubkey,
|
|
3872
|
-
isSigner: true,
|
|
3873
|
-
isWritable: false
|
|
3874
|
-
}],
|
|
4071
|
+
const keys = [{
|
|
4072
|
+
pubkey: lookupTableAddress,
|
|
4073
|
+
isSigner: false,
|
|
4074
|
+
isWritable: true
|
|
4075
|
+
}, {
|
|
4076
|
+
pubkey: params.authority,
|
|
4077
|
+
isSigner: true,
|
|
4078
|
+
isWritable: false
|
|
4079
|
+
}, {
|
|
4080
|
+
pubkey: params.payer,
|
|
4081
|
+
isSigner: true,
|
|
4082
|
+
isWritable: true
|
|
4083
|
+
}, {
|
|
4084
|
+
pubkey: SystemProgram.programId,
|
|
4085
|
+
isSigner: false,
|
|
4086
|
+
isWritable: false
|
|
4087
|
+
}];
|
|
4088
|
+
return [new TransactionInstruction({
|
|
3875
4089
|
programId: this.programId,
|
|
3876
|
-
|
|
3877
|
-
|
|
4090
|
+
keys: keys,
|
|
4091
|
+
data: data
|
|
4092
|
+
}), lookupTableAddress];
|
|
3878
4093
|
}
|
|
3879
|
-
/**
|
|
3880
|
-
* Generate a transaction instruction that authorizes a new PublicKey as the authority
|
|
3881
|
-
* on a Nonce account.
|
|
3882
|
-
*/
|
|
3883
|
-
|
|
3884
4094
|
|
|
3885
|
-
static
|
|
3886
|
-
const type =
|
|
3887
|
-
const data = encodeData(type
|
|
3888
|
-
|
|
3889
|
-
|
|
4095
|
+
static freezeLookupTable(params) {
|
|
4096
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
|
|
4097
|
+
const data = encodeData(type);
|
|
4098
|
+
const keys = [{
|
|
4099
|
+
pubkey: params.lookupTable,
|
|
4100
|
+
isSigner: false,
|
|
4101
|
+
isWritable: true
|
|
4102
|
+
}, {
|
|
4103
|
+
pubkey: params.authority,
|
|
4104
|
+
isSigner: true,
|
|
4105
|
+
isWritable: false
|
|
4106
|
+
}];
|
|
3890
4107
|
return new TransactionInstruction({
|
|
3891
|
-
keys: [{
|
|
3892
|
-
pubkey: params.noncePubkey,
|
|
3893
|
-
isSigner: false,
|
|
3894
|
-
isWritable: true
|
|
3895
|
-
}, {
|
|
3896
|
-
pubkey: params.authorizedPubkey,
|
|
3897
|
-
isSigner: true,
|
|
3898
|
-
isWritable: false
|
|
3899
|
-
}],
|
|
3900
4108
|
programId: this.programId,
|
|
3901
|
-
|
|
4109
|
+
keys: keys,
|
|
4110
|
+
data: data
|
|
3902
4111
|
});
|
|
3903
4112
|
}
|
|
3904
|
-
/**
|
|
3905
|
-
* Generate a transaction instruction that allocates space in an account without funding
|
|
3906
|
-
*/
|
|
3907
4113
|
|
|
4114
|
+
static extendLookupTable(params) {
|
|
4115
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
|
|
4116
|
+
const data = encodeData(type, {
|
|
4117
|
+
addresses: params.addresses.map(addr => addr.toBytes())
|
|
4118
|
+
});
|
|
4119
|
+
const keys = [{
|
|
4120
|
+
pubkey: params.lookupTable,
|
|
4121
|
+
isSigner: false,
|
|
4122
|
+
isWritable: true
|
|
4123
|
+
}, {
|
|
4124
|
+
pubkey: params.authority,
|
|
4125
|
+
isSigner: true,
|
|
4126
|
+
isWritable: false
|
|
4127
|
+
}];
|
|
3908
4128
|
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
if ('basePubkey' in params) {
|
|
3914
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed;
|
|
3915
|
-
data = encodeData(type, {
|
|
3916
|
-
base: toBuffer(params.basePubkey.toBuffer()),
|
|
3917
|
-
seed: params.seed,
|
|
3918
|
-
space: params.space,
|
|
3919
|
-
programId: toBuffer(params.programId.toBuffer())
|
|
3920
|
-
});
|
|
3921
|
-
keys = [{
|
|
3922
|
-
pubkey: params.accountPubkey,
|
|
3923
|
-
isSigner: false,
|
|
4129
|
+
if (params.payer) {
|
|
4130
|
+
keys.push({
|
|
4131
|
+
pubkey: params.payer,
|
|
4132
|
+
isSigner: true,
|
|
3924
4133
|
isWritable: true
|
|
3925
4134
|
}, {
|
|
3926
|
-
pubkey:
|
|
3927
|
-
isSigner:
|
|
4135
|
+
pubkey: SystemProgram.programId,
|
|
4136
|
+
isSigner: false,
|
|
3928
4137
|
isWritable: false
|
|
3929
|
-
}];
|
|
3930
|
-
} else {
|
|
3931
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
|
|
3932
|
-
data = encodeData(type, {
|
|
3933
|
-
space: params.space
|
|
3934
4138
|
});
|
|
3935
|
-
keys = [{
|
|
3936
|
-
pubkey: params.accountPubkey,
|
|
3937
|
-
isSigner: true,
|
|
3938
|
-
isWritable: true
|
|
3939
|
-
}];
|
|
3940
4139
|
}
|
|
3941
4140
|
|
|
3942
4141
|
return new TransactionInstruction({
|
|
3943
|
-
keys,
|
|
3944
4142
|
programId: this.programId,
|
|
3945
|
-
|
|
4143
|
+
keys: keys,
|
|
4144
|
+
data: data
|
|
4145
|
+
});
|
|
4146
|
+
}
|
|
4147
|
+
|
|
4148
|
+
static deactivateLookupTable(params) {
|
|
4149
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
|
|
4150
|
+
const data = encodeData(type);
|
|
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
|
+
return new TransactionInstruction({
|
|
4161
|
+
programId: this.programId,
|
|
4162
|
+
keys: keys,
|
|
4163
|
+
data: data
|
|
4164
|
+
});
|
|
4165
|
+
}
|
|
4166
|
+
|
|
4167
|
+
static closeLookupTable(params) {
|
|
4168
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
|
|
4169
|
+
const data = encodeData(type);
|
|
4170
|
+
const keys = [{
|
|
4171
|
+
pubkey: params.lookupTable,
|
|
4172
|
+
isSigner: false,
|
|
4173
|
+
isWritable: true
|
|
4174
|
+
}, {
|
|
4175
|
+
pubkey: params.authority,
|
|
4176
|
+
isSigner: true,
|
|
4177
|
+
isWritable: false
|
|
4178
|
+
}, {
|
|
4179
|
+
pubkey: params.recipient,
|
|
4180
|
+
isSigner: false,
|
|
4181
|
+
isWritable: true
|
|
4182
|
+
}];
|
|
4183
|
+
return new TransactionInstruction({
|
|
4184
|
+
programId: this.programId,
|
|
4185
|
+
keys: keys,
|
|
4186
|
+
data: data
|
|
3946
4187
|
});
|
|
3947
4188
|
}
|
|
3948
4189
|
|
|
3949
4190
|
}
|
|
3950
|
-
|
|
4191
|
+
AddressLookupTableProgram.programId = new PublicKey('AddressLookupTab1e1111111111111111111111111');
|
|
4192
|
+
|
|
4193
|
+
const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
|
|
4194
|
+
|
|
4195
|
+
/**
|
|
4196
|
+
* Sign, send and confirm a transaction.
|
|
4197
|
+
*
|
|
4198
|
+
* If `commitment` option is not specified, defaults to 'max' commitment.
|
|
4199
|
+
*
|
|
4200
|
+
* @param {Connection} connection
|
|
4201
|
+
* @param {Transaction} transaction
|
|
4202
|
+
* @param {Array<Signer>} signers
|
|
4203
|
+
* @param {ConfirmOptions} [options]
|
|
4204
|
+
* @returns {Promise<TransactionSignature>}
|
|
4205
|
+
*/
|
|
4206
|
+
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
4207
|
+
const sendOptions = options && {
|
|
4208
|
+
skipPreflight: options.skipPreflight,
|
|
4209
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
4210
|
+
maxRetries: options.maxRetries,
|
|
4211
|
+
minContextSlot: options.minContextSlot
|
|
4212
|
+
};
|
|
4213
|
+
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
4214
|
+
const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
|
|
4215
|
+
signature: signature,
|
|
4216
|
+
blockhash: transaction.recentBlockhash,
|
|
4217
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
4218
|
+
}, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
4219
|
+
|
|
4220
|
+
if (status.err) {
|
|
4221
|
+
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
4222
|
+
}
|
|
4223
|
+
|
|
4224
|
+
return signature;
|
|
4225
|
+
}
|
|
4226
|
+
|
|
4227
|
+
// zzz
|
|
4228
|
+
function sleep(ms) {
|
|
4229
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
4230
|
+
}
|
|
3951
4231
|
|
|
3952
4232
|
// rest of the Transaction fields
|
|
3953
4233
|
//
|
|
@@ -6700,8 +6980,15 @@ class Connection {
|
|
|
6700
6980
|
*/
|
|
6701
6981
|
|
|
6702
6982
|
|
|
6703
|
-
async getBlock(slot,
|
|
6704
|
-
const
|
|
6983
|
+
async getBlock(slot, rawConfig) {
|
|
6984
|
+
const {
|
|
6985
|
+
commitment,
|
|
6986
|
+
config
|
|
6987
|
+
} = extractCommitmentFromConfig(rawConfig);
|
|
6988
|
+
|
|
6989
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined
|
|
6990
|
+
/* encoding */
|
|
6991
|
+
, config);
|
|
6705
6992
|
|
|
6706
6993
|
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6707
6994
|
const res = create(unsafeRes, GetBlockRpcResult);
|
|
@@ -6787,8 +7074,15 @@ class Connection {
|
|
|
6787
7074
|
*/
|
|
6788
7075
|
|
|
6789
7076
|
|
|
6790
|
-
async getTransaction(signature,
|
|
6791
|
-
const
|
|
7077
|
+
async getTransaction(signature, rawConfig) {
|
|
7078
|
+
const {
|
|
7079
|
+
commitment,
|
|
7080
|
+
config
|
|
7081
|
+
} = extractCommitmentFromConfig(rawConfig);
|
|
7082
|
+
|
|
7083
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
|
|
7084
|
+
/* encoding */
|
|
7085
|
+
, config);
|
|
6792
7086
|
|
|
6793
7087
|
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6794
7088
|
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
@@ -6810,8 +7104,13 @@ class Connection {
|
|
|
6810
7104
|
*/
|
|
6811
7105
|
|
|
6812
7106
|
|
|
6813
|
-
async getParsedTransaction(signature,
|
|
6814
|
-
const
|
|
7107
|
+
async getParsedTransaction(signature, commitmentOrConfig) {
|
|
7108
|
+
const {
|
|
7109
|
+
commitment,
|
|
7110
|
+
config
|
|
7111
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
7112
|
+
|
|
7113
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed', config);
|
|
6815
7114
|
|
|
6816
7115
|
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6817
7116
|
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
@@ -6827,9 +7126,13 @@ class Connection {
|
|
|
6827
7126
|
*/
|
|
6828
7127
|
|
|
6829
7128
|
|
|
6830
|
-
async getParsedTransactions(signatures,
|
|
7129
|
+
async getParsedTransactions(signatures, commitmentOrConfig) {
|
|
7130
|
+
const {
|
|
7131
|
+
commitment,
|
|
7132
|
+
config
|
|
7133
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6831
7134
|
const batch = signatures.map(signature => {
|
|
6832
|
-
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
7135
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed', config);
|
|
6833
7136
|
|
|
6834
7137
|
return {
|
|
6835
7138
|
methodName: 'getTransaction',
|
|
@@ -6854,9 +7157,15 @@ class Connection {
|
|
|
6854
7157
|
*/
|
|
6855
7158
|
|
|
6856
7159
|
|
|
6857
|
-
async getTransactions(signatures,
|
|
7160
|
+
async getTransactions(signatures, commitmentOrConfig) {
|
|
7161
|
+
const {
|
|
7162
|
+
commitment,
|
|
7163
|
+
config
|
|
7164
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6858
7165
|
const batch = signatures.map(signature => {
|
|
6859
|
-
const args = this._buildArgsAtLeastConfirmed([signature], commitment
|
|
7166
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
|
|
7167
|
+
/* encoding */
|
|
7168
|
+
, config);
|
|
6860
7169
|
|
|
6861
7170
|
return {
|
|
6862
7171
|
methodName: 'getTransaction',
|
|
@@ -7298,6 +7607,28 @@ class Connection {
|
|
|
7298
7607
|
this._pollingBlockhash = false;
|
|
7299
7608
|
}
|
|
7300
7609
|
}
|
|
7610
|
+
/**
|
|
7611
|
+
* get the stake minimum delegation
|
|
7612
|
+
*/
|
|
7613
|
+
|
|
7614
|
+
|
|
7615
|
+
async getStakeMinimumDelegation(config) {
|
|
7616
|
+
const {
|
|
7617
|
+
commitment,
|
|
7618
|
+
config: configArg
|
|
7619
|
+
} = extractCommitmentFromConfig(config);
|
|
7620
|
+
|
|
7621
|
+
const args = this._buildArgs([], commitment, 'base64', configArg);
|
|
7622
|
+
|
|
7623
|
+
const unsafeRes = await this._rpcRequest('getStakeMinimumDelegation', args);
|
|
7624
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(number()));
|
|
7625
|
+
|
|
7626
|
+
if ('error' in res) {
|
|
7627
|
+
throw new SolanaJSONRPCError(res.error, `failed to get stake minimum delegation`);
|
|
7628
|
+
}
|
|
7629
|
+
|
|
7630
|
+
return res.result;
|
|
7631
|
+
}
|
|
7301
7632
|
/**
|
|
7302
7633
|
* Simulate a transaction
|
|
7303
7634
|
*/
|
|
@@ -9935,5 +10266,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9935
10266
|
|
|
9936
10267
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9937
10268
|
|
|
9938
|
-
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 };
|
|
10269
|
+
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 };
|
|
9939
10270
|
//# sourceMappingURL=index.browser.esm.js.map
|