sol-parser-sdk 0.5.9

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 (190) hide show
  1. package/.env.example +24 -0
  2. package/LICENSE +21 -0
  3. package/README.md +236 -0
  4. package/README_CN.md +236 -0
  5. package/dist/accounts/mod.d.ts +15 -0
  6. package/dist/accounts/mod.js +173 -0
  7. package/dist/accounts/nonce.d.ts +5 -0
  8. package/dist/accounts/nonce.js +32 -0
  9. package/dist/accounts/pumpfun.d.ts +16 -0
  10. package/dist/accounts/pumpfun.js +538 -0
  11. package/dist/accounts/pumpswap.d.ts +8 -0
  12. package/dist/accounts/pumpswap.js +192 -0
  13. package/dist/accounts/raydium_orca.d.ts +26 -0
  14. package/dist/accounts/raydium_orca.js +453 -0
  15. package/dist/accounts/rpc_wallet.d.ts +5 -0
  16. package/dist/accounts/rpc_wallet.js +18 -0
  17. package/dist/accounts/rust_aliases.d.ts +10 -0
  18. package/dist/accounts/rust_aliases.js +21 -0
  19. package/dist/accounts/token.d.ts +5 -0
  20. package/dist/accounts/token.js +98 -0
  21. package/dist/accounts/types.d.ts +9 -0
  22. package/dist/accounts/types.js +2 -0
  23. package/dist/accounts/utils.d.ts +1 -0
  24. package/dist/accounts/utils.js +12 -0
  25. package/dist/accounts/wallet_resolve.d.ts +1 -0
  26. package/dist/accounts/wallet_resolve.js +28 -0
  27. package/dist/common/constants.d.ts +10 -0
  28. package/dist/common/constants.js +13 -0
  29. package/dist/core/account_dispatcher_rpc.d.ts +11 -0
  30. package/dist/core/account_dispatcher_rpc.js +155 -0
  31. package/dist/core/account_fill_bonk.d.ts +4 -0
  32. package/dist/core/account_fill_bonk.js +20 -0
  33. package/dist/core/account_fill_meteora.d.ts +15 -0
  34. package/dist/core/account_fill_meteora.js +27 -0
  35. package/dist/core/account_fill_orca.d.ts +5 -0
  36. package/dist/core/account_fill_orca.js +18 -0
  37. package/dist/core/account_fill_pumpfun.d.ts +7 -0
  38. package/dist/core/account_fill_pumpfun.js +167 -0
  39. package/dist/core/account_fill_pumpswap.d.ts +10 -0
  40. package/dist/core/account_fill_pumpswap.js +128 -0
  41. package/dist/core/account_fill_raydium.d.ts +20 -0
  42. package/dist/core/account_fill_raydium.js +104 -0
  43. package/dist/core/account_fill_raydium_launchlab.d.ts +4 -0
  44. package/dist/core/account_fill_raydium_launchlab.js +20 -0
  45. package/dist/core/account_pubkey_cache.d.ts +12 -0
  46. package/dist/core/account_pubkey_cache.js +26 -0
  47. package/dist/core/clock.d.ts +8 -0
  48. package/dist/core/clock.js +20 -0
  49. package/dist/core/common_filler_rpc.d.ts +6 -0
  50. package/dist/core/common_filler_rpc.js +21 -0
  51. package/dist/core/dex_event.d.ts +1704 -0
  52. package/dist/core/dex_event.js +14 -0
  53. package/dist/core/error.d.ts +43 -0
  54. package/dist/core/error.js +16 -0
  55. package/dist/core/json_utils.d.ts +8 -0
  56. package/dist/core/json_utils.js +18 -0
  57. package/dist/core/metadata.d.ts +11 -0
  58. package/dist/core/metadata.js +13 -0
  59. package/dist/core/pumpfun_fee_enrich.d.ts +6 -0
  60. package/dist/core/pumpfun_fee_enrich.js +159 -0
  61. package/dist/core/rpc_invoke_map.d.ts +23 -0
  62. package/dist/core/rpc_invoke_map.js +157 -0
  63. package/dist/core/unified_parser.d.ts +19 -0
  64. package/dist/core/unified_parser.js +50 -0
  65. package/dist/grpc/client.d.ts +83 -0
  66. package/dist/grpc/client.js +645 -0
  67. package/dist/grpc/client_stub.d.ts +5 -0
  68. package/dist/grpc/client_stub.js +5 -0
  69. package/dist/grpc/event_parser.d.ts +6 -0
  70. package/dist/grpc/event_parser.js +15 -0
  71. package/dist/grpc/geyser_connect.d.ts +30 -0
  72. package/dist/grpc/geyser_connect.js +40 -0
  73. package/dist/grpc/log_instr_dedup.d.ts +2 -0
  74. package/dist/grpc/log_instr_dedup.js +402 -0
  75. package/dist/grpc/order_buffer.d.ts +27 -0
  76. package/dist/grpc/order_buffer.js +166 -0
  77. package/dist/grpc/program_ids.d.ts +27 -0
  78. package/dist/grpc/program_ids.js +61 -0
  79. package/dist/grpc/rpc_to_grpc.d.ts +18 -0
  80. package/dist/grpc/rpc_to_grpc.js +127 -0
  81. package/dist/grpc/subscribe_builder.d.ts +13 -0
  82. package/dist/grpc/subscribe_builder.js +66 -0
  83. package/dist/grpc/transaction_meta.d.ts +29 -0
  84. package/dist/grpc/transaction_meta.js +208 -0
  85. package/dist/grpc/types.d.ts +195 -0
  86. package/dist/grpc/types.js +551 -0
  87. package/dist/grpc/yellowstone_parse.d.ts +16 -0
  88. package/dist/grpc/yellowstone_parse.js +62 -0
  89. package/dist/index.d.ts +50 -0
  90. package/dist/index.js +298 -0
  91. package/dist/instr/bonk_ix.d.ts +8 -0
  92. package/dist/instr/bonk_ix.js +131 -0
  93. package/dist/instr/inner.d.ts +4 -0
  94. package/dist/instr/inner.js +453 -0
  95. package/dist/instr/meteora_damm_ix.d.ts +8 -0
  96. package/dist/instr/meteora_damm_ix.js +601 -0
  97. package/dist/instr/meteora_dlmm_ix.d.ts +2 -0
  98. package/dist/instr/meteora_dlmm_ix.js +134 -0
  99. package/dist/instr/meteora_pools_ix.d.ts +2 -0
  100. package/dist/instr/meteora_pools_ix.js +78 -0
  101. package/dist/instr/mod.d.ts +18 -0
  102. package/dist/instr/mod.js +129 -0
  103. package/dist/instr/orca_whirlpool_ix.d.ts +8 -0
  104. package/dist/instr/orca_whirlpool_ix.js +119 -0
  105. package/dist/instr/program_ids.d.ts +4 -0
  106. package/dist/instr/program_ids.js +20 -0
  107. package/dist/instr/pump_fees_ix.d.ts +2 -0
  108. package/dist/instr/pump_fees_ix.js +168 -0
  109. package/dist/instr/pumpfun_ix.d.ts +6 -0
  110. package/dist/instr/pumpfun_ix.js +448 -0
  111. package/dist/instr/pumpswap_ix.d.ts +5 -0
  112. package/dist/instr/pumpswap_ix.js +270 -0
  113. package/dist/instr/raydium_amm_v4_ix.d.ts +6 -0
  114. package/dist/instr/raydium_amm_v4_ix.js +112 -0
  115. package/dist/instr/raydium_clmm_ix.d.ts +5 -0
  116. package/dist/instr/raydium_clmm_ix.js +184 -0
  117. package/dist/instr/raydium_cpmm_ix.d.ts +5 -0
  118. package/dist/instr/raydium_cpmm_ix.js +109 -0
  119. package/dist/instr/raydium_launchlab_ix.d.ts +8 -0
  120. package/dist/instr/raydium_launchlab_ix.js +125 -0
  121. package/dist/instr/rust_aliases.d.ts +10 -0
  122. package/dist/instr/rust_aliases.js +20 -0
  123. package/dist/instr/utils.d.ts +10 -0
  124. package/dist/instr/utils.js +35 -0
  125. package/dist/logs/discriminator_lut.d.ts +19 -0
  126. package/dist/logs/discriminator_lut.js +62 -0
  127. package/dist/logs/meteora_amm.d.ts +8 -0
  128. package/dist/logs/meteora_amm.js +113 -0
  129. package/dist/logs/meteora_damm.d.ts +5 -0
  130. package/dist/logs/meteora_damm.js +367 -0
  131. package/dist/logs/meteora_dbc.d.ts +11 -0
  132. package/dist/logs/meteora_dbc.js +142 -0
  133. package/dist/logs/meteora_dlmm.d.ts +6 -0
  134. package/dist/logs/meteora_dlmm.js +201 -0
  135. package/dist/logs/optimized_matcher.d.ts +11 -0
  136. package/dist/logs/optimized_matcher.js +941 -0
  137. package/dist/logs/orca.d.ts +6 -0
  138. package/dist/logs/orca.js +148 -0
  139. package/dist/logs/program_data.d.ts +2 -0
  140. package/dist/logs/program_data.js +20 -0
  141. package/dist/logs/program_log_discriminators.d.ts +80 -0
  142. package/dist/logs/program_log_discriminators.js +88 -0
  143. package/dist/logs/pump.d.ts +14 -0
  144. package/dist/logs/pump.js +378 -0
  145. package/dist/logs/pump_amm.d.ts +9 -0
  146. package/dist/logs/pump_amm.js +418 -0
  147. package/dist/logs/pump_fees.d.ts +23 -0
  148. package/dist/logs/pump_fees.js +364 -0
  149. package/dist/logs/raydium_amm.d.ts +9 -0
  150. package/dist/logs/raydium_amm.js +224 -0
  151. package/dist/logs/raydium_clmm.d.ts +17 -0
  152. package/dist/logs/raydium_clmm.js +624 -0
  153. package/dist/logs/raydium_cpmm.d.ts +7 -0
  154. package/dist/logs/raydium_cpmm.js +121 -0
  155. package/dist/logs/raydium_launchlab.d.ts +10 -0
  156. package/dist/logs/raydium_launchlab.js +84 -0
  157. package/dist/logs/raydium_launchpad.d.ts +12 -0
  158. package/dist/logs/raydium_launchpad.js +92 -0
  159. package/dist/logs/rust_aliases.d.ts +7 -0
  160. package/dist/logs/rust_aliases.js +16 -0
  161. package/dist/parser_alias.d.ts +3 -0
  162. package/dist/parser_alias.js +2 -0
  163. package/dist/rpc_parser.d.ts +17 -0
  164. package/dist/rpc_parser.js +39 -0
  165. package/dist/rpc_transaction.d.ts +27 -0
  166. package/dist/rpc_transaction.js +416 -0
  167. package/dist/shredstream/alt_lookup.d.ts +9 -0
  168. package/dist/shredstream/alt_lookup.js +70 -0
  169. package/dist/shredstream/client.d.ts +65 -0
  170. package/dist/shredstream/client.js +403 -0
  171. package/dist/shredstream/config.d.ts +30 -0
  172. package/dist/shredstream/config.js +34 -0
  173. package/dist/shredstream/entries_decode.d.ts +28 -0
  174. package/dist/shredstream/entries_decode.js +251 -0
  175. package/dist/shredstream/index.d.ts +17 -0
  176. package/dist/shredstream/index.js +33 -0
  177. package/dist/shredstream/instruction_parse.d.ts +34 -0
  178. package/dist/shredstream/instruction_parse.js +79 -0
  179. package/dist/shredstream/proto_types.d.ts +9 -0
  180. package/dist/shredstream/proto_types.js +2 -0
  181. package/dist/shredstream/shredstream.proto +15 -0
  182. package/dist/shredstream/wire_to_shred_tx.d.ts +2 -0
  183. package/dist/shredstream/wire_to_shred_tx.js +59 -0
  184. package/dist/util/binary.d.ts +14 -0
  185. package/dist/util/binary.js +82 -0
  186. package/dist/util/market.d.ts +18 -0
  187. package/dist/util/market.js +54 -0
  188. package/dist/warmup.d.ts +3 -0
  189. package/dist/warmup.js +23 -0
  190. package/package.json +61 -0
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isGlobalConfigAccount = isGlobalConfigAccount;
4
+ exports.isPoolAccount = isPoolAccount;
5
+ exports.parsePumpswapGlobalConfig = parsePumpswapGlobalConfig;
6
+ exports.parsePumpswapPool = parsePumpswapPool;
7
+ exports.parsePumpswapAccount = parsePumpswapAccount;
8
+ const utils_js_1 = require("./utils.js");
9
+ const binary_js_1 = require("../util/binary.js");
10
+ const program_ids_js_1 = require("../instr/program_ids.js");
11
+ const GLOBAL_DISC = Uint8Array.from([149, 8, 156, 202, 160, 252, 176, 217]);
12
+ const POOL_DISC = Uint8Array.from([241, 154, 109, 4, 17, 177, 109, 188]);
13
+ const GLOBAL_BODY = 634;
14
+ const POOL_BODY = 244;
15
+ function isGlobalConfigAccount(data) {
16
+ return (0, utils_js_1.hasDiscriminator)(data, GLOBAL_DISC);
17
+ }
18
+ function isPoolAccount(data) {
19
+ return (0, utils_js_1.hasDiscriminator)(data, POOL_DISC);
20
+ }
21
+ function parsePumpswapGlobalConfig(account, metadata) {
22
+ if (account.data.length < 8 + GLOBAL_BODY)
23
+ return null;
24
+ if (!isGlobalConfigAccount(account.data))
25
+ return null;
26
+ const d = account.data.subarray(8);
27
+ let o = 0;
28
+ const admin = (0, binary_js_1.readPubkey)(d, o);
29
+ if (admin === null)
30
+ return null;
31
+ o += 32;
32
+ const lp_fee_basis_points = (0, binary_js_1.readU64LE)(d, o);
33
+ if (lp_fee_basis_points === null)
34
+ return null;
35
+ o += 8;
36
+ const protocol_fee_basis_points = (0, binary_js_1.readU64LE)(d, o);
37
+ if (protocol_fee_basis_points === null)
38
+ return null;
39
+ o += 8;
40
+ const disable_flags = (0, binary_js_1.readU8)(d, o);
41
+ if (disable_flags === null)
42
+ return null;
43
+ o += 1;
44
+ const protocol_fee_recipients = [];
45
+ for (let i = 0; i < 8; i++) {
46
+ const pk = (0, binary_js_1.readPubkey)(d, o);
47
+ if (pk === null)
48
+ return null;
49
+ protocol_fee_recipients.push(pk);
50
+ o += 32;
51
+ }
52
+ const coin_creator_fee_basis_points = (0, binary_js_1.readU64LE)(d, o);
53
+ if (coin_creator_fee_basis_points === null)
54
+ return null;
55
+ o += 8;
56
+ const admin_set_coin_creator_authority = (0, binary_js_1.readPubkey)(d, o);
57
+ if (admin_set_coin_creator_authority === null)
58
+ return null;
59
+ o += 32;
60
+ const whitelist_pda = (0, binary_js_1.readPubkey)(d, o);
61
+ if (whitelist_pda === null)
62
+ return null;
63
+ o += 32;
64
+ const reserved_fee_recipient = (0, binary_js_1.readPubkey)(d, o);
65
+ if (reserved_fee_recipient === null)
66
+ return null;
67
+ o += 32;
68
+ const mayhem_b = (0, binary_js_1.readU8)(d, o);
69
+ if (mayhem_b === null)
70
+ return null;
71
+ const mayhem_mode_enabled = mayhem_b !== 0;
72
+ o += 1;
73
+ const reserved_fee_recipients = [];
74
+ for (let i = 0; i < 7; i++) {
75
+ const pk = (0, binary_js_1.readPubkey)(d, o);
76
+ if (pk === null)
77
+ return null;
78
+ reserved_fee_recipients.push(pk);
79
+ o += 32;
80
+ }
81
+ const global_config = {
82
+ admin,
83
+ lp_fee_basis_points,
84
+ protocol_fee_basis_points,
85
+ disable_flags,
86
+ protocol_fee_recipients,
87
+ coin_creator_fee_basis_points,
88
+ admin_set_coin_creator_authority,
89
+ whitelist_pda,
90
+ reserved_fee_recipient,
91
+ mayhem_mode_enabled,
92
+ reserved_fee_recipients,
93
+ };
94
+ const ev = {
95
+ metadata,
96
+ pubkey: account.pubkey,
97
+ executable: account.executable,
98
+ lamports: account.lamports,
99
+ owner: account.owner,
100
+ rent_epoch: account.rent_epoch,
101
+ global_config,
102
+ };
103
+ return { PumpSwapGlobalConfigAccount: ev };
104
+ }
105
+ function parsePumpswapPool(account, metadata) {
106
+ if (account.data.length < 8 + POOL_BODY)
107
+ return null;
108
+ if (!isPoolAccount(account.data))
109
+ return null;
110
+ const d = account.data.subarray(8);
111
+ let o = 0;
112
+ const pool_bump = (0, binary_js_1.readU8)(d, o);
113
+ if (pool_bump === null)
114
+ return null;
115
+ o += 1;
116
+ const index = (0, binary_js_1.readU16LE)(d, o);
117
+ if (index === null)
118
+ return null;
119
+ o += 2;
120
+ const creator = (0, binary_js_1.readPubkey)(d, o);
121
+ if (creator === null)
122
+ return null;
123
+ o += 32;
124
+ const base_mint = (0, binary_js_1.readPubkey)(d, o);
125
+ if (base_mint === null)
126
+ return null;
127
+ o += 32;
128
+ const quote_mint = (0, binary_js_1.readPubkey)(d, o);
129
+ if (quote_mint === null)
130
+ return null;
131
+ o += 32;
132
+ const lp_mint = (0, binary_js_1.readPubkey)(d, o);
133
+ if (lp_mint === null)
134
+ return null;
135
+ o += 32;
136
+ const pool_base_token_account = (0, binary_js_1.readPubkey)(d, o);
137
+ if (pool_base_token_account === null)
138
+ return null;
139
+ o += 32;
140
+ const pool_quote_token_account = (0, binary_js_1.readPubkey)(d, o);
141
+ if (pool_quote_token_account === null)
142
+ return null;
143
+ o += 32;
144
+ const lp_supply = (0, binary_js_1.readU64LE)(d, o);
145
+ if (lp_supply === null)
146
+ return null;
147
+ o += 8;
148
+ const coin_creator = (0, binary_js_1.readPubkey)(d, o);
149
+ if (coin_creator === null)
150
+ return null;
151
+ o += 32;
152
+ const mayhem = (0, binary_js_1.readU8)(d, o);
153
+ if (mayhem === null)
154
+ return null;
155
+ o += 1;
156
+ const cashback = (0, binary_js_1.readU8)(d, o);
157
+ if (cashback === null)
158
+ return null;
159
+ const pool = {
160
+ pool_bump,
161
+ index,
162
+ creator,
163
+ base_mint,
164
+ quote_mint,
165
+ lp_mint,
166
+ pool_base_token_account,
167
+ pool_quote_token_account,
168
+ lp_supply,
169
+ coin_creator,
170
+ is_mayhem_mode: mayhem !== 0,
171
+ is_cashback_coin: cashback !== 0,
172
+ };
173
+ const ev = {
174
+ metadata,
175
+ pubkey: account.pubkey,
176
+ executable: account.executable,
177
+ lamports: account.lamports,
178
+ owner: account.owner,
179
+ rent_epoch: account.rent_epoch,
180
+ pool,
181
+ };
182
+ return { PumpSwapPoolAccount: ev };
183
+ }
184
+ function parsePumpswapAccount(account, metadata) {
185
+ if (account.owner !== program_ids_js_1.PUMPSWAP_PROGRAM_ID)
186
+ return null;
187
+ if (isGlobalConfigAccount(account.data))
188
+ return parsePumpswapGlobalConfig(account, metadata);
189
+ if (isPoolAccount(account.data))
190
+ return parsePumpswapPool(account, metadata);
191
+ return null;
192
+ }
@@ -0,0 +1,26 @@
1
+ import type { EventMetadata } from "../core/metadata.js";
2
+ import type { DexEvent } from "../core/dex_event.js";
3
+ import type { AccountData } from "./types.js";
4
+ export declare function isRaydiumClmmAmmConfigAccount(data: Uint8Array): boolean;
5
+ export declare function isRaydiumClmmPoolStateAccount(data: Uint8Array): boolean;
6
+ export declare function isRaydiumClmmTickArrayStateAccount(data: Uint8Array): boolean;
7
+ export declare function isRaydiumCpmmAmmConfigAccount(data: Uint8Array): boolean;
8
+ export declare function isRaydiumCpmmPoolStateAccount(data: Uint8Array): boolean;
9
+ export declare function isOrcaWhirlpoolAccount(data: Uint8Array): boolean;
10
+ export declare function isOrcaPositionAccount(data: Uint8Array): boolean;
11
+ export declare function isOrcaTickArrayAccount(data: Uint8Array): boolean;
12
+ export declare function isOrcaFeeTierAccount(data: Uint8Array): boolean;
13
+ export declare function isOrcaWhirlpoolsConfigAccount(data: Uint8Array): boolean;
14
+ export declare function parseRaydiumClmmAccount(account: AccountData, metadata: EventMetadata): DexEvent | null;
15
+ export declare function parseRaydiumCpmmAccount(account: AccountData, metadata: EventMetadata): DexEvent | null;
16
+ export declare function parseOrcaWhirlpoolAccount(account: AccountData, metadata: EventMetadata): DexEvent | null;
17
+ export declare function parseRaydiumClmmAmmConfig(account: AccountData, metadata: EventMetadata): DexEvent | null;
18
+ export declare function parseRaydiumClmmPoolState(account: AccountData, metadata: EventMetadata): DexEvent | null;
19
+ export declare function parseRaydiumClmmTickArrayState(account: AccountData, metadata: EventMetadata): DexEvent | null;
20
+ export declare function parseRaydiumCpmmAmmConfig(account: AccountData, metadata: EventMetadata): DexEvent | null;
21
+ export declare function parseRaydiumCpmmPoolState(account: AccountData, metadata: EventMetadata): DexEvent | null;
22
+ export declare function parseOrcaWhirlpool(account: AccountData, metadata: EventMetadata): DexEvent | null;
23
+ export declare function parseOrcaPosition(account: AccountData, metadata: EventMetadata): DexEvent | null;
24
+ export declare function parseOrcaTickArray(account: AccountData, metadata: EventMetadata): DexEvent | null;
25
+ export declare function parseOrcaFeeTier(account: AccountData, metadata: EventMetadata): DexEvent | null;
26
+ export declare function parseOrcaWhirlpoolsConfig(account: AccountData, metadata: EventMetadata): DexEvent | null;
@@ -0,0 +1,453 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRaydiumClmmAmmConfigAccount = isRaydiumClmmAmmConfigAccount;
4
+ exports.isRaydiumClmmPoolStateAccount = isRaydiumClmmPoolStateAccount;
5
+ exports.isRaydiumClmmTickArrayStateAccount = isRaydiumClmmTickArrayStateAccount;
6
+ exports.isRaydiumCpmmAmmConfigAccount = isRaydiumCpmmAmmConfigAccount;
7
+ exports.isRaydiumCpmmPoolStateAccount = isRaydiumCpmmPoolStateAccount;
8
+ exports.isOrcaWhirlpoolAccount = isOrcaWhirlpoolAccount;
9
+ exports.isOrcaPositionAccount = isOrcaPositionAccount;
10
+ exports.isOrcaTickArrayAccount = isOrcaTickArrayAccount;
11
+ exports.isOrcaFeeTierAccount = isOrcaFeeTierAccount;
12
+ exports.isOrcaWhirlpoolsConfigAccount = isOrcaWhirlpoolsConfigAccount;
13
+ exports.parseRaydiumClmmAccount = parseRaydiumClmmAccount;
14
+ exports.parseRaydiumCpmmAccount = parseRaydiumCpmmAccount;
15
+ exports.parseOrcaWhirlpoolAccount = parseOrcaWhirlpoolAccount;
16
+ exports.parseRaydiumClmmAmmConfig = parseRaydiumClmmAmmConfig;
17
+ exports.parseRaydiumClmmPoolState = parseRaydiumClmmPoolState;
18
+ exports.parseRaydiumClmmTickArrayState = parseRaydiumClmmTickArrayState;
19
+ exports.parseRaydiumCpmmAmmConfig = parseRaydiumCpmmAmmConfig;
20
+ exports.parseRaydiumCpmmPoolState = parseRaydiumCpmmPoolState;
21
+ exports.parseOrcaWhirlpool = parseOrcaWhirlpool;
22
+ exports.parseOrcaPosition = parseOrcaPosition;
23
+ exports.parseOrcaTickArray = parseOrcaTickArray;
24
+ exports.parseOrcaFeeTier = parseOrcaFeeTier;
25
+ exports.parseOrcaWhirlpoolsConfig = parseOrcaWhirlpoolsConfig;
26
+ const web3_js_1 = require("@solana/web3.js");
27
+ const program_ids_js_1 = require("../instr/program_ids.js");
28
+ const utils_js_1 = require("./utils.js");
29
+ const CLMM_AMM_CONFIG_DISC = Uint8Array.from([218, 244, 33, 104, 203, 203, 43, 111]);
30
+ const CLMM_POOL_STATE_DISC = Uint8Array.from([247, 237, 227, 245, 215, 195, 222, 70]);
31
+ const CLMM_TICK_ARRAY_STATE_DISC = Uint8Array.from([192, 155, 85, 205, 49, 249, 129, 42]);
32
+ const CLMM_AMM_CONFIG_BODY = 109;
33
+ const CLMM_POOL_STATE_BODY = 1536;
34
+ const CLMM_TICK_ARRAY_STATE_BODY = 10232;
35
+ const CLMM_TICK_ARRAY_LEN = 60;
36
+ const CPMM_AMM_CONFIG_DISC = CLMM_AMM_CONFIG_DISC;
37
+ const CPMM_POOL_STATE_DISC = CLMM_POOL_STATE_DISC;
38
+ const CPMM_AMM_CONFIG_BODY = 228;
39
+ const CPMM_POOL_STATE_BODY = 629;
40
+ const ORCA_WHIRLPOOL_DISC = Uint8Array.from([63, 149, 209, 12, 225, 128, 99, 9]);
41
+ const ORCA_POSITION_DISC = Uint8Array.from([170, 188, 143, 228, 122, 64, 247, 208]);
42
+ const ORCA_TICK_ARRAY_DISC = Uint8Array.from([69, 97, 189, 190, 110, 7, 66, 187]);
43
+ const ORCA_FEE_TIER_DISC = Uint8Array.from([56, 75, 159, 76, 142, 68, 190, 105]);
44
+ const ORCA_WHIRLPOOLS_CONFIG_DISC = Uint8Array.from([157, 20, 49, 224, 217, 87, 193, 254]);
45
+ const ORCA_WHIRLPOOL_BODY = 645;
46
+ const ORCA_POSITION_BODY = 208;
47
+ const ORCA_TICK_ARRAY_BODY = 9980;
48
+ const ORCA_FEE_TIER_BODY = 36;
49
+ const ORCA_WHIRLPOOLS_CONFIG_BODY = 98;
50
+ const ORCA_TICK_ARRAY_LEN = 88;
51
+ const U128_SIGN_BIT = 1n << 127n;
52
+ const U128_MOD = 1n << 128n;
53
+ class Reader {
54
+ data;
55
+ offset = 0;
56
+ view;
57
+ constructor(data) {
58
+ this.data = data;
59
+ this.view = new DataView(data.buffer, data.byteOffset, data.byteLength);
60
+ }
61
+ require(size) {
62
+ if (this.offset + size > this.data.length) {
63
+ throw new RangeError("account data is truncated");
64
+ }
65
+ const start = this.offset;
66
+ this.offset += size;
67
+ return start;
68
+ }
69
+ u8() {
70
+ return this.view.getUint8(this.require(1));
71
+ }
72
+ bool() {
73
+ return this.u8() !== 0;
74
+ }
75
+ u16() {
76
+ return this.view.getUint16(this.require(2), true);
77
+ }
78
+ u32() {
79
+ return this.view.getUint32(this.require(4), true);
80
+ }
81
+ i32() {
82
+ return this.view.getInt32(this.require(4), true);
83
+ }
84
+ u64() {
85
+ return this.view.getBigUint64(this.require(8), true);
86
+ }
87
+ u128() {
88
+ const lo = this.u64();
89
+ const hi = this.u64();
90
+ return lo | (hi << 64n);
91
+ }
92
+ i128() {
93
+ const value = this.u128();
94
+ return value >= U128_SIGN_BIT ? value - U128_MOD : value;
95
+ }
96
+ pubkey() {
97
+ const start = this.require(32);
98
+ return new web3_js_1.PublicKey(this.data.subarray(start, start + 32)).toBase58();
99
+ }
100
+ bytes(len) {
101
+ const start = this.require(len);
102
+ return Array.from(this.data.subarray(start, start + len));
103
+ }
104
+ }
105
+ function readArray(len, read) {
106
+ const out = new Array(len);
107
+ for (let i = 0; i < len; i++)
108
+ out[i] = read();
109
+ return out;
110
+ }
111
+ function parseBody(data, parse) {
112
+ try {
113
+ return parse(new Reader(data));
114
+ }
115
+ catch {
116
+ return null;
117
+ }
118
+ }
119
+ function bodyAfterDiscriminator(account, disc, bodySize) {
120
+ if (account.data.length < 8 + bodySize || !(0, utils_js_1.hasDiscriminator)(account.data, disc))
121
+ return null;
122
+ return account.data.subarray(8);
123
+ }
124
+ function isRaydiumClmmAmmConfigAccount(data) {
125
+ return (0, utils_js_1.hasDiscriminator)(data, CLMM_AMM_CONFIG_DISC);
126
+ }
127
+ function isRaydiumClmmPoolStateAccount(data) {
128
+ return (0, utils_js_1.hasDiscriminator)(data, CLMM_POOL_STATE_DISC);
129
+ }
130
+ function isRaydiumClmmTickArrayStateAccount(data) {
131
+ return (0, utils_js_1.hasDiscriminator)(data, CLMM_TICK_ARRAY_STATE_DISC);
132
+ }
133
+ function isRaydiumCpmmAmmConfigAccount(data) {
134
+ return (0, utils_js_1.hasDiscriminator)(data, CPMM_AMM_CONFIG_DISC);
135
+ }
136
+ function isRaydiumCpmmPoolStateAccount(data) {
137
+ return (0, utils_js_1.hasDiscriminator)(data, CPMM_POOL_STATE_DISC);
138
+ }
139
+ function isOrcaWhirlpoolAccount(data) {
140
+ return (0, utils_js_1.hasDiscriminator)(data, ORCA_WHIRLPOOL_DISC);
141
+ }
142
+ function isOrcaPositionAccount(data) {
143
+ return (0, utils_js_1.hasDiscriminator)(data, ORCA_POSITION_DISC);
144
+ }
145
+ function isOrcaTickArrayAccount(data) {
146
+ return (0, utils_js_1.hasDiscriminator)(data, ORCA_TICK_ARRAY_DISC);
147
+ }
148
+ function isOrcaFeeTierAccount(data) {
149
+ return (0, utils_js_1.hasDiscriminator)(data, ORCA_FEE_TIER_DISC);
150
+ }
151
+ function isOrcaWhirlpoolsConfigAccount(data) {
152
+ return (0, utils_js_1.hasDiscriminator)(data, ORCA_WHIRLPOOLS_CONFIG_DISC);
153
+ }
154
+ function parseRaydiumClmmAccount(account, metadata) {
155
+ if (account.owner !== program_ids_js_1.RAYDIUM_CLMM_PROGRAM_ID)
156
+ return null;
157
+ return (parseRaydiumClmmAmmConfig(account, metadata) ??
158
+ parseRaydiumClmmPoolState(account, metadata) ??
159
+ parseRaydiumClmmTickArrayState(account, metadata));
160
+ }
161
+ function parseRaydiumCpmmAccount(account, metadata) {
162
+ if (account.owner !== program_ids_js_1.RAYDIUM_CPMM_PROGRAM_ID)
163
+ return null;
164
+ return parseRaydiumCpmmAmmConfig(account, metadata) ?? parseRaydiumCpmmPoolState(account, metadata);
165
+ }
166
+ function parseOrcaWhirlpoolAccount(account, metadata) {
167
+ if (account.owner !== program_ids_js_1.ORCA_WHIRLPOOL_PROGRAM_ID)
168
+ return null;
169
+ return (parseOrcaWhirlpool(account, metadata) ??
170
+ parseOrcaPosition(account, metadata) ??
171
+ parseOrcaTickArray(account, metadata) ??
172
+ parseOrcaFeeTier(account, metadata) ??
173
+ parseOrcaWhirlpoolsConfig(account, metadata));
174
+ }
175
+ function parseRaydiumClmmAmmConfig(account, metadata) {
176
+ const body = bodyAfterDiscriminator(account, CLMM_AMM_CONFIG_DISC, CLMM_AMM_CONFIG_BODY);
177
+ if (!body)
178
+ return null;
179
+ const amm_config = parseBody(body, (r) => ({
180
+ bump: r.u8(),
181
+ index: r.u16(),
182
+ owner: r.pubkey(),
183
+ protocol_fee_rate: r.u32(),
184
+ trade_fee_rate: r.u32(),
185
+ tick_spacing: r.u16(),
186
+ fund_fee_rate: r.u32(),
187
+ padding_u32: r.u32(),
188
+ fund_owner: r.pubkey(),
189
+ padding: readArray(3, () => r.u64()),
190
+ }));
191
+ return amm_config ? { RaydiumClmmAmmConfigAccount: { metadata, pubkey: account.pubkey, amm_config } } : null;
192
+ }
193
+ function parseRaydiumClmmPoolState(account, metadata) {
194
+ const body = bodyAfterDiscriminator(account, CLMM_POOL_STATE_DISC, CLMM_POOL_STATE_BODY);
195
+ if (!body)
196
+ return null;
197
+ const pool_state = parseBody(body, (r) => ({
198
+ bump: [r.u8()],
199
+ amm_config: r.pubkey(),
200
+ owner: r.pubkey(),
201
+ token_mint_0: r.pubkey(),
202
+ token_mint_1: r.pubkey(),
203
+ token_vault_0: r.pubkey(),
204
+ token_vault_1: r.pubkey(),
205
+ observation_key: r.pubkey(),
206
+ mint_decimals_0: r.u8(),
207
+ mint_decimals_1: r.u8(),
208
+ tick_spacing: r.u16(),
209
+ liquidity: r.u128(),
210
+ sqrt_price_x64: r.u128(),
211
+ tick_current: r.i32(),
212
+ padding3: r.u16(),
213
+ padding4: r.u16(),
214
+ fee_growth_global_0_x64: r.u128(),
215
+ fee_growth_global_1_x64: r.u128(),
216
+ protocol_fees_token_0: r.u64(),
217
+ protocol_fees_token_1: r.u64(),
218
+ padding5: readArray(4, () => r.u128()),
219
+ status: r.u8(),
220
+ fee_on: r.u8(),
221
+ padding: r.bytes(6),
222
+ reward_infos: readArray(3, () => readClmmRewardInfo(r)),
223
+ tick_array_bitmap: readArray(16, () => r.u64()),
224
+ padding6: readArray(4, () => r.u64()),
225
+ fund_fees_token_0: r.u64(),
226
+ fund_fees_token_1: r.u64(),
227
+ open_time: r.u64(),
228
+ recent_epoch: r.u64(),
229
+ dynamic_fee_info: readClmmDynamicFeeInfo(r),
230
+ padding1: readArray(14, () => r.u64()),
231
+ padding2: readArray(32, () => r.u64()),
232
+ }));
233
+ return pool_state ? { RaydiumClmmPoolStateAccount: { metadata, pubkey: account.pubkey, pool_state } } : null;
234
+ }
235
+ function parseRaydiumClmmTickArrayState(account, metadata) {
236
+ const body = bodyAfterDiscriminator(account, CLMM_TICK_ARRAY_STATE_DISC, CLMM_TICK_ARRAY_STATE_BODY);
237
+ if (!body)
238
+ return null;
239
+ const tick_array_state = parseBody(body, (r) => ({
240
+ pool_id: r.pubkey(),
241
+ start_tick_index: r.i32(),
242
+ ticks: readArray(CLMM_TICK_ARRAY_LEN, () => readClmmTick(r)),
243
+ initialized_tick_count: r.u8(),
244
+ recent_epoch: r.u64(),
245
+ padding: r.bytes(107),
246
+ }));
247
+ return tick_array_state
248
+ ? { RaydiumClmmTickArrayStateAccount: { metadata, pubkey: account.pubkey, tick_array_state } }
249
+ : null;
250
+ }
251
+ function readClmmRewardInfo(r) {
252
+ return {
253
+ reward_state: r.u8(),
254
+ open_time: r.u64(),
255
+ end_time: r.u64(),
256
+ last_update_time: r.u64(),
257
+ emissions_per_second_x64: r.u128(),
258
+ reward_total_emitted: r.u64(),
259
+ reward_claimed: r.u64(),
260
+ token_mint: r.pubkey(),
261
+ token_vault: r.pubkey(),
262
+ authority: r.pubkey(),
263
+ reward_growth_global_x64: r.u128(),
264
+ };
265
+ }
266
+ function readClmmDynamicFeeInfo(r) {
267
+ return {
268
+ filter_period: r.u16(),
269
+ decay_period: r.u16(),
270
+ reduction_factor: r.u16(),
271
+ dynamic_fee_control: r.u32(),
272
+ max_volatility_accumulator: r.u32(),
273
+ tick_spacing_index_reference: r.i32(),
274
+ volatility_reference: r.u32(),
275
+ volatility_accumulator: r.u32(),
276
+ last_update_timestamp: r.u64(),
277
+ padding: r.bytes(46),
278
+ };
279
+ }
280
+ function readClmmTick(r) {
281
+ return {
282
+ tick: r.i32(),
283
+ liquidity_net: r.i128(),
284
+ liquidity_gross: r.u128(),
285
+ fee_growth_outside_0_x64: r.u128(),
286
+ fee_growth_outside_1_x64: r.u128(),
287
+ reward_growths_outside_x64: readArray(3, () => r.u128()),
288
+ order_phase: r.u64(),
289
+ orders_amount: r.u64(),
290
+ part_filled_orders_remaining: r.u64(),
291
+ unfilled_ratio_x64: r.u128(),
292
+ padding: readArray(3, () => r.u32()),
293
+ };
294
+ }
295
+ function parseRaydiumCpmmAmmConfig(account, metadata) {
296
+ const body = bodyAfterDiscriminator(account, CPMM_AMM_CONFIG_DISC, CPMM_AMM_CONFIG_BODY);
297
+ if (!body)
298
+ return null;
299
+ const amm_config = parseBody(body, (r) => ({
300
+ bump: r.u8(),
301
+ disable_create_pool: r.bool(),
302
+ index: r.u16(),
303
+ trade_fee_rate: r.u64(),
304
+ protocol_fee_rate: r.u64(),
305
+ fund_fee_rate: r.u64(),
306
+ create_pool_fee: r.u64(),
307
+ protocol_owner: r.pubkey(),
308
+ fund_owner: r.pubkey(),
309
+ creator_fee_rate: r.u64(),
310
+ padding: readArray(15, () => r.u64()),
311
+ }));
312
+ return amm_config ? { RaydiumCpmmAmmConfigAccount: { metadata, pubkey: account.pubkey, amm_config } } : null;
313
+ }
314
+ function parseRaydiumCpmmPoolState(account, metadata) {
315
+ const body = bodyAfterDiscriminator(account, CPMM_POOL_STATE_DISC, CPMM_POOL_STATE_BODY);
316
+ if (!body)
317
+ return null;
318
+ const pool_state = parseBody(body, (r) => ({
319
+ amm_config: r.pubkey(),
320
+ pool_creator: r.pubkey(),
321
+ token_0_vault: r.pubkey(),
322
+ token_1_vault: r.pubkey(),
323
+ lp_mint: r.pubkey(),
324
+ token_0_mint: r.pubkey(),
325
+ token_1_mint: r.pubkey(),
326
+ token_0_program: r.pubkey(),
327
+ token_1_program: r.pubkey(),
328
+ observation_key: r.pubkey(),
329
+ auth_bump: r.u8(),
330
+ status: r.u8(),
331
+ lp_mint_decimals: r.u8(),
332
+ mint_0_decimals: r.u8(),
333
+ mint_1_decimals: r.u8(),
334
+ lp_supply: r.u64(),
335
+ protocol_fees_token_0: r.u64(),
336
+ protocol_fees_token_1: r.u64(),
337
+ fund_fees_token_0: r.u64(),
338
+ fund_fees_token_1: r.u64(),
339
+ open_time: r.u64(),
340
+ recent_epoch: r.u64(),
341
+ creator_fee_on: r.u8(),
342
+ enable_creator_fee: r.bool(),
343
+ padding1: r.bytes(6),
344
+ creator_fees_token_0: r.u64(),
345
+ creator_fees_token_1: r.u64(),
346
+ padding: readArray(28, () => r.u64()),
347
+ }));
348
+ return pool_state ? { RaydiumCpmmPoolStateAccount: { metadata, pubkey: account.pubkey, pool_state } } : null;
349
+ }
350
+ function parseOrcaWhirlpool(account, metadata) {
351
+ const body = bodyAfterDiscriminator(account, ORCA_WHIRLPOOL_DISC, ORCA_WHIRLPOOL_BODY);
352
+ if (!body)
353
+ return null;
354
+ const whirlpool = parseBody(body, (r) => ({
355
+ whirlpools_config: r.pubkey(),
356
+ whirlpool_bump: r.u8(),
357
+ tick_spacing: r.u16(),
358
+ tick_spacing_seed: r.bytes(2),
359
+ fee_rate: r.u16(),
360
+ protocol_fee_rate: r.u16(),
361
+ liquidity: r.u128(),
362
+ sqrt_price: r.u128(),
363
+ tick_current_index: r.i32(),
364
+ protocol_fee_owed_a: r.u64(),
365
+ protocol_fee_owed_b: r.u64(),
366
+ token_mint_a: r.pubkey(),
367
+ token_vault_a: r.pubkey(),
368
+ fee_growth_global_a: r.u128(),
369
+ token_mint_b: r.pubkey(),
370
+ token_vault_b: r.pubkey(),
371
+ fee_growth_global_b: r.u128(),
372
+ reward_last_updated_timestamp: r.u64(),
373
+ reward_infos: readArray(3, () => readOrcaWhirlpoolRewardInfo(r)),
374
+ }));
375
+ return whirlpool ? { OrcaWhirlpoolAccount: { metadata, pubkey: account.pubkey, whirlpool } } : null;
376
+ }
377
+ function parseOrcaPosition(account, metadata) {
378
+ const body = bodyAfterDiscriminator(account, ORCA_POSITION_DISC, ORCA_POSITION_BODY);
379
+ if (!body)
380
+ return null;
381
+ const position = parseBody(body, (r) => ({
382
+ whirlpool: r.pubkey(),
383
+ position_mint: r.pubkey(),
384
+ liquidity: r.u128(),
385
+ tick_lower_index: r.i32(),
386
+ tick_upper_index: r.i32(),
387
+ fee_growth_checkpoint_a: r.u128(),
388
+ fee_owed_a: r.u64(),
389
+ fee_growth_checkpoint_b: r.u128(),
390
+ fee_owed_b: r.u64(),
391
+ reward_infos: readArray(3, () => readOrcaPositionRewardInfo(r)),
392
+ }));
393
+ return position ? { OrcaPositionAccount: { metadata, pubkey: account.pubkey, position } } : null;
394
+ }
395
+ function parseOrcaTickArray(account, metadata) {
396
+ const body = bodyAfterDiscriminator(account, ORCA_TICK_ARRAY_DISC, ORCA_TICK_ARRAY_BODY);
397
+ if (!body)
398
+ return null;
399
+ const tick_array = parseBody(body, (r) => ({
400
+ start_tick_index: r.i32(),
401
+ ticks: readArray(ORCA_TICK_ARRAY_LEN, () => readOrcaTick(r)),
402
+ whirlpool: r.pubkey(),
403
+ }));
404
+ return tick_array ? { OrcaTickArrayAccount: { metadata, pubkey: account.pubkey, tick_array } } : null;
405
+ }
406
+ function parseOrcaFeeTier(account, metadata) {
407
+ const body = bodyAfterDiscriminator(account, ORCA_FEE_TIER_DISC, ORCA_FEE_TIER_BODY);
408
+ if (!body)
409
+ return null;
410
+ const fee_tier = parseBody(body, (r) => ({
411
+ whirlpools_config: r.pubkey(),
412
+ tick_spacing: r.u16(),
413
+ default_fee_rate: r.u16(),
414
+ }));
415
+ return fee_tier ? { OrcaFeeTierAccount: { metadata, pubkey: account.pubkey, fee_tier } } : null;
416
+ }
417
+ function parseOrcaWhirlpoolsConfig(account, metadata) {
418
+ const body = bodyAfterDiscriminator(account, ORCA_WHIRLPOOLS_CONFIG_DISC, ORCA_WHIRLPOOLS_CONFIG_BODY);
419
+ if (!body)
420
+ return null;
421
+ const config = parseBody(body, (r) => ({
422
+ fee_authority: r.pubkey(),
423
+ collect_protocol_fees_authority: r.pubkey(),
424
+ reward_emissions_super_authority: r.pubkey(),
425
+ default_protocol_fee_rate: r.u16(),
426
+ }));
427
+ return config ? { OrcaWhirlpoolsConfigAccount: { metadata, pubkey: account.pubkey, config } } : null;
428
+ }
429
+ function readOrcaWhirlpoolRewardInfo(r) {
430
+ return {
431
+ mint: r.pubkey(),
432
+ vault: r.pubkey(),
433
+ authority: r.pubkey(),
434
+ emissions_per_second_x64: r.u128(),
435
+ growth_global_x64: r.u128(),
436
+ };
437
+ }
438
+ function readOrcaPositionRewardInfo(r) {
439
+ return {
440
+ growth_inside_checkpoint: r.u128(),
441
+ amount_owed: r.u64(),
442
+ };
443
+ }
444
+ function readOrcaTick(r) {
445
+ return {
446
+ initialized: r.bool(),
447
+ liquidity_net: r.i128(),
448
+ liquidity_gross: r.u128(),
449
+ fee_growth_outside_a: r.u128(),
450
+ fee_growth_outside_b: r.u128(),
451
+ reward_growths_outside: readArray(3, () => r.u128()),
452
+ };
453
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 与 Rust `accounts::rpc_resolve_user_wallet_pubkey` 对齐(异步 RPC)。
3
+ */
4
+ import type { Connection } from "@solana/web3.js";
5
+ export declare function rpcResolveUserWalletPubkey(connection: Connection, addressBs58: string): Promise<string | null>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rpcResolveUserWalletPubkey = rpcResolveUserWalletPubkey;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const wallet_resolve_js_1 = require("./wallet_resolve.js");
6
+ async function rpcResolveUserWalletPubkey(connection, addressBs58) {
7
+ let pk;
8
+ try {
9
+ pk = new web3_js_1.PublicKey(addressBs58);
10
+ }
11
+ catch {
12
+ return null;
13
+ }
14
+ const acc = await connection.getAccountInfo(pk);
15
+ if (!acc)
16
+ return null;
17
+ return (0, wallet_resolve_js_1.userWalletPubkeyForOnchainAccount)(addressBs58, acc.owner.toBase58(), acc.data, acc.executable);
18
+ }