-
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
Open
spacesailor24
wants to merge
12
commits into
main
Choose a base branch
from
feat/hl-buildercode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+719
−552
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
337aa19
feat: add builder fee
spacesailor24 109f48c
chore: nx release plan
spacesailor24 a24034c
fix: always run APPROVE_BUILDER_CODE execute
spacesailor24 91f907d
chore: nitpick formatting
spacesailor24 025ecb3
Update packages/apps/ability-hyperliquid/test/e2e/spot/sell.spec.ts
spacesailor24 1c20a27
Update packages/apps/ability-hyperliquid/test/e2e/perp/short.spec.ts
spacesailor24 ce201dd
Update packages/apps/ability-hyperliquid/test/e2e/perp/short.spec.ts
spacesailor24 ab256dc
chore: remove timeouts from e2e tests
spacesailor24 d95bf8c
chore: turn off lit client debug
spacesailor24 6e0510e
chore: add error response to failed builder approval
spacesailor24 d456156
chore: copilot fixes
spacesailor24 4f0b148
Refactor test to remove wait for builder rewards
spacesailor24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| ability-hyperliquid: minor | ||
| --- | ||
|
|
||
| Add Vincent builders fee to spot sell and perp long and short trades. |
4 changes: 2 additions & 2 deletions
4
packages/apps/ability-hyperliquid/src/generated/lit-action.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/apps/ability-hyperliquid/src/generated/vincent-ability-metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| { | ||
| "ipfsCid": "QmaGop5dGvYeGpLd19FPH2i8fDqnHAHSgzyuhmetUqmU3C" | ||
| "ipfsCid": "QmeRz1hh6ejpaXiK2JDJbWpcNbAQvd4BzYgHCFErxGMCfS" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/apps/ability-hyperliquid/src/lib/ability-checks/is-builder-code-approved.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import type { InfoClient } from '@nktkas/hyperliquid'; | ||
|
|
||
| /** | ||
| * Check if a given address has approved a given builder address | ||
| * @param infoClient - Hyperliquid InfoClient instance | ||
| * @param ethAddress - Ethereum address to check approval for | ||
| * @param builderAddress - Builder address to check approval for | ||
| * @returns true if the builder is approved, false otherwise | ||
| */ | ||
| export const isBuilderCodeApproved = async ({ | ||
| infoClient, | ||
| ethAddress, | ||
| builderAddress, | ||
| }: { | ||
| infoClient: InfoClient; | ||
| ethAddress: string; | ||
| builderAddress: string; | ||
| }): Promise<boolean> => { | ||
| // Call maxBuilderFee to get the maximum builder fee approved for this builder | ||
| // If the builder is not approved, this will return 0 | ||
| const maxFee = await infoClient.maxBuilderFee({ | ||
| user: ethAddress as `0x${string}`, | ||
| builder: builderAddress as `0x${string}`, | ||
| }); | ||
|
|
||
| // Builder is approved if maxFee is greater than 0 | ||
| const isApproved = typeof maxFee === 'number' && maxFee > 0; | ||
|
|
||
| console.log('[isBuilderCodeApproved] Builder approval check', { | ||
| ethAddress, | ||
| builderAddress, | ||
| maxFee, | ||
| isApproved, | ||
| }); | ||
|
|
||
| return isApproved; | ||
| }; |
85 changes: 85 additions & 0 deletions
85
packages/apps/ability-hyperliquid/src/lib/ability-helpers/approve-builder-code.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import * as hyperliquid from '@nktkas/hyperliquid'; | ||
| import { | ||
| ApproveBuilderFeeRequest, | ||
| ApproveBuilderFeeTypes, | ||
| SuccessResponse, | ||
| parser, | ||
| } from '@nktkas/hyperliquid/api/exchange'; | ||
| import { signUserSignedAction } from '@nktkas/hyperliquid/signing'; | ||
| import { bigIntReplacer } from '@lit-protocol/vincent-ability-sdk'; | ||
|
|
||
| import { LitActionPkpEthersWallet } from './lit-action-pkp-ethers-wallet'; | ||
| import { getHyperliquidNonce } from './get-hyperliquid-nonce'; | ||
| import { getHyperliquidChainId, getHyperliquidChainName } from './get-hyperliquid-chain-id'; | ||
|
|
||
| export type ApproveBuilderCodeResult = { | ||
| approveResult: SuccessResponse | hyperliquid.ErrorResponse; | ||
| }; | ||
|
|
||
| /** | ||
| * Approve a builder code (builder address) with a maximum fee rate on Hyperliquid | ||
| * @param transport - Hyperliquid HTTP transport instance | ||
| * @param pkpPublicKey - PKP public key for signing | ||
| * @param builderAddress - Builder address to approve | ||
| * @param maxFeeRate - Maximum fee rate as a percentage string (e.g., "0.01" for 0.01%) | ||
| * @param useTestnet - Whether to use testnet (default: false) | ||
| * @returns Approval result from Hyperliquid | ||
| */ | ||
| export async function approveBuilderCode({ | ||
| transport, | ||
| pkpPublicKey, | ||
| builderAddress, | ||
| maxFeeRate, | ||
| useTestnet = false, | ||
| }: { | ||
| transport: hyperliquid.HttpTransport; | ||
| pkpPublicKey: string; | ||
| builderAddress: string; | ||
| maxFeeRate: string; // e.g., "0.01" for 0.01% | ||
spacesailor24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| useTestnet?: boolean; | ||
| }): Promise<ApproveBuilderCodeResult> { | ||
| const pkpWallet = new LitActionPkpEthersWallet(pkpPublicKey); | ||
| const nonce = await getHyperliquidNonce(); | ||
|
|
||
| // Ensure maxFeeRate has the % suffix (required by Hyperliquid schema) | ||
| const maxFeeRateWithPercent = maxFeeRate.endsWith('%') ? maxFeeRate : `${maxFeeRate}%`; | ||
spacesailor24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Construct approve builder fee action | ||
| const approveAction = parser(ApproveBuilderFeeRequest.entries.action)({ | ||
| type: 'approveBuilderFee', | ||
| signatureChainId: getHyperliquidChainId(useTestnet), | ||
| hyperliquidChain: getHyperliquidChainName(useTestnet), | ||
| maxFeeRate: maxFeeRateWithPercent, | ||
| builder: builderAddress, | ||
| nonce, | ||
| }); | ||
|
|
||
| // ApproveBuilderFee is a user-signed action that uses EIP-712 typed data | ||
| const signature = await signUserSignedAction({ | ||
| wallet: pkpWallet, | ||
| action: approveAction, | ||
| types: ApproveBuilderFeeTypes, | ||
| }); | ||
|
|
||
| const approveResult = await Lit.Actions.runOnce( | ||
| { waitForResponse: true, name: 'HyperLiquidApproveBuilderFeeRequest' }, | ||
| async () => { | ||
| return JSON.stringify( | ||
| { | ||
| result: await transport.request('exchange', { | ||
| action: approveAction, | ||
| signature, | ||
| nonce, | ||
| }), | ||
| }, | ||
| bigIntReplacer, | ||
| 2, | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| const parsedApproveResult = JSON.parse(approveResult); | ||
| return { | ||
| approveResult: parsedApproveResult.result as SuccessResponse | hyperliquid.ErrorResponse, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export const HYPERLIQUID_BUILDER_ADDRESS = '0x132Db5f531Ba38628F1640683354229daE04E8e6'; | ||
| export const HYPERLIQUID_BUILDER_FEE_RATE = '0.05'; // Percentage as string (e.g., "0.05" = 0.05%) | ||
spacesailor24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.