-
Notifications
You must be signed in to change notification settings - Fork 7
Feat: Add Hyperliquid Builders Fee to Spot and Perp Orders #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds Hyperliquid builder fee support to spot sell and perpetual (long/short) orders, enabling the collection of 0.05% builder fees. The implementation includes automatic approval of builder codes during execution, a new approveBuilderCode action for explicit approval, and comprehensive E2E test coverage validating builder reward accrual.
Key Changes
- Implements automatic builder code approval with 0.05% fee for
spotSell,perpLong, andperpShortactions - Adds new
approveBuilderCodeability action with corresponding precheck and execute logic - Standardizes E2E test setup using
setupVincentDevelopmentEnvironmenthelper function
Reviewed Changes
Copilot reviewed 31 out of 33 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/lib/vincent-ability.ts |
Adds builder fee approval checks in precheck, automatic approval in execute, and fee configuration for spot/perp orders |
src/lib/constants.ts |
Defines Vincent builder address and 0.05% fee rate constants |
src/lib/types.ts |
Adds APPROVE_BUILDER_CODE enum value to HyperliquidAction |
src/lib/schemas.ts |
Adds schema validation for approveBuilderCode action and result |
src/lib/ability-helpers/approve-builder-code.ts |
Implements builder code approval via EIP-712 signed action |
src/lib/ability-helpers/execute-spot-order.ts |
Adds optional builder fee parameter for spot sell orders |
src/lib/ability-helpers/execute-perp-order.ts |
Adds optional builder fee parameter for perpetual orders |
src/lib/ability-checks/is-builder-code-approved.ts |
Implements check for existing builder code approval status |
test/e2e/approve-builder-code.spec.ts |
New E2E test validating explicit builder code approval |
test/e2e/spot/sell.spec.ts |
Validates builder rewards increase after spot sell execution |
test/e2e/perp/long.spec.ts |
Validates builder rewards increase after perp long execution |
test/e2e/perp/short.spec.ts |
Validates builder rewards increase after perp short execution |
| Multiple E2E test files | Standardizes test setup using setupVincentDevelopmentEnvironment helper |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/apps/ability-hyperliquid/test/e2e/transfer/to-spot.spec.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 31 out of 33 changed files in this pull request and generated 13 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/apps/ability-hyperliquid/src/lib/ability-helpers/approve-builder-code.ts
Show resolved
Hide resolved
packages/apps/ability-hyperliquid/src/lib/ability-helpers/approve-builder-code.ts
Show resolved
Hide resolved
packages/apps/ability-hyperliquid/src/lib/ability-helpers/execute-spot-order.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 31 out of 33 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| */ | ||
| builderFee?: { | ||
| builderAddress: string; // Builder address | ||
| feeInTenthsOfBps: number; // Fee in tenths of basis points (e.g., 50 = 0.05%) |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is inconsistent with line 27. Line 27 correctly states '50 = 0.05% = 5 basis points' but line 32 only says '50 = 0.05%' without clarifying the basis points. For consistency and clarity, update line 32 to match the format on line 27: // Fee in tenths of basis points (e.g., 50 = 0.05% = 5 basis points)
| feeInTenthsOfBps: number; // Fee in tenths of basis points (e.g., 50 = 0.05%) | |
| feeInTenthsOfBps: number; // Fee in tenths of basis points (e.g., 50 = 0.05% = 5 basis points) |
| */ | ||
| builderFee?: { | ||
| builderAddress: string; // Builder address | ||
| feeInTenthsOfBps: number; // Fee in tenths of basis points (e.g., 10 = 0.01%) |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment should clarify the basis points conversion for consistency with spot orders. Update to: // Fee in tenths of basis points (e.g., 10 = 0.01% = 1 basis point) to match the documentation style on line 46.
| feeInTenthsOfBps: number; // Fee in tenths of basis points (e.g., 10 = 0.01%) | |
| feeInTenthsOfBps: number; // Fee in tenths of basis points (e.g., 10 = 0.01% = 1 basis point) |
| * (since 1% = 100 basis points = 1000 tenths of basis points) | ||
| */ | ||
| function percentageToTenthsOfBps(percentageStr: string): number { | ||
| const percentage = parseFloat(percentageStr); |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function should validate the input to prevent invalid conversions. Add input validation to check if percentageStr is a valid numeric string and if parseFloat returns NaN. Consider: if (isNaN(percentage) || percentage < 0) { throw new Error('Invalid percentage value'); }
| const percentage = parseFloat(percentageStr); | |
| const percentage = parseFloat(percentageStr); | |
| if (isNaN(percentage) || percentage < 0) { | |
| throw new Error('Invalid percentage value'); | |
| } |
| it('should validate builder rewards increased after spot sell', async () => { | ||
| // Wait a bit for order to fill and builder rewards to be credited | ||
| // Builder rewards are processed onchain, so we need to wait for the transaction to be processed | ||
| await new Promise((resolve) => setTimeout(resolve, 10000)); |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded 10-second timeout is a magic number that could fail in slower network conditions or cause unnecessary delays in faster environments. Consider extracting this to a named constant like BUILDER_REWARD_PROCESSING_TIMEOUT_MS = 10000 or make it configurable via environment variable for different test environments.
Description
Both
precheckandexecutenow ensure that the Agent Wallet’s PKP has granted the required Hyperliquid Builder Fee permission (hardcoded at0.05%) for our Vincent Builder address whenever the Ability Action isspotSell,perpLong, orperpShortprecheckwill fail for these three actionsexecutewill automatically grant the required permission for these three actions, before executing the actionA new Ability action was added:
approveBuilderCodeprecheckwill fail if already permittedexecutewill permit it even if already permittedSetup code for all E2E tests was standardized
Some missing response types for various Ability actions are now exported
Docs will be updated in a fast follow PR
Type of change
Although maybe this is a breaking change?
How Has This Been Tested?
test/e2e/perp/long.spec.ts,test/e2e/perp/short.spec.ts, andtest/e2e/spot/sell.spec.tswere updated to check the HL Builder reward balance before executing their E2E tests, and then after to validate the reward balance increasedtest/e2e/approve-builder-code.spec.tswas added to validate explicitly permitting the HL Builder worksThe following are the E2E test commands and their success output:
Before initial permit:
After permitted:
Checklist:
nx release plan) describing my changes and the version bump