-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add chain-specific finalization thresholds
- Add chainConfig with default and chain-specific finalization thresholds - Add getFinalizationThreshold utility function - Add tests for configuration and threshold retrieval
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getFinalizationThreshold, chainConfig } from '../chain-config'; | ||
|
||
describe('Chain Configuration', () => { | ||
it('should return correct finalization threshold for known chains', () => { | ||
expect(getFinalizationThreshold('1')).toBe(25); // Ethereum Mainnet | ||
expect(getFinalizationThreshold('10')).toBe(2); // Optimism | ||
expect(getFinalizationThreshold('8453')).toBe(4); // Base | ||
}); | ||
|
||
it('should return default finalization threshold for unknown chains', () => { | ||
expect(getFinalizationThreshold('123')).toBe( | ||
chainConfig.defaultFinalizationThreshold | ||
); | ||
expect(getFinalizationThreshold('999')).toBe( | ||
chainConfig.defaultFinalizationThreshold | ||
); | ||
}); | ||
|
||
it('should have valid configuration values', () => { | ||
// All thresholds should be positive numbers | ||
expect(chainConfig.defaultFinalizationThreshold).toBeGreaterThan(0); | ||
|
||
Object.entries(chainConfig.finalizationThresholds).forEach( | ||
([_chainId, threshold]) => { | ||
expect(Number.isInteger(threshold)).toBe(true); | ||
expect(threshold).toBeGreaterThan(0); | ||
} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Configuration for chain-specific settings | ||
*/ | ||
|
||
export interface ChainConfig { | ||
defaultFinalizationThreshold: number; | ||
finalizationThresholds: Record<string, number>; | ||
} | ||
|
||
export const chainConfig: ChainConfig = { | ||
// Default finalization threshold in seconds | ||
defaultFinalizationThreshold: 3, | ||
|
||
// Chain-specific finalization thresholds in seconds | ||
finalizationThresholds: { | ||
// Ethereum Mainnet | ||
'1': 25, | ||
// Optimism | ||
'10': 2, | ||
// Base | ||
'8453': 4, | ||
}, | ||
}; | ||
|
||
/** | ||
* Get the finalization threshold for a specific chain ID | ||
* @param chainId - The chain ID to get the threshold for | ||
* @returns The finalization threshold in seconds | ||
*/ | ||
export function getFinalizationThreshold(chainId: string): number { | ||
return ( | ||
chainConfig.finalizationThresholds[chainId] ?? | ||
chainConfig.defaultFinalizationThreshold | ||
); | ||
} |