From 31bcd61643883ef3769aa6e2a488f0b5972db5b8 Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Wed, 25 Oct 2023 17:20:42 +0300 Subject: [PATCH] 0.5.2 --- package.json | 2 +- src/abi/fetcher/AbiFetcher.ts | 41 +++++++++++++++++++++++++++-------- src/abi/types.ts | 10 +++++++-- test/abi.test.ts | 2 +- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index ffd1ca6..2a25ade 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@instadapp/utils", - "version": "0.5.1", + "version": "0.5.2", "description": "", "repository": "instadapp/utils", "license": "MIT", diff --git a/src/abi/fetcher/AbiFetcher.ts b/src/abi/fetcher/AbiFetcher.ts index 6aefbd2..e415c06 100644 --- a/src/abi/fetcher/AbiFetcher.ts +++ b/src/abi/fetcher/AbiFetcher.ts @@ -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' } } @@ -53,14 +55,18 @@ export class AbiFetcher { } private async fetchABI (contractAddress: string, network: Network): Promise { - 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}`) @@ -88,14 +94,14 @@ export class AbiFetcher { }) } - private async fetchABIFromBlockscout (contractAddress: string, network: Network): Promise { - const { retries, networkToBlockscoutAPI } = this.options + private async fetchABIFromBlockscoutV4 (contractAddress: string, network: Network): Promise { + 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, @@ -114,6 +120,23 @@ export class AbiFetcher { }) } + private async fetchABIFromBlockscoutV5 (contractAddress: string, network: Network): Promise { + 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): Promise { const { cache } = this.options diff --git a/src/abi/types.ts b/src/abi/types.ts index b707f8f..77c84ca 100644 --- a/src/abi/types.ts +++ b/src/abi/types.ts @@ -53,10 +53,16 @@ export interface IAbiFetcherOptions { * @default { aurora: 'https://explorer.aurora.dev/graphiql', - fuse: 'https://explorer.fuse.io/graphiql', } */ - networkToBlockscoutAPI: Partial>, + networkToBlockscoutV4Graph: Partial>, + /** + * @default + { + fuse: 'https://explorer.fuse.io/api', + } + */ + networkToBlockscoutV5Api: Partial>, /** * @default proxyAndImplementation */ diff --git a/test/abi.test.ts b/test/abi.test.ts index b0c86c3..5c564cf 100644 --- a/test/abi.test.ts +++ b/test/abi.test.ts @@ -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)