Skip to content

Commit afbb544

Browse files
committed
feat: move interface ID generation to interfaces package
- Move InterfaceIdExtractor contract to interfaces package - Move interface ID generation script to interfaces package - Integrate interface ID generation into interfaces package build process - Update contracts package to use interface IDs from interfaces package - Remove local interface ID generation from contracts package - Place generated interface IDs in src/types/interfaceIds.ts following package conventions This centralizes interface ID generation in the interfaces package where it belongs, making it available for all packages to use and eliminating duplication.
1 parent 1eef7b1 commit afbb544

File tree

8 files changed

+25
-43
lines changed

8 files changed

+25
-43
lines changed

packages/contracts/contracts/tests/MockIssuanceAllocator.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ contract MockIssuanceAllocator is ERC165, IIssuanceAllocator {
139139
* @inheritdoc IIssuanceAllocator
140140
* @dev Mock implementation that forces notification and returns current block
141141
*/
142-
function forceTargetNoChangeNotificationBlock(address target, uint256 blockNumber) external override returns (uint256) {
142+
function forceTargetNoChangeNotificationBlock(
143+
address target,
144+
uint256 blockNumber
145+
) external override returns (uint256) {
143146
require(!_shouldRevert, "MockIssuanceAllocator: reverted");
144147
if (_allocatedTargets[target]) {
145148
IIssuanceTarget(target).beforeIssuanceAllocationChange();

packages/contracts/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
"prepack": "pnpm build",
3131
"clean": "rm -rf artifacts/ cache/ types/ abis/ build/ dist/ coverage/",
3232
"build": "pnpm build:self",
33-
"build:self": "pnpm compile && pnpm generate:interface-ids",
33+
"build:self": "pnpm compile",
3434
"compile": "hardhat compile",
35-
"generate:interface-ids": "cd test && python3 scripts/generateInterfaceIds.py",
3635
"test": "pnpm --filter @graphprotocol/contracts-tests test",
3736
"test:coverage": "pnpm --filter @graphprotocol/contracts-tests run test:coverage",
3837
"deploy": "pnpm predeploy && pnpm build",

packages/contracts/test/helpers/interfaceIds.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/contracts/test/tests/unit/rewards/rewards.test.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,12 @@ describe('Rewards', () => {
186186
})
187187

188188
it('should support IRewardsManager interface', async function () {
189-
// Use the auto-generated interface ID from Solidity compilation
190-
const { IRewardsManager } = require('../../../helpers/interfaceIds')
189+
// Use the auto-generated interface ID from the interfaces package
190+
const { IRewardsManager } = require('@graphprotocol/interfaces')
191191
const supports = await rewardsManager.supportsInterface(IRewardsManager)
192192
expect(supports).to.be.true
193193
})
194194

195-
it('should have consistent interface IDs with Solidity calculations', async function () {
196-
const InterfaceIdExtractorFactory = await hre.ethers.getContractFactory('InterfaceIdExtractor')
197-
const extractor = await InterfaceIdExtractorFactory.deploy()
198-
await extractor.deployed()
199-
200-
const { IRewardsManager, IIssuanceTarget, IERC165 } = require('../../../helpers/interfaceIds')
201-
202-
// Verify each interface ID matches what Solidity calculates
203-
expect(await extractor.getIRewardsManagerId()).to.equal(IRewardsManager)
204-
expect(await extractor.getIIssuanceTargetId()).to.equal(IIssuanceTarget)
205-
expect(await extractor.getIERC165Id()).to.equal(IERC165)
206-
})
207-
208195
it('should support IERC165 interface', async function () {
209196
// Test the specific IERC165 interface - this should hit the third branch
210197
// interfaceId == type(IERC165).interfaceId

packages/contracts/contracts/tests/InterfaceIdExtractor.sol renamed to packages/interfaces/contracts/utils/InterfaceIdExtractor.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
pragma solidity 0.7.6;
33

4-
import { IRewardsManager } from "@graphprotocol/interfaces/contracts/contracts/rewards/IRewardsManager.sol";
5-
import { IIssuanceTarget } from "@graphprotocol/interfaces/contracts/issuance/allocate/IIssuanceTarget.sol";
4+
import { IRewardsManager } from "../contracts/rewards/IRewardsManager.sol";
5+
import { IIssuanceTarget } from "../issuance/allocate/IIssuanceTarget.sol";
66
import { IERC165 } from "@openzeppelin/contracts/introspection/IERC165.sol";
77

88
/**

packages/interfaces/scripts/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ find_files() {
4141
echo "📦 Compiling contracts with Hardhat..."
4242
pnpm hardhat compile
4343

44+
# Step 1.5: Generate interface IDs
45+
echo "🔧 Generating interface IDs..."
46+
python3 scripts/generateInterfaceIds.py
47+
4448
# Step 2: Generate types (only if needed)
4549
echo "🏗️ Checking type definitions..."
4650

packages/contracts/test/scripts/generateInterfaceIds.py renamed to packages/interfaces/scripts/generateInterfaceIds.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ def run_hardhat_task():
2626
async function main() {
2727
const InterfaceIdExtractor = await hre.ethers.getContractFactory('InterfaceIdExtractor')
2828
const extractor = await InterfaceIdExtractor.deploy()
29-
await extractor.deployed()
30-
29+
await extractor.waitForDeployment()
30+
3131
const results = {
3232
IRewardsManager: await extractor.getIRewardsManagerId(),
3333
IIssuanceTarget: await extractor.getIIssuanceTargetId(),
3434
IERC165: await extractor.getIERC165Id(),
3535
}
36-
36+
3737
console.log(JSON.stringify(results))
3838
}
3939
@@ -44,7 +44,7 @@ def run_hardhat_task():
4444
"""
4545

4646
script_dir = Path(__file__).parent
47-
project_dir = script_dir.parent.parent
47+
project_dir = script_dir.parent
4848

4949
# Write temporary script
5050
with tempfile.NamedTemporaryFile(mode='w', suffix='.js', delete=False) as temp_file:
@@ -62,7 +62,8 @@ def run_hardhat_task():
6262
)
6363

6464
if result.returncode != 0:
65-
raise RuntimeError(f"Hardhat script failed with code {result.returncode}: {result.stderr}")
65+
raise RuntimeError(
66+
f"Hardhat script failed with code {result.returncode}: {result.stderr}")
6667

6768
# Extract JSON from output
6869
for line in result.stdout.split('\n'):
@@ -90,7 +91,8 @@ def run_hardhat_task():
9091
def extract_interface_ids():
9192
"""Extract interface IDs using the InterfaceIdExtractor contract"""
9293
script_dir = Path(__file__).parent
93-
extractor_path = script_dir.parent.parent / "artifacts" / "contracts" / "tests" / "InterfaceIdExtractor.sol" / "InterfaceIdExtractor.json"
94+
extractor_path = script_dir.parent / "artifacts" / "contracts" / \
95+
"utils" / "InterfaceIdExtractor.sol" / "InterfaceIdExtractor.json"
9496

9597
if not extractor_path.exists():
9698
print("❌ InterfaceIdExtractor artifact not found")
@@ -137,14 +139,11 @@ def main():
137139

138140
# Write to output file
139141
script_dir = Path(__file__).parent
140-
output_file = script_dir.parent / "helpers" / "interfaceIds.ts"
141-
142-
# Create helpers directory if it doesn't exist
143-
output_file.parent.mkdir(exist_ok=True)
144-
142+
output_file = script_dir.parent / "src" / "types" / "interfaceIds.ts"
143+
145144
with open(output_file, 'w') as f:
146145
f.write(content)
147-
146+
148147
log(f"✅ Generated {output_file}")
149148

150149

packages/interfaces/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ContractRunner, Interface } from 'ethers'
33
import { factories } from '../types'
44

55
export * from './types/horizon'
6+
export * from './types/interfaceIds'
67
export * from './types/subgraph-service'
78

89
/**

0 commit comments

Comments
 (0)