oneie 5.7.6 → 5.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/README.md +19 -1
  2. package/dist/package.json +7 -8
  3. package/dist/src/age-yefbe8pe.js +1 -0
  4. package/dist/src/evm-tx-ee2q0e3w.js +1 -0
  5. package/dist/src/hl-run-tgrkrk69.js +1 -0
  6. package/dist/src/index-0rj9wdk9.js +4 -0
  7. package/dist/src/index-91y484c2.js +2052 -0
  8. package/dist/src/index-940y3rnv.js +12 -0
  9. package/dist/src/index.js +1047 -121
  10. package/dist/src/message-key-db1xjdkw.js +1 -0
  11. package/dist/src/message-lock-5vr8079x.js +5 -0
  12. package/dist/src/sweep-order-c2p6rk8c.js +1 -0
  13. package/dist/src/sweep-runner-t68xe7vx.js +1 -0
  14. package/package.json +7 -8
  15. package/dist/src/agent.d.ts +0 -75
  16. package/dist/src/agent.js +0 -1334
  17. package/dist/src/agentverse.d.ts +0 -26
  18. package/dist/src/agentverse.js +0 -171
  19. package/dist/src/args.d.ts +0 -9
  20. package/dist/src/args.js +0 -61
  21. package/dist/src/auth.d.ts +0 -6
  22. package/dist/src/auth.js +0 -121
  23. package/dist/src/balances.d.ts +0 -89
  24. package/dist/src/balances.js +0 -202
  25. package/dist/src/banner.d.ts +0 -1
  26. package/dist/src/banner.js +0 -17
  27. package/dist/src/broadcast.d.ts +0 -8
  28. package/dist/src/broadcast.js +0 -175
  29. package/dist/src/catalog.d.ts +0 -12
  30. package/dist/src/catalog.js +0 -76
  31. package/dist/src/chat.d.ts +0 -2
  32. package/dist/src/chat.js +0 -92
  33. package/dist/src/client.d.ts +0 -5
  34. package/dist/src/client.js +0 -157
  35. package/dist/src/compiler.d.ts +0 -36
  36. package/dist/src/compiler.js +0 -366
  37. package/dist/src/config.d.ts +0 -24
  38. package/dist/src/config.js +0 -70
  39. package/dist/src/connect.d.ts +0 -2
  40. package/dist/src/connect.js +0 -64
  41. package/dist/src/coordinate.d.ts +0 -3
  42. package/dist/src/coordinate.js +0 -58
  43. package/dist/src/create.d.ts +0 -2
  44. package/dist/src/create.js +0 -113
  45. package/dist/src/deploy.d.ts +0 -2
  46. package/dist/src/deploy.js +0 -19
  47. package/dist/src/dev.d.ts +0 -2
  48. package/dist/src/dev.js +0 -75
  49. package/dist/src/device-flow.d.ts +0 -57
  50. package/dist/src/device-flow.js +0 -173
  51. package/dist/src/doctor.d.ts +0 -26
  52. package/dist/src/doctor.js +0 -146
  53. package/dist/src/draw.d.ts +0 -18
  54. package/dist/src/draw.js +0 -156
  55. package/dist/src/endpoint.d.ts +0 -2
  56. package/dist/src/endpoint.js +0 -250
  57. package/dist/src/env.d.ts +0 -3
  58. package/dist/src/env.js +0 -37
  59. package/dist/src/eval.d.ts +0 -2
  60. package/dist/src/eval.js +0 -43
  61. package/dist/src/fn.d.ts +0 -2
  62. package/dist/src/fn.js +0 -70
  63. package/dist/src/group.d.ts +0 -2
  64. package/dist/src/group.js +0 -117
  65. package/dist/src/hl-run.d.ts +0 -119
  66. package/dist/src/hl-run.js +0 -480
  67. package/dist/src/hl.d.ts +0 -17
  68. package/dist/src/hl.js +0 -148
  69. package/dist/src/index.d.ts +0 -2
  70. package/dist/src/init.d.ts +0 -76
  71. package/dist/src/init.js +0 -278
  72. package/dist/src/join.d.ts +0 -11
  73. package/dist/src/join.js +0 -293
  74. package/dist/src/key-publish.d.ts +0 -40
  75. package/dist/src/key-publish.js +0 -232
  76. package/dist/src/key-seal.d.ts +0 -21
  77. package/dist/src/key-seal.js +0 -142
  78. package/dist/src/key-sweep.d.ts +0 -93
  79. package/dist/src/key-sweep.js +0 -263
  80. package/dist/src/key.d.ts +0 -26
  81. package/dist/src/key.js +0 -338
  82. package/dist/src/lib/age-plugin.d.ts +0 -51
  83. package/dist/src/lib/age-plugin.js +0 -130
  84. package/dist/src/lib/agent-env.d.ts +0 -12
  85. package/dist/src/lib/agent-env.js +0 -48
  86. package/dist/src/lib/api-path.d.ts +0 -2
  87. package/dist/src/lib/api-path.js +0 -40
  88. package/dist/src/lib/asker.d.ts +0 -34
  89. package/dist/src/lib/asker.js +0 -126
  90. package/dist/src/lib/client.d.ts +0 -20
  91. package/dist/src/lib/client.js +0 -71
  92. package/dist/src/lib/env-sealed.d.ts +0 -53
  93. package/dist/src/lib/env-sealed.js +0 -184
  94. package/dist/src/lib/flow-tag.d.ts +0 -86
  95. package/dist/src/lib/flow-tag.js +0 -230
  96. package/dist/src/lib/hl-core/actions.d.ts +0 -99
  97. package/dist/src/lib/hl-core/actions.js +0 -69
  98. package/dist/src/lib/hl-core/eip712.d.ts +0 -33
  99. package/dist/src/lib/hl-core/eip712.js +0 -107
  100. package/dist/src/lib/hl-core/errors.d.ts +0 -10
  101. package/dist/src/lib/hl-core/errors.js +0 -15
  102. package/dist/src/lib/hl-core/exchange.d.ts +0 -24
  103. package/dist/src/lib/hl-core/exchange.js +0 -47
  104. package/dist/src/lib/hl-core/index.d.ts +0 -13
  105. package/dist/src/lib/hl-core/index.js +0 -14
  106. package/dist/src/lib/hl-core/meta.d.ts +0 -57
  107. package/dist/src/lib/hl-core/meta.js +0 -110
  108. package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
  109. package/dist/src/lib/hl-core/msgpack.js +0 -136
  110. package/dist/src/lib/hl-core/net.d.ts +0 -2
  111. package/dist/src/lib/hl-core/net.js +0 -7
  112. package/dist/src/lib/hl-core/signing.d.ts +0 -103
  113. package/dist/src/lib/hl-core/signing.js +0 -295
  114. package/dist/src/lib/hl-core/wire.d.ts +0 -34
  115. package/dist/src/lib/hl-core/wire.js +0 -81
  116. package/dist/src/lib/invoked-as.d.ts +0 -2
  117. package/dist/src/lib/invoked-as.js +0 -24
  118. package/dist/src/lib/journey-words.d.ts +0 -84
  119. package/dist/src/lib/journey-words.js +0 -360
  120. package/dist/src/lib/journey.d.ts +0 -148
  121. package/dist/src/lib/journey.js +0 -245
  122. package/dist/src/lib/key-receipt.d.ts +0 -48
  123. package/dist/src/lib/key-receipt.js +0 -116
  124. package/dist/src/lib/key-source.d.ts +0 -9
  125. package/dist/src/lib/key-source.js +0 -33
  126. package/dist/src/lib/keyfile.d.ts +0 -136
  127. package/dist/src/lib/keyfile.js +0 -397
  128. package/dist/src/lib/launch-claude.d.ts +0 -5
  129. package/dist/src/lib/launch-claude.js +0 -45
  130. package/dist/src/lib/lock-lookup.d.ts +0 -40
  131. package/dist/src/lib/lock-lookup.js +0 -92
  132. package/dist/src/lib/message-seal.d.ts +0 -63
  133. package/dist/src/lib/message-seal.js +0 -150
  134. package/dist/src/lib/network.d.ts +0 -15
  135. package/dist/src/lib/network.js +0 -41
  136. package/dist/src/lib/paths.d.ts +0 -41
  137. package/dist/src/lib/paths.js +0 -91
  138. package/dist/src/lib/plan-draw.d.ts +0 -56
  139. package/dist/src/lib/plan-draw.js +0 -219
  140. package/dist/src/lib/plan-live.d.ts +0 -20
  141. package/dist/src/lib/plan-live.js +0 -192
  142. package/dist/src/lib/qr.d.ts +0 -21
  143. package/dist/src/lib/qr.js +0 -402
  144. package/dist/src/lib/roster.d.ts +0 -20
  145. package/dist/src/lib/roster.js +0 -79
  146. package/dist/src/lib/sale-card.d.ts +0 -117
  147. package/dist/src/lib/sale-card.js +0 -261
  148. package/dist/src/lib/shop-init.d.ts +0 -62
  149. package/dist/src/lib/shop-init.js +0 -63
  150. package/dist/src/lib/sui-grpc-send.d.ts +0 -50
  151. package/dist/src/lib/sui-grpc-send.js +0 -89
  152. package/dist/src/lib/swap-core.d.ts +0 -163
  153. package/dist/src/lib/swap-core.js +0 -405
  154. package/dist/src/lib/tasks-digest.d.ts +0 -66
  155. package/dist/src/lib/tasks-digest.js +0 -200
  156. package/dist/src/lib/tasks-graph.d.ts +0 -79
  157. package/dist/src/lib/tasks-graph.js +0 -463
  158. package/dist/src/lib/tasks-lens.d.ts +0 -31
  159. package/dist/src/lib/tasks-lens.js +0 -47
  160. package/dist/src/lib/tasks-next.d.ts +0 -25
  161. package/dist/src/lib/tasks-next.js +0 -103
  162. package/dist/src/lib/tasks-prove.d.ts +0 -15
  163. package/dist/src/lib/tasks-prove.js +0 -68
  164. package/dist/src/lib/tasks-route.d.ts +0 -29
  165. package/dist/src/lib/tasks-route.js +0 -151
  166. package/dist/src/lib/tasks-score.d.ts +0 -36
  167. package/dist/src/lib/tasks-score.js +0 -152
  168. package/dist/src/lib/tasks-workspace.d.ts +0 -18
  169. package/dist/src/lib/tasks-workspace.js +0 -73
  170. package/dist/src/lib/vault-read.d.ts +0 -24
  171. package/dist/src/lib/vault-read.js +0 -77
  172. package/dist/src/lib/vaultfile.d.ts +0 -88
  173. package/dist/src/lib/vaultfile.js +0 -222
  174. package/dist/src/lib/wallet-money.d.ts +0 -222
  175. package/dist/src/lib/wallet-money.js +0 -578
  176. package/dist/src/lib/wallet-request.d.ts +0 -50
  177. package/dist/src/lib/wallet-request.js +0 -86
  178. package/dist/src/links.d.ts +0 -5
  179. package/dist/src/links.js +0 -45
  180. package/dist/src/media.d.ts +0 -29
  181. package/dist/src/media.js +0 -487
  182. package/dist/src/message-receipt.d.ts +0 -25
  183. package/dist/src/message-receipt.js +0 -71
  184. package/dist/src/message.d.ts +0 -13
  185. package/dist/src/message.js +0 -92
  186. package/dist/src/onboard.d.ts +0 -16
  187. package/dist/src/onboard.js +0 -149
  188. package/dist/src/plugin.d.ts +0 -2
  189. package/dist/src/plugin.js +0 -193
  190. package/dist/src/push.d.ts +0 -2
  191. package/dist/src/push.js +0 -115
  192. package/dist/src/render.d.ts +0 -21
  193. package/dist/src/render.js +0 -32
  194. package/dist/src/secrets-device.d.ts +0 -32
  195. package/dist/src/secrets-device.js +0 -127
  196. package/dist/src/secrets-give.d.ts +0 -125
  197. package/dist/src/secrets-give.js +0 -236
  198. package/dist/src/secrets-list.d.ts +0 -27
  199. package/dist/src/secrets-list.js +0 -84
  200. package/dist/src/secrets-run.d.ts +0 -31
  201. package/dist/src/secrets-run.js +0 -182
  202. package/dist/src/secrets.d.ts +0 -33
  203. package/dist/src/secrets.js +0 -200
  204. package/dist/src/setup.d.ts +0 -6
  205. package/dist/src/setup.js +0 -127
  206. package/dist/src/ship.d.ts +0 -2
  207. package/dist/src/ship.js +0 -18
  208. package/dist/src/shop.d.ts +0 -10
  209. package/dist/src/shop.js +0 -110
  210. package/dist/src/skill-parser.d.ts +0 -14
  211. package/dist/src/skill-parser.js +0 -113
  212. package/dist/src/skill.d.ts +0 -2
  213. package/dist/src/skill.js +0 -493
  214. package/dist/src/slug.d.ts +0 -2
  215. package/dist/src/slug.js +0 -6
  216. package/dist/src/social.d.ts +0 -2
  217. package/dist/src/social.js +0 -106
  218. package/dist/src/staff.d.ts +0 -2
  219. package/dist/src/staff.js +0 -104
  220. package/dist/src/start.d.ts +0 -15
  221. package/dist/src/start.js +0 -203
  222. package/dist/src/status.d.ts +0 -2
  223. package/dist/src/status.js +0 -52
  224. package/dist/src/substrate.d.ts +0 -2
  225. package/dist/src/substrate.js +0 -258
  226. package/dist/src/swap.d.ts +0 -93
  227. package/dist/src/swap.js +0 -622
  228. package/dist/src/tasks.d.ts +0 -2
  229. package/dist/src/tasks.js +0 -743
  230. package/dist/src/templates.d.ts +0 -1
  231. package/dist/src/templates.js +0 -213
  232. package/dist/src/trade.d.ts +0 -2
  233. package/dist/src/trade.js +0 -91
  234. package/dist/src/trail.d.ts +0 -2
  235. package/dist/src/trail.js +0 -41
  236. package/dist/src/validate.d.ts +0 -13
  237. package/dist/src/validate.js +0 -35
  238. package/dist/src/wallet-money.d.ts +0 -152
  239. package/dist/src/wallet-money.js +0 -564
  240. package/dist/src/wallet.d.ts +0 -167
  241. package/dist/src/wallet.js +0 -855
  242. package/dist/src/workflow.d.ts +0 -2
  243. package/dist/src/workflow.js +0 -166
  244. package/dist/src/write.d.ts +0 -43
  245. package/dist/src/write.js +0 -180
@@ -1,89 +0,0 @@
1
- export const SUI_GRPC = {
2
- mainnet: 'https://fullnode.mainnet.sui.io:443',
3
- testnet: 'https://fullnode.testnet.sui.io:443',
4
- };
5
- /** A variable specifier: no bundler or typechecker pulls @mysten/sui in; it loads from the person's own install. */
6
- export const loadSpec = (spec) => import(spec);
7
- /** A named failure that may carry the digest of a transaction that might still land. */
8
- export class SuiSendError extends Error {
9
- code;
10
- digest;
11
- constructor(code, message, digest) {
12
- super(message);
13
- this.code = code;
14
- this.digest = digest;
15
- }
16
- }
17
- const withDeadline = (p, ms, code, digest) => new Promise((resolve, reject) => {
18
- const t = setTimeout(() => reject(new SuiSendError(code, `the node did not answer within ${Math.round(ms / 1000)} s`, digest)), ms);
19
- p.then((v) => { clearTimeout(t); resolve(v); }, (e) => { clearTimeout(t); reject(e); });
20
- });
21
- export const gasMistOf = (g) => {
22
- if (!g)
23
- return 0n;
24
- const n = BigInt(g.computationCost ?? 0) + BigInt(g.storageCost ?? 0) - BigInt(g.storageRebate ?? 0);
25
- return n > 0n ? n : 0n;
26
- };
27
- export async function suiSendGrpc(r, load = loadSpec, deadlineMs = 30_000) {
28
- let kp, grpc, txm; // eslint-disable-line @typescript-eslint/no-explicit-any
29
- try {
30
- ;
31
- [kp, grpc, txm] = await Promise.all([load('@mysten/sui/keypairs/ed25519'), load('@mysten/sui/grpc'), load('@mysten/sui/transactions')]);
32
- }
33
- catch {
34
- throw new SuiSendError('sui_signer_unavailable', 'install @mysten/sui beside oneie (npm i @mysten/sui)');
35
- }
36
- const hex = r.privateKeyHex.replace(/^0x/, '');
37
- const keypair = kp.Ed25519Keypair.fromSecretKey(Uint8Array.from((hex.match(/.{2}/g) ?? []).map((x) => parseInt(x, 16))));
38
- if (String(keypair.toSuiAddress()).toLowerCase() !== r.from.toLowerCase())
39
- throw new SuiSendError('vault_key_mismatch', 'the vault key does not derive the sending address');
40
- const baseUrl = (r.rpc ?? SUI_GRPC[r.net]).replace(/\/$/, '');
41
- const client = new grpc.SuiGrpcClient({ network: r.net, baseUrl });
42
- const tx = new txm.Transaction();
43
- tx.setSender(keypair.toSuiAddress());
44
- tx.transferObjects([txm.coinWithBalance({ type: r.coinType, balance: r.amountUnits })], tx.pure.address(r.to));
45
- let bytes;
46
- try {
47
- bytes = await withDeadline(tx.build({ client }), deadlineMs, 'sui_node_unreachable');
48
- }
49
- catch (e) {
50
- if (e instanceof SuiSendError)
51
- throw new SuiSendError('sui_node_unreachable', `${new URL(baseUrl).host}: ${e.message}. Nothing was signed.`);
52
- const m = e.message ?? String(e);
53
- if (/fetch failed|ECONN|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|unavailable|network/i.test(m))
54
- throw new SuiSendError('sui_node_unreachable', `${new URL(baseUrl).host}: ${m}. Nothing was signed. Pass --rpc <a gRPC base URL> to use another node.`);
55
- throw new SuiSendError('sui_build_failed', `${m}. Nothing was signed.`);
56
- }
57
- // The digest of the very bytes we are about to sign — derived from them, never asked of a node, so it cannot hang.
58
- const digest = String(txm.TransactionDataBuilder.getDigestFromBytes(bytes));
59
- const t0 = Date.now();
60
- const { signature } = await keypair.signTransaction(bytes);
61
- let res; // eslint-disable-line @typescript-eslint/no-explicit-any
62
- try {
63
- res = await withDeadline(client.core.executeTransaction({ transaction: bytes, signatures: [signature], include: { effects: true } }), deadlineMs, 'sui_unconfirmed', digest);
64
- }
65
- catch (e) {
66
- if (e instanceof SuiSendError)
67
- throw e;
68
- // Did the network take it anyway? Ask by digest before telling anyone it failed.
69
- throw new SuiSendError('sui_unconfirmed', `${e.message}. It may still have landed`, digest);
70
- }
71
- const finalMs = Date.now() - t0;
72
- const done = res?.Transaction ?? res?.FailedTransaction;
73
- if (!done)
74
- throw new SuiSendError('sui_unconfirmed', 'the node answered without a transaction', digest);
75
- if (done.status?.success !== true)
76
- throw new SuiSendError('sui_transfer_failed', String(done.status?.error?.message ?? 'the transfer failed on chain'), String(done.digest ?? digest));
77
- // Read-your-write for whoever looks next; not part of finalMs and never allowed to fail a landed send.
78
- try {
79
- await withDeadline(client.core.waitForTransaction({ digest: String(done.digest ?? digest) }), 10_000, 'wait_timeout');
80
- }
81
- catch { /* landed already */ }
82
- return { digest: String(done.digest ?? digest), gasMist: gasMistOf(done.effects?.gasUsed), finalMs };
83
- }
84
- /** 1_234_000_000 MIST → "1.234 SUI" (trailing zeros trimmed, at least one digit). */
85
- export function mistToSui(mist) {
86
- const w = (mist / 1000000000n).toString();
87
- const f = (mist % 1000000000n).toString().padStart(9, '0').replace(/0+$/, '');
88
- return f ? `${w}.${f}` : w;
89
- }
@@ -1,163 +0,0 @@
1
- /**
2
- * swap-core — the pure half of `one swap` (text/swap-plan.md § CLI).
3
- *
4
- * The CLI cannot import one.ie/web code and must not import a new @oneie/sdk export
5
- * (R2: packages/cli/node_modules resolves another tree's SDK, so a new subpath would pass
6
- * hollow). So the four things the client check needs are ported here, verbatim in behaviour,
7
- * and tests/swap-parity.test.ts runs them against the web originals so the copy cannot drift:
8
- *
9
- * SWAP_TABLE + resolveAlias ← one.ie/web/src/lib/swap/assets.ts (SWAP_ASSETS, resolveAsset)
10
- * parseUnits + formatUnits ← one.ie/web/src/lib/units.ts
11
- * checkQuote ← one.ie/web/src/lib/swap/core.ts (R16, incl. 3fef1b14c fields)
12
- * sendUri ← one.ie/web/src/lib/swap/core.ts
13
- *
14
- * Nothing here touches the network, and nothing here ever signs. No Number cast touches an amount.
15
- */
16
- export type SwapChain = 'ethereum' | 'base' | 'arbitrum' | 'solana' | 'sui' | 'bitcoin' | 'hyperliquid';
17
- export type SwapSigner = 'browser' | 'external' | 'none';
18
- export interface SwapRow {
19
- alias: string;
20
- chain: SwapChain;
21
- symbol: string;
22
- assetId: string;
23
- decimals: number;
24
- contract: string | null;
25
- signer: SwapSigner;
26
- origin: boolean;
27
- destination: boolean;
28
- }
29
- export declare const HL_USDC_ASSET_ID = "1cs_v1:hypercore:hip1:0x6d1e7cde53ba9467b783cb7c530ce054";
30
- /** Copied from one.ie/web/src/lib/swap/assets.ts — tests/swap-parity.test.ts pins it row by row. */
31
- export declare const SWAP_TABLE: readonly SwapRow[];
32
- export type AliasResult = {
33
- ok: true;
34
- asset: SwapRow;
35
- } | {
36
- ok: false;
37
- error: 'unknown_asset';
38
- } | {
39
- ok: false;
40
- error: 'ambiguous_asset';
41
- options: string[];
42
- } | {
43
- ok: false;
44
- error: 'not_a_destination';
45
- asset: SwapRow;
46
- };
47
- /** Same rules as the web resolveAsset — a parity test compares every alias both ways. */
48
- export declare function resolveAlias(input: unknown, side: 'from' | 'to'): AliasResult;
49
- export declare function rowById(assetId: unknown): SwapRow | undefined;
50
- export declare function parseUnits(input: string, decimals: number): bigint | null;
51
- export declare function formatUnits(value: bigint, decimals: number): string;
52
- /** The one rule (plan § CLI): the amount is the token that looks like a plain decimal. */
53
- export declare const AMOUNT_TOKEN: RegExp;
54
- export type Words = {
55
- ok: true;
56
- amount: string;
57
- from: string;
58
- to: string;
59
- } | {
60
- ok: false;
61
- error: 'bad_amount' | 'usage';
62
- next: string;
63
- };
64
- /**
65
- * `one swap 0.01 BTC hl` = `one swap 0.01 BTC to hl` = `one swap BTC hl 0.01`.
66
- * Exactly one plain-decimal amount (nonzero), a literal `to` dropped, two asset words left
67
- * in order (from, to). `1e3`, `0x10`, `-1`, `.5` and `0` are refused here, before any call.
68
- */
69
- export declare function parseSwapWords(words: readonly string[]): Words;
70
- /** --slippage <bps>: an integer 1..500, read by regex and parseInt, never a Number cast. */
71
- export declare function parseSlippage(s: string | undefined): {
72
- ok: true;
73
- bps?: number;
74
- } | {
75
- ok: false;
76
- };
77
- /** --mine a,b,c → the caller's own addresses, as typed. */
78
- export declare function parseMine(s: string | undefined): string[];
79
- export declare const ONECLICK = "https://1click.chaindefuser.com";
80
- export declare const ONECLICK_PROTOCOL_RECIPIENT = "5880ad2b362620fadf759cbceb1cd5737ce8c6ed7fb8e9942881e6731f9247dd";
81
- export declare const DEFAULT_SLIPPAGE_BPS = 100;
82
- /** ONE's app fee, pinned in client code (null = none, so any non-1Click fee row fails). Same as core.ts. */
83
- export declare const ONE_APP_FEE: {
84
- recipient: string;
85
- bps: number;
86
- } | null;
87
- /** Cap on summed 1Click protocol rows — measured 0/1/20 bps over 74 keyless routes (max 20), 25 = the documented no-key 0.25%. Same as core.ts. */
88
- export declare const PROTOCOL_FEE_CAP_BPS = 25;
89
- /** 1Click's own status URL for a deposit address — a fixed host, the address in URLSearchParams. */
90
- export declare function oneClickStatusUrl(depositAddress: string): string;
91
- export declare function depositAddressFits(addr: unknown): addr is string;
92
- export declare const HL_ADDRESS: RegExp;
93
- export interface MyQuoteValues {
94
- depositAddress: string;
95
- recipient: string;
96
- refundTo: string;
97
- originAsset: string;
98
- destinationAsset: string;
99
- exact: 'in' | 'out';
100
- amountBase: string;
101
- maxAmountInBase?: string;
102
- slippageBps?: number;
103
- appFeeCapBps?: number;
104
- appFeeRecipient?: string;
105
- protocolFeeCapBps?: number;
106
- }
107
- export type CheckField = 'stored' | 'depositAddress' | 'recipient' | 'refundTo' | 'originAsset' | 'destinationAsset' | 'depositType' | 'depositMode' | 'memo' | 'swapType' | 'amount' | 'amountIn' | 'refundType' | 'recipientType' | 'slippageTolerance' | 'appFees';
108
- export type CheckResult = {
109
- ok: true;
110
- } | {
111
- ok: false;
112
- error: 'quote_mismatch';
113
- field: CheckField;
114
- };
115
- type Obj = Record<string, unknown>;
116
- export declare function sameAddress(a: unknown, b: unknown): boolean;
117
- export declare function checkQuote(stored: unknown, mine: MyQuoteValues): CheckResult;
118
- /** What 1Click itself recorded for a deposit address — read straight out of its status body. */
119
- export interface StoredRecord {
120
- recipient?: string;
121
- refundTo?: string;
122
- originAsset?: string;
123
- destinationAsset?: string;
124
- amountInBase?: string;
125
- amountOutBase?: string;
126
- minAmountOutBase?: string;
127
- /** quoteRequest.swapType and quoteRequest.amount — what the status door re-checks (R16). */
128
- swapType?: string;
129
- amountBase?: string;
130
- refundAfter?: string;
131
- addressExpires?: string;
132
- quotedAt?: string;
133
- status?: string;
134
- }
135
- export declare function storedRecord(body: unknown): StoredRecord;
136
- /** Never print a send line inside the last five minutes before refunds begin. */
137
- export declare const SEND_MARGIN_MS: number;
138
- /**
139
- * Is there still time to send? `quotedAt` (1Click's clock) corrects this machine's skew:
140
- * skew = localNowAtQuote − quotedAt; 1Click's now ≈ localNow − skew.
141
- */
142
- export declare function stillSendable(refundAfter: string | undefined, now: Date, skewMs?: number): boolean;
143
- export declare function sendUri(asset: SwapRow, to: string, amountBase: bigint): string | undefined;
144
- /**
145
- * The page origin a link points at. The server's own link is only trusted for its ORIGIN, and
146
- * only when that origin is https://one.ie or localhost — a gateway call can come back as
147
- * https://api.one.ie/swap, which is no page. The query is always built here, never copied.
148
- */
149
- export declare function pageOrigin(serverLink: unknown): string;
150
- export declare function swapLink(origin: string, q: {
151
- from: string;
152
- to: string;
153
- amount: string;
154
- exact?: 'in' | 'out';
155
- }): string;
156
- export declare function depositLink(origin: string, depositAddress: string): string;
157
- /** The quote, one fact per line. `network: mainnet` is always the first line. */
158
- export declare function quoteLines(r: Obj): string[];
159
- export declare function statusLines(r: Obj): string[];
160
- /** Perps and spot, side by side — never summed (unified accounts show everything in spot). */
161
- export declare function hlLines(h: Obj): string[];
162
- export declare function assetLines(assets: readonly Obj[]): string[];
163
- export {};
@@ -1,405 +0,0 @@
1
- /**
2
- * swap-core — the pure half of `one swap` (text/swap-plan.md § CLI).
3
- *
4
- * The CLI cannot import one.ie/web code and must not import a new @oneie/sdk export
5
- * (R2: packages/cli/node_modules resolves another tree's SDK, so a new subpath would pass
6
- * hollow). So the four things the client check needs are ported here, verbatim in behaviour,
7
- * and tests/swap-parity.test.ts runs them against the web originals so the copy cannot drift:
8
- *
9
- * SWAP_TABLE + resolveAlias ← one.ie/web/src/lib/swap/assets.ts (SWAP_ASSETS, resolveAsset)
10
- * parseUnits + formatUnits ← one.ie/web/src/lib/units.ts
11
- * checkQuote ← one.ie/web/src/lib/swap/core.ts (R16, incl. 3fef1b14c fields)
12
- * sendUri ← one.ie/web/src/lib/swap/core.ts
13
- *
14
- * Nothing here touches the network, and nothing here ever signs. No Number cast touches an amount.
15
- */
16
- export const HL_USDC_ASSET_ID = '1cs_v1:hypercore:hip1:0x6d1e7cde53ba9467b783cb7c530ce054';
17
- /** Copied from one.ie/web/src/lib/swap/assets.ts — tests/swap-parity.test.ts pins it row by row. */
18
- export const SWAP_TABLE = [
19
- { alias: 'BTC', chain: 'bitcoin', symbol: 'BTC', assetId: 'nep141:btc.omft.near', decimals: 8, contract: null, signer: 'external', origin: true, destination: true },
20
- { alias: 'ETH@ethereum', chain: 'ethereum', symbol: 'ETH', assetId: 'nep141:eth.omft.near', decimals: 18, contract: null, signer: 'browser', origin: true, destination: true },
21
- { alias: 'ETH@base', chain: 'base', symbol: 'ETH', assetId: 'nep141:base.omft.near', decimals: 18, contract: null, signer: 'browser', origin: true, destination: true },
22
- { alias: 'ETH@arbitrum', chain: 'arbitrum', symbol: 'ETH', assetId: 'nep141:arb.omft.near', decimals: 18, contract: null, signer: 'external', origin: true, destination: true },
23
- { alias: 'USDC@ethereum', chain: 'ethereum', symbol: 'USDC', assetId: 'nep141:eth-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.omft.near', decimals: 6, contract: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', signer: 'browser', origin: true, destination: true },
24
- { alias: 'USDC@base', chain: 'base', symbol: 'USDC', assetId: 'nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near', decimals: 6, contract: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', signer: 'browser', origin: true, destination: true },
25
- { alias: 'USDC@arbitrum', chain: 'arbitrum', symbol: 'USDC', assetId: 'nep141:arb-0xaf88d065e77c8cc2239327c5edb3a432268e5831.omft.near', decimals: 6, contract: '0xaf88d065e77c8cc2239327c5edb3a432268e5831', signer: 'external', origin: true, destination: true },
26
- { alias: 'USDT@ethereum', chain: 'ethereum', symbol: 'USDT', assetId: 'nep141:eth-0xdac17f958d2ee523a2206206994597c13d831ec7.omft.near', decimals: 6, contract: '0xdac17f958d2ee523a2206206994597c13d831ec7', signer: 'external', origin: true, destination: true },
27
- { alias: 'USDT0@arbitrum', chain: 'arbitrum', symbol: 'USDT0', assetId: 'nep141:arb-0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9.omft.near', decimals: 6, contract: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', signer: 'external', origin: true, destination: true },
28
- { alias: 'SOL', chain: 'solana', symbol: 'SOL', assetId: 'nep141:sol.omft.near', decimals: 9, contract: null, signer: 'external', origin: true, destination: true },
29
- { alias: 'USDC@solana', chain: 'solana', symbol: 'USDC', assetId: 'nep141:sol-5ce3bf3a31af18be40ba30f721101b4341690186.omft.near', decimals: 6, contract: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', signer: 'external', origin: true, destination: true },
30
- { alias: 'SUI', chain: 'sui', symbol: 'SUI', assetId: 'nep141:sui.omft.near', decimals: 9, contract: null, signer: 'browser', origin: true, destination: true },
31
- { alias: 'USDC@sui', chain: 'sui', symbol: 'USDC', assetId: 'nep141:sui-c1b81ecaf27933252d31a963bc5e9458f13c18ce.omft.near', decimals: 6, contract: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC', signer: 'browser', origin: true, destination: true },
32
- { alias: 'USDC@hyperliquid', chain: 'hyperliquid', symbol: 'USDC', assetId: HL_USDC_ASSET_ID, decimals: 8, contract: '0x6d1e7cde53ba9467b783cb7c530ce054', signer: 'none', origin: false, destination: true },
33
- ];
34
- const CHAIN_SYNONYMS = {
35
- ethereum: 'ethereum', eth: 'ethereum', 'ethereum-mainnet': 'ethereum',
36
- base: 'base',
37
- arbitrum: 'arbitrum', arb: 'arbitrum',
38
- solana: 'solana', sol: 'solana',
39
- sui: 'sui',
40
- bitcoin: 'bitcoin', btc: 'bitcoin',
41
- hyperliquid: 'hyperliquid', hl: 'hyperliquid', hypercore: 'hyperliquid',
42
- };
43
- const DEST_DEFAULT = { ETH: 'ETH@ethereum', USDC: 'USDC@base', USDT: 'USDT@ethereum' };
44
- const byAlias = new Map(SWAP_TABLE.map((a) => [a.alias.toLowerCase(), a]));
45
- /** Same rules as the web resolveAsset — a parity test compares every alias both ways. */
46
- export function resolveAlias(input, side) {
47
- const raw = typeof input === 'string' ? input.trim() : '';
48
- if (!raw)
49
- return { ok: false, error: 'unknown_asset' };
50
- const lower = raw.toLowerCase();
51
- let asset;
52
- if (lower === 'hl' || lower === 'hyperliquid' || lower === 'hypercore') {
53
- asset = byAlias.get('usdc@hyperliquid');
54
- }
55
- else if (lower.includes('@')) {
56
- const [sym, ch] = lower.split('@', 2);
57
- const chain = CHAIN_SYNONYMS[ch];
58
- if (!chain)
59
- return { ok: false, error: 'unknown_asset' };
60
- asset = SWAP_TABLE.find((a) => a.symbol.toLowerCase() === sym && a.chain === chain);
61
- }
62
- else {
63
- const rows = SWAP_TABLE.filter((a) => a.symbol.toLowerCase() === lower);
64
- if (rows.length === 1)
65
- asset = rows[0];
66
- else if (rows.length > 1) {
67
- if (side === 'to')
68
- asset = byAlias.get((DEST_DEFAULT[raw.toUpperCase()] ?? '').toLowerCase());
69
- if (!asset)
70
- return { ok: false, error: 'ambiguous_asset', options: rows.map((r) => r.alias) };
71
- }
72
- }
73
- if (!asset)
74
- return { ok: false, error: 'unknown_asset' };
75
- if (side === 'to' && !asset.destination)
76
- return { ok: false, error: 'not_a_destination', asset };
77
- return { ok: true, asset };
78
- }
79
- export function rowById(assetId) {
80
- return SWAP_TABLE.find((a) => a.assetId === assetId);
81
- }
82
- // ─── units (verbatim from one.ie/web/src/lib/units.ts) ─────────────────────────
83
- export function parseUnits(input, decimals) {
84
- const s = input.trim();
85
- if (s !== input || !/^(\d+\.?\d*|\.\d+)$/.test(s))
86
- return null;
87
- const [whole, frac = ''] = s.split('.');
88
- if (frac.length > decimals)
89
- return null;
90
- return BigInt(whole || '0') * 10n ** BigInt(decimals) + BigInt((frac + '0'.repeat(decimals)).slice(0, decimals) || '0');
91
- }
92
- export function formatUnits(value, decimals) {
93
- const neg = value < 0n;
94
- const v = neg ? -value : value;
95
- const base = 10n ** BigInt(decimals);
96
- const whole = v / base;
97
- const frac = (v % base).toString().padStart(decimals, '0').replace(/0+$/, '');
98
- return `${neg ? '-' : ''}${whole}${frac ? `.${frac}` : ''}`;
99
- }
100
- // ─── grammar ──────────────────────────────────────────────────────────────────
101
- /** The one rule (plan § CLI): the amount is the token that looks like a plain decimal. */
102
- export const AMOUNT_TOKEN = /^\d+(\.\d+)?$/;
103
- const USAGE = 'one swap <amount> <from> [to] <to> — e.g. one swap 0.01 BTC hl · one swap 10 USDC@base to hl';
104
- /**
105
- * `one swap 0.01 BTC hl` = `one swap 0.01 BTC to hl` = `one swap BTC hl 0.01`.
106
- * Exactly one plain-decimal amount (nonzero), a literal `to` dropped, two asset words left
107
- * in order (from, to). `1e3`, `0x10`, `-1`, `.5` and `0` are refused here, before any call.
108
- */
109
- export function parseSwapWords(words) {
110
- const kept = words.filter((w) => w.toLowerCase() !== 'to');
111
- const amounts = kept.filter((w) => AMOUNT_TOKEN.test(w));
112
- const rest = kept.filter((w) => !AMOUNT_TOKEN.test(w));
113
- if (amounts.length === 0) {
114
- return { ok: false, error: 'bad_amount', next: `No amount found — write it as a plain decimal like 10 or 0.01 (never 1e3, -1 or .5). ${USAGE}` };
115
- }
116
- if (amounts.length > 1)
117
- return { ok: false, error: 'usage', next: `Two amounts given (${amounts.join(', ')}); give one. ${USAGE}` };
118
- const amount = amounts[0];
119
- if (!/[1-9]/.test(amount))
120
- return { ok: false, error: 'bad_amount', next: 'The amount must be more than zero.' };
121
- if (rest.length !== 2)
122
- return { ok: false, error: 'usage', next: `Name exactly two assets, what you pay and what you get. ${USAGE}` };
123
- return { ok: true, amount, from: rest[0], to: rest[1] };
124
- }
125
- /** --slippage <bps>: an integer 1..500, read by regex and parseInt, never a Number cast. */
126
- export function parseSlippage(s) {
127
- if (s === undefined)
128
- return { ok: true };
129
- if (!/^\d{1,3}$/.test(s))
130
- return { ok: false };
131
- const bps = Number.parseInt(s, 10);
132
- return bps >= 1 && bps <= 500 ? { ok: true, bps } : { ok: false };
133
- }
134
- /** --mine a,b,c → the caller's own addresses, as typed. */
135
- export function parseMine(s) {
136
- if (!s)
137
- return [];
138
- return s.split(/[\s,]+/).map((x) => x.trim()).filter(Boolean);
139
- }
140
- // ─── the client check (R16) — verbatim from one.ie/web/src/lib/swap/core.ts ────
141
- export const ONECLICK = 'https://1click.chaindefuser.com';
142
- export const ONECLICK_PROTOCOL_RECIPIENT = '5880ad2b362620fadf759cbceb1cd5737ce8c6ed7fb8e9942881e6731f9247dd';
143
- export const DEFAULT_SLIPPAGE_BPS = 100;
144
- /** ONE's app fee, pinned in client code (null = none, so any non-1Click fee row fails). Same as core.ts. */
145
- export const ONE_APP_FEE = null;
146
- /** Cap on summed 1Click protocol rows — measured 0/1/20 bps over 74 keyless routes (max 20), 25 = the documented no-key 0.25%. Same as core.ts. */
147
- export const PROTOCOL_FEE_CAP_BPS = 25;
148
- /** 1Click's own status URL for a deposit address — a fixed host, the address in URLSearchParams. */
149
- export function oneClickStatusUrl(depositAddress) {
150
- return `${ONECLICK}/v0/status?${new URLSearchParams({ depositAddress }).toString()}`;
151
- }
152
- const DEPOSIT_RE = /^[A-Za-z0-9:._-]{20,128}$/;
153
- export function depositAddressFits(addr) {
154
- return typeof addr === 'string' && DEPOSIT_RE.test(addr);
155
- }
156
- export const HL_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
157
- const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
158
- function bigOf(s) {
159
- if (typeof s === 'number' && Number.isInteger(s) && s >= 0)
160
- return BigInt(s);
161
- if (typeof s !== 'string' || !/^\d+$/.test(s))
162
- return null;
163
- return BigInt(s);
164
- }
165
- export function sameAddress(a, b) {
166
- if (typeof a !== 'string' || typeof b !== 'string' || !a || !b)
167
- return false;
168
- if (a.startsWith('0x') && b.startsWith('0x'))
169
- return a.toLowerCase() === b.toLowerCase();
170
- return a === b;
171
- }
172
- export function checkQuote(stored, mine) {
173
- const fail = (field) => ({ ok: false, error: 'quote_mismatch', field });
174
- if (!isObj(stored))
175
- return fail('stored');
176
- const qr = isObj(stored['quoteResponse']) ? stored['quoteResponse'] : stored;
177
- const req = isObj(qr['quoteRequest']) ? qr['quoteRequest'] : null;
178
- const q = isObj(qr['quote']) ? qr['quote'] : null;
179
- if (!req || !q)
180
- return fail('stored');
181
- if (!sameAddress(q['depositAddress'], mine.depositAddress))
182
- return fail('depositAddress');
183
- if (!sameAddress(req['recipient'], mine.recipient))
184
- return fail('recipient');
185
- if (!sameAddress(req['refundTo'], mine.refundTo))
186
- return fail('refundTo');
187
- if (req['originAsset'] !== mine.originAsset)
188
- return fail('originAsset');
189
- if (req['destinationAsset'] !== mine.destinationAsset)
190
- return fail('destinationAsset');
191
- if (req['depositType'] !== 'ORIGIN_CHAIN')
192
- return fail('depositType');
193
- if (req['refundType'] !== 'ORIGIN_CHAIN')
194
- return fail('refundType');
195
- if (req['recipientType'] !== 'DESTINATION_CHAIN')
196
- return fail('recipientType');
197
- if (req['slippageTolerance'] !== (mine.slippageBps ?? DEFAULT_SLIPPAGE_BPS))
198
- return fail('slippageTolerance');
199
- const fees = req['appFees'] === undefined || req['appFees'] === null ? [] : req['appFees'];
200
- if (!Array.isArray(fees))
201
- return fail('appFees');
202
- const payee = mine.appFeeRecipient ?? ONE_APP_FEE?.recipient;
203
- let other = 0;
204
- let protocol = 0;
205
- for (const f of fees) {
206
- if (!isObj(f) || typeof f['fee'] !== 'number' || !Number.isFinite(f['fee']) || f['fee'] < 0)
207
- return fail('appFees');
208
- if (f['recipient'] === ONECLICK_PROTOCOL_RECIPIENT) {
209
- protocol += f['fee'];
210
- continue;
211
- }
212
- if (payee !== undefined && f['recipient'] !== payee)
213
- return fail('appFees');
214
- other += f['fee'];
215
- }
216
- if (protocol > (mine.protocolFeeCapBps ?? PROTOCOL_FEE_CAP_BPS))
217
- return fail('appFees');
218
- if (other > (mine.appFeeCapBps ?? ONE_APP_FEE?.bps ?? 0))
219
- return fail('appFees');
220
- if (req['depositMode'] !== undefined && req['depositMode'] !== 'SIMPLE')
221
- return fail('depositMode');
222
- if (q['depositMemo'] !== undefined && q['depositMemo'] !== null && q['depositMemo'] !== '')
223
- return fail('memo');
224
- const wantType = mine.exact === 'out' ? 'EXACT_OUTPUT' : 'EXACT_INPUT';
225
- if (req['swapType'] !== wantType)
226
- return fail('swapType');
227
- if (String(req['amount'] ?? '') !== mine.amountBase)
228
- return fail('amount');
229
- if (mine.exact === 'in') {
230
- if (String(q['amountIn'] ?? '') !== mine.amountBase)
231
- return fail('amountIn');
232
- }
233
- else {
234
- const cap = bigOf(mine.maxAmountInBase);
235
- const got = bigOf(q['amountIn']);
236
- if (cap === null || got === null || got > cap)
237
- return fail('amountIn');
238
- }
239
- return { ok: true };
240
- }
241
- export function storedRecord(body) {
242
- if (!isObj(body))
243
- return {};
244
- const qr = isObj(body['quoteResponse']) ? body['quoteResponse'] : body;
245
- const req = isObj(qr['quoteRequest']) ? qr['quoteRequest'] : {};
246
- const q = isObj(qr['quote']) ? qr['quote'] : {};
247
- const s = (v) => (typeof v === 'string' && v ? v : undefined);
248
- const amountIn = bigOf(q['amountIn']);
249
- const amountOut = bigOf(q['amountOut']);
250
- const minOut = bigOf(q['minAmountOut']);
251
- return {
252
- recipient: s(req['recipient']),
253
- refundTo: s(req['refundTo']),
254
- originAsset: s(req['originAsset']),
255
- destinationAsset: s(req['destinationAsset']),
256
- amountInBase: amountIn === null ? undefined : amountIn.toString(),
257
- amountOutBase: amountOut === null ? undefined : amountOut.toString(),
258
- minAmountOutBase: minOut === null ? undefined : minOut.toString(),
259
- swapType: s(req['swapType']),
260
- amountBase: bigOf(req['amount'])?.toString(),
261
- // refundAfter is quoteRequest.deadline (1Click starts refunding), NOT quote.deadline (~72 h).
262
- refundAfter: s(req['deadline']),
263
- addressExpires: s(q['timeWhenInactive']) ?? s(q['deadline']),
264
- quotedAt: s(qr['timestamp']),
265
- status: s(body['status']),
266
- };
267
- }
268
- /** Never print a send line inside the last five minutes before refunds begin. */
269
- export const SEND_MARGIN_MS = 5 * 60_000;
270
- /**
271
- * Is there still time to send? `quotedAt` (1Click's clock) corrects this machine's skew:
272
- * skew = localNowAtQuote − quotedAt; 1Click's now ≈ localNow − skew.
273
- */
274
- export function stillSendable(refundAfter, now, skewMs = 0) {
275
- if (!refundAfter)
276
- return false;
277
- const t = Date.parse(refundAfter);
278
- if (Number.isNaN(t))
279
- return false;
280
- return now.getTime() - skewMs < t - SEND_MARGIN_MS;
281
- }
282
- // ─── send instruction (verbatim from core.sendUri) ─────────────────────────────
283
- const EVM_CHAIN_ID = { ethereum: 1, base: 8453, arbitrum: 42161 };
284
- export function sendUri(asset, to, amountBase) {
285
- const dec = formatUnits(amountBase, asset.decimals);
286
- if (asset.chain === 'bitcoin')
287
- return `bitcoin:${to}?amount=${dec}`;
288
- if (asset.chain === 'solana')
289
- return `solana:${to}?amount=${dec}${asset.contract ? `&spl-token=${asset.contract}` : ''}`;
290
- const id = EVM_CHAIN_ID[asset.chain];
291
- if (!id)
292
- return undefined;
293
- if (!asset.contract)
294
- return `ethereum:${to}@${id}?value=${amountBase.toString()}`;
295
- return `ethereum:${asset.contract}@${id}/transfer?address=${to}&uint256=${amountBase.toString()}`;
296
- }
297
- // ─── links ─────────────────────────────────────────────────────────────────────
298
- const LOCAL_ORIGIN = /^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/;
299
- /**
300
- * The page origin a link points at. The server's own link is only trusted for its ORIGIN, and
301
- * only when that origin is https://one.ie or localhost — a gateway call can come back as
302
- * https://api.one.ie/swap, which is no page. The query is always built here, never copied.
303
- */
304
- export function pageOrigin(serverLink) {
305
- if (typeof serverLink !== 'string')
306
- return 'https://one.ie';
307
- try {
308
- const o = new URL(serverLink).origin;
309
- return o === 'https://one.ie' || LOCAL_ORIGIN.test(o) ? o : 'https://one.ie';
310
- }
311
- catch {
312
- return 'https://one.ie';
313
- }
314
- }
315
- export function swapLink(origin, q) {
316
- const p = new URLSearchParams({ from: q.from, to: q.to, amount: q.amount });
317
- if (q.exact === 'out')
318
- p.set('exact', 'out');
319
- return `${origin}/swap?${p.toString()}`;
320
- }
321
- export function depositLink(origin, depositAddress) {
322
- return `${origin}/swap?${new URLSearchParams({ deposit: depositAddress }).toString()}`;
323
- }
324
- // ─── human lines ───────────────────────────────────────────────────────────────
325
- const pad = (k) => k.padEnd(10);
326
- /** The quote, one fact per line. `network: mainnet` is always the first line. */
327
- export function quoteLines(r) {
328
- const from = isObj(r['from']) ? r['from'] : {};
329
- const to = isObj(r['to']) ? r['to'] : {};
330
- const lines = [];
331
- lines.push(`${pad('network')}${r['dry'] === false ? 'mainnet — real funds' : 'mainnet (1Click has no testnet; this is a price only)'}`);
332
- if (r['amountIn'] !== undefined)
333
- lines.push(`${pad('you send')}${r['amountIn']} ${from['alias'] ?? ''}${from['chain'] ? ` on ${from['chain']}` : ''}${r['amountInUsd'] ? ` (~$${r['amountInUsd']})` : ''}`);
334
- if (r['minAmountIn'] !== undefined && r['minAmountIn'] !== r['amountIn'])
335
- lines.push(`${pad('min send')}${r['minAmountIn']} ${from['alias'] ?? ''}`);
336
- if (r['amountOut'] !== undefined)
337
- lines.push(`${pad('you get')}${r['amountOut']} ${to['alias'] ?? ''}${r['amountOutUsd'] ? ` (~$${r['amountOutUsd']})` : ''}`);
338
- if (r['minAmountOut'] !== undefined)
339
- lines.push(`${pad('min recv')}${r['minAmountOut']} ${to['alias'] ?? ''} (after slippage)`);
340
- const fees = Array.isArray(r['fees']) ? r['fees'] : [];
341
- for (const f of fees) {
342
- const amt = f.amount ? `${f.amount} ${f.asset ?? ''}`.trim() : '';
343
- const bps = typeof f.bps === 'number' ? `${f.bps} bps` : '';
344
- lines.push(`${pad('fee')}${[f.kind, [amt, bps].filter(Boolean).join(' · '), f.note ? `— ${f.note}` : ''].filter(Boolean).join(' ')}`);
345
- }
346
- if (r['costUsd'] !== undefined)
347
- lines.push(`${pad('cost')}$${r['costUsd']} (value in − value out, read from the live quote)`);
348
- if (typeof r['timeEstimateSec'] === 'number')
349
- lines.push(`${pad('eta')}~${r['timeEstimateSec']} s after the deposit confirms`);
350
- const route = isObj(r['route']) ? r['route'] : {};
351
- if (route['credits'] === 'perps')
352
- lines.push(`${pad('lands in')}your Hyperliquid PERPS balance`);
353
- const warnings = Array.isArray(r['warnings']) ? r['warnings'] : [];
354
- for (const w of warnings)
355
- lines.push(`${pad('warning')}${w}`);
356
- return lines;
357
- }
358
- export function statusLines(r) {
359
- const lines = [`${pad('network')}mainnet`];
360
- if (r['status'] !== undefined)
361
- lines.push(`${pad('status')}${r['status']}${r['terminal'] ? ' (final)' : ''}`);
362
- if (r['explain'])
363
- lines.push(`${pad('means')}${r['explain']}`);
364
- if (r['from'] || r['to'])
365
- lines.push(`${pad('swap')}${r['from'] ?? '?'} → ${r['to'] ?? '?'}`);
366
- if (r['amountIn'] !== undefined)
367
- lines.push(`${pad('deposited')}${r['amountIn']}`);
368
- if (r['amountOut'] !== undefined)
369
- lines.push(`${pad('delivered')}${r['amountOut']}${r['amountOutUsd'] ? ` (~$${r['amountOutUsd']})` : ''}`);
370
- if (r['refundedAmount'] !== undefined && r['refundedAmount'] !== '0')
371
- lines.push(`${pad('refunded')}${r['refundedAmount']}${r['refundReason'] ? ` — ${r['refundReason']}` : ''}`);
372
- for (const key of ['originTxs', 'destinationTxs']) {
373
- const txs = Array.isArray(r[key]) ? r[key] : [];
374
- for (const t of txs)
375
- lines.push(`${pad(key === 'originTxs' ? 'deposit tx' : 'deliver tx')}${t.explorerUrl ?? t.hash ?? ''}`);
376
- }
377
- if (r['submitted'] === true)
378
- lines.push(`${pad('tx hash')}forwarded to 1Click to speed matching (not a verification)`);
379
- if (r['refundAfter'])
380
- lines.push(`${pad('refunds')}begin ${r['refundAfter']} if not filled`);
381
- if (isObj(r['hyperliquid']))
382
- lines.push(...hlLines(r['hyperliquid']));
383
- return lines;
384
- }
385
- /** Perps and spot, side by side — never summed (unified accounts show everything in spot). */
386
- export function hlLines(h) {
387
- const perps = isObj(h['perps']) ? h['perps'] : {};
388
- const spot = Array.isArray(h['spot']) ? h['spot'] : [];
389
- const lines = [
390
- `${pad('hl')}${h['address'] ?? ''} on ${h['network'] ?? 'mainnet'}`,
391
- `${pad('perps')}account value $${perps['accountValue'] ?? '0'} · withdrawable $${perps['withdrawable'] ?? '0'}`,
392
- ];
393
- if (!spot.length)
394
- lines.push(`${pad('spot')}(empty)`);
395
- for (const s of spot)
396
- lines.push(`${pad('spot')}${s.total ?? '0'} ${s.coin ?? ''}${s.hold && s.hold !== '0' && s.hold !== '0.0' ? ` (${s.hold} on hold)` : ''}`);
397
- if (h['firstDeposit'] === true)
398
- lines.push(`${pad('note')}empty account — Hyperliquid MAY take a one-time ~1 USDC activation (unverified)`);
399
- lines.push(`${pad('note')}perps and spot are separate balances; they are not summed`);
400
- return lines;
401
- }
402
- export function assetLines(assets) {
403
- const head = `${'alias'.padEnd(18)}${'chain'.padEnd(13)}${'decimals'.padEnd(10)}${'signer'.padEnd(10)}from to`;
404
- return [head, ...assets.map((a) => `${String(a['alias'] ?? '').padEnd(18)}${String(a['chain'] ?? '').padEnd(13)}${String(a['decimals'] ?? '').padEnd(10)}${String(a['signer'] ?? '').padEnd(10)}${a['origin'] ? 'yes ' : 'dry '} ${a['destination'] ? 'yes' : 'no'}`)];
405
- }