Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions lib/opengradient/contracts/teeRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
import { ethers } from 'ethers';
import type { Address } from 'viem';

import type { TEENodeWithStatus, TEEInfo, TEERegistryOverview, TEETypeInfo, TEETypeSummary } from 'lib/opengradient/teeRegistry';
import { TEE_REGISTRY_ADDRESS } from 'lib/opengradient/teeRegistry';

import TEERegistryAbi from './abi/TEERegistry.json';
import { ethDevnetProvider } from './providers';

export const TEE_REGISTRY_ADDRESS = '0x4e72238852f3c918f4E4e57AeC9280dDB0c80248';

const contract = new ethers.Contract(TEE_REGISTRY_ADDRESS, TEERegistryAbi, ethDevnetProvider);

export interface TEETypeInfo {
typeId: number;
name: string;
addedAt: bigint;
}

export interface TEEInfo {
teeId: string;
owner: Address;
paymentAddress: Address;
endpoint: string;
publicKey: string;
tlsCertificate: string;
pcrHash: string;
teeType: number;
enabled: boolean;
registeredAt: bigint;
lastHeartbeatAt: bigint;
}

export interface TEENodeWithStatus extends TEEInfo {
isActive: boolean;
}

export interface TEETypeSummary {
typeId: number;
name: string;
totalNodes: number;
enabledNodes: number;
activeNodes: number;
approvedPCRs: number;
addedAt: bigint;
}

export interface TEERegistryStats {
totalTypes: number;
totalNodes: number;
activeNodes: number;
enabledNodes: number;
approvedPCRs: number;
}

export const getTEETypes = async(): Promise<Array<TEETypeInfo>> => {
const [ typeIds, infos ] = await contract.getTEETypes();

Expand Down Expand Up @@ -68,7 +109,11 @@ export const getHeartbeatMaxAge = async(): Promise<bigint> => {
/**
* Fetch full registry overview: types, nodes per type with status, and global stats.
*/
export const getTEERegistryOverviewFromContract = async(): Promise<TEERegistryOverview> => {
export const getTEERegistryOverview = async(): Promise<{
types: Array<TEETypeSummary>;
stats: TEERegistryStats;
nodesByType: Record<number, Array<TEENodeWithStatus>>;
}> => {
// 1. Get all TEE types
const types = await getTEETypes();

Expand Down Expand Up @@ -141,3 +186,5 @@ export const getTEERegistryOverviewFromContract = async(): Promise<TEERegistryOv
nodesByType,
};
};

export const TEE_REGISTRY_QUERY_KEY = [ 'opengradient', 'teeRegistry' ];
107 changes: 0 additions & 107 deletions lib/opengradient/teeRegistry.ts

This file was deleted.

15 changes: 0 additions & 15 deletions pages/api/opengradient/tee-registry.ts

This file was deleted.

2 changes: 1 addition & 1 deletion ui/home/HeroBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import { route } from 'nextjs-routes';

import useApiQuery from 'lib/api/useApiQuery';
import { getTEERegistryOverview, TEE_REGISTRY_QUERY_KEY } from 'lib/opengradient/teeRegistry';
import { getTEERegistryOverview, TEE_REGISTRY_QUERY_KEY } from 'lib/opengradient/contracts/teeRegistry';
import { HOMEPAGE_STATS, HOMEPAGE_STATS_MICROSERVICE } from 'stubs/stats';
import { LinkBox, LinkOverlay } from 'toolkit/chakra/link';
import { Skeleton } from 'toolkit/chakra/skeleton';
Expand Down
5 changes: 3 additions & 2 deletions ui/home/TrustedExecution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import { route } from 'nextjs-routes';

import dayjs from 'lib/date/dayjs';
import { getTEERegistryOverview, TEE_REGISTRY_QUERY_KEY, TEE_REGISTRY_ADDRESS, type TEENodeWithStatus } from 'lib/opengradient/teeRegistry';
import { getTEERegistryOverview, TEE_REGISTRY_QUERY_KEY, TEE_REGISTRY_ADDRESS, type TEENodeWithStatus } from 'lib/opengradient/contracts/teeRegistry';
import { Link } from 'toolkit/chakra/link';
import { Skeleton } from 'toolkit/chakra/skeleton';
import { PLACEHOLDER_TEE_REGISTRY_STATS, PLACEHOLDER_TEE_TYPES } from 'ui/opengradient/teeRegistry/placeholders';
Expand Down Expand Up @@ -143,6 +143,7 @@ const TrustedExecution = () => {
.sort((a, b) => Number(b.lastHeartbeatAt - a.lastHeartbeatAt));
}, [ query.data?.nodesByType ]);
const primaryType = types[0];
const visibleNodes = nodes.slice(0, 3);
const isLoading = query.isPlaceholderData;

return (
Expand Down Expand Up @@ -308,7 +309,7 @@ const TrustedExecution = () => {
</Text>
</Flex>
<VStack align="stretch" gap={ 0 }>
{ nodes.length > 0 ? nodes.map((node) => (
{ visibleNodes.length > 0 ? visibleNodes.map((node) => (
<NodePreview key={ node.teeId } node={ node } loading={ isLoading }/>
)) : (
<Text py={ 5 } fontSize="13px" color={ text.muted }>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ui/opengradient/teeRegistry/TEENodeDetailDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, Flex, Text, VStack } from '@chakra-ui/react';
import React from 'react';

import dayjs from 'lib/date/dayjs';
import type { TEENodeWithStatus } from 'lib/opengradient/teeRegistry';
import type { TEENodeWithStatus } from 'lib/opengradient/contracts/teeRegistry';
import { DrawerBackdrop, DrawerBody, DrawerCloseTrigger, DrawerContent, DrawerHeader, DrawerRoot, DrawerTitle } from 'toolkit/chakra/drawer';
import { OPENGRADIENT_BRAND } from 'ui/opengradient/brand';
import AddressEntity from 'ui/shared/entities/address/AddressEntity';
Expand Down
2 changes: 1 addition & 1 deletion ui/opengradient/teeRegistry/TEENodesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, Flex, Text } from '@chakra-ui/react';
import React from 'react';

import dayjs from 'lib/date/dayjs';
import type { TEENodeWithStatus, TEETypeSummary } from 'lib/opengradient/teeRegistry';
import type { TEENodeWithStatus, TEETypeSummary } from 'lib/opengradient/contracts/teeRegistry';
import { Skeleton } from 'toolkit/chakra/skeleton';
import { TableBody, TableCell, TableColumnHeader, TableHeaderSticky, TableRoot, TableRow } from 'toolkit/chakra/table';
import { OPENGRADIENT_BRAND } from 'ui/opengradient/brand';
Expand Down
2 changes: 1 addition & 1 deletion ui/opengradient/teeRegistry/TEETypeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Flex, Grid, Text } from '@chakra-ui/react';
import React from 'react';

import type { TEETypeSummary } from 'lib/opengradient/teeRegistry';
import type { TEETypeSummary } from 'lib/opengradient/contracts/teeRegistry';
import { Skeleton } from 'toolkit/chakra/skeleton';
import { OPENGRADIENT_BRAND } from 'ui/opengradient/brand';

Expand Down
2 changes: 1 addition & 1 deletion ui/opengradient/teeRegistry/placeholders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TEERegistryStats, TEETypeSummary } from 'lib/opengradient/teeRegistry';
import type { TEERegistryStats, TEETypeSummary } from 'lib/opengradient/contracts/teeRegistry';

export const PLACEHOLDER_TEE_REGISTRY_STATS: TEERegistryStats = {
totalTypes: 0,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ui/pages/opengradient/TEERegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import React from 'react';

import { route } from 'nextjs-routes';

import { getTEERegistryOverview, TEE_REGISTRY_QUERY_KEY, TEE_REGISTRY_ADDRESS } from 'lib/opengradient/teeRegistry';
import type { TEENodeWithStatus } from 'lib/opengradient/teeRegistry';
import { getTEERegistryOverview, TEE_REGISTRY_QUERY_KEY, TEE_REGISTRY_ADDRESS } from 'lib/opengradient/contracts/teeRegistry';
import type { TEENodeWithStatus } from 'lib/opengradient/contracts/teeRegistry';
import { Checkbox } from 'toolkit/chakra/checkbox';
import { Link } from 'toolkit/chakra/link';
import { Skeleton } from 'toolkit/chakra/skeleton';
Expand Down
Loading