@sage-protocol/sdk 0.1.13 → 0.1.14
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/browser/index.mjs +289 -90
- package/dist/index.cjs +350 -91
- package/dist/index.mjs +350 -91
- package/dist/node/index.cjs +350 -91
- package/dist/node/index.mjs +350 -91
- package/package.json +2 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -14,7 +14,7 @@ var require_package = __commonJS({
|
|
|
14
14
|
"package.json"(exports, module) {
|
|
15
15
|
module.exports = {
|
|
16
16
|
name: "@sage-protocol/sdk",
|
|
17
|
-
version: "0.1.
|
|
17
|
+
version: "0.1.14",
|
|
18
18
|
description: "Backend-agnostic SDK for interacting with the Sage Protocol (governance, SubDAOs, tokens).",
|
|
19
19
|
main: "dist/index.cjs",
|
|
20
20
|
module: "dist/index.mjs",
|
|
@@ -70,6 +70,7 @@ var require_package = __commonJS({
|
|
|
70
70
|
release: "yarn build && npm publish --workspace @sage-protocol/sdk"
|
|
71
71
|
},
|
|
72
72
|
dependencies: {
|
|
73
|
+
"content-hash": "^2.5.2",
|
|
73
74
|
"@merit-systems/echo-typescript-sdk": "^1.0.17",
|
|
74
75
|
"@whetstone-research/doppler-sdk": "^0.0.1-alpha.40",
|
|
75
76
|
ai: "^3.2.3",
|
|
@@ -389,6 +390,32 @@ var require_utils = __commonJS({
|
|
|
389
390
|
var require_subgraph = __commonJS({
|
|
390
391
|
"src/browser/subgraph.js"(exports, module) {
|
|
391
392
|
var { getAddress } = require_utils();
|
|
393
|
+
function sanitizeOrderBy(orderBy, allowed, fallback) {
|
|
394
|
+
const value = (orderBy || "").toString();
|
|
395
|
+
return allowed.includes(value) ? value : fallback;
|
|
396
|
+
}
|
|
397
|
+
function sanitizeOrderDirection(direction, fallback = "desc") {
|
|
398
|
+
const v = (direction || "").toString().toLowerCase();
|
|
399
|
+
return v === "asc" ? "asc" : "desc";
|
|
400
|
+
}
|
|
401
|
+
function safeGetAddress(value) {
|
|
402
|
+
try {
|
|
403
|
+
return getAddress(value);
|
|
404
|
+
} catch {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function mapSafe(list, mapper) {
|
|
409
|
+
const out = [];
|
|
410
|
+
for (const item of list || []) {
|
|
411
|
+
try {
|
|
412
|
+
const v = mapper(item);
|
|
413
|
+
if (v != null) out.push(v);
|
|
414
|
+
} catch {
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return out;
|
|
418
|
+
}
|
|
392
419
|
async function query(url, document, variables) {
|
|
393
420
|
if (!url) throw new Error("subgraph url required");
|
|
394
421
|
const controller = new AbortController();
|
|
@@ -428,15 +455,21 @@ var require_subgraph = __commonJS({
|
|
|
428
455
|
}
|
|
429
456
|
}
|
|
430
457
|
`, { governor: String(governor).toLowerCase(), first, skip });
|
|
431
|
-
return (data?.proposals
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
458
|
+
return mapSafe(data?.proposals, (p) => {
|
|
459
|
+
const proposer = safeGetAddress(p.proposer);
|
|
460
|
+
if (!proposer) return null;
|
|
461
|
+
const targets = (p.targets || []).map((t) => safeGetAddress(t)).filter(Boolean);
|
|
462
|
+
if (!targets.length && (p.targets || []).length) return null;
|
|
463
|
+
return {
|
|
464
|
+
id: BigInt(p.id),
|
|
465
|
+
proposer,
|
|
466
|
+
description: p.description,
|
|
467
|
+
createdAt: Number(p.createdAt || 0),
|
|
468
|
+
targets,
|
|
469
|
+
values: (p.values || []).map((value) => BigInt(String(value))),
|
|
470
|
+
calldatas: p.calldatas || []
|
|
471
|
+
};
|
|
472
|
+
});
|
|
440
473
|
}
|
|
441
474
|
var STATE_STRING_TO_NUMBER = {
|
|
442
475
|
PENDING: 0,
|
|
@@ -453,6 +486,8 @@ var require_subgraph = __commonJS({
|
|
|
453
486
|
async function listProposalsFiltered({ url, governor, states, fromTimestamp, toTimestamp, first = 20, skip = 0, orderBy = "createdAt", orderDirection = "desc" }) {
|
|
454
487
|
const govLower = governor ? String(governor).toLowerCase() : null;
|
|
455
488
|
const statesUpper = Array.isArray(states) && states.length ? states.map((s) => String(s).toUpperCase()) : null;
|
|
489
|
+
const safeOrderBy = sanitizeOrderBy(orderBy, ["createdAt", "updatedAt", "eta"], "createdAt");
|
|
490
|
+
const safeOrderDirection = sanitizeOrderDirection(orderDirection, "desc");
|
|
456
491
|
const doc = `
|
|
457
492
|
query($first: Int!, $skip: Int!, $governor: Bytes, $states: [String!], $from: Int, $to: Int) {
|
|
458
493
|
proposals(
|
|
@@ -464,8 +499,8 @@ var require_subgraph = __commonJS({
|
|
|
464
499
|
}
|
|
465
500
|
first: $first
|
|
466
501
|
skip: $skip
|
|
467
|
-
orderBy: ${
|
|
468
|
-
orderDirection: ${
|
|
502
|
+
orderBy: ${safeOrderBy}
|
|
503
|
+
orderDirection: ${safeOrderDirection}
|
|
469
504
|
) {
|
|
470
505
|
id
|
|
471
506
|
proposer
|
|
@@ -486,19 +521,23 @@ var require_subgraph = __commonJS({
|
|
|
486
521
|
if (fromTimestamp !== void 0) variables.from = Number(fromTimestamp);
|
|
487
522
|
if (toTimestamp !== void 0) variables.to = Number(toTimestamp);
|
|
488
523
|
const data = await query(url, doc, variables);
|
|
489
|
-
return (data?.proposals
|
|
524
|
+
return mapSafe(data?.proposals, (p) => {
|
|
490
525
|
const stateStr = String(p.state || "").toUpperCase();
|
|
491
526
|
const stateNum = STATE_STRING_TO_NUMBER[stateStr] != null ? STATE_STRING_TO_NUMBER[stateStr] : null;
|
|
527
|
+
const proposer = safeGetAddress(p.proposer);
|
|
528
|
+
if (!proposer) return null;
|
|
529
|
+
const targets = (p.targets || []).map((t) => safeGetAddress(t)).filter(Boolean);
|
|
530
|
+
if (!targets.length && (p.targets || []).length) return null;
|
|
492
531
|
return {
|
|
493
532
|
id: BigInt(p.id),
|
|
494
|
-
proposer
|
|
533
|
+
proposer,
|
|
495
534
|
description: p.description || "",
|
|
496
535
|
createdAt: Number(p.createdAt || 0),
|
|
497
536
|
updatedAt: Number(p.updatedAt || 0),
|
|
498
537
|
state: stateStr,
|
|
499
538
|
stateNum,
|
|
500
539
|
eta: p.eta ? BigInt(String(p.eta)) : null,
|
|
501
|
-
targets
|
|
540
|
+
targets,
|
|
502
541
|
values: (p.values || []).map((value) => BigInt(String(value))),
|
|
503
542
|
calldatas: p.calldatas || []
|
|
504
543
|
};
|
|
@@ -517,19 +556,120 @@ var require_subgraph = __commonJS({
|
|
|
517
556
|
}
|
|
518
557
|
}
|
|
519
558
|
`, { first, skip });
|
|
520
|
-
return (data?.libraries
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
559
|
+
return mapSafe(data?.libraries, (lib) => {
|
|
560
|
+
const sub = safeGetAddress(lib.subDAO);
|
|
561
|
+
const proposer = safeGetAddress(lib.proposer);
|
|
562
|
+
if (!sub || !proposer) return null;
|
|
563
|
+
return {
|
|
564
|
+
id: lib.id,
|
|
565
|
+
manifestCID: lib.manifestCID,
|
|
566
|
+
subdao: sub,
|
|
567
|
+
proposer,
|
|
568
|
+
createdAt: Number(lib.createdAt || 0)
|
|
569
|
+
};
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
async function getSubdaoLibraries({ url, subdao, first = 20, skip = 0 }) {
|
|
573
|
+
if (!url) throw new Error("subgraph url required");
|
|
574
|
+
const hasFilter = !!subdao;
|
|
575
|
+
const whereClause = hasFilter ? "where:{ subdao:$subdao }" : "";
|
|
576
|
+
const doc = `
|
|
577
|
+
query($subdao:Bytes,$first:Int!,$skip:Int!){
|
|
578
|
+
subDAOLibraryPointers(
|
|
579
|
+
${whereClause}
|
|
580
|
+
first:$first,
|
|
581
|
+
skip:$skip,
|
|
582
|
+
orderBy: updatedAt,
|
|
583
|
+
orderDirection: desc
|
|
584
|
+
){
|
|
585
|
+
id
|
|
586
|
+
subdao
|
|
587
|
+
libraryId
|
|
588
|
+
manifestCID
|
|
589
|
+
previousCID
|
|
590
|
+
promptCount
|
|
591
|
+
updatedAt
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
`;
|
|
595
|
+
const variables = {
|
|
596
|
+
first: Math.min(Math.max(1, Number(first || 20)), 100),
|
|
597
|
+
skip
|
|
598
|
+
};
|
|
599
|
+
if (hasFilter) {
|
|
600
|
+
const addr = safeGetAddress(subdao);
|
|
601
|
+
if (!addr) throw new Error("invalid subdao address");
|
|
602
|
+
variables.subdao = addr.toLowerCase();
|
|
603
|
+
}
|
|
604
|
+
const data = await query(url, doc, variables);
|
|
605
|
+
return mapSafe(data?.subDAOLibraryPointers, (row) => {
|
|
606
|
+
const id = row?.id;
|
|
607
|
+
const manifestCID = row?.manifestCID;
|
|
608
|
+
const sub = safeGetAddress(row?.subdao);
|
|
609
|
+
if (!id || !manifestCID || !sub) return null;
|
|
610
|
+
return {
|
|
611
|
+
id: String(id),
|
|
612
|
+
subdao: sub,
|
|
613
|
+
libraryId: String(row.libraryId || "main"),
|
|
614
|
+
manifestCID: String(manifestCID),
|
|
615
|
+
previousCID: row.previousCID || null,
|
|
616
|
+
promptCount: row.promptCount != null ? Number(row.promptCount) : null,
|
|
617
|
+
updatedAt: row.updatedAt != null ? Number(row.updatedAt) : null
|
|
618
|
+
};
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
async function getSubdaoPrompts({ url, registry, first = 50, skip = 0, orderBy = "updatedAt", orderDirection = "desc" }) {
|
|
622
|
+
if (!url) throw new Error("subgraph url required");
|
|
623
|
+
const reg = safeGetAddress(registry);
|
|
624
|
+
if (!reg) throw new Error("invalid registry address");
|
|
625
|
+
const safeOrderBy = sanitizeOrderBy(orderBy, ["updatedAt"], "updatedAt");
|
|
626
|
+
const safeOrderDirection = sanitizeOrderDirection(orderDirection, "desc");
|
|
627
|
+
const doc = `
|
|
628
|
+
query($registry:Bytes!,$first:Int!,$skip:Int!){
|
|
629
|
+
prompts(
|
|
630
|
+
where:{ registry:$registry },
|
|
631
|
+
first:$first,
|
|
632
|
+
skip:$skip,
|
|
633
|
+
orderBy: ${safeOrderBy},
|
|
634
|
+
orderDirection: ${safeOrderDirection}
|
|
635
|
+
){
|
|
636
|
+
id
|
|
637
|
+
key
|
|
638
|
+
cid
|
|
639
|
+
version
|
|
640
|
+
author
|
|
641
|
+
registry
|
|
642
|
+
updatedAt
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
`;
|
|
646
|
+
const data = await query(url, doc, {
|
|
647
|
+
registry: reg.toLowerCase(),
|
|
648
|
+
first: Math.min(Math.max(1, Number(first || 50)), 100),
|
|
649
|
+
skip
|
|
650
|
+
});
|
|
651
|
+
return mapSafe(data?.prompts, (p) => {
|
|
652
|
+
const author = safeGetAddress(p.author);
|
|
653
|
+
const regAddr = safeGetAddress(p.registry);
|
|
654
|
+
if (!author || !regAddr) return null;
|
|
655
|
+
return {
|
|
656
|
+
id: String(p.id),
|
|
657
|
+
key: String(p.key),
|
|
658
|
+
cid: String(p.cid),
|
|
659
|
+
version: BigInt(p.version || "0"),
|
|
660
|
+
author,
|
|
661
|
+
registry: regAddr,
|
|
662
|
+
updatedAt: Number(p.updatedAt || 0)
|
|
663
|
+
};
|
|
664
|
+
});
|
|
527
665
|
}
|
|
528
666
|
module.exports = {
|
|
529
667
|
query,
|
|
530
668
|
listProposals,
|
|
531
669
|
listProposalsFiltered,
|
|
532
670
|
listLibraries,
|
|
671
|
+
getSubdaoLibraries,
|
|
672
|
+
getSubdaoPrompts,
|
|
533
673
|
/**
|
|
534
674
|
* Canonical proposal timeline. Tries common fields first, then event-style fallbacks.
|
|
535
675
|
* Returns { id, createdAt, queuedAt, executedAt, canceledAt, eta, state } (numbers/strings may be null when unavailable).
|
|
@@ -595,86 +735,127 @@ var require_subgraph = __commonJS({
|
|
|
595
735
|
async listLiquidityAddPlans({ url, subdao = null, first = 50, skip = 0, orderBy = "blockTimestamp", orderDirection = "desc" }) {
|
|
596
736
|
if (!url) throw new Error("subgraph url required");
|
|
597
737
|
const filters = [];
|
|
598
|
-
if (subdao)
|
|
738
|
+
if (subdao) {
|
|
739
|
+
const addr = safeGetAddress(subdao);
|
|
740
|
+
if (!addr) throw new Error("invalid subdao address");
|
|
741
|
+
filters.push(`subdao: "${addr.toLowerCase()}"`);
|
|
742
|
+
}
|
|
599
743
|
const where = filters.length ? `where: { ${filters.join(", ")} }` : "";
|
|
744
|
+
const safeOrderBy = sanitizeOrderBy(orderBy, ["blockTimestamp", "blockNumber"], "blockTimestamp");
|
|
745
|
+
const safeOrderDirection = sanitizeOrderDirection(orderDirection, "desc");
|
|
600
746
|
const doc = `
|
|
601
747
|
query($first:Int!,$skip:Int!){
|
|
602
|
-
liquidityAddPlans(${where} first:$first, skip:$skip, orderBy: ${
|
|
748
|
+
liquidityAddPlans(${where} first:$first, skip:$skip, orderBy: ${safeOrderBy}, orderDirection: ${safeOrderDirection}){
|
|
603
749
|
id subdao pool sxxxToken stableToken sxxxAmount stableAmount lpRecipient blockNumber blockTimestamp transactionHash
|
|
604
750
|
}
|
|
605
751
|
}
|
|
606
752
|
`;
|
|
607
753
|
const data = await query(url, doc, { first, skip });
|
|
608
|
-
return (data?.liquidityAddPlans
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
754
|
+
return mapSafe(data?.liquidityAddPlans, (e) => {
|
|
755
|
+
const sub = safeGetAddress(e.subdao);
|
|
756
|
+
const pool = safeGetAddress(e.pool);
|
|
757
|
+
const sxxxToken = safeGetAddress(e.sxxxToken);
|
|
758
|
+
const stableToken = safeGetAddress(e.stableToken);
|
|
759
|
+
const lpRecipient = safeGetAddress(e.lpRecipient);
|
|
760
|
+
if (!sub || !pool || !sxxxToken || !stableToken || !lpRecipient) return null;
|
|
761
|
+
return {
|
|
762
|
+
id: String(e.id),
|
|
763
|
+
subdao: sub,
|
|
764
|
+
pool,
|
|
765
|
+
sxxxToken,
|
|
766
|
+
stableToken,
|
|
767
|
+
sxxxAmount: BigInt(String(e.sxxxAmount)),
|
|
768
|
+
stableAmount: BigInt(String(e.stableAmount)),
|
|
769
|
+
lpRecipient,
|
|
770
|
+
blockNumber: Number(e.blockNumber || 0),
|
|
771
|
+
blockTimestamp: Number(e.blockTimestamp || 0),
|
|
772
|
+
transactionHash: e.transactionHash
|
|
773
|
+
};
|
|
774
|
+
});
|
|
621
775
|
},
|
|
622
776
|
async listLiquidityRemovePlans({ url, subdao = null, first = 50, skip = 0, orderBy = "blockTimestamp", orderDirection = "desc" }) {
|
|
623
777
|
if (!url) throw new Error("subgraph url required");
|
|
624
778
|
const filters = [];
|
|
625
|
-
if (subdao)
|
|
779
|
+
if (subdao) {
|
|
780
|
+
const addr = safeGetAddress(subdao);
|
|
781
|
+
if (!addr) throw new Error("invalid subdao address");
|
|
782
|
+
filters.push(`subdao: "${addr.toLowerCase()}"`);
|
|
783
|
+
}
|
|
626
784
|
const where = filters.length ? `where: { ${filters.join(", ")} }` : "";
|
|
785
|
+
const safeOrderBy = sanitizeOrderBy(orderBy, ["blockTimestamp", "blockNumber"], "blockTimestamp");
|
|
786
|
+
const safeOrderDirection = sanitizeOrderDirection(orderDirection, "desc");
|
|
627
787
|
const doc = `
|
|
628
788
|
query($first:Int!,$skip:Int!){
|
|
629
|
-
liquidityRemovePlans(${where} first:$first, skip:$skip, orderBy: ${
|
|
789
|
+
liquidityRemovePlans(${where} first:$first, skip:$skip, orderBy: ${safeOrderBy}, orderDirection: ${safeOrderDirection}){
|
|
630
790
|
id subdao pool lpToken lpAmount recipient blockNumber blockTimestamp transactionHash
|
|
631
791
|
}
|
|
632
792
|
}
|
|
633
793
|
`;
|
|
634
794
|
const data = await query(url, doc, { first, skip });
|
|
635
|
-
return (data?.liquidityRemovePlans
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
795
|
+
return mapSafe(data?.liquidityRemovePlans, (e) => {
|
|
796
|
+
const sub = safeGetAddress(e.subdao);
|
|
797
|
+
const pool = safeGetAddress(e.pool);
|
|
798
|
+
const lpToken = safeGetAddress(e.lpToken);
|
|
799
|
+
const recipient = safeGetAddress(e.recipient);
|
|
800
|
+
if (!sub || !pool || !lpToken || !recipient) return null;
|
|
801
|
+
return {
|
|
802
|
+
id: String(e.id),
|
|
803
|
+
subdao: sub,
|
|
804
|
+
pool,
|
|
805
|
+
lpToken,
|
|
806
|
+
lpAmount: BigInt(String(e.lpAmount)),
|
|
807
|
+
recipient,
|
|
808
|
+
blockNumber: Number(e.blockNumber || 0),
|
|
809
|
+
blockTimestamp: Number(e.blockTimestamp || 0),
|
|
810
|
+
transactionHash: e.transactionHash
|
|
811
|
+
};
|
|
812
|
+
});
|
|
646
813
|
},
|
|
647
814
|
async listPromptsByTag({ url, tagsHash, registry = null, first = 50, skip = 0, orderBy = "updatedAt", orderDirection = "desc" }) {
|
|
648
815
|
if (!url) throw new Error("subgraph url required");
|
|
649
816
|
const clauses = [`tagsHash: "${String(tagsHash)}"`];
|
|
650
|
-
if (registry)
|
|
817
|
+
if (registry) {
|
|
818
|
+
const addr = safeGetAddress(registry);
|
|
819
|
+
if (!addr) throw new Error("invalid registry address");
|
|
820
|
+
clauses.push(`registry: "${addr.toLowerCase()}"`);
|
|
821
|
+
}
|
|
651
822
|
const where = `where: { ${clauses.join(", ")} }`;
|
|
823
|
+
const safeOrderBy = sanitizeOrderBy(orderBy, ["updatedAt"], "updatedAt");
|
|
824
|
+
const safeOrderDirection = sanitizeOrderDirection(orderDirection, "desc");
|
|
652
825
|
const doc = `
|
|
653
826
|
query($first:Int!,$skip:Int!) {
|
|
654
|
-
prompts(${where} first:$first, skip:$skip, orderBy: ${
|
|
827
|
+
prompts(${where} first:$first, skip:$skip, orderBy: ${safeOrderBy}, orderDirection: ${safeOrderDirection}) {
|
|
655
828
|
id key cid version author registry updatedAt tagsHash
|
|
656
829
|
}
|
|
657
830
|
}
|
|
658
831
|
`;
|
|
659
832
|
const data = await query(url, doc, { first, skip });
|
|
660
|
-
return (data?.prompts
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
833
|
+
return mapSafe(data?.prompts, (p) => {
|
|
834
|
+
const author = safeGetAddress(p.author);
|
|
835
|
+
const regAddr = safeGetAddress(p.registry);
|
|
836
|
+
if (!author || !regAddr) return null;
|
|
837
|
+
return {
|
|
838
|
+
id: String(p.id),
|
|
839
|
+
key: String(p.key),
|
|
840
|
+
cid: String(p.cid),
|
|
841
|
+
version: BigInt(p.version || "0"),
|
|
842
|
+
author,
|
|
843
|
+
registry: regAddr,
|
|
844
|
+
updatedAt: Number(p.updatedAt || 0),
|
|
845
|
+
tagsHash: String(p.tagsHash || "")
|
|
846
|
+
};
|
|
847
|
+
});
|
|
670
848
|
},
|
|
671
849
|
// Prompt helpers (registry scoped)
|
|
672
850
|
async listRegistryPrompts({ url, registry, first = 50, skip = 0, orderBy = "updatedAt", orderDirection = "desc" }) {
|
|
673
851
|
if (!url) throw new Error("subgraph url required");
|
|
674
|
-
const reg =
|
|
852
|
+
const reg = safeGetAddress(registry);
|
|
853
|
+
if (!reg) throw new Error("invalid registry address");
|
|
854
|
+
const safeOrderBy = sanitizeOrderBy(orderBy, ["updatedAt"], "updatedAt");
|
|
855
|
+
const safeOrderDirection = sanitizeOrderDirection(orderDirection, "desc");
|
|
675
856
|
const doc = `
|
|
676
857
|
query($first:Int!,$skip:Int!,$registry:Bytes!) {
|
|
677
|
-
prompts(where:{ registry: $registry }, first:$first, skip:$skip, orderBy: ${
|
|
858
|
+
prompts(where:{ registry: $registry }, first:$first, skip:$skip, orderBy: ${safeOrderBy}, orderDirection: ${safeOrderDirection}) {
|
|
678
859
|
id
|
|
679
860
|
key
|
|
680
861
|
cid
|
|
@@ -686,19 +867,25 @@ var require_subgraph = __commonJS({
|
|
|
686
867
|
}
|
|
687
868
|
`;
|
|
688
869
|
const data = await query(url, doc, { first, skip, registry: reg.toLowerCase() });
|
|
689
|
-
return (data?.prompts
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
870
|
+
return mapSafe(data?.prompts, (p) => {
|
|
871
|
+
const author = safeGetAddress(p.author);
|
|
872
|
+
const regAddr = safeGetAddress(p.registry);
|
|
873
|
+
if (!author || !regAddr) return null;
|
|
874
|
+
return {
|
|
875
|
+
id: String(p.id),
|
|
876
|
+
key: String(p.key),
|
|
877
|
+
cid: String(p.cid),
|
|
878
|
+
version: BigInt(p.version || "0"),
|
|
879
|
+
author,
|
|
880
|
+
registry: regAddr,
|
|
881
|
+
updatedAt: Number(p.updatedAt || 0)
|
|
882
|
+
};
|
|
883
|
+
});
|
|
698
884
|
},
|
|
699
885
|
async getPromptByKey({ url, registry, key }) {
|
|
700
886
|
if (!url) throw new Error("subgraph url required");
|
|
701
|
-
const reg =
|
|
887
|
+
const reg = safeGetAddress(registry);
|
|
888
|
+
if (!reg) throw new Error("invalid registry address");
|
|
702
889
|
const doc = `
|
|
703
890
|
query($registry:Bytes!,$key:String!) {
|
|
704
891
|
prompts(where:{ registry: $registry, key: $key }, first:1) {
|
|
@@ -714,15 +901,19 @@ var require_subgraph = __commonJS({
|
|
|
714
901
|
`;
|
|
715
902
|
const data = await query(url, doc, { registry: reg.toLowerCase(), key: String(key) });
|
|
716
903
|
const p = (data?.prompts || [])[0];
|
|
717
|
-
|
|
904
|
+
if (!p) return null;
|
|
905
|
+
const author = safeGetAddress(p.author);
|
|
906
|
+
const regAddr = safeGetAddress(p.registry);
|
|
907
|
+
if (!author || !regAddr) return null;
|
|
908
|
+
return {
|
|
718
909
|
id: String(p.id),
|
|
719
910
|
key: String(p.key),
|
|
720
911
|
cid: String(p.cid),
|
|
721
912
|
version: BigInt(p.version || "0"),
|
|
722
|
-
author
|
|
723
|
-
registry:
|
|
913
|
+
author,
|
|
914
|
+
registry: regAddr,
|
|
724
915
|
updatedAt: Number(p.updatedAt || 0)
|
|
725
|
-
}
|
|
916
|
+
};
|
|
726
917
|
},
|
|
727
918
|
async getProposalById({ url, id }) {
|
|
728
919
|
if (!url) throw new Error("subgraph url required");
|
|
@@ -730,18 +921,26 @@ var require_subgraph = __commonJS({
|
|
|
730
921
|
const data = await query(url, doc, { id: String(id) });
|
|
731
922
|
const p = data?.proposal;
|
|
732
923
|
if (!p) return null;
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
924
|
+
try {
|
|
925
|
+
const proposer = safeGetAddress(p.proposer);
|
|
926
|
+
if (!proposer) return null;
|
|
927
|
+
const targets = (p.targets || []).map((t) => safeGetAddress(t)).filter(Boolean);
|
|
928
|
+
if (!targets.length && (p.targets || []).length) return null;
|
|
929
|
+
return {
|
|
930
|
+
id: BigInt(p.id),
|
|
931
|
+
proposer,
|
|
932
|
+
description: p.description || "",
|
|
933
|
+
createdAt: Number(p.createdAt || 0),
|
|
934
|
+
updatedAt: Number(p.updatedAt || 0),
|
|
935
|
+
state: String(p.state || ""),
|
|
936
|
+
eta: p.eta ? BigInt(String(p.eta)) : null,
|
|
937
|
+
targets,
|
|
938
|
+
values: (p.values || []).map((v) => BigInt(String(v))),
|
|
939
|
+
calldatas: p.calldatas || []
|
|
940
|
+
};
|
|
941
|
+
} catch {
|
|
942
|
+
return null;
|
|
943
|
+
}
|
|
745
944
|
}
|
|
746
945
|
};
|
|
747
946
|
}
|