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,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sale, drawn for a terminal — `one shop card`. The same four offers, two rails and six channels the
|
|
3
|
+
* home band, the chat and the film draw, as text no wider than 70 characters.
|
|
4
|
+
*
|
|
5
|
+
* SOURCE: one.ie/web/src/lib/sale/showcase.ts. The CLI is published on its own and cannot import the web
|
|
6
|
+
* package at runtime, so the words are copied here. tests/sale-card.test.ts reads that file as text and
|
|
7
|
+
* goes red when a name, price, cadence, rail or channel label drifts — change both together.
|
|
8
|
+
*
|
|
9
|
+
* Every line is a picture: nothing here mints, fetches or charges. A monthly subscription is card only.
|
|
10
|
+
* Card money goes to the seller's Stripe; USDC to the seller's own wallet. ONE holds neither.
|
|
11
|
+
*/
|
|
12
|
+
import { asciiOf } from './journey-words.js';
|
|
13
|
+
// Copied from showcase.ts SALE_OFFERS (href dropped: a terminal never opens a route).
|
|
14
|
+
export const SALE_OFFERS = [
|
|
15
|
+
{
|
|
16
|
+
kind: 'product', kindLabel: 'Product', name: 'Sold, the book', detail: 'The playbook, every chapter',
|
|
17
|
+
price: '$20', cents: 2000, cadence: '', verb: 'Buy', stamp: 'Paid',
|
|
18
|
+
link: 'one.ie/books/sold', live: false, rails: ['card', 'crypto'],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
kind: 'service', kindLabel: 'Service', name: 'Strategy call', detail: '30 minutes · Thursday 10:00',
|
|
22
|
+
price: '$100', cents: 10000, cadence: '', verb: 'Book', stamp: 'Booked',
|
|
23
|
+
link: 'one.ie/call', live: false, rails: ['card', 'crypto'],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
kind: 'subscription', kindLabel: 'Subscription', name: 'The Sold community', detail: 'People and agents, selling together',
|
|
27
|
+
price: '$100', cents: 10000, cadence: '/month', verb: 'Join', stamp: 'Joined',
|
|
28
|
+
link: 'one.ie/sold', live: true, rails: ['card'],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
kind: 'course', kindLabel: 'Course', name: 'Sold', detail: 'The course, with a month of the community',
|
|
32
|
+
price: '$100', cents: 10000, cadence: '', verb: 'Enrol', stamp: 'Enrolled',
|
|
33
|
+
link: 'one.ie/sold', live: true, rails: ['card', 'crypto'],
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
export const SALE_RAILS = [
|
|
37
|
+
{ id: 'card', label: 'Card', issuer: 'ONE', lands: "Paid into the seller's Stripe" },
|
|
38
|
+
{ id: 'crypto', label: 'USDC', issuer: 'USDC · Sui', lands: "Paid to the seller's own wallet" },
|
|
39
|
+
];
|
|
40
|
+
export const SALE_CHANNELS = [
|
|
41
|
+
{ id: 'web', label: 'Web page', bar: 'yourshop.example', native: true },
|
|
42
|
+
{ id: 'chat', label: 'Chat', bar: 'Chat', native: true },
|
|
43
|
+
{ id: 'whatsapp', label: 'WhatsApp', bar: 'WhatsApp', native: false },
|
|
44
|
+
{ id: 'instagram', label: 'Instagram', bar: 'Instagram', native: false },
|
|
45
|
+
{ id: 'sms', label: 'SMS', bar: 'Messages', native: false },
|
|
46
|
+
{ id: 'email', label: 'Email', bar: 'Inbox', native: false },
|
|
47
|
+
];
|
|
48
|
+
export const SALE_COPY = {
|
|
49
|
+
opens: 'the link opens on the card',
|
|
50
|
+
cardOnly: 'Monthly is card only.',
|
|
51
|
+
example: 'Example sale. Nothing here is a real payment.',
|
|
52
|
+
exampleOffer: 'Example price.',
|
|
53
|
+
address: '0x5a1e…0e01',
|
|
54
|
+
settled: 'On Sui',
|
|
55
|
+
shop: 'Your shop',
|
|
56
|
+
from: 'hello@yourshop.example',
|
|
57
|
+
ask: 'How much is it?',
|
|
58
|
+
time: '10:02',
|
|
59
|
+
emailFrom: 'From',
|
|
60
|
+
emailSubject: 'Subject',
|
|
61
|
+
emailPay: 'Pay',
|
|
62
|
+
};
|
|
63
|
+
export const SALE_KIND_IDS = SALE_OFFERS.map((o) => o.kind);
|
|
64
|
+
export const SALE_RAIL_IDS = SALE_RAILS.map((r) => r.id);
|
|
65
|
+
export const SALE_CHANNEL_IDS = SALE_CHANNELS.map((c) => c.id);
|
|
66
|
+
export const saleOffer = (kind) => SALE_OFFERS.find((o) => o.kind === kind) ?? SALE_OFFERS[0];
|
|
67
|
+
export const saleRail = (id) => SALE_RAILS.find((r) => r.id === id) ?? SALE_RAILS[0];
|
|
68
|
+
export const saleChannel = (id) => SALE_CHANNELS.find((c) => c.id === id) ?? SALE_CHANNELS[0];
|
|
69
|
+
/** Asking a card-only offer for crypto gives card — the same rule the web face follows. */
|
|
70
|
+
export const saleRailFor = (offer, rail) => (offer.rails.includes(rail) ? rail : offer.rails[0]);
|
|
71
|
+
export const salePrice = (offer) => `${offer.price}${offer.cadence}`;
|
|
72
|
+
export const salePay = (offer) => `${offer.verb} · ${salePrice(offer)}`;
|
|
73
|
+
/** From cents, so a dollar price never rounds into a different coin amount. */
|
|
74
|
+
export function saleUsdc(offer) {
|
|
75
|
+
const whole = offer.cents % 100 === 0;
|
|
76
|
+
return `${whole ? offer.cents / 100 : (offer.cents / 100).toFixed(2)} USDC`;
|
|
77
|
+
}
|
|
78
|
+
export const salePayOn = (offer, rail) => saleRailFor(offer, rail) === 'crypto' ? `${offer.verb} · ${saleUsdc(offer)}` : salePay(offer);
|
|
79
|
+
export function saleMessage(channel, offer) {
|
|
80
|
+
const p = salePrice(offer);
|
|
81
|
+
switch (channel) {
|
|
82
|
+
case 'chat': return `${offer.name} is ${p}. Pay here.`;
|
|
83
|
+
case 'email': return `${offer.name}, ${p}. Pay with the button below.`;
|
|
84
|
+
case 'sms': return `${offer.name} is ${p}. Pay here:`;
|
|
85
|
+
case 'instagram': return `It's ${p}. Here's the link:`;
|
|
86
|
+
case 'whatsapp': return `${offer.name} is ${p}. Pay here:`;
|
|
87
|
+
default: return `${offer.name}, ${p}.`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export const saleSubject = (offer) => `Your ${offer.kindLabel.toLowerCase()}: ${offer.name}`;
|
|
91
|
+
/** The `?via=` tag is how /sales counts which channel a sale came through. */
|
|
92
|
+
export const saleLink = (offer, channel) => channel === 'web' || channel === 'chat' ? offer.link : `${offer.link}?via=${channel}`;
|
|
93
|
+
/** A string from a flag, or null: the CLI refuses a word it does not know rather than drawing the default. */
|
|
94
|
+
export const saleKindOf = (v) => pick(v, SALE_KIND_IDS);
|
|
95
|
+
export const saleRailOf = (v) => pick(v, SALE_RAIL_IDS);
|
|
96
|
+
export const saleChannelOf = (v) => pick(v, SALE_CHANNEL_IDS);
|
|
97
|
+
function pick(v, ids) {
|
|
98
|
+
const s = typeof v === 'string' ? v.trim().toLowerCase() : '';
|
|
99
|
+
return ids.includes(s) ? s : null;
|
|
100
|
+
}
|
|
101
|
+
// ── drawing ──────────────────────────────────────────────────────────────────
|
|
102
|
+
/** The skill's limit (.claude/skills/ascii): every line fits a phone and a chat panel. */
|
|
103
|
+
export const SALE_MAX_WIDTH = 70;
|
|
104
|
+
const CARD_IN = 44; // card content; the card is 48 wide
|
|
105
|
+
const FRAME_IN = 62; // frame content; the frame is 66 wide
|
|
106
|
+
const INDENT = ' ';
|
|
107
|
+
const len = (s) => [...s].length;
|
|
108
|
+
function wrap(text, width) {
|
|
109
|
+
const lines = [];
|
|
110
|
+
let line = '';
|
|
111
|
+
for (const w of text.split(' ')) {
|
|
112
|
+
if (line && len(line) + 1 + len(w) > width) {
|
|
113
|
+
lines.push(line);
|
|
114
|
+
line = w;
|
|
115
|
+
}
|
|
116
|
+
else
|
|
117
|
+
line = line ? `${line} ${w}` : w;
|
|
118
|
+
}
|
|
119
|
+
if (line)
|
|
120
|
+
lines.push(line);
|
|
121
|
+
return lines;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Boxes are padded AFTER each cell is made ASCII, so "…" becoming "..." widens the cell, not the border.
|
|
125
|
+
*/
|
|
126
|
+
function boxer(inner, ascii) {
|
|
127
|
+
const g = (s) => (ascii ? asciiOf(s) : s);
|
|
128
|
+
const [tl, tr, bl, br, h, v] = ascii ? ['+', '+', '+', '+', '-', '|'] : ['╭', '╮', '╰', '╯', '─', '│'];
|
|
129
|
+
const fit = (s) => {
|
|
130
|
+
const t = g(s);
|
|
131
|
+
return len(t) > inner ? [...t].slice(0, inner).join('') : t;
|
|
132
|
+
};
|
|
133
|
+
const row = (s = '') => { const t = fit(s); return `${v} ${t}${' '.repeat(inner - len(t))} ${v}`; };
|
|
134
|
+
return {
|
|
135
|
+
top: `${tl}${h.repeat(inner + 2)}${tr}`,
|
|
136
|
+
bottom: `${bl}${h.repeat(inner + 2)}${br}`,
|
|
137
|
+
row,
|
|
138
|
+
/** Left and right in one row, at least two spaces apart. */
|
|
139
|
+
split: (l, r) => {
|
|
140
|
+
const a = g(l), b = g(r);
|
|
141
|
+
return row(`${a}${' '.repeat(Math.max(2, inner - len(a) - len(b)))}${b}`);
|
|
142
|
+
},
|
|
143
|
+
right: (s) => { const t = fit(s); return `${v} ${' '.repeat(inner - len(t))}${t} ${v}`; },
|
|
144
|
+
center: (s) => {
|
|
145
|
+
const t = fit(s), pad = inner - len(t), left = Math.floor(pad / 2);
|
|
146
|
+
return `${v} ${' '.repeat(left)}${t}${' '.repeat(pad - left)} ${v}`;
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** One offer as a payment card, on the rail it can really take. */
|
|
151
|
+
export function saleCardLines(kind, opts = {}) {
|
|
152
|
+
const offer = saleOffer(kind);
|
|
153
|
+
const asked = opts.rail ?? 'card';
|
|
154
|
+
const rail = saleRailFor(offer, asked);
|
|
155
|
+
const copy = saleRail(rail);
|
|
156
|
+
const b = boxer(CARD_IN, Boolean(opts.ascii));
|
|
157
|
+
const crypto = rail === 'crypto';
|
|
158
|
+
const price = crypto ? saleUsdc(offer) : salePrice(offer);
|
|
159
|
+
const paid = opts.phase === 'paid';
|
|
160
|
+
const stamp = `✓ ${offer.stamp}${paid && crypto ? ` · ${SALE_COPY.settled}` : ''}`;
|
|
161
|
+
return [
|
|
162
|
+
b.top,
|
|
163
|
+
b.split(copy.issuer, offer.kindLabel),
|
|
164
|
+
b.row(),
|
|
165
|
+
b.row(offer.name),
|
|
166
|
+
...wrap(offer.detail, CARD_IN).map((l) => b.row(l)),
|
|
167
|
+
b.row(),
|
|
168
|
+
offer.live ? b.row(price) : b.split(price, SALE_COPY.exampleOffer),
|
|
169
|
+
...(crypto ? [b.row(SALE_COPY.address)] : []),
|
|
170
|
+
b.row(),
|
|
171
|
+
b.row(paid ? stamp : `[ ${salePayOn(offer, rail)} ]`),
|
|
172
|
+
b.row(),
|
|
173
|
+
// Asked for USDC on a monthly offer: say why the card face is drawn, not silently swap.
|
|
174
|
+
...(rail !== asked ? [b.row(SALE_COPY.cardOnly)] : []),
|
|
175
|
+
b.row(`${copy.label} · ${copy.lands}`),
|
|
176
|
+
b.bottom,
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
/** The card inside a channel's thread: who, the agent's words and link, then the card it opens on. */
|
|
180
|
+
export function saleFrameLines(kind, channel, opts = {}) {
|
|
181
|
+
const offer = saleOffer(kind);
|
|
182
|
+
const c = saleChannel(channel);
|
|
183
|
+
const b = boxer(FRAME_IN, Boolean(opts.ascii));
|
|
184
|
+
const msg = saleMessage(channel, offer);
|
|
185
|
+
const link = saleLink(offer, channel);
|
|
186
|
+
const said = (text) => wrap(text, FRAME_IN).map((l) => b.row(l));
|
|
187
|
+
const head = (() => {
|
|
188
|
+
switch (channel) {
|
|
189
|
+
case 'web': return [b.row(c.bar)];
|
|
190
|
+
case 'chat': return [b.row(c.bar)];
|
|
191
|
+
case 'sms': return [b.center(SALE_COPY.shop), b.center(c.bar)];
|
|
192
|
+
case 'email': return [b.split(c.bar, SALE_COPY.time)];
|
|
193
|
+
default: return [b.row(`${SALE_COPY.shop} · ${c.bar}`)];
|
|
194
|
+
}
|
|
195
|
+
})();
|
|
196
|
+
const body = (() => {
|
|
197
|
+
switch (channel) {
|
|
198
|
+
case 'web': return [];
|
|
199
|
+
case 'chat': return said(msg);
|
|
200
|
+
case 'whatsapp':
|
|
201
|
+
case 'instagram':
|
|
202
|
+
return [b.right(SALE_COPY.ask), b.row(), ...said(msg), b.row(link), b.row(SALE_COPY.time)];
|
|
203
|
+
case 'sms':
|
|
204
|
+
return [b.center(SALE_COPY.time), b.row(), ...said(msg), b.row(link)];
|
|
205
|
+
case 'email':
|
|
206
|
+
return [
|
|
207
|
+
b.row(`${SALE_COPY.emailFrom.padEnd(8)}${SALE_COPY.shop} ${SALE_COPY.from}`),
|
|
208
|
+
b.row(`${SALE_COPY.emailSubject.padEnd(8)}${saleSubject(offer)}`),
|
|
209
|
+
b.row(),
|
|
210
|
+
...said(msg),
|
|
211
|
+
...said(offer.detail),
|
|
212
|
+
b.row(),
|
|
213
|
+
b.row(`[ ${SALE_COPY.emailPay} ${salePrice(offer)} ] ${link}`),
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
})();
|
|
217
|
+
return [
|
|
218
|
+
b.top,
|
|
219
|
+
...head,
|
|
220
|
+
b.row(),
|
|
221
|
+
...body,
|
|
222
|
+
...(body.length ? [b.row()] : []),
|
|
223
|
+
...(c.native ? [] : [b.row(`↓ ${SALE_COPY.opens}`), b.row()]),
|
|
224
|
+
...saleCardLines(kind, opts).map((l) => b.row(INDENT + l)),
|
|
225
|
+
b.bottom,
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
/** The whole drawing: one offer or several, framed or bare, with the example line once at the end. */
|
|
229
|
+
export function drawSale(kinds, opts = {}) {
|
|
230
|
+
const blocks = kinds.map((k) => (opts.channel ? saleFrameLines(k, opts.channel, opts) : saleCardLines(k, opts)).join('\n'));
|
|
231
|
+
return [...blocks, opts.ascii ? asciiOf(SALE_COPY.example) : SALE_COPY.example].join('\n\n') + '\n';
|
|
232
|
+
}
|
|
233
|
+
/** The same sale as data, for --json and for an agent: what would be drawn, never a payment. */
|
|
234
|
+
export function saleJson(kinds, opts = {}) {
|
|
235
|
+
const asked = opts.rail ?? 'card';
|
|
236
|
+
return {
|
|
237
|
+
ok: true,
|
|
238
|
+
example: true,
|
|
239
|
+
note: SALE_COPY.example,
|
|
240
|
+
offers: kinds.map((k) => {
|
|
241
|
+
const offer = saleOffer(k);
|
|
242
|
+
const rail = saleRailFor(offer, asked);
|
|
243
|
+
return {
|
|
244
|
+
kind: offer.kind,
|
|
245
|
+
name: offer.name,
|
|
246
|
+
price: salePrice(offer),
|
|
247
|
+
cents: offer.cents,
|
|
248
|
+
live: offer.live,
|
|
249
|
+
rail,
|
|
250
|
+
...(rail !== asked ? { cardOnly: SALE_COPY.cardOnly } : {}),
|
|
251
|
+
pay: salePayOn(offer, rail),
|
|
252
|
+
// --paid must change the data too, or an agent reading --json sees a flag it passed do nothing.
|
|
253
|
+
...(opts.phase === 'paid' ? { stamp: `${offer.stamp}${rail === 'crypto' ? ` · ${SALE_COPY.settled}` : ''}` } : {}),
|
|
254
|
+
lands: saleRail(rail).lands,
|
|
255
|
+
...(opts.channel
|
|
256
|
+
? { channel: opts.channel, message: saleMessage(opts.channel, offer), link: saleLink(offer, opts.channel) }
|
|
257
|
+
: { link: offer.link }),
|
|
258
|
+
};
|
|
259
|
+
}),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sui-grpc-send.ts — one Sui transfer (SUI or any coin type) over gRPC.
|
|
3
|
+
*
|
|
4
|
+
* Sui JSON-RPC is switched off on every public fullnode ("JSON-RPC on public fullnodes has
|
|
5
|
+
* been deprecated"), so the send goes over Mysten's gRPC fullnodes — the same endpoints and
|
|
6
|
+
* `client.core.executeTransaction` shape one.ie/web/src/lib/sui-transport.ts uses (copied, never
|
|
7
|
+
* imported: the CLI ships alone). `@mysten/sui` loads on demand so a command that never sends
|
|
8
|
+
* pays nothing for it.
|
|
9
|
+
*
|
|
10
|
+
* Never hangs, never re-sends: the digest is known BEFORE the node is asked (it is the hash of
|
|
11
|
+
* the bytes we signed), so a node that goes quiet is refused by name with that digest in hand.
|
|
12
|
+
*/
|
|
13
|
+
import type { Net } from './wallet-money.js';
|
|
14
|
+
export declare const SUI_GRPC: Record<Net, string>;
|
|
15
|
+
export interface SuiSendReq {
|
|
16
|
+
asset: 'SUI' | 'USDC' | 'ETH';
|
|
17
|
+
coinType: string;
|
|
18
|
+
from: string;
|
|
19
|
+
to: string;
|
|
20
|
+
amountUnits: bigint;
|
|
21
|
+
privateKeyHex: string;
|
|
22
|
+
/** An optional gRPC base URL override; default is Mysten's public fullnode for `net`. */
|
|
23
|
+
rpc?: string;
|
|
24
|
+
net: Net;
|
|
25
|
+
}
|
|
26
|
+
export interface SuiSendDone {
|
|
27
|
+
digest: string;
|
|
28
|
+
/** computation + storage − rebate, in MIST (never below 0). */
|
|
29
|
+
gasMist: bigint;
|
|
30
|
+
/** Wall-clock from signing to the node returning the certified effects, in ms. */
|
|
31
|
+
finalMs: number;
|
|
32
|
+
}
|
|
33
|
+
type Loader = (spec: string) => Promise<Record<string, unknown>>;
|
|
34
|
+
/** A variable specifier: no bundler or typechecker pulls @mysten/sui in; it loads from the person's own install. */
|
|
35
|
+
export declare const loadSpec: Loader;
|
|
36
|
+
/** A named failure that may carry the digest of a transaction that might still land. */
|
|
37
|
+
export declare class SuiSendError extends Error {
|
|
38
|
+
code: string;
|
|
39
|
+
digest?: string | undefined;
|
|
40
|
+
constructor(code: string, message: string, digest?: string | undefined);
|
|
41
|
+
}
|
|
42
|
+
export declare const gasMistOf: (g: {
|
|
43
|
+
computationCost?: string;
|
|
44
|
+
storageCost?: string;
|
|
45
|
+
storageRebate?: string;
|
|
46
|
+
} | undefined) => bigint;
|
|
47
|
+
export declare function suiSendGrpc(r: SuiSendReq, load?: Loader, deadlineMs?: number): Promise<SuiSendDone>;
|
|
48
|
+
/** 1_234_000_000 MIST → "1.234 SUI" (trailing zeros trimmed, at least one digit). */
|
|
49
|
+
export declare function mistToSui(mist: bigint): string;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
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 {};
|