fix(stake): accept tokenProgramId parameter in account builders#177
fix(stake): accept tokenProgramId parameter in account builders#1776figpsolseeker wants to merge 1 commit intodcccrypto:mainfrom
Conversation
initPoolAccounts, depositAccounts, withdrawAccounts, and flushToInsuranceAccounts all hardcoded TOKEN_PROGRAM_ID (SPL Token). If the collateral mint or LP mint is owned by Token-2022, all token operations (create, transfer, burn) would fail because the wrong token program is referenced in the instruction account list. Each function now accepts an optional tokenProgramId parameter that defaults to TOKEN_PROGRAM_ID for backward compatibility. Callers with Token-2022 mints pass TOKEN_2022_PROGRAM_ID explicitly. This is a non-breaking change — existing callers that omit the parameter get the same behaviour as before. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughFour account-key builder functions in the Solana stake module ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
🧹 Nitpick comments (1)
src/solana/stake.ts (1)
509-582: Add explicit tests for non-defaulttokenProgramIdpath.Current coverage exercises default behavior; please add assertions that passing a custom
tokenProgramIdis reflected in each builder’s returned account list to prevent regressions.🧪 Suggested test shape
+it('uses provided tokenProgramId in all stake account builders', () => { + const customTokenProgramId = new PublicKey('11111111111111111111111111111111'); + + expect(initPoolAccounts(initPoolArgs, customTokenProgramId)[8].pubkey.equals(customTokenProgramId)).toBe(true); + expect(depositAccounts(depositArgs, customTokenProgramId)[8].pubkey.equals(customTokenProgramId)).toBe(true); + expect(withdrawAccounts(withdrawArgs, customTokenProgramId)[8].pubkey.equals(customTokenProgramId)).toBe(true); + expect(flushToInsuranceAccounts(flushArgs, customTokenProgramId)[7].pubkey.equals(customTokenProgramId)).toBe(true); +});🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/solana/stake.ts` around lines 509 - 582, Add unit tests that exercise the non-default tokenProgramId path for initPoolAccounts, depositAccounts, withdrawAccounts, and flushToInsuranceAccounts: call each function with a custom PublicKey (not TOKEN_PROGRAM_ID) and assert the returned account array includes that custom key (and not the default) in the expected slot for the token program entry; ensure tests check both pubkey equality and isSigner/isWritable flags for that entry to guard against regressions when the tokenProgramId parameter is provided.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/solana/stake.ts`:
- Around line 509-582: Add unit tests that exercise the non-default
tokenProgramId path for initPoolAccounts, depositAccounts, withdrawAccounts, and
flushToInsuranceAccounts: call each function with a custom PublicKey (not
TOKEN_PROGRAM_ID) and assert the returned account array includes that custom key
(and not the default) in the expected slot for the token program entry; ensure
tests check both pubkey equality and isSigner/isWritable flags for that entry to
guard against regressions when the tokenProgramId parameter is provided.
Summary
initPoolAccounts,depositAccounts,withdrawAccounts, andflushToInsuranceAccountsall hardcodedTOKEN_PROGRAM_ID(SPL Token). If the collateral mint or LP mint is owned by Token-2022 (TOKEN_2022_PROGRAM_ID), all token operations (create, transfer, burn) would fail because the wrong token program is referenced in the instruction account list.Changes
Each function now accepts an optional
tokenProgramIdparameter that defaults toTOKEN_PROGRAM_IDfor backward compatibility:Updated functions:
initPoolAccounts(stake.ts:504)depositAccounts(stake.ts:523)withdrawAccounts(stake.ts:542)flushToInsuranceAccounts(stake.ts:560)This is a non-breaking change — existing callers that omit the parameter get the same behaviour as before.
Test plan
npm run lint(tsc --noEmit) cleanvitest run: same 14 pre-existing failures asmain, zero new failuresSummary by CodeRabbit