@sage-protocol/sdk 0.1.21 → 0.1.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sage-protocol/sdk",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
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",
package/types/index.d.ts CHANGED
@@ -140,6 +140,42 @@ export interface VotesTokenDescription {
140
140
  description: string;
141
141
  }
142
142
 
143
+ // ============ Governance Profile Types (3-Axis Model) ============
144
+
145
+ export type GovernanceKind = 'operator' | 'token';
146
+ export type ProposalAccess = 'council-only' | 'community-threshold';
147
+ export type ExecutionAccess = 'council-only' | 'anyone';
148
+ export type GovernancePlaybook = 'council-closed' | 'council-drafts' | 'community' | 'legacy' | 'custom';
149
+
150
+ export interface GovernanceProfile {
151
+ /** Profile version: 1=legacy (detected via heuristics), 2=explicit 3-axis profile */
152
+ version: 1 | 2;
153
+ /** OPERATOR (council/EOA decides) or TOKEN (ERC20Votes snapshot) */
154
+ governanceKind: GovernanceKind | null;
155
+ /** COUNCIL_ONLY (only COUNCIL_ROLE) or COMMUNITY_THRESHOLD (token holders >= threshold) */
156
+ proposalAccess: ProposalAccess | null;
157
+ /** COUNCIL_ONLY (only council can execute) or ANYONE (public execution) */
158
+ executionAccess: ExecutionAccess | null;
159
+ /** Derived playbook name for UX */
160
+ playbook: GovernancePlaybook;
161
+ /** True if proposals require COUNCIL_ROLE */
162
+ isCouncil: boolean;
163
+ /** True if SXXX stake is required to propose (TOKEN + COMMUNITY_THRESHOLD only) */
164
+ requiresStake: boolean;
165
+ }
166
+
167
+ export interface GovernanceModeDetectionResult extends GovernanceProfile {
168
+ /** Legacy operator flag */
169
+ operator: boolean;
170
+ /** Legacy governance mode label */
171
+ governance: string;
172
+ governor: AddressLike | null;
173
+ timelock: AddressLike | null;
174
+ subdao: AddressLike | null;
175
+ stakeRequired: bigint | null;
176
+ depositWei: bigint | null;
177
+ }
178
+
143
179
  export interface VotingStatus {
144
180
  subdao: AddressLike | null;
145
181
  governor: AddressLike;
@@ -292,15 +328,7 @@ export interface GovernanceModule {
292
328
  calldatas?: string[];
293
329
  descriptionHash: string;
294
330
  }): TransactionPayload;
295
- detectMode(args: { provider: ProviderLike; governor?: AddressLike; timelock?: AddressLike | null; subdao?: AddressLike | null }): Promise<{
296
- operator: boolean;
297
- governance: string;
298
- governor: AddressLike | null;
299
- timelock: AddressLike | null;
300
- subdao: AddressLike | null;
301
- stakeRequired: bigint | null;
302
- depositWei: bigint | null;
303
- }>;
331
+ detectMode(args: { provider: ProviderLike; governor?: AddressLike; timelock?: AddressLike | null; subdao?: AddressLike | null }): Promise<GovernanceModeDetectionResult>;
304
332
  [key: string]: any;
305
333
  }
306
334
 
@@ -499,13 +527,13 @@ export interface LibrarySearchResponse {
499
527
  }
500
528
 
501
529
  export interface LibraryModule {
502
- listManifests(args: { provider: ProviderLike; registry: AddressLike; offset?: number; limit?: number }): Promise<{ total: bigint; manifests: Array<{ manifestCID: string; previousCID: string; timestamp: bigint; proposer: AddressLike; promptCount: number; }> }>;
503
- getManifestInfo(args: { provider: ProviderLike; registry: AddressLike; manifestCID: string }): Promise<{ manifestCID: string; previousCID: string; timestamp: bigint; proposer: AddressLike; promptCount: number; }>;
504
- getLatestLibrary(args: { provider: ProviderLike; registry: AddressLike; subdao: AddressLike; libraryId?: string }): Promise<{ manifestCID: string; previousCID: string; timestamp: bigint; proposer: AddressLike; promptCount: number; } | null>;
530
+ listManifests(args: { provider: ProviderLike; registry: AddressLike; factoryAddress: AddressLike; offset?: number; limit?: number }): Promise<{ total: bigint; manifests: Array<{ manifestCID: string; previousCID: string; timestamp: bigint; proposer: AddressLike; promptCount: number; version: string; }> }>;
531
+ getManifestInfo(args: { provider: ProviderLike; registry: AddressLike; manifestCID: string }): Promise<never>;
532
+ getLatestLibrary(args: { provider: ProviderLike; registry: AddressLike; subdao: AddressLike }): Promise<{ manifestCID: string; previousCID: string; timestamp: bigint; proposer: AddressLike; promptCount: number; version: string; } | null>;
505
533
  hasScopedOwnership(args: { provider: ProviderLike; registry: AddressLike; subdao: AddressLike; manifestCID: string }): Promise<boolean>;
506
- buildUpdateLibraryForSubDAOTx(args: { registry: AddressLike; subdao: AddressLike; manifestCID: string; promptCount?: bigint | number | string; libraryId?: string }): TransactionPayload;
534
+ buildUpdateLibraryTx(args: { registry: AddressLike; subdao: AddressLike; manifestCID: string; version?: string }): TransactionPayload;
507
535
  buildAuthorizeTimelockTx(args: { registry: AddressLike; timelock: AddressLike; subdao: AddressLike }): TransactionPayload;
508
- executionReadiness(args: { provider: ProviderLike; registry: AddressLike; timelock: AddressLike; subdao: AddressLike; libraryId?: string; manifestCID?: string; promptCount?: bigint | number | string }): Promise<{ ok: boolean; error: string | null; missingRole: string | null }>;
536
+ executionReadiness(args: { provider: ProviderLike; registry: AddressLike; timelock: AddressLike; subdao: AddressLike; manifestCID?: string; version?: string }): Promise<{ ok: boolean; error: string | null; missingRole: string | null }>;
509
537
  searchRegistry(args: { provider: ProviderLike; registry: AddressLike; query: string; limit?: number; ipfsClient?: any; ipfsOptions?: Record<string, any>; libraryAdapter?: any; manifestFetcher?: (cid: string) => Promise<any>; }): Promise<LibrarySearchResponse>;
510
538
  validation: { createManifestValidator(options?: Record<string, any>): ManifestValidator };
511
539
  }
@@ -858,6 +886,122 @@ export interface BountySubmission {
858
886
  exists: boolean;
859
887
  }
860
888
 
889
+ // ---- Contributions Module ----
890
+
891
+ export type GovernanceModel = 'TOKEN_VOTING' | 'COUNCIL' | 'OPERATOR' | 'DIRECT';
892
+
893
+ export interface PromptContribution {
894
+ id: string;
895
+ dao: AddressLike;
896
+ daoName: string | null;
897
+ promptKey: string;
898
+ contributor: AddressLike;
899
+ cid: string;
900
+ timestamp: number;
901
+ createdAt: number;
902
+ updatedAt: number;
903
+ transactionHash: string | null;
904
+ governanceModel: GovernanceModel;
905
+ proposalId: bigint | null;
906
+ forVotes: bigint | null;
907
+ againstVotes: bigint | null;
908
+ abstainVotes: bigint | null;
909
+ uniqueVoters: number | null;
910
+ quorum: bigint | null;
911
+ fromBounty: boolean;
912
+ bountyId: bigint | null;
913
+ badgeId: bigint | null;
914
+ badgeEvidenceURI: string | null;
915
+ }
916
+
917
+ export interface ContributionAggregates {
918
+ totalContributions: number;
919
+ uniqueContributors: number;
920
+ bountyOriginated: number;
921
+ governanceOriginated: number;
922
+ totalForVotes: bigint;
923
+ totalAgainstVotes: bigint;
924
+ averageVoterCount: number;
925
+ badgeCount: number;
926
+ }
927
+
928
+ export interface GovernanceQuality {
929
+ model: GovernanceModel;
930
+ decentralization: number;
931
+ consensus: number;
932
+ raw: Record<string, any>;
933
+ }
934
+
935
+ export interface SoulboundBadge {
936
+ id: string;
937
+ contract: AddressLike;
938
+ badgeId: bigint;
939
+ recipient: AddressLike;
940
+ evidenceURI: string | null;
941
+ blockNumber: number;
942
+ blockTimestamp: number;
943
+ transactionHash: string | null;
944
+ }
945
+
946
+ export interface ContributionsModule {
947
+ GovernanceModel: {
948
+ TOKEN_VOTING: 'TOKEN_VOTING';
949
+ COUNCIL: 'COUNCIL';
950
+ OPERATOR: 'OPERATOR';
951
+ DIRECT: 'DIRECT';
952
+ };
953
+
954
+ listContributions(args: {
955
+ url: string;
956
+ subdao?: AddressLike;
957
+ promptKey?: string;
958
+ contributor?: AddressLike;
959
+ fromBounty?: boolean;
960
+ first?: number;
961
+ skip?: number;
962
+ orderBy?: 'updatedAt' | 'createdAt';
963
+ orderDirection?: 'asc' | 'desc';
964
+ }): Promise<PromptContribution[]>;
965
+
966
+ getByPrompt(args: {
967
+ url: string;
968
+ subdao: AddressLike;
969
+ promptKey: string;
970
+ }): Promise<{ contributions: PromptContribution[]; aggregates: ContributionAggregates }>;
971
+
972
+ getById(args: {
973
+ url: string;
974
+ id: string;
975
+ }): Promise<PromptContribution | null>;
976
+
977
+ getByContributor(args: {
978
+ url: string;
979
+ contributor: AddressLike;
980
+ first?: number;
981
+ skip?: number;
982
+ }): Promise<PromptContribution[]>;
983
+
984
+ getBadgesByRecipient(args: {
985
+ url: string;
986
+ recipient: AddressLike;
987
+ first?: number;
988
+ }): Promise<SoulboundBadge[]>;
989
+
990
+ getGovernanceQuality(
991
+ contribution: PromptContribution,
992
+ context?: { totalHolders?: number; totalCouncilMembers?: number }
993
+ ): GovernanceQuality;
994
+
995
+ enrichWithGovernanceModel(
996
+ contribution: PromptContribution,
997
+ subdaoInfo: any
998
+ ): PromptContribution;
999
+
1000
+ detectGovernanceModel(subdaoInfo: any): GovernanceModel;
1001
+
1002
+ computeAggregates(contributions: PromptContribution[]): ContributionAggregates;
1003
+ }
1004
+
861
1005
  export interface BountyModule {
862
1006
  // Constants
863
1007
  getMaxSubmissionsPerBounty(args: { provider: ProviderLike; bountySystem: AddressLike }): Promise<bigint>;
@@ -926,6 +1070,220 @@ export interface BountyModule {
926
1070
  buildRemoveFromWhitelistTx(args: { bountySystem: AddressLike; bountyId: BigNumberish; addresses: AddressLike[] }): TransactionPayload;
927
1071
  }
928
1072
 
1073
+ // ============ Git Storage Client Types ============
1074
+
1075
+ export type GitObjectType = 'blob' | 'tree' | 'commit';
1076
+
1077
+ export interface GitObject {
1078
+ /** Object ID (SHA-1 hash) */
1079
+ oid: string;
1080
+ /** Object type */
1081
+ type: GitObjectType;
1082
+ /** Object size in bytes */
1083
+ size: number;
1084
+ /** Base64 encoded object data */
1085
+ data: string;
1086
+ }
1087
+
1088
+ export interface GitRef {
1089
+ /** Reference name (e.g., 'refs/heads/main') */
1090
+ name: string;
1091
+ /** Object ID the ref points to */
1092
+ oid: string;
1093
+ /** Last update timestamp */
1094
+ updatedAt: number;
1095
+ /** Wallet address of last updater */
1096
+ updatedBy?: string;
1097
+ }
1098
+
1099
+ export interface GitCommit {
1100
+ /** Commit hash */
1101
+ oid: string;
1102
+ /** Tree object hash */
1103
+ treeOid: string;
1104
+ /** Parent commit hash */
1105
+ parentOid?: string;
1106
+ /** Commit message */
1107
+ message: string;
1108
+ /** Author name */
1109
+ authorName?: string;
1110
+ /** Author email */
1111
+ authorEmail?: string;
1112
+ /** Author wallet address */
1113
+ authorAddress?: string;
1114
+ /** Commit timestamp */
1115
+ timestamp: number;
1116
+ }
1117
+
1118
+ export interface LibraryMetadata {
1119
+ /** SubDAO address */
1120
+ subdao: string;
1121
+ /** Library name */
1122
+ name: string;
1123
+ /** Library description */
1124
+ description?: string;
1125
+ /** Library visibility */
1126
+ visibility: 'public' | 'private';
1127
+ /** Creation timestamp */
1128
+ createdAt: number;
1129
+ /** Last update timestamp */
1130
+ updatedAt: number;
1131
+ /** Fork information */
1132
+ forkOf?: {
1133
+ subdao: string;
1134
+ commit: string;
1135
+ };
1136
+ }
1137
+
1138
+ export interface Collaborator {
1139
+ /** Wallet address */
1140
+ address: string;
1141
+ /** Permission level */
1142
+ permission: 'read' | 'write' | 'admin';
1143
+ /** When collaborator was added */
1144
+ addedAt: number;
1145
+ /** Who added the collaborator */
1146
+ addedBy?: string;
1147
+ }
1148
+
1149
+ export interface PushResult {
1150
+ /** Whether push succeeded */
1151
+ success: boolean;
1152
+ /** New commit hash */
1153
+ commitHash?: string;
1154
+ /** Error message if failed */
1155
+ error?: string;
1156
+ }
1157
+
1158
+ export interface PushPayload {
1159
+ /** Objects to push */
1160
+ objects: GitObject[];
1161
+ /** Ref updates (name -> oid) */
1162
+ refs: Record<string, string>;
1163
+ /** Commit message */
1164
+ message: string;
1165
+ }
1166
+
1167
+ export interface CloneResult {
1168
+ /** All objects in the library */
1169
+ objects: GitObject[];
1170
+ /** All refs (name -> oid) */
1171
+ refs: Record<string, string>;
1172
+ /** Library metadata */
1173
+ metadata: LibraryMetadata;
1174
+ }
1175
+
1176
+ export interface FetchResult {
1177
+ /** Objects since the given commit */
1178
+ objects: GitObject[];
1179
+ /** Current refs (name -> oid) */
1180
+ refs: Record<string, string>;
1181
+ }
1182
+
1183
+ export interface CollaboratorPermissions {
1184
+ canRead: boolean;
1185
+ canWrite: boolean;
1186
+ isAdmin: boolean;
1187
+ permission?: string;
1188
+ }
1189
+
1190
+ export interface GitAuthProvider {
1191
+ /** Get wallet address */
1192
+ getAddress(): Promise<string>;
1193
+ /** Sign a message */
1194
+ signMessage(message: string): Promise<string>;
1195
+ }
1196
+
1197
+ export interface GitStorageClientOptions {
1198
+ /** Request timeout in milliseconds (default: 30000) */
1199
+ timeout?: number;
1200
+ /** Custom headers */
1201
+ headers?: Record<string, string>;
1202
+ /** Ethers signer for authenticated requests */
1203
+ signer?: GitAuthProvider | (() => Promise<GitAuthProvider>);
1204
+ /** Custom auth provider */
1205
+ getAuth?: () => Promise<{ address: string; signature: string; nonce: string }>;
1206
+ /** Bearer token for authentication */
1207
+ token?: string;
1208
+ }
1209
+
1210
+ export interface GitStorageClient {
1211
+ readonly baseUrl: string;
1212
+ readonly timeout: number;
1213
+ readonly headers: Record<string, string>;
1214
+
1215
+ // Library Management
1216
+ createLibrary(subdao: string, name: string, options?: {
1217
+ description?: string;
1218
+ visibility?: 'public' | 'private';
1219
+ }): Promise<LibraryMetadata>;
1220
+
1221
+ getLibrary(subdao: string): Promise<LibraryMetadata>;
1222
+
1223
+ listLibraries(options?: {
1224
+ limit?: number;
1225
+ cursor?: string;
1226
+ }): Promise<{ libraries: LibraryMetadata[]; cursor?: string }>;
1227
+
1228
+ deleteLibrary(subdao: string): Promise<{ ok: boolean }>;
1229
+
1230
+ // Git Object Operations
1231
+ putObjects(subdao: string, objects: GitObject[]): Promise<{ stored: number }>;
1232
+ getObject(subdao: string, oid: string): Promise<GitObject>;
1233
+ getObjects(subdao: string, oids: string[]): Promise<{ objects: GitObject[] }>;
1234
+
1235
+ // Reference Operations
1236
+ listRefs(subdao: string): Promise<{ refs: GitRef[] }>;
1237
+ getRef(subdao: string, refName: string): Promise<GitRef>;
1238
+ updateRef(subdao: string, refName: string, oid: string, options?: {
1239
+ oldOid?: string;
1240
+ }): Promise<{ ok: boolean }>;
1241
+
1242
+ // Sync Operations
1243
+ push(subdao: string, payload: PushPayload): Promise<PushResult>;
1244
+ clone(subdao: string): Promise<CloneResult>;
1245
+ fetch(subdao: string, since?: string): Promise<FetchResult>;
1246
+
1247
+ // File Access
1248
+ getHistory(subdao: string, options?: {
1249
+ ref?: string;
1250
+ limit?: number;
1251
+ }): Promise<{ commits: GitCommit[] }>;
1252
+
1253
+ getTree(subdao: string, ref: string, path: string): Promise<{ entries: Array<{
1254
+ name: string;
1255
+ type: 'blob' | 'tree';
1256
+ oid: string;
1257
+ }> }>;
1258
+
1259
+ getBlob(subdao: string, ref: string, path: string): Promise<{ content: string }>;
1260
+ getFile(subdao: string, ref: string, path: string): Promise<string>;
1261
+
1262
+ // Fork Operations
1263
+ fork(sourceSubdao: string, targetSubdao: string): Promise<{ success: boolean; commitHash?: string }>;
1264
+ getForks(subdao: string): Promise<{ forks: Array<{ subdao: string; forkedAt: number }> }>;
1265
+ getUpstream(subdao: string): Promise<{ upstreamSubdao: string; upstreamCommit: string; forkedAt: number }>;
1266
+
1267
+ // Collaborator Operations
1268
+ listCollaborators(subdao: string): Promise<{ collaborators: Collaborator[] }>;
1269
+ addCollaborator(subdao: string, address: string, permission: 'read' | 'write' | 'admin'): Promise<{ ok: boolean }>;
1270
+ removeCollaborator(subdao: string, address: string): Promise<{ ok: boolean }>;
1271
+ getPermissions(subdao: string, address: string): Promise<CollaboratorPermissions>;
1272
+
1273
+ // High-Level Convenience Methods
1274
+ pushManifest(subdao: string, manifest: object, message: string): Promise<PushResult>;
1275
+ getManifest(subdao: string, ref?: string): Promise<object>;
1276
+
1277
+ // Cache Management
1278
+ clearAuthCache(): void;
1279
+ }
1280
+
1281
+ export interface GitStorageClientConstructor {
1282
+ new (baseUrl: string, options?: GitStorageClientOptions): GitStorageClient;
1283
+ }
1284
+
1285
+ export declare const GitStorageClient: GitStorageClientConstructor;
1286
+
929
1287
  export interface SageSDK {
930
1288
  version: string;
931
1289
  getProvider: (rpcUrl: string) => any;
@@ -959,9 +1317,17 @@ export interface SageSDK {
959
1317
  votingMultiplier: VotingMultiplierModule;
960
1318
  auction: AuctionModule;
961
1319
  bounty: BountyModule;
1320
+ contributions: ContributionsModule;
962
1321
  subgraph: Record<string, any>;
963
1322
  errors: Record<string, any>;
964
1323
  resolveGovernanceContext: (args: any) => Promise<any>;
1324
+ // Client exports
1325
+ clients: {
1326
+ DiscoveryClient: any;
1327
+ GitStorageClient: GitStorageClientConstructor;
1328
+ };
1329
+ DiscoveryClient: any;
1330
+ GitStorageClient: GitStorageClientConstructor;
965
1331
  }
966
1332
 
967
1333
  declare const sdk: SageSDK;