@solana/web3.js 1.50.1 → 1.53.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/README.md +4 -0
- package/lib/index.browser.cjs.js +2903 -2809
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +2903 -2810
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +2903 -2809
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +870 -831
- package/lib/index.esm.js +2903 -2810
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +3631 -3537
- 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 +2905 -2811
- package/lib/index.native.js.map +1 -1
- package/package.json +2 -2
- package/src/account-data.ts +39 -0
- package/src/account.ts +1 -1
- package/src/connection.ts +56 -8
- package/src/fee-calculator.ts +2 -0
- package/src/index.ts +3 -14
- package/src/loader.ts +4 -5
- package/src/message/index.ts +32 -0
- package/src/{message.ts → message/legacy.ts} +7 -37
- package/src/nonce-account.ts +1 -1
- package/src/{address-lookup-table-program.ts → programs/address-lookup-table/index.ts} +8 -6
- package/src/programs/address-lookup-table/state.ts +84 -0
- package/src/{compute-budget.ts → programs/compute-budget.ts} +4 -4
- package/src/{ed25519-program.ts → programs/ed25519.ts} +4 -4
- package/src/programs/index.ts +7 -0
- package/src/{secp256k1-program.ts → programs/secp256k1.ts} +4 -4
- package/src/{stake-program.ts → programs/stake.ts} +7 -7
- package/src/{system-program.ts → programs/system.ts} +8 -8
- package/src/{vote-program.ts → programs/vote.ts} +7 -7
- package/src/publickey.ts +2 -2
- package/src/{transaction-constants.ts → transaction/constants.ts} +0 -0
- package/src/{util/tx-expiry-custom-errors.ts → transaction/expiry-custom-errors.ts} +0 -0
- package/src/transaction/index.ts +3 -0
- package/src/{transaction.ts → transaction/legacy.ts} +10 -13
- package/src/{util → utils}/__forks__/react-native/url-impl.ts +0 -0
- package/src/{util → utils}/assert.ts +0 -0
- package/src/{util → utils}/bigint.ts +0 -0
- package/src/{util → utils}/borsh-schema.ts +0 -0
- package/src/{util → utils}/cluster.ts +0 -0
- package/src/utils/index.ts +4 -0
- package/src/{util → utils}/makeWebsocketUrl.ts +0 -0
- package/src/{util → utils}/promise-timeout.ts +0 -0
- package/src/{util → utils}/send-and-confirm-raw-transaction.ts +0 -0
- package/src/{util → utils}/send-and-confirm-transaction.ts +0 -0
- package/src/{util → utils}/shortvec-encoding.ts +0 -0
- package/src/{util → utils}/sleep.ts +0 -0
- package/src/{util → utils}/to-buffer.ts +0 -0
- package/src/{util → utils}/url-impl.ts +0 -0
- package/src/validator-info.ts +1 -1
- package/src/vote-account.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/web3.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.53.0",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"rpc-websockets": "^7.5.0",
|
|
74
74
|
"secp256k1": "^4.0.2",
|
|
75
75
|
"superstruct": "^0.14.2",
|
|
76
|
-
"tweetnacl": "^1.0.
|
|
76
|
+
"tweetnacl": "^1.0.3"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@babel/core": "^7.12.13",
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as BufferLayout from '@solana/buffer-layout';
|
|
2
|
+
|
|
3
|
+
export interface IAccountStateData {
|
|
4
|
+
readonly typeIndex: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export type AccountType<TInputData extends IAccountStateData> = {
|
|
11
|
+
/** The account type index (from solana upstream program) */
|
|
12
|
+
index: number;
|
|
13
|
+
/** The BufferLayout to use to build data */
|
|
14
|
+
layout: BufferLayout.Layout<TInputData>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Decode account data buffer using an AccountType
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export function decodeData<TAccountStateData extends IAccountStateData>(
|
|
22
|
+
type: AccountType<TAccountStateData>,
|
|
23
|
+
data: Uint8Array,
|
|
24
|
+
): TAccountStateData {
|
|
25
|
+
let decoded: TAccountStateData;
|
|
26
|
+
try {
|
|
27
|
+
decoded = type.layout.decode(data);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
throw new Error('invalid instruction; ' + err);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (decoded.typeIndex !== type.index) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`invalid account data; account type mismatch ${decoded.typeIndex} != ${type.index}`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return decoded;
|
|
39
|
+
}
|
package/src/account.ts
CHANGED
package/src/connection.ts
CHANGED
|
@@ -24,7 +24,6 @@ import type {Struct} from 'superstruct';
|
|
|
24
24
|
import {Client as RpcWebSocketClient} from 'rpc-websockets';
|
|
25
25
|
import RpcClient from 'jayson/lib/client/browser';
|
|
26
26
|
|
|
27
|
-
import {URL} from './util/url-impl';
|
|
28
27
|
import {AgentManager} from './agent-manager';
|
|
29
28
|
import {EpochSchedule} from './epoch-schedule';
|
|
30
29
|
import {SendTransactionError, SolanaJSONRPCError} from './errors';
|
|
@@ -35,14 +34,16 @@ import {Signer} from './keypair';
|
|
|
35
34
|
import {MS_PER_SLOT} from './timing';
|
|
36
35
|
import {Transaction, TransactionStatus} from './transaction';
|
|
37
36
|
import {Message} from './message';
|
|
38
|
-
import
|
|
39
|
-
import
|
|
40
|
-
import {
|
|
37
|
+
import {AddressLookupTableAccount} from './programs/address-lookup-table/state';
|
|
38
|
+
import assert from './utils/assert';
|
|
39
|
+
import {sleep} from './utils/sleep';
|
|
40
|
+
import {toBuffer} from './utils/to-buffer';
|
|
41
41
|
import {
|
|
42
42
|
TransactionExpiredBlockheightExceededError,
|
|
43
43
|
TransactionExpiredTimeoutError,
|
|
44
|
-
} from './
|
|
45
|
-
import {makeWebsocketUrl} from './
|
|
44
|
+
} from './transaction/expiry-custom-errors';
|
|
45
|
+
import {makeWebsocketUrl} from './utils/makeWebsocketUrl';
|
|
46
|
+
import {URL} from './utils/url-impl';
|
|
46
47
|
import type {Blockhash} from './blockhash';
|
|
47
48
|
import type {FeeCalculator} from './fee-calculator';
|
|
48
49
|
import type {TransactionSignature} from './transaction';
|
|
@@ -804,6 +805,14 @@ export type TokenBalance = {
|
|
|
804
805
|
*/
|
|
805
806
|
export type ParsedConfirmedTransactionMeta = ParsedTransactionMeta;
|
|
806
807
|
|
|
808
|
+
/**
|
|
809
|
+
* Collection of addresses loaded by a transaction using address table lookups
|
|
810
|
+
*/
|
|
811
|
+
export type LoadedAddresses = {
|
|
812
|
+
writable: Array<PublicKey>;
|
|
813
|
+
readonly: Array<PublicKey>;
|
|
814
|
+
};
|
|
815
|
+
|
|
807
816
|
/**
|
|
808
817
|
* Metadata for a parsed transaction on the ledger
|
|
809
818
|
*/
|
|
@@ -824,6 +833,8 @@ export type ParsedTransactionMeta = {
|
|
|
824
833
|
postTokenBalances?: Array<TokenBalance> | null;
|
|
825
834
|
/** The error result of transaction processing */
|
|
826
835
|
err: TransactionError | null;
|
|
836
|
+
/** The collection of addresses loaded using address lookup tables */
|
|
837
|
+
loadedAddresses?: LoadedAddresses;
|
|
827
838
|
};
|
|
828
839
|
|
|
829
840
|
export type CompiledInnerInstruction = {
|
|
@@ -874,6 +885,8 @@ export type TransactionResponse = {
|
|
|
874
885
|
|
|
875
886
|
/**
|
|
876
887
|
* A confirmed transaction on the ledger
|
|
888
|
+
*
|
|
889
|
+
* @deprecated Deprecated since Solana v1.8.0.
|
|
877
890
|
*/
|
|
878
891
|
export type ConfirmedTransaction = {
|
|
879
892
|
/** The slot during which the transaction was processed */
|
|
@@ -1003,7 +1016,9 @@ export type BlockResponse = {
|
|
|
1003
1016
|
};
|
|
1004
1017
|
|
|
1005
1018
|
/**
|
|
1006
|
-
* A
|
|
1019
|
+
* A confirmed block on the ledger
|
|
1020
|
+
*
|
|
1021
|
+
* @deprecated Deprecated since Solana v1.8.0.
|
|
1007
1022
|
*/
|
|
1008
1023
|
export type ConfirmedBlock = {
|
|
1009
1024
|
/** Blockhash of this block */
|
|
@@ -1794,6 +1809,11 @@ const TokenBalanceResult = pick({
|
|
|
1794
1809
|
uiTokenAmount: TokenAmountResult,
|
|
1795
1810
|
});
|
|
1796
1811
|
|
|
1812
|
+
const LoadedAddressesResult = pick({
|
|
1813
|
+
writable: array(PublicKeyFromString),
|
|
1814
|
+
readonly: array(PublicKeyFromString),
|
|
1815
|
+
});
|
|
1816
|
+
|
|
1797
1817
|
/**
|
|
1798
1818
|
* @internal
|
|
1799
1819
|
*/
|
|
@@ -1821,6 +1841,7 @@ const ConfirmedTransactionMetaResult = pick({
|
|
|
1821
1841
|
logMessages: optional(nullable(array(string()))),
|
|
1822
1842
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
1823
1843
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
1844
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
1824
1845
|
});
|
|
1825
1846
|
|
|
1826
1847
|
/**
|
|
@@ -1844,6 +1865,7 @@ const ParsedConfirmedTransactionMetaResult = pick({
|
|
|
1844
1865
|
logMessages: optional(nullable(array(string()))),
|
|
1845
1866
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
1846
1867
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
1868
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
1847
1869
|
});
|
|
1848
1870
|
|
|
1849
1871
|
/**
|
|
@@ -2850,14 +2872,17 @@ export class Connection {
|
|
|
2850
2872
|
*/
|
|
2851
2873
|
async getParsedAccountInfo(
|
|
2852
2874
|
publicKey: PublicKey,
|
|
2853
|
-
|
|
2875
|
+
commitmentOrConfig?: Commitment | GetAccountInfoConfig,
|
|
2854
2876
|
): Promise<
|
|
2855
2877
|
RpcResponseAndContext<AccountInfo<Buffer | ParsedAccountData> | null>
|
|
2856
2878
|
> {
|
|
2879
|
+
const {commitment, config} =
|
|
2880
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
2857
2881
|
const args = this._buildArgs(
|
|
2858
2882
|
[publicKey.toBase58()],
|
|
2859
2883
|
commitment,
|
|
2860
2884
|
'jsonParsed',
|
|
2885
|
+
config,
|
|
2861
2886
|
);
|
|
2862
2887
|
const unsafeRes = await this._rpcRequest('getAccountInfo', args);
|
|
2863
2888
|
const res = create(
|
|
@@ -4194,6 +4219,29 @@ export class Connection {
|
|
|
4194
4219
|
return res.result;
|
|
4195
4220
|
}
|
|
4196
4221
|
|
|
4222
|
+
async getAddressLookupTable(
|
|
4223
|
+
accountKey: PublicKey,
|
|
4224
|
+
config?: GetAccountInfoConfig,
|
|
4225
|
+
): Promise<RpcResponseAndContext<AddressLookupTableAccount | null>> {
|
|
4226
|
+
const {context, value: accountInfo} = await this.getAccountInfoAndContext(
|
|
4227
|
+
accountKey,
|
|
4228
|
+
config,
|
|
4229
|
+
);
|
|
4230
|
+
|
|
4231
|
+
let value = null;
|
|
4232
|
+
if (accountInfo !== null) {
|
|
4233
|
+
value = new AddressLookupTableAccount({
|
|
4234
|
+
key: accountKey,
|
|
4235
|
+
state: AddressLookupTableAccount.deserialize(accountInfo.data),
|
|
4236
|
+
});
|
|
4237
|
+
}
|
|
4238
|
+
|
|
4239
|
+
return {
|
|
4240
|
+
context,
|
|
4241
|
+
value,
|
|
4242
|
+
};
|
|
4243
|
+
}
|
|
4244
|
+
|
|
4197
4245
|
/**
|
|
4198
4246
|
* Fetch the contents of a Nonce account from the cluster, return with context
|
|
4199
4247
|
*/
|
package/src/fee-calculator.ts
CHANGED
|
@@ -9,6 +9,8 @@ export const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Calculator for transaction fees.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated Deprecated since Solana v1.8.0.
|
|
12
14
|
*/
|
|
13
15
|
export interface FeeCalculator {
|
|
14
16
|
/** Cost in lamports to validate a signature. */
|
package/src/index.ts
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
export * from './account';
|
|
2
|
-
export * from './address-lookup-table-program';
|
|
3
2
|
export * from './blockhash';
|
|
4
3
|
export * from './bpf-loader-deprecated';
|
|
5
4
|
export * from './bpf-loader';
|
|
6
|
-
export * from './compute-budget';
|
|
7
5
|
export * from './connection';
|
|
8
6
|
export * from './epoch-schedule';
|
|
9
|
-
export * from './
|
|
7
|
+
export * from './errors';
|
|
10
8
|
export * from './fee-calculator';
|
|
11
9
|
export * from './keypair';
|
|
12
10
|
export * from './loader';
|
|
13
11
|
export * from './message';
|
|
14
12
|
export * from './nonce-account';
|
|
13
|
+
export * from './programs';
|
|
15
14
|
export * from './publickey';
|
|
16
|
-
export * from './stake-program';
|
|
17
|
-
export * from './system-program';
|
|
18
|
-
export * from './secp256k1-program';
|
|
19
15
|
export * from './transaction';
|
|
20
|
-
export * from './transaction-constants';
|
|
21
16
|
export * from './validator-info';
|
|
22
17
|
export * from './vote-account';
|
|
23
|
-
export * from './vote-program';
|
|
24
18
|
export * from './sysvar';
|
|
25
|
-
export * from './
|
|
26
|
-
export * from './util/borsh-schema';
|
|
27
|
-
export * from './util/send-and-confirm-transaction';
|
|
28
|
-
export * from './util/send-and-confirm-raw-transaction';
|
|
29
|
-
export * from './util/tx-expiry-custom-errors';
|
|
30
|
-
export * from './util/cluster';
|
|
19
|
+
export * from './utils';
|
|
31
20
|
|
|
32
21
|
/**
|
|
33
22
|
* There are 1-billion lamports in one SOL
|
package/src/loader.ts
CHANGED
|
@@ -2,15 +2,14 @@ import {Buffer} from 'buffer';
|
|
|
2
2
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
3
3
|
|
|
4
4
|
import {PublicKey} from './publickey';
|
|
5
|
-
import {Transaction} from './transaction';
|
|
5
|
+
import {Transaction, PACKET_DATA_SIZE} from './transaction';
|
|
6
6
|
import {SYSVAR_RENT_PUBKEY} from './sysvar';
|
|
7
|
-
import {sendAndConfirmTransaction} from './
|
|
8
|
-
import {sleep} from './
|
|
7
|
+
import {sendAndConfirmTransaction} from './utils/send-and-confirm-transaction';
|
|
8
|
+
import {sleep} from './utils/sleep';
|
|
9
9
|
import type {Connection} from './connection';
|
|
10
10
|
import type {Signer} from './keypair';
|
|
11
|
-
import {SystemProgram} from './system
|
|
11
|
+
import {SystemProgram} from './programs/system';
|
|
12
12
|
import {IInstructionInputData} from './instruction';
|
|
13
|
-
import {PACKET_DATA_SIZE} from './transaction-constants';
|
|
14
13
|
|
|
15
14
|
// Keep program chunks under PACKET_DATA_SIZE, leaving enough room for the
|
|
16
15
|
// rest of the Transaction fields
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export * from './legacy';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The message header, identifying signed and read-only account
|
|
5
|
+
*/
|
|
6
|
+
export type MessageHeader = {
|
|
7
|
+
/**
|
|
8
|
+
* The number of signatures required for this message to be considered valid. The
|
|
9
|
+
* signatures must match the first `numRequiredSignatures` of `accountKeys`.
|
|
10
|
+
*/
|
|
11
|
+
numRequiredSignatures: number;
|
|
12
|
+
/** The last `numReadonlySignedAccounts` of the signed keys are read-only accounts */
|
|
13
|
+
numReadonlySignedAccounts: number;
|
|
14
|
+
/** The last `numReadonlySignedAccounts` of the unsigned keys are read-only accounts */
|
|
15
|
+
numReadonlyUnsignedAccounts: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* An instruction to execute by a program
|
|
20
|
+
*
|
|
21
|
+
* @property {number} programIdIndex
|
|
22
|
+
* @property {number[]} accounts
|
|
23
|
+
* @property {string} data
|
|
24
|
+
*/
|
|
25
|
+
export type CompiledInstruction = {
|
|
26
|
+
/** Index into the transaction keys array indicating the program account that executes this instruction */
|
|
27
|
+
programIdIndex: number;
|
|
28
|
+
/** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
|
|
29
|
+
accounts: number[];
|
|
30
|
+
/** The program input data encoded as base 58 */
|
|
31
|
+
data: string;
|
|
32
|
+
};
|
|
@@ -2,43 +2,13 @@ import bs58 from 'bs58';
|
|
|
2
2
|
import {Buffer} from 'buffer';
|
|
3
3
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
4
4
|
|
|
5
|
-
import {PublicKey} from '
|
|
6
|
-
import type {Blockhash} from '
|
|
7
|
-
import * as Layout from '
|
|
8
|
-
import {PACKET_DATA_SIZE} from '
|
|
9
|
-
import * as shortvec from '
|
|
10
|
-
import {toBuffer} from '
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The message header, identifying signed and read-only account
|
|
14
|
-
*/
|
|
15
|
-
export type MessageHeader = {
|
|
16
|
-
/**
|
|
17
|
-
* The number of signatures required for this message to be considered valid. The
|
|
18
|
-
* signatures must match the first `numRequiredSignatures` of `accountKeys`.
|
|
19
|
-
*/
|
|
20
|
-
numRequiredSignatures: number;
|
|
21
|
-
/** The last `numReadonlySignedAccounts` of the signed keys are read-only accounts */
|
|
22
|
-
numReadonlySignedAccounts: number;
|
|
23
|
-
/** The last `numReadonlySignedAccounts` of the unsigned keys are read-only accounts */
|
|
24
|
-
numReadonlyUnsignedAccounts: number;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* An instruction to execute by a program
|
|
29
|
-
*
|
|
30
|
-
* @property {number} programIdIndex
|
|
31
|
-
* @property {number[]} accounts
|
|
32
|
-
* @property {string} data
|
|
33
|
-
*/
|
|
34
|
-
export type CompiledInstruction = {
|
|
35
|
-
/** Index into the transaction keys array indicating the program account that executes this instruction */
|
|
36
|
-
programIdIndex: number;
|
|
37
|
-
/** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
|
|
38
|
-
accounts: number[];
|
|
39
|
-
/** The program input data encoded as base 58 */
|
|
40
|
-
data: string;
|
|
41
|
-
};
|
|
5
|
+
import {PublicKey} from '../publickey';
|
|
6
|
+
import type {Blockhash} from '../blockhash';
|
|
7
|
+
import * as Layout from '../layout';
|
|
8
|
+
import {PACKET_DATA_SIZE} from '../transaction/constants';
|
|
9
|
+
import * as shortvec from '../utils/shortvec-encoding';
|
|
10
|
+
import {toBuffer} from '../utils/to-buffer';
|
|
11
|
+
import {CompiledInstruction, MessageHeader} from './index';
|
|
42
12
|
|
|
43
13
|
/**
|
|
44
14
|
* Message constructor arguments
|
package/src/nonce-account.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as Layout from './layout';
|
|
|
6
6
|
import {PublicKey} from './publickey';
|
|
7
7
|
import type {FeeCalculator} from './fee-calculator';
|
|
8
8
|
import {FeeCalculatorLayout} from './fee-calculator';
|
|
9
|
-
import {toBuffer} from './
|
|
9
|
+
import {toBuffer} from './utils/to-buffer';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {toBufferLE} from 'bigint-buffer';
|
|
2
2
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
3
3
|
|
|
4
|
-
import * as Layout from '
|
|
5
|
-
import {PublicKey} from '
|
|
6
|
-
import * as bigintLayout from '
|
|
7
|
-
import {SystemProgram} from '
|
|
8
|
-
import {TransactionInstruction} from '
|
|
9
|
-
import {decodeData, encodeData, IInstructionInputData} from '
|
|
4
|
+
import * as Layout from '../../layout';
|
|
5
|
+
import {PublicKey} from '../../publickey';
|
|
6
|
+
import * as bigintLayout from '../../utils/bigint';
|
|
7
|
+
import {SystemProgram} from '../system';
|
|
8
|
+
import {TransactionInstruction} from '../../transaction';
|
|
9
|
+
import {decodeData, encodeData, IInstructionInputData} from '../../instruction';
|
|
10
|
+
|
|
11
|
+
export * from './state';
|
|
10
12
|
|
|
11
13
|
export type CreateLookupTableParams = {
|
|
12
14
|
/** Account used to derive and control the new address lookup table. */
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as BufferLayout from '@solana/buffer-layout';
|
|
2
|
+
|
|
3
|
+
import assert from '../../utils/assert';
|
|
4
|
+
import * as Layout from '../../layout';
|
|
5
|
+
import {PublicKey} from '../../publickey';
|
|
6
|
+
import {u64} from '../../utils/bigint';
|
|
7
|
+
import {decodeData} from '../../account-data';
|
|
8
|
+
|
|
9
|
+
export type AddressLookupTableState = {
|
|
10
|
+
deactivationSlot: bigint;
|
|
11
|
+
lastExtendedSlot: number;
|
|
12
|
+
lastExtendedSlotStartIndex: number;
|
|
13
|
+
authority?: PublicKey;
|
|
14
|
+
addresses: Array<PublicKey>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type AddressLookupTableAccountArgs = {
|
|
18
|
+
key: PublicKey;
|
|
19
|
+
state: AddressLookupTableState;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/// The serialized size of lookup table metadata
|
|
23
|
+
const LOOKUP_TABLE_META_SIZE = 56;
|
|
24
|
+
|
|
25
|
+
export class AddressLookupTableAccount {
|
|
26
|
+
key: PublicKey;
|
|
27
|
+
state: AddressLookupTableState;
|
|
28
|
+
|
|
29
|
+
constructor(args: AddressLookupTableAccountArgs) {
|
|
30
|
+
this.key = args.key;
|
|
31
|
+
this.state = args.state;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
isActive(): boolean {
|
|
35
|
+
const U64_MAX = 2n ** 64n - 1n;
|
|
36
|
+
return this.state.deactivationSlot === U64_MAX;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static deserialize(accountData: Uint8Array): AddressLookupTableState {
|
|
40
|
+
const meta = decodeData(LookupTableMetaLayout, accountData);
|
|
41
|
+
|
|
42
|
+
const serializedAddressesLen = accountData.length - LOOKUP_TABLE_META_SIZE;
|
|
43
|
+
assert(serializedAddressesLen >= 0, 'lookup table is invalid');
|
|
44
|
+
assert(serializedAddressesLen % 32 === 0, 'lookup table is invalid');
|
|
45
|
+
|
|
46
|
+
const numSerializedAddresses = serializedAddressesLen / 32;
|
|
47
|
+
const {addresses} = BufferLayout.struct<{addresses: Array<Uint8Array>}>([
|
|
48
|
+
BufferLayout.seq(Layout.publicKey(), numSerializedAddresses, 'addresses'),
|
|
49
|
+
]).decode(accountData.slice(LOOKUP_TABLE_META_SIZE));
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
deactivationSlot: meta.deactivationSlot,
|
|
53
|
+
lastExtendedSlot: meta.lastExtendedSlot,
|
|
54
|
+
lastExtendedSlotStartIndex: meta.lastExtendedStartIndex,
|
|
55
|
+
authority:
|
|
56
|
+
meta.authority.length !== 0
|
|
57
|
+
? new PublicKey(meta.authority[0])
|
|
58
|
+
: undefined,
|
|
59
|
+
addresses: addresses.map(address => new PublicKey(address)),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const LookupTableMetaLayout = {
|
|
65
|
+
index: 1,
|
|
66
|
+
layout: BufferLayout.struct<{
|
|
67
|
+
typeIndex: number;
|
|
68
|
+
deactivationSlot: bigint;
|
|
69
|
+
lastExtendedSlot: number;
|
|
70
|
+
lastExtendedStartIndex: number;
|
|
71
|
+
authority: Array<Uint8Array>;
|
|
72
|
+
}>([
|
|
73
|
+
BufferLayout.u32('typeIndex'),
|
|
74
|
+
u64('deactivationSlot'),
|
|
75
|
+
BufferLayout.nu64('lastExtendedSlot'),
|
|
76
|
+
BufferLayout.u8('lastExtendedStartIndex'),
|
|
77
|
+
BufferLayout.u8(), // option
|
|
78
|
+
BufferLayout.seq(
|
|
79
|
+
Layout.publicKey(),
|
|
80
|
+
BufferLayout.offset(BufferLayout.u8(), -1),
|
|
81
|
+
'authority',
|
|
82
|
+
),
|
|
83
|
+
]),
|
|
84
|
+
};
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
decodeData,
|
|
6
6
|
InstructionType,
|
|
7
7
|
IInstructionInputData,
|
|
8
|
-
} from '
|
|
9
|
-
import {PublicKey} from '
|
|
10
|
-
import {TransactionInstruction} from '
|
|
11
|
-
import {u64} from '
|
|
8
|
+
} from '../instruction';
|
|
9
|
+
import {PublicKey} from '../publickey';
|
|
10
|
+
import {TransactionInstruction} from '../transaction';
|
|
11
|
+
import {u64} from '../utils/bigint';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Compute Budget Instruction class
|
|
@@ -2,10 +2,10 @@ import {Buffer} from 'buffer';
|
|
|
2
2
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
3
3
|
import nacl from 'tweetnacl';
|
|
4
4
|
|
|
5
|
-
import {Keypair} from '
|
|
6
|
-
import {PublicKey} from '
|
|
7
|
-
import {TransactionInstruction} from '
|
|
8
|
-
import assert from '
|
|
5
|
+
import {Keypair} from '../keypair';
|
|
6
|
+
import {PublicKey} from '../publickey';
|
|
7
|
+
import {TransactionInstruction} from '../transaction';
|
|
8
|
+
import assert from '../utils/assert';
|
|
9
9
|
|
|
10
10
|
const PRIVATE_KEY_BYTES = 64;
|
|
11
11
|
const PUBLIC_KEY_BYTES = 32;
|
|
@@ -3,10 +3,10 @@ import * as BufferLayout from '@solana/buffer-layout';
|
|
|
3
3
|
import secp256k1 from 'secp256k1';
|
|
4
4
|
import sha3 from 'js-sha3';
|
|
5
5
|
|
|
6
|
-
import {PublicKey} from '
|
|
7
|
-
import {TransactionInstruction} from '
|
|
8
|
-
import assert from '
|
|
9
|
-
import {toBuffer} from '
|
|
6
|
+
import {PublicKey} from '../publickey';
|
|
7
|
+
import {TransactionInstruction} from '../transaction';
|
|
8
|
+
import assert from '../utils/assert';
|
|
9
|
+
import {toBuffer} from '../utils/to-buffer';
|
|
10
10
|
|
|
11
11
|
const {publicKeyCreate, ecdsaSign} = secp256k1;
|
|
12
12
|
|
|
@@ -5,17 +5,17 @@ import {
|
|
|
5
5
|
decodeData,
|
|
6
6
|
InstructionType,
|
|
7
7
|
IInstructionInputData,
|
|
8
|
-
} from '
|
|
9
|
-
import * as Layout from '
|
|
10
|
-
import {PublicKey} from '
|
|
11
|
-
import {SystemProgram} from './system
|
|
8
|
+
} from '../instruction';
|
|
9
|
+
import * as Layout from '../layout';
|
|
10
|
+
import {PublicKey} from '../publickey';
|
|
11
|
+
import {SystemProgram} from './system';
|
|
12
12
|
import {
|
|
13
13
|
SYSVAR_CLOCK_PUBKEY,
|
|
14
14
|
SYSVAR_RENT_PUBKEY,
|
|
15
15
|
SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
16
|
-
} from '
|
|
17
|
-
import {Transaction, TransactionInstruction} from '
|
|
18
|
-
import {toBuffer} from '
|
|
16
|
+
} from '../sysvar';
|
|
17
|
+
import {Transaction, TransactionInstruction} from '../transaction';
|
|
18
|
+
import {toBuffer} from '../utils/to-buffer';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Address of the stake config account which configures the rate
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
decodeData,
|
|
6
6
|
InstructionType,
|
|
7
7
|
IInstructionInputData,
|
|
8
|
-
} from '
|
|
9
|
-
import * as Layout from '
|
|
10
|
-
import {NONCE_ACCOUNT_LENGTH} from '
|
|
11
|
-
import {PublicKey} from '
|
|
12
|
-
import {SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY} from '
|
|
13
|
-
import {Transaction, TransactionInstruction} from '
|
|
14
|
-
import {toBuffer} from '
|
|
15
|
-
import {u64} from '
|
|
8
|
+
} from '../instruction';
|
|
9
|
+
import * as Layout from '../layout';
|
|
10
|
+
import {NONCE_ACCOUNT_LENGTH} from '../nonce-account';
|
|
11
|
+
import {PublicKey} from '../publickey';
|
|
12
|
+
import {SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY} from '../sysvar';
|
|
13
|
+
import {Transaction, TransactionInstruction} from '../transaction';
|
|
14
|
+
import {toBuffer} from '../utils/to-buffer';
|
|
15
|
+
import {u64} from '../utils/bigint';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Create account system transaction params
|
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
decodeData,
|
|
6
6
|
InstructionType,
|
|
7
7
|
IInstructionInputData,
|
|
8
|
-
} from '
|
|
9
|
-
import * as Layout from '
|
|
10
|
-
import {PublicKey} from '
|
|
11
|
-
import {SystemProgram} from './system
|
|
12
|
-
import {SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY} from '
|
|
13
|
-
import {Transaction, TransactionInstruction} from '
|
|
14
|
-
import {toBuffer} from '
|
|
8
|
+
} from '../instruction';
|
|
9
|
+
import * as Layout from '../layout';
|
|
10
|
+
import {PublicKey} from '../publickey';
|
|
11
|
+
import {SystemProgram} from './system';
|
|
12
|
+
import {SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY} from '../sysvar';
|
|
13
|
+
import {Transaction, TransactionInstruction} from '../transaction';
|
|
14
|
+
import {toBuffer} from '../utils/to-buffer';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Vote account info
|
package/src/publickey.ts
CHANGED
|
@@ -4,8 +4,8 @@ import {Buffer} from 'buffer';
|
|
|
4
4
|
import nacl from 'tweetnacl';
|
|
5
5
|
import {sha256} from '@ethersproject/sha2';
|
|
6
6
|
|
|
7
|
-
import {Struct, SOLANA_SCHEMA} from './
|
|
8
|
-
import {toBuffer} from './
|
|
7
|
+
import {Struct, SOLANA_SCHEMA} from './utils/borsh-schema';
|
|
8
|
+
import {toBuffer} from './utils/to-buffer';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Maximum length of derived pubkey seed
|
|
File without changes
|
|
File without changes
|