@sage-protocol/sdk 0.2.3 → 0.2.5
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 +1 -0
- package/dist/browser/index.mjs +16 -11
- package/dist/index.cjs +346 -41
- package/dist/index.mjs +346 -41
- package/dist/node/index.cjs +346 -41
- package/dist/node/index.mjs +346 -41
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -20,7 +20,7 @@ var require_package = __commonJS({
|
|
|
20
20
|
"package.json"(exports2, module2) {
|
|
21
21
|
module2.exports = {
|
|
22
22
|
name: "@sage-protocol/sdk",
|
|
23
|
-
version: "0.2.
|
|
23
|
+
version: "0.2.5",
|
|
24
24
|
description: "Backend-agnostic SDK for interacting with the Sage Protocol (governance, SubDAOs, tokens).",
|
|
25
25
|
main: "dist/index.cjs",
|
|
26
26
|
module: "dist/index.mjs",
|
|
@@ -86,7 +86,7 @@ var require_package = __commonJS({
|
|
|
86
86
|
},
|
|
87
87
|
devDependencies: {
|
|
88
88
|
proxyquire: "^2.1.3",
|
|
89
|
-
sinon: "^
|
|
89
|
+
sinon: "^21.0.0",
|
|
90
90
|
tsup: "^8.1.0",
|
|
91
91
|
typescript: "^5.4.0"
|
|
92
92
|
},
|
|
@@ -186,15 +186,21 @@ var require_abi = __commonJS({
|
|
|
186
186
|
"function libraryByDAO(address) view returns (string manifestCID, address lastUpdater, uint256 lastUpdated, string version, address forkedFromDAO, uint256 sxxxForkFee, uint256 nonce)",
|
|
187
187
|
"function daoTimelock(address) view returns (address)",
|
|
188
188
|
"function getLibrary(address) view returns (tuple(string manifestCID, address lastUpdater, uint256 lastUpdated, string version, address forkedFromDAO, uint256 sxxxForkFee, uint256 nonce))",
|
|
189
|
+
"function getLibraryIds(address dao) view returns (bytes32[] memory)",
|
|
190
|
+
"function getLibraryStream(address dao, string libraryId) view returns (tuple(string manifestCID, address lastUpdater, uint256 lastUpdated, string version, address forkedFromDAO, uint256 sxxxForkFee, uint256 nonce))",
|
|
189
191
|
"function getLibraryForkFee(address dao) view returns (uint256)",
|
|
190
192
|
"function setLibraryForkFee(address dao, uint256 fee)",
|
|
191
193
|
"function updateLibrary(address dao, string manifestCID, string version)",
|
|
192
194
|
"function updateLibraryCAS(address dao, string manifestCID, string version, uint256 expectedNonce)",
|
|
195
|
+
"function updateLibraryStream(address dao, string libraryId, string manifestCID, string version)",
|
|
196
|
+
"function updateLibraryStreamCAS(address dao, string libraryId, string manifestCID, string version, uint256 expectedNonce)",
|
|
193
197
|
"function registerDAO(address dao, address timelock)",
|
|
194
198
|
"function registerForkedDAO(address childDAO, address childTimelock, address parentDAO, string manifestCID, string version)",
|
|
195
199
|
"function initializeLibraryFromFork(address sourceDao, address forkedDao)",
|
|
196
200
|
"event LibraryUpdated(address indexed dao, string manifestCID, address indexed timelock, string version, uint256 nonce)",
|
|
197
|
-
"event DAORegistered(address indexed dao, address indexed timelock)",
|
|
201
|
+
"event DAORegistered(address indexed dao, address indexed timelock, address indexed creator)",
|
|
202
|
+
"event LibraryCreated(address indexed dao, bytes32 indexed libraryIdHash, string libraryId, address indexed creator)",
|
|
203
|
+
"event LibraryStreamUpdated(address indexed dao, bytes32 indexed libraryIdHash, string libraryId, string manifestCID, address indexed updater, string version, uint256 nonce)",
|
|
198
204
|
"event LibraryForked(address indexed sourceDao, address indexed forkedDao, string manifestCID)",
|
|
199
205
|
"event LibraryForkFeeUpdated(address indexed dao, uint256 fee)",
|
|
200
206
|
"error NonceMismatch(uint256 expected, uint256 actual)"
|
|
@@ -798,7 +804,7 @@ var require_subgraph = __commonJS({
|
|
|
798
804
|
const whereClause = hasFilter ? "where:{ subdao:$subdao }" : "";
|
|
799
805
|
const doc = `
|
|
800
806
|
query($subdao:Bytes,$first:Int!,$skip:Int!){
|
|
801
|
-
|
|
807
|
+
libraryProjects(
|
|
802
808
|
${whereClause}
|
|
803
809
|
first:$first,
|
|
804
810
|
skip:$skip,
|
|
@@ -807,14 +813,10 @@ var require_subgraph = __commonJS({
|
|
|
807
813
|
){
|
|
808
814
|
id
|
|
809
815
|
subdao
|
|
810
|
-
libraryId
|
|
811
816
|
manifestCID
|
|
812
|
-
|
|
813
|
-
|
|
817
|
+
version
|
|
818
|
+
nonce
|
|
814
819
|
updatedAt
|
|
815
|
-
createdAt
|
|
816
|
-
blockNumber
|
|
817
|
-
blockTimestamp
|
|
818
820
|
}
|
|
819
821
|
}
|
|
820
822
|
`;
|
|
@@ -828,23 +830,24 @@ var require_subgraph = __commonJS({
|
|
|
828
830
|
variables.subdao = addr.toLowerCase();
|
|
829
831
|
}
|
|
830
832
|
const data = await query(url, doc, variables);
|
|
831
|
-
return mapSafe(data?.
|
|
833
|
+
return mapSafe(data?.libraryProjects, (row) => {
|
|
832
834
|
const id2 = row?.id;
|
|
833
835
|
const manifestCID = row?.manifestCID;
|
|
834
836
|
const sub = safeGetAddress(row?.subdao);
|
|
835
837
|
if (!id2 || !manifestCID || !sub) return null;
|
|
836
|
-
const timestamp = (row.updatedAt != null ? Number(row.updatedAt) : null) || (row.createdAt != null ? Number(row.createdAt) : null) || (row.blockTimestamp != null ? Number(row.blockTimestamp) : null);
|
|
837
838
|
return {
|
|
838
839
|
id: String(id2),
|
|
839
840
|
subdao: sub,
|
|
840
|
-
libraryId: String(
|
|
841
|
+
libraryId: String(id2),
|
|
841
842
|
manifestCID: String(manifestCID),
|
|
842
|
-
previousCID:
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
843
|
+
previousCID: null,
|
|
844
|
+
// LibraryProject doesn't track previous CID
|
|
845
|
+
promptCount: null,
|
|
846
|
+
// LibraryProject doesn't track prompt count
|
|
847
|
+
updatedAt: row.updatedAt != null ? Number(row.updatedAt) : null,
|
|
848
|
+
createdAt: null,
|
|
849
|
+
blockNumber: null,
|
|
850
|
+
blockTimestamp: null
|
|
848
851
|
};
|
|
849
852
|
});
|
|
850
853
|
}
|
|
@@ -2130,7 +2133,7 @@ var require_subgraph2 = __commonJS({
|
|
|
2130
2133
|
const whereClause = hasFilter ? "where:{ subdao:$subdao }" : "";
|
|
2131
2134
|
const doc = `
|
|
2132
2135
|
query($subdao:Bytes,$first:Int!,$skip:Int!){
|
|
2133
|
-
|
|
2136
|
+
libraryProjects(
|
|
2134
2137
|
${whereClause}
|
|
2135
2138
|
first:$first,
|
|
2136
2139
|
skip:$skip,
|
|
@@ -2139,10 +2142,9 @@ var require_subgraph2 = __commonJS({
|
|
|
2139
2142
|
){
|
|
2140
2143
|
id
|
|
2141
2144
|
subdao
|
|
2142
|
-
libraryId
|
|
2143
2145
|
manifestCID
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
+
version
|
|
2147
|
+
nonce
|
|
2146
2148
|
updatedAt
|
|
2147
2149
|
}
|
|
2148
2150
|
}
|
|
@@ -2157,7 +2159,7 @@ var require_subgraph2 = __commonJS({
|
|
|
2157
2159
|
variables.subdao = addr.toLowerCase();
|
|
2158
2160
|
}
|
|
2159
2161
|
const data = await query(url, doc, variables);
|
|
2160
|
-
return mapSafe(data?.
|
|
2162
|
+
return mapSafe(data?.libraryProjects, (row) => {
|
|
2161
2163
|
const id2 = row?.id;
|
|
2162
2164
|
const manifestCID = row?.manifestCID;
|
|
2163
2165
|
const sub = safeGetAddress(row?.subdao);
|
|
@@ -2165,10 +2167,10 @@ var require_subgraph2 = __commonJS({
|
|
|
2165
2167
|
return {
|
|
2166
2168
|
id: String(id2),
|
|
2167
2169
|
subdao: sub,
|
|
2168
|
-
libraryId: String(
|
|
2170
|
+
libraryId: String(id2),
|
|
2169
2171
|
manifestCID: String(manifestCID),
|
|
2170
|
-
previousCID:
|
|
2171
|
-
promptCount:
|
|
2172
|
+
previousCID: null,
|
|
2173
|
+
promptCount: null,
|
|
2172
2174
|
updatedAt: row.updatedAt != null ? Number(row.updatedAt) : null
|
|
2173
2175
|
};
|
|
2174
2176
|
});
|
|
@@ -3831,6 +3833,16 @@ var require_library = __commonJS({
|
|
|
3831
3833
|
throw new SageSDKError(CODES.INVALID_ARGS, `invalid ${label}`, { cause: err });
|
|
3832
3834
|
}
|
|
3833
3835
|
}
|
|
3836
|
+
function normaliseLibraryId(libraryId) {
|
|
3837
|
+
const raw = (libraryId == null ? "" : String(libraryId)).trim().toLowerCase();
|
|
3838
|
+
if (!raw) return "default";
|
|
3839
|
+
if (raw === "main") return "default";
|
|
3840
|
+
const ok = /^[a-z0-9]([a-z0-9-]{0,62}[a-z0-9])?$/.test(raw) && !raw.includes("--");
|
|
3841
|
+
if (!ok) {
|
|
3842
|
+
throw new SageSDKError(CODES.INVALID_ARGS, `invalid libraryId`, { libraryId });
|
|
3843
|
+
}
|
|
3844
|
+
return raw;
|
|
3845
|
+
}
|
|
3834
3846
|
async function listManifests({ provider, registry, factoryAddress, offset = 0, limit = 50 }) {
|
|
3835
3847
|
if (!provider) throw new SageSDKError(CODES.INVALID_ARGS, "provider required");
|
|
3836
3848
|
if (!factoryAddress) throw new SageSDKError(CODES.INVALID_ARGS, "factoryAddress required for V4 listing");
|
|
@@ -3869,6 +3881,35 @@ var require_library = __commonJS({
|
|
|
3869
3881
|
sxxxForkFee: BigInt(info.sxxxForkFee.toString())
|
|
3870
3882
|
};
|
|
3871
3883
|
}
|
|
3884
|
+
async function getLibraryStreamInfo({ provider, registry, subdao, libraryId = "default" }) {
|
|
3885
|
+
if (!provider) throw new SageSDKError(CODES.INVALID_ARGS, "provider required");
|
|
3886
|
+
if (!subdao) throw new SageSDKError(CODES.INVALID_ARGS, "subdao required");
|
|
3887
|
+
const addr = normalise(registry, "registry");
|
|
3888
|
+
const dao = normalise(subdao, "subdao");
|
|
3889
|
+
const libId = normaliseLibraryId(libraryId);
|
|
3890
|
+
const contract = new Contract(addr, ABI.LibraryRegistry, provider);
|
|
3891
|
+
const info = await contract.getLibraryStream(dao, libId);
|
|
3892
|
+
return {
|
|
3893
|
+
libraryId: libId,
|
|
3894
|
+
manifestCID: info.manifestCID,
|
|
3895
|
+
previousCID: "",
|
|
3896
|
+
timestamp: BigInt(info.lastUpdated.toString()),
|
|
3897
|
+
proposer: getAddress(info.lastUpdater),
|
|
3898
|
+
promptCount: 0,
|
|
3899
|
+
version: info.version,
|
|
3900
|
+
nonce: BigInt(info.nonce.toString()),
|
|
3901
|
+
forkedFromDAO: info.forkedFromDAO && info.forkedFromDAO !== "0x0000000000000000000000000000000000000000" ? getAddress(info.forkedFromDAO) : null,
|
|
3902
|
+
sxxxForkFee: BigInt(info.sxxxForkFee.toString())
|
|
3903
|
+
};
|
|
3904
|
+
}
|
|
3905
|
+
async function getLibraryIds({ provider, registry, subdao }) {
|
|
3906
|
+
if (!provider) throw new SageSDKError(CODES.INVALID_ARGS, "provider required");
|
|
3907
|
+
if (!subdao) throw new SageSDKError(CODES.INVALID_ARGS, "subdao required");
|
|
3908
|
+
const addr = normalise(registry, "registry");
|
|
3909
|
+
const dao = normalise(subdao, "subdao");
|
|
3910
|
+
const contract = new Contract(addr, ABI.LibraryRegistry, provider);
|
|
3911
|
+
return await contract.getLibraryIds(dao);
|
|
3912
|
+
}
|
|
3872
3913
|
async function getManifestInfo({ provider, registry, manifestCID }) {
|
|
3873
3914
|
throw new SageSDKError(CODES.UNSUPPORTED_OPERATION, "getManifestInfo(cid) is not supported in V4. Use getLibraryInfo(subdao).");
|
|
3874
3915
|
}
|
|
@@ -3891,26 +3932,42 @@ var require_library = __commonJS({
|
|
|
3891
3932
|
const info = await getLatestLibrary({ provider, registry, subdao });
|
|
3892
3933
|
return info && info.manifestCID === manifestCID;
|
|
3893
3934
|
}
|
|
3894
|
-
function buildUpdateLibraryTx({ registry, subdao, manifestCID, version = "1.0.0" }) {
|
|
3935
|
+
function buildUpdateLibraryTx({ registry, subdao, libraryId = "default", manifestCID, version = "1.0.0" }) {
|
|
3895
3936
|
const to = normalise(registry, "registry");
|
|
3896
3937
|
if (!manifestCID) throw new SageSDKError(CODES.INVALID_ARGS, "manifestCID required");
|
|
3897
|
-
const
|
|
3898
|
-
const
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
String(version)
|
|
3902
|
-
|
|
3938
|
+
const dao = normalise(subdao, "subdao");
|
|
3939
|
+
const libId = normaliseLibraryId(libraryId);
|
|
3940
|
+
if (libId === "default") {
|
|
3941
|
+
const iface2 = new Interface(["function updateLibrary(address,string,string)"]);
|
|
3942
|
+
const data2 = iface2.encodeFunctionData("updateLibrary", [dao, String(manifestCID), String(version)]);
|
|
3943
|
+
return { to, data: data2, value: 0n };
|
|
3944
|
+
}
|
|
3945
|
+
const iface = new Interface(["function updateLibraryStream(address,string,string,string)"]);
|
|
3946
|
+
const data = iface.encodeFunctionData("updateLibraryStream", [dao, libId, String(manifestCID), String(version)]);
|
|
3903
3947
|
return { to, data, value: 0n };
|
|
3904
3948
|
}
|
|
3905
|
-
function buildUpdateLibraryCAS({ registry, subdao, manifestCID, version = "1.0.0", expectedNonce }) {
|
|
3949
|
+
function buildUpdateLibraryCAS({ registry, subdao, libraryId = "default", manifestCID, version = "1.0.0", expectedNonce }) {
|
|
3906
3950
|
const to = normalise(registry, "registry");
|
|
3907
3951
|
if (!manifestCID) throw new SageSDKError(CODES.INVALID_ARGS, "manifestCID required");
|
|
3908
3952
|
if (expectedNonce === void 0 || expectedNonce === null) {
|
|
3909
3953
|
throw new SageSDKError(CODES.INVALID_ARGS, "expectedNonce required for CAS update");
|
|
3910
3954
|
}
|
|
3911
|
-
const
|
|
3912
|
-
const
|
|
3913
|
-
|
|
3955
|
+
const dao = normalise(subdao, "subdao");
|
|
3956
|
+
const libId = normaliseLibraryId(libraryId);
|
|
3957
|
+
if (libId === "default") {
|
|
3958
|
+
const iface2 = new Interface(["function updateLibraryCAS(address,string,string,uint256)"]);
|
|
3959
|
+
const data2 = iface2.encodeFunctionData("updateLibraryCAS", [
|
|
3960
|
+
dao,
|
|
3961
|
+
String(manifestCID),
|
|
3962
|
+
String(version),
|
|
3963
|
+
BigInt(expectedNonce)
|
|
3964
|
+
]);
|
|
3965
|
+
return { to, data: data2, value: 0n };
|
|
3966
|
+
}
|
|
3967
|
+
const iface = new Interface(["function updateLibraryStreamCAS(address,string,string,string,uint256)"]);
|
|
3968
|
+
const data = iface.encodeFunctionData("updateLibraryStreamCAS", [
|
|
3969
|
+
dao,
|
|
3970
|
+
libId,
|
|
3914
3971
|
String(manifestCID),
|
|
3915
3972
|
String(version),
|
|
3916
3973
|
BigInt(expectedNonce)
|
|
@@ -3921,6 +3978,8 @@ var require_library = __commonJS({
|
|
|
3921
3978
|
listManifests,
|
|
3922
3979
|
getManifestInfo,
|
|
3923
3980
|
getLibraryInfo,
|
|
3981
|
+
getLibraryStreamInfo,
|
|
3982
|
+
getLibraryIds,
|
|
3924
3983
|
getLatestLibrary,
|
|
3925
3984
|
hasScopedOwnership,
|
|
3926
3985
|
buildUpdateLibraryTx,
|
|
@@ -4476,7 +4535,12 @@ var require_governance = __commonJS({
|
|
|
4476
4535
|
if (!parsed) throw new Error("ProposalCreated event not found");
|
|
4477
4536
|
const targets = parsed.args.targets.map(getAddress);
|
|
4478
4537
|
const calldatas = parsed.args.calldatas.map((d) => typeof d === "string" ? d : "0x" + Buffer.from(d).toString("hex"));
|
|
4479
|
-
const LibraryIface = new Interface([
|
|
4538
|
+
const LibraryIface = new Interface([
|
|
4539
|
+
"function updateLibrary(address dao, string manifestCID, string version)",
|
|
4540
|
+
"function updateLibraryCAS(address dao, string manifestCID, string version, uint256 expectedNonce)",
|
|
4541
|
+
"function updateLibraryStream(address dao, string libraryId, string manifestCID, string version)",
|
|
4542
|
+
"function updateLibraryStreamCAS(address dao, string libraryId, string manifestCID, string version, uint256 expectedNonce)"
|
|
4543
|
+
]);
|
|
4480
4544
|
const PromptIface = new Interface(["function updatePromptByGovernance(string,string)"]);
|
|
4481
4545
|
const effects = [];
|
|
4482
4546
|
for (let i = 0; i < calldatas.length; i++) {
|
|
@@ -4490,7 +4554,10 @@ var require_governance = __commonJS({
|
|
|
4490
4554
|
try {
|
|
4491
4555
|
const reg = new Contract(
|
|
4492
4556
|
targets[i],
|
|
4493
|
-
[
|
|
4557
|
+
[
|
|
4558
|
+
"function libraryByDAO(address) view returns (tuple(string manifestCID,address lastUpdater,uint256 lastUpdated,string version,address forkedFromDAO,uint256 sxxxForkFee))",
|
|
4559
|
+
"function getLibraryStream(address,string) view returns (tuple(string manifestCID,address lastUpdater,uint256 lastUpdated,string version,address forkedFromDAO,uint256 sxxxForkFee,uint256 nonce))"
|
|
4560
|
+
],
|
|
4494
4561
|
provider
|
|
4495
4562
|
);
|
|
4496
4563
|
const info = await reg.libraryByDAO(dao).catch(() => null);
|
|
@@ -4501,10 +4568,130 @@ var require_governance = __commonJS({
|
|
|
4501
4568
|
} catch (_) {
|
|
4502
4569
|
}
|
|
4503
4570
|
effects.push({
|
|
4504
|
-
type: "
|
|
4571
|
+
type: "libraryUpdate",
|
|
4572
|
+
index: i,
|
|
4573
|
+
target: targets[i],
|
|
4574
|
+
dao: getAddress(dao),
|
|
4575
|
+
libraryId: "default",
|
|
4576
|
+
previousCid: previousCID,
|
|
4577
|
+
previousVersion,
|
|
4578
|
+
newCid: String(newCid),
|
|
4579
|
+
newVersion: String(version)
|
|
4580
|
+
});
|
|
4581
|
+
continue;
|
|
4582
|
+
} catch (_) {
|
|
4583
|
+
}
|
|
4584
|
+
try {
|
|
4585
|
+
const decoded = LibraryIface.decodeFunctionData("updateLibraryCAS", data);
|
|
4586
|
+
const [dao, newCid, version] = decoded;
|
|
4587
|
+
let previousCID = null;
|
|
4588
|
+
let previousVersion = null;
|
|
4589
|
+
try {
|
|
4590
|
+
const reg = new Contract(
|
|
4591
|
+
targets[i],
|
|
4592
|
+
[
|
|
4593
|
+
"function libraryByDAO(address) view returns (tuple(string manifestCID,address lastUpdater,uint256 lastUpdated,string version,address forkedFromDAO,uint256 sxxxForkFee))",
|
|
4594
|
+
"function getLibraryStream(address,string) view returns (tuple(string manifestCID,address lastUpdater,uint256 lastUpdated,string version,address forkedFromDAO,uint256 sxxxForkFee,uint256 nonce))"
|
|
4595
|
+
],
|
|
4596
|
+
provider
|
|
4597
|
+
);
|
|
4598
|
+
const info = await reg.libraryByDAO(dao).catch(() => null);
|
|
4599
|
+
if (info && typeof info.manifestCID === "string") {
|
|
4600
|
+
previousCID = info.manifestCID || null;
|
|
4601
|
+
previousVersion = info.version || null;
|
|
4602
|
+
}
|
|
4603
|
+
} catch (_) {
|
|
4604
|
+
}
|
|
4605
|
+
effects.push({
|
|
4606
|
+
type: "libraryUpdate",
|
|
4607
|
+
index: i,
|
|
4608
|
+
target: targets[i],
|
|
4609
|
+
dao: getAddress(dao),
|
|
4610
|
+
libraryId: "default",
|
|
4611
|
+
previousCid: previousCID,
|
|
4612
|
+
previousVersion,
|
|
4613
|
+
newCid: String(newCid),
|
|
4614
|
+
newVersion: String(version)
|
|
4615
|
+
});
|
|
4616
|
+
continue;
|
|
4617
|
+
} catch (_) {
|
|
4618
|
+
}
|
|
4619
|
+
try {
|
|
4620
|
+
const decoded = LibraryIface.decodeFunctionData("updateLibraryStream", data);
|
|
4621
|
+
const [dao, libraryId, newCid, version] = decoded;
|
|
4622
|
+
let previousCID = null;
|
|
4623
|
+
let previousVersion = null;
|
|
4624
|
+
try {
|
|
4625
|
+
const reg = new Contract(
|
|
4626
|
+
targets[i],
|
|
4627
|
+
[
|
|
4628
|
+
"function getLibraryStream(address,string) view returns (tuple(string manifestCID,address lastUpdater,uint256 lastUpdated,string version,address forkedFromDAO,uint256 sxxxForkFee,uint256 nonce))",
|
|
4629
|
+
"function libraryByDAO(address) view returns (tuple(string manifestCID,address lastUpdater,uint256 lastUpdated,string version,address forkedFromDAO,uint256 sxxxForkFee))"
|
|
4630
|
+
],
|
|
4631
|
+
provider
|
|
4632
|
+
);
|
|
4633
|
+
let info = null;
|
|
4634
|
+
try {
|
|
4635
|
+
info = await reg.getLibraryStream(dao, String(libraryId));
|
|
4636
|
+
} catch (_) {
|
|
4637
|
+
if (String(libraryId) === "default") {
|
|
4638
|
+
info = await reg.libraryByDAO(dao).catch(() => null);
|
|
4639
|
+
}
|
|
4640
|
+
}
|
|
4641
|
+
if (info && typeof info.manifestCID === "string") {
|
|
4642
|
+
previousCID = info.manifestCID || null;
|
|
4643
|
+
previousVersion = info.version || null;
|
|
4644
|
+
}
|
|
4645
|
+
} catch (_) {
|
|
4646
|
+
}
|
|
4647
|
+
effects.push({
|
|
4648
|
+
type: "libraryUpdate",
|
|
4505
4649
|
index: i,
|
|
4506
4650
|
target: targets[i],
|
|
4507
4651
|
dao: getAddress(dao),
|
|
4652
|
+
libraryId: String(libraryId),
|
|
4653
|
+
previousCid: previousCID,
|
|
4654
|
+
previousVersion,
|
|
4655
|
+
newCid: String(newCid),
|
|
4656
|
+
newVersion: String(version)
|
|
4657
|
+
});
|
|
4658
|
+
continue;
|
|
4659
|
+
} catch (_) {
|
|
4660
|
+
}
|
|
4661
|
+
try {
|
|
4662
|
+
const decoded = LibraryIface.decodeFunctionData("updateLibraryStreamCAS", data);
|
|
4663
|
+
const [dao, libraryId, newCid, version] = decoded;
|
|
4664
|
+
let previousCID = null;
|
|
4665
|
+
let previousVersion = null;
|
|
4666
|
+
try {
|
|
4667
|
+
const reg = new Contract(
|
|
4668
|
+
targets[i],
|
|
4669
|
+
[
|
|
4670
|
+
"function getLibraryStream(address,string) view returns (tuple(string manifestCID,address lastUpdater,uint256 lastUpdated,string version,address forkedFromDAO,uint256 sxxxForkFee,uint256 nonce))",
|
|
4671
|
+
"function libraryByDAO(address) view returns (tuple(string manifestCID,address lastUpdater,uint256 lastUpdated,string version,address forkedFromDAO,uint256 sxxxForkFee))"
|
|
4672
|
+
],
|
|
4673
|
+
provider
|
|
4674
|
+
);
|
|
4675
|
+
let info = null;
|
|
4676
|
+
try {
|
|
4677
|
+
info = await reg.getLibraryStream(dao, String(libraryId));
|
|
4678
|
+
} catch (_) {
|
|
4679
|
+
if (String(libraryId) === "default") {
|
|
4680
|
+
info = await reg.libraryByDAO(dao).catch(() => null);
|
|
4681
|
+
}
|
|
4682
|
+
}
|
|
4683
|
+
if (info && typeof info.manifestCID === "string") {
|
|
4684
|
+
previousCID = info.manifestCID || null;
|
|
4685
|
+
previousVersion = info.version || null;
|
|
4686
|
+
}
|
|
4687
|
+
} catch (_) {
|
|
4688
|
+
}
|
|
4689
|
+
effects.push({
|
|
4690
|
+
type: "libraryUpdate",
|
|
4691
|
+
index: i,
|
|
4692
|
+
target: targets[i],
|
|
4693
|
+
dao: getAddress(dao),
|
|
4694
|
+
libraryId: String(libraryId),
|
|
4508
4695
|
previousCid: previousCID,
|
|
4509
4696
|
previousVersion,
|
|
4510
4697
|
newCid: String(newCid),
|
|
@@ -4841,9 +5028,127 @@ var require_governance = __commonJS({
|
|
|
4841
5028
|
description: desc.description
|
|
4842
5029
|
};
|
|
4843
5030
|
}
|
|
5031
|
+
async function getProposalVotingStatus({ provider, governor, proposalId }) {
|
|
5032
|
+
if (!provider) throw new SageSDKError(CODES.INVALID_ARGS, "provider required");
|
|
5033
|
+
if (!proposalId) throw new SageSDKError(CODES.INVALID_ARGS, "proposalId required");
|
|
5034
|
+
const addr = normaliseGovernor(governor);
|
|
5035
|
+
const g = new Contract(addr, ABI.Governor, provider);
|
|
5036
|
+
const pid = typeof proposalId === "bigint" ? proposalId : BigInt(String(proposalId));
|
|
5037
|
+
const [
|
|
5038
|
+
stateNum,
|
|
5039
|
+
snapshot,
|
|
5040
|
+
deadline,
|
|
5041
|
+
votes,
|
|
5042
|
+
votingDelay,
|
|
5043
|
+
votingPeriod,
|
|
5044
|
+
proposalThreshold,
|
|
5045
|
+
govName
|
|
5046
|
+
] = await Promise.all([
|
|
5047
|
+
g.state(pid).catch(() => null),
|
|
5048
|
+
g.proposalSnapshot(pid).catch(() => null),
|
|
5049
|
+
g.proposalDeadline(pid).catch(() => null),
|
|
5050
|
+
g.proposalVotes(pid).catch(() => null),
|
|
5051
|
+
g.votingDelay().catch(() => null),
|
|
5052
|
+
g.votingPeriod().catch(() => null),
|
|
5053
|
+
g.proposalThreshold().catch(() => null),
|
|
5054
|
+
g.name().catch(() => null)
|
|
5055
|
+
]);
|
|
5056
|
+
let quorum = null;
|
|
5057
|
+
if (snapshot != null) {
|
|
5058
|
+
try {
|
|
5059
|
+
quorum = await g.quorum(snapshot);
|
|
5060
|
+
quorum = BigInt(quorum.toString());
|
|
5061
|
+
} catch {
|
|
5062
|
+
try {
|
|
5063
|
+
const qv = await g.quorumVotes();
|
|
5064
|
+
quorum = BigInt(qv.toString());
|
|
5065
|
+
} catch {
|
|
5066
|
+
}
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
let forVotes = 0n;
|
|
5070
|
+
let againstVotes = 0n;
|
|
5071
|
+
let abstainVotes = 0n;
|
|
5072
|
+
if (Array.isArray(votes)) {
|
|
5073
|
+
againstVotes = BigInt(votes[0]);
|
|
5074
|
+
forVotes = BigInt(votes[1]);
|
|
5075
|
+
abstainVotes = BigInt(votes[2]);
|
|
5076
|
+
} else if (votes && typeof votes === "object") {
|
|
5077
|
+
if (votes.againstVotes != null) againstVotes = BigInt(votes.againstVotes);
|
|
5078
|
+
if (votes.forVotes != null) forVotes = BigInt(votes.forVotes);
|
|
5079
|
+
if (votes.abstainVotes != null) abstainVotes = BigInt(votes.abstainVotes);
|
|
5080
|
+
}
|
|
5081
|
+
const totalVotes = forVotes + againstVotes + abstainVotes;
|
|
5082
|
+
const participatingVotes = forVotes + againstVotes;
|
|
5083
|
+
const quorumMet = quorum != null ? forVotes >= quorum : null;
|
|
5084
|
+
const quorumProgress = quorum != null && quorum > 0n ? Number(forVotes * 10000n / quorum) / 100 : null;
|
|
5085
|
+
const stateMap = ["PENDING", "ACTIVE", "CANCELED", "DEFEATED", "SUCCEEDED", "QUEUED", "EXPIRED", "EXECUTED"];
|
|
5086
|
+
const state = typeof stateNum === "number" && stateNum >= 0 && stateNum < stateMap.length ? stateMap[stateNum] : null;
|
|
5087
|
+
const BLOCK_TIME_SECONDS = 2;
|
|
5088
|
+
const votingDelaySeconds = votingDelay != null ? Number(votingDelay) * BLOCK_TIME_SECONDS : null;
|
|
5089
|
+
const votingPeriodSeconds = votingPeriod != null ? Number(votingPeriod) * BLOCK_TIME_SECONDS : null;
|
|
5090
|
+
const formatSXXX = (val) => {
|
|
5091
|
+
if (val == null) return null;
|
|
5092
|
+
const num = Number(val) / 1e18;
|
|
5093
|
+
if (num >= 1e6) return `${(num / 1e6).toFixed(1)}M`;
|
|
5094
|
+
if (num >= 1e3) return `${(num / 1e3).toFixed(1)}K`;
|
|
5095
|
+
return num.toFixed(2);
|
|
5096
|
+
};
|
|
5097
|
+
const formatDuration = (seconds) => {
|
|
5098
|
+
if (seconds == null) return null;
|
|
5099
|
+
if (seconds < 60) return `${seconds} seconds`;
|
|
5100
|
+
if (seconds < 3600) return `${Math.round(seconds / 60)} minutes`;
|
|
5101
|
+
if (seconds < 86400) return `${(seconds / 3600).toFixed(1)} hours`;
|
|
5102
|
+
return `${(seconds / 86400).toFixed(1)} days`;
|
|
5103
|
+
};
|
|
5104
|
+
return {
|
|
5105
|
+
governor: addr,
|
|
5106
|
+
governorName: govName,
|
|
5107
|
+
proposalId: pid.toString(),
|
|
5108
|
+
state,
|
|
5109
|
+
stateNum: typeof stateNum === "number" ? stateNum : null,
|
|
5110
|
+
// Raw values (bigint as string for JSON serialization)
|
|
5111
|
+
votes: {
|
|
5112
|
+
for: forVotes.toString(),
|
|
5113
|
+
against: againstVotes.toString(),
|
|
5114
|
+
abstain: abstainVotes.toString(),
|
|
5115
|
+
total: totalVotes.toString()
|
|
5116
|
+
},
|
|
5117
|
+
quorum: quorum?.toString() || null,
|
|
5118
|
+
proposalThreshold: proposalThreshold?.toString() || null,
|
|
5119
|
+
snapshot: snapshot?.toString() || null,
|
|
5120
|
+
deadline: deadline?.toString() || null,
|
|
5121
|
+
votingDelay: votingDelay?.toString() || null,
|
|
5122
|
+
votingPeriod: votingPeriod?.toString() || null,
|
|
5123
|
+
// Computed status
|
|
5124
|
+
quorumMet,
|
|
5125
|
+
quorumProgress,
|
|
5126
|
+
// percentage (0-100+)
|
|
5127
|
+
passing: forVotes > againstVotes,
|
|
5128
|
+
// Formatted for display
|
|
5129
|
+
formatted: {
|
|
5130
|
+
forVotes: formatSXXX(forVotes),
|
|
5131
|
+
againstVotes: formatSXXX(againstVotes),
|
|
5132
|
+
abstainVotes: formatSXXX(abstainVotes),
|
|
5133
|
+
totalVotes: formatSXXX(totalVotes),
|
|
5134
|
+
quorum: formatSXXX(quorum),
|
|
5135
|
+
proposalThreshold: formatSXXX(proposalThreshold),
|
|
5136
|
+
votingDelay: formatDuration(votingDelaySeconds),
|
|
5137
|
+
votingPeriod: formatDuration(votingPeriodSeconds)
|
|
5138
|
+
},
|
|
5139
|
+
// Plain language summary
|
|
5140
|
+
summary: {
|
|
5141
|
+
quorumStatus: quorum != null ? quorumMet ? `Quorum reached (${formatSXXX(forVotes)} of ${formatSXXX(quorum)} SXXX required)` : `${formatSXXX(forVotes)} of ${formatSXXX(quorum)} SXXX needed for quorum (${quorumProgress?.toFixed(1)}%)` : "Quorum information unavailable",
|
|
5142
|
+
voteStatus: `${formatSXXX(forVotes)} SXXX for, ${formatSXXX(againstVotes)} SXXX against`,
|
|
5143
|
+
outcome: forVotes > againstVotes ? "Currently passing" : forVotes < againstVotes ? "Currently failing" : "Tied",
|
|
5144
|
+
votingPeriod: votingPeriodSeconds ? `Voting period: ${formatDuration(votingPeriodSeconds)}` : null
|
|
5145
|
+
}
|
|
5146
|
+
};
|
|
5147
|
+
}
|
|
4844
5148
|
module2.exports = {
|
|
4845
5149
|
getGovernorInfo,
|
|
4846
5150
|
getProposal,
|
|
5151
|
+
getProposalVotingStatus,
|
|
4847
5152
|
listProposals,
|
|
4848
5153
|
getProposalMetadata,
|
|
4849
5154
|
hashDescription,
|