Skip to content

Commit

Permalink
0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KABBOUCHI committed Jan 28, 2024
1 parent 06cb187 commit 53dc6fb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@instadapp/utils",
"version": "0.7.0",
"version": "0.7.1",
"description": "",
"repository": "instadapp/utils",
"license": "MIT",
Expand Down
9 changes: 9 additions & 0 deletions src/abi/fetcher/AbiFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ export class AbiFetcher {
}
}

if (!implementationAddress) {
try {
const contract = new Contract(contractAddress, originalAbi, provider as any)
implementationAddress = await contract.implementation()
} catch (error) {

}
}

if (implementationAddress) {
implementationAbi = await this._get(implementationAddress, network, metadata)
return proxyFetchMode === 'implementationOnly' ? implementationAbi : [...originalAbi, ...implementationAbi]
Expand Down
14 changes: 10 additions & 4 deletions test/abi.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, describe, test, vi } from 'vitest'
import NodeCache from 'node-cache'
import { AbiFetcher, ICache } from '../src'
import { mainnetUsdcImplementationAbi, mainnetUsdcProxyAbi, polygonMaticABI } from './fixtures'
import { polygonMaticABI } from './fixtures'

const defaultAbiCache = new NodeCache()

Expand Down Expand Up @@ -78,13 +78,13 @@ describe.concurrent('abi', () => {
const network = 'mainnet'

const proxyOnlyAbi = await defaultAbiFetcher.get(usdcAddress, network, 'proxyOnly')
expect(proxyOnlyAbi).toEqual(mainnetUsdcProxyAbi)
expect(proxyOnlyAbi.length).toBe(9)

const implementationOnlyAbi = await defaultAbiFetcher.get(usdcAddress, network, 'implementationOnly')
expect(implementationOnlyAbi).toEqual(mainnetUsdcImplementationAbi)
expect(implementationOnlyAbi.length).toBe(72)

const abi = await defaultAbiFetcher.get(usdcAddress, network, 'proxyAndImplementation')
expect(abi).toEqual([...mainnetUsdcProxyAbi, ...mainnetUsdcImplementationAbi])
expect(abi.length).toBe(81)
})

test('can fetch proxy implementation - EIP-897', async () => {
Expand Down Expand Up @@ -135,6 +135,12 @@ describe.concurrent('abi', () => {

expect(abi.length).to.be.greaterThan(0)
})

test('support raw implementation address', async () => {
const abi = await defaultAbiFetcher.get('0x0204Cd037B2ec03605CFdFe482D8e257C765fA1B', 'mainnet', 'implementationOnly')

expect(abi.length).to.be.greaterThan(0)
})
}, {
retry: 2
})

0 comments on commit 53dc6fb

Please sign in to comment.