Skip to content

Commit

Permalink
feat: sourcify cli plugin (#1841)
Browse files Browse the repository at this point in the history
* chore: update vhs

* sourcify cli plugin

* parse sourcify response

* fix typecheck

* changeset

* add docs

* restore correct public assets

* refactor: sourcify plugin errors

* test: update snapshot

---------

Co-authored-by: wslyvh <[email protected]>
  • Loading branch information
tmm and wslyvh authored Feb 13, 2023
1 parent 7ecc5fa commit cb707f0
Show file tree
Hide file tree
Showing 9 changed files with 767 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sweet-horses-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@wagmi/cli': patch
---

Added [Sourcify](https://sourcify.dev) CLI plugin.
2 changes: 1 addition & 1 deletion docs/pages/cli/plugins.en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ description: 'wagmi CLI plugins'
| [Foundry](/cli/plugins/foundry) | Generate ABIs and watch for Foundry project changes. |
| [Hardhat](/cli/plugins/hardhat) | Generate ABIs and watch for Hardhat projects changes. |
| [React](/cli/plugins/react) | Generate type-safe React Hooks from configuration `contracts`. |
| [Sourcify](/cli/plugins/sourcify) | Fetch ABIs from Sourcify from configuration `contracts`. |

## Creating plugins

Creating plugins to hook into the CLI is quite simple. Plugins most commonly inject contracts into `contracts` config, e.g. [Etherscan](/cli/plugins/etherscan) and [ERC](/cli/plugins/erc) plugins, and/or generate code using the `run` option, e.g. the [React](/cli/plugins/react) plugin. All you need to do is write a function that returns the `Plugin` type (`name` is the only required property, but you likely want to at least include `contracts` or `run`).


```ts filename="wagmi.config.ts"
import type { Plugin } from '@wagmi/cli'

Expand Down
105 changes: 105 additions & 0 deletions docs/pages/cli/plugins/sourcify.en-US.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
title: 'Sourcify'
description: 'Sourcify plugin'
---

# Sourcify

Plugin for fetching ABIs from [Sourcify](https://sourcify.dev/). Sourcify is a decentralized, open-source, smart contract verification and metadata repository.

```ts
import { sourcify } from '@wagmi/cli/plugins'
```

## Usage

```ts
import { defineConfig } from '@wagmi/cli'
import { sourcify } from '@wagmi/cli/plugins'

export default defineConfig({
plugins: [
sourcify({
contracts: [
{
name: 'deposit',
address: '0x00000000219ab540356cbb839cbe05303d7705fa',
},
],
}),
],
})
```

## Configuration

### contracts

Contracts to fetch ABIs for.

```ts {7-12}
import { defineConfig } from '@wagmi/cli'
import { sourcify } from '@wagmi/cli/plugins'

export default defineConfig({
plugins: [
sourcify({
contracts: [
{
name: 'deposit',
address: '0x00000000219ab540356cbb839cbe05303d7705fa',
},
],
}),
],
})
```

### chainId

Chain id to use for fetching ABI. If `address` is an object, `chainId` is used to select the address.

```ts {7,16}
import { defineConfig } from '@wagmi/cli'
import { sourcify } from '@wagmi/cli/plugins'

export default defineConfig({
plugins: [
sourcify({
chainId: 100,
contracts: [
{
name: 'Community',
address: {
100: '0xC4c622862a8F548997699bE24EA4bc504e5cA865',
137: '0xC4c622862a8F548997699bE24EA4bc504e5cA865',
},
},
],
}),
],
})
```

### cacheDuration (optional)

Duration in milliseconds to cache ABIs. Defaults to `1_800_000` (30 minutes).

```ts {7}
import { defineConfig } from '@wagmi/cli'
import { sourcify } from '@wagmi/cli/plugins'

export default defineConfig({
plugins: [
sourcify({
cacheDuration: 300_000,
contracts: [
{
name: 'deposit',
address: '0x00000000219ab540356cbb839cbe05303d7705fa',
},
],
}),
],
})
```
258 changes: 258 additions & 0 deletions packages/cli/src/plugins/__snapshots__/sourcify.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
// Vitest Snapshot v1

exports[`sourcify > contracts > fetches ABI 1`] = `
[
{
"abi": [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor",
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "bytes",
"name": "pubkey",
"type": "bytes",
},
{
"indexed": false,
"internalType": "bytes",
"name": "withdrawal_credentials",
"type": "bytes",
},
{
"indexed": false,
"internalType": "bytes",
"name": "amount",
"type": "bytes",
},
{
"indexed": false,
"internalType": "bytes",
"name": "signature",
"type": "bytes",
},
{
"indexed": false,
"internalType": "bytes",
"name": "index",
"type": "bytes",
},
],
"name": "DepositEvent",
"type": "event",
},
{
"inputs": [
{
"internalType": "bytes",
"name": "pubkey",
"type": "bytes",
},
{
"internalType": "bytes",
"name": "withdrawal_credentials",
"type": "bytes",
},
{
"internalType": "bytes",
"name": "signature",
"type": "bytes",
},
{
"internalType": "bytes32",
"name": "deposit_data_root",
"type": "bytes32",
},
],
"name": "deposit",
"outputs": [],
"stateMutability": "payable",
"type": "function",
},
{
"inputs": [],
"name": "get_deposit_count",
"outputs": [
{
"internalType": "bytes",
"name": "",
"type": "bytes",
},
],
"stateMutability": "view",
"type": "function",
},
{
"inputs": [],
"name": "get_deposit_root",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32",
},
],
"stateMutability": "view",
"type": "function",
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceId",
"type": "bytes4",
},
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool",
},
],
"stateMutability": "pure",
"type": "function",
},
],
"address": {
"1": "0x00000000219ab540356cbb839cbe05303d7705fa",
},
"name": "DepositContract",
},
]
`;

exports[`sourcify > contracts > fetches ABI with multichain deployment 1`] = `
[
{
"abi": [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor",
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "bytes",
"name": "pubkey",
"type": "bytes",
},
{
"indexed": false,
"internalType": "bytes",
"name": "withdrawal_credentials",
"type": "bytes",
},
{
"indexed": false,
"internalType": "bytes",
"name": "amount",
"type": "bytes",
},
{
"indexed": false,
"internalType": "bytes",
"name": "signature",
"type": "bytes",
},
{
"indexed": false,
"internalType": "bytes",
"name": "index",
"type": "bytes",
},
],
"name": "DepositEvent",
"type": "event",
},
{
"inputs": [
{
"internalType": "bytes",
"name": "pubkey",
"type": "bytes",
},
{
"internalType": "bytes",
"name": "withdrawal_credentials",
"type": "bytes",
},
{
"internalType": "bytes",
"name": "signature",
"type": "bytes",
},
{
"internalType": "bytes32",
"name": "deposit_data_root",
"type": "bytes32",
},
],
"name": "deposit",
"outputs": [],
"stateMutability": "payable",
"type": "function",
},
{
"inputs": [],
"name": "get_deposit_count",
"outputs": [
{
"internalType": "bytes",
"name": "",
"type": "bytes",
},
],
"stateMutability": "view",
"type": "function",
},
{
"inputs": [],
"name": "get_deposit_root",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32",
},
],
"stateMutability": "view",
"type": "function",
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceId",
"type": "bytes4",
},
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool",
},
],
"stateMutability": "pure",
"type": "function",
},
],
"address": {
"100": "0xC4c622862a8F548997699bE24EA4bc504e5cA865",
"137": "0xC4c622862a8F548997699bE24EA4bc504e5cA865",
},
"name": "Community",
},
]
`;
1 change: 1 addition & 0 deletions packages/cli/src/plugins/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ it('should expose correct exports', () => {
"foundry",
"hardhat",
"react",
"sourcify",
]
`)
})
Loading

1 comment on commit cb707f0

@vercel
Copy link

@vercel vercel bot commented on cb707f0 Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.