Skip to content

Commit

Permalink
0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
KABBOUCHI committed Oct 25, 2023
1 parent d5113c4 commit 31bcd61
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 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.5.1",
"version": "0.5.2",
"description": "",
"repository": "instadapp/utils",
"license": "MIT",
Expand Down
41 changes: 32 additions & 9 deletions src/abi/fetcher/AbiFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ const DEFAULTS: IAbiFetcherOptions = {
'polygon-zkevm': 'https://api-zkevm.polygonscan.com/api',
base: 'https://api.basescan.org/api'
},
networkToBlockscoutAPI: {
aurora: 'https://explorer.aurora.dev/graphiql',
fuse: 'https://explorer.fuse.io/graphiql'
networkToBlockscoutV4Graph: {
aurora: 'https://explorer.aurora.dev/graphiql'
},
networkToBlockscoutV5Api: {
fuse: 'https://explorer.fuse.io/api'
}
}

Expand All @@ -53,14 +55,18 @@ export class AbiFetcher {
}

private async fetchABI (contractAddress: string, network: Network): Promise<JsonFragment[]> {
const { networkToEtherscanAPI, networkToBlockscoutAPI } = this.options
const { networkToEtherscanAPI, networkToBlockscoutV4Graph, networkToBlockscoutV5Api } = this.options

if (networkToEtherscanAPI[network]) {
return await this.fetchABIFromEtherscan(contractAddress, network)
}

if (networkToBlockscoutAPI[network]) {
return await this.fetchABIFromBlockscout(contractAddress, network)
if (networkToBlockscoutV4Graph[network]) {
return await this.fetchABIFromBlockscoutV4(contractAddress, network)
}

if (networkToBlockscoutV5Api[network]) {
return await this.fetchABIFromBlockscoutV5(contractAddress, network)
}

throw new Error(`Couldn't fetch ABI for ${contractAddress}`)
Expand Down Expand Up @@ -88,14 +94,14 @@ export class AbiFetcher {
})
}

private async fetchABIFromBlockscout (contractAddress: string, network: Network): Promise<JsonFragment[]> {
const { retries, networkToBlockscoutAPI } = this.options
private async fetchABIFromBlockscoutV4 (contractAddress: string, network: Network): Promise<JsonFragment[]> {
const { retries, networkToBlockscoutV4Graph } = this.options

return await retry(
async () =>
await axios
.post(
networkToBlockscoutAPI[network],
networkToBlockscoutV4Graph[network],
{
query: `{\n address(hash:"${contractAddress}") {\n \tsmartContract {\n abi\n }\n }\t\n}`,
variables: null,
Expand All @@ -114,6 +120,23 @@ export class AbiFetcher {
})
}

private async fetchABIFromBlockscoutV5 (contractAddress: string, network: Network): Promise<JsonFragment[]> {
const { retries, networkToBlockscoutV5Api } = this.options

return await retry(
async () =>
await axios
.get(
`${networkToBlockscoutV5Api[network]}/v2/smart-contracts/${contractAddress}`
)
.then(({ data }) => {
return data.abi
}),
{
retries
})
}

private async _get (contractAddress: string, network: Network, metadata?: Record<string, any>): Promise<JsonFragment[]> {
const { cache } = this.options

Expand Down
10 changes: 8 additions & 2 deletions src/abi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ export interface IAbiFetcherOptions {
* @default
{
aurora: 'https://explorer.aurora.dev/graphiql',
fuse: 'https://explorer.fuse.io/graphiql',
}
*/
networkToBlockscoutAPI: Partial<Record<Network, string>>,
networkToBlockscoutV4Graph: Partial<Record<Network, string>>,
/**
* @default
{
fuse: 'https://explorer.fuse.io/api',
}
*/
networkToBlockscoutV5Api: Partial<Record<Network, string>>,
/**
* @default proxyAndImplementation
*/
Expand Down
2 changes: 1 addition & 1 deletion test/abi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe.concurrent('abi', () => {
expect(abi.length).to.be.greaterThan(0)
})

test.skip('can fetch abi using blockscout - fuse', async () => {
test('can fetch abi using blockscout v5 - fuse', async () => {
const abi = await defaultAbiFetcher.get('0xeEeEEb57642040bE42185f49C52F7E9B38f8eeeE', 'fuse', 'implementationOnly')

expect(abi.length).to.be.greaterThan(0)
Expand Down

0 comments on commit 31bcd61

Please sign in to comment.