@sage-protocol/sdk 0.2.3 → 0.2.4

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.
@@ -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.3",
23
+ version: "0.2.4",
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: "^17.0.1",
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
- subDAOLibraryPointers(
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
- previousCID
813
- promptCount
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?.subDAOLibraryPointers, (row) => {
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(row.libraryId || "main"),
841
+ libraryId: String(id2),
841
842
  manifestCID: String(manifestCID),
842
- previousCID: row.previousCID || null,
843
- promptCount: row.promptCount != null ? Number(row.promptCount) : null,
844
- updatedAt: timestamp,
845
- createdAt: row.createdAt != null ? Number(row.createdAt) : null,
846
- blockNumber: row.blockNumber != null ? Number(row.blockNumber) : null,
847
- blockTimestamp: row.blockTimestamp != null ? Number(row.blockTimestamp) : null
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
- subDAOLibraryPointers(
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
- previousCID
2145
- promptCount
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?.subDAOLibraryPointers, (row) => {
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(row.libraryId || "main"),
2170
+ libraryId: String(id2),
2169
2171
  manifestCID: String(manifestCID),
2170
- previousCID: row.previousCID || null,
2171
- promptCount: row.promptCount != null ? Number(row.promptCount) : null,
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 iface = new Interface(["function updateLibrary(address,string,string)"]);
3898
- const data = iface.encodeFunctionData("updateLibrary", [
3899
- normalise(subdao, "subdao"),
3900
- String(manifestCID),
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 iface = new Interface(["function updateLibraryCAS(address,string,string,uint256)"]);
3912
- const data = iface.encodeFunctionData("updateLibraryCAS", [
3913
- normalise(subdao, "subdao"),
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(["function updateLibrary(address,string,string)"]);
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
- ["function libraryByDAO(address) view returns (tuple(string manifestCID,address lastUpdater,uint256 lastUpdated,string version,address forkedFromDAO,uint256 sxxxForkFee))"],
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: "libraryUpdateV4",
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",
4649
+ index: i,
4650
+ target: targets[i],
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",
4505
4691
  index: i,
4506
4692
  target: targets[i],
4507
4693
  dao: getAddress(dao),
4694
+ libraryId: String(libraryId),
4508
4695
  previousCid: previousCID,
4509
4696
  previousVersion,
4510
4697
  newCid: String(newCid),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sage-protocol/sdk",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Backend-agnostic SDK for interacting with the Sage Protocol (governance, SubDAOs, tokens).",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "devDependencies": {
68
68
  "proxyquire": "^2.1.3",
69
- "sinon": "^17.0.1",
69
+ "sinon": "^21.0.0",
70
70
  "tsup": "^8.1.0",
71
71
  "typescript": "^5.4.0"
72
72
  },