Skip to content

Commit 1b4f0ce

Browse files
authored
Get ABI from Sourcify (#42)
* Experiment with getting ABI from Sourcify with collateral damage * Add config.abiSource * Fetch ABIs from Sourcify * Fix lint error * Add e2e test for abiSource Sourcify * Use pascalCase instead of startCase without first space * Add newlines to warnings for better visibility * Print compilation diagnostics with path to the file * Ignore outDirs in ESLint * Remove unused zod schema * Add missing dependencies to test-e2e * Run format * Throw when networkId is not found * Register ts-node only if it is not registered already * Test double ts-node registration * Document abiSource and networkIds in README * Add changeset for a bugfix
1 parent fc98312 commit 1b4f0ce

102 files changed

Lines changed: 457 additions & 105 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/lazy-frogs-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@dethcrypto/eth-sdk': patch
3+
---
4+
5+
Fix: Custom network identifiers in `config.contracts` don't fail config validation anymore.

.changeset/tame-pots-kneel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@dethcrypto/eth-sdk': patch
3+
---
4+
5+
Fetch contract ABIs from Sourcify when `config.abiSource` is set to `"sourcify'`.

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@ dist
33
yarn-error.log
44
.DS_Store
55
*.tsbuildinfo
6-
packages/tests/eth-sdk
7-
packages/tests/out
86
.env
97
examples/*/yarn.lock

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
.vscode
33
package.json
44
**/dist/**
5-
packages/test-e2e/test/sdk
5+
packages/test-e2e/test/*/sdk
6+
packages/test-e2e/test/*/outDir

examples/hardhat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"@nomiclabs/hardhat-ethers": "^2.0.2",
2121
"ethers": "^5.4.7",
2222
"hardhat": "^2.6.5",
23-
"typescript": "^4.4.4"
23+
"typescript": "^4"
2424
}
2525
}

examples/vite-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@types/react-dom": "^17.0.0",
3333
"@vitejs/plugin-react": "^1.0.0",
3434
"concurrently": "^6.3.0",
35-
"typescript": "^4.4.4",
35+
"typescript": "^4",
3636
"vite": "^2.6.4"
3737
}
3838
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"proxyquire": "^2.1.3",
5252
"ts-essentials": "^9.0.0",
5353
"ts-node": "^10.4.0",
54-
"typescript": "^4.4.4",
54+
"typescript": "^4",
5555
"wsrun": "^5.2.4"
5656
}
5757
}

packages/eth-sdk/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
- [`etherscanURLs`](#etherscanurls)
3131
- [`rpc`](#rpc)
3232
- [`noFollowProxies`](#nofollowproxies)
33+
- [`abiSource`](#abisource)
34+
- [`networkIds`](#networkids)
3335
- [Examples](#examples)
3436
- [Videos](#videos)
3537
- [Motivation and use cases](#motivation-and-use-cases)
@@ -168,7 +170,8 @@ Predefined network identifiers are:
168170
"arbitrumOne" "arbitrumTestnet"
169171
```
170172

171-
You can configure your own Etherscan URLs in [`etherscanURLs`](#etherscanurls).
173+
You can use other networks, but you will need to configure Etherscan URLs for them in [`etherscanURLs`](#etherscanurls)
174+
or provide [`networkIds`](#networkids) when using Sourcify as `abiSource`.
172175

173176
### `outputPath`
174177

@@ -235,6 +238,33 @@ You can opt out of proxy following by setting `noFollowProxies` flag in your con
235238
}
236239
```
237240

241+
### `abiSource`
242+
243+
_Default: `"etherscan"`_
244+
245+
One of `"etherscan"`, `"sourcify"`. Specifies the source to fetch contract ABIs from.
246+
247+
### `networkIds`
248+
249+
As Sourcify `/files` endpoint requires network identifier, you will need to provide one when using a custom network.
250+
251+
```json
252+
{
253+
"abiSource": "sourcify",
254+
"networkIds": {
255+
"myNetwork": 3
256+
},
257+
"contracts": {
258+
"myNetwork": {
259+
"dai": "0x6b175474e89094c44da98b954eedeac495271d0f"
260+
}
261+
}
262+
}
263+
```
264+
265+
`eth-sdk` already knows ids of 19 commonly used networks, including mainnet, testnets, Optimism and Arbitrum, so you
266+
won't need to provide them. You can find the list of all predefined networks in [`contracts`](#contracts) documentation.
267+
238268
# Examples
239269

240270
Check out examples of using `eth-sdk` in [`/examples`][examples] directory.

packages/eth-sdk/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
"zod": "^3.11.5"
5454
},
5555
"peerDependencies": {
56-
"ethers": "^5",
57-
"@ethersproject/abstract-provider": "^5",
5856
"@ethersproject/abi": "^5",
59-
"@ethersproject/bignumber": "^5"
57+
"@ethersproject/abstract-provider": "^5",
58+
"@ethersproject/bignumber": "^5",
59+
"ethers": "^5"
6060
}
6161
}

packages/eth-sdk/src/abi-management/etherscan/getAbiFromEtherscan.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { parseAddress, UserEtherscanURLs } from '../../config'
55
import { FetchJson } from '../../peripherals/fetchJson'
66
import { Abi } from '../../types'
77
import { UserProvidedNetworkSymbol } from '../networks'
8-
import { EtherscanResponse, getABIFromEtherscan } from './getAbiFromEtherscan'
8+
import { EtherscanResponse, getAbiFromEtherscan } from './getAbiFromEtherscan'
99

10-
describe(getABIFromEtherscan.name, () => {
10+
describe(getAbiFromEtherscan.name, () => {
1111
it('fetches from predefined etherscan URL', async () => {
1212
const apiKey = '{{ API_KEY }}'
1313
const fetch = mockEndpoint()
14-
const actual = await getABIFromEtherscan('mainnet', DAI_ADDRESS, apiKey, {}, fetch)
14+
const actual = await getAbiFromEtherscan('mainnet', DAI_ADDRESS, apiKey, {}, fetch)
1515

1616
expect(actual).toEqual(RETURNED_ABI)
1717
expect(fetch).toHaveBeenCalledWith([
@@ -29,7 +29,7 @@ describe(getABIFromEtherscan.name, () => {
2929

3030
const fetch = mockEndpoint()
3131

32-
const actual = await getABIFromEtherscan(symbol, ADDRESS_ZERO, apiKey, userNetworks, fetch)
32+
const actual = await getAbiFromEtherscan(symbol, ADDRESS_ZERO, apiKey, userNetworks, fetch)
3333

3434
expect(actual).toEqual(RETURNED_ABI)
3535
expect(fetch).toHaveBeenCalledWith([

0 commit comments

Comments
 (0)