Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/export-solo-precompile-ethers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sei-js/precompiles': minor
---

Export the Solo precompile from the `ethers` entrypoint. `ETHERS_SOLO_PRECOMPILE_ABI` and `getSoloPrecompileEthersV6Contract` were implemented but never re-exported from `src/ethers/index.ts`, so they were unreachable from the `@sei-js/precompiles` package root.

The `@sei-js/precompiles/ethers` subpath shown in the doc examples remains unresolvable and is unchanged here — the package still publishes no `exports` map. That is tracked separately.
41 changes: 41 additions & 0 deletions packages/precompiles/src/__tests__/barrelParity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as ethersBarrel from '../ethers';
import * as precompilesBarrel from '../precompiles';
import * as viemBarrel from '../viem';

const precompileNamesFrom = (barrel: Record<string, unknown>, prefix: '' | 'ETHERS_' | 'VIEM_'): string[] => {
const pattern = new RegExp(`^${prefix}([A-Z0-9]+)_PRECOMPILE_ABI$`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[suggestion] [A-Z0-9]+ excludes _, so a precompile whose name spans multiple words is silently invisible to this guard. A future CONFIDENTIAL_TRANSFERS_PRECOMPILE_ABI fails ^([A-Z0-9]+)_PRECOMPILE_ABI$ (the class can't span the interior underscore, and ^ blocks a partial match on the trailing segment), and ETHERS_CONFIDENTIAL_TRANSFERS_PRECOMPILE_ABI fails the prefixed form identically — so the name drops out of all three lists symmetrically and the comparisons still pass. That's exactly the bug this PR is fixing: solo missing from just the ethers barrel would go undetected for such a precompile. The toBeGreaterThan(0) guard above doesn't help either, since the other 12 names keep the base list non-empty.

[A-Z0-9_]+ fixes it. Note the prefixed patterns then need the anchor to stay meaningful — ^ETHERS_([A-Z0-9_]+)_PRECOMPILE_ABI$ is fine, but the unprefixed ^([A-Z0-9_]+)_PRECOMPILE_ABI$ applied to a barrel that also held ETHERS_* keys would capture ETHERS_FOO. It's safe here because src/precompiles re-exports nothing prefixed, though a short comment recording that assumption would help the next editor.


return Object.keys(barrel)
.map((key) => pattern.exec(key)?.[1])
.filter((name): name is string => name !== undefined)
.sort();
};

describe('Precompile barrel parity', () => {
const precompileNames = precompileNamesFrom(precompilesBarrel, '');
const ethersNames = precompileNamesFrom(ethersBarrel, 'ETHERS_');
const viemNames = precompileNamesFrom(viemBarrel, 'VIEM_');

// Without this the three comparisons below would pass on three empty sets if the
// ABI naming convention ever changes out from under the pattern above.
it('discovers precompiles in the base barrel', () => {
expect(precompileNames.length).toBeGreaterThan(0);
});

it('exposes the same precompiles from the ethers barrel as the base barrel', () => {
expect(ethersNames).toEqual(precompileNames);
});

it('exposes the same precompiles from the viem barrel as the base barrel', () => {
expect(viemNames).toEqual(precompileNames);
});

it('exposes an ethers contract factory for each precompile', () => {
const factories = Object.keys(ethersBarrel)
.map((key) => /^get([A-Za-z0-9]+)PrecompileEthersV6Contract$/.exec(key)?.[1]?.toUpperCase())
.filter((name): name is string => name !== undefined)
.sort();

expect(factories).toEqual(precompileNames);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ETHERS_ORACLE_PRECOMPILE_ABI,
ETHERS_POINTERVIEW_PRECOMPILE_ABI,
ETHERS_POINTER_PRECOMPILE_ABI,
ETHERS_SOLO_PRECOMPILE_ABI,
ETHERS_STAKING_PRECOMPILE_ABI,
ETHERS_WASM_PRECOMPILE_ABI,
getAddressPrecompileEthersV6Contract,
Expand All @@ -21,6 +22,7 @@ import {
getOraclePrecompileEthersV6Contract,
getPointerPrecompileEthersV6Contract,
getPointerviewPrecompileEthersV6Contract,
getSoloPrecompileEthersV6Contract,
getStakingPrecompileEthersV6Contract,
getWasmPrecompileEthersV6Contract
} from '../';
Expand Down Expand Up @@ -51,7 +53,6 @@ import {
WASM_PRECOMPILE_ABI,
WASM_PRECOMPILE_ADDRESS
} from '../../precompiles';
import { ETHERS_SOLO_PRECOMPILE_ABI, getSoloPrecompileEthersV6Contract } from '../soloPrecompile';

const FACTORIES: [string, string, InterfaceAbi, unknown, (runner: ContractRunner) => Contract][] = [
['ADDRESS', ADDRESS_PRECOMPILE_ADDRESS, ADDRESS_PRECOMPILE_ABI, ETHERS_ADDRESS_PRECOMPILE_ABI, getAddressPrecompileEthersV6Contract],
Expand Down
1 change: 1 addition & 0 deletions packages/precompiles/src/ethers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export * from './jsonPrecompile';
export * from './oraclePrecompile';
export * from './pointerPrecompile';
export * from './pointerviewPrecompile';
export * from './soloPrecompile';
export * from './stakingPrecompile';
export * from './wasmPrecompile';
2 changes: 1 addition & 1 deletion packages/precompiles/src/ethers/soloPrecompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ETHERS_SOLO_PRECOMPILE_ABI = SOLO_PRECOMPILE_ABI as InterfaceAbi;
* ```
*
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the Oracle precompile contract.
* @returns The typed contract instance for interacting with the Solo precompile contract.
* @category Contract Factory
*/
export const getSoloPrecompileEthersV6Contract = (runner: ContractRunner) => {
Expand Down
Loading