@lightprotocol/stateless.js 0.22.0 → 0.22.1-alpha.1

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.
Files changed (71) hide show
  1. package/README.md +10 -10
  2. package/dist/cjs/browser/constants.d.ts +24 -7
  3. package/dist/cjs/browser/index.cjs +1 -1
  4. package/dist/cjs/browser/index.cjs.map +1 -1
  5. package/dist/cjs/browser/rpc-interface.d.ts +275 -275
  6. package/dist/cjs/browser/rpc.d.ts +5 -1
  7. package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +4 -0
  8. package/dist/cjs/browser/utils/address.d.ts +7 -6
  9. package/dist/cjs/browser/utils/conversion.d.ts +1 -0
  10. package/dist/cjs/browser/utils/index.d.ts +1 -0
  11. package/dist/cjs/browser/utils/instruction.d.ts +35 -0
  12. package/dist/cjs/node/constants.d.ts +24 -7
  13. package/dist/cjs/node/index.cjs +1 -1
  14. package/dist/cjs/node/index.cjs.map +1 -1
  15. package/dist/cjs/node/rpc-interface.d.ts +275 -275
  16. package/dist/cjs/node/rpc.d.ts +5 -1
  17. package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +4 -0
  18. package/dist/cjs/node/utils/address.d.ts +7 -6
  19. package/dist/cjs/node/utils/conversion.d.ts +1 -0
  20. package/dist/cjs/node/utils/index.d.ts +1 -0
  21. package/dist/cjs/node/utils/instruction.d.ts +35 -0
  22. package/dist/es/browser/actions/compress.d.ts +18 -0
  23. package/dist/es/browser/actions/create-account.d.ts +38 -0
  24. package/dist/es/browser/actions/decompress.d.ts +15 -0
  25. package/dist/es/browser/actions/index.d.ts +5 -0
  26. package/dist/es/browser/actions/transfer.d.ts +16 -0
  27. package/dist/es/browser/constants.d.ts +157 -0
  28. package/dist/es/browser/errors.d.ts +74 -0
  29. package/dist/es/browser/index.d.ts +9 -0
  30. package/dist/es/browser/index.js +2 -0
  31. package/dist/es/browser/index.js.map +1 -0
  32. package/dist/es/browser/programs/index.d.ts +1 -0
  33. package/dist/es/browser/programs/system/idl.d.ts +997 -0
  34. package/dist/es/browser/programs/system/index.d.ts +5 -0
  35. package/dist/es/browser/programs/system/layout.d.ts +77 -0
  36. package/dist/es/browser/programs/system/pack.d.ts +74 -0
  37. package/dist/es/browser/programs/system/program.d.ts +175 -0
  38. package/dist/es/browser/programs/system/select-compressed-accounts.d.ts +10 -0
  39. package/dist/es/browser/rpc-interface.d.ts +2779 -0
  40. package/dist/es/browser/rpc.d.ts +284 -0
  41. package/dist/es/browser/state/BN254.d.ts +13 -0
  42. package/dist/es/browser/state/bn.d.ts +3 -0
  43. package/dist/es/browser/state/compressed-account.d.ts +205 -0
  44. package/dist/es/browser/state/index.d.ts +4 -0
  45. package/dist/es/browser/state/types.d.ts +449 -0
  46. package/dist/es/browser/test-helpers/index.d.ts +3 -0
  47. package/dist/es/browser/test-helpers/merkle-tree/index.d.ts +2 -0
  48. package/dist/es/browser/test-helpers/merkle-tree/indexed-array.d.ts +85 -0
  49. package/dist/es/browser/test-helpers/merkle-tree/merkle-tree.d.ts +92 -0
  50. package/dist/es/browser/test-helpers/test-rpc/get-compressed-accounts.d.ts +7 -0
  51. package/dist/es/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +40 -0
  52. package/dist/es/browser/test-helpers/test-rpc/get-parsed-events.d.ts +15 -0
  53. package/dist/es/browser/test-helpers/test-rpc/index.d.ts +3 -0
  54. package/dist/es/browser/test-helpers/test-rpc/test-rpc.d.ts +239 -0
  55. package/dist/es/browser/test-helpers/test-utils.d.ts +31 -0
  56. package/dist/es/browser/utils/address.d.ts +64 -0
  57. package/dist/es/browser/utils/airdrop.d.ts +7 -0
  58. package/dist/es/browser/utils/calculate-compute-unit-price.d.ts +7 -0
  59. package/dist/es/browser/utils/conversion.d.ts +36 -0
  60. package/dist/es/browser/utils/dedupe-signer.d.ts +3 -0
  61. package/dist/es/browser/utils/get-state-tree-infos.d.ts +48 -0
  62. package/dist/es/browser/utils/index.d.ts +13 -0
  63. package/dist/es/browser/utils/instruction.d.ts +35 -0
  64. package/dist/es/browser/utils/parse-validity-proof.d.ts +20 -0
  65. package/dist/es/browser/utils/pipe.d.ts +2 -0
  66. package/dist/es/browser/utils/send-and-confirm.d.ts +52 -0
  67. package/dist/es/browser/utils/sleep.d.ts +1 -0
  68. package/dist/es/browser/utils/state-tree-lookup-table.d.ts +68 -0
  69. package/dist/es/browser/utils/validation.d.ts +8 -0
  70. package/dist/types/index.d.ts +78 -16
  71. package/package.json +16 -8
@@ -0,0 +1,5 @@
1
+ export { LightSystemProgram as LightSystemProgramIDL, IDL } from './idl';
2
+ export * from './layout';
3
+ export * from './pack';
4
+ export * from './program';
5
+ export * from './select-compressed-accounts';
@@ -0,0 +1,77 @@
1
+ import { Buffer } from 'buffer';
2
+ import { PublicKey, AccountMeta } from '@solana/web3.js';
3
+ import { Layout } from '@coral-xyz/borsh';
4
+ import { InstructionDataInvoke, InstructionDataInvokeCpi, PublicTransactionEvent } from '../../state';
5
+ export declare const CompressedAccountLayout: import("buffer-layout").Layout<unknown>;
6
+ export declare const MerkleContextLayout: import("buffer-layout").Layout<unknown>;
7
+ export declare const NewAddressParamsLayout: import("buffer-layout").Layout<unknown>;
8
+ export declare const InstructionDataInvokeLayout: Layout<InstructionDataInvoke>;
9
+ export declare function encodeInstructionDataInvoke(data: InstructionDataInvoke): Buffer;
10
+ export declare const InstructionDataInvokeCpiLayout: Layout<InstructionDataInvokeCpi>;
11
+ export declare const CompressedProofLayout: import("buffer-layout").Layout<unknown>;
12
+ export declare const CompressedCpiContextLayout: import("buffer-layout").Layout<unknown>;
13
+ export declare const NewAddressParamsAssignedPackedLayout: import("buffer-layout").Layout<unknown>;
14
+ export declare const PackedMerkleContextLayout: import("buffer-layout").Layout<unknown>;
15
+ export declare const InAccountLayout: import("buffer-layout").Layout<unknown>;
16
+ export declare const PackedReadOnlyAddressLayout: import("buffer-layout").Layout<unknown>;
17
+ export declare const PackedReadOnlyCompressedAccountLayout: import("buffer-layout").Layout<unknown>;
18
+ export declare const InstructionDataInvokeCpiWithReadOnlyLayout: import("buffer-layout").Layout<unknown>;
19
+ export declare function decodeInstructionDataInvokeCpiWithReadOnly(buffer: Buffer): unknown;
20
+ export declare function decodeInstructionDataInvoke(buffer: Buffer): InstructionDataInvoke;
21
+ export declare function decodeInstructionDataInvokeCpi(buffer: Buffer): InstructionDataInvokeCpi;
22
+ export type invokeAccountsLayoutParams = {
23
+ /**
24
+ * Fee payer.
25
+ */
26
+ feePayer: PublicKey;
27
+ /**
28
+ * Authority.
29
+ */
30
+ authority: PublicKey;
31
+ /**
32
+ * The registered program pda
33
+ */
34
+ registeredProgramPda: PublicKey;
35
+ /**
36
+ * Noop program.
37
+ */
38
+ noopProgram: PublicKey;
39
+ /**
40
+ * Account compression authority.
41
+ */
42
+ accountCompressionAuthority: PublicKey;
43
+ /**
44
+ * Account compression program.
45
+ */
46
+ accountCompressionProgram: PublicKey;
47
+ /**
48
+ * Solana pool pda. Some() if compression or decompression is done.
49
+ */
50
+ solPoolPda: PublicKey | null;
51
+ /**
52
+ * Decompression recipient.
53
+ */
54
+ decompressionRecipient: PublicKey | null;
55
+ /**
56
+ * Solana system program.
57
+ */
58
+ systemProgram: PublicKey;
59
+ };
60
+ export declare const invokeAccountsLayout: (accounts: invokeAccountsLayoutParams) => AccountMeta[];
61
+ export declare const PublicTransactionEventLayout: Layout<PublicTransactionEvent>;
62
+ export declare function encodePublicTransactionEvent(data: PublicTransactionEvent): Buffer;
63
+ export declare function decodePublicTransactionEvent(buffer: Buffer): PublicTransactionEvent;
64
+ export declare const AppendNullifyCreateAddressInputsMetaLayout: import("buffer-layout").Layout<unknown>;
65
+ export declare const AppendLeavesInputLayout: import("buffer-layout").Layout<unknown>;
66
+ export declare const InsertNullifierInputLayout: import("buffer-layout").Layout<unknown>;
67
+ export declare const InsertAddressInputLayout: import("buffer-layout").Layout<unknown>;
68
+ export declare const MerkleTreeSequenceNumberLayout: import("buffer-layout").Layout<unknown>;
69
+ export declare function deserializeAppendNullifyCreateAddressInputsIndexer(buffer: Buffer): {
70
+ meta: unknown;
71
+ leaves: unknown[];
72
+ nullifiers: unknown[];
73
+ addresses: unknown[];
74
+ sequence_numbers: unknown[];
75
+ output_leaf_indices: number[];
76
+ };
77
+ export declare function convertToPublicTransactionEvent(decoded: any, remainingAccounts: PublicKey[], invokeData: InstructionDataInvoke): PublicTransactionEvent;
@@ -0,0 +1,74 @@
1
+ import { AccountMeta, PublicKey } from '@solana/web3.js';
2
+ import { AccountProofInput, CompressedAccountLegacy, NewAddressProofInput, OutputCompressedAccountWithPackedContext, PackedCompressedAccountWithMerkleContext, TreeInfo } from '../../state';
3
+ import { CompressedAccountWithMerkleContextLegacy, PackedAddressTreeInfo, PackedStateTreeInfo } from '../../state/compressed-account';
4
+ /**
5
+ * @internal Finds the index of a PublicKey in an array, or adds it if not
6
+ * present
7
+ * */
8
+ export declare function getIndexOrAdd(accountsArray: PublicKey[], key: PublicKey): number;
9
+ /**
10
+ * @internal
11
+ * Pads output state trees with the 0th state tree of the input state.
12
+ *
13
+ * @param outputStateMerkleTrees Optional output state trees
14
+ * to be inserted into the
15
+ * output state. Defaults to
16
+ * the 0th state tree of the
17
+ * input state. Gets padded to
18
+ * the length of
19
+ * outputCompressedAccounts.
20
+ * @param numberOfOutputCompressedAccounts The number of output
21
+ * compressed accounts.
22
+ *
23
+ * @returns Padded output state trees.
24
+ */
25
+ export declare function padOutputStateMerkleTrees(outputStateMerkleTrees: PublicKey, numberOfOutputCompressedAccounts: number): PublicKey[];
26
+ export declare function toAccountMetas(remainingAccounts: PublicKey[]): AccountMeta[];
27
+ export interface PackedStateTreeInfos {
28
+ packedTreeInfos: PackedStateTreeInfo[];
29
+ outputTreeIndex: number;
30
+ }
31
+ export interface PackedTreeInfos {
32
+ stateTrees?: PackedStateTreeInfos;
33
+ addressTrees: PackedAddressTreeInfo[];
34
+ }
35
+ /**
36
+ * Packs TreeInfos. Replaces PublicKey with index pointer to remaining accounts.
37
+ *
38
+ * Only use for MUT, CLOSE, NEW_ADDRESSES. For INIT, pass
39
+ * {@link newAddressParamsPacked} and `outputStateTreeIndex` to your program
40
+ * instead.
41
+ *
42
+ *
43
+ * @param remainingAccounts Optional existing array of accounts
44
+ * to append to.
45
+ * @param accountProofInputs Account proof inputs.
46
+ * @param newAddressProofInputs New address proof inputs.
47
+ *
48
+ * @returns Remaining accounts, packed state and address tree infos, state tree
49
+ * output index and address tree infos.
50
+ */
51
+ export declare function packTreeInfos(remainingAccounts: PublicKey[], accountProofInputs: AccountProofInput[], newAddressProofInputs: NewAddressProofInput[]): PackedTreeInfos;
52
+ /**
53
+ * Packs Compressed Accounts.
54
+ *
55
+ * Replaces PublicKey with index pointer to remaining accounts.
56
+ *
57
+ *
58
+ * @param inputCompressedAccounts Ix input state to be consumed
59
+ * @param inputStateRootIndices The recent state root indices of the
60
+ * input state. The expiry is tied to
61
+ * the proof.
62
+ * @param outputCompressedAccounts Ix output state to be created
63
+ * @param outputStateTreeInfo The output state tree info. Gets
64
+ * padded to the length of
65
+ * outputCompressedAccounts.
66
+ *
67
+ * @param remainingAccounts Optional existing array of accounts
68
+ * to append to.
69
+ **/
70
+ export declare function packCompressedAccounts(inputCompressedAccounts: CompressedAccountWithMerkleContextLegacy[], inputStateRootIndices: number[], outputCompressedAccounts: CompressedAccountLegacy[], outputStateTreeInfo?: TreeInfo, remainingAccounts?: PublicKey[]): {
71
+ packedInputCompressedAccounts: PackedCompressedAccountWithMerkleContext[];
72
+ packedOutputCompressedAccounts: OutputCompressedAccountWithPackedContext[];
73
+ remainingAccounts: PublicKey[];
74
+ };
@@ -0,0 +1,175 @@
1
+ import BN from 'bn.js';
2
+ import { PublicKey, TransactionInstruction } from '@solana/web3.js';
3
+ import { CompressedAccountWithMerkleContext, ValidityProof, TreeInfo, CompressedAccountLegacy } from '../../state';
4
+ import { NewAddressParams } from '../../utils';
5
+ export declare const sumUpLamports: (accounts: CompressedAccountWithMerkleContext[]) => BN;
6
+ /**
7
+ * Create compressed account system transaction params
8
+ */
9
+ type CreateAccountWithSeedParams = {
10
+ /**
11
+ * The payer of the transaction.
12
+ */
13
+ payer: PublicKey;
14
+ /**
15
+ * Address params for the new compressed account.
16
+ */
17
+ newAddressParams: NewAddressParams;
18
+ /**
19
+ * Address of the new compressed account
20
+ */
21
+ newAddress: number[];
22
+ /**
23
+ * Recent validity proof proving that there's no existing compressed account
24
+ * registered with newAccountAddress
25
+ */
26
+ recentValidityProof: ValidityProof | null;
27
+ /**
28
+ * State tree pubkey. Defaults to a public state tree if unspecified.
29
+ */
30
+ outputStateTreeInfo?: TreeInfo;
31
+ /**
32
+ * Public key of the program to assign as the owner of the created account.
33
+ */
34
+ programId?: PublicKey;
35
+ /**
36
+ * Optional input accounts to transfer lamports from into the new compressed
37
+ * account.
38
+ */
39
+ inputCompressedAccounts?: CompressedAccountWithMerkleContext[];
40
+ /**
41
+ * Optional input state root indices of 'inputCompressedAccounts'. The
42
+ * expiry is tied to the 'recentValidityProof'.
43
+ */
44
+ inputStateRootIndices?: number[];
45
+ /**
46
+ * Optional lamports to transfer into the new compressed account.
47
+ */
48
+ lamports?: number | BN;
49
+ };
50
+ /**
51
+ * Defines the parameters for the transfer method
52
+ */
53
+ type TransferParams = {
54
+ /**
55
+ * The payer of the transaction.
56
+ */
57
+ payer: PublicKey;
58
+ /**
59
+ * The input state to be consumed.
60
+ */
61
+ inputCompressedAccounts: CompressedAccountWithMerkleContext[];
62
+ /**
63
+ * Recipient address.
64
+ */
65
+ toAddress: PublicKey;
66
+ /**
67
+ * Amount of lamports to transfer.
68
+ */
69
+ lamports: number | BN;
70
+ /**
71
+ * The recent state root indices of the input state. The expiry is tied to
72
+ * the proof.
73
+ */
74
+ recentInputStateRootIndices: number[];
75
+ /**
76
+ * The recent validity proof for state inclusion of the input state. Expires
77
+ * after n slots.
78
+ */
79
+ recentValidityProof: ValidityProof | null;
80
+ };
81
+ /**
82
+ * Defines the parameters for the transfer method
83
+ */
84
+ type CompressParams = {
85
+ /**
86
+ * The payer of the transaction.
87
+ */
88
+ payer: PublicKey;
89
+ /**
90
+ * address that the lamports are attached to. also defaults to the recipient owner
91
+ */
92
+ toAddress: PublicKey;
93
+ /**
94
+ * amount of lamports to compress.
95
+ */
96
+ lamports: number | BN;
97
+ /**
98
+ * The state tree that the tx output should be inserted into.
99
+ */
100
+ outputStateTreeInfo: TreeInfo;
101
+ };
102
+ /**
103
+ * Defines the parameters for the transfer method
104
+ */
105
+ type DecompressParams = {
106
+ /**
107
+ * The payer of the transaction.
108
+ */
109
+ payer: PublicKey;
110
+ /**
111
+ * The input state to be consumed.
112
+ */
113
+ inputCompressedAccounts: CompressedAccountWithMerkleContext[];
114
+ /**
115
+ * Recipient address of uncompressed lamports
116
+ */
117
+ toAddress: PublicKey;
118
+ /**
119
+ * amount of lamports to decompress.
120
+ */
121
+ lamports: number | BN;
122
+ /**
123
+ * The recent state root indices of the input state. The expiry is tied to
124
+ * the proof.
125
+ */
126
+ recentInputStateRootIndices: number[];
127
+ /**
128
+ * The recent validity proof for state inclusion of the input state. It
129
+ * expires after n slots.
130
+ */
131
+ recentValidityProof: ValidityProof | null;
132
+ };
133
+ export declare class LightSystemProgram {
134
+ /**
135
+ * @internal
136
+ */
137
+ constructor();
138
+ /**
139
+ * The LightSystemProgram program ID.
140
+ */
141
+ static programId: PublicKey;
142
+ /**
143
+ * @internal
144
+ * Cwct1kQLwJm8Z3HetLu8m4SXkhD6FZ5fXbJQCxTxPnGY
145
+ *
146
+ */
147
+ static deriveCompressedSolPda(): PublicKey;
148
+ static createTransferOutputState(inputCompressedAccounts: CompressedAccountWithMerkleContext[], toAddress: PublicKey, lamports: number | BN): CompressedAccountLegacy[];
149
+ static createDecompressOutputState(inputCompressedAccounts: CompressedAccountWithMerkleContext[], lamports: number | BN): CompressedAccountLegacy[];
150
+ /**
151
+ * No data by default
152
+ */
153
+ static createNewAddressOutputState(address: number[], owner: PublicKey, lamports?: BN | number, inputCompressedAccounts?: CompressedAccountWithMerkleContext[]): CompressedAccountLegacy[];
154
+ /**
155
+ * Creates instruction to create compressed account with PDA.
156
+ * Cannot write data.
157
+ */
158
+ static createAccount({ payer, newAddressParams, newAddress, recentValidityProof, outputStateTreeInfo, inputCompressedAccounts, inputStateRootIndices, lamports, }: CreateAccountWithSeedParams): Promise<TransactionInstruction>;
159
+ /**
160
+ * Creates a transaction instruction that transfers compressed lamports from
161
+ * one owner to another.
162
+ */
163
+ static transfer({ payer, inputCompressedAccounts, toAddress, lamports, recentInputStateRootIndices, recentValidityProof, }: TransferParams): Promise<TransactionInstruction>;
164
+ /**
165
+ * Creates a transaction instruction that transfers compressed lamports from
166
+ * one owner to another.
167
+ */
168
+ static compress({ payer, toAddress, lamports, outputStateTreeInfo, }: CompressParams): Promise<TransactionInstruction>;
169
+ /**
170
+ * Creates a transaction instruction that transfers compressed lamports from
171
+ * one owner to another.
172
+ */
173
+ static decompress({ payer, inputCompressedAccounts, toAddress, lamports, recentInputStateRootIndices, recentValidityProof, }: DecompressParams): Promise<TransactionInstruction>;
174
+ }
175
+ export {};
@@ -0,0 +1,10 @@
1
+ import BN from 'bn.js';
2
+ import { CompressedAccountWithMerkleContext } from '../../state';
3
+ /**
4
+ * Selects the minimal number of compressed SOL accounts for a transfer.
5
+ *
6
+ * 1. Sorts the accounts by amount in descending order
7
+ * 2. Accumulates the amount until it is greater than or equal to the transfer
8
+ * amount
9
+ */
10
+ export declare function selectMinCompressedSolAccountsForTransfer(accounts: CompressedAccountWithMerkleContext[], transferLamports: BN | number): [selectedAccounts: CompressedAccountWithMerkleContext[], total: BN];