Skip to content

Commit 5cd7d62

Browse files
committed
Add default ABIs as fallback
1 parent 2a6940b commit 5cd7d62

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

packages/transaction-decoder/src/abi-loader.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Effect, Either, RequestResolver, Request, Array, Data, PrimaryKey, Schema, SchemaAST } from 'effect'
22
import { ContractABI } from './abi-strategy/request-model.js'
3-
import { Abi } from 'viem'
3+
import { Abi, erc20Abi, erc721Abi } from 'viem'
44
import * as AbiStore from './abi-store.js'
55
import * as StrategyExecutorModule from './abi-strategy/strategy-executor.js'
66
import { SAFE_MULTISEND_SIGNATURE, SAFE_MULTISEND_ABI, AA_ABIS } from './decoding/constants.js'
@@ -32,7 +32,7 @@ export class EmptyCalldataError extends Data.TaggedError('DecodeError')<
3232
}
3333
}
3434

35-
class SchemaAbi extends Schema.make<Abi>(SchemaAST.objectKeyword) {}
35+
class SchemaAbi extends Schema.make<Abi>(SchemaAST.objectKeyword) { }
3636
class AbiLoader extends Schema.TaggedRequest<AbiLoader>()('AbiLoader', {
3737
failure: Schema.instanceOf(MissingABIError),
3838
success: Schema.Array(Schema.Struct({ abi: SchemaAbi, id: Schema.optional(Schema.String) })),
@@ -81,18 +81,18 @@ const setValue = (key: AbiLoader, abi: (ContractABI & { strategyId: string }) |
8181
},
8282
abi == null
8383
? {
84-
type: 'func' as const,
85-
abi: '',
86-
address: key.address,
87-
chainID: key.chainID,
88-
signature: key.signature || '',
89-
status: 'not-found' as const,
90-
}
84+
type: 'func' as const,
85+
abi: '',
86+
address: key.address,
87+
chainID: key.chainID,
88+
signature: key.signature || '',
89+
status: 'not-found' as const,
90+
}
9191
: {
92-
...abi,
93-
source: abi.strategyId,
94-
status: 'success' as const,
95-
},
92+
...abi,
93+
source: abi.strategyId,
94+
status: 'success' as const,
95+
},
9696
)
9797
})
9898

@@ -309,9 +309,9 @@ export const AbiLoaderRequestResolver = RequestResolver.makeBatched((requests: A
309309
const cacheEffect =
310310
allAbis.length > 0
311311
? Effect.forEach(allAbis, (abi) => setValue(request, abi), {
312-
discard: true,
313-
concurrency: 'unbounded',
314-
})
312+
discard: true,
313+
concurrency: 'unbounded',
314+
})
315315
: setValue(request, null)
316316

317317
return Effect.zipRight(
@@ -335,14 +335,15 @@ export const AbiLoaderRequestResolver = RequestResolver.makeBatched((requests: A
335335
// in a missing Fragment. We treat this issue as a minor one for now, as we expect it to occur rarely on contracts that
336336
// are not verified and with a non standard events structure.
337337

338+
const errorAbis: Abi = [...solidityPanic, ...solidityError]
339+
338340
export const getAndCacheAbi = (params: AbiStore.AbiParams) =>
339341
Effect.gen(function* () {
340342
if (params.event === '0x' || params.signature === '0x') {
341343
return yield* Effect.fail(new EmptyCalldataError(params))
342344
}
343345

344346
if (params.signature && errorFunctionSignatures.includes(params.signature)) {
345-
const errorAbis: Abi = [...solidityPanic, ...solidityError]
346347
return [{ abi: errorAbis, id: undefined }]
347348
}
348349

@@ -354,7 +355,11 @@ export const getAndCacheAbi = (params: AbiStore.AbiParams) =>
354355
return [{ abi: AA_ABIS[params.signature], id: undefined }]
355356
}
356357

357-
return yield* Effect.request(new AbiLoader(params), AbiLoaderRequestResolver)
358+
const abis = yield* Effect.request(new AbiLoader(params), AbiLoaderRequestResolver)
359+
return Array.appendAll(abis, [
360+
{ abi: erc20Abi, id: undefined },
361+
{ abi: erc721Abi, id: undefined },
362+
])
358363
}).pipe(
359364
Effect.withSpan('AbiLoader.GetAndCacheAbi', {
360365
attributes: {

0 commit comments

Comments
 (0)