fix: parse slot0 response as array — viem v2 compat (#2) #3
No reviewers
Labels
No labels
action
backlog
blocked
in-progress
priority
tech-debt
underspecified
vision
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: johba/harb#3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/issue-2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #2
Summary
Test plan
AI Review
Summary
Small, focused bug fix. viem v2 decodes multi-output contract calls as plain arrays; the ABI confirms
tickis output index 1 ([sqrtPriceX96, tick, observationIndex, ...]). The fix is correct.Findings
None. The implementation is sound:
slot0Response[1]correctly targetstickperUNISWAP_POOL_ABI(useSwapKrk.ts:75)Number()coercion is safe —int24range (−8,388,608 to 8,388,607) is well within JS safe integersVerdict
APPROVE — Correct viem v2 fix: tick is at array index 1 per the ABI, Number() coercion is safe for int24 range, fallback preserves compatibility.
Reviewed at
0eb1816| AGENTS.mdAI Review: APPROVE — Correct viem v2 fix: tick is at array index 1 per the ABI, Number() coercion is safe for int24 range, fallback preserves compatibility.
AI Review
Summary\n\nSmall, focused fix for viem v2's breaking change:
readContractnow returns multi-output calls as plain tuples rather than named objects.\n\n### Correctness\n\nVerified againstUNISWAP_POOL_ABIinuseSwapKrk.ts:\n\n\noutputs[0] = sqrtPriceX96 (uint160)\noutputs[1] = tick (int24)\n\n\nIndex 1 is correct.Number(slot0Response[1])is safe —int24is well within JavaScript safe-integer range regardless of whether viem surfaces it asnumberorbigint.\n\n### Code quality\n\n- ChangingcurrentTickfromnumber | nulltonumber(throwing instead of leavingnull) is a cleaner type.\n- The comment explaining the viem v2 tuple layout is helpful and accurate.\n- TheisRecordfallback for named-object shape is a reasonable forward-compat guard.\n\nNo issues found.Verdict
APPROVE — Correct array-index fix for viem v2 tuple return; fallback preserves forward compat
Reviewed at
0eb1816| AGENTS.mdAI Review: APPROVE — Correct array-index fix for viem v2 tuple return; fallback preserves forward compat
AI Re-review (round 3)
Previous Findings\n\nNo findings in the previous review — it was an APPROVE at
0eb1816. The author pushed additional commits after approval, and this re-review covers those incremental changes.\n\n### Incremental Changes Assessment\n\nThe incremental diff (0eb1816→f1e4c37) made the following changes to already-approved code:\n\n#### 1.typeof slot0Response[1] === 'number'replacesNumber(slot0Response[1])\n\n- mediumCheatsView.vue:559: The approved version usedNumber(slot0Response[1]), which the previous review explicitly noted was safe "regardless of whether viem surfaces it asnumberorbigint". The newtypeof === 'number'guard silently rejects abigintvalue — if viem returnsint24asbigint(or ever changes to do so), the condition is false,currentTickstaysnull, and the function throws"Unable to determine current pool tick"— the exact bug this PR was meant to fix. In practice viem 2.x mapsint24tonumber, so it works today, but the guard is now fragile. RestoreNumber(slot0Response[1])(or checktypeof === 'number' || typeof === 'bigint') to be safe.\n\n#### 2. Explanatory comment removed\n\n- minorCheatsView.vue:558: The approved version included:\n \n This context is valuable for the next person touching this code. Removing it leaves a bare index access with no explanation of the tuple layout or the viem v2 reason for it.\n\n#### 3. Type regressed fromnumbertonumber | null\n\n- minorCheatsView.vue:558: The previous review praisedlet currentTick: number(with inline throw) as cleaner. The revert tonumber | nullis functionally equivalent (null check throws on the next line), but is a step backward in type clarity for no gain.\n\n### Summary\n\nThe coreArray.isArrayfix is correct and the index is right. But the incremental changes after approval made the code less robust and less readable than the version that was approved. Recommend restoringNumber()coercion and the viem v2 comment, and preferringlet currentTick: numberwith the throw in theelsebranch.Verdict
REQUEST_CHANGES — Incremental commits regressed from the approved version: dropped bigint coercion safety and removed the explanatory comment
Reviewed at
f1e4c37| Previous:0eb1816| AGENTS.mdAI Re-review (round 3): REQUEST_CHANGES — Incremental commits regressed from the approved version: dropped bigint coercion safety and removed the explanatory comment