1- import {
2- Context ,
3- Effect ,
4- Either ,
5- RequestResolver ,
6- Request ,
7- Array ,
8- pipe ,
9- Data ,
10- PrimaryKey ,
11- Schema ,
12- SchemaAST ,
13- } from 'effect'
14- import { ContractABI , ContractAbiResolverStrategy , GetContractABIStrategy } from './abi-strategy/request-model.js'
1+ import { Effect , Either , RequestResolver , Request , Array , pipe , Data , PrimaryKey , Schema , SchemaAST } from 'effect'
2+ import { ContractABI } from './abi-strategy/request-model.js'
153import { Abi } from 'viem'
16-
17- export interface AbiParams {
18- chainID : number
19- address : string
20- event ?: string | undefined
21- signature ?: string | undefined
22- }
23-
24- export interface ContractAbiSuccess {
25- status : 'success'
26- result : ContractABI
27- }
28-
29- export interface ContractAbiNotFound {
30- status : 'not-found'
31- result : null
32- }
33-
34- export interface ContractAbiEmpty {
35- status : 'empty'
36- result : null
37- }
38-
39- export type ContractAbiResult = ContractAbiSuccess | ContractAbiNotFound | ContractAbiEmpty
40-
41- type ChainOrDefault = number | 'default'
42-
43- export interface AbiStore < Key = AbiParams , Value = ContractAbiResult > {
44- readonly strategies : Record < ChainOrDefault , readonly ContractAbiResolverStrategy [ ] >
45- readonly set : ( key : Key , value : Value ) => Effect . Effect < void , never >
46- readonly get : ( arg : Key ) => Effect . Effect < Value , never >
47- readonly getMany ?: ( arg : Array < Key > ) => Effect . Effect < Array < Value > , never >
48- }
49-
50- export const AbiStore = Context . GenericTag < AbiStore > ( '@3loop-decoder/AbiStore' )
4+ import { AbiParams , AbiStore } from './abi-store.js'
515
526interface LoadParameters {
537 readonly chainID : number
@@ -174,7 +128,7 @@ const getBestMatch = (abi: ContractABI | null) => {
174128const AbiLoaderRequestResolver : Effect . Effect <
175129 RequestResolver . RequestResolver < AbiLoader , never > ,
176130 never ,
177- AbiStore < AbiParams , ContractAbiResult >
131+ AbiStore
178132> = RequestResolver . makeBatched ( ( requests : Array < AbiLoader > ) =>
179133 Effect . gen ( function * ( ) {
180134 if ( requests . length === 0 ) return
@@ -218,27 +172,19 @@ const AbiLoaderRequestResolver: Effect.Effect<
218172 const allAvailableStrategies = Array . prependAll ( strategies . default , strategies [ req . chainID ] ?? [ ] ) . filter (
219173 ( strategy ) => strategy . type === 'address' ,
220174 )
221-
222175 return Effect . validateFirst ( allAvailableStrategies , ( strategy ) => {
223- return pipe (
224- Effect . request (
225- new GetContractABIStrategy ( {
226- address : req . address ,
227- chainId : req . chainID ,
228- strategyId : strategy . id ,
229- } ) ,
230- strategy . resolver ,
231- ) ,
232- Effect . withRequestCaching ( true ) ,
233- )
176+ return strategy . resolver ( {
177+ address : req . address ,
178+ chainId : req . chainID ,
179+ strategyId : strategy . id ,
180+ } )
234181 } ) . pipe (
235182 Effect . map ( Either . left ) ,
236183 Effect . orElseSucceed ( ( ) => Either . right ( req ) ) ,
237184 )
238185 } ,
239186 {
240187 concurrency : 'unbounded' ,
241- batching : true ,
242188 } ,
243189 )
244190
@@ -254,19 +200,13 @@ const AbiLoaderRequestResolver: Effect.Effect<
254200
255201 // TODO: Distinct the errors and missing data, so we can retry on errors
256202 return Effect . validateFirst ( allAvailableStrategies , ( strategy ) =>
257- pipe (
258- Effect . request (
259- new GetContractABIStrategy ( {
260- address,
261- chainId : chainID ,
262- event,
263- signature,
264- strategyId : strategy . id ,
265- } ) ,
266- strategy . resolver ,
267- ) ,
268- Effect . withRequestCaching ( true ) ,
269- ) ,
203+ strategy . resolver ( {
204+ address,
205+ chainId : chainID ,
206+ event,
207+ signature,
208+ strategyId : strategy . id ,
209+ } ) ,
270210 ) . pipe ( Effect . orElseSucceed ( ( ) => null ) )
271211 } ,
272212 {
0 commit comments