Skip to content

Commit d8bba3b

Browse files
committed
feat: 🎸 Wagmi-generated APIs exports
1 parent b8f7aad commit d8bba3b

File tree

9 files changed

+2784
-440
lines changed

9 files changed

+2784
-440
lines changed

package/.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ cache-zk
1212
artifacts
1313
cache
1414
network
15-
typechain
15+
wagmi

package/package.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
],
2121
"license": "MIT",
2222
"private": false,
23+
"type": "module",
2324
"types": "./lib/src/index.d.ts",
2425
"main": "./lib/src/index.js",
2526
"files": [
2627
"src",
2728
"lib",
28-
"artifacts",
29-
"typechain",
3029
"!**/*.tsbuildinfo",
3130
"!**/**.dbg.json"
3231
],
@@ -43,10 +42,6 @@
4342
".": {
4443
"types": "./lib/src/index.d.ts",
4544
"import": "./lib/src/index.js"
46-
},
47-
"./types": {
48-
"types": "./lib/typechain/index.d.ts",
49-
"import": "./lib/typechain/index.js"
5045
}
5146
},
5247
"release": {
@@ -86,12 +81,10 @@
8681
"prettier-plugin-jsdoc": "^0.4.2",
8782
"ts-node": "^10.9.1",
8883
"typescript": "^5.0.4",
89-
"ethers": "^6.4.0",
90-
"typechain": "^8.1.1",
91-
"@typechain/ethers-v6": "^0.3.2"
84+
"@wagmi/cli": "^1.0.1"
9285
},
9386
"scripts": {
94-
"build": "rm -rf ./lib && typechain --target=ethers-v6 --out-dir typechain ./artifacts/contracts/Config.sol/Config.json ./artifacts/contracts/EntitiesRegistry.sol/EntitiesRegistry.json ./artifacts/contracts/Market.sol/Market.json ./artifacts/contracts/test/MockERC20Dec18Permit.sol/MockERC20Dec18Permit.json ./artifacts/contracts/test/MockERC20Dec18.sol/MockERC20Dec18.json ./artifacts/contracts/test/MockERC20Dec6Permit.sol/MockERC20Dec6Permit.json ./artifacts/contracts/test/MockERC20Dec6.sol/MockERC20Dec6.json && tsc -p ./tsconfig.build.json",
87+
"build": "rm -rf lib && yarn wagmi generate && tsc -p ./tsconfig.build.json",
9588
"lint": "eslint --ext .ts",
9689
"lint:fix": "eslint --ext .ts --fix && prettier --check !network --write ."
9790
}

package/src/constants.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { encodeBytes32String } from 'ethers';
2-
31
// Protocol entities types (kinds) as object
42
export const kinds = {
5-
// ethers.encodeBytes32String('supplier')
3+
// 'supplier'
64
supplier: '0x737570706c696572000000000000000000000000000000000000000000000000',
7-
// ethers.encodeBytes32String('retailer')
5+
// 'retailer'
86
retailer: '0x72657461696c6572000000000000000000000000000000000000000000000000',
97
};
108

package/src/index.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,6 @@ import ERC20PermitJson from '../artifacts/contracts/test/MockERC20Dec18Permit.so
55
import ERC20Json from '../artifacts/contracts/test/MockERC20Dec18.sol/MockERC20Dec18.json';
66
import ERC20Permit6Json from '../artifacts/contracts/test/MockERC20Dec6Permit.sol/MockERC20Dec6Permit.json';
77
import ERC206Json from '../artifacts/contracts/test/MockERC20Dec6.sol/MockERC20Dec6.json';
8-
9-
export * from '../typechain';
10-
export {
11-
MockERC20Dec18Permit as ERC20Permit,
12-
MockERC20Dec18Permit__factory as ERC20Permit__factory,
13-
MockERC20Dec18 as ERC20,
14-
MockERC20Dec18__factory as ERC20__factory,
15-
MockERC20Dec6Permit as ERC20Permit6,
16-
MockERC20Dec6Permit__factory as ERC20Permit6__factory,
17-
MockERC20Dec6 as ERC20_6,
18-
MockERC20Dec6__factory as ERC20_6__factory,
19-
} from '../typechain';
20-
export * from './constants';
218
export {
229
ConfigJson,
2310
EntitiesRegistryJson,
@@ -27,3 +14,5 @@ export {
2714
ERC20Permit6Json,
2815
ERC206Json,
2916
};
17+
export * from './constants.js';
18+
export * from '../wagmi/index.js';

package/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "./lib"
4+
"outDir": "lib"
55
}
66
}

package/tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"compilerOptions": {
33
"strict": true,
44
"esModuleInterop": true,
5-
"lib": ["ESNext", "DOM", "DOM.Iterable"],
6-
"target": "ESNext",
5+
"lib": ["ES2022", "DOM"],
6+
"target": "ES2022",
77
"module": "ESNext",
88
"moduleResolution": "NodeNext",
99
"skipLibCheck": true,
@@ -19,5 +19,5 @@
1919
"importsNotUsedAsValues": "remove",
2020
"noImplicitReturns": true
2121
},
22-
"include": ["src/**/*.ts", "typechain/**/*.ts"]
22+
"include": ["./src/index.ts"]
2323
}

package/wagmi.config.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Config as WagmiConfig, ContractConfig } from '@wagmi/cli';
2+
import { Abi } from 'abitype';
3+
// import { react } from '@wagmi/cli/plugins';
4+
// import { actions } from '@wagmi/cli/plugins'
5+
6+
import Config from './artifacts/contracts/Config.sol/Config.json';
7+
import EntitiesRegistry from './artifacts/contracts/EntitiesRegistry.sol/EntitiesRegistry.json';
8+
import Market from './artifacts/contracts/Market.sol/Market.json';
9+
import ERC20_18_Permit from './artifacts/contracts/test/MockERC20Dec18Permit.sol/MockERC20Dec18Permit.json';
10+
import ERC20_18 from './artifacts/contracts/test/MockERC20Dec18.sol/MockERC20Dec18.json';
11+
import ERC20_6_Permit from './artifacts/contracts/test/MockERC20Dec6Permit.sol/MockERC20Dec6Permit.json';
12+
import ERC20_6 from './artifacts/contracts/test/MockERC20Dec6.sol/MockERC20Dec6.json';
13+
14+
type Artifacts = Record<string, any>;
15+
16+
const artifacts: Artifacts = {
17+
Config,
18+
EntitiesRegistry,
19+
Market,
20+
ERC20_18_Permit,
21+
ERC20_18,
22+
ERC20_6_Permit,
23+
ERC20_6,
24+
};
25+
26+
const createContractConfig = (artifacts: Artifacts): ContractConfig[] =>
27+
Object.entries(artifacts).map((a) => ({
28+
name: a[0],
29+
abi: a[1].abi as Abi,
30+
}));
31+
32+
const config: WagmiConfig = {
33+
out: './wagmi/index.ts',
34+
contracts: createContractConfig(artifacts),
35+
plugins: [
36+
// actions({
37+
// getContract: true,
38+
// readContract: true,
39+
// prepareWriteContract: true,
40+
// writeContract: true,
41+
// watchContractEvent: true,
42+
// }),
43+
// react({
44+
// useContractRead: true,
45+
// useContractFunctionRead: true,
46+
// usePrepareContractFunctionWrite: true,
47+
// }),
48+
],
49+
};
50+
51+
export default config;

0 commit comments

Comments
 (0)