|
1 | | -import { |
2 | | - EtherscanStrategyResolver, |
3 | | - FourByteStrategyResolver, |
4 | | - ContractABI, |
5 | | - AbiStore, |
6 | | - SourcifyStrategyResolver, |
7 | | - OpenchainStrategyResolver, |
8 | | - EtherscanV2StrategyResolver, |
9 | | -} from '../effect.js' |
10 | | -import { Config, Effect, Layer } from 'effect' |
| 1 | +import { ContractABI, AbiStore } from '../effect.js' |
| 2 | +import { Effect, Layer } from 'effect' |
11 | 3 |
|
12 | 4 | const abiCache = new Map<string, ContractABI>() |
13 | 5 |
|
14 | | -export const InMemoryAbiStoreLive = Layer.effect( |
15 | | - AbiStore, |
16 | | - Effect.gen(function* () { |
17 | | - const etherscanApiKey = yield* Config.string('ETHERSCAN_API_KEY').pipe( |
18 | | - Effect.catchTag('ConfigError', () => { |
19 | | - return Effect.succeed(undefined) |
20 | | - }), |
21 | | - ) |
22 | | - const etherscanEndpoint = yield* Config.string('ETHERSCAN_ENDPOINT').pipe(Effect.orElseSucceed(() => undefined)) |
23 | | - |
24 | | - const etherscanStrategy = |
25 | | - etherscanEndpoint && etherscanApiKey |
26 | | - ? EtherscanStrategyResolver({ |
27 | | - apikey: etherscanApiKey, |
28 | | - endpoint: etherscanEndpoint, |
29 | | - }) |
30 | | - : etherscanApiKey |
31 | | - ? EtherscanV2StrategyResolver({ |
32 | | - apikey: etherscanApiKey, |
33 | | - }) |
34 | | - : undefined |
35 | | - |
36 | | - return AbiStore.of({ |
37 | | - strategies: { |
38 | | - default: [ |
39 | | - etherscanStrategy, |
40 | | - SourcifyStrategyResolver(), |
41 | | - OpenchainStrategyResolver(), |
42 | | - FourByteStrategyResolver(), |
43 | | - ].filter(Boolean), |
44 | | - }, |
| 6 | +export const make = (strategies: AbiStore['strategies']) => |
| 7 | + Layer.succeed( |
| 8 | + AbiStore, |
| 9 | + AbiStore.of({ |
| 10 | + strategies, |
45 | 11 | set: (_key, value) => |
46 | 12 | Effect.sync(() => { |
47 | 13 | if (value.status === 'success') { |
@@ -82,6 +48,5 @@ export const InMemoryAbiStoreLive = Layer.effect( |
82 | 48 | result: null, |
83 | 49 | } |
84 | 50 | }), |
85 | | - }) |
86 | | - }), |
87 | | -) |
| 51 | + }), |
| 52 | + ) |
0 commit comments