feat(solana): override tokens#1479
Conversation
📝 WalkthroughWalkthroughAdds Yarn package manager metadata, refreshes Solana token data, introduces SOL/WSOL overrides, and updates generation to validate Jupiter tokens, merge overrides, sort output, and report validation drops. ChangesSolana token generation
Package manager metadata
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant main
participant JupiterStrictSet
participant readOverrides
participant applyOverrides
main->>JupiterStrictSet: validate and map tokens
main->>readOverrides: load SolanaOverrides.json
readOverrides-->>main: override entries
main->>applyOverrides: merge Jupiter tokens and overrides
applyOverrides-->>main: replaced and appended tokens
main->>main: sort tokens and write output
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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
🧹 Nitpick comments (1)
src/scripts/solana.ts (1)
112-125: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winValidate override entries and guard
JSON.parse.
readOverrides()guards the missing-file and non-array cases but then does an uncheckedJSON.parse(throws uncaught on malformed JSON, crashing the whole generation run) and castsparsed as TokenInfo[]without checking that each entry actually has the requiredTokenInfofields (chainId,address,name,symbol,decimals). Since the PR objective states this file is meant to be hand-extended for other tokens over time, a future typo/missing field would silently propagate intoSolanaDefault.jsoninstead of being caught here, the wayisValidTokenalready catches malformed Jupiter entries.♻️ Proposed fix: guard parsing and validate entries
+function isValidOverride(t: unknown): t is TokenInfo { + const o = t as Partial<TokenInfo> + return Boolean( + o && + typeof o.address === 'string' && + typeof o.name === 'string' && + typeof o.symbol === 'string' && + Number.isInteger(o.decimals) && + (o.decimals ?? -1) >= 0 && + typeof o.chainId === 'number', + ) +} + function readOverrides(): TokenInfo[] { const filePath = path.join(SRC_DIR, OVERRIDES_FILE) if (!fs.existsSync(filePath)) { console.log(`No overrides file at ${filePath}, skipping`) return [] } - const parsed = JSON.parse(fs.readFileSync(filePath, 'utf-8')) + let parsed: unknown + try { + parsed = JSON.parse(fs.readFileSync(filePath, 'utf-8')) + } catch (e) { + console.warn(`Failed to parse ${OVERRIDES_FILE}, skipping overrides: ${e}`) + return [] + } if (!Array.isArray(parsed)) { console.warn(`Unexpected ${OVERRIDES_FILE} shape (expected array), skipping overrides`) return [] } - return parsed as TokenInfo[] + const valid = parsed.filter(isValidOverride) + if (valid.length !== parsed.length) { + console.warn(`Dropped ${parsed.length - valid.length} malformed override entries`) + } + return valid }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/scripts/solana.ts` around lines 112 - 125, Update readOverrides() to catch JSON.parse failures and return no overrides with a warning instead of allowing malformed JSON to abort generation. After confirming the parsed value is an array, validate every entry using the existing isValidToken validation or equivalent checks for chainId, address, name, symbol, and decimals; return an empty override list and warn when any entry is invalid, and only then treat the entries as TokenInfo[].
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@package.json`:
- Around line 74-75: Update the shared CI setup before the yarn install step to
enable Corepack and activate the packageManager-declared Yarn 1.22.22 version,
ensuring the existing yarn install --frozen-lockfile command uses the pinned
Yarn release.
---
Nitpick comments:
In `@src/scripts/solana.ts`:
- Around line 112-125: Update readOverrides() to catch JSON.parse failures and
return no overrides with a warning instead of allowing malformed JSON to abort
generation. After confirming the parsed value is an array, validate every entry
using the existing isValidToken validation or equivalent checks for chainId,
address, name, symbol, and decimals; return an empty override list and warn when
any entry is invalid, and only then treat the entries as TokenInfo[].
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e9c66230-02d2-44e4-849f-f781eebd7992
📒 Files selected for processing (4)
package.jsonsrc/public/SolanaDefault.jsonsrc/public/SolanaOverrides.jsonsrc/scripts/solana.ts
The source of tokens doesn't define SOL and WSOL well, so I added a static
SolanaOverrides.jsonto control that.In the future we can use it to fix other tokens.
Summary by CodeRabbit
New Features
Bug Fixes
Chores