oneie 5.7.5 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -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/ceiling.d.ts +36 -0
- package/dist/src/ceiling.js +189 -0
- package/dist/src/check.d.ts +11 -0
- package/dist/src/check.js +53 -0
- package/dist/src/credits.d.ts +29 -0
- package/dist/src/credits.js +88 -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 +15 -1
- package/dist/src/join.js +4 -0
- package/dist/src/key-sweep.d.ts +19 -3
- package/dist/src/key-sweep.js +70 -20
- package/dist/src/lib/check-words.d.ts +57 -0
- package/dist/src/lib/check-words.js +144 -0
- 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 +162 -20
- package/dist/src/lib/journey.d.ts +2 -0
- package/dist/src/lib/journey.js +21 -2
- package/dist/src/lib/key-source.d.ts +9 -0
- package/dist/src/lib/key-source.js +33 -0
- package/dist/src/lib/net-choice.d.ts +28 -0
- package/dist/src/lib/net-choice.js +72 -0
- package/dist/src/lib/network.d.ts +22 -0
- package/dist/src/lib/network.js +50 -0
- package/dist/src/lib/next-words.d.ts +105 -0
- package/dist/src/lib/next-words.js +298 -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 +90 -0
- package/dist/src/lib/sui-grpc-send.js +128 -0
- package/dist/src/lib/timed-fetch.d.ts +33 -0
- package/dist/src/lib/timed-fetch.js +59 -0
- package/dist/src/lib/vaultfile.d.ts +15 -0
- package/dist/src/lib/vaultfile.js +28 -1
- 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/move.d.ts +36 -0
- package/dist/src/move.js +152 -0
- package/dist/src/network-cmd.d.ts +17 -0
- package/dist/src/network-cmd.js +74 -0
- package/dist/src/next.d.ts +12 -0
- package/dist/src/next.js +67 -0
- package/dist/src/onboard.js +4 -3
- package/dist/src/shop-buy.d.ts +16 -0
- package/dist/src/shop-buy.js +101 -0
- package/dist/src/shop.js +40 -1
- package/dist/src/staff.js +10 -0
- package/dist/src/start.d.ts +12 -0
- package/dist/src/start.js +51 -21
- package/dist/src/thread.d.ts +2 -0
- package/dist/src/thread.js +52 -0
- package/dist/src/wallet-money.d.ts +158 -0
- package/dist/src/wallet-money.js +664 -0
- package/dist/src/wallet.d.ts +2 -0
- package/dist/src/wallet.js +290 -27
- package/dist/src/workflow.js +4 -1
- package/package.json +5 -2
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wallet-request.ts — the agent's half of "an agent asks, the owner's fingerprint decides".
|
|
3
|
+
*
|
|
4
|
+
* The agent builds a SENTENCE the owner's own chat already understands and wraps it in a link:
|
|
5
|
+
* `https://one.ie/chat#money=<sentence>`. Opening it types the sentence as the owner's line and
|
|
6
|
+
* shows the send card they sign with Touch ID. Nothing here signs, holds or opens a key; it only
|
|
7
|
+
* names the agent's own PUBLIC receiving address.
|
|
8
|
+
*
|
|
9
|
+
* The grammar is MIRRORED from one.ie/web/src/lib/chat/money-intent.ts (SEND, amountOk,
|
|
10
|
+
* chainsFor, moneyLink) — copied, never imported: the CLI ships alone. If the web's send pattern
|
|
11
|
+
* moves, tests/wallet-request.test.ts is the place that says so.
|
|
12
|
+
*/
|
|
13
|
+
import { SUI } from './wallet-money.js';
|
|
14
|
+
const WORD = { ethereum: 'ethereum', eth: 'ethereum', base: 'base', sui: 'sui' };
|
|
15
|
+
/** `USDC` · `SUI` · `ETH@base` · `USDC@ethereum` — anything the web grammar would not read is refused by name. */
|
|
16
|
+
export function parseRequestAsset(word) {
|
|
17
|
+
const [a = '', c] = word.trim().split('@');
|
|
18
|
+
const asset = a.toUpperCase();
|
|
19
|
+
if (asset !== 'ETH' && asset !== 'USDC' && asset !== 'SUI') {
|
|
20
|
+
return { ok: false, error: 'unsupported_asset', message: `Ask for USDC or SUI on Sui, or ETH or USDC on Ethereum or Base — not "${word}".` };
|
|
21
|
+
}
|
|
22
|
+
if (c === undefined) {
|
|
23
|
+
if (asset === 'ETH')
|
|
24
|
+
return { ok: false, error: 'chain_needed', message: 'ETH lives on Ethereum and Base — say which: ETH@ethereum or ETH@base.' };
|
|
25
|
+
return { ok: true, asset, chain: 'sui', defaulted: asset === 'USDC' };
|
|
26
|
+
}
|
|
27
|
+
const chain = WORD[c.toLowerCase()];
|
|
28
|
+
if (!chain)
|
|
29
|
+
return { ok: false, error: 'unsupported_chain', message: `"${c}" is not a chain a request link can name — ethereum, base or sui.` };
|
|
30
|
+
if (asset === 'ETH' && chain === 'sui')
|
|
31
|
+
return { ok: false, error: 'asset_not_on_chain', message: 'ETH does not live on Sui.' };
|
|
32
|
+
if (asset === 'SUI' && chain !== 'sui')
|
|
33
|
+
return { ok: false, error: 'asset_not_on_chain', message: `SUI lives on Sui, not ${chain}.` };
|
|
34
|
+
return { ok: true, asset, chain, defaulted: false };
|
|
35
|
+
}
|
|
36
|
+
/** The web's amountOk: a positive plain decimal, at most 18 places. */
|
|
37
|
+
export const amountOk = (a) => /^(?:\d+(?:\.\d{1,18})?|\.\d{1,18})$/.test(a) && Number.parseFloat(a) > 0;
|
|
38
|
+
/** `send 20 USDC on sui to 0x…` — the chain is always said, so the card never has to ask which. */
|
|
39
|
+
export const sentenceFor = (amount, asset, chain, to) => `send ${amount} ${asset} on ${chain} to ${to}`;
|
|
40
|
+
/** The web's moneyLink: the sentence is capped at 200 characters. */
|
|
41
|
+
export const linkFor = (sentence, origin = 'https://one.ie') => `${origin.replace(/\/$/, '')}/chat#money=${encodeURIComponent(sentence.trim().slice(0, 200))}`;
|
|
42
|
+
// The web's SEND pattern (money-intent.ts), verbatim.
|
|
43
|
+
const LEAD = "(?:(?:please|pls|ok|okay)\\s+)?(?:(?:can|could|will|would)\\s+you\\s+)?(?:(?:i\\s+(?:want|need)\\s+to|i'?d\\s+like\\s+to|let'?s|lets)\\s+)?";
|
|
44
|
+
const END = '[\\s.!]*$';
|
|
45
|
+
const AMOUNT = '(\\d+(?:\\.\\d+)?|\\.\\d+)';
|
|
46
|
+
const SEND = new RegExp(`^${LEAD}(?:send|pay|transfer)\\s+${AMOUNT}\\s*(eth|usdc|sui)(?:\\s*(?:on\\s+|@)(ethereum|eth|mainnet|base|sui))?\\s+to\\s+(\\S+)(?:\\s+on\\s+(ethereum|eth|mainnet|base|sui))?${END}`, 'i');
|
|
47
|
+
/** What the web's `matchMoneyIntent` would make of this sentence, as far as a send goes — or null. */
|
|
48
|
+
export function matchSend(text) {
|
|
49
|
+
const line = text.trim().replace(/\s+/g, ' ');
|
|
50
|
+
if (!line || line.length > 200)
|
|
51
|
+
return null;
|
|
52
|
+
const m = SEND.exec(line);
|
|
53
|
+
if (!m || !amountOk(m[1]))
|
|
54
|
+
return null;
|
|
55
|
+
const symbol = m[2].toUpperCase();
|
|
56
|
+
const to = m[4];
|
|
57
|
+
const family = /^0x[0-9a-fA-F]{40}$/.test(to) ? 'evm' : /^0x[0-9a-fA-F]{64}$/.test(to) ? 'sui' : null;
|
|
58
|
+
if (!family)
|
|
59
|
+
return null;
|
|
60
|
+
const possible = symbol === 'SUI' ? (family === 'evm' ? [] : ['sui']) : symbol === 'ETH' ? (family === 'sui' ? [] : ['eth', 'base']) : family === 'sui' ? ['sui'] : ['eth', 'base'];
|
|
61
|
+
if (possible.length === 0)
|
|
62
|
+
return null;
|
|
63
|
+
const said = (m[3] ?? m[5])?.toLowerCase();
|
|
64
|
+
const word = said === undefined ? null : { ethereum: 'eth', eth: 'eth', mainnet: 'eth', base: 'base', sui: 'sui' }[said] ?? null;
|
|
65
|
+
if (word && !possible.includes(word))
|
|
66
|
+
return null;
|
|
67
|
+
return { amount: m[1], symbol, chain: word ?? (possible.length === 1 ? possible[0] : null), to };
|
|
68
|
+
}
|
|
69
|
+
export const shortAddr = (a) => (a.length > 14 ? `${a.slice(0, 6)}…${a.slice(-4)}` : a);
|
|
70
|
+
/** The latest transaction that touched `address` on Sui — what an arrival most likely is. Null when it cannot be read. */
|
|
71
|
+
export async function latestSuiDigest(f, net, address) {
|
|
72
|
+
try {
|
|
73
|
+
const res = await f(SUI[net].graphql, {
|
|
74
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
75
|
+
body: JSON.stringify({ query: 'query($a: SuiAddress!) { transactions(last: 1, filter: { affectedAddress: $a }) { nodes { digest } } }', variables: { a: address } }),
|
|
76
|
+
});
|
|
77
|
+
if (!res.ok)
|
|
78
|
+
return null;
|
|
79
|
+
const r = (await res.json());
|
|
80
|
+
const d = r.data?.transactions?.nodes?.[0]?.digest;
|
|
81
|
+
return typeof d === 'string' && d ? d : null;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* move.ts — `one move publish <package dir>`: publish a Move package from a THROWAWAY deployer
|
|
3
|
+
* and hand everything it made to its owner, so no key that ever touched the publish keeps power.
|
|
4
|
+
*
|
|
5
|
+
* 1. build `sui move build --dump-bytecode-as-base64 -e <net>` in a temp copy (the repo's
|
|
6
|
+
* Move.lock and build/ are never written).
|
|
7
|
+
* 2. mint a fresh deployer key, in memory. It is kept, 0600, under ~/.one/deployers/ only so
|
|
8
|
+
* a crash between steps can still return the dust; it never prints and owns nothing
|
|
9
|
+
* once the run ends.
|
|
10
|
+
* 3. fund `--fund` SUI from the sealed vault in `--fund-dir` to the deployer.
|
|
11
|
+
* 4. publish one transaction: publish, and the UpgradeCap to `--owner` in the same PTB.
|
|
12
|
+
* 5. hand on one transaction from the deployer: every object `init` gave it goes to `--owner`
|
|
13
|
+
* (a `::WorkerCap` to `--worker-cap-to` when named), and the whole gas coin goes
|
|
14
|
+
* back to the funder.
|
|
15
|
+
* 6. read every created object is read back from the chain; the run is ok only if the
|
|
16
|
+
* UpgradeCap and every handed-on object sit with the address they were sent to and
|
|
17
|
+
* the deployer holds nothing.
|
|
18
|
+
*
|
|
19
|
+
* Dry by default: without --live it builds, prints the plan, and signs nothing. Only addresses,
|
|
20
|
+
* object ids and digests are printed. Every Sui act goes through suiExecGrpc, the CLI's one signer.
|
|
21
|
+
*/
|
|
22
|
+
import { Command } from 'commander';
|
|
23
|
+
import { type SuiCreated } from './lib/sui-grpc-send.js';
|
|
24
|
+
import { type Net } from './lib/wallet-money.js';
|
|
25
|
+
export interface MoveBytecode {
|
|
26
|
+
modules: string[];
|
|
27
|
+
dependencies: string[];
|
|
28
|
+
digest: number[];
|
|
29
|
+
}
|
|
30
|
+
/** Compile in a temp copy so the repo's Move.lock and build/ stay untouched. */
|
|
31
|
+
export declare function buildBytecode(dir: string, net: Net): MoveBytecode;
|
|
32
|
+
/** Where each object the deployer was given goes: a WorkerCap to its worker, everything else to the owner. */
|
|
33
|
+
export declare function handOnPlan(created: SuiCreated[], deployer: string, owner: string, workerCapTo?: string): Array<SuiCreated & {
|
|
34
|
+
to: string;
|
|
35
|
+
}>;
|
|
36
|
+
export declare function moveCmd(): Command;
|
package/dist/src/move.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* move.ts — `one move publish <package dir>`: publish a Move package from a THROWAWAY deployer
|
|
3
|
+
* and hand everything it made to its owner, so no key that ever touched the publish keeps power.
|
|
4
|
+
*
|
|
5
|
+
* 1. build `sui move build --dump-bytecode-as-base64 -e <net>` in a temp copy (the repo's
|
|
6
|
+
* Move.lock and build/ are never written).
|
|
7
|
+
* 2. mint a fresh deployer key, in memory. It is kept, 0600, under ~/.one/deployers/ only so
|
|
8
|
+
* a crash between steps can still return the dust; it never prints and owns nothing
|
|
9
|
+
* once the run ends.
|
|
10
|
+
* 3. fund `--fund` SUI from the sealed vault in `--fund-dir` to the deployer.
|
|
11
|
+
* 4. publish one transaction: publish, and the UpgradeCap to `--owner` in the same PTB.
|
|
12
|
+
* 5. hand on one transaction from the deployer: every object `init` gave it goes to `--owner`
|
|
13
|
+
* (a `::WorkerCap` to `--worker-cap-to` when named), and the whole gas coin goes
|
|
14
|
+
* back to the funder.
|
|
15
|
+
* 6. read every created object is read back from the chain; the run is ok only if the
|
|
16
|
+
* UpgradeCap and every handed-on object sit with the address they were sent to and
|
|
17
|
+
* the deployer holds nothing.
|
|
18
|
+
*
|
|
19
|
+
* Dry by default: without --live it builds, prints the plan, and signs nothing. Only addresses,
|
|
20
|
+
* object ids and digests are printed. Every Sui act goes through suiExecGrpc, the CLI's one signer.
|
|
21
|
+
*/
|
|
22
|
+
import { Command } from 'commander';
|
|
23
|
+
import { spawnSync } from 'node:child_process';
|
|
24
|
+
import { randomBytes } from 'node:crypto';
|
|
25
|
+
import { cpSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
26
|
+
import { homedir, tmpdir } from 'node:os';
|
|
27
|
+
import { basename, join, resolve } from 'node:path';
|
|
28
|
+
import { out } from './lib/client.js';
|
|
29
|
+
import { SuiSendError, loadSpec, mistToSui, suiExecGrpc, suiReadObjects, suiSendGrpc } from './lib/sui-grpc-send.js';
|
|
30
|
+
import { SUI_NATIVE } from './lib/wallet-money.js';
|
|
31
|
+
import { unlock } from './wallet.js';
|
|
32
|
+
import { netLine, resolveNet } from './lib/net-choice.js';
|
|
33
|
+
const SUI_ADDR = /^0x[0-9a-f]{64}$/i;
|
|
34
|
+
/** Compile in a temp copy so the repo's Move.lock and build/ stay untouched. */
|
|
35
|
+
export function buildBytecode(dir, net) {
|
|
36
|
+
const work = mkdtempSync(join(tmpdir(), 'one-move-'));
|
|
37
|
+
try {
|
|
38
|
+
const copy = join(work, basename(resolve(dir)));
|
|
39
|
+
cpSync(resolve(dir), copy, { recursive: true, filter: (p) => !p.includes(`${'/'}build${'/'}`) && !p.endsWith('/build') });
|
|
40
|
+
const r = spawnSync('sui', ['move', 'build', '--dump-bytecode-as-base64', '-e', net, '--path', copy], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
|
|
41
|
+
if (r.error)
|
|
42
|
+
throw new SuiSendError('sui_cli_missing', 'the `sui` CLI is not on PATH (brew install sui)');
|
|
43
|
+
const line = (r.stdout ?? '').split('\n').reverse().find((l) => l.trim().startsWith('{"modules"'));
|
|
44
|
+
if (r.status !== 0 || !line)
|
|
45
|
+
throw new SuiSendError('move_build_failed', ((r.stderr ?? '') + (r.stdout ?? '')).trim().split('\n').slice(-3).join(' | ') || 'no bytecode');
|
|
46
|
+
return JSON.parse(line);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
rmSync(work, { recursive: true, force: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Where each object the deployer was given goes: a WorkerCap to its worker, everything else to the owner. */
|
|
53
|
+
export function handOnPlan(created, deployer, owner, workerCapTo) {
|
|
54
|
+
return created
|
|
55
|
+
.filter((c) => c.owner.toLowerCase() === deployer.toLowerCase())
|
|
56
|
+
.map((c) => ({ ...c, to: workerCapTo && /::WorkerCap$/.test(c.type) ? workerCapTo : owner }));
|
|
57
|
+
}
|
|
58
|
+
export function moveCmd() {
|
|
59
|
+
const cmd = new Command('move').description('Move packages on Sui — publish from a throwaway key and hand every cap to its owner');
|
|
60
|
+
cmd.command('publish <dir>')
|
|
61
|
+
.description('Publish a Move package from a THROWAWAY deployer: fund it from --fund-dir, publish, send the UpgradeCap and every init object to --owner (a WorkerCap to --worker-cap-to), return the gas, read it all back. Dry unless --live')
|
|
62
|
+
.requiredOption('--owner <address>', 'Sui address that receives the UpgradeCap and every owned object the package creates')
|
|
63
|
+
.option('--worker-cap-to <address>', 'Sui address for a ::WorkerCap (default: --owner)')
|
|
64
|
+
.option('--fund-dir <dir>', 'Sealed vault folder that funds the deployer (Keychain / Touch ID)')
|
|
65
|
+
.option('--fund <sui>', 'SUI to fund the deployer with', '1')
|
|
66
|
+
.option('--net <network>', 'testnet | mainnet (default: ONE_NETWORK, then `one network`, then the deploy)')
|
|
67
|
+
.option('--rpc <url>', 'gRPC base URL override')
|
|
68
|
+
.option('--live', 'Sign and send. Without it: build and print the plan only')
|
|
69
|
+
.action(async (dir, o, sub) => {
|
|
70
|
+
const t0 = Date.now();
|
|
71
|
+
const nc = await resolveNet(o.net);
|
|
72
|
+
if (!nc.ok)
|
|
73
|
+
return out(sub, nc);
|
|
74
|
+
const net = nc.net;
|
|
75
|
+
if (!SUI_ADDR.test(o.owner))
|
|
76
|
+
return out(sub, { ok: false, error: 'owner_not_a_sui_address' });
|
|
77
|
+
if (o.workerCapTo && !SUI_ADDR.test(o.workerCapTo))
|
|
78
|
+
return out(sub, { ok: false, error: 'worker_cap_to_not_a_sui_address' });
|
|
79
|
+
if (!/^\d+(\.\d{1,9})?$/.test(o.fund) || Number(o.fund) <= 0)
|
|
80
|
+
return out(sub, { ok: false, error: 'fund_not_an_amount' });
|
|
81
|
+
const fundMist = BigInt(o.fund.split('.')[0]) * 1000000000n + BigInt((o.fund.split('.')[1] ?? '').padEnd(9, '0') || '0');
|
|
82
|
+
let code;
|
|
83
|
+
try {
|
|
84
|
+
code = buildBytecode(dir, net);
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return out(sub, { ok: false, error: e.code ?? 'move_build_failed', detail: e.message });
|
|
88
|
+
}
|
|
89
|
+
const plan = {
|
|
90
|
+
package: basename(resolve(dir)), net, networkFrom: nc.from, says: netLine(nc), modules: code.modules.length, dependencies: code.dependencies,
|
|
91
|
+
owner: o.owner, workerCapTo: o.workerCapTo ?? o.owner, fund: `${o.fund} SUI`, fundDir: o.fundDir ?? null,
|
|
92
|
+
};
|
|
93
|
+
if (!o.live)
|
|
94
|
+
return out(sub, { ok: true, dry: true, plan, next: 'add --live (and --fund-dir) to publish' });
|
|
95
|
+
if (!o.fundDir)
|
|
96
|
+
return out(sub, { ok: false, error: 'fund_dir_required', detail: '--live needs --fund-dir <vault folder> to fund the deployer' });
|
|
97
|
+
const opened = await unlock(o.fundDir);
|
|
98
|
+
if ('error' in opened)
|
|
99
|
+
return out(sub, { ok: false, error: 'vault_locked', detail: opened.error });
|
|
100
|
+
const funderKey = opened.keys.find((k) => k.chain === 'sui');
|
|
101
|
+
if (!funderKey)
|
|
102
|
+
return out(sub, { ok: false, error: 'no_sui_key_in_vault' });
|
|
103
|
+
// The throwaway. Kept 0600 outside any repo only so dust can be recovered after a crash.
|
|
104
|
+
const kp = (await loadSpec('@mysten/sui/keypairs/ed25519'));
|
|
105
|
+
const secret = randomBytes(32);
|
|
106
|
+
const deployer = kp.Ed25519Keypair.fromSecretKey(secret).toSuiAddress();
|
|
107
|
+
const secretHex = secret.toString('hex');
|
|
108
|
+
const keep = join(homedir(), '.one', 'deployers');
|
|
109
|
+
mkdirSync(keep, { recursive: true, mode: 0o700 });
|
|
110
|
+
const keptAt = join(keep, `${net}-${plan.package}-${Date.now()}.json`);
|
|
111
|
+
writeFileSync(keptAt, JSON.stringify({ net, package: plan.package, address: deployer, secretKeyHex: secretHex, minted: new Date().toISOString() }), { mode: 0o600 });
|
|
112
|
+
const steps = { deployer, deployerKeptAt: keptAt };
|
|
113
|
+
try {
|
|
114
|
+
const fundTx = await suiSendGrpc({ asset: 'SUI', coinType: SUI_NATIVE, from: funderKey.address, to: deployer, amountUnits: fundMist, privateKeyHex: funderKey.privateKeyHex, net, rpc: o.rpc });
|
|
115
|
+
steps.fund = { digest: fundTx.digest, from: funderKey.address, amount: `${o.fund} SUI`, ms: fundTx.finalMs };
|
|
116
|
+
const pub = await suiExecGrpc({
|
|
117
|
+
net, rpc: o.rpc, from: deployer, privateKeyHex: secretHex,
|
|
118
|
+
build: (tx) => {
|
|
119
|
+
const [upgradeCap] = tx.publish({ modules: code.modules, dependencies: code.dependencies });
|
|
120
|
+
tx.transferObjects([upgradeCap], tx.pure.address(o.owner));
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
const pkg = pub.created.find((c) => c.owner === 'package');
|
|
124
|
+
const upgradeCap = pub.created.find((c) => /::package::UpgradeCap$/.test(c.type));
|
|
125
|
+
steps.publish = { digest: pub.digest, packageId: pkg?.objectId, upgradeCap: upgradeCap?.objectId, created: pub.created, gas: `${mistToSui(pub.gasMist)} SUI`, ms: pub.finalMs };
|
|
126
|
+
const hand = handOnPlan(pub.created, deployer, o.owner, o.workerCapTo);
|
|
127
|
+
const back = await suiExecGrpc({
|
|
128
|
+
net, rpc: o.rpc, from: deployer, privateKeyHex: secretHex,
|
|
129
|
+
build: (tx) => {
|
|
130
|
+
for (const to of new Set(hand.map((h) => h.to))) {
|
|
131
|
+
tx.transferObjects(hand.filter((h) => h.to === to).map((h) => tx.object(h.objectId)), tx.pure.address(to));
|
|
132
|
+
}
|
|
133
|
+
tx.transferObjects([tx.gas], tx.pure.address(funderKey.address));
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
steps.handOn = { digest: back.digest, objects: hand.map((h) => ({ objectId: h.objectId, type: h.type, to: h.to })), gasReturnedTo: funderKey.address, ms: back.finalMs };
|
|
137
|
+
// Read back. Ok only if every cap sits where it was sent and the deployer holds nothing.
|
|
138
|
+
const ids = [...(upgradeCap ? [upgradeCap.objectId] : []), ...hand.map((h) => h.objectId)];
|
|
139
|
+
const read = await suiReadObjects(net, ids, { rpc: o.rpc });
|
|
140
|
+
const want = new Map([...(upgradeCap ? [[upgradeCap.objectId, o.owner]] : []), ...hand.map((h) => [h.objectId, h.to])]);
|
|
141
|
+
const wrong = read.filter((r) => (want.get(r.objectId) ?? '').toLowerCase() !== r.owner.toLowerCase());
|
|
142
|
+
steps.readBack = read;
|
|
143
|
+
const ok = Boolean(pkg && upgradeCap) && wrong.length === 0;
|
|
144
|
+
return out(sub, { ok, ...(ok ? {} : { error: 'read_back_mismatch', wrong }), net, packageId: pkg?.objectId, upgradeCap: upgradeCap?.objectId, ...steps, wallMs: Date.now() - t0 });
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
const err = e;
|
|
148
|
+
return out(sub, { ok: false, error: err.code ?? 'move_publish_failed', detail: err.message, ...(err.digest ? { digest: err.digest } : {}), ...steps, recover: `deployer key kept at ${keptAt} (0600) — return its SUI with a send from that key` });
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return cmd;
|
|
152
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* network-cmd.ts — `one network [mainnet|testnet|auto]`: the one switch every chain command reads
|
|
3
|
+
* (lib/net-choice.ts). Bare: which network a command would use right now, and why. A name: save it in
|
|
4
|
+
* ~/.config/one/network. `auto`: clear it, so commands follow the deploy again.
|
|
5
|
+
*
|
|
6
|
+
* Tony, 2026-11-12: "making the switch between testnet to mainnet and back to testnet for training to be
|
|
7
|
+
* seamless and delightful." So the switch says, in one line, what it means for your money, then shows the
|
|
8
|
+
* wallet in this folder on that network — and on testnet with nothing in it, the one command for free coins.
|
|
9
|
+
*/
|
|
10
|
+
import { Command } from 'commander';
|
|
11
|
+
import { type NetChoice } from './lib/net-choice.js';
|
|
12
|
+
import { type Net } from './lib/network.js';
|
|
13
|
+
/** The headline: what this network means for your money, in plain words. */
|
|
14
|
+
export declare function headline(c: NetChoice & {
|
|
15
|
+
ok: true;
|
|
16
|
+
}, deploy: Net | null): string;
|
|
17
|
+
export declare function networkCmd(): Command;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* network-cmd.ts — `one network [mainnet|testnet|auto]`: the one switch every chain command reads
|
|
3
|
+
* (lib/net-choice.ts). Bare: which network a command would use right now, and why. A name: save it in
|
|
4
|
+
* ~/.config/one/network. `auto`: clear it, so commands follow the deploy again.
|
|
5
|
+
*
|
|
6
|
+
* Tony, 2026-11-12: "making the switch between testnet to mainnet and back to testnet for training to be
|
|
7
|
+
* seamless and delightful." So the switch says, in one line, what it means for your money, then shows the
|
|
8
|
+
* wallet in this folder on that network — and on testnet with nothing in it, the one command for free coins.
|
|
9
|
+
*/
|
|
10
|
+
import { Command } from 'commander';
|
|
11
|
+
import { jsonMode, out } from './lib/client.js';
|
|
12
|
+
import { NET_FILE, resolveNet, saveNet, savedNet, webBase } from './lib/net-choice.js';
|
|
13
|
+
import { readDeployNetwork } from './lib/network.js';
|
|
14
|
+
import { SUI, SUI_NATIVE, readSuiCoin } from './lib/wallet-money.js';
|
|
15
|
+
import { deadlineFetch, vaultSuiAddressOf } from './wallet-money.js';
|
|
16
|
+
/** The headline: what this network means for your money, in plain words. */
|
|
17
|
+
export function headline(c, deploy) {
|
|
18
|
+
const why = { flag: '--net', env: 'ONE_NETWORK', saved: 'your choice', deploy: 'one.ie' }[c.from];
|
|
19
|
+
if (c.net === 'testnet')
|
|
20
|
+
return `◐ Practice — test coins, free to get, nothing real moves. (${why})`;
|
|
21
|
+
return `● Real money — every send names MAINNET and waits for --live. (${why}${c.from !== 'deploy' && deploy === 'testnet' ? ', while one.ie still runs testnet' : ''})`;
|
|
22
|
+
}
|
|
23
|
+
const units = (v, d) => {
|
|
24
|
+
const w = (v / 10n ** BigInt(d)).toString();
|
|
25
|
+
const f = (v % 10n ** BigInt(d)).toString().padStart(d, '0').replace(/0+$/, '');
|
|
26
|
+
return f ? `${w}.${f}` : w;
|
|
27
|
+
};
|
|
28
|
+
export function networkCmd() {
|
|
29
|
+
return new Command('network')
|
|
30
|
+
.description('Testnet or mainnet for every chain command. Bare: the network now and why. `mainnet|testnet`: switch. `auto`: follow one.ie. Order: --net, ONE_NETWORK, this choice, the deploy')
|
|
31
|
+
.argument('[choice]', 'mainnet | testnet | auto')
|
|
32
|
+
.option('--api <url>', 'one.ie base URL whose deploy is followed')
|
|
33
|
+
.option('--dir <path>', 'The wallet folder to show on this network', '.')
|
|
34
|
+
.action(async (choice, o, sub) => {
|
|
35
|
+
const t0 = Date.now();
|
|
36
|
+
if (choice !== undefined) {
|
|
37
|
+
if (choice !== 'mainnet' && choice !== 'testnet' && choice !== 'auto')
|
|
38
|
+
return out(sub, { ok: false, error: 'bad_choice', message: 'one network mainnet | testnet | auto' });
|
|
39
|
+
saveNet(choice === 'auto' ? null : choice);
|
|
40
|
+
}
|
|
41
|
+
const base = webBase(o.api);
|
|
42
|
+
const [now, deploy] = await Promise.all([resolveNet(undefined, o.api), readDeployNetwork(base)]);
|
|
43
|
+
const saved = savedNet();
|
|
44
|
+
const env = process.env.ONE_NETWORK?.trim() || null;
|
|
45
|
+
// This folder's wallet, on the network just chosen. Public address only — the vault never opens.
|
|
46
|
+
const sui = vaultSuiAddressOf(o.dir);
|
|
47
|
+
let wallet = null;
|
|
48
|
+
if (now.ok && sui) {
|
|
49
|
+
const f = deadlineFetch(6000);
|
|
50
|
+
const [s, u] = await Promise.all([readSuiCoin(f, now.net, sui, SUI_NATIVE), readSuiCoin(f, now.net, sui, SUI[now.net].usdc)]);
|
|
51
|
+
wallet = { address: sui, sui: s === null ? null : units(s, 9), usdc: u === null ? null : units(u, 6) };
|
|
52
|
+
}
|
|
53
|
+
const empty = wallet && wallet.sui !== null && Number(wallet.sui) === 0;
|
|
54
|
+
if (jsonMode(sub))
|
|
55
|
+
return out(sub, { ok: now.ok, network: now.ok ? now.net : null, from: now.ok ? now.from : null, deploy, saved, env, wallet, ms: Date.now() - t0, ...(now.ok ? {} : { error: now.error }) });
|
|
56
|
+
if (!now.ok) {
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
process.stdout.write(`? Which network? ${now.message}\n`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const short = (a) => `${a.slice(0, 6)}…${a.slice(-4)}`;
|
|
62
|
+
const lines = [
|
|
63
|
+
headline(now, deploy),
|
|
64
|
+
...(wallet ? [` your wallet ${short(wallet.address)}: ${wallet.sui ?? '—'} SUI · ${wallet.usdc ?? '—'} USDC on ${now.net}`] : []),
|
|
65
|
+
...(now.net === 'testnet' && wallet && empty ? [` free test coins: one wallet faucet ${wallet.address} --chain sui --network testnet`] : []),
|
|
66
|
+
'',
|
|
67
|
+
now.net === 'testnet' ? ' back to real money: one network mainnet' : ' practise first: one network testnet',
|
|
68
|
+
saved ? ' follow one.ie again: one network auto' : ` one.ie runs ${deploy ?? 'an unreadable network'} — this follows it`,
|
|
69
|
+
...(env ? [` ONE_NETWORK=${env} is set in this shell and wins over the switch`] : []),
|
|
70
|
+
` order: --net, then ONE_NETWORK, then this switch${saved ? ` (${NET_FILE})` : ''}, then one.ie`,
|
|
71
|
+
];
|
|
72
|
+
process.stdout.write(lines.join('\n') + '\n');
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `one next` (alias `one learn`): where you are, and the one thing to do now.
|
|
3
|
+
* `one learn <topic>` teaches one thing: me · key · wallets · limit · sell · paid · ask · never · course.
|
|
4
|
+
*
|
|
5
|
+
* Reads this folder only (`.one/`), never the network: the "what now" door answers at
|
|
6
|
+
* once. The words are `lib/next-words.ts`; this file reads the disk and prints.
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { type NextFacts } from './lib/next-words.js';
|
|
10
|
+
/** The folder's facts. Secrets are checked for presence only; their contents are never read. */
|
|
11
|
+
export declare function readFacts(dir: string): NextFacts;
|
|
12
|
+
export declare function nextCmd(): Command;
|
package/dist/src/next.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `one next` (alias `one learn`): where you are, and the one thing to do now.
|
|
3
|
+
* `one learn <topic>` teaches one thing: me · key · wallets · limit · sell · paid · ask · never · course.
|
|
4
|
+
*
|
|
5
|
+
* Reads this folder only (`.one/`), never the network: the "what now" door answers at
|
|
6
|
+
* once. The words are `lib/next-words.ts`; this file reads the disk and prints.
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { jsonMode } from './lib/client.js';
|
|
12
|
+
import { cliPrefix } from './lib/invoked-as.js';
|
|
13
|
+
import { isAgentEnvironment } from './lib/agent-env.js';
|
|
14
|
+
import { KEY_DIR_NAME, KEY_FILE_NAME, LEGACY_KEY_DIR_NAME } from './lib/keyfile.js';
|
|
15
|
+
import { readVaultFolder } from './lib/vaultfile.js';
|
|
16
|
+
import { asciiOf } from './lib/journey-words.js';
|
|
17
|
+
import { isTopic, learnWords, nextData, nextWords, TOPICS } from './lib/next-words.js';
|
|
18
|
+
/** The folder's facts. Secrets are checked for presence only; their contents are never read. */
|
|
19
|
+
export function readFacts(dir) {
|
|
20
|
+
let state = null;
|
|
21
|
+
try {
|
|
22
|
+
const s = JSON.parse(readFileSync(join(dir, KEY_DIR_NAME, 'journey.json'), 'utf8'));
|
|
23
|
+
if (s && s.v === 1 && typeof s.workspace === 'string')
|
|
24
|
+
state = s;
|
|
25
|
+
}
|
|
26
|
+
catch { /* no journey here yet */ }
|
|
27
|
+
const hasKey = [KEY_DIR_NAME, LEGACY_KEY_DIR_NAME].some((d) => existsSync(join(dir, d, KEY_FILE_NAME)));
|
|
28
|
+
const v = readVaultFolder(dir);
|
|
29
|
+
return { state, hasKey, vault: v ? v.wrap : null };
|
|
30
|
+
}
|
|
31
|
+
export function nextCmd() {
|
|
32
|
+
return new Command('next')
|
|
33
|
+
.alias('learn')
|
|
34
|
+
.description(`Where you are, and the one thing to do now. Teach one thing: learn <${TOPICS.join('|')}>`)
|
|
35
|
+
.argument('[topic]', TOPICS.join(' | '))
|
|
36
|
+
.option('--for <reader>', 'agent (the whole primer) or person (one step). Default: agent in an agent shell, person at a terminal')
|
|
37
|
+
.option('--dir <path>', 'The agent\'s folder', '.')
|
|
38
|
+
.action((topic, opts, cmd) => {
|
|
39
|
+
if (topic && !isTopic(topic)) {
|
|
40
|
+
const error = `no lesson called "${topic}". Lessons: ${TOPICS.join(', ')}`;
|
|
41
|
+
if (jsonMode(cmd))
|
|
42
|
+
process.stdout.write(JSON.stringify({ ok: false, error }) + '\n');
|
|
43
|
+
else
|
|
44
|
+
process.stderr.write(`${error}\n`);
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (opts.for && opts.for !== 'agent' && opts.for !== 'person') {
|
|
49
|
+
process.stderr.write('--for is agent or person\n');
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const facts = readFacts(opts.dir);
|
|
54
|
+
const cli = cliPrefix();
|
|
55
|
+
if (jsonMode(cmd)) {
|
|
56
|
+
const data = nextData(facts, cli);
|
|
57
|
+
// A topic narrows the answer to that one lesson; bare gives every lesson.
|
|
58
|
+
const body = topic ? { ...data, lessons: data.lessons.filter((l) => l.topic === topic) } : data;
|
|
59
|
+
process.stdout.write(JSON.stringify({ ok: true, ...body }) + '\n');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const reader = opts.for ?? (isAgentEnvironment() ? 'agent' : 'person');
|
|
63
|
+
const text = topic && isTopic(topic) ? learnWords(facts, cli, reader, topic) : nextWords(facts, cli, reader);
|
|
64
|
+
const plain = !process.stdout.isTTY || 'NO_COLOR' in process.env;
|
|
65
|
+
process.stdout.write(plain ? asciiOf(text) : text);
|
|
66
|
+
});
|
|
67
|
+
}
|
package/dist/src/onboard.js
CHANGED
|
@@ -34,10 +34,10 @@ async function ask(base, key, receiver, data) {
|
|
|
34
34
|
// agent has a key to call the substrate with.
|
|
35
35
|
const STAGE_GUIDE = {
|
|
36
36
|
registered: 'done — your identity exists (uid + apiKey minted).',
|
|
37
|
-
bootstrapped: 'done — your own
|
|
37
|
+
bootstrapped: 'done — your own group exists (gid + aid + scopedKey minted).',
|
|
38
38
|
active: 'publish a capability or place a market offer: `one agent publish` or `one trade market`.',
|
|
39
39
|
settled: 'complete a sale: `one trade hire` (as a buyer) or accept + settle an offer (as the seller).',
|
|
40
|
-
adopted: 'get adopted by another
|
|
40
|
+
adopted: 'get adopted by another group — accept an invite, or have your capability hired long-term.',
|
|
41
41
|
};
|
|
42
42
|
const STAGE_ORDER = ['registered', 'bootstrapped', 'active', 'settled', 'adopted'];
|
|
43
43
|
function out(cmd, data) {
|
|
@@ -52,7 +52,7 @@ function out(cmd, data) {
|
|
|
52
52
|
}
|
|
53
53
|
const stages = data.stages ?? [];
|
|
54
54
|
process.stdout.write(`✓ onboarded as ${data.uid ?? '?'}\n`);
|
|
55
|
-
process.stdout.write(`
|
|
55
|
+
process.stdout.write(` group: ${data.group ?? data.workspace ?? '?'}\n`);
|
|
56
56
|
process.stdout.write(` url: ${data.url ?? '?'}\n\n`);
|
|
57
57
|
process.stdout.write(' lifecycle: register → bootstrap → active → settled → adopted\n');
|
|
58
58
|
for (const s of stages) {
|
|
@@ -139,6 +139,7 @@ export function onboardCmd() {
|
|
|
139
139
|
ok: true,
|
|
140
140
|
uid: uid || '(unknown — no ONE_UID in env; re-run in a fresh dir to see it)',
|
|
141
141
|
workspace,
|
|
142
|
+
group: workspace, // the word a person reads; `workspace` stays for scripts
|
|
142
143
|
url: workspace ? `${base}/u/${workspace}` : base,
|
|
143
144
|
key: `${KEY_FILE} (0600)`,
|
|
144
145
|
stages,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* shop-buy.ts — `one shop buy <workspace> <ppid>`: an agent buys a store's product with USDC on Sui from its own
|
|
3
|
+
* vault, through the same route the checkout page uses (/api/storefront/crypto):
|
|
4
|
+
*
|
|
5
|
+
* 1. quote action:'quote' — the store's price, its Sui option, usdcEligible
|
|
6
|
+
* 2. escrow action:'escrow' — a deposit address for THIS sale and the exact USDC amount pay recorded
|
|
7
|
+
* 3. pay the vault in --dir sends exactly that USDC to the deposit address (suiSendGrpc, the one Sui signer)
|
|
8
|
+
* 4. status action:'status' — polled until pay sees the money (completed); forwardTxHash once the sweep moves it on
|
|
9
|
+
*
|
|
10
|
+
* No address or amount is ever typed: both come back from the route, which reads them server-side. Dry by default:
|
|
11
|
+
* without --live it quotes and stops — the escrow address is minted only by a live run, because minting one is a write.
|
|
12
|
+
*/
|
|
13
|
+
import { Command } from 'commander';
|
|
14
|
+
/** "1.000000" USDC → 1000000 base units (6 decimals); anything else → null. */
|
|
15
|
+
export declare function usdcUnits(v: unknown): bigint | null;
|
|
16
|
+
export declare function shopBuyCmd(): Command;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* shop-buy.ts — `one shop buy <workspace> <ppid>`: an agent buys a store's product with USDC on Sui from its own
|
|
3
|
+
* vault, through the same route the checkout page uses (/api/storefront/crypto):
|
|
4
|
+
*
|
|
5
|
+
* 1. quote action:'quote' — the store's price, its Sui option, usdcEligible
|
|
6
|
+
* 2. escrow action:'escrow' — a deposit address for THIS sale and the exact USDC amount pay recorded
|
|
7
|
+
* 3. pay the vault in --dir sends exactly that USDC to the deposit address (suiSendGrpc, the one Sui signer)
|
|
8
|
+
* 4. status action:'status' — polled until pay sees the money (completed); forwardTxHash once the sweep moves it on
|
|
9
|
+
*
|
|
10
|
+
* No address or amount is ever typed: both come back from the route, which reads them server-side. Dry by default:
|
|
11
|
+
* without --live it quotes and stops — the escrow address is minted only by a live run, because minting one is a write.
|
|
12
|
+
*/
|
|
13
|
+
import { Command } from 'commander';
|
|
14
|
+
import { authHeaders, out, resolveBase } from './lib/client.js';
|
|
15
|
+
import { suiSendGrpc } from './lib/sui-grpc-send.js';
|
|
16
|
+
import { SUI } from './lib/wallet-money.js';
|
|
17
|
+
import { unlock } from './wallet.js';
|
|
18
|
+
import { netLine, resolveNet } from './lib/net-choice.js';
|
|
19
|
+
const SUI_ADDR = /^0x[0-9a-f]{64}$/i;
|
|
20
|
+
/** "1.000000" USDC → 1000000 base units (6 decimals); anything else → null. */
|
|
21
|
+
export function usdcUnits(v) {
|
|
22
|
+
if (typeof v !== 'string' || !/^\d{1,9}(\.\d{1,6})?$/.test(v.trim()))
|
|
23
|
+
return null;
|
|
24
|
+
const [w, f = ''] = v.trim().split('.');
|
|
25
|
+
const n = BigInt(w) * 1000000n + BigInt(f.padEnd(6, '0'));
|
|
26
|
+
return n > 0n ? n : null;
|
|
27
|
+
}
|
|
28
|
+
async function crypto(base, body) {
|
|
29
|
+
const res = await fetch(`${base.replace(/\/$/, '')}/api/storefront/crypto`, { method: 'POST', headers: { ...authHeaders(), 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
30
|
+
return { status: res.status, json: (await res.json().catch(() => ({}))) };
|
|
31
|
+
}
|
|
32
|
+
export function shopBuyCmd() {
|
|
33
|
+
return new Command('buy')
|
|
34
|
+
.description("Buy a store's product with USDC on Sui from the vault in --dir: quote, escrow address for this sale, pay the exact USDC, poll until pay sees it. Dry (quote only) unless --live")
|
|
35
|
+
.argument('<workspace>', 'The store, e.g. one')
|
|
36
|
+
.argument('<ppid>', 'The price id, e.g. price_58bgh7w7y97ickj6')
|
|
37
|
+
.option('--dir <vault>', 'The sealed vault that pays', '.')
|
|
38
|
+
.option('--net <network>', 'mainnet | testnet (default: ONE_NETWORK, then `one network`, then the deploy)')
|
|
39
|
+
.option('--api <url>', 'one.ie base URL')
|
|
40
|
+
.option('--rpc <url>', 'Sui gRPC base URL override')
|
|
41
|
+
.option('--wait <seconds>', 'How long to poll status after paying', '120')
|
|
42
|
+
.option('--live', 'Mint the escrow address, pay it and poll. Without it: the quote only')
|
|
43
|
+
.action(async (workspace, ppid, o, sub) => {
|
|
44
|
+
const t0 = Date.now();
|
|
45
|
+
const nc = await resolveNet(o.net, o.api);
|
|
46
|
+
if (!nc.ok)
|
|
47
|
+
return out(sub, nc);
|
|
48
|
+
const net = nc.net;
|
|
49
|
+
const base = resolveBase({ api: o.api }, 'https://one.ie');
|
|
50
|
+
const q = await crypto(base, { action: 'quote', workspace, ppid, chains: ['SUI'] });
|
|
51
|
+
const sui = (q.json.options ?? []).find((x) => x.chain === 'SUI');
|
|
52
|
+
if (q.status !== 200 || !sui)
|
|
53
|
+
return out(sub, { ok: false, error: String(q.json.error ?? 'no_sui_option'), status: q.status });
|
|
54
|
+
if (sui.usdcEligible !== true)
|
|
55
|
+
return out(sub, { ok: false, error: 'usdc_not_offered', detail: 'this store does not take USDC on Sui for this price' });
|
|
56
|
+
const quote = { workspace, ppid, usd: q.json.amountUsd, escrow: q.json.escrow, custody: q.json.custody, net, networkFrom: nc.from, says: netLine(nc) };
|
|
57
|
+
if (!o.live)
|
|
58
|
+
return out(sub, { ok: true, dry: true, quote, next: 'add --live to mint this sale\'s deposit address and pay it in USDC from --dir' });
|
|
59
|
+
const opened = await unlock(o.dir);
|
|
60
|
+
if ('error' in opened)
|
|
61
|
+
return out(sub, { ok: false, error: 'vault_locked', detail: opened.error });
|
|
62
|
+
const key = opened.keys.find((k) => k.chain === 'sui');
|
|
63
|
+
if (!key)
|
|
64
|
+
return out(sub, { ok: false, error: 'no_sui_key_in_vault' });
|
|
65
|
+
const e = await crypto(base, { action: 'escrow', workspace, ppid, chain: 'SUI' });
|
|
66
|
+
const paymentId = String(e.json.paymentId ?? '');
|
|
67
|
+
const escrowAddress = String(e.json.escrowAddress ?? '');
|
|
68
|
+
const units = usdcUnits(e.json.usdc);
|
|
69
|
+
if (e.status !== 200 || !paymentId || !SUI_ADDR.test(escrowAddress))
|
|
70
|
+
return out(sub, { ok: false, error: String(e.json.error ?? 'escrow_failed'), status: e.status });
|
|
71
|
+
if (units === null)
|
|
72
|
+
return out(sub, { ok: false, error: 'usdc_not_offered_on_this_escrow', paymentId, detail: 'pay did not echo a USDC amount for this deposit address — nothing was sent' });
|
|
73
|
+
if (e.json.network === 'testnet' && net === 'mainnet')
|
|
74
|
+
return out(sub, { ok: false, error: 'network_mismatch', paymentId });
|
|
75
|
+
let digest;
|
|
76
|
+
let finalMs;
|
|
77
|
+
try {
|
|
78
|
+
const sent = await suiSendGrpc({ asset: 'USDC', coinType: SUI[net].usdc, from: key.address, to: escrowAddress, amountUnits: units, privateKeyHex: key.privateKeyHex, rpc: o.rpc, net });
|
|
79
|
+
digest = sent.digest;
|
|
80
|
+
finalMs = sent.finalMs;
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
const se = err;
|
|
84
|
+
return out(sub, { ok: false, error: se.code ?? 'send_failed', detail: se.message, ...(se.digest ? { digest: se.digest } : {}), paymentId, escrowAddress });
|
|
85
|
+
}
|
|
86
|
+
const deadline = Date.now() + Math.max(10, Number(o.wait) || 120) * 1000;
|
|
87
|
+
let s = {};
|
|
88
|
+
while (Date.now() < deadline) {
|
|
89
|
+
s = (await crypto(base, { action: 'status', workspace, paymentId, chain: 'SUI', amount: String(e.json.amount ?? '') })).json;
|
|
90
|
+
if (s.status === 'completed' || s.status === 'forwarded' || s.forwardTxHash)
|
|
91
|
+
break;
|
|
92
|
+
await new Promise((r) => setTimeout(r, 4000));
|
|
93
|
+
}
|
|
94
|
+
const seen = s.status === 'completed' || s.status === 'forwarded' || Boolean(s.forwardTxHash);
|
|
95
|
+
return out(sub, {
|
|
96
|
+
ok: seen, ...(seen ? {} : { error: 'not_seen_yet', next: 'poll again: the money is at the deposit address' }),
|
|
97
|
+
paid: `${e.json.usdc} USDC`, paymentId, escrowAddress, digest, explorer: `${SUI[net].explorer}/tx/${digest}`, payer: key.address,
|
|
98
|
+
status: s.status ?? null, forwardTxHash: s.forwardTxHash ?? null, finalMs, wallMs: Date.now() - t0,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|