outsmart 2.0.0-alpha.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.
Files changed (235) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +568 -0
  3. package/dist/cli.d.ts +44 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +1251 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/dex/byreal-clmm.d.ts +16 -0
  8. package/dist/dex/byreal-clmm.d.ts.map +1 -0
  9. package/dist/dex/byreal-clmm.js +39 -0
  10. package/dist/dex/byreal-clmm.js.map +1 -0
  11. package/dist/dex/dflow.d.ts +27 -0
  12. package/dist/dex/dflow.d.ts.map +1 -0
  13. package/dist/dex/dflow.js +200 -0
  14. package/dist/dex/dflow.js.map +1 -0
  15. package/dist/dex/fusion-amm.d.ts +44 -0
  16. package/dist/dex/fusion-amm.d.ts.map +1 -0
  17. package/dist/dex/fusion-amm.js +546 -0
  18. package/dist/dex/fusion-amm.js.map +1 -0
  19. package/dist/dex/futarchy-amm.d.ts +32 -0
  20. package/dist/dex/futarchy-amm.d.ts.map +1 -0
  21. package/dist/dex/futarchy-amm.js +443 -0
  22. package/dist/dex/futarchy-amm.js.map +1 -0
  23. package/dist/dex/futarchy-idl.d.ts +2568 -0
  24. package/dist/dex/futarchy-idl.d.ts.map +1 -0
  25. package/dist/dex/futarchy-idl.js +2570 -0
  26. package/dist/dex/futarchy-idl.js.map +1 -0
  27. package/dist/dex/futarchy-launchpad.d.ts +68 -0
  28. package/dist/dex/futarchy-launchpad.d.ts.map +1 -0
  29. package/dist/dex/futarchy-launchpad.js +377 -0
  30. package/dist/dex/futarchy-launchpad.js.map +1 -0
  31. package/dist/dex/index.d.ts +88 -0
  32. package/dist/dex/index.d.ts.map +1 -0
  33. package/dist/dex/index.js +159 -0
  34. package/dist/dex/index.js.map +1 -0
  35. package/dist/dex/jupiter-ultra.d.ts +27 -0
  36. package/dist/dex/jupiter-ultra.d.ts.map +1 -0
  37. package/dist/dex/jupiter-ultra.js +369 -0
  38. package/dist/dex/jupiter-ultra.js.map +1 -0
  39. package/dist/dex/meteora-damm-v1.d.ts +36 -0
  40. package/dist/dex/meteora-damm-v1.d.ts.map +1 -0
  41. package/dist/dex/meteora-damm-v1.js +314 -0
  42. package/dist/dex/meteora-damm-v1.js.map +1 -0
  43. package/dist/dex/meteora-damm-v2.d.ts +103 -0
  44. package/dist/dex/meteora-damm-v2.d.ts.map +1 -0
  45. package/dist/dex/meteora-damm-v2.js +1146 -0
  46. package/dist/dex/meteora-damm-v2.js.map +1 -0
  47. package/dist/dex/meteora-dbc.d.ts +38 -0
  48. package/dist/dex/meteora-dbc.d.ts.map +1 -0
  49. package/dist/dex/meteora-dbc.js +374 -0
  50. package/dist/dex/meteora-dbc.js.map +1 -0
  51. package/dist/dex/meteora-dlmm.d.ts +79 -0
  52. package/dist/dex/meteora-dlmm.d.ts.map +1 -0
  53. package/dist/dex/meteora-dlmm.js +735 -0
  54. package/dist/dex/meteora-dlmm.js.map +1 -0
  55. package/dist/dex/orca.d.ts +31 -0
  56. package/dist/dex/orca.d.ts.map +1 -0
  57. package/dist/dex/orca.js +536 -0
  58. package/dist/dex/orca.js.map +1 -0
  59. package/dist/dex/pancakeswap-clmm.d.ts +16 -0
  60. package/dist/dex/pancakeswap-clmm.d.ts.map +1 -0
  61. package/dist/dex/pancakeswap-clmm.js +39 -0
  62. package/dist/dex/pancakeswap-clmm.js.map +1 -0
  63. package/dist/dex/pumpfun-amm.d.ts +46 -0
  64. package/dist/dex/pumpfun-amm.d.ts.map +1 -0
  65. package/dist/dex/pumpfun-amm.js +692 -0
  66. package/dist/dex/pumpfun-amm.js.map +1 -0
  67. package/dist/dex/pumpfun.d.ts +41 -0
  68. package/dist/dex/pumpfun.d.ts.map +1 -0
  69. package/dist/dex/pumpfun.js +555 -0
  70. package/dist/dex/pumpfun.js.map +1 -0
  71. package/dist/dex/raydium-amm-v4.d.ts +11 -0
  72. package/dist/dex/raydium-amm-v4.d.ts.map +1 -0
  73. package/dist/dex/raydium-amm-v4.js +649 -0
  74. package/dist/dex/raydium-amm-v4.js.map +1 -0
  75. package/dist/dex/raydium-clmm.d.ts +12 -0
  76. package/dist/dex/raydium-clmm.d.ts.map +1 -0
  77. package/dist/dex/raydium-clmm.js +675 -0
  78. package/dist/dex/raydium-clmm.js.map +1 -0
  79. package/dist/dex/raydium-cpmm.d.ts +10 -0
  80. package/dist/dex/raydium-cpmm.d.ts.map +1 -0
  81. package/dist/dex/raydium-cpmm.js +613 -0
  82. package/dist/dex/raydium-cpmm.js.map +1 -0
  83. package/dist/dex/raydium-launchlab.d.ts +12 -0
  84. package/dist/dex/raydium-launchlab.d.ts.map +1 -0
  85. package/dist/dex/raydium-launchlab.js +530 -0
  86. package/dist/dex/raydium-launchlab.js.map +1 -0
  87. package/dist/dex/shared/clmm-base.d.ts +58 -0
  88. package/dist/dex/shared/clmm-base.d.ts.map +1 -0
  89. package/dist/dex/shared/clmm-base.js +891 -0
  90. package/dist/dex/shared/clmm-base.js.map +1 -0
  91. package/dist/dex/types.d.ts +601 -0
  92. package/dist/dex/types.d.ts.map +1 -0
  93. package/dist/dex/types.js +137 -0
  94. package/dist/dex/types.js.map +1 -0
  95. package/dist/dexscreener/index.d.ts +2 -0
  96. package/dist/dexscreener/index.d.ts.map +1 -0
  97. package/dist/dexscreener/index.js +18 -0
  98. package/dist/dexscreener/index.js.map +1 -0
  99. package/dist/dexscreener/info.d.ts +22 -0
  100. package/dist/dexscreener/info.d.ts.map +1 -0
  101. package/dist/dexscreener/info.js +104 -0
  102. package/dist/dexscreener/info.js.map +1 -0
  103. package/dist/helpers/check_balance.d.ts +10 -0
  104. package/dist/helpers/check_balance.d.ts.map +1 -0
  105. package/dist/helpers/check_balance.js +34 -0
  106. package/dist/helpers/check_balance.js.map +1 -0
  107. package/dist/helpers/config.d.ts +51 -0
  108. package/dist/helpers/config.d.ts.map +1 -0
  109. package/dist/helpers/config.js +118 -0
  110. package/dist/helpers/config.js.map +1 -0
  111. package/dist/helpers/index.d.ts +8 -0
  112. package/dist/helpers/index.d.ts.map +1 -0
  113. package/dist/helpers/index.js +29 -0
  114. package/dist/helpers/index.js.map +1 -0
  115. package/dist/helpers/logger.d.ts +27 -0
  116. package/dist/helpers/logger.d.ts.map +1 -0
  117. package/dist/helpers/logger.js +39 -0
  118. package/dist/helpers/logger.js.map +1 -0
  119. package/dist/helpers/token-2022.d.ts +32 -0
  120. package/dist/helpers/token-2022.d.ts.map +1 -0
  121. package/dist/helpers/token-2022.js +48 -0
  122. package/dist/helpers/token-2022.js.map +1 -0
  123. package/dist/helpers/unwrap_sol.d.ts +2 -0
  124. package/dist/helpers/unwrap_sol.d.ts.map +1 -0
  125. package/dist/helpers/unwrap_sol.js +67 -0
  126. package/dist/helpers/unwrap_sol.js.map +1 -0
  127. package/dist/helpers/util.d.ts +698 -0
  128. package/dist/helpers/util.d.ts.map +1 -0
  129. package/dist/helpers/util.js +181 -0
  130. package/dist/helpers/util.js.map +1 -0
  131. package/dist/helpers/utils.d.ts +10 -0
  132. package/dist/helpers/utils.d.ts.map +1 -0
  133. package/dist/helpers/utils.js +97 -0
  134. package/dist/helpers/utils.js.map +1 -0
  135. package/dist/helpers/wrap_sol.d.ts +3 -0
  136. package/dist/helpers/wrap_sol.d.ts.map +1 -0
  137. package/dist/helpers/wrap_sol.js +88 -0
  138. package/dist/helpers/wrap_sol.js.map +1 -0
  139. package/dist/index.d.ts +14 -0
  140. package/dist/index.d.ts.map +1 -0
  141. package/dist/index.js +32 -0
  142. package/dist/index.js.map +1 -0
  143. package/dist/transactions/bloXroute_tips_tx_executor.d.ts +4 -0
  144. package/dist/transactions/bloXroute_tips_tx_executor.d.ts.map +1 -0
  145. package/dist/transactions/bloXroute_tips_tx_executor.js +70 -0
  146. package/dist/transactions/bloXroute_tips_tx_executor.js.map +1 -0
  147. package/dist/transactions/index.d.ts +6 -0
  148. package/dist/transactions/index.d.ts.map +1 -0
  149. package/dist/transactions/index.js +30 -0
  150. package/dist/transactions/index.js.map +1 -0
  151. package/dist/transactions/jito_tips_tx_executor.d.ts +15 -0
  152. package/dist/transactions/jito_tips_tx_executor.d.ts.map +1 -0
  153. package/dist/transactions/jito_tips_tx_executor.js +99 -0
  154. package/dist/transactions/jito_tips_tx_executor.js.map +1 -0
  155. package/dist/transactions/landing/index.d.ts +30 -0
  156. package/dist/transactions/landing/index.d.ts.map +1 -0
  157. package/dist/transactions/landing/index.js +60 -0
  158. package/dist/transactions/landing/index.js.map +1 -0
  159. package/dist/transactions/landing/nonce-manager.d.ts +116 -0
  160. package/dist/transactions/landing/nonce-manager.d.ts.map +1 -0
  161. package/dist/transactions/landing/nonce-manager.js +393 -0
  162. package/dist/transactions/landing/nonce-manager.js.map +1 -0
  163. package/dist/transactions/landing/orchestrator.d.ts +104 -0
  164. package/dist/transactions/landing/orchestrator.d.ts.map +1 -0
  165. package/dist/transactions/landing/orchestrator.js +329 -0
  166. package/dist/transactions/landing/orchestrator.js.map +1 -0
  167. package/dist/transactions/landing/providers/astralane.d.ts +12 -0
  168. package/dist/transactions/landing/providers/astralane.d.ts.map +1 -0
  169. package/dist/transactions/landing/providers/astralane.js +132 -0
  170. package/dist/transactions/landing/providers/astralane.js.map +1 -0
  171. package/dist/transactions/landing/providers/blockrazor.d.ts +11 -0
  172. package/dist/transactions/landing/providers/blockrazor.d.ts.map +1 -0
  173. package/dist/transactions/landing/providers/blockrazor.js +134 -0
  174. package/dist/transactions/landing/providers/blockrazor.js.map +1 -0
  175. package/dist/transactions/landing/providers/bloxroute.d.ts +12 -0
  176. package/dist/transactions/landing/providers/bloxroute.d.ts.map +1 -0
  177. package/dist/transactions/landing/providers/bloxroute.js +102 -0
  178. package/dist/transactions/landing/providers/bloxroute.js.map +1 -0
  179. package/dist/transactions/landing/providers/flashblock.d.ts +10 -0
  180. package/dist/transactions/landing/providers/flashblock.d.ts.map +1 -0
  181. package/dist/transactions/landing/providers/flashblock.js +102 -0
  182. package/dist/transactions/landing/providers/flashblock.js.map +1 -0
  183. package/dist/transactions/landing/providers/helius-sender.d.ts +11 -0
  184. package/dist/transactions/landing/providers/helius-sender.d.ts.map +1 -0
  185. package/dist/transactions/landing/providers/helius-sender.js +101 -0
  186. package/dist/transactions/landing/providers/helius-sender.js.map +1 -0
  187. package/dist/transactions/landing/providers/jito.d.ts +16 -0
  188. package/dist/transactions/landing/providers/jito.d.ts.map +1 -0
  189. package/dist/transactions/landing/providers/jito.js +110 -0
  190. package/dist/transactions/landing/providers/jito.js.map +1 -0
  191. package/dist/transactions/landing/providers/nextblock.d.ts +11 -0
  192. package/dist/transactions/landing/providers/nextblock.d.ts.map +1 -0
  193. package/dist/transactions/landing/providers/nextblock.js +109 -0
  194. package/dist/transactions/landing/providers/nextblock.js.map +1 -0
  195. package/dist/transactions/landing/providers/node1.d.ts +11 -0
  196. package/dist/transactions/landing/providers/node1.d.ts.map +1 -0
  197. package/dist/transactions/landing/providers/node1.js +101 -0
  198. package/dist/transactions/landing/providers/node1.js.map +1 -0
  199. package/dist/transactions/landing/providers/nozomi.d.ts +11 -0
  200. package/dist/transactions/landing/providers/nozomi.d.ts.map +1 -0
  201. package/dist/transactions/landing/providers/nozomi.js +124 -0
  202. package/dist/transactions/landing/providers/nozomi.js.map +1 -0
  203. package/dist/transactions/landing/providers/soyas.d.ts +16 -0
  204. package/dist/transactions/landing/providers/soyas.d.ts.map +1 -0
  205. package/dist/transactions/landing/providers/soyas.js +192 -0
  206. package/dist/transactions/landing/providers/soyas.js.map +1 -0
  207. package/dist/transactions/landing/providers/stellium.d.ts +11 -0
  208. package/dist/transactions/landing/providers/stellium.d.ts.map +1 -0
  209. package/dist/transactions/landing/providers/stellium.js +102 -0
  210. package/dist/transactions/landing/providers/stellium.js.map +1 -0
  211. package/dist/transactions/landing/providers/zero-slot.d.ts +10 -0
  212. package/dist/transactions/landing/providers/zero-slot.d.ts.map +1 -0
  213. package/dist/transactions/landing/providers/zero-slot.js +92 -0
  214. package/dist/transactions/landing/providers/zero-slot.js.map +1 -0
  215. package/dist/transactions/landing/tip-accounts.d.ts +22 -0
  216. package/dist/transactions/landing/tip-accounts.d.ts.map +1 -0
  217. package/dist/transactions/landing/tip-accounts.js +140 -0
  218. package/dist/transactions/landing/tip-accounts.js.map +1 -0
  219. package/dist/transactions/landing/types.d.ts +98 -0
  220. package/dist/transactions/landing/types.d.ts.map +1 -0
  221. package/dist/transactions/landing/types.js +30 -0
  222. package/dist/transactions/landing/types.js.map +1 -0
  223. package/dist/transactions/nozomi/tx-submission.d.ts +14 -0
  224. package/dist/transactions/nozomi/tx-submission.d.ts.map +1 -0
  225. package/dist/transactions/nozomi/tx-submission.js +107 -0
  226. package/dist/transactions/nozomi/tx-submission.js.map +1 -0
  227. package/dist/transactions/send-rpc.d.ts +54 -0
  228. package/dist/transactions/send-rpc.d.ts.map +1 -0
  229. package/dist/transactions/send-rpc.js +126 -0
  230. package/dist/transactions/send-rpc.js.map +1 -0
  231. package/dist/transactions/simple_tx_executor.d.ts +10 -0
  232. package/dist/transactions/simple_tx_executor.d.ts.map +1 -0
  233. package/dist/transactions/simple_tx_executor.js +33 -0
  234. package/dist/transactions/simple_tx_executor.js.map +1 -0
  235. package/package.json +112 -0
@@ -0,0 +1,393 @@
1
+ "use strict";
2
+ /**
3
+ * Durable Nonce Account Manager
4
+ *
5
+ * Manages durable nonce accounts for concurrent TX landing safety.
6
+ *
7
+ * Problem: The "concurrent" landing strategy fires the SAME transaction to
8
+ * 9+ providers in parallel. Without a durable nonce, if multiple providers
9
+ * land it, the user gets DUPLICATE BUYS — spending 2-9x more SOL than intended.
10
+ *
11
+ * Solution: Durable nonce transactions use a nonce account's stored blockhash.
12
+ * Once consumed by the first successful landing, all other copies become
13
+ * invalid on-chain. This guarantees exactly-once execution.
14
+ *
15
+ * How it works:
16
+ * 1. NonceManager.create() creates a nonce account on-chain (~0.0015 SOL)
17
+ * 2. Before concurrent submission, NonceManager.get() fetches the current nonce
18
+ * 3. NonceManager.buildAdvanceIx() is prepended as the FIRST instruction
19
+ * 4. The nonce value replaces the blockhash in the transaction message
20
+ * 5. Providers treat the nonce as a regular blockhash — no provider changes needed
21
+ *
22
+ * Config is stored at ~/.outsmart/nonce.json
23
+ */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || (function () {
41
+ var ownKeys = function(o) {
42
+ ownKeys = Object.getOwnPropertyNames || function (o) {
43
+ var ar = [];
44
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
45
+ return ar;
46
+ };
47
+ return ownKeys(o);
48
+ };
49
+ return function (mod) {
50
+ if (mod && mod.__esModule) return mod;
51
+ var result = {};
52
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
53
+ __setModuleDefault(result, mod);
54
+ return result;
55
+ };
56
+ })();
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.NonceManager = void 0;
59
+ const web3_js_1 = require("@solana/web3.js");
60
+ const fs = __importStar(require("fs"));
61
+ const path = __importStar(require("path"));
62
+ const readline = __importStar(require("readline"));
63
+ // ---------------------------------------------------------------------------
64
+ // NonceManager class
65
+ // ---------------------------------------------------------------------------
66
+ class NonceManager {
67
+ connection;
68
+ authority;
69
+ nonceAddress = null;
70
+ configLoaded = false;
71
+ /**
72
+ * @param connection - Solana RPC connection
73
+ * @param authority - Wallet keypair that controls the nonce account
74
+ */
75
+ constructor(connection, authority) {
76
+ this.connection = connection;
77
+ this.authority = authority;
78
+ }
79
+ // -----------------------------------------------------------------------
80
+ // Static config paths
81
+ // -----------------------------------------------------------------------
82
+ /** Directory for outsmart config files */
83
+ static get configDir() {
84
+ const home = process.env.HOME || process.env.USERPROFILE || "~";
85
+ return path.join(home, ".outsmart");
86
+ }
87
+ /** Path to nonce config JSON */
88
+ static get configPath() {
89
+ return path.join(NonceManager.configDir, "nonce.json");
90
+ }
91
+ /** Path to nonce keypair JSON */
92
+ static get keypairPath() {
93
+ return path.join(NonceManager.configDir, "nonce-keypair.json");
94
+ }
95
+ // -----------------------------------------------------------------------
96
+ // Config I/O
97
+ // -----------------------------------------------------------------------
98
+ readConfig() {
99
+ try {
100
+ if (!fs.existsSync(NonceManager.configPath))
101
+ return null;
102
+ const raw = fs.readFileSync(NonceManager.configPath, "utf8");
103
+ return JSON.parse(raw);
104
+ }
105
+ catch {
106
+ return null;
107
+ }
108
+ }
109
+ writeConfig(config) {
110
+ fs.mkdirSync(NonceManager.configDir, { recursive: true });
111
+ fs.writeFileSync(NonceManager.configPath, JSON.stringify(config, null, 2), { encoding: "utf8", mode: 0o600 });
112
+ }
113
+ deleteConfig() {
114
+ try {
115
+ if (fs.existsSync(NonceManager.configPath)) {
116
+ fs.unlinkSync(NonceManager.configPath);
117
+ }
118
+ if (fs.existsSync(NonceManager.keypairPath)) {
119
+ fs.unlinkSync(NonceManager.keypairPath);
120
+ }
121
+ }
122
+ catch {
123
+ // Best-effort cleanup
124
+ }
125
+ }
126
+ // -----------------------------------------------------------------------
127
+ // Core operations
128
+ // -----------------------------------------------------------------------
129
+ /**
130
+ * Check if a valid nonce account exists (config + on-chain).
131
+ */
132
+ async exists() {
133
+ const config = this.readConfig();
134
+ if (!config)
135
+ return false;
136
+ try {
137
+ const pubkey = new web3_js_1.PublicKey(config.nonceAccountAddress);
138
+ const accountInfo = await this.connection.getAccountInfo(pubkey);
139
+ if (!accountInfo)
140
+ return false;
141
+ // Verify it's actually a nonce account by trying to decode it
142
+ web3_js_1.NonceAccount.fromAccountData(accountInfo.data);
143
+ this.nonceAddress = pubkey;
144
+ this.configLoaded = true;
145
+ return true;
146
+ }
147
+ catch {
148
+ return false;
149
+ }
150
+ }
151
+ /**
152
+ * Create a new nonce account on-chain.
153
+ *
154
+ * Cost: ~0.0015 SOL (rent-exempt minimum for nonce account).
155
+ *
156
+ * @returns The nonce account address and initial nonce value
157
+ */
158
+ async create() {
159
+ // Generate a new keypair for the nonce account
160
+ const nonceKeypair = web3_js_1.Keypair.generate();
161
+ // Calculate minimum rent for nonce account
162
+ const rent = await this.connection.getMinimumBalanceForRentExemption(web3_js_1.NONCE_ACCOUNT_LENGTH);
163
+ // Build the create + initialize instructions
164
+ const createAccountIx = web3_js_1.SystemProgram.createAccount({
165
+ fromPubkey: this.authority.publicKey,
166
+ newAccountPubkey: nonceKeypair.publicKey,
167
+ lamports: rent,
168
+ space: web3_js_1.NONCE_ACCOUNT_LENGTH,
169
+ programId: web3_js_1.SystemProgram.programId,
170
+ });
171
+ const initNonceIx = web3_js_1.SystemProgram.nonceInitialize({
172
+ noncePubkey: nonceKeypair.publicKey,
173
+ authorizedPubkey: this.authority.publicKey,
174
+ });
175
+ // Build, sign, and send the transaction
176
+ const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash("confirmed");
177
+ const message = new web3_js_1.TransactionMessage({
178
+ payerKey: this.authority.publicKey,
179
+ recentBlockhash: blockhash,
180
+ instructions: [createAccountIx, initNonceIx],
181
+ }).compileToV0Message();
182
+ const tx = new web3_js_1.VersionedTransaction(message);
183
+ tx.sign([this.authority, nonceKeypair]);
184
+ const signature = await this.connection.sendRawTransaction(tx.serialize(), {
185
+ skipPreflight: false,
186
+ maxRetries: 3,
187
+ });
188
+ // Wait for confirmation
189
+ await this.connection.confirmTransaction({ signature, blockhash, lastValidBlockHeight }, "confirmed");
190
+ // Save the keypair securely
191
+ fs.mkdirSync(NonceManager.configDir, { recursive: true });
192
+ fs.writeFileSync(NonceManager.keypairPath, JSON.stringify(Array.from(nonceKeypair.secretKey)), { encoding: "utf8", mode: 0o600 });
193
+ // Save config
194
+ const config = {
195
+ nonceAccountAddress: nonceKeypair.publicKey.toBase58(),
196
+ nonceKeypairPath: NonceManager.keypairPath,
197
+ authorityPubkey: this.authority.publicKey.toBase58(),
198
+ createdAt: new Date().toISOString(),
199
+ };
200
+ this.writeConfig(config);
201
+ // Set internal state
202
+ this.nonceAddress = nonceKeypair.publicKey;
203
+ this.configLoaded = true;
204
+ // Fetch the initial nonce value
205
+ const accountInfo = await this.connection.getAccountInfo(nonceKeypair.publicKey);
206
+ if (!accountInfo) {
207
+ throw new Error("Nonce account created but could not be read back");
208
+ }
209
+ const nonceAccount = web3_js_1.NonceAccount.fromAccountData(accountInfo.data);
210
+ console.log(`[nonce] Created nonce account: ${nonceKeypair.publicKey.toBase58()}`);
211
+ console.log(`[nonce] Cost: ${(rent / web3_js_1.LAMPORTS_PER_SOL).toFixed(6)} SOL (rent-exempt)`);
212
+ return {
213
+ nonceAccount: nonceKeypair.publicKey,
214
+ nonce: nonceAccount.nonce,
215
+ };
216
+ }
217
+ /**
218
+ * Load the nonce account from config and fetch its current on-chain state.
219
+ *
220
+ * @returns Nonce address, current nonce value, and authority
221
+ * @throws Error if no nonce config exists or account is invalid
222
+ */
223
+ async load() {
224
+ const config = this.readConfig();
225
+ if (!config) {
226
+ throw new Error("No nonce account configured. Run NonceManager.create() first, " +
227
+ "or use the 'outsmart nonce create' command.");
228
+ }
229
+ const address = new web3_js_1.PublicKey(config.nonceAccountAddress);
230
+ const accountInfo = await this.connection.getAccountInfo(address);
231
+ if (!accountInfo) {
232
+ throw new Error(`Nonce account ${config.nonceAccountAddress} not found on-chain. ` +
233
+ "It may have been closed. Run NonceManager.create() to create a new one.");
234
+ }
235
+ const nonceAccount = web3_js_1.NonceAccount.fromAccountData(accountInfo.data);
236
+ this.nonceAddress = address;
237
+ this.configLoaded = true;
238
+ return {
239
+ address,
240
+ nonce: nonceAccount.nonce,
241
+ authority: nonceAccount.authorizedPubkey,
242
+ };
243
+ }
244
+ /**
245
+ * Get the current nonce value (fetches fresh from chain every time).
246
+ *
247
+ * IMPORTANT: Nonce value changes after each use. Always call get() fresh
248
+ * before building a transaction.
249
+ */
250
+ async get() {
251
+ if (!this.nonceAddress) {
252
+ await this.load();
253
+ }
254
+ const accountInfo = await this.connection.getAccountInfo(this.nonceAddress);
255
+ if (!accountInfo) {
256
+ throw new Error(`Nonce account ${this.nonceAddress.toBase58()} no longer exists on-chain.`);
257
+ }
258
+ const nonceAccount = web3_js_1.NonceAccount.fromAccountData(accountInfo.data);
259
+ return {
260
+ nonce: nonceAccount.nonce,
261
+ address: this.nonceAddress,
262
+ };
263
+ }
264
+ /**
265
+ * Build a nonceAdvance instruction.
266
+ *
267
+ * This MUST be the FIRST instruction in any transaction using a durable nonce.
268
+ * The Solana runtime recognizes the nonceAdvance instruction and validates
269
+ * the nonce value as the blockhash.
270
+ *
271
+ * @returns TransactionInstruction for SystemProgram.nonceAdvance
272
+ */
273
+ buildAdvanceIx() {
274
+ if (!this.nonceAddress) {
275
+ throw new Error("Nonce account not loaded. Call load() or create() first.");
276
+ }
277
+ return web3_js_1.SystemProgram.nonceAdvance({
278
+ noncePubkey: this.nonceAddress,
279
+ authorizedPubkey: this.authority.publicKey,
280
+ });
281
+ }
282
+ /**
283
+ * Ensure a nonce account exists, prompting the user to create one if needed.
284
+ *
285
+ * In non-interactive mode (piped stdin), defaults to false (skip nonce creation).
286
+ *
287
+ * @returns true if a nonce account exists (or was just created), false if user declined
288
+ */
289
+ async ensureExists() {
290
+ if (await this.exists()) {
291
+ return true;
292
+ }
293
+ // Check if stdin is interactive (TTY)
294
+ if (!process.stdin.isTTY) {
295
+ console.warn("[nonce] No nonce account found. Non-interactive mode — skipping creation.");
296
+ console.warn("[nonce] Concurrent landing without nonce risks duplicate buys.");
297
+ return false;
298
+ }
299
+ // Prompt the user
300
+ const answer = await this.promptUser("Concurrent TX landing requires a durable nonce account (~0.0015 SOL).\n" +
301
+ "Without it, duplicate buys are possible. Create one now? [Y/n] ");
302
+ const normalized = answer.trim().toLowerCase();
303
+ if (normalized === "" || normalized === "y" || normalized === "yes") {
304
+ try {
305
+ await this.create();
306
+ return true;
307
+ }
308
+ catch (err) {
309
+ console.error("[nonce] Failed to create nonce account:", err);
310
+ return false;
311
+ }
312
+ }
313
+ console.warn("[nonce] Nonce creation declined. Concurrent strategy will fall back to race.");
314
+ return false;
315
+ }
316
+ /**
317
+ * Close the nonce account and reclaim the rent (~0.0015 SOL).
318
+ *
319
+ * Withdraws all lamports back to the authority wallet and deletes
320
+ * the local config files.
321
+ */
322
+ async close() {
323
+ if (!this.nonceAddress) {
324
+ const config = this.readConfig();
325
+ if (!config) {
326
+ throw new Error("No nonce account to close.");
327
+ }
328
+ this.nonceAddress = new web3_js_1.PublicKey(config.nonceAccountAddress);
329
+ }
330
+ // Get nonce account balance
331
+ const accountInfo = await this.connection.getAccountInfo(this.nonceAddress);
332
+ if (!accountInfo) {
333
+ // Already closed — just clean up config
334
+ this.deleteConfig();
335
+ this.nonceAddress = null;
336
+ this.configLoaded = false;
337
+ return { txSignature: "", confirmed: true };
338
+ }
339
+ const withdrawIx = web3_js_1.SystemProgram.nonceWithdraw({
340
+ noncePubkey: this.nonceAddress,
341
+ authorizedPubkey: this.authority.publicKey,
342
+ toPubkey: this.authority.publicKey,
343
+ lamports: accountInfo.lamports,
344
+ });
345
+ const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash("confirmed");
346
+ const message = new web3_js_1.TransactionMessage({
347
+ payerKey: this.authority.publicKey,
348
+ recentBlockhash: blockhash,
349
+ instructions: [withdrawIx],
350
+ }).compileToV0Message();
351
+ const tx = new web3_js_1.VersionedTransaction(message);
352
+ tx.sign([this.authority]);
353
+ const signature = await this.connection.sendRawTransaction(tx.serialize(), {
354
+ skipPreflight: false,
355
+ maxRetries: 3,
356
+ });
357
+ await this.connection.confirmTransaction({ signature, blockhash, lastValidBlockHeight }, "confirmed");
358
+ const reclaimedSol = accountInfo.lamports / web3_js_1.LAMPORTS_PER_SOL;
359
+ console.log(`[nonce] Closed nonce account ${this.nonceAddress.toBase58()}. ` +
360
+ `Reclaimed ${reclaimedSol.toFixed(6)} SOL.`);
361
+ // Clean up config
362
+ this.deleteConfig();
363
+ this.nonceAddress = null;
364
+ this.configLoaded = false;
365
+ return { txSignature: signature, confirmed: true };
366
+ }
367
+ // -----------------------------------------------------------------------
368
+ // Helpers
369
+ // -----------------------------------------------------------------------
370
+ /**
371
+ * Get the nonce account address, if loaded.
372
+ */
373
+ getAddress() {
374
+ return this.nonceAddress;
375
+ }
376
+ /**
377
+ * Prompt the user for input via readline.
378
+ */
379
+ promptUser(question) {
380
+ const rl = readline.createInterface({
381
+ input: process.stdin,
382
+ output: process.stdout,
383
+ });
384
+ return new Promise((resolve) => {
385
+ rl.question(question, (answer) => {
386
+ rl.close();
387
+ resolve(answer);
388
+ });
389
+ });
390
+ }
391
+ }
392
+ exports.NonceManager = NonceManager;
393
+ //# sourceMappingURL=nonce-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nonce-manager.js","sourceRoot":"","sources":["../../../src/transactions/landing/nonce-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAWyB;AAEzB,uCAAyB;AACzB,2CAA6B;AAC7B,mDAAqC;AAiBrC,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,MAAa,YAAY;IACf,UAAU,CAAa;IACvB,SAAS,CAAU;IACnB,YAAY,GAAqB,IAAI,CAAC;IACtC,YAAY,GAAG,KAAK,CAAC;IAE7B;;;OAGG;IACH,YAAY,UAAsB,EAAE,S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;IAC1E,UAAU;IACV,0EAA0E;IAE1E;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,QAAgB;QACjC,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;YAClC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;QAEH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;gBAC/B,EAAE,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA1aD,oCA0aC"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * TX Landing Orchestrator
3
+ *
4
+ * Manages multiple TX landing providers and implements submission strategies:
5
+ * - concurrent: Fire to all enabled providers in parallel (fire-and-forget)
6
+ * Uses durable nonce for exactly-once execution safety.
7
+ * - race: Fire to all, return first accepted result
8
+ * - random: Pick 1-3 random providers + always include a fallback (nozomi)
9
+ * - sequential: Try providers in order, stop on first success
10
+ */
11
+ import { Keypair, TransactionInstruction } from "@solana/web3.js";
12
+ import { NonceManager } from "./nonce-manager";
13
+ import { ILandingProvider, LandingResult, SubmitOptions, OrchestratorConfig } from "./types";
14
+ export declare class LandingOrchestrator {
15
+ private providers;
16
+ private config;
17
+ private nonceManager;
18
+ constructor(config?: Partial<OrchestratorConfig>);
19
+ /**
20
+ * Get all currently enabled providers.
21
+ */
22
+ getEnabledProviders(): ILandingProvider[];
23
+ /**
24
+ * Get a specific provider by name.
25
+ */
26
+ getProvider(name: string): ILandingProvider | undefined;
27
+ /**
28
+ * List all registered provider names and their enabled status.
29
+ */
30
+ listProviders(): Array<{
31
+ name: string;
32
+ enabled: boolean;
33
+ }>;
34
+ /**
35
+ * Set the NonceManager for durable nonce support.
36
+ * When set, the concurrent strategy will use nonce for exactly-once execution.
37
+ */
38
+ setNonceManager(nm: NonceManager): void;
39
+ /**
40
+ * Get the current NonceManager, if any.
41
+ */
42
+ getNonceManager(): NonceManager | null;
43
+ /**
44
+ * Submit a transaction using the configured strategy.
45
+ */
46
+ submit(ixs: TransactionInstruction[], signer: Keypair, blockhash: string | {
47
+ blockhash: string;
48
+ lastValidBlockHeight: number;
49
+ }, opts?: Partial<SubmitOptions>): Promise<LandingResult[]>;
50
+ /**
51
+ * Fire to all enabled providers in parallel. Returns all results.
52
+ * This matches the source `concurrent_snipe_tx_landing` behavior.
53
+ *
54
+ * When a NonceManager is set, this method:
55
+ * 1. Fetches the current nonce value from chain
56
+ * 2. Prepends nonceAdvance as the FIRST instruction
57
+ * 3. Uses the nonce value as the blockhash
58
+ * This guarantees exactly-once execution even when 9+ providers receive
59
+ * the same transaction — the nonce is consumed by the first landing.
60
+ *
61
+ * Without nonce: falls back to race strategy with a warning.
62
+ */
63
+ private submitConcurrent;
64
+ /**
65
+ * Fire to all enabled providers, return on first accepted result.
66
+ */
67
+ private submitRace;
68
+ /**
69
+ * Pick 1-3 random providers + always include nozomi as fallback.
70
+ * Matches the source `randomLandTx` behavior.
71
+ */
72
+ private submitRandom;
73
+ /**
74
+ * Try providers in order, stop on first success.
75
+ */
76
+ private submitSequential;
77
+ /**
78
+ * Submit with timeout wrapper.
79
+ */
80
+ private submitWithTimeout;
81
+ /**
82
+ * Resolve provider names to instances, filtering to enabled only.
83
+ */
84
+ private getResolvedProviders;
85
+ /**
86
+ * Ping all providers that support it (for keep-alive).
87
+ */
88
+ pingAll(): Promise<void>;
89
+ }
90
+ /**
91
+ * Get or create the default orchestrator singleton.
92
+ *
93
+ * If a nonce account config exists at ~/.outsmart/nonce.json, the orchestrator
94
+ * will automatically use it for concurrent landing safety.
95
+ */
96
+ export declare function getOrchestrator(config?: Partial<OrchestratorConfig>): LandingOrchestrator;
97
+ /**
98
+ * Convenience: submit via the default orchestrator.
99
+ */
100
+ export declare function landTransaction(ixs: TransactionInstruction[], signer: Keypair, blockhash: string | {
101
+ blockhash: string;
102
+ lastValidBlockHeight: number;
103
+ }, opts?: Partial<SubmitOptions>): Promise<LandingResult[]>;
104
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../../src/transactions/landing/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,OAAO,EACP,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,kBAAkB,EAEnB,MAAM,SAAS,CAAC;AAmDjB,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,SAAS,CAA4C;IAC7D,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,YAAY,CAA6B;gBAErC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC;IAmBhD;;OAEG;IACH,mBAAmB,IAAI,gBAAgB,EAAE;IAOzC;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAIvD;;OAEG;IACH,aAAa,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAO1D;;;OAGG;IACH,eAAe,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI;IAIvC;;OAEG;IACH,eAAe,IAAI,YAAY,GAAG,IAAI;IAItC;;OAEG;IACG,MAAM,CACV,GAAG,EAAE,sBAAsB,EAAE,EAC7B,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,oBAAoB,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