Skip to content

Commit 7c820c8

Browse files
committed
Merge branch 'main' of https://github.com/elizaOS/jeju into main-3
2 parents 4796e94 + b78e0a4 commit 7c820c8

File tree

2 files changed

+65
-26
lines changed

2 files changed

+65
-26
lines changed

apps/autocrat/api/dao-service.ts

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,26 +1138,43 @@ export class DAOService {
11381138
return this.parseDAO(expectRawDAO(result))
11391139
}
11401140

1141-
async getDAOFull(daoId: string): Promise<DAOFull> {
1142-
expectDefined(daoId, 'DAO ID is required')
1141+
async getDAOFull(daoIdOrName: string): Promise<DAOFull> {
1142+
expectDefined(daoIdOrName, 'DAO ID or name is required')
11431143
expect(
1144-
daoId.length > 0 && daoId.length <= 100,
1145-
`DAO ID must be 1-100 characters, got ${daoId.length}`,
1144+
daoIdOrName.length > 0 && daoIdOrName.length <= 100,
1145+
`DAO ID/name must be 1-100 characters, got ${daoIdOrName.length}`,
11461146
)
1147-
const cached = this.daoCache.get(daoId)
1147+
const cached = this.daoCache.get(daoIdOrName)
11481148
if (cached) {
11491149
return cached
11501150
}
11511151

1152+
let daoIdHex: `0x${string}`
1153+
1154+
// If it looks like a bytes32 hex, use it directly
1155+
if (daoIdOrName.startsWith('0x') && daoIdOrName.length === 66) {
1156+
daoIdHex = daoIdOrName as `0x${string}`
1157+
} else {
1158+
// Look up by name first to get the actual daoId
1159+
const nameResult = await this.publicClient.readContract({
1160+
address: this.config.daoRegistryAddress,
1161+
abi: DAORegistryABI,
1162+
functionName: 'getDAOByName',
1163+
args: [daoIdOrName],
1164+
})
1165+
const dao = nameResult as { daoId: `0x${string}` }
1166+
daoIdHex = dao.daoId
1167+
}
1168+
11521169
const result = await this.publicClient.readContract({
11531170
address: this.config.daoRegistryAddress,
11541171
abi: DAORegistryABI,
11551172
functionName: 'getDAOFull',
1156-
args: [toHex(daoId)],
1173+
args: [daoIdHex],
11571174
})
11581175

11591176
const daoFull = this.parseDAOFull(expectRawDAOFull(result))
1160-
this.daoCache.set(daoId, daoFull)
1177+
this.daoCache.set(daoIdOrName, daoFull)
11611178

11621179
return daoFull
11631180
}
@@ -1210,7 +1227,7 @@ export class DAOService {
12101227
minQualityScore: Number(result.minQualityScore),
12111228
boardVotingPeriod: Number(result.boardVotingPeriod),
12121229
gracePeriod: Number(result.gracePeriod),
1213-
minProposalStake: result.minProposalStake,
1230+
minProposalStake: result.minProposalStake.toString(),
12141231
quorumBps: Number(result.quorumBps),
12151232
}
12161233
}
@@ -1232,7 +1249,7 @@ export class DAOService {
12321249

12331250
return result.map((m) => ({
12341251
member: m.member,
1235-
agentId: m.agentId,
1252+
agentId: m.agentId.toString(),
12361253
role: m.role,
12371254
weight: Number(m.weight),
12381255
addedAt: Number(m.addedAt),
@@ -1293,18 +1310,40 @@ export class DAOService {
12931310
return [...result]
12941311
}
12951312

1296-
async daoExists(daoId: string): Promise<boolean> {
1297-
expectDefined(daoId, 'DAO ID is required')
1313+
async daoExists(daoIdOrName: string): Promise<boolean> {
1314+
expectDefined(daoIdOrName, 'DAO ID or name is required')
12981315
expect(
1299-
daoId.length > 0 && daoId.length <= 100,
1300-
`DAO ID must be 1-100 characters, got ${daoId.length}`,
1316+
daoIdOrName.length > 0 && daoIdOrName.length <= 100,
1317+
`DAO ID/name must be 1-100 characters, got ${daoIdOrName.length}`,
13011318
)
1302-
return this.publicClient.readContract({
1303-
address: this.config.daoRegistryAddress,
1304-
abi: DAORegistryABI,
1305-
functionName: 'daoExists',
1306-
args: [toHex(daoId)],
1307-
})
1319+
1320+
// If it looks like a bytes32 hex, check by ID directly
1321+
if (daoIdOrName.startsWith('0x') && daoIdOrName.length === 66) {
1322+
return this.publicClient.readContract({
1323+
address: this.config.daoRegistryAddress,
1324+
abi: DAORegistryABI,
1325+
functionName: 'daoExists',
1326+
args: [daoIdOrName as `0x${string}`],
1327+
})
1328+
}
1329+
1330+
// Otherwise, try to look up by name using getDAOByName
1331+
// If it returns a non-zero daoId, the DAO exists
1332+
try {
1333+
const result = await this.publicClient.readContract({
1334+
address: this.config.daoRegistryAddress,
1335+
abi: DAORegistryABI,
1336+
functionName: 'getDAOByName',
1337+
args: [daoIdOrName],
1338+
})
1339+
// Check if the returned daoId is non-zero
1340+
const dao = result as { daoId: `0x${string}` }
1341+
return (
1342+
dao.daoId !== '0x0000000000000000000000000000000000000000000000000000000000000000'
1343+
)
1344+
} catch {
1345+
return false
1346+
}
13081347
}
13091348

13101349
async getDAOCount(): Promise<number> {
@@ -2003,12 +2042,12 @@ export class DAOService {
20032042
minQualityScore: Number(raw.params.minQualityScore),
20042043
boardVotingPeriod: Number(raw.params.boardVotingPeriod),
20052044
gracePeriod: Number(raw.params.gracePeriod),
2006-
minProposalStake: raw.params.minProposalStake,
2045+
minProposalStake: raw.params.minProposalStake.toString(),
20072046
quorumBps: Number(raw.params.quorumBps),
20082047
},
20092048
boardMembers: raw.boardMembers.map((m) => ({
20102049
member: m.member,
2011-
agentId: m.agentId,
2050+
agentId: m.agentId.toString(),
20122051
role: m.role,
20132052
weight: Number(m.weight),
20142053
addedAt: Number(m.addedAt),
@@ -2032,8 +2071,8 @@ export class DAOService {
20322071
additionalRecipients: [...raw.additionalRecipients],
20332072
recipientShares: raw.recipientShares.map((s) => Number(s)),
20342073
directorWeight: Number(raw.directorWeight),
2035-
communityStake: raw.communityStake,
2036-
totalFunded: raw.totalFunded,
2074+
communityStake: raw.communityStake.toString(),
2075+
totalFunded: raw.totalFunded.toString(),
20372076
status: toFundingStatus(raw.status),
20382077
createdAt: Number(raw.createdAt),
20392078
lastFundedAt: Number(raw.lastFundedAt),

apps/autocrat/lib/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export interface DirectorPersona {
103103

104104
export interface BoardMemberConfig {
105105
member: Address
106-
agentId: bigint // EIP-8004 ID for AI, 0n for human
106+
agentId: string // EIP-8004 ID for AI (as string for JSON), "0" for human
107107
role: string
108108
weight: number
109109
addedAt: number
@@ -116,9 +116,9 @@ export interface GovernanceParams {
116116
boardVotingPeriod: number
117117
autocratVotingPeriod?: number
118118
gracePeriod: number
119-
minProposalStake: bigint
119+
minProposalStake: string // In wei, as string for JSON
120120
minBackers?: number
121-
minStakeForVeto?: bigint
121+
minStakeForVeto?: string // In wei, as string for JSON
122122
vetoThreshold?: number
123123
quorumBps: number
124124
}

0 commit comments

Comments
 (0)