-
Notifications
You must be signed in to change notification settings - Fork 88
feat(pricing): add sign-session-key pricing support and product-awa…
#925
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
Merged
Ansonhkg
merged 3 commits into
naga
from
feature/jss-118-naga-featbug-add-signsessionkey-product-index-3-for
Oct 8, 2025
Merged
Changes from 1 commit
Commits
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
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
60 changes: 60 additions & 0 deletions
60
...rks/src/networks/vNaga/shared/managers/pricing-manager/getMaxPricesForNodeProduct.spec.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,60 @@ | ||
| import { PRODUCT_IDS } from '@lit-protocol/constants'; | ||
|
|
||
| import { getMaxPricesForNodeProduct } from './getMaxPricesForNodeProduct'; | ||
|
|
||
| describe('getMaxPricesForNodeProduct', () => { | ||
| it('uses the requested product column when ranking nodes', () => { | ||
| const nodePrices = [ | ||
| { | ||
| url: 'https://node-a', | ||
| prices: [80n, 5n, 9n, 30n], | ||
| }, | ||
| { | ||
| url: 'https://node-b', | ||
| prices: [70n, 4n, 8n, 10n], | ||
| }, | ||
| { | ||
| url: 'https://node-c', | ||
| prices: [60n, 3n, 7n, 20n], | ||
| }, | ||
| ]; | ||
|
|
||
| // Log the incoming order to show the encryption column is already sorted lowest-first. | ||
| console.log( | ||
| 'incoming order', | ||
| nodePrices.map(({ url, prices }) => ({ | ||
| url, | ||
| decryptionPrice: prices[PRODUCT_IDS.DECRYPTION], | ||
| signPrice: prices[PRODUCT_IDS.SIGN], | ||
| litActionPrice: prices[PRODUCT_IDS.LIT_ACTION], | ||
| signSessionKeyPrice: prices[PRODUCT_IDS.SIGN_SESSION_KEY], | ||
| })) | ||
| ); | ||
|
|
||
| // Call the helper exactly like the SDK does: ask for SIGN_SESSION_KEY prices, | ||
| // pass the raw price feed output, and cap the request at two nodes. | ||
| const result = getMaxPricesForNodeProduct({ | ||
| nodePrices, | ||
| userMaxPrice: 100n, | ||
| productId: PRODUCT_IDS.SIGN_SESSION_KEY, | ||
| numRequiredNodes: 2, | ||
| }); | ||
|
|
||
| console.log( | ||
| 'selected nodes', | ||
| result.map(({ url, price }) => ({ url, price })) | ||
| ); | ||
|
|
||
| // After sorting the nodes by the session-key column, the helper should | ||
| // return node-b (10) and node-c (20) even though the original array was | ||
| // ordered by the decryption price column. | ||
| expect(result).toHaveLength(2); | ||
| expect(result[0].url).toBe('https://node-b'); | ||
| expect(result[1].url).toBe('https://node-c'); | ||
|
|
||
| // Base prices are taken from the SIGN_SESSION_KEY column (10 and 20) | ||
| // with the excess (100 - 30 = 70) split evenly. | ||
| expect(result[0].price).toBe(10n + 35n); | ||
| expect(result[1].price).toBe(20n + 35n); | ||
| }); | ||
| }); | ||
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.