Skip to content

Commit

Permalink
Experimental erc20 fix crash when no address provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Dec 21, 2024
1 parent d34983a commit 6f23034
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-coats-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@3loop/transaction-decoder': patch
---

Fix crash in experimental erc20 resolver when address is empty. We provide an empty address when we decode logs for errors
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { erc20Abi, getAddress, getContract } from 'viem'

const getLocalFragments = (service: PublicClient, { address, chainId }: RequestModel.GetContractABIStrategy) =>
Effect.gen(function* () {
if (address === '') return Effect.fail(new RequestModel.ResolveStrategyABIError('local-strategy', address, chainId))

const client = yield* service
.getPublicClient(chainId)
.pipe(
Expand All @@ -13,11 +15,13 @@ const getLocalFragments = (service: PublicClient, { address, chainId }: RequestM
),
)

const inst = getContract({
abi: erc20Abi,
address: getAddress(address),
client: client.client,
})
const inst = yield* Effect.try(() =>
getContract({
abi: erc20Abi,
address: getAddress(address),
client: client.client,
}),
)

const decimals = yield* Effect.tryPromise({
try: () => inst.read.decimals(),
Expand Down

0 comments on commit 6f23034

Please sign in to comment.