paralith-mcp 0.5.1 → 0.5.2

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/dist/http.mjs CHANGED
@@ -967,7 +967,7 @@ async function postAdmitted(post, {
967
967
  onRefused,
968
968
  random = Math.random,
969
969
  now = Date.now,
970
- sleep: sleep2 = pause
970
+ sleep: sleep3 = pause
971
971
  } = {}) {
972
972
  const started = now();
973
973
  for (let attempt = 0; ; attempt += 1) {
@@ -984,7 +984,7 @@ async function postAdmitted(post, {
984
984
  } catch {
985
985
  }
986
986
  try {
987
- await sleep2(wait2, signal);
987
+ await sleep3(wait2, signal);
988
988
  } catch (reason) {
989
989
  throw new AdmissionWaitAborted(reason);
990
990
  }
@@ -18464,6 +18464,7 @@ var DEFAULT_TIMING = Object.freeze({
18464
18464
  attestorRelay: 3e4
18465
18465
  });
18466
18466
  var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : null;
18467
+ var DEFAULT_SETTLE = Object.freeze({ withinMs: 3e4, everyMs: 1e3 });
18467
18468
  async function manifestFromRoot({ root, node, nodes = [], consumers = [], fetch: fetch2, family = "pusd" }) {
18468
18469
  const r = await readPublished(node, root, "bridgeinfo", { fetch: fetch2 });
18469
18470
  const info = r.present && obj(r.value) ? r.value : {};
@@ -19385,11 +19386,21 @@ function ledgerBacking(graph2, id4) {
19385
19386
  unbacked: circulating > backing ? circulating - backing : 0n
19386
19387
  };
19387
19388
  }
19388
- async function readGraph(manifest, { fetch: fetch2, trustManifest = false, timing, account } = {}) {
19389
+ var DEFAULT_SETTLE2 = Object.freeze({ withinMs: 3e4, everyMs: 1e3 });
19390
+ function lagOf(graph2) {
19391
+ const ok = graph2.root.replicas.filter((r) => r.ok);
19392
+ const quorum = Math.floor(graph2.root.replicas.length / 2) + 1;
19393
+ const top = ok.length ? Math.max(...ok.map((r) => r.revision)) : null;
19394
+ const replicas = graph2.root.convergence === "catching-up" && ok.length >= quorum ? ok.filter((r) => r.revision < top).map((r) => r.node) : [];
19395
+ const ledgers = Object.values(graph2.ledgers).filter((l) => l.lane && l.registry && (l.lane.creditFloor < l.registry.creditSeq || l.lane.moveCreditFloor < l.registry.moveCreditSeq)).map((l) => l.id);
19396
+ return { replicas, ledgers };
19397
+ }
19398
+ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
19399
+ async function readGraph(manifest, { fetch: fetch2, trustManifest = false, timing, account, settle = DEFAULT_SETTLE2 } = {}) {
19389
19400
  const opts = { fetch: fetch2 };
19390
19401
  const replicaNodes = manifest.replicas?.length ? manifest.replicas : [manifest.root.node];
19391
19402
  const none = { present: false };
19392
- const replicas = Promise.all(replicaNodes.map(async (node) => {
19403
+ const readReplica = async (node) => {
19393
19404
  const [r, intents] = await Promise.all([
19394
19405
  readPublished2(node, manifest.root.id, "bridgeinfo", opts),
19395
19406
  account ? readPublished2(node, manifest.root.id, rootIntentKey(account), opts) : none
@@ -19399,25 +19410,41 @@ async function readGraph(manifest, { fetch: fetch2, trustManifest = false, timin
19399
19410
  rootIntents: intents.present ? obj2(intents.value) : {}
19400
19411
  } : null;
19401
19412
  return { node, info, error: r.error ?? (r.present ? void 0 : "absent") };
19402
- }));
19403
- const lanes = Promise.all(manifest.ledgers.map(async (l) => {
19413
+ };
19414
+ const readLane = async (l) => {
19404
19415
  const [r, p] = await Promise.all([
19405
19416
  readPublished2(l.node, l.id, "laneinfo", opts),
19406
19417
  readPublished2(l.node, l.id, "lanepeers", opts)
19407
19418
  ]);
19408
19419
  const laneinfo = r.present && r.value && typeof r.value === "object" ? r.value : null;
19409
19420
  const peers = p.present && obj2(p.value) ? p.value : void 0;
19410
- return [l.id, { laneinfo, peers, error: r.error ?? (r.present ? void 0 : "absent") }];
19411
- }));
19421
+ return { laneinfo, peers, error: r.error ?? (r.present ? void 0 : "absent") };
19422
+ };
19412
19423
  const consumers = Promise.all(manifest.consumers.map(async (c) => {
19413
19424
  const r = await readPublished2(c.node, c.id, "vaultinfo", opts);
19414
19425
  return [c.id, { vaultinfo: r.present ? r.value : null, error: r.error }];
19415
19426
  }));
19416
- return normalizeGraph(manifest, {
19417
- replicas: await replicas,
19418
- lanes: Object.fromEntries(await lanes),
19419
- consumers: Object.fromEntries(await consumers)
19420
- }, { trustManifest, timing });
19427
+ const [replicas, lanes] = await Promise.all([
19428
+ Promise.all(replicaNodes.map(readReplica)),
19429
+ Promise.all(manifest.ledgers.map(async (l) => [l.id, await readLane(l)])).then(Object.fromEntries)
19430
+ ]);
19431
+ const reads3 = { replicas, lanes, consumers: Object.fromEntries(await consumers) };
19432
+ let graph2 = normalizeGraph(manifest, reads3, { trustManifest, timing });
19433
+ const { withinMs = DEFAULT_SETTLE2.withinMs, everyMs = DEFAULT_SETTLE2.everyMs } = settle || { withinMs: 0 };
19434
+ const until2 = Date.now() + withinMs;
19435
+ for (let lag = lagOf(graph2); (lag.replicas.length || lag.ledgers.length) && Date.now() + everyMs <= until2; lag = lagOf(graph2)) {
19436
+ await sleep(everyMs);
19437
+ await Promise.all([
19438
+ ...lag.replicas.map(async (node) => {
19439
+ reads3.replicas[replicaNodes.indexOf(node)] = await readReplica(node);
19440
+ }),
19441
+ ...lag.ledgers.map(async (id4) => {
19442
+ reads3.lanes[id4] = await readLane(manifest.ledgers.find((l) => l.id === id4));
19443
+ })
19444
+ ]);
19445
+ graph2 = normalizeGraph(manifest, reads3, { trustManifest, timing });
19446
+ }
19447
+ return graph2;
19421
19448
  }
19422
19449
  async function manifestFromRoot2({ root, node, nodes = [], consumers = [], fetch: fetch2, family = "pusd" }) {
19423
19450
  const r = await readPublished2(node, root, "bridgeinfo", { fetch: fetch2 });
@@ -20186,7 +20213,7 @@ async function runConversion(graph2, plan, {
20186
20213
  prepare = (spec) => spec,
20187
20214
  onProgress = () => {
20188
20215
  },
20189
- sleep: sleep2 = (ms) => new Promise((r) => setTimeout(r, ms)),
20216
+ sleep: sleep3 = (ms) => new Promise((r) => setTimeout(r, ms)),
20190
20217
  now = () => Date.now(),
20191
20218
  pollMs = 3e3,
20192
20219
  fetch: fetch2
@@ -20219,7 +20246,7 @@ async function runConversion(graph2, plan, {
20219
20246
  current = null;
20220
20247
  while (!current) {
20221
20248
  if (now() > deadline) throw new Error(`${l.name}: step ${steps} of ${total} has not landed`);
20222
- await sleep2(pollMs);
20249
+ await sleep3(pollMs);
20223
20250
  const after = await read().catch(() => null);
20224
20251
  let certified = null;
20225
20252
  if (step.kind === "leave") {
@@ -20894,14 +20921,14 @@ function parseAmount(text, decimals = 6) {
20894
20921
  if (atoms2 <= 0n) throw new Error("Amount must be positive");
20895
20922
  return atoms2;
20896
20923
  }
20897
- var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
20924
+ var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
20898
20925
  async function until(what, read, done, timeoutMs = 6e5, everyMs = 3e3) {
20899
20926
  const deadline = Date.now() + timeoutMs;
20900
20927
  for (; ; ) {
20901
20928
  const value2 = await read().catch(() => null);
20902
20929
  if (value2 !== null && done(value2)) return value2;
20903
20930
  if (Date.now() > deadline) throw new Error(`Timed out after ${timeoutMs / 1e3} s waiting for ${what}`);
20904
- await sleep(everyMs);
20931
+ await sleep2(everyMs);
20905
20932
  }
20906
20933
  }
20907
20934
 
@@ -20915,7 +20942,7 @@ import { z as z2 } from "zod";
20915
20942
  // package.json
20916
20943
  var package_default = {
20917
20944
  name: "paralith-mcp",
20918
- version: "0.5.1",
20945
+ version: "0.5.2",
20919
20946
  description: "MCP server for Paralith on AO: an AI with one 24-word phrase plays Rune Realm, trades and bridges PUSD; plus paralith-bridge, the bridge operator CLI (TEST deployment).",
20920
20947
  license: "UNLICENSED",
20921
20948
  homepage: "https://docs.paralithmarkets.com/ai/mcp",
@@ -23087,7 +23114,7 @@ async function sendSpec(spec) {
23087
23114
  const reply = await px.hyperbeam.send(spec.tags, { process: spec.process, node: spec.node, composed: true });
23088
23115
  return JSON.stringify(reply ?? null);
23089
23116
  }
23090
- async function convertForConsumer({ g, me: me2, consumer, atoms: atoms2, send: send2, read, sleep: sleep2, now, fetch: fetch2 }) {
23117
+ async function convertForConsumer({ g, me: me2, consumer, atoms: atoms2, send: send2, read, sleep: sleep3, now, fetch: fetch2 }) {
23091
23118
  const want = BigInt(atoms2);
23092
23119
  const before = await read();
23093
23120
  const plan = planConversion(g, before, { consumer, amount: want, account: me2 });
@@ -23104,7 +23131,7 @@ async function convertForConsumer({ g, me: me2, consumer, atoms: atoms2, send: s
23104
23131
  roundTrip: eta(l.roundTripMs),
23105
23132
  signatures: l.signatures
23106
23133
  }));
23107
- const after = plan.legs.length ? (await runConversion(g, plan, { account: me2, send: send2, read, before, sleep: sleep2, now, fetch: fetch2 })).summary : before;
23134
+ const after = plan.legs.length ? (await runConversion(g, plan, { account: me2, send: send2, read, before, sleep: sleep3, now, fetch: fetch2 })).summary : before;
23108
23135
  const ledger = plan.trusted.map((id4) => ({ id: id4, amount: after.locations.find((l) => l.id === id4)?.amount ?? 0n })).filter((x) => x.amount >= want).sort((a, b) => b.amount > a.amount ? 1 : b.amount < a.amount ? -1 : 0)[0]?.id;
23109
23136
  if (!ledger) throw new Error("No single ledger the book trusts holds the whole amount.");
23110
23137
  return { ledger, moved };
@@ -23674,7 +23701,7 @@ function registerExchange(server) {
23674
23701
  if (!reply?.pending) return { ...await orderReport(t, m, wallets.ao.address, reply?.order?.order?.id ?? reply?.orderId), reply };
23675
23702
  let outcome = { state: "pending" };
23676
23703
  for (let i = 0; i < 60 && ["pending", "unconfirmed"].includes(outcome.state); i++) {
23677
- await sleep(2e3);
23704
+ await sleep2(2e3);
23678
23705
  outcome = await px.game.venue.readVenuePendingOutcome(t.process, wallets.ao.address, reply.pending).catch(() => outcome);
23679
23706
  }
23680
23707
  return {
@@ -23750,7 +23777,7 @@ function registerExchange(server) {
23750
23777
  if (pay?.token && pay.amount) {
23751
23778
  const goal = BigInt(pay.before ?? 0) + BigInt(pay.amount);
23752
23779
  let held = 0n;
23753
- for (const deadline = Date.now() + 12e4; Date.now() < deadline; await sleep(2e3)) {
23780
+ for (const deadline = Date.now() + 12e4; Date.now() < deadline; await sleep2(2e3)) {
23754
23781
  held = await tokenAtoms(pay.token, address).catch(() => 0n);
23755
23782
  if (held >= goal) return done({ wallet: formatAtoms2(held, t.den(asset)) });
23756
23783
  }
@@ -24058,7 +24085,7 @@ function registerVaults(server) {
24058
24085
  const position = async () => (await px.game.venue.readVenueVaultPositions(t.process, address).catch(() => ({})))?.[m.id]?.[strategy];
24059
24086
  const shares = async () => BigInt((await position())?.shares ?? 0);
24060
24087
  const grew = async (from) => {
24061
- for (const deadline = Date.now() + 2e4; Date.now() < deadline; await sleep(2e3)) if (await shares() > from) return true;
24088
+ for (const deadline = Date.now() + 2e4; Date.now() < deadline; await sleep2(2e3)) if (await shares() > from) return true;
24062
24089
  return false;
24063
24090
  };
24064
24091
  const deposit = () => px.game.venue.depositVenueVault(
package/dist/server.mjs CHANGED
@@ -1085,7 +1085,7 @@ async function postAdmitted(post, {
1085
1085
  onRefused,
1086
1086
  random = Math.random,
1087
1087
  now = Date.now,
1088
- sleep: sleep2 = pause
1088
+ sleep: sleep3 = pause
1089
1089
  } = {}) {
1090
1090
  const started = now();
1091
1091
  for (let attempt = 0; ; attempt += 1) {
@@ -1102,7 +1102,7 @@ async function postAdmitted(post, {
1102
1102
  } catch {
1103
1103
  }
1104
1104
  try {
1105
- await sleep2(wait2, signal);
1105
+ await sleep3(wait2, signal);
1106
1106
  } catch (reason) {
1107
1107
  throw new AdmissionWaitAborted(reason);
1108
1108
  }
@@ -7975,7 +7975,7 @@ function createParalith({ graph: graph2, signer, address, transport: own, env })
7975
7975
  contract: (contract, pid, at = node) => bind(contract, pid, contract, at)
7976
7976
  };
7977
7977
  }
7978
- var SLOT_RESULT_HEADERS, slotResultPath, nonEmpty, shouldPushOutbox, OUTBOX_DELIVERY_PATH, OUTBOX_DELIVERY_VALUE, deliveringNodes, OUTBOX_DELIVERY_RECHECK_MS, receiptSlot, receiptTerminal, receiptLookup, notDeliveringAnswer, DEFAULT_TRANSPORT_TIMEOUTS, PUSH_SOCKET_CAP_MS, PUSH_DISPATCHER, GAS_DEVICE, GAS_MAX_TAG_BYTES, GAS_MAX_FOR, ADDRESS, HTML, GasRequiredError, GAS_REQUIRED_EVENT, announced, cleanNode, GasReadError, GAS_LIMIT_MARGIN, ESTIMATE_MS, GAS_LIMIT_READ_MS, reads, ADMISSION_HEADER, ADMISSION_BACKOFF, ADMISSION_BUDGET_MS, pause, AdmissionWaitAborted, worker, nextId, waiting, abortError, wait, observed, REPROBE_EVERY, SHARD_BUCKETS2, SHARD_ID2, PID2, encoder2, AO_TAGS, NetworkError, AmbiguousWriteError, AdmissionRefusedError, RECONCILERS, OutboxDeliveryError, AcceptedWriteError, LATE_REPLY_SLOTS, LateReplyError, clean, BALANCE_READ_TIMING, READ_PATH, HTML_BODY, ABSENT_CONFIRMATIONS, STALE_AFTER_MISSES, STALE_FORGET_MS, PUSH_READ_TIMEOUT_MS, COMPUTE_READ, PUSH_READ, ReadTimeoutError, SIGNATURE_BYTES, openSignedScopes, synchronousSignedScope, CONFIRM_INTERVAL_MS, ASSET_CONFIRM_INTERVAL_MS, KNOWN_HEAD_FRESH_MS, REPLY_BUCKETS, COMPOSED_PUSH_PATH, COMPOSED_WRITE_TIMEOUT_MS, ComposedUnsupportedError, COMPOSED_FLAG, ERROR_CLASSES, SdkError, HTML2, cleanNode2, RESERVED, KEY, berries_exports, BERRIES, BERRY_LABELS, BERRY_ASSETS, BERRY_DENOMINATION, GAME_BRIDGE_ASSETS, isGameBridgeAsset, minWithdraw, isBerry, FAUCET_MIN, FAUCET_MAX, FAUCET_DAILY_BUDGET, PUSD_UNIT, DAY_MS, HOUR_MS, faucetDay, faucetHour, whole, TOKEN_BUCKETS2, tokenBalanceKey2, FOLDS_KEY2, FOLD_PRIME2, ONE_BUCKET2, vaultBalanceKey, pairBalanceKey, pairFillsKey, DepositQuarantinedError, ID2, ASSET_UNITS, TOKEN_OF_BERRY, whole2, createAssets, GENERATED_MONSTER_INDEX, authoredEntries, AUTHORED_BY_NO, ITEM_NAME, types_exports, GameError, where, COLLECTION_ART, COLLECTION_BERRY, LATE_CONFIRM_MS, LATE_POLL_MS, FLEET_PROTOCOL, PROCESS_ID, OPAQUE_ID, fleetSide, fleetActionId, EMPTY_BOOK, BRIDGE_ASSETS, sumOf, legacyItems, legacyFactions, RUNE_ATOMS, actionId, tags, LAYOUTS, objectOf, atomsOf, ID22, unwrap5, INTERVALS, DEFAULT_ORDER_DEADLINE_MS, LP_STRATEGIES, LP_FLEX, VAULT, SEPARATOR, ROW_MAX_AGE_MS, tags2, big, EMPTY_ROW_MAX_AGE_MS, isQuietRow, unwrap6, sequence, actionId2, vaultCache, freeOf, ShardedVenue, VaultAdmin, ID3, orderTags, PROCESS_ID2, EMPTY_STAKE, DAO_SIDES, BURN_ADDRESS, BPS, big2, shareFloor, percent, DAO_RULES, ADDRESS2, tags3, unwrap8, DaoClient, orderbook_exports, HISTORY_SCHEMA, ARCHIVE_PROTOCOL, HISTORY_BLOOM_K, DEFAULT_GATEWAY, tagKey, B64, SIG_LAYOUT, B64URL, tagMap, int, ARCHIVE_QUERY, IDS_QUERY, WRAPPED_QUERY, CACHE_LIMIT, SEPARATOR2, DB_NAME, STORE, TradeCache, integer, validPoint, annualise, quoteValue, unitAtoms, lotsPerUnit, FAUCET_STANDARD, FAUCET_SCHEDULE, FAUCET_MIN2, FAUCET_MAX2, FAUCET_DAILY_BUDGET2, PUSD_UNIT2, DAY_MS2, HOUR_MS2, utf8, faucetDay2, faucetHour2, whole3, ID4, tags4, unwrap9, PairClient, PROCESS_ID3, catalogReads, sequence2, actionId3, messageTags, unwrap10, VenueClient, createVenueClient, MAX_QUANTITY, DIGITS, ID5, isId, HTML3, cleanNode3, SCHEMA, DOMAIN, fail, crypto22, hasHexBuiltin, hexes, asciis, Hash, HashMD, SHA512_IV, U32_MASK64, _32n, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, add3L, add3H, add4L, add4H, add5L, add5H, K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA512, sha512, _0n, _1n, isPosBig, bitMask, notImplemented, _0n2, _1n2, _2n, _3n, _4n, _5n, _7n, _8n, _9n, _16n, isNegativeLE, FIELD_FIELDS, _0n3, _1n3, pointPrecomputes, pointWindowSizes, wNAF, _0n4, _1n4, _2n2, _8n2, PrimeEdwardsPoint, _0n5, _1n5, _2n3, _3n2, _5n2, _8n3, ed25519_CURVE_p, ed25519_CURVE, ED25519_SQRT_M1, Fp, Fn, ed25519Defaults, ed25519, SQRT_M1, SQRT_AD_MINUS_ONE, INVSQRT_A_MINUS_D, ONE_MINUS_D_SQ, D_MINUS_ONE_SQ, invertSqrt, MAX_255B, bytes255ToNumberLE, _RistrettoPoint, utf82, b64uDecode, b64uEncode, join, SIG_TYPES, tagOf, DEFAULT_TIMING, obj, STATES, LABEL, CLASSES, RESERVED2, squash, id2, toTags2, CHAINS, ACTIONS, INTEGER_FIELDS, CONVERSION_LABEL, RANK, MOVE_LABEL, utf83, ROOT_ACTIONS, configured;
7978
+ var SLOT_RESULT_HEADERS, slotResultPath, nonEmpty, shouldPushOutbox, OUTBOX_DELIVERY_PATH, OUTBOX_DELIVERY_VALUE, deliveringNodes, OUTBOX_DELIVERY_RECHECK_MS, receiptSlot, receiptTerminal, receiptLookup, notDeliveringAnswer, DEFAULT_TRANSPORT_TIMEOUTS, PUSH_SOCKET_CAP_MS, PUSH_DISPATCHER, GAS_DEVICE, GAS_MAX_TAG_BYTES, GAS_MAX_FOR, ADDRESS, HTML, GasRequiredError, GAS_REQUIRED_EVENT, announced, cleanNode, GasReadError, GAS_LIMIT_MARGIN, ESTIMATE_MS, GAS_LIMIT_READ_MS, reads, ADMISSION_HEADER, ADMISSION_BACKOFF, ADMISSION_BUDGET_MS, pause, AdmissionWaitAborted, worker, nextId, waiting, abortError, wait, observed, REPROBE_EVERY, SHARD_BUCKETS2, SHARD_ID2, PID2, encoder2, AO_TAGS, NetworkError, AmbiguousWriteError, AdmissionRefusedError, RECONCILERS, OutboxDeliveryError, AcceptedWriteError, LATE_REPLY_SLOTS, LateReplyError, clean, BALANCE_READ_TIMING, READ_PATH, HTML_BODY, ABSENT_CONFIRMATIONS, STALE_AFTER_MISSES, STALE_FORGET_MS, PUSH_READ_TIMEOUT_MS, COMPUTE_READ, PUSH_READ, ReadTimeoutError, SIGNATURE_BYTES, openSignedScopes, synchronousSignedScope, CONFIRM_INTERVAL_MS, ASSET_CONFIRM_INTERVAL_MS, KNOWN_HEAD_FRESH_MS, REPLY_BUCKETS, COMPOSED_PUSH_PATH, COMPOSED_WRITE_TIMEOUT_MS, ComposedUnsupportedError, COMPOSED_FLAG, ERROR_CLASSES, SdkError, HTML2, cleanNode2, RESERVED, KEY, berries_exports, BERRIES, BERRY_LABELS, BERRY_ASSETS, BERRY_DENOMINATION, GAME_BRIDGE_ASSETS, isGameBridgeAsset, minWithdraw, isBerry, FAUCET_MIN, FAUCET_MAX, FAUCET_DAILY_BUDGET, PUSD_UNIT, DAY_MS, HOUR_MS, faucetDay, faucetHour, whole, TOKEN_BUCKETS2, tokenBalanceKey2, FOLDS_KEY2, FOLD_PRIME2, ONE_BUCKET2, vaultBalanceKey, pairBalanceKey, pairFillsKey, DepositQuarantinedError, ID2, ASSET_UNITS, TOKEN_OF_BERRY, whole2, createAssets, GENERATED_MONSTER_INDEX, authoredEntries, AUTHORED_BY_NO, ITEM_NAME, types_exports, GameError, where, COLLECTION_ART, COLLECTION_BERRY, LATE_CONFIRM_MS, LATE_POLL_MS, FLEET_PROTOCOL, PROCESS_ID, OPAQUE_ID, fleetSide, fleetActionId, EMPTY_BOOK, BRIDGE_ASSETS, sumOf, legacyItems, legacyFactions, RUNE_ATOMS, actionId, tags, LAYOUTS, objectOf, atomsOf, ID22, unwrap5, INTERVALS, DEFAULT_ORDER_DEADLINE_MS, LP_STRATEGIES, LP_FLEX, VAULT, SEPARATOR, ROW_MAX_AGE_MS, tags2, big, EMPTY_ROW_MAX_AGE_MS, isQuietRow, unwrap6, sequence, actionId2, vaultCache, freeOf, ShardedVenue, VaultAdmin, ID3, orderTags, PROCESS_ID2, EMPTY_STAKE, DAO_SIDES, BURN_ADDRESS, BPS, big2, shareFloor, percent, DAO_RULES, ADDRESS2, tags3, unwrap8, DaoClient, orderbook_exports, HISTORY_SCHEMA, ARCHIVE_PROTOCOL, HISTORY_BLOOM_K, DEFAULT_GATEWAY, tagKey, B64, SIG_LAYOUT, B64URL, tagMap, int, ARCHIVE_QUERY, IDS_QUERY, WRAPPED_QUERY, CACHE_LIMIT, SEPARATOR2, DB_NAME, STORE, TradeCache, integer, validPoint, annualise, quoteValue, unitAtoms, lotsPerUnit, FAUCET_STANDARD, FAUCET_SCHEDULE, FAUCET_MIN2, FAUCET_MAX2, FAUCET_DAILY_BUDGET2, PUSD_UNIT2, DAY_MS2, HOUR_MS2, utf8, faucetDay2, faucetHour2, whole3, ID4, tags4, unwrap9, PairClient, PROCESS_ID3, catalogReads, sequence2, actionId3, messageTags, unwrap10, VenueClient, createVenueClient, MAX_QUANTITY, DIGITS, ID5, isId, HTML3, cleanNode3, SCHEMA, DOMAIN, fail, crypto22, hasHexBuiltin, hexes, asciis, Hash, HashMD, SHA512_IV, U32_MASK64, _32n, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, add3L, add3H, add4L, add4H, add5L, add5H, K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA512, sha512, _0n, _1n, isPosBig, bitMask, notImplemented, _0n2, _1n2, _2n, _3n, _4n, _5n, _7n, _8n, _9n, _16n, isNegativeLE, FIELD_FIELDS, _0n3, _1n3, pointPrecomputes, pointWindowSizes, wNAF, _0n4, _1n4, _2n2, _8n2, PrimeEdwardsPoint, _0n5, _1n5, _2n3, _3n2, _5n2, _8n3, ed25519_CURVE_p, ed25519_CURVE, ED25519_SQRT_M1, Fp, Fn, ed25519Defaults, ed25519, SQRT_M1, SQRT_AD_MINUS_ONE, INVSQRT_A_MINUS_D, ONE_MINUS_D_SQ, D_MINUS_ONE_SQ, invertSqrt, MAX_255B, bytes255ToNumberLE, _RistrettoPoint, utf82, b64uDecode, b64uEncode, join, SIG_TYPES, tagOf, DEFAULT_TIMING, obj, DEFAULT_SETTLE, STATES, LABEL, CLASSES, RESERVED2, squash, id2, toTags2, CHAINS, ACTIONS, INTEGER_FIELDS, CONVERSION_LABEL, RANK, MOVE_LABEL, utf83, ROOT_ACTIONS, configured;
7979
7979
  var init_paralith = __esm({
7980
7980
  "../sdk/dist/paralith.js"() {
7981
7981
  "use strict";
@@ -18960,6 +18960,7 @@ var init_paralith = __esm({
18960
18960
  attestorRelay: 3e4
18961
18961
  });
18962
18962
  obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : null;
18963
+ DEFAULT_SETTLE = Object.freeze({ withinMs: 3e4, everyMs: 1e3 });
18963
18964
  STATES = Object.freeze([
18964
18965
  "active",
18965
18966
  "catching-up",
@@ -19621,11 +19622,19 @@ function ledgerBacking(graph2, id4) {
19621
19622
  unbacked: circulating > backing ? circulating - backing : 0n
19622
19623
  };
19623
19624
  }
19624
- async function readGraph(manifest, { fetch: fetch2, trustManifest = false, timing, account } = {}) {
19625
+ function lagOf(graph2) {
19626
+ const ok = graph2.root.replicas.filter((r) => r.ok);
19627
+ const quorum = Math.floor(graph2.root.replicas.length / 2) + 1;
19628
+ const top = ok.length ? Math.max(...ok.map((r) => r.revision)) : null;
19629
+ const replicas = graph2.root.convergence === "catching-up" && ok.length >= quorum ? ok.filter((r) => r.revision < top).map((r) => r.node) : [];
19630
+ const ledgers = Object.values(graph2.ledgers).filter((l) => l.lane && l.registry && (l.lane.creditFloor < l.registry.creditSeq || l.lane.moveCreditFloor < l.registry.moveCreditSeq)).map((l) => l.id);
19631
+ return { replicas, ledgers };
19632
+ }
19633
+ async function readGraph(manifest, { fetch: fetch2, trustManifest = false, timing, account, settle = DEFAULT_SETTLE2 } = {}) {
19625
19634
  const opts = { fetch: fetch2 };
19626
19635
  const replicaNodes = manifest.replicas?.length ? manifest.replicas : [manifest.root.node];
19627
19636
  const none = { present: false };
19628
- const replicas = Promise.all(replicaNodes.map(async (node) => {
19637
+ const readReplica = async (node) => {
19629
19638
  const [r, intents] = await Promise.all([
19630
19639
  readPublished2(node, manifest.root.id, "bridgeinfo", opts),
19631
19640
  account ? readPublished2(node, manifest.root.id, rootIntentKey(account), opts) : none
@@ -19635,25 +19644,41 @@ async function readGraph(manifest, { fetch: fetch2, trustManifest = false, timin
19635
19644
  rootIntents: intents.present ? obj2(intents.value) : {}
19636
19645
  } : null;
19637
19646
  return { node, info, error: r.error ?? (r.present ? void 0 : "absent") };
19638
- }));
19639
- const lanes = Promise.all(manifest.ledgers.map(async (l) => {
19647
+ };
19648
+ const readLane = async (l) => {
19640
19649
  const [r, p] = await Promise.all([
19641
19650
  readPublished2(l.node, l.id, "laneinfo", opts),
19642
19651
  readPublished2(l.node, l.id, "lanepeers", opts)
19643
19652
  ]);
19644
19653
  const laneinfo = r.present && r.value && typeof r.value === "object" ? r.value : null;
19645
19654
  const peers = p.present && obj2(p.value) ? p.value : void 0;
19646
- return [l.id, { laneinfo, peers, error: r.error ?? (r.present ? void 0 : "absent") }];
19647
- }));
19655
+ return { laneinfo, peers, error: r.error ?? (r.present ? void 0 : "absent") };
19656
+ };
19648
19657
  const consumers = Promise.all(manifest.consumers.map(async (c) => {
19649
19658
  const r = await readPublished2(c.node, c.id, "vaultinfo", opts);
19650
19659
  return [c.id, { vaultinfo: r.present ? r.value : null, error: r.error }];
19651
19660
  }));
19652
- return normalizeGraph(manifest, {
19653
- replicas: await replicas,
19654
- lanes: Object.fromEntries(await lanes),
19655
- consumers: Object.fromEntries(await consumers)
19656
- }, { trustManifest, timing });
19661
+ const [replicas, lanes] = await Promise.all([
19662
+ Promise.all(replicaNodes.map(readReplica)),
19663
+ Promise.all(manifest.ledgers.map(async (l) => [l.id, await readLane(l)])).then(Object.fromEntries)
19664
+ ]);
19665
+ const reads3 = { replicas, lanes, consumers: Object.fromEntries(await consumers) };
19666
+ let graph2 = normalizeGraph(manifest, reads3, { trustManifest, timing });
19667
+ const { withinMs = DEFAULT_SETTLE2.withinMs, everyMs = DEFAULT_SETTLE2.everyMs } = settle || { withinMs: 0 };
19668
+ const until2 = Date.now() + withinMs;
19669
+ for (let lag = lagOf(graph2); (lag.replicas.length || lag.ledgers.length) && Date.now() + everyMs <= until2; lag = lagOf(graph2)) {
19670
+ await sleep(everyMs);
19671
+ await Promise.all([
19672
+ ...lag.replicas.map(async (node) => {
19673
+ reads3.replicas[replicaNodes.indexOf(node)] = await readReplica(node);
19674
+ }),
19675
+ ...lag.ledgers.map(async (id4) => {
19676
+ reads3.lanes[id4] = await readLane(manifest.ledgers.find((l) => l.id === id4));
19677
+ })
19678
+ ]);
19679
+ graph2 = normalizeGraph(manifest, reads3, { trustManifest, timing });
19680
+ }
19681
+ return graph2;
19657
19682
  }
19658
19683
  async function manifestFromRoot2({ root, node, nodes = [], consumers = [], fetch: fetch2, family = "pusd" }) {
19659
19684
  const r = await readPublished2(node, root, "bridgeinfo", { fetch: fetch2 });
@@ -19691,7 +19716,7 @@ async function manifestFromRoot2({ root, node, nodes = [], consumers = [], fetch
19691
19716
  consumers: consumers.map((c) => ({ ...c, trusts: [] }))
19692
19717
  });
19693
19718
  }
19694
- var DEFAULT_TIMING2, big3, obj2;
19719
+ var DEFAULT_TIMING2, big3, obj2, DEFAULT_SETTLE2, sleep;
19695
19720
  var init_graph = __esm({
19696
19721
  "../hypertoken/src/graph.mjs"() {
19697
19722
  init_read();
@@ -19708,6 +19733,8 @@ var init_graph = __esm({
19708
19733
  });
19709
19734
  big3 = (v, what) => atomsOr0(v, what);
19710
19735
  obj2 = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : null;
19736
+ DEFAULT_SETTLE2 = Object.freeze({ withinMs: 3e4, everyMs: 1e3 });
19737
+ sleep = (ms) => new Promise((r) => setTimeout(r, ms));
19711
19738
  }
19712
19739
  });
19713
19740
 
@@ -20456,7 +20483,7 @@ async function runConversion(graph2, plan, {
20456
20483
  prepare = (spec) => spec,
20457
20484
  onProgress = () => {
20458
20485
  },
20459
- sleep: sleep2 = (ms) => new Promise((r) => setTimeout(r, ms)),
20486
+ sleep: sleep3 = (ms) => new Promise((r) => setTimeout(r, ms)),
20460
20487
  now = () => Date.now(),
20461
20488
  pollMs = 3e3,
20462
20489
  fetch: fetch2
@@ -20489,7 +20516,7 @@ async function runConversion(graph2, plan, {
20489
20516
  current = null;
20490
20517
  while (!current) {
20491
20518
  if (now() > deadline) throw new Error(`${l.name}: step ${steps} of ${total} has not landed`);
20492
- await sleep2(pollMs);
20519
+ await sleep3(pollMs);
20493
20520
  const after = await read().catch(() => null);
20494
20521
  let certified = null;
20495
20522
  if (step.kind === "leave") {
@@ -21158,7 +21185,7 @@ __export(runtime_exports, {
21158
21185
  readKey: () => readKey2,
21159
21186
  runtime: () => runtime,
21160
21187
  sdk: () => sdk,
21161
- sleep: () => sleep,
21188
+ sleep: () => sleep2,
21162
21189
  tokenAtoms: () => tokenAtoms,
21163
21190
  until: () => until
21164
21191
  });
@@ -21278,10 +21305,10 @@ async function until(what, read, done, timeoutMs = 6e5, everyMs = 3e3) {
21278
21305
  const value2 = await read().catch(() => null);
21279
21306
  if (value2 !== null && done(value2)) return value2;
21280
21307
  if (Date.now() > deadline) throw new Error(`Timed out after ${timeoutMs / 1e3} s waiting for ${what}`);
21281
- await sleep(everyMs);
21308
+ await sleep2(everyMs);
21282
21309
  }
21283
21310
  }
21284
- var HERE, DIST, graph, NODE, SHARDS, gameFor, chains, PROCESS_ALIASES, TOKENS, discovered, TOKEN_DECIMALS, DAOS, ID7, READ_ONLY, loaded, sdk, HTML5, sleep;
21311
+ var HERE, DIST, graph, NODE, SHARDS, gameFor, chains, PROCESS_ALIASES, TOKENS, discovered, TOKEN_DECIMALS, DAOS, ID7, READ_ONLY, loaded, sdk, HTML5, sleep2;
21285
21312
  var init_runtime = __esm({
21286
21313
  "src/runtime.mjs"() {
21287
21314
  init_ans104();
@@ -21309,7 +21336,7 @@ var init_runtime = __esm({
21309
21336
  loaded = null;
21310
21337
  sdk = () => runtime().then(({ px }) => px);
21311
21338
  HTML5 = /^\s*(?:<!doctype\s+html|<html|<head|<body)/i;
21312
- sleep = (ms) => new Promise((r) => setTimeout(r, ms));
21339
+ sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
21313
21340
  }
21314
21341
  });
21315
21342
 
@@ -21319,7 +21346,7 @@ var init_package = __esm({
21319
21346
  "package.json"() {
21320
21347
  package_default = {
21321
21348
  name: "paralith-mcp",
21322
- version: "0.5.1",
21349
+ version: "0.5.2",
21323
21350
  description: "MCP server for Paralith on AO: an AI with one 24-word phrase plays Rune Realm, trades and bridges PUSD; plus paralith-bridge, the bridge operator CLI (TEST deployment).",
21324
21351
  license: "UNLICENSED",
21325
21352
  homepage: "https://docs.paralithmarkets.com/ai/mcp",
@@ -23543,7 +23570,7 @@ async function sendSpec(spec) {
23543
23570
  const reply = await px.hyperbeam.send(spec.tags, { process: spec.process, node: spec.node, composed: true });
23544
23571
  return JSON.stringify(reply ?? null);
23545
23572
  }
23546
- async function convertForConsumer({ g, me: me2, consumer, atoms: atoms2, send: send2, read, sleep: sleep2, now, fetch: fetch2 }) {
23573
+ async function convertForConsumer({ g, me: me2, consumer, atoms: atoms2, send: send2, read, sleep: sleep3, now, fetch: fetch2 }) {
23547
23574
  const want = BigInt(atoms2);
23548
23575
  const before = await read();
23549
23576
  const plan = planConversion(g, before, { consumer, amount: want, account: me2 });
@@ -23560,7 +23587,7 @@ async function convertForConsumer({ g, me: me2, consumer, atoms: atoms2, send: s
23560
23587
  roundTrip: eta(l.roundTripMs),
23561
23588
  signatures: l.signatures
23562
23589
  }));
23563
- const after = plan.legs.length ? (await runConversion(g, plan, { account: me2, send: send2, read, before, sleep: sleep2, now, fetch: fetch2 })).summary : before;
23590
+ const after = plan.legs.length ? (await runConversion(g, plan, { account: me2, send: send2, read, before, sleep: sleep3, now, fetch: fetch2 })).summary : before;
23564
23591
  const ledger = plan.trusted.map((id4) => ({ id: id4, amount: after.locations.find((l) => l.id === id4)?.amount ?? 0n })).filter((x) => x.amount >= want).sort((a, b) => b.amount > a.amount ? 1 : b.amount < a.amount ? -1 : 0)[0]?.id;
23565
23592
  if (!ledger) throw new Error("No single ledger the book trusts holds the whole amount.");
23566
23593
  return { ledger, moved };
@@ -24144,7 +24171,7 @@ function registerExchange(server) {
24144
24171
  if (!reply?.pending) return { ...await orderReport(t, m, wallets.ao.address, reply?.order?.order?.id ?? reply?.orderId), reply };
24145
24172
  let outcome = { state: "pending" };
24146
24173
  for (let i = 0; i < 60 && ["pending", "unconfirmed"].includes(outcome.state); i++) {
24147
- await sleep(2e3);
24174
+ await sleep2(2e3);
24148
24175
  outcome = await px.game.venue.readVenuePendingOutcome(t.process, wallets.ao.address, reply.pending).catch(() => outcome);
24149
24176
  }
24150
24177
  return {
@@ -24220,7 +24247,7 @@ function registerExchange(server) {
24220
24247
  if (pay?.token && pay.amount) {
24221
24248
  const goal = BigInt(pay.before ?? 0) + BigInt(pay.amount);
24222
24249
  let held = 0n;
24223
- for (const deadline = Date.now() + 12e4; Date.now() < deadline; await sleep(2e3)) {
24250
+ for (const deadline = Date.now() + 12e4; Date.now() < deadline; await sleep2(2e3)) {
24224
24251
  held = await tokenAtoms(pay.token, address).catch(() => 0n);
24225
24252
  if (held >= goal) return done({ wallet: formatAtoms2(held, t.den(asset)) });
24226
24253
  }
@@ -24552,7 +24579,7 @@ function registerVaults(server) {
24552
24579
  const position = async () => (await px.game.venue.readVenueVaultPositions(t.process, address).catch(() => ({})))?.[m.id]?.[strategy];
24553
24580
  const shares = async () => BigInt((await position())?.shares ?? 0);
24554
24581
  const grew = async (from) => {
24555
- for (const deadline = Date.now() + 2e4; Date.now() < deadline; await sleep(2e3)) if (await shares() > from) return true;
24582
+ for (const deadline = Date.now() + 2e4; Date.now() < deadline; await sleep2(2e3)) if (await shares() > from) return true;
24556
24583
  return false;
24557
24584
  };
24558
24585
  const deposit = () => px.game.venue.depositVenueVault(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paralith-mcp",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "MCP server for Paralith on AO: an AI with one 24-word phrase plays Rune Realm, trades and bridges PUSD; plus paralith-bridge, the bridge operator CLI (TEST deployment).",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://docs.paralithmarkets.com/ai/mcp",