feat: enhance Djed-SDK by shipping pre-configured network variables#97
feat: enhance Djed-SDK by shipping pre-configured network variables#97Rav1Chauhan wants to merge 2 commits intoDjedAlliance:mainfrom
Conversation
📝 WalkthroughWalkthroughAdds exported pre-configured network variables and a helper to retrieve them: a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@djed-sdk/src/constants.js`:
- Around line 24-39: The NETWORKS constant contains invalid placeholder Ethereum
addresses and incomplete Infura RPC URLs which will break runtime contract
instantiation; update NETWORKS (the sepolia and mainnet entries: djedAddress,
oracleAddress, rpcUrl) by either (A) replacing the placeholder hex strings with
the actual deployed contract addresses and full RPC URLs (including the Infura
project id) or (B) explicitly mark them as configurable (e.g., set djedAddress
and oracleAddress to null) and add JSDoc/comments and runtime validation that
throws a clear error if NETWORKS.*.djedAddress or oracleAddress or rpcUrl are
missing so consumers must provide real values before calling any
contract-related code.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4e111cf1-7ac9-4bf9-a826-e37cc0de4b2c
📒 Files selected for processing (2)
djed-sdk/src/constants.jsdjed-sdk/src/index.js
There was a problem hiding this comment.
♻️ Duplicate comments (1)
djed-sdk/src/constants.js (1)
24-50:⚠️ Potential issue | 🟠 Major
NETWORKSis still a template, not a usable pre-configured SDK config.Both entries leave
rpcUrl,djedAddress, andoracleAddressasnull, andgetNetworkConfig()returns them unchanged. That means callers still need to manually supply every runtime-critical value beforegetWeb3,getDjedContract, orgetOracleContractcan work, so this doesn’t yet deliver the “pre-configured network variables” promised by the PR. If real deployed values cannot be shipped here, the helper should at least merge explicit overrides and fail fast with a clear error instead of returning an unusable config.Suggested direction
export const NETWORKS = { sepolia: { name: "Sepolia", chainId: 11155111, rpcUrl: null, djedAddress: null, oracleAddress: null }, mainnet: { name: "Ethereum Mainnet", chainId: 1, rpcUrl: null, djedAddress: null, oracleAddress: null } }; -export const getNetworkConfig = (networkName = "sepolia") => { - const config = NETWORKS[networkName]; +export const getNetworkConfig = (networkName = "sepolia", overrides = {}) => { + const config = NETWORKS[networkName]; if (!config) { throw new Error(`Unsupported network: ${networkName}`); } - return config; + const resolvedConfig = { ...config, ...overrides }; + + if (!resolvedConfig.rpcUrl || !resolvedConfig.djedAddress || !resolvedConfig.oracleAddress) { + throw new Error( + `Network "${networkName}" is incomplete. Provide rpcUrl, djedAddress, and oracleAddress.` + ); + } + + return resolvedConfig; };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@djed-sdk/src/constants.js` around lines 24 - 50, getNetworkConfig currently returns template entries from NETWORKS with rpcUrl, djedAddress, and oracleAddress left null; update getNetworkConfig(networkName = "sepolia", overrides = {}) to merge NETWORKS[networkName] with the overrides object (Object.assign or spread) and then validate required keys (rpcUrl, djedAddress, oracleAddress) on the merged config; if any are missing or falsy, throw a clear Error naming the missing fields so callers fail fast instead of receiving an unusable config. Use the NETWORKS constant and function getNetworkConfig as the reference points to implement the merge-and-validate behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@djed-sdk/src/constants.js`:
- Around line 24-50: getNetworkConfig currently returns template entries from
NETWORKS with rpcUrl, djedAddress, and oracleAddress left null; update
getNetworkConfig(networkName = "sepolia", overrides = {}) to merge
NETWORKS[networkName] with the overrides object (Object.assign or spread) and
then validate required keys (rpcUrl, djedAddress, oracleAddress) on the merged
config; if any are missing or falsy, throw a clear Error naming the missing
fields so callers fail fast instead of receiving an unusable config. Use the
NETWORKS constant and function getNetworkConfig as the reference points to
implement the merge-and-validate behavior.
Addressed Issues:
Fixes #6
Screenshots/Recordings:
N/A – This change introduces SDK configuration variables and does not affect the UI.
Additional Notes:
This PR enhances the Djed-SDK by introducing pre-configured network variables to improve developer experience.
Previously, developers had to manually configure network-specific variables such as DJED contract addresses when using SDK functions. This update introduces a NETWORKS configuration object that provides predefined variables for supported networks.
Changes included in this PR:
Added NETWORKS configuration in src/constants.js
Exported network variables through src/index.js
Developers can now directly import network configurations from the SDK without manual setup.
Benefits:
Reduces configuration errors
Improves developer experience
Enables faster integration with the SDK
Checklist
AI Usage Disclosure
Check one of the checkboxes below:
I have used the following AI models and tools: TODO
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.
Summary by CodeRabbit