four-flap-meme-sdk 1.5.55 → 1.5.56

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 (150) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -1
  3. package/dist/sol/constants.d.ts +150 -0
  4. package/dist/sol/constants.js +188 -0
  5. package/dist/sol/dex/blockrazor/client.d.ts +51 -0
  6. package/dist/sol/dex/blockrazor/client.js +96 -0
  7. package/dist/sol/dex/blockrazor/constants.d.ts +34 -0
  8. package/dist/sol/dex/blockrazor/constants.js +55 -0
  9. package/dist/sol/dex/blockrazor/geyser.d.ts +128 -0
  10. package/dist/sol/dex/blockrazor/geyser.js +530 -0
  11. package/dist/sol/dex/blockrazor/index.d.ts +18 -0
  12. package/dist/sol/dex/blockrazor/index.js +23 -0
  13. package/dist/sol/dex/blockrazor/send.d.ts +135 -0
  14. package/dist/sol/dex/blockrazor/send.js +254 -0
  15. package/dist/sol/dex/blockrazor/types.d.ts +191 -0
  16. package/dist/sol/dex/blockrazor/types.js +5 -0
  17. package/dist/sol/dex/index.d.ts +10 -0
  18. package/dist/sol/dex/index.js +16 -0
  19. package/dist/sol/dex/jup/client.d.ts +33 -0
  20. package/dist/sol/dex/jup/client.js +110 -0
  21. package/dist/sol/dex/jup/index.d.ts +16 -0
  22. package/dist/sol/dex/jup/index.js +148 -0
  23. package/dist/sol/dex/jup/legacy.d.ts +623 -0
  24. package/dist/sol/dex/jup/legacy.js +416 -0
  25. package/dist/sol/dex/jup/lend.d.ts +640 -0
  26. package/dist/sol/dex/jup/lend.js +603 -0
  27. package/dist/sol/dex/jup/portfolio.d.ts +362 -0
  28. package/dist/sol/dex/jup/portfolio.js +367 -0
  29. package/dist/sol/dex/jup/price.d.ts +173 -0
  30. package/dist/sol/dex/jup/price.js +220 -0
  31. package/dist/sol/dex/jup/recurring.d.ts +437 -0
  32. package/dist/sol/dex/jup/recurring.js +320 -0
  33. package/dist/sol/dex/jup/send.d.ts +282 -0
  34. package/dist/sol/dex/jup/send.js +295 -0
  35. package/dist/sol/dex/jup/studio.d.ts +457 -0
  36. package/dist/sol/dex/jup/studio.js +488 -0
  37. package/dist/sol/dex/jup/tokens.d.ts +767 -0
  38. package/dist/sol/dex/jup/tokens.js +697 -0
  39. package/dist/sol/dex/jup/trigger.d.ts +511 -0
  40. package/dist/sol/dex/jup/trigger.js +397 -0
  41. package/dist/sol/dex/jup/types.d.ts +433 -0
  42. package/dist/sol/dex/jup/types.js +5 -0
  43. package/dist/sol/dex/jup/ultra.d.ts +646 -0
  44. package/dist/sol/dex/jup/ultra.js +853 -0
  45. package/dist/sol/dex/meteora/client.d.ts +76 -0
  46. package/dist/sol/dex/meteora/client.js +219 -0
  47. package/dist/sol/dex/meteora/damm-v1-bundle.d.ts +61 -0
  48. package/dist/sol/dex/meteora/damm-v1-bundle.js +112 -0
  49. package/dist/sol/dex/meteora/damm-v1.d.ts +118 -0
  50. package/dist/sol/dex/meteora/damm-v1.js +315 -0
  51. package/dist/sol/dex/meteora/damm-v2-bundle.d.ts +82 -0
  52. package/dist/sol/dex/meteora/damm-v2-bundle.js +242 -0
  53. package/dist/sol/dex/meteora/damm-v2.d.ts +172 -0
  54. package/dist/sol/dex/meteora/damm-v2.js +632 -0
  55. package/dist/sol/dex/meteora/dbc-bundle.d.ts +123 -0
  56. package/dist/sol/dex/meteora/dbc-bundle.js +304 -0
  57. package/dist/sol/dex/meteora/dbc.d.ts +192 -0
  58. package/dist/sol/dex/meteora/dbc.js +619 -0
  59. package/dist/sol/dex/meteora/dlmm-bundle.d.ts +39 -0
  60. package/dist/sol/dex/meteora/dlmm-bundle.js +189 -0
  61. package/dist/sol/dex/meteora/dlmm.d.ts +157 -0
  62. package/dist/sol/dex/meteora/dlmm.js +671 -0
  63. package/dist/sol/dex/meteora/index.d.ts +25 -0
  64. package/dist/sol/dex/meteora/index.js +65 -0
  65. package/dist/sol/dex/meteora/types.d.ts +787 -0
  66. package/dist/sol/dex/meteora/types.js +110 -0
  67. package/dist/sol/dex/orca/index.d.ts +10 -0
  68. package/dist/sol/dex/orca/index.js +16 -0
  69. package/dist/sol/dex/orca/orca-bundle.d.ts +41 -0
  70. package/dist/sol/dex/orca/orca-bundle.js +173 -0
  71. package/dist/sol/dex/orca/orca.d.ts +65 -0
  72. package/dist/sol/dex/orca/orca.js +474 -0
  73. package/dist/sol/dex/orca/types.d.ts +263 -0
  74. package/dist/sol/dex/orca/types.js +38 -0
  75. package/dist/sol/dex/orca/wavebreak-bundle.d.ts +34 -0
  76. package/dist/sol/dex/orca/wavebreak-bundle.js +198 -0
  77. package/dist/sol/dex/orca/wavebreak-types.d.ts +227 -0
  78. package/dist/sol/dex/orca/wavebreak-types.js +23 -0
  79. package/dist/sol/dex/orca/wavebreak.d.ts +78 -0
  80. package/dist/sol/dex/orca/wavebreak.js +497 -0
  81. package/dist/sol/dex/pump/index.d.ts +9 -0
  82. package/dist/sol/dex/pump/index.js +14 -0
  83. package/dist/sol/dex/pump/pump-bundle.d.ts +92 -0
  84. package/dist/sol/dex/pump/pump-bundle.js +383 -0
  85. package/dist/sol/dex/pump/pump-swap-bundle.d.ts +103 -0
  86. package/dist/sol/dex/pump/pump-swap-bundle.js +380 -0
  87. package/dist/sol/dex/pump/pump-swap.d.ts +46 -0
  88. package/dist/sol/dex/pump/pump-swap.js +199 -0
  89. package/dist/sol/dex/pump/pump.d.ts +35 -0
  90. package/dist/sol/dex/pump/pump.js +352 -0
  91. package/dist/sol/dex/pump/types.d.ts +215 -0
  92. package/dist/sol/dex/pump/types.js +5 -0
  93. package/dist/sol/dex/raydium/index.d.ts +8 -0
  94. package/dist/sol/dex/raydium/index.js +12 -0
  95. package/dist/sol/dex/raydium/launchlab.d.ts +68 -0
  96. package/dist/sol/dex/raydium/launchlab.js +210 -0
  97. package/dist/sol/dex/raydium/raydium-bundle.d.ts +64 -0
  98. package/dist/sol/dex/raydium/raydium-bundle.js +324 -0
  99. package/dist/sol/dex/raydium/raydium.d.ts +40 -0
  100. package/dist/sol/dex/raydium/raydium.js +366 -0
  101. package/dist/sol/dex/raydium/types.d.ts +240 -0
  102. package/dist/sol/dex/raydium/types.js +5 -0
  103. package/dist/sol/index.d.ts +11 -0
  104. package/dist/sol/index.js +18 -0
  105. package/dist/sol/jito/bundle.d.ts +90 -0
  106. package/dist/sol/jito/bundle.js +263 -0
  107. package/dist/sol/jito/index.d.ts +7 -0
  108. package/dist/sol/jito/index.js +7 -0
  109. package/dist/sol/jito/tip.d.ts +51 -0
  110. package/dist/sol/jito/tip.js +83 -0
  111. package/dist/sol/jito/types.d.ts +100 -0
  112. package/dist/sol/jito/types.js +5 -0
  113. package/dist/sol/nozomi/client.d.ts +63 -0
  114. package/dist/sol/nozomi/client.js +222 -0
  115. package/dist/sol/nozomi/index.d.ts +8 -0
  116. package/dist/sol/nozomi/index.js +8 -0
  117. package/dist/sol/nozomi/tip.d.ts +50 -0
  118. package/dist/sol/nozomi/tip.js +80 -0
  119. package/dist/sol/nozomi/types.d.ts +96 -0
  120. package/dist/sol/nozomi/types.js +5 -0
  121. package/dist/sol/token/create-complete.d.ts +115 -0
  122. package/dist/sol/token/create-complete.js +235 -0
  123. package/dist/sol/token/create-token.d.ts +57 -0
  124. package/dist/sol/token/create-token.js +230 -0
  125. package/dist/sol/token/index.d.ts +9 -0
  126. package/dist/sol/token/index.js +14 -0
  127. package/dist/sol/token/metadata-upload.d.ts +86 -0
  128. package/dist/sol/token/metadata-upload.js +173 -0
  129. package/dist/sol/token/metadata.d.ts +92 -0
  130. package/dist/sol/token/metadata.js +274 -0
  131. package/dist/sol/token/types.d.ts +153 -0
  132. package/dist/sol/token/types.js +5 -0
  133. package/dist/sol/types.d.ts +176 -0
  134. package/dist/sol/types.js +7 -0
  135. package/dist/sol/utils/balance.d.ts +160 -0
  136. package/dist/sol/utils/balance.js +638 -0
  137. package/dist/sol/utils/connection.d.ts +78 -0
  138. package/dist/sol/utils/connection.js +168 -0
  139. package/dist/sol/utils/index.d.ts +9 -0
  140. package/dist/sol/utils/index.js +9 -0
  141. package/dist/sol/utils/lp-inspect.d.ts +75 -0
  142. package/dist/sol/utils/lp-inspect.js +235 -0
  143. package/dist/sol/utils/transfer.d.ts +196 -0
  144. package/dist/sol/utils/transfer.js +307 -0
  145. package/dist/sol/utils/wallet.d.ts +107 -0
  146. package/dist/sol/utils/wallet.js +210 -0
  147. package/package.json +44 -5
  148. package/README.zh-CN.pdf +0 -0
  149. package/dist/flap/portal-bundle-merkle/encryption.d.ts +0 -16
  150. package/dist/flap/portal-bundle-merkle/encryption.js +0 -146
@@ -0,0 +1,128 @@
1
+ /**
2
+ * BlockRazor Geyser Stream 服务
3
+ * @module sol/dex/blockrazor/geyser
4
+ *
5
+ * Geyser Stream 是基于 Yellowstone gRPC 的高性能 Solana 数据流服务。
6
+ *
7
+ * @see https://blockrazor.gitbook.io/blockrazor/solana/geyser-stream
8
+ */
9
+ import type { GeyserRegion, GeyserSubscribeConfig, GeyserClientConfig, GeyserEventHandlers, GeyserStreamControl } from './types.js';
10
+ /**
11
+ * Geyser Proto 定义(内联)
12
+ *
13
+ * 用于动态加载 gRPC 服务
14
+ */
15
+ export declare const GEYSER_PROTO_DEFINITION = "\nsyntax = \"proto3\";\n\npackage geyser;\n\nservice Geyser {\n rpc Subscribe(stream SubscribeRequest) returns (stream SubscribeUpdate);\n}\n\nmessage SubscribeRequest {\n map<string, SubscribeRequestFilterAccounts> accounts = 1;\n map<string, SubscribeRequestFilterSlots> slots = 2;\n map<string, SubscribeRequestFilterTransactions> transactions = 3;\n map<string, SubscribeRequestFilterBlocks> blocks = 4;\n map<string, SubscribeRequestFilterBlocksMeta> blocks_meta = 5;\n map<string, SubscribeRequestFilterEntry> entry = 6;\n optional CommitmentLevel commitment = 7;\n repeated SubscribeRequestAccountsDataSlice accounts_data_slice = 8;\n optional SubscribeRequestPing ping = 9;\n}\n\nenum CommitmentLevel {\n PROCESSED = 0;\n CONFIRMED = 1;\n FINALIZED = 2;\n}\n\nmessage SubscribeRequestFilterAccounts {\n repeated string account = 1;\n repeated string owner = 2;\n repeated SubscribeRequestFilterAccountsFilter filters = 3;\n optional bool nonempty_txn_signature = 4;\n}\n\nmessage SubscribeRequestFilterAccountsFilter {\n oneof filter {\n SubscribeRequestFilterAccountsFilterMemcmp memcmp = 1;\n uint64 datasize = 2;\n bool token_account_state = 3;\n SubscribeRequestFilterAccountsFilterLamports lamports = 4;\n }\n}\n\nmessage SubscribeRequestFilterAccountsFilterMemcmp {\n uint64 offset = 1;\n oneof data {\n bytes bytes = 2;\n string base58 = 3;\n string base64 = 4;\n }\n}\n\nmessage SubscribeRequestFilterAccountsFilterLamports {\n oneof cmp {\n uint64 eq = 1;\n uint64 ne = 2;\n uint64 lt = 3;\n uint64 gt = 4;\n }\n}\n\nmessage SubscribeRequestFilterSlots {\n optional bool filter_by_commitment = 1;\n optional bool interleave_global_updates = 2;\n}\n\nmessage SubscribeRequestFilterTransactions {\n optional bool vote = 1;\n optional bool failed = 2;\n optional string signature = 3;\n repeated string account_include = 4;\n repeated string account_exclude = 5;\n repeated string account_required = 6;\n}\n\nmessage SubscribeRequestFilterBlocks {\n repeated string account_include = 1;\n optional bool include_transactions = 2;\n optional bool include_accounts = 3;\n optional bool include_entries = 4;\n}\n\nmessage SubscribeRequestFilterBlocksMeta {}\n\nmessage SubscribeRequestFilterEntry {}\n\nmessage SubscribeRequestAccountsDataSlice {\n uint64 offset = 1;\n uint64 length = 2;\n}\n\nmessage SubscribeRequestPing {\n int32 id = 1;\n}\n\nmessage SubscribeUpdate {\n repeated string filters = 1;\n oneof update_oneof {\n SubscribeUpdateAccount account = 2;\n SubscribeUpdateSlot slot = 3;\n SubscribeUpdateTransaction transaction = 4;\n SubscribeUpdateTransactionInfo transaction_info = 10;\n SubscribeUpdateBlock block = 5;\n SubscribeUpdatePing ping = 6;\n SubscribeUpdatePong pong = 7;\n SubscribeUpdateBlockMeta block_meta = 8;\n SubscribeUpdateEntry entry = 9;\n }\n uint64 created_at = 11;\n}\n\nmessage SubscribeUpdateAccount {\n SubscribeUpdateAccountInfo account = 1;\n uint64 slot = 2;\n optional bool is_startup = 3;\n}\n\nmessage SubscribeUpdateAccountInfo {\n bytes pubkey = 1;\n uint64 lamports = 2;\n bytes owner = 3;\n bool executable = 4;\n uint64 rent_epoch = 5;\n bytes data = 6;\n uint64 write_version = 7;\n optional bytes txn_signature = 8;\n}\n\nmessage SubscribeUpdateSlot {\n uint64 slot = 1;\n optional uint64 parent = 2;\n CommitmentLevel status = 3;\n optional int64 dead_error = 4;\n}\n\nmessage SubscribeUpdateTransaction {\n SubscribeUpdateTransactionInfo transaction = 1;\n uint64 slot = 2;\n}\n\nmessage SubscribeUpdateTransactionInfo {\n bytes signature = 1;\n bool is_vote = 2;\n bytes transaction = 3;\n bytes meta = 4;\n optional uint64 index = 5;\n}\n\nmessage SubscribeUpdateBlock {\n uint64 slot = 1;\n string blockhash = 2;\n SubscribeUpdateBlockRewards rewards = 3;\n UnixTimestamp block_time = 4;\n BlockHeight block_height = 5;\n uint64 parent_slot = 6;\n string parent_blockhash = 7;\n uint64 executed_transaction_count = 8;\n uint64 entries_count = 9;\n repeated SubscribeUpdateTransactionInfo transactions = 10;\n repeated SubscribeUpdateAccountInfo updated_account_count = 11;\n repeated SubscribeUpdateEntry entries = 12;\n}\n\nmessage SubscribeUpdateBlockRewards {\n bytes rewards = 1;\n}\n\nmessage UnixTimestamp {\n int64 timestamp = 1;\n}\n\nmessage BlockHeight {\n uint64 block_height = 1;\n}\n\nmessage SubscribeUpdatePing {}\n\nmessage SubscribeUpdatePong {\n int32 id = 1;\n}\n\nmessage SubscribeUpdateBlockMeta {\n uint64 slot = 1;\n string blockhash = 2;\n SubscribeUpdateBlockRewards rewards = 3;\n UnixTimestamp block_time = 4;\n BlockHeight block_height = 5;\n uint64 parent_slot = 6;\n string parent_blockhash = 7;\n uint64 executed_transaction_count = 8;\n uint64 entries_count = 9;\n}\n\nmessage SubscribeUpdateEntry {\n uint64 slot = 1;\n uint64 index = 2;\n uint64 num_hashes = 3;\n bytes hash = 4;\n uint64 executed_transaction_count = 5;\n optional uint64 starting_transaction_index = 6;\n}\n";
16
+ /**
17
+ * 获取 Geyser Stream 端点
18
+ *
19
+ * @param region 区域
20
+ * @returns gRPC 端点地址
21
+ */
22
+ export declare function getGeyserEndpoint(region?: GeyserRegion): string;
23
+ /**
24
+ * 构建 Geyser 订阅请求
25
+ *
26
+ * @param config 订阅配置
27
+ * @returns gRPC 请求对象
28
+ */
29
+ export declare function buildGeyserSubscribeRequest(config: GeyserSubscribeConfig): Record<string, unknown>;
30
+ /**
31
+ * 创建默认账户订阅配置
32
+ *
33
+ * @param owners 拥有者地址列表
34
+ * @param accounts 特定账户地址列表
35
+ * @returns 订阅配置
36
+ */
37
+ export declare function createAccountSubscribeConfig(owners?: string[], accounts?: string[]): GeyserSubscribeConfig;
38
+ /**
39
+ * 创建默认交易订阅配置
40
+ *
41
+ * @param accountInclude 包含涉及这些账户的交易
42
+ * @param accountRequired 交易必须涉及这些账户
43
+ * @returns 订阅配置
44
+ */
45
+ export declare function createTransactionSubscribeConfig(accountInclude?: string[], accountRequired?: string[]): GeyserSubscribeConfig;
46
+ /**
47
+ * 创建默认区块订阅配置
48
+ *
49
+ * @param accountInclude 包含涉及这些账户的区块
50
+ * @param includeTransactions 是否包含交易
51
+ * @returns 订阅配置
52
+ */
53
+ export declare function createBlockSubscribeConfig(accountInclude?: string[], includeTransactions?: boolean): GeyserSubscribeConfig;
54
+ /**
55
+ * 创建 Geyser 订阅(需要 @grpc/grpc-js 和 @grpc/proto-loader)
56
+ *
57
+ * 注意:此函数需要安装 gRPC 依赖:
58
+ * ```bash
59
+ * npm install @grpc/grpc-js @grpc/proto-loader
60
+ * ```
61
+ *
62
+ * @param clientConfig 客户端配置
63
+ * @param subscribeConfig 订阅配置
64
+ * @param handlers 事件处理器
65
+ * @returns 流控制对象
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * import { Sol } from 'four-flap-meme-sdk'
70
+ * import bs58 from 'bs58'
71
+ *
72
+ * const stream = await Sol.createGeyserSubscription(
73
+ * {
74
+ * host: Sol.getGeyserEndpoint('tokyo'),
75
+ * token: 'your-auth-token',
76
+ * },
77
+ * Sol.createTransactionSubscribeConfig(
78
+ * ['your-account-address'], // 监听涉及此账户的交易
79
+ * ),
80
+ * {
81
+ * onTransaction: (update, raw) => {
82
+ * console.log(`交易: ${bs58.encode(update.transaction.signature)}`)
83
+ * },
84
+ * onError: (err) => console.error('错误:', err),
85
+ * onEnd: () => console.log('流结束'),
86
+ * },
87
+ * )
88
+ *
89
+ * // 关闭流
90
+ * stream.close()
91
+ * ```
92
+ */
93
+ export declare function createGeyserSubscription(clientConfig: GeyserClientConfig, subscribeConfig: GeyserSubscribeConfig, handlers: GeyserEventHandlers): Promise<GeyserStreamControl>;
94
+ /**
95
+ * 简化版:订阅账户更新
96
+ *
97
+ * @param token 认证 Token
98
+ * @param accounts 账户地址列表
99
+ * @param onUpdate 更新回调
100
+ * @param region 区域(默认 tokyo)
101
+ * @returns 流控制对象
102
+ */
103
+ export declare function subscribeGeyserAccounts(token: string, accounts: string[], onUpdate: (pubkey: string, lamports: string, slot: string) => void, region?: GeyserRegion): Promise<{
104
+ close: () => void;
105
+ }>;
106
+ /**
107
+ * 简化版:订阅交易更新
108
+ *
109
+ * @param token 认证 Token
110
+ * @param accountInclude 包含涉及这些账户的交易
111
+ * @param onUpdate 更新回调
112
+ * @param region 区域(默认 tokyo)
113
+ * @returns 流控制对象
114
+ */
115
+ export declare function subscribeGeyserTransactions(token: string, accountInclude: string[], onUpdate: (signature: string, isVote: boolean, slot: string) => void, region?: GeyserRegion): Promise<{
116
+ close: () => void;
117
+ }>;
118
+ /**
119
+ * 简化版:订阅区块更新
120
+ *
121
+ * @param token 认证 Token
122
+ * @param onUpdate 更新回调
123
+ * @param region 区域(默认 tokyo)
124
+ * @returns 流控制对象
125
+ */
126
+ export declare function subscribeGeyserBlocks(token: string, onUpdate: (slot: string, blockhash: string, txCount: number) => void, region?: GeyserRegion): Promise<{
127
+ close: () => void;
128
+ }>;
@@ -0,0 +1,530 @@
1
+ /**
2
+ * BlockRazor Geyser Stream 服务
3
+ * @module sol/dex/blockrazor/geyser
4
+ *
5
+ * Geyser Stream 是基于 Yellowstone gRPC 的高性能 Solana 数据流服务。
6
+ *
7
+ * @see https://blockrazor.gitbook.io/blockrazor/solana/geyser-stream
8
+ */
9
+ import { GEYSER_STREAM_ENDPOINTS } from './constants.js';
10
+ // ============================================================================
11
+ // Geyser Proto 定义
12
+ // ============================================================================
13
+ /**
14
+ * Geyser Proto 定义(内联)
15
+ *
16
+ * 用于动态加载 gRPC 服务
17
+ */
18
+ export const GEYSER_PROTO_DEFINITION = `
19
+ syntax = "proto3";
20
+
21
+ package geyser;
22
+
23
+ service Geyser {
24
+ rpc Subscribe(stream SubscribeRequest) returns (stream SubscribeUpdate);
25
+ }
26
+
27
+ message SubscribeRequest {
28
+ map<string, SubscribeRequestFilterAccounts> accounts = 1;
29
+ map<string, SubscribeRequestFilterSlots> slots = 2;
30
+ map<string, SubscribeRequestFilterTransactions> transactions = 3;
31
+ map<string, SubscribeRequestFilterBlocks> blocks = 4;
32
+ map<string, SubscribeRequestFilterBlocksMeta> blocks_meta = 5;
33
+ map<string, SubscribeRequestFilterEntry> entry = 6;
34
+ optional CommitmentLevel commitment = 7;
35
+ repeated SubscribeRequestAccountsDataSlice accounts_data_slice = 8;
36
+ optional SubscribeRequestPing ping = 9;
37
+ }
38
+
39
+ enum CommitmentLevel {
40
+ PROCESSED = 0;
41
+ CONFIRMED = 1;
42
+ FINALIZED = 2;
43
+ }
44
+
45
+ message SubscribeRequestFilterAccounts {
46
+ repeated string account = 1;
47
+ repeated string owner = 2;
48
+ repeated SubscribeRequestFilterAccountsFilter filters = 3;
49
+ optional bool nonempty_txn_signature = 4;
50
+ }
51
+
52
+ message SubscribeRequestFilterAccountsFilter {
53
+ oneof filter {
54
+ SubscribeRequestFilterAccountsFilterMemcmp memcmp = 1;
55
+ uint64 datasize = 2;
56
+ bool token_account_state = 3;
57
+ SubscribeRequestFilterAccountsFilterLamports lamports = 4;
58
+ }
59
+ }
60
+
61
+ message SubscribeRequestFilterAccountsFilterMemcmp {
62
+ uint64 offset = 1;
63
+ oneof data {
64
+ bytes bytes = 2;
65
+ string base58 = 3;
66
+ string base64 = 4;
67
+ }
68
+ }
69
+
70
+ message SubscribeRequestFilterAccountsFilterLamports {
71
+ oneof cmp {
72
+ uint64 eq = 1;
73
+ uint64 ne = 2;
74
+ uint64 lt = 3;
75
+ uint64 gt = 4;
76
+ }
77
+ }
78
+
79
+ message SubscribeRequestFilterSlots {
80
+ optional bool filter_by_commitment = 1;
81
+ optional bool interleave_global_updates = 2;
82
+ }
83
+
84
+ message SubscribeRequestFilterTransactions {
85
+ optional bool vote = 1;
86
+ optional bool failed = 2;
87
+ optional string signature = 3;
88
+ repeated string account_include = 4;
89
+ repeated string account_exclude = 5;
90
+ repeated string account_required = 6;
91
+ }
92
+
93
+ message SubscribeRequestFilterBlocks {
94
+ repeated string account_include = 1;
95
+ optional bool include_transactions = 2;
96
+ optional bool include_accounts = 3;
97
+ optional bool include_entries = 4;
98
+ }
99
+
100
+ message SubscribeRequestFilterBlocksMeta {}
101
+
102
+ message SubscribeRequestFilterEntry {}
103
+
104
+ message SubscribeRequestAccountsDataSlice {
105
+ uint64 offset = 1;
106
+ uint64 length = 2;
107
+ }
108
+
109
+ message SubscribeRequestPing {
110
+ int32 id = 1;
111
+ }
112
+
113
+ message SubscribeUpdate {
114
+ repeated string filters = 1;
115
+ oneof update_oneof {
116
+ SubscribeUpdateAccount account = 2;
117
+ SubscribeUpdateSlot slot = 3;
118
+ SubscribeUpdateTransaction transaction = 4;
119
+ SubscribeUpdateTransactionInfo transaction_info = 10;
120
+ SubscribeUpdateBlock block = 5;
121
+ SubscribeUpdatePing ping = 6;
122
+ SubscribeUpdatePong pong = 7;
123
+ SubscribeUpdateBlockMeta block_meta = 8;
124
+ SubscribeUpdateEntry entry = 9;
125
+ }
126
+ uint64 created_at = 11;
127
+ }
128
+
129
+ message SubscribeUpdateAccount {
130
+ SubscribeUpdateAccountInfo account = 1;
131
+ uint64 slot = 2;
132
+ optional bool is_startup = 3;
133
+ }
134
+
135
+ message SubscribeUpdateAccountInfo {
136
+ bytes pubkey = 1;
137
+ uint64 lamports = 2;
138
+ bytes owner = 3;
139
+ bool executable = 4;
140
+ uint64 rent_epoch = 5;
141
+ bytes data = 6;
142
+ uint64 write_version = 7;
143
+ optional bytes txn_signature = 8;
144
+ }
145
+
146
+ message SubscribeUpdateSlot {
147
+ uint64 slot = 1;
148
+ optional uint64 parent = 2;
149
+ CommitmentLevel status = 3;
150
+ optional int64 dead_error = 4;
151
+ }
152
+
153
+ message SubscribeUpdateTransaction {
154
+ SubscribeUpdateTransactionInfo transaction = 1;
155
+ uint64 slot = 2;
156
+ }
157
+
158
+ message SubscribeUpdateTransactionInfo {
159
+ bytes signature = 1;
160
+ bool is_vote = 2;
161
+ bytes transaction = 3;
162
+ bytes meta = 4;
163
+ optional uint64 index = 5;
164
+ }
165
+
166
+ message SubscribeUpdateBlock {
167
+ uint64 slot = 1;
168
+ string blockhash = 2;
169
+ SubscribeUpdateBlockRewards rewards = 3;
170
+ UnixTimestamp block_time = 4;
171
+ BlockHeight block_height = 5;
172
+ uint64 parent_slot = 6;
173
+ string parent_blockhash = 7;
174
+ uint64 executed_transaction_count = 8;
175
+ uint64 entries_count = 9;
176
+ repeated SubscribeUpdateTransactionInfo transactions = 10;
177
+ repeated SubscribeUpdateAccountInfo updated_account_count = 11;
178
+ repeated SubscribeUpdateEntry entries = 12;
179
+ }
180
+
181
+ message SubscribeUpdateBlockRewards {
182
+ bytes rewards = 1;
183
+ }
184
+
185
+ message UnixTimestamp {
186
+ int64 timestamp = 1;
187
+ }
188
+
189
+ message BlockHeight {
190
+ uint64 block_height = 1;
191
+ }
192
+
193
+ message SubscribeUpdatePing {}
194
+
195
+ message SubscribeUpdatePong {
196
+ int32 id = 1;
197
+ }
198
+
199
+ message SubscribeUpdateBlockMeta {
200
+ uint64 slot = 1;
201
+ string blockhash = 2;
202
+ SubscribeUpdateBlockRewards rewards = 3;
203
+ UnixTimestamp block_time = 4;
204
+ BlockHeight block_height = 5;
205
+ uint64 parent_slot = 6;
206
+ string parent_blockhash = 7;
207
+ uint64 executed_transaction_count = 8;
208
+ uint64 entries_count = 9;
209
+ }
210
+
211
+ message SubscribeUpdateEntry {
212
+ uint64 slot = 1;
213
+ uint64 index = 2;
214
+ uint64 num_hashes = 3;
215
+ bytes hash = 4;
216
+ uint64 executed_transaction_count = 5;
217
+ optional uint64 starting_transaction_index = 6;
218
+ }
219
+ `;
220
+ // ============================================================================
221
+ // 辅助函数
222
+ // ============================================================================
223
+ /**
224
+ * 获取 Geyser Stream 端点
225
+ *
226
+ * @param region 区域
227
+ * @returns gRPC 端点地址
228
+ */
229
+ export function getGeyserEndpoint(region = 'tokyo') {
230
+ switch (region) {
231
+ case 'tokyo':
232
+ return GEYSER_STREAM_ENDPOINTS.TOKYO;
233
+ case 'frankfurt':
234
+ return GEYSER_STREAM_ENDPOINTS.FRANKFURT;
235
+ case 'newyork':
236
+ return GEYSER_STREAM_ENDPOINTS.NEW_YORK;
237
+ case 'amsterdam':
238
+ return GEYSER_STREAM_ENDPOINTS.AMSTERDAM;
239
+ default:
240
+ return GEYSER_STREAM_ENDPOINTS.TOKYO;
241
+ }
242
+ }
243
+ /**
244
+ * 构建 Geyser 订阅请求
245
+ *
246
+ * @param config 订阅配置
247
+ * @returns gRPC 请求对象
248
+ */
249
+ export function buildGeyserSubscribeRequest(config) {
250
+ const request = {};
251
+ // 账户订阅
252
+ if (config.subscribeAccounts && config.accountParams) {
253
+ const { filterKey, owners, accounts, filters, nonemptyTxnSignature } = config.accountParams;
254
+ request.accounts = {
255
+ [filterKey]: {
256
+ owner: owners || [],
257
+ account: accounts || [],
258
+ filters: filters || [],
259
+ nonempty_txn_signature: nonemptyTxnSignature || false,
260
+ },
261
+ };
262
+ }
263
+ // 区块订阅
264
+ if (config.subscribeBlocks && config.blockParams) {
265
+ const { filterKey, accountInclude, includeTransactions, includeAccounts, includeEntries } = config.blockParams;
266
+ request.blocks = {
267
+ [filterKey]: {
268
+ account_include: accountInclude || [],
269
+ include_transactions: includeTransactions ?? true,
270
+ include_accounts: includeAccounts ?? false,
271
+ include_entries: includeEntries ?? false,
272
+ },
273
+ };
274
+ }
275
+ // 交易订阅
276
+ if (config.subscribeTransactions && config.transactionParams) {
277
+ const { filterKey, vote, failed, accountInclude, accountExclude, accountRequired, signature } = config.transactionParams;
278
+ request.transactions = {
279
+ [filterKey]: {
280
+ vote: vote ?? false,
281
+ failed: failed ?? false,
282
+ account_include: accountInclude || [],
283
+ account_exclude: accountExclude || [],
284
+ account_required: accountRequired || [],
285
+ signature: signature || null,
286
+ },
287
+ };
288
+ }
289
+ // Commitment
290
+ request.commitment = config.commitment || 'CONFIRMED';
291
+ return request;
292
+ }
293
+ // ============================================================================
294
+ // 配置工厂函数
295
+ // ============================================================================
296
+ /**
297
+ * 创建默认账户订阅配置
298
+ *
299
+ * @param owners 拥有者地址列表
300
+ * @param accounts 特定账户地址列表
301
+ * @returns 订阅配置
302
+ */
303
+ export function createAccountSubscribeConfig(owners, accounts) {
304
+ return {
305
+ commitment: 'CONFIRMED',
306
+ subscribeAccounts: true,
307
+ accountParams: {
308
+ filterKey: 'account-filter',
309
+ owners: owners || [],
310
+ accounts: accounts || [],
311
+ filters: [],
312
+ nonemptyTxnSignature: false,
313
+ },
314
+ };
315
+ }
316
+ /**
317
+ * 创建默认交易订阅配置
318
+ *
319
+ * @param accountInclude 包含涉及这些账户的交易
320
+ * @param accountRequired 交易必须涉及这些账户
321
+ * @returns 订阅配置
322
+ */
323
+ export function createTransactionSubscribeConfig(accountInclude, accountRequired) {
324
+ return {
325
+ commitment: 'CONFIRMED',
326
+ subscribeTransactions: true,
327
+ transactionParams: {
328
+ filterKey: 'tx-filter',
329
+ vote: false,
330
+ failed: false,
331
+ accountInclude: accountInclude || [],
332
+ accountExclude: [],
333
+ accountRequired: accountRequired || [],
334
+ signature: null,
335
+ },
336
+ };
337
+ }
338
+ /**
339
+ * 创建默认区块订阅配置
340
+ *
341
+ * @param accountInclude 包含涉及这些账户的区块
342
+ * @param includeTransactions 是否包含交易
343
+ * @returns 订阅配置
344
+ */
345
+ export function createBlockSubscribeConfig(accountInclude, includeTransactions = true) {
346
+ return {
347
+ commitment: 'CONFIRMED',
348
+ subscribeBlocks: true,
349
+ blockParams: {
350
+ filterKey: 'block-filter',
351
+ accountInclude: accountInclude || [],
352
+ includeTransactions,
353
+ includeAccounts: false,
354
+ includeEntries: false,
355
+ },
356
+ };
357
+ }
358
+ // ============================================================================
359
+ // Geyser 订阅
360
+ // ============================================================================
361
+ /**
362
+ * 创建 Geyser 订阅(需要 @grpc/grpc-js 和 @grpc/proto-loader)
363
+ *
364
+ * 注意:此函数需要安装 gRPC 依赖:
365
+ * ```bash
366
+ * npm install @grpc/grpc-js @grpc/proto-loader
367
+ * ```
368
+ *
369
+ * @param clientConfig 客户端配置
370
+ * @param subscribeConfig 订阅配置
371
+ * @param handlers 事件处理器
372
+ * @returns 流控制对象
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * import { Sol } from 'four-flap-meme-sdk'
377
+ * import bs58 from 'bs58'
378
+ *
379
+ * const stream = await Sol.createGeyserSubscription(
380
+ * {
381
+ * host: Sol.getGeyserEndpoint('tokyo'),
382
+ * token: 'your-auth-token',
383
+ * },
384
+ * Sol.createTransactionSubscribeConfig(
385
+ * ['your-account-address'], // 监听涉及此账户的交易
386
+ * ),
387
+ * {
388
+ * onTransaction: (update, raw) => {
389
+ * console.log(`交易: ${bs58.encode(update.transaction.signature)}`)
390
+ * },
391
+ * onError: (err) => console.error('错误:', err),
392
+ * onEnd: () => console.log('流结束'),
393
+ * },
394
+ * )
395
+ *
396
+ * // 关闭流
397
+ * stream.close()
398
+ * ```
399
+ */
400
+ export async function createGeyserSubscription(clientConfig, subscribeConfig, handlers) {
401
+ // 动态导入 gRPC 依赖(可选依赖)
402
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
403
+ let grpc;
404
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
405
+ let protoLoader;
406
+ try {
407
+ // 使用动态 require 避免类型检查问题
408
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
409
+ grpc = require('@grpc/grpc-js');
410
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
411
+ protoLoader = require('@grpc/proto-loader');
412
+ }
413
+ catch {
414
+ throw new Error('Geyser Stream requires @grpc/grpc-js and @grpc/proto-loader. ' +
415
+ 'Install them with: npm install @grpc/grpc-js @grpc/proto-loader');
416
+ }
417
+ // 使用内联 proto 定义
418
+ const packageDefinition = protoLoader.loadSync(GEYSER_PROTO_DEFINITION, {
419
+ keepCase: true,
420
+ longs: String,
421
+ enums: String,
422
+ defaults: true,
423
+ oneofs: true,
424
+ });
425
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
426
+ const geyserProto = grpc.loadPackageDefinition(packageDefinition).geyser;
427
+ // 创建 SSL 凭证
428
+ const sslCreds = grpc.credentials.createSsl();
429
+ // 创建 metadata
430
+ const metadata = new grpc.Metadata();
431
+ metadata.add('x-token', clientConfig.token);
432
+ // 创建客户端
433
+ const client = new geyserProto.Geyser(clientConfig.host, sslCreds);
434
+ // 建立流
435
+ const stream = client.Subscribe(metadata);
436
+ // 处理更新
437
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
438
+ stream.on('data', (update) => {
439
+ const geyserUpdate = update;
440
+ switch (geyserUpdate.update_oneof) {
441
+ case 'account':
442
+ if (geyserUpdate.account && handlers.onAccount) {
443
+ handlers.onAccount(geyserUpdate.account, geyserUpdate.account.account.pubkey);
444
+ }
445
+ break;
446
+ case 'block':
447
+ if (geyserUpdate.block && handlers.onBlock) {
448
+ handlers.onBlock(geyserUpdate.block);
449
+ }
450
+ break;
451
+ case 'transaction':
452
+ if (geyserUpdate.transaction && handlers.onTransaction) {
453
+ handlers.onTransaction(geyserUpdate.transaction, geyserUpdate.transaction.transaction.signature);
454
+ }
455
+ break;
456
+ }
457
+ });
458
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
459
+ stream.on('error', (err) => {
460
+ if (handlers.onError) {
461
+ handlers.onError(err instanceof Error ? err : new Error(String(err)));
462
+ }
463
+ });
464
+ stream.on('end', () => {
465
+ if (handlers.onEnd) {
466
+ handlers.onEnd();
467
+ }
468
+ });
469
+ // 发送订阅请求
470
+ const request = buildGeyserSubscribeRequest(subscribeConfig);
471
+ stream.write(request);
472
+ return {
473
+ close: () => stream.end(),
474
+ write: (data) => stream.write(data),
475
+ };
476
+ }
477
+ // ============================================================================
478
+ // 简化版订阅方法
479
+ // ============================================================================
480
+ /**
481
+ * 简化版:订阅账户更新
482
+ *
483
+ * @param token 认证 Token
484
+ * @param accounts 账户地址列表
485
+ * @param onUpdate 更新回调
486
+ * @param region 区域(默认 tokyo)
487
+ * @returns 流控制对象
488
+ */
489
+ export async function subscribeGeyserAccounts(token, accounts, onUpdate, region = 'tokyo') {
490
+ const bs58 = await import('bs58');
491
+ return createGeyserSubscription({ host: getGeyserEndpoint(region), token }, createAccountSubscribeConfig(undefined, accounts), {
492
+ onAccount: (update) => {
493
+ const pubkey = bs58.default.encode(update.account.pubkey);
494
+ onUpdate(pubkey, update.account.lamports, update.slot);
495
+ },
496
+ });
497
+ }
498
+ /**
499
+ * 简化版:订阅交易更新
500
+ *
501
+ * @param token 认证 Token
502
+ * @param accountInclude 包含涉及这些账户的交易
503
+ * @param onUpdate 更新回调
504
+ * @param region 区域(默认 tokyo)
505
+ * @returns 流控制对象
506
+ */
507
+ export async function subscribeGeyserTransactions(token, accountInclude, onUpdate, region = 'tokyo') {
508
+ const bs58 = await import('bs58');
509
+ return createGeyserSubscription({ host: getGeyserEndpoint(region), token }, createTransactionSubscribeConfig(accountInclude), {
510
+ onTransaction: (update) => {
511
+ const signature = bs58.default.encode(update.transaction.signature);
512
+ onUpdate(signature, update.transaction.isVote, update.slot);
513
+ },
514
+ });
515
+ }
516
+ /**
517
+ * 简化版:订阅区块更新
518
+ *
519
+ * @param token 认证 Token
520
+ * @param onUpdate 更新回调
521
+ * @param region 区域(默认 tokyo)
522
+ * @returns 流控制对象
523
+ */
524
+ export async function subscribeGeyserBlocks(token, onUpdate, region = 'tokyo') {
525
+ return createGeyserSubscription({ host: getGeyserEndpoint(region), token }, createBlockSubscribeConfig(), {
526
+ onBlock: (update) => {
527
+ onUpdate(update.slot, update.blockhash, update.transactions.length);
528
+ },
529
+ });
530
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * BlockRazor Solana Service
3
+ * @module sol/dex/blockrazor
4
+ *
5
+ * BlockRazor 提供 Solana 服务:
6
+ * - 高性能交易落地 (Transaction Landing)
7
+ * - 三明治攻击缓解模式 (Sandwich Mitigation)
8
+ * - Revert 保护
9
+ * - Geyser Stream (gRPC 实时数据流)
10
+ *
11
+ * @see https://blockrazor.gitbook.io/blockrazor/solana/send-transaction
12
+ * @see https://blockrazor.gitbook.io/blockrazor/solana/geyser-stream
13
+ */
14
+ export * from './types.js';
15
+ export * from './constants.js';
16
+ export { setBlockRazorConfig, getBlockRazorConfig, getBlockRazorEndpoint, getRandomBlockRazorTipAccount, validateSendParams, } from './client.js';
17
+ export { blockRazorSendTransaction, blockRazorSendTransactionV2, blockRazorHealth, blockRazorHealthV2, blockRazorFastSend, blockRazorSafeSend, blockRazorSendWithRevertProtection, startBlockRazorKeepAlive, } from './send.js';
18
+ export { GEYSER_PROTO_DEFINITION, getGeyserEndpoint, buildGeyserSubscribeRequest, createAccountSubscribeConfig, createTransactionSubscribeConfig, createBlockSubscribeConfig, createGeyserSubscription, subscribeGeyserAccounts, subscribeGeyserTransactions, subscribeGeyserBlocks, } from './geyser.js';