Skip to content

Commit 01d9430

Browse files
committed
fix: package entry points and other small improvements
1 parent 1aeb0a2 commit 01d9430

File tree

8 files changed

+61
-85
lines changed

8 files changed

+61
-85
lines changed

contracts/deployments/contractsEthers.ts

+1-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ethers } from "ethers";
2-
import { arbitrum, arbitrumSepolia } from "viem/chains";
32
import {
43
klerosCoreConfig as devnetCoreConfig,
54
sortitionModuleConfig as devnetSortitionConfig,
@@ -83,34 +82,7 @@ import {
8382
SortitionModuleNeo,
8483
SortitionModuleNeo__factory,
8584
} from "../typechain-types";
86-
87-
const deployments = {
88-
devnet: {
89-
chainId: arbitrumSepolia.id,
90-
},
91-
university: {
92-
chainId: arbitrumSepolia.id,
93-
},
94-
testnet: {
95-
chainId: arbitrumSepolia.id,
96-
},
97-
mainnetNeo: {
98-
chainId: arbitrum.id,
99-
},
100-
} as const;
101-
102-
type DeploymentName = keyof typeof deployments;
103-
104-
type ContractConfig = {
105-
address: Record<number, `0x${string}`>;
106-
abi: readonly any[];
107-
};
108-
109-
function getAddress(config: ContractConfig, chainId: number): `0x${string}` {
110-
const address = config.address[chainId];
111-
if (!address) throw new Error(`No address found for chainId ${chainId}`);
112-
return address;
113-
}
85+
import { type ContractConfig, type DeploymentName, deployments, getAddress } from "./utils";
11486

11587
type CommonFactoriesConfigs = {
11688
dkcConfig: ContractConfig;

contracts/deployments/contractsViem.ts

+9-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { arbitrum, arbitrumSepolia } from "viem/chains";
1+
import { type PublicClient, type WalletClient, getContract } from "viem";
2+
import { type ContractConfig, type DeploymentName, deployments, getAddress } from "./utils";
23
import {
34
klerosCoreConfig as devnetCoreConfig,
45
sortitionModuleConfig as devnetSortitionConfig,
@@ -46,35 +47,19 @@ import {
4647
pnkConfig as mainnetPnkConfig,
4748
klerosCoreSnapshotProxyConfig as mainnetSnapshotProxyConfig,
4849
} from "./mainnet.viem";
49-
import { type PublicClient, type WalletClient, getContract } from "viem";
50-
51-
const deployments = {
52-
devnet: {
53-
chainId: arbitrumSepolia.id,
54-
},
55-
university: {
56-
chainId: arbitrumSepolia.id,
57-
},
58-
testnet: {
59-
chainId: arbitrumSepolia.id,
60-
},
61-
mainnetNeo: {
62-
chainId: arbitrum.id,
63-
},
64-
} as const;
65-
66-
type DeploymentName = keyof typeof deployments;
67-
68-
type ContractConfig = {
69-
address: Record<number, `0x${string}`>;
70-
abi: readonly any[];
71-
};
7250

7351
type ContractInstance = {
7452
address: `0x${string}`;
7553
abi: readonly any[];
7654
};
7755

56+
function getContractConfig({ config, chainId }: { config: ContractConfig; chainId: number }): ContractInstance {
57+
return {
58+
address: getAddress(config, chainId),
59+
abi: config.abi,
60+
};
61+
}
62+
7863
type ContractInstances = {
7964
klerosCore: ContractInstance;
8065
sortition: ContractInstance;
@@ -91,19 +76,6 @@ type ContractInstances = {
9176
klerosCoreSnapshotProxy: ContractInstance;
9277
};
9378

94-
function getAddress(config: ContractConfig, chainId: number): `0x${string}` {
95-
const address = config.address[chainId];
96-
if (!address) throw new Error(`No address found for chainId ${chainId}`);
97-
return address;
98-
}
99-
100-
function getContractConfig({ config, chainId }: { config: ContractConfig; chainId: number }): ContractInstance {
101-
return {
102-
address: getAddress(config, chainId),
103-
abi: config.abi,
104-
};
105-
}
106-
10779
function getCommonConfigs({
10880
chainId,
10981
configs,

contracts/deployments/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export * as testnetViem from "./testnet.viem";
1111
// Typechain-types
1212
export * from "../typechain-types";
1313

14+
// Common utils
15+
export * from "./utils";
16+
1417
// Contracts getters
1518
export { getContracts as getContractsEthers } from "./contractsEthers";
1619
export { getContracts as getContractsViem } from "./contractsViem";

contracts/deployments/utils.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { arbitrum, arbitrumSepolia } from "viem/chains";
2+
3+
export const deployments = {
4+
devnet: {
5+
chainId: arbitrumSepolia.id,
6+
},
7+
university: {
8+
chainId: arbitrumSepolia.id,
9+
},
10+
testnet: {
11+
chainId: arbitrumSepolia.id,
12+
},
13+
mainnetNeo: {
14+
chainId: arbitrum.id,
15+
},
16+
} as const;
17+
18+
export type DeploymentName = keyof typeof deployments;
19+
20+
export type ContractConfig = {
21+
address: Record<number, `0x${string}`>;
22+
abi: readonly any[];
23+
};
24+
25+
export function getAddress(config: ContractConfig, chainId: number): `0x${string}` {
26+
const address = config.address[chainId];
27+
if (!address) throw new Error(`No address found for chainId ${chainId}`);
28+
return address;
29+
}

contracts/package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "@kleros/kleros-v2-contracts",
3-
"version": "0.8.1",
3+
"version": "0.9.2",
44
"description": "Smart contracts for Kleros version 2",
5-
"main": "./dist/cjs/index.js",
6-
"module": "./dist/esm/index.js",
7-
"types": "./dist/types/index.d.ts",
5+
"main": "./cjs/deployments/index.js",
6+
"module": "./esm/deployments/index.js",
7+
"types": "./types/deployments/index.d.ts",
88
"exports": {
99
".": {
10-
"types": "./dist/types/index.d.ts",
11-
"import": "./dist/esm/index.js",
12-
"require": "./dist/cjs/index.js",
13-
"default": "./dist/esm/index.js"
10+
"types": "./types/deployments/index.d.ts",
11+
"import": "./esm/deployments/index.js",
12+
"require": "./cjs/deployments/index.js",
13+
"default": "./esm/deployments/index.js"
1414
}
1515
},
1616
"files": [

contracts/scripts/publish.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
shopt -s extglob
44

5-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
66

77
#--------------------------------------
88
# Error handling
@@ -11,7 +11,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
1111
set -Ee
1212
function _catch {
1313
# Don't propagate to outer shell
14-
exit 0
14+
exit 0
1515
}
1616
function _finally {
1717
# TODO: rollback version bump
@@ -27,6 +27,9 @@ if [[ "$PWD" != */contracts ]]; then
2727
exit 1
2828
fi
2929

30+
# Bump the version
31+
yarn version $1
32+
3033
# Recompile the contracts
3134
yarn clean
3235
yarn build
@@ -53,7 +56,7 @@ mkdir dist
5356
yarn build:all
5457

5558
# Copy the README and contracts
56-
cp -pr README.md src/ dist/
59+
cp -pr README.md src/ dist/
5760

5861
# Remove unwanted files
5962
rm -rf dist/config
@@ -67,12 +70,9 @@ rm -rf dist/deployments/**/solcInputs
6770
rm -rf dist/deployments/localhost
6871
rm -rf dist/deployments/hardhat
6972
rm -rf dist/deployments/hardhat.viem.ts
70-
jq 'del(.scripts.prepare)' package.json > dist/package.json
71-
72-
# Bump the version
73-
yarn version $1
73+
jq 'del(.scripts.prepare)' package.json >dist/package.json
7474

7575
# Publish the package
7676
cd dist
77-
npm publish --dry-run
77+
npm publish
7878
cd -

contracts/test/integration/getContractsEthers.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const neoContractMapping: ContractMapping = {
8787
klerosCoreSnapshotProxy: { name: "KlerosCoreSnapshotProxy" },
8888
};
8989

90-
describe("getContracts", () => {
90+
describe("getContractsEthers", () => {
9191
// Use real providers for each network
9292
const arbitrumSepoliaProvider = new ethers.JsonRpcProvider("https://sepolia-rollup.arbitrum.io/rpc");
9393
const arbitrumProvider = new ethers.JsonRpcProvider("https://arb1.arbitrum.io/rpc");

contracts/test/integration/getContractsViem.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from "chai";
2-
import { createPublicClient, createWalletClient, http, Address } from "viem";
2+
import { createPublicClient, http } from "viem";
33
import { arbitrum, arbitrumSepolia } from "viem/chains";
44
import { getContracts } from "../../deployments/contractsViem";
55
import { getActualAddress } from "../utils/getActualAddress";
@@ -68,7 +68,7 @@ const neoContractMapping: ContractMapping = {
6868
klerosCoreSnapshotProxy: { name: "KlerosCoreSnapshotProxy" },
6969
};
7070

71-
describe("getContracts", () => {
71+
describe("getContractsViem", () => {
7272
// Create Viem clients for testing
7373
const arbitrumSepoliaClient = createPublicClient({
7474
chain: arbitrumSepolia,

0 commit comments

Comments
 (0)