oneie 5.7.4 → 5.7.6
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.
- package/README.md +15 -0
- package/dist/package.json +5 -2
- package/dist/src/balances.d.ts +89 -0
- package/dist/src/balances.js +202 -0
- package/dist/src/hl-run.d.ts +119 -0
- package/dist/src/hl-run.js +480 -0
- package/dist/src/hl.d.ts +17 -0
- package/dist/src/hl.js +148 -0
- package/dist/src/index.js +4 -0
- package/dist/src/key-sweep.d.ts +19 -3
- package/dist/src/key-sweep.js +63 -20
- package/dist/src/lib/hl-core/actions.d.ts +99 -0
- package/dist/src/lib/hl-core/actions.js +69 -0
- package/dist/src/lib/hl-core/eip712.d.ts +33 -0
- package/dist/src/lib/hl-core/eip712.js +107 -0
- package/dist/src/lib/hl-core/errors.d.ts +10 -0
- package/dist/src/lib/hl-core/errors.js +15 -0
- package/dist/src/lib/hl-core/exchange.d.ts +24 -0
- package/dist/src/lib/hl-core/exchange.js +47 -0
- package/dist/src/lib/hl-core/index.d.ts +13 -0
- package/dist/src/lib/hl-core/index.js +14 -0
- package/dist/src/lib/hl-core/meta.d.ts +57 -0
- package/dist/src/lib/hl-core/meta.js +110 -0
- package/dist/src/lib/hl-core/msgpack.d.ts +18 -0
- package/dist/src/lib/hl-core/msgpack.js +136 -0
- package/dist/src/lib/hl-core/net.d.ts +2 -0
- package/dist/src/lib/hl-core/net.js +7 -0
- package/dist/src/lib/hl-core/signing.d.ts +103 -0
- package/dist/src/lib/hl-core/signing.js +295 -0
- package/dist/src/lib/hl-core/wire.d.ts +34 -0
- package/dist/src/lib/hl-core/wire.js +81 -0
- package/dist/src/lib/journey-words.d.ts +54 -3
- package/dist/src/lib/journey-words.js +159 -20
- package/dist/src/lib/journey.js +1 -1
- package/dist/src/lib/key-source.d.ts +9 -0
- package/dist/src/lib/key-source.js +33 -0
- package/dist/src/lib/network.d.ts +15 -0
- package/dist/src/lib/network.js +41 -0
- package/dist/src/lib/qr.d.ts +21 -0
- package/dist/src/lib/qr.js +402 -0
- package/dist/src/lib/sale-card.d.ts +117 -0
- package/dist/src/lib/sale-card.js +261 -0
- package/dist/src/lib/sui-grpc-send.d.ts +50 -0
- package/dist/src/lib/sui-grpc-send.js +89 -0
- package/dist/src/lib/swap-core.d.ts +163 -0
- package/dist/src/lib/swap-core.js +405 -0
- package/dist/src/lib/wallet-money.d.ts +222 -0
- package/dist/src/lib/wallet-money.js +578 -0
- package/dist/src/lib/wallet-request.d.ts +50 -0
- package/dist/src/lib/wallet-request.js +86 -0
- package/dist/src/onboard.js +4 -3
- package/dist/src/shop.js +38 -1
- package/dist/src/staff.js +10 -0
- package/dist/src/start.js +14 -6
- package/dist/src/swap.d.ts +93 -0
- package/dist/src/swap.js +622 -0
- package/dist/src/wallet-money.d.ts +152 -0
- package/dist/src/wallet-money.js +564 -0
- package/dist/src/wallet.js +169 -24
- package/package.json +5 -2
|
@@ -0,0 +1,405 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wallet-money.ts — the pure half of `one wallet balances | receive | send | request`:
|
|
3
|
+
* the chain table, the words a person types, the reads, which chain a bare `USDC`
|
|
4
|
+
* means, the plan a send would sign, and the client check (R16) run before it does.
|
|
5
|
+
*
|
|
6
|
+
* Every chain read takes `Fetch` as an argument (tests hand in a fake; the command
|
|
7
|
+
* hands in a fetch with a deadline). A read that fails is null, never 0.
|
|
8
|
+
* Nothing here opens a vault or holds a key.
|
|
9
|
+
*/
|
|
10
|
+
import { type BalanceRow, type Fetch, type HlRead } from '../balances.js';
|
|
11
|
+
export type Net = 'mainnet' | 'testnet';
|
|
12
|
+
export type EvmChain = 'ethereum' | 'base' | 'arbitrum';
|
|
13
|
+
export type SendChain = EvmChain | 'sui';
|
|
14
|
+
export type SendAsset = 'ETH' | 'USDC' | 'SUI';
|
|
15
|
+
export type Obj = Record<string, unknown>;
|
|
16
|
+
export interface EvmNet {
|
|
17
|
+
chainId: number;
|
|
18
|
+
rpc: string;
|
|
19
|
+
usdc: string;
|
|
20
|
+
explorer: string;
|
|
21
|
+
label: string;
|
|
22
|
+
}
|
|
23
|
+
/** The three EVM chains on each network. Testnet USDC contracts read back `symbol() = USDC` (2026-11-09). */
|
|
24
|
+
export declare const EVM: Record<EvmChain, Record<Net, EvmNet>>;
|
|
25
|
+
export declare const EVM_CHAIN_NAMES: readonly EvmChain[];
|
|
26
|
+
/** Sui's public JSON-RPC answers "deprecated" on mainnet and testnet (measured 2026-11-09); GraphQL is the public read. */
|
|
27
|
+
export declare const SUI: Record<Net, {
|
|
28
|
+
graphql: string;
|
|
29
|
+
usdc: string;
|
|
30
|
+
explorer: string;
|
|
31
|
+
label: string;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const SUI_NATIVE = "0x2::sui::SUI";
|
|
34
|
+
export declare const DECIMALS: Record<SendAsset, number>;
|
|
35
|
+
export declare function parseNet(v: unknown): Net | null;
|
|
36
|
+
/** "0.5" → base units; anything that is not a plain positive decimal within `decimals` places → null. */
|
|
37
|
+
export declare function parseAmount(input: string, decimals: number): bigint | null;
|
|
38
|
+
export type AssetWord = {
|
|
39
|
+
ok: true;
|
|
40
|
+
asset: SendAsset;
|
|
41
|
+
chain?: SendChain;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
error: string;
|
|
45
|
+
message: string;
|
|
46
|
+
};
|
|
47
|
+
/** `ETH` · `USDC@base` · `SUI` — the asset and, when named, the chain. */
|
|
48
|
+
export declare function parseAssetWord(word: string): AssetWord;
|
|
49
|
+
/** The chains a bare asset could mean, in a fixed order. */
|
|
50
|
+
export declare function candidateChains(asset: SendAsset): SendChain[];
|
|
51
|
+
export declare const familyOf: (chain: SendChain) => "evm" | "sui";
|
|
52
|
+
export declare const chainLabel: (chain: SendChain, net: Net) => string;
|
|
53
|
+
export declare function addressShape(addr: string): 'evm' | 'sui' | null;
|
|
54
|
+
export declare function evmRpc(f: Fetch, rpc: string, method: string, params: unknown[]): Promise<string>;
|
|
55
|
+
export declare function readEvmAsset(f: Fetch, chain: EvmChain, net: Net, asset: 'ETH' | 'USDC', address: string): Promise<bigint | null>;
|
|
56
|
+
/** A coin balance on Sui via GraphQL; an address that never held the coin answers a null balance — a real zero. */
|
|
57
|
+
export declare function readSuiCoin(f: Fetch, net: Net, address: string, coinType: string): Promise<bigint | null>;
|
|
58
|
+
export declare function readAsset(f: Fetch, asset: SendAsset, chain: SendChain, net: Net, address: string): Promise<bigint | null>;
|
|
59
|
+
/** SOL in lamports from a public Solana node (testnet = devnet, where ONE's test money lives). */
|
|
60
|
+
export declare const SOL_RPC: Record<Net, string>;
|
|
61
|
+
export declare function readSol(f: Fetch, net: Net, address: string): Promise<bigint | null>;
|
|
62
|
+
/** BTC in satoshis from mempool.space: confirmed + unconfirmed, funded minus spent. */
|
|
63
|
+
export declare const BTC_API: Record<Net, string>;
|
|
64
|
+
export declare function readBtc(f: Fetch, net: Net, address: string): Promise<bigint | null>;
|
|
65
|
+
export interface Addresses {
|
|
66
|
+
evm?: string;
|
|
67
|
+
sui?: string;
|
|
68
|
+
solana?: string;
|
|
69
|
+
btc?: string;
|
|
70
|
+
}
|
|
71
|
+
export type MoneyRow = BalanceRow & {
|
|
72
|
+
source: 'wallet:get' | 'chain';
|
|
73
|
+
};
|
|
74
|
+
export interface MoneyBalances {
|
|
75
|
+
ok: true;
|
|
76
|
+
network: Net;
|
|
77
|
+
addresses: Addresses;
|
|
78
|
+
rows: MoneyRow[];
|
|
79
|
+
hyperliquid?: HlRead;
|
|
80
|
+
note: string;
|
|
81
|
+
}
|
|
82
|
+
/** What a server-given address must look like before it is used, printed or pasted anywhere. */
|
|
83
|
+
export declare const ADDRESS_SHAPE: Record<'evm' | 'sui' | 'solana' | 'btc', RegExp>;
|
|
84
|
+
/** wallet:get's rows for one actor → the addresses it holds. A row whose address is not its chain's shape is dropped. */
|
|
85
|
+
export declare function addressesFor(walletGet: Obj, actor: string): Addresses;
|
|
86
|
+
/**
|
|
87
|
+
* Every balance of one actor on ONE network. A wallet:get row is used only when it says
|
|
88
|
+
* it was read on the network asked (a server that ignores `net` answers the deploy's —
|
|
89
|
+
* production's is testnet — and such a row is dropped, never shown under the wrong label).
|
|
90
|
+
* What wallet:get does not read — USDC everywhere, ETH on Base and Arbitrum, USDT on
|
|
91
|
+
* mainnet, and SOL/BTC when the server gave no row — is read from the chains here.
|
|
92
|
+
*/
|
|
93
|
+
export declare function moneyBalances(args: {
|
|
94
|
+
walletGet: Obj | null;
|
|
95
|
+
actor: string;
|
|
96
|
+
addresses: Addresses;
|
|
97
|
+
net: Net;
|
|
98
|
+
}, f: Fetch, hlRead?: (address: string) => Promise<HlRead>): Promise<MoneyBalances>;
|
|
99
|
+
export declare function moneyLines(r: MoneyBalances): string[];
|
|
100
|
+
export type ReceiveChain = EvmChain | 'sui' | 'solana' | 'bitcoin';
|
|
101
|
+
export type ReceivePlan = {
|
|
102
|
+
ok: true;
|
|
103
|
+
chain: ReceiveChain;
|
|
104
|
+
network: Net;
|
|
105
|
+
address: string;
|
|
106
|
+
uri: string;
|
|
107
|
+
label: string;
|
|
108
|
+
accepts: string;
|
|
109
|
+
warning: string;
|
|
110
|
+
} | {
|
|
111
|
+
ok: false;
|
|
112
|
+
error: string;
|
|
113
|
+
message: string;
|
|
114
|
+
options?: string[];
|
|
115
|
+
};
|
|
116
|
+
/** Which chains these addresses can receive on — the list a refusal names. */
|
|
117
|
+
export declare function receivableChains(a: Addresses): ReceiveChain[];
|
|
118
|
+
/** One chain, one address, one QR payload. No chain = refused: one 0x address is three chains. */
|
|
119
|
+
export declare function receivePlan(chainWord: string | undefined, a: Addresses, net: Net): ReceivePlan;
|
|
120
|
+
/** wallet:invoice takes cents: USD or USDC, at most 2 decimals. Anything else is refused by name. */
|
|
121
|
+
export declare function invoiceCents(amount: string, asset: string): {
|
|
122
|
+
ok: true;
|
|
123
|
+
cents: number;
|
|
124
|
+
} | {
|
|
125
|
+
ok: false;
|
|
126
|
+
error: string;
|
|
127
|
+
message: string;
|
|
128
|
+
};
|
|
129
|
+
export interface EvmTxFields {
|
|
130
|
+
chainId: number;
|
|
131
|
+
nonce: bigint;
|
|
132
|
+
maxPriorityFeePerGas: bigint;
|
|
133
|
+
maxFeePerGas: bigint;
|
|
134
|
+
gasLimit: bigint;
|
|
135
|
+
to: string;
|
|
136
|
+
value: bigint;
|
|
137
|
+
data: string;
|
|
138
|
+
}
|
|
139
|
+
export interface SendPlan {
|
|
140
|
+
network: Net;
|
|
141
|
+
chain: SendChain;
|
|
142
|
+
chainLabel: string;
|
|
143
|
+
asset: SendAsset;
|
|
144
|
+
amount: string;
|
|
145
|
+
amountUnits: bigint;
|
|
146
|
+
from: string;
|
|
147
|
+
to: string;
|
|
148
|
+
/** How `to` was found: typed (an address in argv), or resolved from a name. */
|
|
149
|
+
toSource: 'typed' | 'wallet:get' | 'identity:address';
|
|
150
|
+
/** Why this chain — named, or the only one holding it. */
|
|
151
|
+
choice: string;
|
|
152
|
+
balanceUnits: bigint;
|
|
153
|
+
/** EVM: the transaction exactly as it would be signed. */
|
|
154
|
+
tx?: EvmTxFields;
|
|
155
|
+
/** EVM: gasLimit × maxFeePerGas — the most the fee can be, in wei. */
|
|
156
|
+
feeMaxUnits?: bigint;
|
|
157
|
+
/** Sui: the coin type moved. */
|
|
158
|
+
coinType?: string;
|
|
159
|
+
explorer: string;
|
|
160
|
+
}
|
|
161
|
+
export interface PlanDeps {
|
|
162
|
+
fetch: Fetch;
|
|
163
|
+
/** The sender's registered addresses (wallet:get), read once. */
|
|
164
|
+
from: Addresses;
|
|
165
|
+
/** Resolves a name (slug or agent id) to an address of `family`; null = none. */
|
|
166
|
+
resolve: (name: string, family: 'evm' | 'sui') => Promise<{
|
|
167
|
+
address: string;
|
|
168
|
+
source: 'wallet:get' | 'identity:address';
|
|
169
|
+
} | null>;
|
|
170
|
+
}
|
|
171
|
+
export type PlanResult = {
|
|
172
|
+
ok: true;
|
|
173
|
+
plan: SendPlan;
|
|
174
|
+
} | {
|
|
175
|
+
ok: false;
|
|
176
|
+
error: string;
|
|
177
|
+
message: string;
|
|
178
|
+
options?: Obj[];
|
|
179
|
+
};
|
|
180
|
+
/** A bare asset → the one chain that holds it. Two → refused with the list; a failed read → refused (it might be a second). */
|
|
181
|
+
export declare function pickChain(asset: SendAsset, from: Addresses, net: Net, f: Fetch): Promise<{
|
|
182
|
+
ok: true;
|
|
183
|
+
chain: SendChain;
|
|
184
|
+
choice: string;
|
|
185
|
+
} | {
|
|
186
|
+
ok: false;
|
|
187
|
+
error: string;
|
|
188
|
+
message: string;
|
|
189
|
+
options: Obj[];
|
|
190
|
+
}>;
|
|
191
|
+
/** Everything a send would sign, read and checked — nothing signed, nothing sent. */
|
|
192
|
+
export declare function planSend(intent: {
|
|
193
|
+
amount: string;
|
|
194
|
+
asset: string;
|
|
195
|
+
to: string;
|
|
196
|
+
net: Net;
|
|
197
|
+
}, deps: PlanDeps): Promise<PlanResult>;
|
|
198
|
+
/** ERC-20 transfer(address,uint256) — the same bytes as @oneie/sdk/evm-tx encodeErc20Transfer, kept here so a dry run needs no SDK upgrade. */
|
|
199
|
+
export declare function erc20TransferData(to: string, amount: bigint): string;
|
|
200
|
+
/**
|
|
201
|
+
* R16 — before a key signs, rebuild what the transaction MUST be from the person's own inputs
|
|
202
|
+
* (argv, and the address they confirmed), never from a server answer or the plan's echo, and
|
|
203
|
+
* compare. Any difference refuses.
|
|
204
|
+
*/
|
|
205
|
+
export declare function clientCheck(plan: SendPlan, own: {
|
|
206
|
+
amount: string;
|
|
207
|
+
asset: SendAsset;
|
|
208
|
+
chain: SendChain;
|
|
209
|
+
to: string;
|
|
210
|
+
net: Net;
|
|
211
|
+
}): {
|
|
212
|
+
ok: true;
|
|
213
|
+
} | {
|
|
214
|
+
ok: false;
|
|
215
|
+
field: string;
|
|
216
|
+
};
|
|
217
|
+
/** What a person reads before anything is signed. */
|
|
218
|
+
export declare function planLines(p: SendPlan): string[];
|
|
219
|
+
/** A plan as JSON-safe values (bigints as decimal strings). */
|
|
220
|
+
export declare function planJson(p: SendPlan): Obj;
|
|
221
|
+
/** The `wallet send … --payment-tx` line that records a broadcast transfer in ONE's ledger. */
|
|
222
|
+
export declare function recordLine(p: SendPlan, hash: string, cli: string): string;
|