paralith-mcp 0.4.7 → 0.4.8
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 +53 -52
- package/dist/bridge.mjs +462 -22
- package/dist/chains.json +14 -72
- package/dist/client.mjs +9249 -8777
- package/dist/graph.json +101 -24
- package/dist/http.mjs +291 -157
- package/dist/server.mjs +309 -163
- package/package.json +52 -52
package/dist/http.mjs
CHANGED
|
@@ -210,21 +210,102 @@ function saveAgent(name, entry) {
|
|
|
210
210
|
return all[name];
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
// ../rune-ao/src/lib/shard-route.mjs
|
|
214
|
+
var SHARD_BUCKETS = 64;
|
|
215
|
+
var SHARD_ID = /^[a-z0-9]{1,8}$/;
|
|
216
|
+
var PID = /^[A-Za-z0-9_-]{43}$/;
|
|
217
|
+
var encoder = new TextEncoder();
|
|
218
|
+
function shardBucket(address) {
|
|
219
|
+
if (typeof address !== "string" || address === "") return null;
|
|
220
|
+
let h = 0;
|
|
221
|
+
for (const byte of encoder.encode(address)) h = (h * 31 + byte) % 2147483647;
|
|
222
|
+
return h % SHARD_BUCKETS;
|
|
223
|
+
}
|
|
224
|
+
function evenShardBuckets(ids) {
|
|
225
|
+
return Array.from(
|
|
226
|
+
{ length: SHARD_BUCKETS },
|
|
227
|
+
(_, bucket) => ids[Math.floor(bucket * ids.length / SHARD_BUCKETS)]
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
function shardMap(processes = {}) {
|
|
231
|
+
const game = processes.game || "";
|
|
232
|
+
const shards = { ...processes.shards || {} };
|
|
233
|
+
const ids = Object.keys(shards).sort();
|
|
234
|
+
const market = processes.market || "";
|
|
235
|
+
const lobby = processes.lobby || "";
|
|
236
|
+
if (ids.length === 0) {
|
|
237
|
+
return { game, sharded: false, shards: {}, buckets: [], pids: game ? [game] : [], market, lobby };
|
|
238
|
+
}
|
|
239
|
+
for (const id of ids) {
|
|
240
|
+
if (!SHARD_ID.test(id) || !PID.test(shards[id])) {
|
|
241
|
+
throw new Error(`graph shard ${JSON.stringify(id)} is not <shard id>: <process id>`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const buckets = Array.isArray(processes.shardBuckets) && processes.shardBuckets.length ? [...processes.shardBuckets] : evenShardBuckets(ids);
|
|
245
|
+
if (buckets.length !== SHARD_BUCKETS || !buckets.every((id) => shards[id])) {
|
|
246
|
+
throw new Error(`graph shardBuckets must be ${SHARD_BUCKETS} ids from shards`);
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
game: game || shards[buckets[0]],
|
|
250
|
+
sharded: true,
|
|
251
|
+
shards,
|
|
252
|
+
buckets,
|
|
253
|
+
pids: ids.map((id) => shards[id]),
|
|
254
|
+
market,
|
|
255
|
+
lobby
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function shardOf(map, address) {
|
|
259
|
+
if (!map?.sharded) return "";
|
|
260
|
+
const bucket = shardBucket(address);
|
|
261
|
+
return bucket === null ? "" : map.buckets[bucket];
|
|
262
|
+
}
|
|
263
|
+
function processFor(map, address) {
|
|
264
|
+
const id = shardOf(map, address);
|
|
265
|
+
return id ? map.shards[id] : map?.game || "";
|
|
266
|
+
}
|
|
267
|
+
function gameTargets(map) {
|
|
268
|
+
if (!map?.sharded) return map?.game ? [{ shard: "", process: map.game }] : [];
|
|
269
|
+
return Object.keys(map.shards).sort().map((shard) => ({ shard, process: map.shards[shard] }));
|
|
270
|
+
}
|
|
271
|
+
async function fanOut(map, attempt) {
|
|
272
|
+
return Promise.all(gameTargets(map).map(async (target) => {
|
|
273
|
+
try {
|
|
274
|
+
return { ...target, value: await attempt(target) };
|
|
275
|
+
} catch (error) {
|
|
276
|
+
return { ...target, error: error instanceof Error ? error.message : String(error) };
|
|
277
|
+
}
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
|
|
213
281
|
// src/runtime.mjs
|
|
214
282
|
var HERE = path3.dirname(fileURLToPath(import.meta.url));
|
|
215
283
|
var DIST = fs3.existsSync(path3.join(HERE, "graph.json")) ? HERE : path3.join(HERE, "..", "dist");
|
|
216
284
|
var graph = JSON.parse(fs3.readFileSync(path3.join(DIST, "graph.json"), "utf8"));
|
|
217
285
|
var NODE = graph.node.replace(/\/$/, "");
|
|
286
|
+
var SHARDS = shardMap(graph.processes);
|
|
287
|
+
var gameFor = (address) => processFor(SHARDS, address) || graph.processes.game;
|
|
218
288
|
var chains = JSON.parse(fs3.readFileSync(path3.join(DIST, "chains.json"), "utf8"));
|
|
219
289
|
var PROCESS_ALIASES = {
|
|
220
290
|
game: graph.processes.game,
|
|
221
291
|
rune: graph.processes.rune,
|
|
222
292
|
pusd: graph.processes.pusd,
|
|
223
293
|
...graph.processes.dao ? { dao: graph.processes.dao } : {},
|
|
224
|
-
|
|
294
|
+
...graph.processes.gold ? { gold: graph.processes.gold } : {},
|
|
225
295
|
"token-venue": graph.processes.externalVenue,
|
|
226
|
-
...Object.fromEntries(Object.entries(graph.processes.
|
|
296
|
+
...Object.fromEntries(Object.entries(graph.processes.berries ?? {}).filter(([, v]) => v).map(([k, v]) => [`${k}-token`, v])),
|
|
297
|
+
// Sharded: each shard by its id (`game` is bucket 0's), the market, the lobby.
|
|
298
|
+
...Object.fromEntries(Object.entries(graph.processes.shards ?? {}).map(([id, pid]) => [`game-${id}`, pid])),
|
|
299
|
+
...graph.processes.market ? { market: graph.processes.market } : {},
|
|
300
|
+
...graph.processes.lobby ? { lobby: graph.processes.lobby } : {}
|
|
227
301
|
};
|
|
302
|
+
var TOKENS = Object.fromEntries(Object.entries({
|
|
303
|
+
rune: graph.processes.rune,
|
|
304
|
+
gold: graph.processes.gold,
|
|
305
|
+
pusd: graph.processes.pusd,
|
|
306
|
+
...Object.fromEntries(Object.entries(graph.processes.berries ?? {}).map(([k, v]) => [`${k}_berry`, v]))
|
|
307
|
+
}).filter(([, id]) => id));
|
|
308
|
+
var TOKEN_DECIMALS = { gold: 2 };
|
|
228
309
|
var ID = /^[A-Za-z0-9_-]{43}$/;
|
|
229
310
|
function processId(nameOrId) {
|
|
230
311
|
if (ID.test(nameOrId)) return nameOrId;
|
|
@@ -249,8 +330,14 @@ function runtime() {
|
|
|
249
330
|
}
|
|
250
331
|
var HTML = /^\s*(?:<!doctype\s+html|<html|<head|<body)/i;
|
|
251
332
|
async function readKey(process2, key, node = NODE) {
|
|
333
|
+
let pid = processId(process2);
|
|
334
|
+
if (SHARDS.sharded && pid === graph.processes.game) {
|
|
335
|
+
if (key.startsWith("player-")) pid = gameFor(key.slice(7));
|
|
336
|
+
else if (SHARDS.market && /^market/.test(key)) pid = SHARDS.market;
|
|
337
|
+
else if (SHARDS.lobby && key === "challenges") pid = SHARDS.lobby;
|
|
338
|
+
}
|
|
252
339
|
const res = await fetch(
|
|
253
|
-
`${node}/${
|
|
340
|
+
`${node}/${pid}~process@1.0/now/${key}`,
|
|
254
341
|
{ headers: { accept: "text/plain" }, signal: AbortSignal.timeout(6e4) }
|
|
255
342
|
);
|
|
256
343
|
if (res.status === 404) return null;
|
|
@@ -308,7 +395,7 @@ import { z } from "zod";
|
|
|
308
395
|
// package.json
|
|
309
396
|
var package_default = {
|
|
310
397
|
name: "paralith-mcp",
|
|
311
|
-
version: "0.4.
|
|
398
|
+
version: "0.4.8",
|
|
312
399
|
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).",
|
|
313
400
|
license: "UNLICENSED",
|
|
314
401
|
homepage: "https://docs.paralithmarkets.com/ai/mcp",
|
|
@@ -544,7 +631,8 @@ function hunt(run) {
|
|
|
544
631
|
// src/game.mjs
|
|
545
632
|
var FACTIONS = ["Sky Nomads", "Aqua Guardians", "Inferno Blades", "Stone Titans"];
|
|
546
633
|
var BERRIES = ["air_berry", "fire_berry", "rock_berry", "water_berry"];
|
|
547
|
-
var SHOP_ITEMS = [...BERRIES, "
|
|
634
|
+
var SHOP_ITEMS = [...BERRIES, "rune"];
|
|
635
|
+
var ASSET = z2.enum(["rune", "gold", ...BERRIES]);
|
|
548
636
|
async function me() {
|
|
549
637
|
const { api, wallets } = await runtime();
|
|
550
638
|
return { api, address: wallets?.ao.address };
|
|
@@ -560,9 +648,17 @@ async function player2(address) {
|
|
|
560
648
|
async function findBattle(id) {
|
|
561
649
|
const fleet = await readKey("game", "battlefleet").catch(() => null);
|
|
562
650
|
const workers = (fleet?.workers ?? []).map((w) => w.workerProcessId).filter(Boolean);
|
|
563
|
-
const
|
|
651
|
+
const games = SHARDS.sharded ? SHARDS.pids : ["game"];
|
|
652
|
+
const found = await Promise.all([...games.map((g) => readKey(g, `battle-op-${id}`)), ...workers.map((w) => readKey(w, `battle-${id}`))].map((read) => read.catch(() => null)));
|
|
564
653
|
return found.find((b) => b && typeof b === "object") ?? null;
|
|
565
654
|
}
|
|
655
|
+
async function perShard(read) {
|
|
656
|
+
return Object.fromEntries((await fanOut(SHARDS, ({ process: process2 }) => read(process2))).map(({ shard, value, error }) => [shard, value ?? { error }]));
|
|
657
|
+
}
|
|
658
|
+
function arenaTiers(api, who) {
|
|
659
|
+
if (who || !SHARDS.sharded) return api.readArenaTiers({ process: gameFor(who ?? "") });
|
|
660
|
+
return perShard((process2) => api.readArenaTiers({ process: process2 }));
|
|
661
|
+
}
|
|
566
662
|
var seenBy = (b, address) => b && typeof b === "object" ? Object.defineProperty(b, "viewer", { value: address, enumerable: false, configurable: true }) : b;
|
|
567
663
|
function registerGame(server) {
|
|
568
664
|
tool(
|
|
@@ -584,31 +680,27 @@ function registerGame(server) {
|
|
|
584
680
|
"game_catalog",
|
|
585
681
|
"The game rules as data: activity costs/gains, arena terms, element effectiveness, free moves (Rally, Mend), hunt capture odds, items, level-up rules and every move pool. Free, unsigned.",
|
|
586
682
|
{},
|
|
587
|
-
async () =>
|
|
588
|
-
const catalog = await (await me()).api.readCatalog();
|
|
589
|
-
if (catalog?.levelUp) {
|
|
590
|
-
catalog.levelUp = { ...catalog.levelUp, costDivisor: 32, cost: "ceil(targetLevel^2 / 32) Rune" };
|
|
591
|
-
}
|
|
592
|
-
return catalog;
|
|
593
|
-
},
|
|
683
|
+
async () => (await me()).api.readCatalog(),
|
|
594
684
|
READ
|
|
595
685
|
);
|
|
596
686
|
tool(
|
|
597
687
|
server,
|
|
598
688
|
"game_world",
|
|
599
|
-
"Shared world state: access rules, factions, arena difficulty tiers, open PvP challenges and the leaderboard (top 10). Free, unsigned.",
|
|
600
|
-
{},
|
|
601
|
-
async () => {
|
|
602
|
-
const { api } = await me();
|
|
689
|
+
"Shared world state: access rules, factions, arena difficulty tiers (the pots on your shard), open PvP challenges and the leaderboard (top 10). Free, unsigned.",
|
|
690
|
+
{ address: z2.string().optional().describe("Whose shard's arena pots; omit for yours.") },
|
|
691
|
+
async ({ address }) => {
|
|
692
|
+
const { api, address: mine } = await me();
|
|
693
|
+
const who = address ?? mine;
|
|
603
694
|
const [access, factions, tiers, challenges, leaderboard] = await Promise.all([
|
|
604
695
|
readKey("game", "access"),
|
|
605
696
|
api.readFactions(),
|
|
606
|
-
api
|
|
697
|
+
arenaTiers(api, who),
|
|
607
698
|
api.readChallenges(),
|
|
608
699
|
api.readLeaderboard()
|
|
609
700
|
]);
|
|
701
|
+
const { admitted, pending, purchased, ...policy } = access ?? {};
|
|
610
702
|
return {
|
|
611
|
-
access,
|
|
703
|
+
access: access && policy,
|
|
612
704
|
factions: factions?.map(({ members, ...f }) => f),
|
|
613
705
|
arenaTiers: tiers,
|
|
614
706
|
openChallenges: challenges,
|
|
@@ -633,7 +725,7 @@ function registerGame(server) {
|
|
|
633
725
|
tool(
|
|
634
726
|
server,
|
|
635
727
|
"game_companion",
|
|
636
|
-
"Care for and manage companions. feed: 1 berry, +20 energy for a berry of its own element, +10 for any other. play: 10 energy + 1 berry, +25 happiness after 15 min. quest: 25 energy + 25 happiness, 1 h, then exp and Gold. claim: collect a finished play/quest. store (1 Rune; moves a companion into the collection) / retrieve / set_active / transfer manage the collection. adopt: once, if you have a faction but no companion.",
|
|
728
|
+
"Care for and manage companions. feed: 1 berry, +20 energy for a berry of its own element, +10 for any other. play: 10 energy + 1 berry, +25 happiness after 15 min. quest: 25 energy + 25 happiness, 1 h, then exp and Gold. claim: collect a finished play/quest. store (1 Rune; moves a companion into the collection) / retrieve / set_active / transfer manage the collection; a transfer to an account on another shard is pending (player.moving) until that shard lands it. adopt: once, if you have a faction but no companion.",
|
|
637
729
|
{
|
|
638
730
|
action: z2.enum(["feed", "play", "quest", "claim", "adopt", "store", "retrieve", "set_active", "transfer"]),
|
|
639
731
|
monster_id: z2.string().optional().describe("Companion id; omit for the active one."),
|
|
@@ -705,9 +797,14 @@ function registerGame(server) {
|
|
|
705
797
|
tool(
|
|
706
798
|
server,
|
|
707
799
|
"game_shop_quote",
|
|
708
|
-
"The NPC realm shop's current Gold prices (bid/ask) and stock for berries,
|
|
709
|
-
{},
|
|
710
|
-
async () =>
|
|
800
|
+
"The NPC realm shop's current Gold prices (bid/ask) and stock for berries and Rune, on your shard (each shard has its own desks). Free, unsigned.",
|
|
801
|
+
{ address: z2.string().optional().describe("Whose shard's desks; omit for yours.") },
|
|
802
|
+
async ({ address }) => {
|
|
803
|
+
const { api, address: mine } = await me();
|
|
804
|
+
const who = address ?? mine;
|
|
805
|
+
if (who || !SHARDS.sharded) return api.readEconomy({ process: gameFor(who ?? "") });
|
|
806
|
+
return perShard((process2) => api.readEconomy({ process: process2 }));
|
|
807
|
+
},
|
|
711
808
|
READ
|
|
712
809
|
);
|
|
713
810
|
tool(
|
|
@@ -826,7 +923,7 @@ function registerGame(server) {
|
|
|
826
923
|
tool(
|
|
827
924
|
server,
|
|
828
925
|
"hunt_begin",
|
|
829
|
-
"Start a hunt with a companion. Entry fee:
|
|
926
|
+
"Start a hunt with a companion. Entry fee: 5 of each berry, 25 energy and 25 happiness, not refunded. Up to 3 Rune go with the run and come back when it ends, unless a capture spends them.",
|
|
830
927
|
{ monster_id: z2.string().describe("Companion to hunt with (see game_player).") },
|
|
831
928
|
async ({ monster_id }) => (await me()).api.beginHunt(monster_id),
|
|
832
929
|
WRITE,
|
|
@@ -848,7 +945,7 @@ function registerGame(server) {
|
|
|
848
945
|
tool(
|
|
849
946
|
server,
|
|
850
947
|
"hunt_act",
|
|
851
|
-
"Act in your live hunt. A hunt is one encounter. search: find the wild creature (once per hunt). attack: one round with a move; losing ends the run. After a win: capture (one try with 1-3 Rune
|
|
948
|
+
"Act in your live hunt. A hunt is one encounter. search: find the wild creature (once per hunt). attack: one round with a move; losing ends the run. After a win: capture (one try with 1-3 Rune, consumed either way, ends the run) or end. end: finish the run and get unspent supplies back. retry_settlement: re-send a stuck final.",
|
|
852
949
|
{
|
|
853
950
|
action: z2.enum(["search", "attack", "capture", "end", "retry_settlement"]),
|
|
854
951
|
move: z2.string().optional(),
|
|
@@ -892,20 +989,21 @@ function registerGame(server) {
|
|
|
892
989
|
tool(
|
|
893
990
|
server,
|
|
894
991
|
"companion_market",
|
|
895
|
-
"Trade companions for in-game Rune (listings: companion_market_browse). list: sell a companion from your collection (never the active one; game_companion store moves it there for 1 Rune). buy
|
|
992
|
+
"Trade companions for in-game Rune (listings: companion_market_browse). list: sell a companion from your collection (never the active one; game_companion store moves it there for 1 Rune). buy: listing_id and its price -- the market sells only at exactly the price you name (and listing_shard: the listing's shard, when it names one); the price is held (player.buying) until the market answers with the companion or the Rune. cancel: by listing_id.",
|
|
896
993
|
{
|
|
897
994
|
action: z2.enum(["list", "buy", "cancel"]),
|
|
898
995
|
monster_id: z2.string().optional(),
|
|
899
996
|
price: z2.number().int().min(1).max(1e6).optional(),
|
|
900
|
-
listing_id: z2.string().optional()
|
|
997
|
+
listing_id: z2.string().optional(),
|
|
998
|
+
listing_shard: z2.string().optional()
|
|
901
999
|
},
|
|
902
|
-
async ({ action, monster_id, price, listing_id }) => {
|
|
1000
|
+
async ({ action, monster_id, price, listing_id, listing_shard }) => {
|
|
903
1001
|
const { api } = await me();
|
|
904
1002
|
switch (action) {
|
|
905
1003
|
case "list":
|
|
906
1004
|
return api.listMonster(need(monster_id, "monster_id"), need(price, "price"));
|
|
907
1005
|
case "buy":
|
|
908
|
-
return api.buyListing(need(listing_id, "listing_id"));
|
|
1006
|
+
return api.buyListing(need(listing_id, "listing_id"), need(price, "price"), listing_shard ?? "");
|
|
909
1007
|
case "cancel":
|
|
910
1008
|
return api.cancelListing(need(listing_id, "listing_id"));
|
|
911
1009
|
}
|
|
@@ -915,30 +1013,50 @@ function registerGame(server) {
|
|
|
915
1013
|
);
|
|
916
1014
|
tool(
|
|
917
1015
|
server,
|
|
918
|
-
"
|
|
919
|
-
"Move
|
|
920
|
-
{
|
|
921
|
-
async ({
|
|
922
|
-
const { api } = await me();
|
|
923
|
-
if (direction === "withdraw") return api.withdrawRune(amount);
|
|
924
|
-
return api.depositRuneToGame(String(BigInt(amount) * 1000000n));
|
|
925
|
-
},
|
|
1016
|
+
"asset_withdraw",
|
|
1017
|
+
"Move whole units of an in-game asset out to its token in your wallet (minted by the game; the in-game balance is deducted first). Gold: at least 10. Only wallet tokens trade on the exchange.",
|
|
1018
|
+
{ asset: ASSET, amount: z2.number().int().positive().describe("Whole units.") },
|
|
1019
|
+
async ({ asset, amount }) => (await me()).api.assetWithdraw(asset, amount),
|
|
926
1020
|
WRITE,
|
|
927
1021
|
asPlayer
|
|
928
1022
|
);
|
|
929
1023
|
tool(
|
|
930
1024
|
server,
|
|
931
|
-
"
|
|
932
|
-
"
|
|
933
|
-
{},
|
|
934
|
-
async () => {
|
|
1025
|
+
"asset_deposit",
|
|
1026
|
+
"Move whole units of a token from your wallet into the game: the token burns them and the game credits your account. Needs a game account (game_join first): without one it is refused, since the game would hold the burned tokens. Whole units only; a fraction left from trading stays in the wallet.",
|
|
1027
|
+
{ asset: ASSET, amount: z2.number().int().positive().describe("Whole units.") },
|
|
1028
|
+
async ({ asset, amount }) => {
|
|
935
1029
|
const { api, address } = await me();
|
|
936
|
-
const
|
|
937
|
-
|
|
1030
|
+
const p = address ? await api.readPlayer(address) : null;
|
|
1031
|
+
if (!p?.faction) throw new Error("This wallet has no Rune Realm account, so a deposit would not be credited. Call game_join first.");
|
|
1032
|
+
return api.assetDeposit(asset, amount);
|
|
1033
|
+
},
|
|
1034
|
+
WRITE
|
|
1035
|
+
);
|
|
1036
|
+
tool(
|
|
1037
|
+
server,
|
|
1038
|
+
"berry_claim",
|
|
1039
|
+
"Claim today's free berry tokens to your wallet: one berry kind per wallet per UTC day, 1-10 of it, the amount set by the current UTC hour. Once per day. preview: show the berry and the amount for each hour left today, sending nothing.",
|
|
1040
|
+
{ preview: z2.boolean().optional() },
|
|
1041
|
+
async ({ preview }) => {
|
|
1042
|
+
const { api, address } = await me();
|
|
1043
|
+
const now = Date.now();
|
|
1044
|
+
const { berry } = api.berryClaimFor(address, Math.floor(now / DAY_MS));
|
|
1045
|
+
const hour = Math.floor(now / HOUR_MS);
|
|
1046
|
+
if (preview) {
|
|
1047
|
+
const left = 24 - hour % 24;
|
|
1048
|
+
return { berry, hours: Array.from({ length: left }, (_, i) => ({
|
|
1049
|
+
from: new Date((hour + i) * HOUR_MS).toISOString(),
|
|
1050
|
+
amount: api.claimAmountFor(address, hour + i)
|
|
1051
|
+
})) };
|
|
1052
|
+
}
|
|
1053
|
+
return { berry, reply: await api.claimBerry(berry) };
|
|
938
1054
|
},
|
|
939
1055
|
WRITE
|
|
940
1056
|
);
|
|
941
1057
|
}
|
|
1058
|
+
var DAY_MS = 864e5;
|
|
1059
|
+
var HOUR_MS = 36e5;
|
|
942
1060
|
var asPlayer = (r) => r?.address && r?.inventory ? player(r) : r;
|
|
943
1061
|
var battleView = (b) => b?.id ? battle(b, b.viewer) : b;
|
|
944
1062
|
async function attackView(p) {
|
|
@@ -961,11 +1079,10 @@ function need(value, name) {
|
|
|
961
1079
|
|
|
962
1080
|
// src/exchange.mjs
|
|
963
1081
|
import { z as z3 } from "zod";
|
|
964
|
-
var
|
|
965
|
-
|
|
966
|
-
async function terms(venue) {
|
|
1082
|
+
var BOOK = () => graph.processes.externalVenue;
|
|
1083
|
+
async function terms() {
|
|
967
1084
|
const { api } = await runtime();
|
|
968
|
-
const process2 =
|
|
1085
|
+
const process2 = BOOK();
|
|
969
1086
|
const [info, markets] = await Promise.all([readKey(process2, "vaultinfo"), api.readVenueMarkets(process2)]);
|
|
970
1087
|
const assets = info?.Assets ?? {};
|
|
971
1088
|
return { process: process2, assets, markets: markets ?? {}, den: (asset) => Number(assets[asset]?.denomination ?? 0) };
|
|
@@ -997,10 +1114,10 @@ function registerExchange(server) {
|
|
|
997
1114
|
tool(
|
|
998
1115
|
server,
|
|
999
1116
|
"exchange_markets",
|
|
1000
|
-
"List
|
|
1001
|
-
{
|
|
1002
|
-
async (
|
|
1003
|
-
const t = await terms(
|
|
1117
|
+
"List the book's markets (every one quoted in Gold) with lot, tick, taker fee (bps), minimums and status, plus asset denominations. Free.",
|
|
1118
|
+
{},
|
|
1119
|
+
async () => {
|
|
1120
|
+
const t = await terms();
|
|
1004
1121
|
return { process: t.process, assets: t.assets, markets: t.markets };
|
|
1005
1122
|
},
|
|
1006
1123
|
READ
|
|
@@ -1009,9 +1126,9 @@ function registerExchange(server) {
|
|
|
1009
1126
|
server,
|
|
1010
1127
|
"exchange_book",
|
|
1011
1128
|
"Depth for one market in human units: best bid/ask, top 10 levels each side, price band and today's candle. Free.",
|
|
1012
|
-
{
|
|
1013
|
-
async ({
|
|
1014
|
-
const t = await terms(
|
|
1129
|
+
{ item: z3.string().describe("Base asset or market, e.g. fire, rune or fire_gold.") },
|
|
1130
|
+
async ({ item }) => {
|
|
1131
|
+
const t = await terms();
|
|
1015
1132
|
const m = marketFor(t, item);
|
|
1016
1133
|
const { api } = await runtime();
|
|
1017
1134
|
const book = (await api.readVenueBook(t.process))?.[m.id];
|
|
@@ -1040,10 +1157,10 @@ function registerExchange(server) {
|
|
|
1040
1157
|
tool(
|
|
1041
1158
|
server,
|
|
1042
1159
|
"exchange_position",
|
|
1043
|
-
"Balances
|
|
1044
|
-
{
|
|
1045
|
-
async ({
|
|
1046
|
-
const t = await terms(
|
|
1160
|
+
"Balances on the book (free, and where each asset sits) with open orders and recent fills, all in human units; yours unless address is given. Free.",
|
|
1161
|
+
{ address: z3.string().optional() },
|
|
1162
|
+
async ({ address }) => {
|
|
1163
|
+
const t = await terms();
|
|
1047
1164
|
const { api, wallets } = await runtime();
|
|
1048
1165
|
const who = address ?? wallets?.ao.address;
|
|
1049
1166
|
if (!who) throw new Error("This server has no wallet; pass an address.");
|
|
@@ -1081,19 +1198,18 @@ function registerExchange(server) {
|
|
|
1081
1198
|
tool(
|
|
1082
1199
|
server,
|
|
1083
1200
|
"exchange_order",
|
|
1084
|
-
"Place a limit order. price is
|
|
1201
|
+
"Place a limit order. price is Gold per whole base unit; quantity is whole base units. Funds are routed from your book balance, or deposited from your wallet if short, in one signature. In-game balances are not on the book: asset_withdraw them to your wallet first. tif: GTC (rest), IOC (fill what you can now), FOK (all or nothing), PostOnly (never take).",
|
|
1085
1202
|
{
|
|
1086
|
-
venue: VENUE,
|
|
1087
1203
|
side: z3.enum(["buy", "sell"]),
|
|
1088
|
-
item: z3.string(),
|
|
1204
|
+
item: z3.string().describe("Base asset or market, e.g. fire, rune or fire_gold."),
|
|
1089
1205
|
price: z3.string().describe('Decimal, e.g. "12.5".'),
|
|
1090
1206
|
quantity: z3.string().describe('Decimal, e.g. "3".'),
|
|
1091
1207
|
tif: z3.enum(["GTC", "IOC", "FOK", "PostOnly"]).optional(),
|
|
1092
1208
|
stp: z3.enum(["CancelResting", "Reject", "CancelBoth"]).optional(),
|
|
1093
1209
|
expires_in: z3.number().int().positive().optional().describe("Seconds a GTC order may rest.")
|
|
1094
1210
|
},
|
|
1095
|
-
async ({
|
|
1096
|
-
const t = await terms(
|
|
1211
|
+
async ({ side: side2, item, price, quantity, tif, stp, expires_in }) => {
|
|
1212
|
+
const t = await terms();
|
|
1097
1213
|
const m = marketFor(t, item);
|
|
1098
1214
|
const wire = toWire(t, m, price, quantity);
|
|
1099
1215
|
const { api, wallets } = await runtime();
|
|
@@ -1113,7 +1229,7 @@ function registerExchange(server) {
|
|
|
1113
1229
|
}
|
|
1114
1230
|
return {
|
|
1115
1231
|
outcome,
|
|
1116
|
-
route: { from: reply.pending.fromWallet !== "0" ? "wallet" :
|
|
1232
|
+
route: { from: reply.pending.fromWallet !== "0" ? "wallet" : "book" },
|
|
1117
1233
|
...outcome.state === "pending" ? { note: "Still settling; check exchange_position shortly. Do not re-place." } : {}
|
|
1118
1234
|
};
|
|
1119
1235
|
},
|
|
@@ -1123,12 +1239,12 @@ function registerExchange(server) {
|
|
|
1123
1239
|
server,
|
|
1124
1240
|
"exchange_cancel",
|
|
1125
1241
|
"Cancel one order by order_id (as returned by exchange_order / exchange_position), or all your orders (optionally one item).",
|
|
1126
|
-
{
|
|
1127
|
-
async ({
|
|
1242
|
+
{ order_id: z3.string().optional(), all: z3.boolean().optional(), item: z3.string().optional() },
|
|
1243
|
+
async ({ order_id, all, item }) => {
|
|
1128
1244
|
const { api } = await runtime();
|
|
1129
|
-
if (all) return api.cancelAllVenueOrders(
|
|
1245
|
+
if (all) return api.cancelAllVenueOrders(BOOK(), item);
|
|
1130
1246
|
if (!order_id) throw new Error("Give order_id, or all: true.");
|
|
1131
|
-
return api.cancelVenueOrder(
|
|
1247
|
+
return api.cancelVenueOrder(BOOK(), order_id);
|
|
1132
1248
|
},
|
|
1133
1249
|
WRITE
|
|
1134
1250
|
);
|
|
@@ -1136,9 +1252,9 @@ function registerExchange(server) {
|
|
|
1136
1252
|
server,
|
|
1137
1253
|
"exchange_amend",
|
|
1138
1254
|
"Change a resting GTC/PostOnly order's price and/or quantity (human units, like exchange_order).",
|
|
1139
|
-
{
|
|
1140
|
-
async ({
|
|
1141
|
-
const t = await terms(
|
|
1255
|
+
{ order_id: z3.string(), item: z3.string(), price: z3.string().optional(), quantity: z3.string().optional() },
|
|
1256
|
+
async ({ order_id, item, price, quantity }) => {
|
|
1257
|
+
const t = await terms();
|
|
1142
1258
|
const m = marketFor(t, item);
|
|
1143
1259
|
const wire = toWire(t, m, price ?? "1", quantity ?? formatAtoms(BigInt(m.lot), t.den(m.base)));
|
|
1144
1260
|
const { api } = await runtime();
|
|
@@ -1152,21 +1268,18 @@ function registerExchange(server) {
|
|
|
1152
1268
|
tool(
|
|
1153
1269
|
server,
|
|
1154
1270
|
"exchange_transfer",
|
|
1155
|
-
"Move
|
|
1156
|
-
{
|
|
1157
|
-
|
|
1158
|
-
|
|
1271
|
+
"Move tokens between your wallet and the book. deposit: from your wallet. withdraw: back to your wallet. amount is decimal units. Between the game and your wallet, use asset_withdraw / asset_deposit.",
|
|
1272
|
+
{
|
|
1273
|
+
direction: z3.enum(["deposit", "withdraw"]),
|
|
1274
|
+
asset: z3.string().describe("gold, rune, air, water, fire or rock."),
|
|
1275
|
+
amount: z3.string()
|
|
1276
|
+
},
|
|
1277
|
+
async ({ direction, asset, amount }) => {
|
|
1278
|
+
const t = await terms();
|
|
1159
1279
|
const { api } = await runtime();
|
|
1160
|
-
if (direction === "withdraw")
|
|
1161
|
-
if (venue === "game" && !/^\d+$/.test(amount)) throw new Error("The game takes back whole units; withdraw a whole number and leave the fraction.");
|
|
1162
|
-
return api.withdrawFromVenue(t.process, asset, parseAmount(amount, t.den(asset)).toString());
|
|
1163
|
-
}
|
|
1164
|
-
if (venue === "game") {
|
|
1165
|
-
if (!/^\d+$/.test(amount)) throw new Error("Game assets move in whole units.");
|
|
1166
|
-
return api.sendToVenue(asset, Number(amount));
|
|
1167
|
-
}
|
|
1280
|
+
if (direction === "withdraw") return api.withdrawFromVenue(t.process, asset, parseAmount(amount, t.den(asset)).toString());
|
|
1168
1281
|
const token = t.assets[asset]?.process;
|
|
1169
|
-
if (!token) throw new Error(`"${asset}" is not a token on
|
|
1282
|
+
if (!token) throw new Error(`"${asset}" is not a token on the book. Assets: ${Object.keys(t.assets).join(", ")}`);
|
|
1170
1283
|
return api.depositTokenToVenue(token, t.process, parseAmount(amount, t.den(asset)).toString());
|
|
1171
1284
|
},
|
|
1172
1285
|
WRITE
|
|
@@ -1203,9 +1316,15 @@ import { bcs } from "@mysten/sui/bcs";
|
|
|
1203
1316
|
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
1204
1317
|
import { Transaction as SuiTransaction, coinWithBalance } from "@mysten/sui/transactions";
|
|
1205
1318
|
var DAILY_FAUCET = 100000000n;
|
|
1206
|
-
var
|
|
1319
|
+
var DAY_MS2 = 864e5;
|
|
1207
1320
|
var CHAIN = z4.enum(["base", "solana", "sui"]);
|
|
1208
1321
|
var PUSD = graph.processes.pusd;
|
|
1322
|
+
var rootBytes = (id) => {
|
|
1323
|
+
const bytes = Buffer.from(id, "base64url");
|
|
1324
|
+
if (bytes.length !== 32) throw new Error("Canonical PUSD root must decode to 32 bytes.");
|
|
1325
|
+
return bytes;
|
|
1326
|
+
};
|
|
1327
|
+
var rootHex = (id) => `0x${rootBytes(id).toString("hex")}`;
|
|
1209
1328
|
var faucetToken = (cfg) => (cfg.tokens ?? []).find((t) => t.faucet) ?? cfg.tokens?.[0];
|
|
1210
1329
|
function baseChain(w) {
|
|
1211
1330
|
const cfg = chains.base;
|
|
@@ -1246,7 +1365,7 @@ function baseChain(w) {
|
|
|
1246
1365
|
return write({ address: cfg.bridge, abi: BRIDGE, functionName: "deposit", args: [token.address, amount, ao] });
|
|
1247
1366
|
},
|
|
1248
1367
|
/** Submit a signed withdrawal: the set's signatures, sorted by signer. */
|
|
1249
|
-
async claim(w2, set, namespace) {
|
|
1368
|
+
async claim(w2, set, namespace, epoch) {
|
|
1250
1369
|
const RELEASE = parseAbi(["function release(uint64 withdrawalId, address token, address to, uint256 amount, bytes[] sigs)"]);
|
|
1251
1370
|
const id = BigInt(namespace) << 32n | BigInt(w2.id);
|
|
1252
1371
|
const inner = keccak256(encodeAbiParameters(
|
|
@@ -1254,12 +1373,24 @@ function baseChain(w) {
|
|
|
1254
1373
|
{ type: "bytes32" },
|
|
1255
1374
|
{ type: "uint256" },
|
|
1256
1375
|
{ type: "address" },
|
|
1376
|
+
{ type: "bytes32" },
|
|
1377
|
+
{ type: "uint64" },
|
|
1257
1378
|
{ type: "uint64" },
|
|
1258
1379
|
{ type: "address" },
|
|
1259
1380
|
{ type: "address" },
|
|
1260
1381
|
{ type: "uint256" }
|
|
1261
1382
|
],
|
|
1262
|
-
[
|
|
1383
|
+
[
|
|
1384
|
+
keccak256(toBytes("PARALITH_RELEASE_V2")),
|
|
1385
|
+
BigInt(cfg.chainId),
|
|
1386
|
+
cfg.bridge,
|
|
1387
|
+
rootHex(PUSD),
|
|
1388
|
+
BigInt(epoch),
|
|
1389
|
+
id,
|
|
1390
|
+
w2.token,
|
|
1391
|
+
w2.to,
|
|
1392
|
+
BigInt(w2.amount)
|
|
1393
|
+
]
|
|
1263
1394
|
));
|
|
1264
1395
|
const allowed = new Set(set.map((m) => m.base.toLowerCase()));
|
|
1265
1396
|
const rows = await Promise.all(set.filter((m) => w2.sigs?.[m.ao]).map(async (m) => ({
|
|
@@ -1313,7 +1444,7 @@ function solanaChain(w) {
|
|
|
1313
1444
|
if (!info) return DAILY_FAUCET;
|
|
1314
1445
|
const day = info.data.readBigUInt64LE(8);
|
|
1315
1446
|
const claimed = info.data.readBigUInt64LE(16);
|
|
1316
|
-
return day === BigInt(Math.floor(Date.now() /
|
|
1447
|
+
return day === BigInt(Math.floor(Date.now() / DAY_MS2)) ? DAILY_FAUCET - claimed : DAILY_FAUCET;
|
|
1317
1448
|
},
|
|
1318
1449
|
faucet: (amount) => send2(new TransactionInstruction({
|
|
1319
1450
|
programId: program,
|
|
@@ -1343,14 +1474,16 @@ function solanaChain(w) {
|
|
|
1343
1474
|
})),
|
|
1344
1475
|
/** Submit a signed withdrawal: one Ed25519 precompile instruction holding the
|
|
1345
1476
|
* members' signatures over the release message, then `release`. */
|
|
1346
|
-
claim(w2, set, namespace) {
|
|
1477
|
+
claim(w2, set, namespace, epoch) {
|
|
1347
1478
|
const id = BigInt(namespace) << 32n | BigInt(w2.id);
|
|
1348
1479
|
const amount = BigInt(w2.amount);
|
|
1349
1480
|
const to = new PublicKey(w2.to);
|
|
1350
1481
|
const signed = set.filter((m) => w2.sigs?.[m.ao]);
|
|
1351
1482
|
const msg = Buffer.concat([
|
|
1352
|
-
Buffer.from("
|
|
1483
|
+
Buffer.from("PARALITH_RELEASE_V2"),
|
|
1353
1484
|
program.toBuffer(),
|
|
1485
|
+
rootBytes(PUSD),
|
|
1486
|
+
u64(epoch),
|
|
1354
1487
|
u64(id),
|
|
1355
1488
|
mint.toBuffer(),
|
|
1356
1489
|
to.toBuffer(),
|
|
@@ -1529,7 +1662,7 @@ function registerBridge(server) {
|
|
|
1529
1662
|
},
|
|
1530
1663
|
WRITE
|
|
1531
1664
|
);
|
|
1532
|
-
const nudgeNodes = () => Promise.all((chains.nodes ?? []).map((n) => fetch(`${n.url}/~bridge@1.0/nudge`, { signal: AbortSignal.timeout(1e4) }).catch(() => {
|
|
1665
|
+
const nudgeNodes = () => Promise.all((chains.nodes ?? []).map((n) => fetch(`${n.url}/~bridge-attestor@1.0/nudge`, { signal: AbortSignal.timeout(1e4) }).catch(() => {
|
|
1533
1666
|
})));
|
|
1534
1667
|
tool(
|
|
1535
1668
|
server,
|
|
@@ -1573,7 +1706,7 @@ function registerBridge(server) {
|
|
|
1573
1706
|
if (!wait) return out;
|
|
1574
1707
|
const info = await readKey(PUSD, "bridgeinfo");
|
|
1575
1708
|
const set = info?.attestors ?? [];
|
|
1576
|
-
const k = Math.floor(
|
|
1709
|
+
const k = Math.floor(set.length / 2) + 1;
|
|
1577
1710
|
const signed = (w2) => set.filter((m) => w2?.sigs?.[m.ao]).length;
|
|
1578
1711
|
const list = await until(
|
|
1579
1712
|
`${k} node signatures`,
|
|
@@ -1582,7 +1715,7 @@ function registerBridge(server) {
|
|
|
1582
1715
|
9e5
|
|
1583
1716
|
);
|
|
1584
1717
|
const w = list.find((x) => x.id === String(reply.WithdrawalId));
|
|
1585
|
-
const tx = await c.claim(w, set, Number(info.namespace));
|
|
1718
|
+
const tx = await c.claim(w, set, Number(info.namespace), Number(info.epoch));
|
|
1586
1719
|
if (!own) return { ...out, status: "released", tx };
|
|
1587
1720
|
const after = await until("release", () => c.balance(), (b) => b >= before + BigInt(w.amount), 3e5);
|
|
1588
1721
|
return { ...out, status: "released", tx, received: formatAtoms(after - before) };
|
|
@@ -1697,7 +1830,7 @@ function registerDao(server) {
|
|
|
1697
1830
|
tool(
|
|
1698
1831
|
server,
|
|
1699
1832
|
"dao_stake",
|
|
1700
|
-
"stake: transfer
|
|
1833
|
+
"stake: transfer RUNE from your wallet into the DAO (counts as active stake at once). unstake: move active stake to cooling (amount omitted = all); it pays out after the unstake delay, or later if a vote locks it. withdraw: pay out cooling stake whose release time has passed. Use asset_withdraw rune first if your RUNE is in the game.",
|
|
1701
1834
|
{ action: z5.enum(["stake", "unstake", "withdraw"]), amount: z5.string().optional().describe("RUNE, decimal.") },
|
|
1702
1835
|
async ({ action, amount }) => {
|
|
1703
1836
|
const { api, wallets } = await runtime();
|
|
@@ -1772,13 +1905,12 @@ function registerDao(server) {
|
|
|
1772
1905
|
|
|
1773
1906
|
// src/vaults.mjs
|
|
1774
1907
|
import { z as z6 } from "zod";
|
|
1775
|
-
var VENUE2 = z6.enum(["game", "token"]).describe("game: items vs Gold. token: element tokens vs TEST-RUNE.");
|
|
1776
1908
|
var STRATEGY = z6.enum(["amm", "active", "grid"]).describe("amm: passive, steady, close to holding. active: concentrated, best sideways, loses most in trends. grid: fixed steps, best range-bound, loses in trends.");
|
|
1777
|
-
var
|
|
1778
|
-
var
|
|
1779
|
-
async function terms2(
|
|
1909
|
+
var BOOK2 = () => graph.processes.externalVenue;
|
|
1910
|
+
var DAY_MS3 = 864e5;
|
|
1911
|
+
async function terms2() {
|
|
1780
1912
|
const { api } = await runtime();
|
|
1781
|
-
const process2 =
|
|
1913
|
+
const process2 = BOOK2();
|
|
1782
1914
|
const [info, markets] = await Promise.all([readKey(process2, "vaultinfo"), api.readVenueMarkets(process2)]);
|
|
1783
1915
|
const assets = info?.Assets ?? {};
|
|
1784
1916
|
return { process: process2, markets: markets ?? {}, den: (asset) => Number(assets[asset]?.denomination ?? 0) };
|
|
@@ -1820,10 +1952,10 @@ function registerVaults(server) {
|
|
|
1820
1952
|
tool(
|
|
1821
1953
|
server,
|
|
1822
1954
|
"vault_list",
|
|
1823
|
-
"Strategy vaults on
|
|
1824
|
-
{
|
|
1825
|
-
async ({
|
|
1826
|
-
const t = await terms2(
|
|
1955
|
+
"Strategy vaults on the book (one amm, active and grid per market): status, holdings, locked and burned share with their value and unlock dates, spacing, crank budget. Whole units. Optionally one market. Free.",
|
|
1956
|
+
{ item: z6.string().optional().describe("Base asset or market, e.g. fire or rune_gold.") },
|
|
1957
|
+
async ({ item }) => {
|
|
1958
|
+
const t = await terms2();
|
|
1827
1959
|
const { api } = await runtime();
|
|
1828
1960
|
const all = await api.readVenueVaults(t.process);
|
|
1829
1961
|
const out = {};
|
|
@@ -1840,9 +1972,9 @@ function registerVaults(server) {
|
|
|
1840
1972
|
server,
|
|
1841
1973
|
"vault_position",
|
|
1842
1974
|
"Vault shares held by an address (yours unless given): shares, unlocked shares, locks with dates, and the value they own in whole units. Free.",
|
|
1843
|
-
{
|
|
1844
|
-
async ({
|
|
1845
|
-
const t = await terms2(
|
|
1975
|
+
{ address: z6.string().optional() },
|
|
1976
|
+
async ({ address }) => {
|
|
1977
|
+
const t = await terms2();
|
|
1846
1978
|
const { api, wallets } = await runtime();
|
|
1847
1979
|
const who = address ?? wallets?.ao.address;
|
|
1848
1980
|
if (!who) throw new Error("This server has no wallet; pass an address.");
|
|
@@ -1865,9 +1997,8 @@ function registerVaults(server) {
|
|
|
1865
1997
|
tool(
|
|
1866
1998
|
server,
|
|
1867
1999
|
"vault_deposit",
|
|
1868
|
-
"Deposit into a strategy vault. base and quote are MAXIMA in whole units: the vault takes them in its own ratio and uses only what that needs (a vault's first deposit needs both and sets its price). Funds must be in your
|
|
2000
|
+
"Deposit into a strategy vault. base and quote are MAXIMA in whole units: the vault takes them in its own ratio and uses only what that needs (a vault's first deposit needs both and sets its price). Funds must be in your book balance (exchange_transfer deposit first); what is short on the market is moved there in the same signature. lock_days locks the new shares; burn gives them up forever (cannot be undone). Active and grid lose heavily in trends.",
|
|
1869
2001
|
{
|
|
1870
|
-
venue: VENUE2,
|
|
1871
2002
|
item: z6.string(),
|
|
1872
2003
|
strategy: STRATEGY,
|
|
1873
2004
|
base: z6.string().describe("Most base to put in, decimal."),
|
|
@@ -1875,9 +2006,9 @@ function registerVaults(server) {
|
|
|
1875
2006
|
lock_days: z6.number().int().positive().max(3650).optional(),
|
|
1876
2007
|
burn: z6.boolean().optional()
|
|
1877
2008
|
},
|
|
1878
|
-
async ({
|
|
2009
|
+
async ({ item, strategy, base: base2, quote, lock_days, burn }) => {
|
|
1879
2010
|
if (lock_days && burn) throw new Error("Lock or burn, not both.");
|
|
1880
|
-
const t = await terms2(
|
|
2011
|
+
const t = await terms2();
|
|
1881
2012
|
const m = marketFor2(t, item);
|
|
1882
2013
|
const { api } = await runtime();
|
|
1883
2014
|
return api.depositVenueVault(
|
|
@@ -1886,7 +2017,7 @@ function registerVaults(server) {
|
|
|
1886
2017
|
strategy,
|
|
1887
2018
|
parseAmount(base2, t.den(m.base)),
|
|
1888
2019
|
parseAmount(quote, t.den(m.quote)),
|
|
1889
|
-
{ lockFor: lock_days ? lock_days *
|
|
2020
|
+
{ lockFor: lock_days ? lock_days * DAY_MS3 : void 0, burn: !!burn }
|
|
1890
2021
|
);
|
|
1891
2022
|
},
|
|
1892
2023
|
WRITE
|
|
@@ -1894,19 +2025,18 @@ function registerVaults(server) {
|
|
|
1894
2025
|
tool(
|
|
1895
2026
|
server,
|
|
1896
2027
|
"vault_shares",
|
|
1897
|
-
'Act on your UNLOCKED vault shares: withdraw (paid in kind to your
|
|
2028
|
+
'Act on your UNLOCKED vault shares: withdraw (paid in kind to your book balance on that market; works while trading is paused), lock for lock_days, or burn (forever; the value stays in the vault). shares is a number or "all".',
|
|
1898
2029
|
{
|
|
1899
|
-
venue: VENUE2,
|
|
1900
2030
|
item: z6.string(),
|
|
1901
2031
|
strategy: STRATEGY,
|
|
1902
2032
|
action: z6.enum(["withdraw", "lock", "burn"]),
|
|
1903
2033
|
shares: z6.string().describe('"all" or a whole number of shares.'),
|
|
1904
2034
|
lock_days: z6.number().int().positive().max(3650).optional()
|
|
1905
2035
|
},
|
|
1906
|
-
async ({
|
|
2036
|
+
async ({ item, strategy, action, shares, lock_days }) => {
|
|
1907
2037
|
if (action === "lock" && !lock_days) throw new Error("A lock needs lock_days.");
|
|
1908
2038
|
if (shares !== "all" && !/^\d+$/.test(shares)) throw new Error('shares is "all" or a whole number.');
|
|
1909
|
-
const t = await terms2(
|
|
2039
|
+
const t = await terms2();
|
|
1910
2040
|
const m = marketFor2(t, item);
|
|
1911
2041
|
const { api } = await runtime();
|
|
1912
2042
|
return api.venueVaultShares(
|
|
@@ -1915,7 +2045,7 @@ function registerVaults(server) {
|
|
|
1915
2045
|
strategy,
|
|
1916
2046
|
action,
|
|
1917
2047
|
shares === "all" ? "all" : BigInt(shares),
|
|
1918
|
-
lock_days ? lock_days *
|
|
2048
|
+
lock_days ? lock_days * DAY_MS3 : void 0
|
|
1919
2049
|
);
|
|
1920
2050
|
},
|
|
1921
2051
|
WRITE
|
|
@@ -1924,9 +2054,9 @@ function registerVaults(server) {
|
|
|
1924
2054
|
server,
|
|
1925
2055
|
"vault_fund",
|
|
1926
2056
|
"Add to a vault's crank budget, in whole quote units. Anyone may; holders do not own it. It pays whoever cranks the vault when its orders need requoting.",
|
|
1927
|
-
{
|
|
1928
|
-
async ({
|
|
1929
|
-
const t = await terms2(
|
|
2057
|
+
{ item: z6.string(), strategy: STRATEGY, amount: z6.string() },
|
|
2058
|
+
async ({ item, strategy, amount }) => {
|
|
2059
|
+
const t = await terms2();
|
|
1930
2060
|
const m = marketFor2(t, item);
|
|
1931
2061
|
const { api } = await runtime();
|
|
1932
2062
|
return api.fundVenueVault(t.process, m.base, strategy, parseAmount(amount, t.den(m.quote)));
|
|
@@ -1937,9 +2067,9 @@ function registerVaults(server) {
|
|
|
1937
2067
|
server,
|
|
1938
2068
|
"vault_crank",
|
|
1939
2069
|
"Requote a vault whose orders expired or were refused. Pays you 1% of its crank budget if it changed something and nobody was paid for it in the last 60 s; otherwise it pays nothing. Fills never need a crank. Worth it only when vault_list shows a dueAt that has passed; a vault that is not due answers idle.",
|
|
1940
|
-
{
|
|
1941
|
-
async ({
|
|
1942
|
-
const t = await terms2(
|
|
2070
|
+
{ item: z6.string(), strategy: STRATEGY },
|
|
2071
|
+
async ({ item, strategy }) => {
|
|
2072
|
+
const t = await terms2();
|
|
1943
2073
|
const m = marketFor2(t, item);
|
|
1944
2074
|
const { api } = await runtime();
|
|
1945
2075
|
return api.crankVenueVault(t.process, m.base, strategy);
|
|
@@ -1973,9 +2103,9 @@ var VIEWS = {
|
|
|
1973
2103
|
battle: (a) => a.battle_id && a.worker ? link(GAME, "battle", { w: a.worker, b: a.battle_id, a: a.address }) : link(GAME, "battle", { a: need2(a, "address") }),
|
|
1974
2104
|
companion: (a) => link(GAME, "companion", { a: need2(a, "address"), m: a.monster_id }),
|
|
1975
2105
|
hunt: (a) => link(GAME, "hunt", { a: need2(a, "address") }),
|
|
1976
|
-
market: (a) => link(TRADE, "market", { venue:
|
|
1977
|
-
vault: (a) => link(TRADE, "vault", { venue:
|
|
1978
|
-
position: (a) => link(TRADE, "position", { venue:
|
|
2106
|
+
market: (a) => link(TRADE, "market", { venue: "token", m: need2(a, "market") }),
|
|
2107
|
+
vault: (a) => link(TRADE, "vault", { venue: "token", m: need2(a, "market"), v: a.vault ?? "amm" }),
|
|
2108
|
+
position: (a) => link(TRADE, "position", { venue: "token", a: need2(a, "address") }),
|
|
1979
2109
|
bridge: (a) => link(TRADE, "bridge", { a: a.address, chain: a.chain, tx: a.tx })
|
|
1980
2110
|
};
|
|
1981
2111
|
function need2(args, key) {
|
|
@@ -2014,7 +2144,6 @@ function registerShow(server) {
|
|
|
2014
2144
|
monster_id: z7.string().optional().describe("companion: which one; omit for the active companion."),
|
|
2015
2145
|
battle_id: z7.string().optional().describe("battle: a specific battle, with worker."),
|
|
2016
2146
|
worker: z7.string().optional().describe("battle: the battle worker process id."),
|
|
2017
|
-
venue: z7.enum(["game", "token"]).optional().describe("market/vault/position. Default token."),
|
|
2018
2147
|
market: z7.string().optional().describe("market/vault: the market, as exchange_markets lists it."),
|
|
2019
2148
|
vault: z7.enum(["amm", "active", "grid"]).optional(),
|
|
2020
2149
|
chain: z7.enum(["base", "solana", "sui"]).optional().describe("bridge: with tx, one transfer."),
|
|
@@ -2039,7 +2168,8 @@ ${where}` }] };
|
|
|
2039
2168
|
|
|
2040
2169
|
// src/progress.mjs
|
|
2041
2170
|
import { z as z8 } from "zod";
|
|
2042
|
-
var VENUES = {
|
|
2171
|
+
var VENUES = { book: graph.processes.externalVenue };
|
|
2172
|
+
var BERRIES2 = ["air_berry", "water_berry", "fire_berry", "rock_berry"];
|
|
2043
2173
|
var count = (x) => Array.isArray(x) ? x.length : Object.values(x ?? {}).reduce((n, v) => n + Number(v || 0), 0);
|
|
2044
2174
|
async function targets(who) {
|
|
2045
2175
|
const { wallets } = await runtime();
|
|
@@ -2071,7 +2201,7 @@ async function report({ name, addresses: a }) {
|
|
|
2071
2201
|
}
|
|
2072
2202
|
const [p, tokens, venues, redemptions] = await Promise.all([
|
|
2073
2203
|
api.readPlayer(a.ao).catch(() => null),
|
|
2074
|
-
Promise.all(Object.entries(
|
|
2204
|
+
Promise.all(Object.entries(TOKENS).map(async ([t, id]) => [t, await readAtoms(id, `balance-${a.ao}`).catch(() => 0n)])),
|
|
2075
2205
|
Promise.all(Object.entries(VENUES).map(async ([v, pid]) => [
|
|
2076
2206
|
v,
|
|
2077
2207
|
await api.readVenuePosition(pid, a.ao).catch(() => null),
|
|
@@ -2089,6 +2219,7 @@ async function report({ name, addresses: a }) {
|
|
|
2089
2219
|
faction: p.faction,
|
|
2090
2220
|
gold: p.gold,
|
|
2091
2221
|
rune: p.inventory?.rune ?? 0,
|
|
2222
|
+
berries: Object.fromEntries(BERRIES2.map((b) => [b, p.inventory?.[b] ?? 0])),
|
|
2092
2223
|
companion: c && { name: c.name, level: c.level, exp: c.exp, energy: c.energy, happiness: c.happiness },
|
|
2093
2224
|
arena: { wins: p.wins ?? 0, losses: p.losses ?? 0, rating: p.rating, sessionBattlesLeft: p.battlesRemaining ?? 0 },
|
|
2094
2225
|
...p.battleFleet ? { inBattle: p.battleFleet.battleId } : {},
|
|
@@ -2099,7 +2230,7 @@ async function report({ name, addresses: a }) {
|
|
|
2099
2230
|
if (raw && Number(raw.exp ?? 0) >= Number(raw.nextLevelExp ?? Infinity)) todo.push("Companion can level up (game_level_up).");
|
|
2100
2231
|
if (c && (c.energy < 25 || c.happiness < 25)) todo.push("Companion is below the arena's 25 energy/happiness: feed or play.");
|
|
2101
2232
|
}
|
|
2102
|
-
const held = Object.fromEntries(tokens.filter(([, v]) => v > 0n).map(([t, v]) => [t, formatAtoms(v)]));
|
|
2233
|
+
const held = Object.fromEntries(tokens.filter(([, v]) => v > 0n).map(([t, v]) => [t, formatAtoms(v, TOKEN_DECIMALS[t] ?? 6)]));
|
|
2103
2234
|
if (Object.keys(held).length) out.tokens = held;
|
|
2104
2235
|
const trading = {};
|
|
2105
2236
|
for (const [v, pos, vaults] of venues) {
|
|
@@ -2123,7 +2254,7 @@ function registerProgress(server) {
|
|
|
2123
2254
|
tool(
|
|
2124
2255
|
server,
|
|
2125
2256
|
"progress",
|
|
2126
|
-
'How an agent is doing, in one free read: game (companion, Gold, Rune, arena record, live battle or hunt), tokens, open orders and vault shares on
|
|
2257
|
+
'How an agent is doing, in one free read: game (companion, Gold, Rune, berries, arena record, live battle or hunt), tokens, open orders and vault shares on the book, pending bridge redemptions, chain gas, and what needs doing next. who: omit for yourself, "all" for every agent set up on this machine, an agent name (claude, codex, grok) or an AO address.',
|
|
2127
2258
|
{ who: z8.string().optional() },
|
|
2128
2259
|
async ({ who }) => {
|
|
2129
2260
|
const list = await Promise.all((await targets(who)).map(report));
|
|
@@ -2135,35 +2266,38 @@ function registerProgress(server) {
|
|
|
2135
2266
|
|
|
2136
2267
|
// src/build.mjs
|
|
2137
2268
|
var DOCS = process.env.PARALITH_DOCS_URL || "https://docs.paralithmarkets.com";
|
|
2138
|
-
var INSTRUCTIONS = `Paralith on AO (HyperBEAM): Rune Realm (a companion game),
|
|
2139
|
-
|
|
2269
|
+
var INSTRUCTIONS = `Paralith on AO (HyperBEAM): Rune Realm (a companion game), an order book quoted in Gold, and the PUSD bridge.
|
|
2270
|
+
PUSD and the DAO are TEST deployments. Reads are free; every write is a signed message (a few seconds round trip, longer under load).
|
|
2140
2271
|
|
|
2141
2272
|
Start: wallet -> game_player. No account? game_join (pick a faction).
|
|
2142
2273
|
Core loop: game_daily once a day; game_companion feed/play keep energy and happiness up, quest then claim earns exp and Gold;
|
|
2143
2274
|
game_level_up when exp allows; game_learn_move when an offer is pending (it expires at the next level-up).
|
|
2144
2275
|
Arena: arena_enter (25 energy + 25 happiness, 4 fights), arena_fight mode=bot, then arena_attack each round
|
|
2145
2276
|
(read arena_battle for moves and uses left; Rally and Mend are free once each), arena_end leave when done.
|
|
2146
|
-
Hunt: hunt_begin (
|
|
2147
|
-
-> hunt_act search -> attack until defeated -> capture (1-3 Rune
|
|
2148
|
-
|
|
2277
|
+
Hunt: hunt_begin (25 energy + 25 happiness and 5 of each berry, not refunded; up to 3 Rune set aside and returned unless a capture spends them)
|
|
2278
|
+
-> hunt_act search -> attack until defeated -> capture (1-3 Rune) or end. One encounter per hunt.
|
|
2279
|
+
Game <-> wallet: asset_withdraw (in-game -> token; Gold at least 10) / asset_deposit (token -> in-game; needs a game account) for rune, gold and the four berries, whole units.
|
|
2280
|
+
Markets: exchange_markets / exchange_book / exchange_order on the one book: air, water, fire, rock and rune, each quoted in Gold.
|
|
2149
2281
|
Vaults (pooled liquidity, one amm/active/grid per market): vault_list, vault_position, vault_deposit, vault_shares (withdraw/lock/burn), vault_fund, vault_crank.
|
|
2150
|
-
|
|
2151
|
-
DAO (stake
|
|
2282
|
+
Bridge: bridge_balances, bridge_faucet, bridge_deposit, bridge_redeem.
|
|
2283
|
+
DAO (stake RUNE; a passed proposal may send one attached message): dao_info, dao_proposals, dao_stake stake/unstake/withdraw, dao_propose, dao_vote.
|
|
2152
2284
|
|
|
2153
2285
|
HOW RESOURCES FLOW. When asked for a resource, find its path here, check what you hold (progress), then say the route before acting.
|
|
2154
|
-
- Gold
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2286
|
+
- Rune, Gold and the four berries each exist twice: an in-game balance (what the game spends) and a wallet token (what the
|
|
2287
|
+
exchange trades). asset_withdraw and asset_deposit convert 1:1 in whole units; token fractions only come from trading.
|
|
2288
|
+
- Gold. Earn in game: quest claims and arena bot wins, which share one 60 Gold allowance per 20 h (play pays happiness only);
|
|
2289
|
+
selling berries or Rune to the shop (game_shop sell). On the exchange: sell a berry or Rune for the GOLD token.
|
|
2290
|
+
Spend: arena stakes, shop buys; GOLD token buys on the exchange.
|
|
2291
|
+
- Berries. Get: joining, crates (game_daily, game_lootbox), buying with Gold (game_shop); berry tokens from
|
|
2292
|
+
berry_claim (free, one berry kind per wallet per UTC day, 1-10 set by the hour) or the exchange. To use them in game,
|
|
2293
|
+
game_join first (a wallet with no account cannot deposit), then asset_deposit.
|
|
2294
|
+
Use: feed the companion, the hunt entry fee (5 of each berry), arena boosts.
|
|
2295
|
+
- Rune. Get: (1) the shop, only if game_shop_quote shows an ask (it often only bids); (2) sell a companion on companion_market;
|
|
2296
|
+
(3) the token route: berry_claim -> exchange_order sell the berry for GOLD -> exchange_order buy rune -> asset_deposit rune
|
|
2297
|
+
(the deposit needs a game account: game_join first).
|
|
2298
|
+
Public accounts accrue no Rune from game_daily (pass holders only).
|
|
2164
2299
|
Spend in-game Rune: game_level_up (ceil(L^2/32) for level L), hunt capture, companion_market buys, game_companion store (1 Rune).
|
|
2165
|
-
|
|
2166
|
-
- Element tokens (TEST-EARTH/AIR/FIRE/WATER): element_claim daily; trade against TEST-RUNE on the token venue; vault liquidity.
|
|
2300
|
+
RUNE token: exchange, vaults, dao_stake.
|
|
2167
2301
|
- PUSD: bridge in TEST-USDC from Base, Solana or Sui (needs that chain's gas, which the user funds; bridge_faucet gives TEST-USDC).
|
|
2168
2302
|
No PUSD market is listed yet. bridge_redeem waits for k attestor signatures and submits the release (needs destination-chain gas).
|
|
2169
2303
|
- Vaults: deposit both sides of a market to earn from its strategy; withdraw with vault_shares.
|
|
@@ -2179,14 +2313,14 @@ A refusal ({"error": ...}) costs nothing. Use game_catalog for exact costs and m
|
|
|
2179
2313
|
var READ_ONLY_INSTRUCTIONS = `This endpoint is READ-ONLY: it explains the protocol and reads live state for any address, free.
|
|
2180
2314
|
To play, trade or bridge, run the local server with a wallet phrase: ${DOCS}/ai/mcp
|
|
2181
2315
|
|
|
2182
|
-
Paralith on AO (HyperBEAM): Rune Realm (a companion game),
|
|
2183
|
-
|
|
2316
|
+
Paralith on AO (HyperBEAM): Rune Realm (a companion game), an order book quoted in Gold, and the PUSD bridge.
|
|
2317
|
+
PUSD and the DAO are TEST deployments. Pass an address wherever a tool takes one.
|
|
2184
2318
|
|
|
2185
2319
|
- Game: game_player (account, companions, live battle or hunt), game_catalog (rules, costs, move stats),
|
|
2186
2320
|
game_world (factions, arena tiers, open challenges, leaderboard), arena_battle (address or battle_id), hunt_state (address),
|
|
2187
2321
|
game_shop_quote (NPC shop prices and stock), companion_market_browse (listings and recent sales).
|
|
2188
|
-
- Markets: exchange_markets / exchange_book / exchange_position on
|
|
2189
|
-
vault_list, vault_position.
|
|
2322
|
+
- Markets: exchange_markets / exchange_book / exchange_position on the one book (air, water, fire, rock and rune, each quoted
|
|
2323
|
+
in Gold); vault_list, vault_position.
|
|
2190
2324
|
- Bridge and DAO: bridge_info, bridge_status, dao_info, dao_proposals, dao_stake_info.
|
|
2191
2325
|
- Anything else: progress (one address across everything), read_state (any published key), protocol_docs.
|
|
2192
2326
|
|
|
@@ -2202,15 +2336,15 @@ function buildServer() {
|
|
|
2202
2336
|
tool(
|
|
2203
2337
|
server,
|
|
2204
2338
|
"wallet",
|
|
2205
|
-
"Your addresses on AO, Base, Solana and Sui (all from one phrase) and your AO-side balances: in-game Gold and Rune,
|
|
2339
|
+
"Your addresses on AO, Base, Solana and Sui (all from one phrase) and your AO-side balances: in-game Gold, Rune and berries; the Rune, Gold and berry tokens; and PUSD. First call derives the AO key (~30 s, then cached).",
|
|
2206
2340
|
{},
|
|
2207
2341
|
async () => {
|
|
2208
2342
|
const { api, wallets } = await runtime();
|
|
2209
2343
|
const ao = wallets.ao.address;
|
|
2210
2344
|
const player3 = await api.readPlayer(ao).catch(() => null);
|
|
2211
2345
|
const tokens = {};
|
|
2212
|
-
for (const [name, id] of Object.entries(
|
|
2213
|
-
tokens[name] = formatAtoms(await readAtoms(id, `balance-${ao}`).catch(() => 0n));
|
|
2346
|
+
for (const [name, id] of Object.entries(TOKENS)) {
|
|
2347
|
+
tokens[name] = formatAtoms(await readAtoms(id, `balance-${ao}`).catch(() => 0n), TOKEN_DECIMALS[name] ?? 6);
|
|
2214
2348
|
}
|
|
2215
2349
|
return {
|
|
2216
2350
|
addresses: publicAddresses(wallets),
|
|
@@ -2224,7 +2358,7 @@ function buildServer() {
|
|
|
2224
2358
|
tool(
|
|
2225
2359
|
server,
|
|
2226
2360
|
"read_state",
|
|
2227
|
-
`Read any published key of any process, free: /<process>~process@1.0/now/<key>. process is an id or an alias (${Object.keys(PROCESS_ALIASES).join(", ")}). Returns null when absent. Common keys: game: player-<address>, catalogref (the catalog's id, not catalog), leaderboard, factions, arenatiers, challenges, economy, economybook, market, markethistory, battlefleet, huntconfig, access. rune and
|
|
2361
|
+
`Read any published key of any process, free: /<process>~process@1.0/now/<key>. process is an id or an alias (${Object.keys(PROCESS_ALIASES).join(", ")}). Returns null when absent. Common keys: game: player-<address>, catalogref (the catalog's id, not catalog), leaderboard, factions, arenatiers, challenges, economy, economybook, market, markethistory, battlefleet, huntconfig, access, assetprocesses, supply. Sharded, leaderboard, factions, users, arenatiers, economy, economybook, access and supply are each shard's own: read them from game-<shard> (the game_* tools merge them or pick yours). rune, gold and <berry>-token: balance-<address>, tokeninfo (not info), totalsupply. pusd: balance-<address>, bridgeinfo, withdrawals. dao: daoinfo, proposals. token-venue: balance-<address>, vaultinfo, vaultpairs.`,
|
|
2228
2362
|
{ process: z9.string(), key: z9.string() },
|
|
2229
2363
|
async ({ process: process2, key }) => readKey(process2, key),
|
|
2230
2364
|
READ
|