|
1 | 1 | import { ethers } from 'ethers'; |
2 | 2 | import type { Address } from 'viem'; |
3 | 3 |
|
4 | | -import type { TEENodeWithStatus, TEEInfo, TEERegistryOverview, TEETypeInfo, TEETypeSummary } from 'lib/opengradient/teeRegistry'; |
5 | | -import { TEE_REGISTRY_ADDRESS } from 'lib/opengradient/teeRegistry'; |
6 | | - |
7 | 4 | import TEERegistryAbi from './abi/TEERegistry.json'; |
8 | 5 | import { ethDevnetProvider } from './providers'; |
9 | 6 |
|
| 7 | +export const TEE_REGISTRY_ADDRESS = '0x4e72238852f3c918f4E4e57AeC9280dDB0c80248'; |
| 8 | + |
10 | 9 | const contract = new ethers.Contract(TEE_REGISTRY_ADDRESS, TEERegistryAbi, ethDevnetProvider); |
11 | 10 |
|
| 11 | +export interface TEETypeInfo { |
| 12 | + typeId: number; |
| 13 | + name: string; |
| 14 | + addedAt: bigint; |
| 15 | +} |
| 16 | + |
| 17 | +export interface TEEInfo { |
| 18 | + teeId: string; |
| 19 | + owner: Address; |
| 20 | + paymentAddress: Address; |
| 21 | + endpoint: string; |
| 22 | + publicKey: string; |
| 23 | + tlsCertificate: string; |
| 24 | + pcrHash: string; |
| 25 | + teeType: number; |
| 26 | + enabled: boolean; |
| 27 | + registeredAt: bigint; |
| 28 | + lastHeartbeatAt: bigint; |
| 29 | +} |
| 30 | + |
| 31 | +export interface TEENodeWithStatus extends TEEInfo { |
| 32 | + isActive: boolean; |
| 33 | +} |
| 34 | + |
| 35 | +export interface TEETypeSummary { |
| 36 | + typeId: number; |
| 37 | + name: string; |
| 38 | + totalNodes: number; |
| 39 | + enabledNodes: number; |
| 40 | + activeNodes: number; |
| 41 | + approvedPCRs: number; |
| 42 | + addedAt: bigint; |
| 43 | +} |
| 44 | + |
| 45 | +export interface TEERegistryStats { |
| 46 | + totalTypes: number; |
| 47 | + totalNodes: number; |
| 48 | + activeNodes: number; |
| 49 | + enabledNodes: number; |
| 50 | + approvedPCRs: number; |
| 51 | +} |
| 52 | + |
12 | 53 | export const getTEETypes = async(): Promise<Array<TEETypeInfo>> => { |
13 | 54 | const [ typeIds, infos ] = await contract.getTEETypes(); |
14 | 55 |
|
@@ -68,7 +109,11 @@ export const getHeartbeatMaxAge = async(): Promise<bigint> => { |
68 | 109 | /** |
69 | 110 | * Fetch full registry overview: types, nodes per type with status, and global stats. |
70 | 111 | */ |
71 | | -export const getTEERegistryOverviewFromContract = async(): Promise<TEERegistryOverview> => { |
| 112 | +export const getTEERegistryOverview = async(): Promise<{ |
| 113 | + types: Array<TEETypeSummary>; |
| 114 | + stats: TEERegistryStats; |
| 115 | + nodesByType: Record<number, Array<TEENodeWithStatus>>; |
| 116 | +}> => { |
72 | 117 | // 1. Get all TEE types |
73 | 118 | const types = await getTEETypes(); |
74 | 119 |
|
@@ -141,3 +186,5 @@ export const getTEERegistryOverviewFromContract = async(): Promise<TEERegistryOv |
141 | 186 | nodesByType, |
142 | 187 | }; |
143 | 188 | }; |
| 189 | + |
| 190 | +export const TEE_REGISTRY_QUERY_KEY = [ 'opengradient', 'teeRegistry' ]; |
0 commit comments