1+ import type { Context , Event } from 'ponder:registry'
12import { ponder } from 'ponder:registry'
23import { providers } from 'ponder:schema'
34import { PDP_PRODUCT_TYPE } from '@filoz/repair-db'
@@ -6,14 +7,13 @@ import { ServiceProviderRegistryAbi } from './abis.ts'
67import { eventBlock } from './event-utils.ts'
78
89interface ProviderInfo {
9- providerAddress : string | null
10+ providerAddress : Address | null
1011 name : string | null
1112 providerActive : boolean
1213}
1314
14- interface ReadProviderContext {
15- client : any
16- }
15+ type SpRegistryContext = Pick < Context < 'SPRegistry:ProviderRegistered' > , 'client' | 'db' >
16+ type SpRegistryEvent = Pick < Event < 'SPRegistry:ProviderRegistered' > , 'block' | 'log' >
1717
1818function decodeCapabilityValue ( hex : `0x${string } `) : string {
1919 try {
@@ -27,23 +27,23 @@ function decodeCapabilityValue(hex: `0x${string}`): string {
2727}
2828
2929function capabilitiesFromEntries (
30- keys : readonly string [ ] | undefined ,
31- values : readonly `0x${string } `[ ] | undefined
30+ keys : readonly string [ ] ,
31+ values : readonly `0x${string } `[ ]
3232) : Record < string , string > | null {
33- if ( ! keys ? .length ) return null
33+ if ( keys . length === 0 ) return null
3434
3535 const capabilities : Record < string , string > = { }
3636 for ( let i = 0 ; i < keys . length ; i ++ ) {
3737 const key = keys [ i ]
38- const value = values ?. [ i ]
38+ const value = values [ i ]
3939 if ( key === undefined ) continue
4040 capabilities [ key ] = value ? decodeCapabilityValue ( value ) : ''
4141 }
4242 return capabilities
4343}
4444
4545async function readProviderInfo (
46- context : ReadProviderContext ,
46+ context : Pick < SpRegistryContext , 'client' > ,
4747 registryAddress : Address ,
4848 providerId : bigint ,
4949 blockNumber : bigint
@@ -56,7 +56,7 @@ async function readProviderInfo(
5656 blockNumber,
5757 } )
5858
59- const [ providerAddress , , name , , providerActive ] = result as readonly [ string , string , string , string , boolean ]
59+ const [ providerAddress , , name , , providerActive ] = result
6060
6161 return { providerAddress, name, providerActive }
6262}
@@ -67,10 +67,10 @@ async function upsertProviderInfo({
6767 providerId,
6868 providerAddress,
6969} : {
70- context : ReadProviderContext & { db : any }
71- event : { block : { number : bigint } ; log : { address : string } }
70+ context : SpRegistryContext
71+ event : SpRegistryEvent
7272 providerId : bigint
73- providerAddress ?: string
73+ providerAddress ?: Address
7474} ) {
7575 let info : ProviderInfo = {
7676 providerAddress : providerAddress ?? null ,
@@ -79,7 +79,7 @@ async function upsertProviderInfo({
7979 }
8080
8181 try {
82- info = await readProviderInfo ( context , event . log . address as Address , providerId , event . block . number )
82+ info = await readProviderInfo ( context , event . log . address , providerId , event . block . number )
8383 } catch {
8484 // The event payload is enough to keep address-level repair inventory usable.
8585 }
@@ -108,27 +108,18 @@ async function upsertProviderInfo({
108108}
109109
110110ponder . on ( 'SPRegistry:ProviderRegistered' , async ( { event, context } ) => {
111- const { providerId, serviceProvider } = event . args as {
112- providerId : bigint
113- serviceProvider : string
114- }
111+ const { providerId, serviceProvider } = event . args
115112
116113 await upsertProviderInfo ( { context, event, providerId, providerAddress : serviceProvider } )
117114} )
118115
119116ponder . on ( 'SPRegistry:ProviderInfoUpdated' , async ( { event, context } ) => {
120- const { providerId } = event . args as { providerId : bigint }
117+ const { providerId } = event . args
121118 await upsertProviderInfo ( { context, event, providerId } )
122119} )
123120
124121ponder . on ( 'SPRegistry:ProductAdded' , async ( { event, context } ) => {
125- const { providerId, productType, serviceProvider, capabilityKeys, capabilityValues } = event . args as {
126- providerId : bigint
127- productType : number
128- serviceProvider : string
129- capabilityKeys ?: readonly string [ ]
130- capabilityValues ?: readonly `0x${string } `[ ]
131- }
122+ const { providerId, productType, serviceProvider, capabilityKeys, capabilityValues } = event . args
132123 if ( productType !== PDP_PRODUCT_TYPE ) return
133124
134125 const capabilities = capabilitiesFromEntries ( capabilityKeys , capabilityValues )
@@ -157,13 +148,7 @@ ponder.on('SPRegistry:ProductAdded', async ({ event, context }) => {
157148} )
158149
159150ponder . on ( 'SPRegistry:ProductUpdated' , async ( { event, context } ) => {
160- const { providerId, productType, serviceProvider, capabilityKeys, capabilityValues } = event . args as {
161- providerId : bigint
162- productType : number
163- serviceProvider : string
164- capabilityKeys ?: readonly string [ ]
165- capabilityValues ?: readonly `0x${string } `[ ]
166- }
151+ const { providerId, productType, serviceProvider, capabilityKeys, capabilityValues } = event . args
167152 if ( productType !== PDP_PRODUCT_TYPE ) return
168153
169154 const capabilities = capabilitiesFromEntries ( capabilityKeys , capabilityValues )
@@ -192,7 +177,7 @@ ponder.on('SPRegistry:ProductUpdated', async ({ event, context }) => {
192177} )
193178
194179ponder . on ( 'SPRegistry:ProductRemoved' , async ( { event, context } ) => {
195- const { providerId, productType } = event . args as { providerId : bigint ; productType : number }
180+ const { providerId, productType } = event . args
196181 if ( productType !== PDP_PRODUCT_TYPE ) return
197182
198183 const existing = await context . db . find ( providers , { providerId } )
@@ -205,7 +190,7 @@ ponder.on('SPRegistry:ProductRemoved', async ({ event, context }) => {
205190} )
206191
207192ponder . on ( 'SPRegistry:ProviderRemoved' , async ( { event, context } ) => {
208- const { providerId } = event . args as { providerId : bigint }
193+ const { providerId } = event . args
209194 const existing = await context . db . find ( providers , { providerId } )
210195 if ( ! existing ) return
211196
0 commit comments