Skip to content

feat(ur-sdk): PAY_PORTION_FULL_PRECISION support#528

Merged
zi-yang-uni merged 8 commits intomainfrom
ziyiyang/portion-precision
Mar 23, 2026
Merged

feat(ur-sdk): PAY_PORTION_FULL_PRECISION support#528
zi-yang-uni merged 8 commits intomainfrom
ziyiyang/portion-precision

Conversation

@zi-yang-uni
Copy link
Copy Markdown
Contributor

@zi-yang-uni zi-yang-uni commented Mar 2, 2026

PR Scope

Please title your PR according to the following types and scopes following conventional commits:

  • fix(SDK name): will trigger a patch version
  • chore(<type>): will not trigger any release and should be used for internal repo changes
  • <type>(public): will trigger a patch version for non-code changes (e.g. README changes)
  • feat(SDK name): will trigger a minor version
  • feat(breaking): will trigger a major version for a breaking change

Description

[Summary of the change, motivation, and context]

How Has This Been Tested?

[e.g. Manually, E2E tests, unit tests, Storybook]

Are there any breaking changes?

[e.g. Type definitions, API definitions]

If there are breaking changes, please ensure you bump the major version Bump the major version (by using the title feat(breaking): ...), post a notice in #eng-sdks, and explicitly notify all Uniswap Labs consumers of the SDK.

(Optional) Feedback Focus

[Specific parts of this PR you'd like feedback on, or that reviewers should pay closer attention to]

(Optional) Follow Ups

[Things that weren't addressed in this PR, ways you plan to build on this work, or other ways this work could be extended]


✨ Claude-Generated Content

Summary

  • Add PAY_PORTION_FULL_PRECISION command (0x07) support for higher precision fee calculations using 1e18 scale instead of basis points (1e4)
  • Conditionally enabled for Universal Router V2.1.1+ to maintain backward compatibility

Changes

sdks/universal-router-sdk/src/utils/routerCommands.ts

  • Added PAY_PORTION_FULL_PRECISION command type (0x07) with portion parameter (1e18 scale)

sdks/universal-router-sdk/src/utils/numbers.ts

  • Added encodeFee1e18() function to encode fees with 18 decimal precision

sdks/universal-router-sdk/src/entities/actions/uniswap.ts

  • Updated UniswapTrade.encode() to use PAY_PORTION_FULL_PRECISION when urVersion >= V2_1_1
  • Falls back to PAY_PORTION (bips) for older router versions
  • Updated minimum amount out calculation to use 1e18 division for exact output trades when using full precision

sdks/universal-router-sdk/test/utils/commandParser.test.ts

  • Added unit test for PAY_PORTION_FULL_PRECISION command parsing

sdks/universal-router-sdk/test/utils/feeEncoding.test.ts (new)

  • Added comprehensive tests for encodeFeeBips() and encodeFee1e18() functions
  • Added tests comparing precision between bips and 1e18 encoding
  • Added tests verifying correct command bytes (0x06 vs 0x07)

Are there any breaking changes?

No — the external API (options.fee) remains unchanged. The new command is only used when urVersion >= V2_1_1, maintaining backward compatibility with older router versions.

Comment thread sdks/universal-router-sdk/src/entities/actions/uniswap.ts Outdated
Comment thread sdks/universal-router-sdk/src/utils/numbers.ts Outdated
@zi-yang-uni zi-yang-uni requested a review from kristiehuang March 6, 2026 17:25
Comment thread sdks/universal-router-sdk/src/entities/actions/uniswap.ts Outdated
Comment thread sdks/universal-router-sdk/test/utils/feeEncoding.test.ts
@zi-yang-uni zi-yang-uni force-pushed the ziyiyang/portion-precision branch from 269c7cc to 42a18c5 Compare March 13, 2026 16:42
@zi-yang-uni zi-yang-uni requested a review from hensha256 March 13, 2026 16:48
@zi-yang-uni zi-yang-uni force-pushed the ziyiyang/portion-precision branch from 42a18c5 to f5ae63a Compare March 20, 2026 02:53
@zi-yang-uni zi-yang-uni marked this pull request as ready for review March 20, 2026 03:01
@zi-yang-uni zi-yang-uni requested a review from a team as a code owner March 20, 2026 03:01
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 20, 2026

🤖 Claude Code Review

Review complete

Summary

This PR adds support for PAY_PORTION_FULL_PRECISION (command 0x07) in Universal Router v2.1.1, enabling 1e18 precision for fee percentages instead of the legacy bips (1e4) precision.

Changes Reviewed

Core Logic (uniswap.ts:264-311):

  • Correctly branches based on urVersion >= V2_1_1 to select between PAY_PORTION_FULL_PRECISION and PAY_PORTION
  • Throws an error for fractional bips fees on older UR versions (line 277-278), preventing silent precision loss
  • Unified feeDeduction handling - now computed once and applied after both fee conditionals
  • Passes urVersion to addCommand for the new command (line 287)

Fee Encoding (numbers.ts:20-24):

  • FULL_PORTION_PRECISION constant correctly represents 1e18
  • encodeFee1e18() properly multiplies the fee percentage by 1e18

Command Definitions (routerCommands.ts:18, 208-215):

  • PAY_PORTION_FULL_PRECISION = 0x07 correctly defined
  • Command definition uses portion parameter name (vs bips for PAY_PORTION)

Tests (feeEncoding.test.ts):

  • Comprehensive coverage of encoding functions
  • Tests for command selection based on UR version (undefined, V2_0, V2_1_1)
  • Tests for exact input/output behavior with both precision levels
  • Tests verify correct command bytes (0x06 vs 0x07)

Verification of Existing Comments

All previously raised concerns have been addressed:

  • ✅ Version check handles V2_0 consumers correctly (uses PAY_PORTION)
  • ✅ Fractional bips rejection implemented (line 277-278)
  • feeDeduction unified - no longer duplicated
  • urVersion passed to addCommand (line 287)
  • ✅ Constant renamed to FULL_PORTION_PRECISION
  • ✅ Tests cover the encode function's fee command selection

No Issues Found

The implementation is correct and handles backward compatibility properly. V2_0 consumers will continue to receive PAY_PORTION with bips encoding, while V2_1_1+ consumers get the new high-precision command.


💡 Want a fresh review? Add a comment containing @request-claude-review to trigger a new review at any time.

@graphite-app graphite-app Bot requested review from a team March 20, 2026 03:02
github-actions[bot]
github-actions Bot previously approved these changes Mar 20, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review verdict: APPROVE

👆 The main review comment above is the source of truth for this PR review. It is automatically updated on each review cycle, so always refer to it for the most current feedback.

This formal review submission is for the verdict only.

@graphite-app
Copy link
Copy Markdown

graphite-app Bot commented Mar 20, 2026

Graphite Automations

"Request reviewers once CI passes on sdks monorepo" took an action on this PR • (03/20/26)

3 reviewers were added and 1 assignee was added to this PR based on Siyu Jiang (See-You John)'s automation.

Copy link
Copy Markdown
Collaborator

kristiehuang commented Mar 20, 2026

Comment thread sdks/universal-router-sdk/src/entities/actions/uniswap.ts
Comment thread sdks/universal-router-sdk/src/utils/routerCommands.ts
Copy link
Copy Markdown
Collaborator

@kristiehuang kristiehuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments/questions

Comment thread sdks/universal-router-sdk/src/entities/actions/uniswap.ts Outdated
TradeType.EXACT_INPUT
)
const feeOptions: FeeOptions = { fee: new Percent(5, 100), recipient: TEST_FEE_RECIPIENT_ADDRESS }
const opts = swapOptions({ fee: feeOptions, urVersion: URVersion.V2_1 })
Copy link
Copy Markdown
Collaborator

@kristiehuang kristiehuang Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will fail to compile -- deprecated 2.1 entirely, this enum value doesn't exist. only 2.0 and 2.1.1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually wait how did it pass typecheck lol

@github-actions github-actions Bot dismissed their stale review March 23, 2026 16:18

Superseded by new review after PR update

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review verdict: APPROVE

👆 The main review comment above is the source of truth for this PR review. It is automatically updated on each review cycle, so always refer to it for the most current feedback.

This formal review submission is for the verdict only.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review verdict: APPROVE

👆 The main review comment above is the source of truth for this PR review. It is automatically updated on each review cycle, so always refer to it for the most current feedback.

This formal review submission is for the verdict only.

kristiehuang
kristiehuang previously approved these changes Mar 23, 2026
@kristiehuang kristiehuang dismissed their stale review March 23, 2026 18:16

re-approve as swap-be

@zi-yang-uni zi-yang-uni merged commit db54625 into main Mar 23, 2026
9 checks passed
@zi-yang-uni zi-yang-uni deleted the ziyiyang/portion-precision branch March 23, 2026 18:18
Dargon789 pushed a commit to Dargon789/sdks that referenced this pull request Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants