fourmm 0.1.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 (151) hide show
  1. package/README.md +147 -0
  2. package/dist/bin.d.ts +9 -0
  3. package/dist/bin.d.ts.map +1 -0
  4. package/dist/bin.js +14 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/cli.d.ts +319 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +25 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/commands/config.d.ts +35 -0
  11. package/dist/commands/config.d.ts.map +1 -0
  12. package/dist/commands/config.js +145 -0
  13. package/dist/commands/config.js.map +1 -0
  14. package/dist/commands/query.d.ts +51 -0
  15. package/dist/commands/query.d.ts.map +1 -0
  16. package/dist/commands/query.js +364 -0
  17. package/dist/commands/query.js.map +1 -0
  18. package/dist/commands/token.d.ts +55 -0
  19. package/dist/commands/token.d.ts.map +1 -0
  20. package/dist/commands/token.js +650 -0
  21. package/dist/commands/token.js.map +1 -0
  22. package/dist/commands/tools.d.ts +54 -0
  23. package/dist/commands/tools.d.ts.map +1 -0
  24. package/dist/commands/tools.js +499 -0
  25. package/dist/commands/tools.js.map +1 -0
  26. package/dist/commands/trade.d.ts +63 -0
  27. package/dist/commands/trade.d.ts.map +1 -0
  28. package/dist/commands/trade.js +933 -0
  29. package/dist/commands/trade.js.map +1 -0
  30. package/dist/commands/transfer.d.ts +51 -0
  31. package/dist/commands/transfer.d.ts.map +1 -0
  32. package/dist/commands/transfer.js +728 -0
  33. package/dist/commands/transfer.js.map +1 -0
  34. package/dist/commands/wallet.d.ts +111 -0
  35. package/dist/commands/wallet.d.ts.map +1 -0
  36. package/dist/commands/wallet.js +716 -0
  37. package/dist/commands/wallet.js.map +1 -0
  38. package/dist/contracts/erc20.d.ts +72 -0
  39. package/dist/contracts/erc20.d.ts.map +1 -0
  40. package/dist/contracts/erc20.js +55 -0
  41. package/dist/contracts/erc20.js.map +1 -0
  42. package/dist/contracts/fourmemeMmRouter.d.ts +68 -0
  43. package/dist/contracts/fourmemeMmRouter.d.ts.map +1 -0
  44. package/dist/contracts/fourmemeMmRouter.js +48 -0
  45. package/dist/contracts/fourmemeMmRouter.js.map +1 -0
  46. package/dist/contracts/pancakeRouter.d.ts +73 -0
  47. package/dist/contracts/pancakeRouter.d.ts.map +1 -0
  48. package/dist/contracts/pancakeRouter.js +50 -0
  49. package/dist/contracts/pancakeRouter.js.map +1 -0
  50. package/dist/contracts/tokenManager2.d.ts +193 -0
  51. package/dist/contracts/tokenManager2.d.ts.map +1 -0
  52. package/dist/contracts/tokenManager2.js +108 -0
  53. package/dist/contracts/tokenManager2.js.map +1 -0
  54. package/dist/contracts/tokenManagerHelper3.d.ts +118 -0
  55. package/dist/contracts/tokenManagerHelper3.d.ts.map +1 -0
  56. package/dist/contracts/tokenManagerHelper3.js +66 -0
  57. package/dist/contracts/tokenManagerHelper3.js.map +1 -0
  58. package/dist/datastore/cache.d.ts +20 -0
  59. package/dist/datastore/cache.d.ts.map +1 -0
  60. package/dist/datastore/cache.js +45 -0
  61. package/dist/datastore/cache.js.map +1 -0
  62. package/dist/datastore/index.d.ts +85 -0
  63. package/dist/datastore/index.d.ts.map +1 -0
  64. package/dist/datastore/index.js +341 -0
  65. package/dist/datastore/index.js.map +1 -0
  66. package/dist/datastore/paths.d.ts +17 -0
  67. package/dist/datastore/paths.d.ts.map +1 -0
  68. package/dist/datastore/paths.js +39 -0
  69. package/dist/datastore/paths.js.map +1 -0
  70. package/dist/datastore/types.d.ts +105 -0
  71. package/dist/datastore/types.d.ts.map +1 -0
  72. package/dist/datastore/types.js +8 -0
  73. package/dist/datastore/types.js.map +1 -0
  74. package/dist/fourmeme/auth.d.ts +22 -0
  75. package/dist/fourmeme/auth.d.ts.map +1 -0
  76. package/dist/fourmeme/auth.js +78 -0
  77. package/dist/fourmeme/auth.js.map +1 -0
  78. package/dist/fourmeme/create.d.ts +31 -0
  79. package/dist/fourmeme/create.d.ts.map +1 -0
  80. package/dist/fourmeme/create.js +111 -0
  81. package/dist/fourmeme/create.js.map +1 -0
  82. package/dist/fourmeme/upload.d.ts +16 -0
  83. package/dist/fourmeme/upload.d.ts.map +1 -0
  84. package/dist/fourmeme/upload.js +52 -0
  85. package/dist/fourmeme/upload.js.map +1 -0
  86. package/dist/lib/bundle.d.ts +51 -0
  87. package/dist/lib/bundle.d.ts.map +1 -0
  88. package/dist/lib/bundle.js +95 -0
  89. package/dist/lib/bundle.js.map +1 -0
  90. package/dist/lib/config.d.ts +58 -0
  91. package/dist/lib/config.d.ts.map +1 -0
  92. package/dist/lib/config.js +183 -0
  93. package/dist/lib/config.js.map +1 -0
  94. package/dist/lib/const.d.ts +165 -0
  95. package/dist/lib/const.d.ts.map +1 -0
  96. package/dist/lib/const.js +98 -0
  97. package/dist/lib/const.js.map +1 -0
  98. package/dist/lib/env.d.ts +14 -0
  99. package/dist/lib/env.d.ts.map +1 -0
  100. package/dist/lib/env.js +18 -0
  101. package/dist/lib/env.js.map +1 -0
  102. package/dist/lib/guards.d.ts +44 -0
  103. package/dist/lib/guards.d.ts.map +1 -0
  104. package/dist/lib/guards.js +65 -0
  105. package/dist/lib/guards.js.map +1 -0
  106. package/dist/lib/identify.d.ts +85 -0
  107. package/dist/lib/identify.d.ts.map +1 -0
  108. package/dist/lib/identify.js +88 -0
  109. package/dist/lib/identify.js.map +1 -0
  110. package/dist/lib/pricing.d.ts +62 -0
  111. package/dist/lib/pricing.d.ts.map +1 -0
  112. package/dist/lib/pricing.js +302 -0
  113. package/dist/lib/pricing.js.map +1 -0
  114. package/dist/lib/routing.d.ts +57 -0
  115. package/dist/lib/routing.d.ts.map +1 -0
  116. package/dist/lib/routing.js +67 -0
  117. package/dist/lib/routing.js.map +1 -0
  118. package/dist/lib/slippage.d.ts +29 -0
  119. package/dist/lib/slippage.d.ts.map +1 -0
  120. package/dist/lib/slippage.js +110 -0
  121. package/dist/lib/slippage.js.map +1 -0
  122. package/dist/lib/tracker.d.ts +68 -0
  123. package/dist/lib/tracker.d.ts.map +1 -0
  124. package/dist/lib/tracker.js +155 -0
  125. package/dist/lib/tracker.js.map +1 -0
  126. package/dist/lib/viem.d.ts +12 -0
  127. package/dist/lib/viem.d.ts.map +1 -0
  128. package/dist/lib/viem.js +44 -0
  129. package/dist/lib/viem.js.map +1 -0
  130. package/dist/lib/wallet-rows.d.ts +30 -0
  131. package/dist/lib/wallet-rows.d.ts.map +1 -0
  132. package/dist/lib/wallet-rows.js +9 -0
  133. package/dist/lib/wallet-rows.js.map +1 -0
  134. package/dist/lib/walletClient.d.ts +16 -0
  135. package/dist/lib/walletClient.d.ts.map +1 -0
  136. package/dist/lib/walletClient.js +26 -0
  137. package/dist/lib/walletClient.js.map +1 -0
  138. package/dist/wallets/groups/encrypt.d.ts +26 -0
  139. package/dist/wallets/groups/encrypt.d.ts.map +1 -0
  140. package/dist/wallets/groups/encrypt.js +52 -0
  141. package/dist/wallets/groups/encrypt.js.map +1 -0
  142. package/dist/wallets/groups/generate.d.ts +19 -0
  143. package/dist/wallets/groups/generate.d.ts.map +1 -0
  144. package/dist/wallets/groups/generate.js +36 -0
  145. package/dist/wallets/groups/generate.js.map +1 -0
  146. package/dist/wallets/groups/store.d.ts +107 -0
  147. package/dist/wallets/groups/store.d.ts.map +1 -0
  148. package/dist/wallets/groups/store.js +254 -0
  149. package/dist/wallets/groups/store.js.map +1 -0
  150. package/package.json +50 -0
  151. package/skills/SKILL.md +187 -0
@@ -0,0 +1,68 @@
1
+ /**
2
+ * TxTracker — async tx confirmation + DataStore sink.
3
+ *
4
+ * After a command sends a transaction, it calls `trackInBackground(hash, ctx)`
5
+ * and returns immediately. The tracker waits for the receipt in parallel and
6
+ * writes a TransactionRecord + balance snapshot once the tx finalizes.
7
+ *
8
+ * Week 2 scope:
9
+ * - Transfer flows (transfer in/out) and dry-run trades
10
+ * - No on-chain event log decoding yet — we capture block info, gas,
11
+ * status, and a "known amount" passed from the caller
12
+ *
13
+ * Week 3 scope (not done here):
14
+ * - parseEventLogs for TokenManager2.TokenPurchase / TokenSale
15
+ * - Holdings re-accounting (avgBuyPrice / realizedPnl)
16
+ *
17
+ * Fire-and-forget: tracker failures are silent — they must never break the
18
+ * CLI's exit path or mask the original tx hash returned to the agent.
19
+ */
20
+ import type { Address, Hash, PublicClient } from 'viem';
21
+ import type { TxType } from '../datastore/types.js';
22
+ export type TrackContext = {
23
+ ca: Address;
24
+ groupId: number;
25
+ walletAddress: Address;
26
+ txType: TxType;
27
+ /**
28
+ * Signed BNB delta known at submit time (positive = inbound, negative = outbound).
29
+ * Used for transfers where the amount is part of the request, not an event.
30
+ */
31
+ knownAmountBnb?: number;
32
+ /**
33
+ * Counterparty address (for BNB balance snapshot refresh).
34
+ * Optional — if present, we also refresh their balance.
35
+ */
36
+ counterparty?: Address | undefined;
37
+ };
38
+ export type TrackingResult = {
39
+ txHash: Hash;
40
+ status: 'confirmed' | 'failed' | 'timeout';
41
+ blockNumber?: number | undefined;
42
+ blockTime?: number | undefined;
43
+ fee?: number | undefined;
44
+ };
45
+ /**
46
+ * Await a transaction, record it, refresh balances.
47
+ * Always resolves — never throws.
48
+ *
49
+ * If `preReceipt` is provided the receipt wait is skipped entirely — use this
50
+ * when the caller already awaited the receipt (e.g. sequential buy loop).
51
+ */
52
+ export declare function trackTransaction(client: PublicClient, txHash: Hash, context: TrackContext, timeoutMs?: number, preReceipt?: {
53
+ status: string;
54
+ blockNumber: bigint;
55
+ gasUsed: bigint;
56
+ effectiveGasPrice: bigint;
57
+ } | undefined): Promise<TrackingResult>;
58
+ /**
59
+ * Fire-and-forget variant. Does not block the caller and swallows all errors
60
+ * so the CLI can exit immediately after returning the tx hash to the agent.
61
+ */
62
+ export declare function trackInBackground(client: PublicClient, txHash: Hash, context: TrackContext, timeoutMs?: number, preReceipt?: {
63
+ status: string;
64
+ blockNumber: bigint;
65
+ gasUsed: bigint;
66
+ effectiveGasPrice: bigint;
67
+ } | undefined): void;
68
+ //# sourceMappingUR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AE,IAAI,EACZ,OAAO,EAAE,YAAY,EACrB,SAAS,SAAS,EAClB,UAAU,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GAC3G,IAAI,CAQN"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * TxTracker — async tx confirmation + DataStore sink.
3
+ *
4
+ * After a command sends a transaction, it calls `trackInBackground(hash, ctx)`
5
+ * and returns immediately. The tracker waits for the receipt in parallel and
6
+ * writes a TransactionRecord + balance snapshot once the tx finalizes.
7
+ *
8
+ * Week 2 scope:
9
+ * - Transfer flows (transfer in/out) and dry-run trades
10
+ * - No on-chain event log decoding yet — we capture block info, gas,
11
+ * status, and a "known amount" passed from the caller
12
+ *
13
+ * Week 3 scope (not done here):
14
+ * - parseEventLogs for TokenManager2.TokenPurchase / TokenSale
15
+ * - Holdings re-accounting (avgBuyPrice / realizedPnl)
16
+ *
17
+ * Fire-and-forget: tracker failures are silent — they must never break the
18
+ * CLI's exit path or mask the original tx hash returned to the agent.
19
+ */
20
+ import { formatEther, formatUnits } from 'viem';
21
+ import { erc20Abi } from '../contracts/erc20.js';
22
+ import { getDataStore } from '../datastore/index.js';
23
+ import { NATIVE_BNB } from './const.js';
24
+ // ============================================================
25
+ // Public API
26
+ // ============================================================
27
+ /**
28
+ * Await a transaction, record it, refresh balances.
29
+ * Always resolves — never throws.
30
+ *
31
+ * If `preReceipt` is provided the receipt wait is skipped entirely — use this
32
+ * when the caller already awaited the receipt (e.g. sequential buy loop).
33
+ */
34
+ export async function trackTransaction(client, txHash, context, timeoutMs = 30_000, preReceipt) {
35
+ try {
36
+ const receipt = preReceipt ?? await client.waitForTransactionReceipt({
37
+ hash: txHash,
38
+ timeout: timeoutMs,
39
+ });
40
+ const ds = getDataStore();
41
+ const status = receipt.status === 'success' ? 'confirmed' : 'failed';
42
+ // Best-effort block time
43
+ let blockTime = 0;
44
+ try {
45
+ const block = await client.getBlock({ blockNumber: receipt.blockNumber });
46
+ blockTime = Number(block.timestamp);
47
+ }
48
+ catch {
49
+ // fall through — not worth retrying
50
+ }
51
+ const feeBnb = Number(receipt.gasUsed * receipt.effectiveGasPrice) / 1e18;
52
+ ds.appendTransaction(context.ca, context.groupId, {
53
+ txHash,
54
+ txType: context.txType,
55
+ walletAddress: context.walletAddress,
56
+ tokenCA: context.ca,
57
+ amountBnb: context.knownAmountBnb ?? 0,
58
+ amountToken: 0,
59
+ pricePerToken: 0,
60
+ fee: feeBnb,
61
+ blockNumber: Number(receipt.blockNumber),
62
+ blockTime,
63
+ status,
64
+ });
65
+ if (status === 'confirmed') {
66
+ await refreshBalanceSnapshot(client, context.ca, context.groupId, context.walletAddress).catch(() => { });
67
+ await refreshTokenPositionSnapshot(client, context.ca, context.groupId, context.walletAddress, context.txType, context.knownAmountBnb).catch(() => { });
68
+ if (context.counterparty) {
69
+ await refreshBalanceSnapshot(client, context.ca, context.groupId, context.counterparty).catch(() => { });
70
+ }
71
+ }
72
+ return {
73
+ txHash,
74
+ status,
75
+ blockNumber: Number(receipt.blockNumber),
76
+ blockTime,
77
+ fee: feeBnb,
78
+ };
79
+ }
80
+ catch {
81
+ return { txHash, status: 'timeout' };
82
+ }
83
+ }
84
+ /**
85
+ * Fire-and-forget variant. Does not block the caller and swallows all errors
86
+ * so the CLI can exit immediately after returning the tx hash to the agent.
87
+ */
88
+ export function trackInBackground(client, txHash, context, timeoutMs = 30_000, preReceipt) {
89
+ // Use unref'd setTimeout so the pending promise doesn't prevent Node.js exit.
90
+ // The CLI can return tx hashes immediately; tracking happens if the process
91
+ // stays alive long enough, but never blocks exit.
92
+ const t = setTimeout(() => {
93
+ trackTransaction(client, txHash, context, timeoutMs, preReceipt).catch(() => { });
94
+ }, 0);
95
+ if (typeof t.unref === 'function')
96
+ t.unref();
97
+ }
98
+ // ============================================================
99
+ // Internal helpers
100
+ // ============================================================
101
+ /**
102
+ * Read BNB balance for a wallet and PATCH the DataStore balances snapshot.
103
+ *
104
+ * Critical: we send `bnbBalance` only — the DataStore's patch semantics
105
+ * preserve any existing `tokenBalance`. Overwriting tokenBalance to 0 would
106
+ * destroy data written by previous trade tx tracking.
107
+ */
108
+ async function refreshBalanceSnapshot(client, ca, groupId, wallet) {
109
+ const bnbWei = await client.getBalance({ address: wallet });
110
+ const bnb = Number(formatEther(bnbWei));
111
+ const ds = getDataStore();
112
+ ds.updateBalance(ca, groupId, wallet, { bnbBalance: bnb });
113
+ }
114
+ async function refreshTokenPositionSnapshot(client, ca, groupId, wallet, txType, knownAmountBnb) {
115
+ if (ca === NATIVE_BNB)
116
+ return;
117
+ const [rawTokenBalance, decimalsRaw] = await Promise.all([
118
+ client.readContract({
119
+ address: ca,
120
+ abi: erc20Abi,
121
+ functionName: 'balanceOf',
122
+ args: [wallet],
123
+ }),
124
+ client.readContract({
125
+ address: ca,
126
+ abi: erc20Abi,
127
+ functionName: 'decimals',
128
+ }),
129
+ ]);
130
+ const decimals = Number(decimalsRaw);
131
+ const tokenBalance = Number(formatUnits(rawTokenBalance, decimals));
132
+ const ds = getDataStore();
133
+ ds.updateBalance(ca, groupId, wallet, { tokenBalance });
134
+ const currentHolding = ds.getHoldings(ca, groupId)?.wallets.find((row) => row.walletAddress === wallet) ?? null;
135
+ const previousTokenBalance = currentHolding?.tokenBalance ?? 0;
136
+ const patch = { tokenBalance };
137
+ if (txType === 'buy' &&
138
+ typeof knownAmountBnb === 'number' &&
139
+ knownAmountBnb < 0 &&
140
+ tokenBalance > previousTokenBalance) {
141
+ const amountBought = tokenBalance - previousTokenBalance;
142
+ const totalBought = (currentHolding?.totalBought ?? 0) + amountBought;
143
+ const totalCostBnb = (currentHolding?.totalCostBnb ?? 0) + Math.abs(knownAmountBnb);
144
+ patch.totalBought = totalBought;
145
+ patch.totalCostBnb = totalCostBnb;
146
+ patch.avgBuyPrice = totalBought > 0 ? totalCostBnb / totalBought : 0;
147
+ }
148
+ if (txType === 'sell' && previousTokenBalance > tokenBalance) {
149
+ patch.totalSold =
150
+ (currentHolding?.totalSold ?? 0) +
151
+ (previousTokenBalance - tokenBalance);
152
+ }
153
+ ds.updateHolding(ca, groupId, wallet, patch);
154
+ }
155
+ //# sourceMappingURL=tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../src/lib/tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AA+BvC,+DAA+D;AAC/D,aAAa;AACb,+DAA+D;AAE/D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAoB,EACpB,MAAY,EACZ,OAAqB,EACrB,SAAS,GAAG,MAAM,EAClB,UAA4G;IAE5G,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,UAAU,IAAI,MAAM,MAAM,CAAC,yBAAyB,CAAC;YACnE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,SAAS;SACnB,CAAC,CAAA;QAEF,MAAM,EAAE,GAAG,YAAY,EAAE,CAAA;QACzB,MAAM,MAAM,GACV,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAA;QAEvD,yBAAyB;QACzB,IAAI,SAAS,GAAG,CAAC,CAAA;QACjB,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;YACzE,SAAS,GAAG,MAAM,CAAC,KAAK,C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CAAC,cAAc,EAAE,WAAW,IAAI,CAAC,CAAC,GAAG,YAAY,CAAA;QACrE,MAAM,YAAY,GAChB,CAAC,cAAc,EAAE,YAAY,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;QAEhE,KAAK,CAAC,WAAW,GAAG,WAAW,CAAA;QAC/B,KAAK,CAAC,YAAY,GAAG,YAAY,CAAA;QACjC,KAAK,CAAC,WAAW,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;IACtE,CAAC;IAED,IAAI,MAAM,KAAK,MAAM,IAAI,oBAAoB,GAAG,YAAY,EAAE,CAAC;QAC7D,KAAK,CAAC,SAAS;YACb,CAAC,cAAc,EAAE,SAAS,IAAI,CAAC,CAAC;gBAChC,CAAC,oBAAoB,GAAG,YAAY,CAAC,CAAA;IACzC,CAAC;IAED,EAAE,CAAC,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AAC9C,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * viem client factory for fourMM.
3
+ *
4
+ * Builds a public client from the current config — respects rpcUrl and
5
+ * fallbackRpcUrls from ~/.fourmm/config.json.
6
+ */
7
+ import { type PublicClient } from 'viem';
8
+ import { type SupportedChainName } from './const.js';
9
+ export declare function getPublicClient(network?: SupportedChainName | undefined): PublicClient;
10
+ /** Reset all cached clients (exposed for tests) */
11
+ export declare function resetPublicClients(): void;
12
+ //# sourceMappingURL=viem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viem.d.ts","sourceRoot":"","sources":["../../src/lib/viem.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAsC,KAAK,YAAY,EAAE,MAAM,MAAM,CAAA;AAE5E,OAAO,EAAU,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAoB5D,wBAAgB,eAAe,CAC7B,OAAO,CAAC,EAAE,kBAAkB,GAAG,SAAS,GACvC,YAAY,CAmBd;AAED,mDAAmD;AACnD,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * viem client factory for fourMM.
3
+ *
4
+ * Builds a public client from the current config — respects rpcUrl and
5
+ * fallbackRpcUrls from ~/.fourmm/config.json.
6
+ */
7
+ import { createPublicClient, fallback, http } from 'viem';
8
+ import { loadConfig } from './config.js';
9
+ import { CHAINS } from './const.js';
10
+ /**
11
+ * Build a viem PublicClient for reads.
12
+ *
13
+ * Uses viem's `fallback` transport so any failing RPC is rotated out
14
+ * automatically. Clients are cached by (network, rpcUrl, fallbackUrls) so
15
+ * that a `config set rpcUrl` invalidates the cache automatically —
16
+ * otherwise the process would keep the stale RPC until restart.
17
+ */
18
+ const clientCache = new Map();
19
+ function cacheKey(net, rpcUrl, fallbackUrls) {
20
+ return `${net}::${rpcUrl}::${fallbackUrls.join(',')}`;
21
+ }
22
+ export function getPublicClient(network) {
23
+ const config = loadConfig();
24
+ const net = network ?? config.network;
25
+ const key = cacheKey(net, config.rpcUrl, config.fallbackRpcUrls);
26
+ const cached = clientCache.get(key);
27
+ if (cached)
28
+ return cached;
29
+ const chain = CHAINS[net];
30
+ const transports = [config.rpcUrl, ...config.fallbackRpcUrls]
31
+ .filter((url) => Boolean(url))
32
+ .map((url) => http(url, { timeout: 8_000, retryCount: 2 }));
33
+ const client = createPublicClient({
34
+ chain,
35
+ transport: fallback(transports, { rank: true }),
36
+ });
37
+ clientCache.set(key, client);
38
+ return client;
39
+ }
40
+ /** Reset all cached clients (exposed for tests) */
41
+ export function resetPublicClients() {
42
+ clientCache.clear();
43
+ }
44
+ //# sourceMappingURL=viem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viem.js","sourceRoot":"","sources":["../../src/lib/viem.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,Q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,CAAA;IACF,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAC5B,OAAO,MAAM,CAAA;AACf,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,kBAAkB;IAChC,WAAW,CAAC,KAAK,EAAE,CAAA;AACrB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Shared row types for commands that iterate over a wallet group.
3
+ *
4
+ * `transfer in / out`, Week-3's `tools volume / turnover`, and anything else
5
+ * that "for each wallet in a group, do X with status" benefit from a common
6
+ * shape so the output schemas stay uniform.
7
+ */
8
+ import type { Hash } from 'viem';
9
+ import type { StoredWallet } from '../wallets/groups/store.js';
10
+ /**
11
+ * Per-wallet planning result produced during the dry-run phase.
12
+ * `insufficient` is distinct from `sendBnb === 0` so fixed-mode transfers can
13
+ * tell the user "this wallet can't cover the fixed amount + gas".
14
+ */
15
+ export type WalletRow = {
16
+ wallet: StoredWallet;
17
+ balanceBnb: number;
18
+ sendBnb: number;
19
+ /** Explicit flag — true when fixed mode wanted more than the wallet holds */
20
+ insufficient: boolean;
21
+ };
22
+ /** Per-wallet execution result (after broadcast or simulation attempt) */
23
+ export type WalletResult = {
24
+ from: string;
25
+ sendBnb: string;
26
+ status: 'ready' | 'broadcast' | 'skipped' | 'nothing-to-send' | 'insufficient-funds' | 'decrypt-failed' | 'failed';
27
+ txHash?: Hash | undefined;
28
+ error?: string | undefined;
29
+ };
30
+ //# sourceMappingURL=wallet-rows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-rows.d.ts","sourceRoot":"","sources":["../../src/lib/wallet-rows.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,YAAY,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,6EAA6E;IAC7E,YAAY,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,0EAA0E;AAC1E,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EACF,OAAO,GACP,WAAW,GACX,SAAS,GACT,iBAAiB,GACjB,oBAAoB,GACpB,gBAAgB,GAChB,QAAQ,CAAA;IACZ,MAAM,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC3B,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shared row types for commands that iterate over a wallet group.
3
+ *
4
+ * `transfer in / out`, Week-3's `tools volume / turnover`, and anything else
5
+ * that "for each wallet in a group, do X with status" benefit from a common
6
+ * shape so the output schemas stay uniform.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=wallet-rows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-rows.js","sourceRoot":"","sources":["../../src/lib/wallet-rows.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Shared viem WalletClient factory for trade / tools / transfer commands.
3
+ *
4
+ * Previously duplicated as tradeWalletClient / toolsWalletClient / walletClientFor
5
+ * across 3 command files. Extracted here so changes (nonce management, gas
6
+ * settings) are made in one place.
7
+ */
8
+ import { type WalletClient } from 'viem';
9
+ import { type PrivateKeyAccount } from 'viem/accounts';
10
+ import type { CliConfig } from './config.js';
11
+ /**
12
+ * Build a viem WalletClient for the given account + pre-loaded config.
13
+ * Rebuilt per wallet (signer identity changes) but RPC list is stable.
14
+ */
15
+ export declare function makeWalletClient(account: PrivateKeyAccount, config: CliConfig): WalletClient;
16
+ //# sourceMappingURL=walletClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walletClient.d.ts","sourceRoot":"","sources":["../../src/lib/walletClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,SAAS,GAChB,YAAY,CAUd"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Shared viem WalletClient factory for trade / tools / transfer commands.
3
+ *
4
+ * Previously duplicated as tradeWalletClient / toolsWalletClient / walletClientFor
5
+ * across 3 command files. Extracted here so changes (nonce management, gas
6
+ * settings) are made in one place.
7
+ */
8
+ import { createWalletClient, fallback, http, } from 'viem';
9
+ import {} from 'viem/accounts';
10
+ import { bsc, bscTestnet } from 'viem/chains';
11
+ /**
12
+ * Build a viem WalletClient for the given account + pre-loaded config.
13
+ * Rebuilt per wallet (signer identity changes) but RPC list is stable.
14
+ */
15
+ export function makeWalletClient(account, config) {
16
+ const chain = config.network === 'bsc-testnet' ? bscTestnet : bsc;
17
+ const transports = [config.rpcUrl, ...config.fallbackRpcUrls]
18
+ .filter((url) => Boolean(url))
19
+ .map((url) => http(url, { timeout: 8_000 }));
20
+ return createWalletClient({
21
+ account,
22
+ chain,
23
+ transport: fallback(transports, { rank: true }),
24
+ });
25
+ }
26
+ //# sourceMappingURL=walletClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walletClient.js","sourceRoot":"","sources":["../../src/lib/walletClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,IAAI,GAEL,MAAM,MAAM,CAAA;AACb,OAAO,EAA0B,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAA0B,EAC1B,MAAiB;IAEjB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,KAAK,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAA;IACjE,MAAM,UAAU,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,eAAe,CAAC;SAC1D,MAAM,CAAC,CAAC,GAAG,EAAiB,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SAC5C,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,kBAAkB,CAAC;QACxB,OAAO;QACP,KAAK;QACL,SAAS,EAAE,QAAQ,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;KAChD,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * AES encryption primitives for in-house wallet groups.
3
+ *
4
+ * We use crypto-js AES because:
5
+ * 1. It's pure JS — no native binaries — so the build stays portable
6
+ * 2. `CryptoJS.AES.encrypt(text, passphrase)` bakes salt + IV into the
7
+ * ciphertext output, so we don't have to manage those ourselves
8
+ *
9
+ * These in-house keys are short-lived sniper/volume wallets; the threat
10
+ * model is "local disk + master password, encrypted at rest".
11
+ *
12
+ * Note: this format is NOT wire-compatible with ForgeX. The password-check
13
+ * marker is "ALMM_PASSWORD_OK" (kept for backward compat; ForgeX used "FORGEX_PASSWORD_OK").
14
+ */
15
+ /** Encrypt a value with AES using the master password */
16
+ export declare function encrypt(plaintext: string, password: string): string;
17
+ /**
18
+ * Decrypt an AES ciphertext with the master password.
19
+ * Throws if decryption yields an empty string (wrong password or corrupt data).
20
+ */
21
+ export declare function decrypt(ciphertext: string, password: string): string;
22
+ /** Generate a password check string for vault verification */
23
+ export declare function generatePasswordCheck(password: string): string;
24
+ /** Verify a password against a stored check string */
25
+ export declare function verifyPassword(password: string, check: string): boolean;
26
+ //# sourceMappingURL=encrypt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../src/wallets/groups/encrypt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH,yDAAyD;AACzD,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQpE;AAED,8DAA8D;AAC9D,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,sDAAsD;AACtD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAMvE"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * AES encryption primitives for in-house wallet groups.
3
+ *
4
+ * We use crypto-js AES because:
5
+ * 1. It's pure JS — no native binaries — so the build stays portable
6
+ * 2. `CryptoJS.AES.encrypt(text, passphrase)` bakes salt + IV into the
7
+ * ciphertext output, so we don't have to manage those ourselves
8
+ *
9
+ * These in-house keys are short-lived sniper/volume wallets; the threat
10
+ * model is "local disk + master password, encrypted at rest".
11
+ *
12
+ * Note: this format is NOT wire-compatible with ForgeX. The password-check
13
+ * marker is "ALMM_PASSWORD_OK" (kept for backward compat; ForgeX used "FORGEX_PASSWORD_OK").
14
+ */
15
+ import CryptoJS from 'crypto-js';
16
+ // Marker plaintext used to verify the master password without needing to
17
+ // decrypt an entire wallet's private key first.
18
+ const PASSWORD_CHECK_PLAINTEXT = 'ALMM_PASSWORD_OK';
19
+ /** Encrypt a value with AES using the master password */
20
+ export function encrypt(plaintext, password) {
21
+ if (!password)
22
+ throw new Error('encrypt: password is empty');
23
+ return CryptoJS.AES.encrypt(plaintext, password).toString();
24
+ }
25
+ /**
26
+ * Decrypt an AES ciphertext with the master password.
27
+ * Throws if decryption yields an empty string (wrong password or corrupt data).
28
+ */
29
+ export function decrypt(ciphertext, password) {
30
+ if (!password)
31
+ throw new Error('decrypt: password is empty');
32
+ const bytes = CryptoJS.AES.decrypt(ciphertext, password);
33
+ const result = bytes.toString(CryptoJS.enc.Utf8);
34
+ if (!result) {
35
+ throw new Error('decrypt: wrong password or corrupt data');
36
+ }
37
+ return result;
38
+ }
39
+ /** Generate a password check string for vault verification */
40
+ export function generatePasswordCheck(password) {
41
+ return encrypt(PASSWORD_CHECK_PLAINTEXT, password);
42
+ }
43
+ /** Verify a password against a stored check string */
44
+ export function verifyPassword(password, check) {
45
+ try {
46
+ return decrypt(check, password) === PASSWORD_CHECK_PLAINTEXT;
47
+ }
48
+ catch {
49
+ return false;
50
+ }
51
+ }
52
+ //# sourceMappingURL=encrypt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../../../src/wallets/groups/encrypt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,QAAQ,MAAM,WAAW,CAAA;AAEhC,yEAAyE;AACzE,gDAAgD;AAChD,MAAM,wBAAwB,GAAG,kBAAkB,CAAA;AAEnD,yDAAyD;AACzD,MAAM,UAAU,OAAO,CAAC,SAAiB,EAAE,QAAgB;IACzD,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;IAC5D,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAA;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,UAAkB,EAAE,QAAgB;IAC1D,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;IAC5D,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IACxD,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAChD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;IAC5D,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,qBAAqB,CAAC,QAAgB;IACpD,OAAO,OAAO,CAAC,wBAAwB,EAAE,QAAQ,CAAC,CAAA;AACpD,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,KAAa;IAC5D,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,wBAAwB,CAAA;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * In-house wallet generation (batch private keys for sniper / volume groups).
3
+ *
4
+ * We use viem's generatePrivateKey — cryptographically secure random secp256k1 keys.
5
+ * No HD derivation here: each wallet is independent, no shared seed.
6
+ * That's intentional for sniper groups — if one key leaks, the blast radius
7
+ * is bounded to that single wallet.
8
+ */
9
+ import type { Address, Hex } from 'viem';
10
+ export type GeneratedWallet = {
11
+ address: Address;
12
+ privateKey: Hex;
13
+ note: string;
14
+ };
15
+ /** Generate N fresh wallets */
16
+ export declare function generateWallets(count: number, notePrefix?: string): GeneratedWallet[];
17
+ /** Import a wallet from an existing private key */
18
+ export declare function walletFromPrivateKey(privateKey: Hex, note?: string): GeneratedWallet;
19
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/wallets/groups/generate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAExC,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,GAAG,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,+BAA+B;AAC/B,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,SAAK,GAAG,eAAe,EAAE,CAejF;AAED,mDAAmD;AACnD,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,GAAG,EACf,IAAI,SAAK,GACR,eAAe,CAOjB"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * In-house wallet generation (batch private keys for sniper / volume groups).
3
+ *
4
+ * We use viem's generatePrivateKey — cryptographically secure random secp256k1 keys.
5
+ * No HD derivation here: each wallet is independent, no shared seed.
6
+ * That's intentional for sniper groups — if one key leaks, the blast radius
7
+ * is bounded to that single wallet.
8
+ */
9
+ import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
10
+ /** Generate N fresh wallets */
11
+ export function generateWallets(count, notePrefix = '') {
12
+ if (!Number.isInteger(count) || count <= 0) {
13
+ throw new Error(`generateWallets: count must be a positive integer, got ${count}`);
14
+ }
15
+ const wallets = [];
16
+ for (let i = 0; i < count; i++) {
17
+ const pk = generatePrivateKey();
18
+ const account = privateKeyToAccount(pk);
19
+ wallets.push({
20
+ address: account.address,
21
+ privateKey: pk,
22
+ note: notePrefix ? `${notePrefix} #${i + 1}` : '',
23
+ });
24
+ }
25
+ return wallets;
26
+ }
27
+ /** Import a wallet from an existing private key */
28
+ export function walletFromPrivateKey(privateKey, note = '') {
29
+ const account = privateKeyToAccount(privateKey);
30
+ return {
31
+ address: account.address,
32
+ privateKey,
33
+ note,
34
+ };
35
+ }
36
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/wallets/groups/generate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AASvE,+BAA+B;AAC/B,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,UAAU,GAAG,EAAE;IAC5D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,0DAA0D,KAAK,EAAE,CAAC,CAAA;IACpF,CAAC;IACD,MAAM,OAAO,GAAsB,EAAE,CAAA;IACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,MAAM,EAAE,GAAG,kBAAkB,EAAE,CAAA;QAC/B,MAAM,OAAO,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAA;QACvC,OAAO,CAAC,IAAI,CAAC;YACX,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,UAAU,EAAE,EAAE;YACd,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;SAClD,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,oBAAoB,CAClC,UAAe,EACf,IAAI,GAAG,EAAE;IAET,MAAM,OAAO,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAA;IAC/C,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,UAAU;QACV,IAAI;KACL,CAAA;AACH,CAAC"}