Repository navigation
fix/web: read an LP position's money in USD, not quote units labelled as dollars #264
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
lgrawet
wants to merge
3
commits into
hummingbot:main
Choose a base branch
from
lgrawet:fix/lp-money-units-usd
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.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,83 @@ | ||
| /** | ||
| * What an LP position's money figures are *denominated in*, and how they render. | ||
| * | ||
| * The regression this pins: `total_value_quote` / `fees_earned_quote` / | ||
| * `net_pnl_quote` are all measured in the pair's quote — SOL on an `X-SOL` range — | ||
| * and the cards used to prefix every one of them with a `$`. A 0.163 SOL range | ||
| * worth about $20 read as "$0.16": not a rounding error but a wrong number, off | ||
| * by the whole SOL/USD rate. The fix prices the figure off the pool's own quote | ||
| * token, and when that price is unknown leaves it in SOL under the SOL label. | ||
| */ | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import type { ExecutorInfo } from "@/lib/api"; | ||
|
|
||
| import { lpFees, lpPnl, lpValue, positionQuote, readLpPosition } from "./lp-position"; | ||
|
|
||
| /** The SOL price used across these cases, so the dollars are checkable by hand. */ | ||
| const SOL = 121.69; | ||
|
|
||
| function lpExecutor(over: Partial<ExecutorInfo> = {}): ExecutorInfo { | ||
| return { | ||
| id: "e1", | ||
| type: "lp_executor", | ||
| connector: "solana-mainnet-beta", | ||
| trading_pair: "MINT-SOL", | ||
| side: "", | ||
| status: "running", | ||
| close_type: "", | ||
| pnl: 0, | ||
| volume: 0, | ||
| timestamp: 0, | ||
| controller_id: "", | ||
| cum_fees_quote: 0, | ||
| net_pnl_pct: 0, | ||
| entry_price: 0, | ||
| current_price: 0, | ||
| close_timestamp: 0, | ||
| custom_info: {}, | ||
| config: { pool_address: "POOL", connector_name: "solana-mainnet-beta" }, | ||
| ...over, | ||
| } as unknown as ExecutorInfo; | ||
| } | ||
|
|
||
| describe("positionQuote", () => { | ||
| it("reads the quote off the pair and uppercases it", () => { | ||
| expect(positionQuote("oreoU2P8bN6jkk3jbaiVxYnG1dCXcYxwhwyK9jSybcp-SOL")).toBe("SOL"); | ||
| expect(positionQuote("So11111111111111111111111111111111111111112-USDC")).toBe("USDC"); | ||
| }); | ||
|
|
||
| it("falls back to USDT for a pair with no quote segment", () => { | ||
| expect(positionQuote("")).toBe("USDT"); | ||
| expect(positionQuote("SOLONLY")).toBe("USDT"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("readLpPosition", () => { | ||
| it("carries the quote the money figures are denominated in", () => { | ||
| const pos = readLpPosition(lpExecutor({ trading_pair: "MINT-SOL" })); | ||
| expect(pos?.quote).toBe("SOL"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("LP money in USD when the quote's price is known", () => { | ||
| it("prices the position value, PnL and fees in dollars", () => { | ||
| expect(lpValue(0.163339, SOL, "SOL")).toBe("$19.88"); | ||
| expect(lpPnl(0.003097, SOL, "SOL")).toBe("+$0.38"); | ||
| expect(lpFees(0.00136, SOL, "SOL")).toBe("$0.17"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("LP money with no rate: quote units, not dollars", () => { | ||
| it("keeps the figure in SOL and labels it SOL", () => { | ||
| expect(lpValue(0.163339, null, "SOL")).toBe("0.1633 SOL"); | ||
| expect(lpPnl(-0.00025288, null, "SOL")).toBe("-0.0002529 SOL"); | ||
| }); | ||
|
|
||
| it("never stamps a dollar on an unconverted figure", () => { | ||
| expect(lpValue(0.163339, null, "SOL")).not.toContain("$"); | ||
| expect(lpPnl(0.003, null, "SOL")).not.toContain("$"); | ||
| expect(lpFees(2.4e-5, null, "SOL")).not.toContain("$"); | ||
| }); | ||
| }); |
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
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.