@symmio/trading-core 4.1.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +17 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -87
- package/dist/pools/add-market/to-created-pool.d.ts.map +1 -1
- package/dist/pools/add-market/to-created-pool.js +4 -0
- package/dist/pools/add-market/to-created-pool.js.map +1 -1
- package/dist/pools/add-market/types.d.ts +8 -0
- package/dist/pools/add-market/types.d.ts.map +1 -1
- package/dist/pools/auth/authenticate-listing.d.ts +3 -1
- package/dist/pools/auth/authenticate-listing.d.ts.map +1 -1
- package/dist/pools/auth/authenticate-listing.js +28 -23
- package/dist/pools/auth/authenticate-listing.js.map +1 -1
- package/dist/pools/auth/can-reuse-listing-challenge.d.ts +5 -0
- package/dist/pools/auth/can-reuse-listing-challenge.d.ts.map +1 -0
- package/dist/pools/auth/can-reuse-listing-challenge.js +9 -0
- package/dist/pools/auth/can-reuse-listing-challenge.js.map +1 -0
- package/dist/pools/auth/query.d.ts +15 -0
- package/dist/pools/auth/query.d.ts.map +1 -1
- package/dist/pools/auth/query.js +28 -4
- package/dist/pools/auth/query.js.map +1 -1
- package/dist/pools/auth/to-siwe.d.ts +5 -1
- package/dist/pools/auth/to-siwe.d.ts.map +1 -1
- package/dist/pools/auth/to-siwe.js +4 -2
- package/dist/pools/auth/to-siwe.js.map +1 -1
- package/dist/pools/auth/types.d.ts +2 -0
- package/dist/pools/auth/types.d.ts.map +1 -1
- package/dist/pools/cancel-withdraw/cancel-withdraw.js +1 -1
- package/dist/pools/cancel-withdraw/cancel-withdraw.js.map +1 -1
- package/dist/pools/claim-history/get-pool-claim.d.ts +11 -0
- package/dist/pools/claim-history/get-pool-claim.d.ts.map +1 -0
- package/dist/pools/claim-history/get-pool-claim.js +25 -0
- package/dist/pools/claim-history/get-pool-claim.js.map +1 -0
- package/dist/pools/claim-history/index.d.ts +1 -0
- package/dist/pools/claim-history/index.d.ts.map +1 -1
- package/dist/pools/claim-history/to-pool-claim.d.ts.map +1 -1
- package/dist/pools/claim-history/to-pool-claim.js +2 -0
- package/dist/pools/claim-history/to-pool-claim.js.map +1 -1
- package/dist/pools/composition.d.ts +16 -0
- package/dist/pools/composition.d.ts.map +1 -0
- package/dist/pools/composition.js +39 -0
- package/dist/pools/composition.js.map +1 -0
- package/dist/pools/empty-pool-profit.d.ts +4 -0
- package/dist/pools/empty-pool-profit.d.ts.map +1 -0
- package/dist/pools/empty-pool-profit.js +17 -0
- package/dist/pools/empty-pool-profit.js.map +1 -0
- package/dist/pools/index.d.ts +8 -0
- package/dist/pools/index.d.ts.map +1 -1
- package/dist/pools/listing-config/to-listing-config.d.ts +5 -1
- package/dist/pools/listing-config/to-listing-config.d.ts.map +1 -1
- package/dist/pools/listing-config/to-listing-config.js +19 -8
- package/dist/pools/listing-config/to-listing-config.js.map +1 -1
- package/dist/pools/maintenance-fees/get-pool-maintenance-fees.d.ts +37 -0
- package/dist/pools/maintenance-fees/get-pool-maintenance-fees.d.ts.map +1 -0
- package/dist/pools/maintenance-fees/get-pool-maintenance-fees.js +35 -0
- package/dist/pools/maintenance-fees/get-pool-maintenance-fees.js.map +1 -0
- package/dist/pools/maintenance-fees/index.d.ts +3 -0
- package/dist/pools/maintenance-fees/index.d.ts.map +1 -0
- package/dist/pools/maintenance-fees/query.d.ts +11 -0
- package/dist/pools/maintenance-fees/query.d.ts.map +1 -0
- package/dist/pools/maintenance-fees/query.js +21 -0
- package/dist/pools/maintenance-fees/query.js.map +1 -0
- package/dist/pools/market-config/to-listing-market-config.d.ts +6 -1
- package/dist/pools/market-config/to-listing-market-config.d.ts.map +1 -1
- package/dist/pools/market-config/to-listing-market-config.js +1 -0
- package/dist/pools/market-config/to-listing-market-config.js.map +1 -1
- package/dist/pools/market-config/types.d.ts +5 -0
- package/dist/pools/market-config/types.d.ts.map +1 -1
- package/dist/pools/market-config/types.js.map +1 -1
- package/dist/pools/market-data/get-pool-market-data.d.ts +14 -0
- package/dist/pools/market-data/get-pool-market-data.d.ts.map +1 -0
- package/dist/pools/market-data/get-pool-market-data.js +25 -0
- package/dist/pools/market-data/get-pool-market-data.js.map +1 -0
- package/dist/pools/market-data/index.d.ts +2 -0
- package/dist/pools/market-data/index.d.ts.map +1 -0
- package/dist/pools/market-detail/to-listing-market-detail.d.ts +5 -1
- package/dist/pools/market-detail/to-listing-market-detail.d.ts.map +1 -1
- package/dist/pools/market-detail/to-listing-market-detail.js +45 -33
- package/dist/pools/market-detail/to-listing-market-detail.js.map +1 -1
- package/dist/pools/markets/to-listing-market.d.ts +13 -1
- package/dist/pools/markets/to-listing-market.d.ts.map +1 -1
- package/dist/pools/markets/to-listing-market.js +24 -12
- package/dist/pools/markets/to-listing-market.js.map +1 -1
- package/dist/pools/open-positions/calculate-pool-open-positions.d.ts +39 -0
- package/dist/pools/open-positions/calculate-pool-open-positions.d.ts.map +1 -0
- package/dist/pools/open-positions/calculate-pool-open-positions.js +83 -0
- package/dist/pools/open-positions/calculate-pool-open-positions.js.map +1 -0
- package/dist/pools/open-positions/get-pool-open-positions.d.ts +17 -0
- package/dist/pools/open-positions/get-pool-open-positions.d.ts.map +1 -0
- package/dist/pools/open-positions/get-pool-open-positions.js +39 -0
- package/dist/pools/open-positions/get-pool-open-positions.js.map +1 -0
- package/dist/pools/open-positions/index.d.ts +4 -0
- package/dist/pools/open-positions/index.d.ts.map +1 -0
- package/dist/pools/open-positions/query.d.ts +17 -0
- package/dist/pools/open-positions/query.d.ts.map +1 -0
- package/dist/pools/open-positions/query.js +21 -0
- package/dist/pools/open-positions/query.js.map +1 -0
- package/dist/pools/portfolio/calculate-pool-portfolio.d.ts +66 -0
- package/dist/pools/portfolio/calculate-pool-portfolio.d.ts.map +1 -0
- package/dist/pools/portfolio/calculate-pool-portfolio.js +96 -0
- package/dist/pools/portfolio/calculate-pool-portfolio.js.map +1 -0
- package/dist/pools/portfolio/get-pool-portfolio.d.ts +19 -0
- package/dist/pools/portfolio/get-pool-portfolio.d.ts.map +1 -0
- package/dist/pools/portfolio/get-pool-portfolio.js +88 -0
- package/dist/pools/portfolio/get-pool-portfolio.js.map +1 -0
- package/dist/pools/portfolio/index.d.ts +4 -0
- package/dist/pools/portfolio/index.d.ts.map +1 -0
- package/dist/pools/portfolio/query.d.ts +17 -0
- package/dist/pools/portfolio/query.d.ts.map +1 -0
- package/dist/pools/portfolio/query.js +21 -0
- package/dist/pools/portfolio/query.js.map +1 -0
- package/dist/pools/portfolio/read-positions.d.ts +4 -0
- package/dist/pools/portfolio/read-positions.d.ts.map +1 -0
- package/dist/pools/portfolio/read-positions.js +31 -0
- package/dist/pools/portfolio/read-positions.js.map +1 -0
- package/dist/pools/position/calculate-pool-position.d.ts +85 -0
- package/dist/pools/position/calculate-pool-position.d.ts.map +1 -0
- package/dist/pools/position/calculate-pool-position.js +59 -0
- package/dist/pools/position/calculate-pool-position.js.map +1 -0
- package/dist/pools/position/get-pool-position.d.ts +22 -0
- package/dist/pools/position/get-pool-position.d.ts.map +1 -0
- package/dist/pools/position/get-pool-position.js +47 -0
- package/dist/pools/position/get-pool-position.js.map +1 -0
- package/dist/pools/position/index.d.ts +4 -0
- package/dist/pools/position/index.d.ts.map +1 -0
- package/dist/pools/position/query.d.ts +17 -0
- package/dist/pools/position/query.d.ts.map +1 -0
- package/dist/pools/position/query.js +21 -0
- package/dist/pools/position/query.js.map +1 -0
- package/dist/pools/position/sum-deposits.d.ts +10 -0
- package/dist/pools/position/sum-deposits.d.ts.map +1 -0
- package/dist/pools/position/sum-deposits.js +35 -0
- package/dist/pools/position/sum-deposits.js.map +1 -0
- package/dist/pools/profit/get-user-profit.d.ts +4 -0
- package/dist/pools/profit/get-user-profit.d.ts.map +1 -1
- package/dist/pools/profit/get-user-profit.js +18 -12
- package/dist/pools/profit/get-user-profit.js.map +1 -1
- package/dist/pools/profit/to-user-pool-profit.d.ts +22 -4
- package/dist/pools/profit/to-user-pool-profit.d.ts.map +1 -1
- package/dist/pools/profit/to-user-pool-profit.js +28 -12
- package/dist/pools/profit/to-user-pool-profit.js.map +1 -1
- package/dist/pools/quotes/get-pool-quotes.d.ts +8 -1
- package/dist/pools/quotes/get-pool-quotes.d.ts.map +1 -1
- package/dist/pools/quotes/get-pool-quotes.js +8 -1
- package/dist/pools/quotes/get-pool-quotes.js.map +1 -1
- package/dist/pools/quotes/query-document.d.ts.map +1 -1
- package/dist/pools/quotes/query-document.js +1 -1
- package/dist/pools/quotes/query-document.js.map +1 -1
- package/dist/pools/quotes/to-pool-quote.d.ts.map +1 -1
- package/dist/pools/quotes/to-pool-quote.js +13 -0
- package/dist/pools/quotes/to-pool-quote.js.map +1 -1
- package/dist/pools/rewards/query.js +25 -25
- package/dist/pools/statistics/calculate-pool-statistics.d.ts +69 -0
- package/dist/pools/statistics/calculate-pool-statistics.d.ts.map +1 -0
- package/dist/pools/statistics/calculate-pool-statistics.js +42 -0
- package/dist/pools/statistics/calculate-pool-statistics.js.map +1 -0
- package/dist/pools/statistics/get-pool-statistics.d.ts +29 -0
- package/dist/pools/statistics/get-pool-statistics.d.ts.map +1 -0
- package/dist/pools/statistics/get-pool-statistics.js +61 -0
- package/dist/pools/statistics/get-pool-statistics.js.map +1 -0
- package/dist/pools/statistics/index.d.ts +4 -0
- package/dist/pools/statistics/index.d.ts.map +1 -0
- package/dist/pools/statistics/query.d.ts +17 -0
- package/dist/pools/statistics/query.d.ts.map +1 -0
- package/dist/pools/statistics/query.js +21 -0
- package/dist/pools/statistics/query.js.map +1 -0
- package/dist/pools/token-metadata/get-listing-token-metadata.d.ts +32 -0
- package/dist/pools/token-metadata/get-listing-token-metadata.d.ts.map +1 -0
- package/dist/pools/token-metadata/get-listing-token-metadata.js +43 -0
- package/dist/pools/token-metadata/get-listing-token-metadata.js.map +1 -0
- package/dist/pools/token-metadata/index.d.ts +3 -0
- package/dist/pools/token-metadata/index.d.ts.map +1 -0
- package/dist/pools/token-metadata/query.d.ts +11 -0
- package/dist/pools/token-metadata/query.d.ts.map +1 -0
- package/dist/pools/token-metadata/query.js +21 -0
- package/dist/pools/token-metadata/query.js.map +1 -0
- package/dist/pools/token-support/check-listing-token-support.d.ts +23 -0
- package/dist/pools/token-support/check-listing-token-support.d.ts.map +1 -0
- package/dist/pools/token-support/check-listing-token-support.js +36 -0
- package/dist/pools/token-support/check-listing-token-support.js.map +1 -0
- package/dist/pools/token-support/index.d.ts +3 -0
- package/dist/pools/token-support/index.d.ts.map +1 -0
- package/dist/pools/token-support/query.d.ts +11 -0
- package/dist/pools/token-support/query.d.ts.map +1 -0
- package/dist/pools/token-support/query.js +21 -0
- package/dist/pools/token-support/query.js.map +1 -0
- package/dist/pools/trade-history/calculate-history-metrics.d.ts +12 -0
- package/dist/pools/trade-history/calculate-history-metrics.d.ts.map +1 -0
- package/dist/pools/trade-history/calculate-history-metrics.js +36 -0
- package/dist/pools/trade-history/calculate-history-metrics.js.map +1 -0
- package/dist/pools/trade-history/get-pool-trade-history.d.ts +21 -1
- package/dist/pools/trade-history/get-pool-trade-history.d.ts.map +1 -1
- package/dist/pools/trade-history/get-pool-trade-history.js +57 -18
- package/dist/pools/trade-history/get-pool-trade-history.js.map +1 -1
- package/dist/pools/trade-history/query-document.d.ts.map +1 -1
- package/dist/pools/trade-history/query-document.js +1 -1
- package/dist/pools/trade-history/query-document.js.map +1 -1
- package/dist/pools/transactions/get-pool-transaction-range.d.ts +6 -0
- package/dist/pools/transactions/get-pool-transaction-range.d.ts.map +1 -0
- package/dist/pools/transactions/get-pool-transaction-range.js +26 -0
- package/dist/pools/transactions/get-pool-transaction-range.js.map +1 -0
- package/dist/pools/transactions/index.d.ts +1 -0
- package/dist/pools/transactions/index.d.ts.map +1 -1
- package/dist/pools/types/generated/listing-backend.js +34 -10
- package/dist/pools/types/generated/listing-backend.js.map +1 -1
- package/dist/pools/types.d.ts +129 -6
- package/dist/pools/types.d.ts.map +1 -1
- package/dist/pools/types.js.map +1 -1
- package/dist/pools/user-markets/get-user-listing-markets.d.ts +2 -0
- package/dist/pools/user-markets/get-user-listing-markets.d.ts.map +1 -1
- package/dist/pools/user-markets/get-user-listing-markets.js.map +1 -1
- package/dist/pools/user-markets/to-user-listing-market.js +1 -1
- package/dist/pools/user-markets/to-user-listing-market.js.map +1 -1
- package/dist/pools/user-transactions/get-user-transactions.d.ts +2 -0
- package/dist/pools/user-transactions/get-user-transactions.d.ts.map +1 -1
- package/dist/pools/user-transactions/get-user-transactions.js.map +1 -1
- package/dist/pools/user-transactions/to-user-transaction.d.ts +5 -1
- package/dist/pools/user-transactions/to-user-transaction.d.ts.map +1 -1
- package/dist/pools/user-transactions/to-user-transaction.js +3 -0
- package/dist/pools/user-transactions/to-user-transaction.js.map +1 -1
- package/dist/quotes/liquidation/calculate-liquidation-price.d.ts +5 -1
- package/dist/quotes/liquidation/calculate-liquidation-price.d.ts.map +1 -1
- package/dist/quotes/liquidation/calculate-liquidation-price.js +1 -1
- package/dist/quotes/liquidation/calculate-liquidation-price.js.map +1 -1
- package/dist/quotes/upnl/calculate-quote-pnl.d.ts.map +1 -1
- package/dist/quotes/upnl/calculate-quote-pnl.js +8 -8
- package/dist/quotes/upnl/calculate-quote-pnl.js.map +1 -1
- package/dist/quotes/upnl/calculate-quote-upnl.d.ts +2 -2
- package/dist/quotes/upnl/calculate-quote-upnl.d.ts.map +1 -1
- package/dist/quotes/upnl/calculate-quote-upnl.js +16 -15
- package/dist/quotes/upnl/calculate-quote-upnl.js.map +1 -1
- package/dist/symmio-subgraph/types/generated/analytics/gql.d.ts +2 -2
- package/dist/symmio-subgraph/types/generated/analytics/gql.d.ts.map +1 -1
- package/dist/symmio-subgraph/types/generated/analytics/gql.js +2 -2
- package/dist/symmio-subgraph/types/generated/analytics/gql.js.map +1 -1
- package/dist/symmio-subgraph/types/generated/analytics/graphql.d.ts +21 -0
- package/dist/symmio-subgraph/types/generated/analytics/graphql.d.ts.map +1 -1
- package/dist/symmio-subgraph/types/generated/analytics/graphql.js +1 -1
- package/dist/symmio-subgraph/types/generated/analytics/graphql.js.map +1 -1
- package/dist/tpsl/assert-tpsl-acceptance.d.ts +3 -0
- package/dist/tpsl/assert-tpsl-acceptance.d.ts.map +1 -0
- package/dist/tpsl/assert-tpsl-acceptance.js +14 -0
- package/dist/tpsl/assert-tpsl-acceptance.js.map +1 -0
- package/dist/tpsl/delete-quote-tpsl/delete-quote-tpsl.d.ts +4 -3
- package/dist/tpsl/delete-quote-tpsl/delete-quote-tpsl.d.ts.map +1 -1
- package/dist/tpsl/delete-quote-tpsl/delete-quote-tpsl.js +9 -11
- package/dist/tpsl/delete-quote-tpsl/delete-quote-tpsl.js.map +1 -1
- package/dist/tpsl/delete-quote-tpsl/query.d.ts +4 -0
- package/dist/tpsl/delete-quote-tpsl/query.d.ts.map +1 -1
- package/dist/tpsl/delete-quote-tpsl/query.js +1 -0
- package/dist/tpsl/delete-quote-tpsl/query.js.map +1 -1
- package/dist/tpsl/search-tpsl-orders/search-tpsl-orders.d.ts.map +1 -1
- package/dist/tpsl/search-tpsl-orders/search-tpsl-orders.js +31 -28
- package/dist/tpsl/search-tpsl-orders/search-tpsl-orders.js.map +1 -1
- package/dist/tpsl/set-quote-tpsl/build-conditional-order-leg.d.ts +1 -1
- package/dist/tpsl/set-quote-tpsl/build-conditional-order-leg.d.ts.map +1 -1
- package/dist/tpsl/set-quote-tpsl/build-conditional-order-leg.js +9 -7
- package/dist/tpsl/set-quote-tpsl/build-conditional-order-leg.js.map +1 -1
- package/dist/tpsl/set-quote-tpsl/query.d.ts +4 -0
- package/dist/tpsl/set-quote-tpsl/query.d.ts.map +1 -1
- package/dist/tpsl/set-quote-tpsl/query.js +1 -0
- package/dist/tpsl/set-quote-tpsl/query.js.map +1 -1
- package/dist/tpsl/set-quote-tpsl/set-quote-tpsl.d.ts +3 -3
- package/dist/tpsl/set-quote-tpsl/set-quote-tpsl.d.ts.map +1 -1
- package/dist/tpsl/set-quote-tpsl/set-quote-tpsl.js +42 -40
- package/dist/tpsl/set-quote-tpsl/set-quote-tpsl.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,19 +1,35 @@
|
|
|
1
|
-
import { parseListingValue as e,
|
|
1
|
+
import { parseListingValue as e, toListingPercent as t, toListingValue as n } from "../markets/to-listing-market.js";
|
|
2
2
|
//#region src/pools/profit/to-user-pool-profit.ts
|
|
3
|
-
function
|
|
4
|
-
let
|
|
3
|
+
function r(r) {
|
|
4
|
+
let i = n(r.user_lp_amount) ?? 0n, a = n(r.pending_withdraw_lp_amount) ?? 0n;
|
|
5
5
|
return {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
tvl: n(r.tvl),
|
|
7
|
+
apy30d: t(r.apy_30d),
|
|
8
|
+
longPositionAmount: n(r.long_position_amount),
|
|
9
|
+
longPositionValue: n(r.long_position_value),
|
|
10
|
+
longPositionAvgOpenPrice: n(r.long_position_avg_open_price),
|
|
11
|
+
longPositionUpnl: n(r.long_position_upnl),
|
|
12
|
+
shortPositionAmount: n(r.short_position_amount),
|
|
13
|
+
shortPositionValue: n(r.short_position_value),
|
|
14
|
+
shortPositionAvgOpenPrice: n(r.short_position_avg_open_price),
|
|
15
|
+
shortPositionUpnl: n(r.short_position_upnl),
|
|
16
|
+
apyLifetime: t(r.apy_lifetime ?? r.apy_all_time),
|
|
17
|
+
buybackRatio: r.buyback_ratio == null ? null : Number(r.buyback_ratio),
|
|
18
|
+
activeLps: r.active_lps ?? null,
|
|
19
|
+
age: r.age ?? null,
|
|
20
|
+
totalUsdcInPool: n(r.total_usdc_in_pool),
|
|
21
|
+
totalTokenInPool: n(r.total_token_in_pool),
|
|
22
|
+
userBalanceInTokens: n(r.user_balance_in_tokens) ?? 0n,
|
|
23
|
+
userBalanceInUsdc: n(r.user_balance_in_usdc) ?? 0n,
|
|
24
|
+
claimableReward: e(r.claimable_reward) ?? 0n,
|
|
25
|
+
claimedReward: n(r.claimed_reward) ?? 0n,
|
|
26
|
+
userDepositedTokenAmount: n(r.user_deposited_token_amount) ?? 0n,
|
|
27
|
+
userLpAmount: i,
|
|
28
|
+
pendingWithdrawLpAmount: a,
|
|
29
|
+
availableLpAmount: i > a ? i - a : 0n
|
|
14
30
|
};
|
|
15
31
|
}
|
|
16
32
|
//#endregion
|
|
17
|
-
export {
|
|
33
|
+
export { r as toUserPoolProfit };
|
|
18
34
|
|
|
19
35
|
//# sourceMappingURL=to-user-pool-profit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-user-pool-profit.js","names":[],"sources":["../../../src/pools/profit/to-user-pool-profit.ts"],"sourcesContent":["import { parseListingValue, toListingValue } from \"../markets/to-listing-market\";\nimport type { UserPoolProfit } from \"../types\";\nimport type { LPTokenProfitSchema } from \"../types/generated/listing-backend\";\n\n/**\n * Map one raw `LPTokenProfitSchema` from the authed `/v2/profit/{token}` endpoint\n * into the SDK's {@link UserPoolProfit}.\n *\n * Most fields arrive already 1e18-scaled and are read with {@link toListingValue}.\n * The exception is `claimable_reward`, which the service reports in **plain\n * decimal units** (`\"0.0377\"` = `$0.0377`, not `\"37699391270769714\"`) — it is\n * scaled up with {@link parseListingValue} so the SDK still exposes a uniform\n * 18-decimal `bigint`. Running it through `toListingValue` like the others would\n * truncate the value to its integer part (`0n`).\n *\n *
|
|
1
|
+
{"version":3,"file":"to-user-pool-profit.js","names":[],"sources":["../../../src/pools/profit/to-user-pool-profit.ts"],"sourcesContent":["import { parseListingValue, toListingPercent, toListingValue } from \"../markets/to-listing-market\";\nimport type { UserPoolProfit } from \"../types\";\nimport type { LPTokenProfitSchema } from \"../types/generated/listing-backend\";\n\n/**\n * Map one raw `LPTokenProfitSchema` from the authed `/v2/profit/{token}` endpoint\n * into the SDK's {@link UserPoolProfit}.\n *\n * Most fields arrive already 1e18-scaled and are read with {@link toListingValue}.\n * The exception is `claimable_reward`, which the service reports in **plain\n * decimal units** (`\"0.0377\"` = `$0.0377`, not `\"37699391270769714\"`) — it is\n * scaled up with {@link parseListingValue} so the SDK still exposes a uniform\n * 18-decimal `bigint`. Running it through `toListingValue` like the others would\n * truncate the value to its integer part (`0n`).\n *\n * Core position fields retain their existing `0n` defaults. Supplemental market\n * snapshots (TVL, APY, position metrics and totals) retain absence as `null` so\n * callers can distinguish an unknown rollout field from a measured zero.\n *\n * `availableLpAmount` is **derived**, not a wire field: the LP shares free to\n * withdraw are the user's shares minus what is already queued\n * (`userLpAmount − pendingWithdrawLpAmount`), floored at `0n` so a pending amount\n * that meets or exceeds the balance never reads as negative.\n *\n * @param raw - The endpoint's `/v2/profit/{token_contract_address}` response body.\n * @returns The normalized user pool profit.\n */\nexport function toUserPoolProfit(\n raw: LPTokenProfitSchema & {\n tvl?: string | null;\n apy_30d?: string | null;\n long_position_amount?: string | null;\n long_position_value?: string | null;\n long_position_avg_open_price?: string | null;\n long_position_upnl?: string | null;\n short_position_amount?: string | null;\n short_position_value?: string | null;\n short_position_avg_open_price?: string | null;\n short_position_upnl?: string | null;\n apy_lifetime?: string | null;\n apy_all_time?: string | null;\n total_usdc_in_pool?: string | null;\n total_token_in_pool?: string | null;\n buyback_ratio?: string | number | null;\n active_lps?: number | null;\n age?: number | null;\n },\n): UserPoolProfit {\n const userLpAmount = toListingValue(raw.user_lp_amount) ?? 0n;\n const pendingWithdrawLpAmount = toListingValue(raw.pending_withdraw_lp_amount) ?? 0n;\n\n return {\n tvl: toListingValue(raw.tvl),\n apy30d: toListingPercent(raw.apy_30d),\n longPositionAmount: toListingValue(raw.long_position_amount),\n longPositionValue: toListingValue(raw.long_position_value),\n longPositionAvgOpenPrice: toListingValue(raw.long_position_avg_open_price),\n longPositionUpnl: toListingValue(raw.long_position_upnl),\n shortPositionAmount: toListingValue(raw.short_position_amount),\n shortPositionValue: toListingValue(raw.short_position_value),\n shortPositionAvgOpenPrice: toListingValue(raw.short_position_avg_open_price),\n shortPositionUpnl: toListingValue(raw.short_position_upnl),\n apyLifetime: toListingPercent(raw.apy_lifetime ?? raw.apy_all_time),\n buybackRatio: raw.buyback_ratio == null ? null : Number(raw.buyback_ratio),\n activeLps: raw.active_lps ?? null,\n age: raw.age ?? null,\n totalUsdcInPool: toListingValue(raw.total_usdc_in_pool),\n totalTokenInPool: toListingValue(raw.total_token_in_pool),\n userBalanceInTokens: toListingValue(raw.user_balance_in_tokens) ?? 0n,\n userBalanceInUsdc: toListingValue(raw.user_balance_in_usdc) ?? 0n,\n claimableReward: parseListingValue(raw.claimable_reward) ?? 0n,\n claimedReward: toListingValue(raw.claimed_reward) ?? 0n,\n userDepositedTokenAmount: toListingValue(raw.user_deposited_token_amount) ?? 0n,\n userLpAmount,\n pendingWithdrawLpAmount,\n availableLpAmount: userLpAmount > pendingWithdrawLpAmount ? userLpAmount - pendingWithdrawLpAmount : 0n,\n };\n}\n"],"mappings":";;AA2BA,SAAgB,EACd,GAmBgB;CAChB,IAAM,IAAe,EAAe,EAAI,cAAc,KAAK,IACrD,IAA0B,EAAe,EAAI,0BAA0B,KAAK;CAElF,OAAO;EACL,KAAK,EAAe,EAAI,GAAG;EAC3B,QAAQ,EAAiB,EAAI,OAAO;EACpC,oBAAoB,EAAe,EAAI,oBAAoB;EAC3D,mBAAmB,EAAe,EAAI,mBAAmB;EACzD,0BAA0B,EAAe,EAAI,4BAA4B;EACzE,kBAAkB,EAAe,EAAI,kBAAkB;EACvD,qBAAqB,EAAe,EAAI,qBAAqB;EAC7D,oBAAoB,EAAe,EAAI,oBAAoB;EAC3D,2BAA2B,EAAe,EAAI,6BAA6B;EAC3E,mBAAmB,EAAe,EAAI,mBAAmB;EACzD,aAAa,EAAiB,EAAI,gBAAgB,EAAI,YAAY;EAClE,cAAc,EAAI,iBAAiB,OAAO,OAAO,OAAO,EAAI,aAAa;EACzE,WAAW,EAAI,cAAc;EAC7B,KAAK,EAAI,OAAO;EAChB,iBAAiB,EAAe,EAAI,kBAAkB;EACtD,kBAAkB,EAAe,EAAI,mBAAmB;EACxD,qBAAqB,EAAe,EAAI,sBAAsB,KAAK;EACnE,mBAAmB,EAAe,EAAI,oBAAoB,KAAK;EAC/D,iBAAiB,EAAkB,EAAI,gBAAgB,KAAK;EAC5D,eAAe,EAAe,EAAI,cAAc,KAAK;EACrD,0BAA0B,EAAe,EAAI,2BAA2B,KAAK;EAC7E;EACA;EACA,mBAAmB,IAAe,IAA0B,IAAe,IAA0B;CACvG;AACF"}
|
|
@@ -38,7 +38,14 @@ export type GetPoolQuotesParameters = Compute<ChainIdParameter & {
|
|
|
38
38
|
/** Return type of {@link getPoolQuotes}. */
|
|
39
39
|
export interface GetPoolQuotesReturnType {
|
|
40
40
|
/** The pool's quote rows for the requested statuses. */
|
|
41
|
-
quotes:
|
|
41
|
+
quotes: PoolQuoteBookEntry[];
|
|
42
|
+
}
|
|
43
|
+
/** A normalized quote with requested-order metrics, in 18-decimal units; unknown inputs stay null. */
|
|
44
|
+
export interface PoolQuoteBookEntry extends PoolQuote {
|
|
45
|
+
/** Requested price, otherwise opened price; an explicitly reported zero is retained. */
|
|
46
|
+
orderPrice: bigint | null;
|
|
47
|
+
/** Full requested quantity times orderPrice, scaled to 18 decimals. */
|
|
48
|
+
orderNotional: bigint | null;
|
|
42
49
|
}
|
|
43
50
|
/**
|
|
44
51
|
* Read a **pool's** quote book from the analytics subgraph.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-pool-quotes.d.ts","sourceRoot":"","sources":["../../../src/pools/quotes/get-pool-quotes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAO/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAO1C;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,EAAE,SAAS,MAAM,EAAW,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS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;IACd,6DAA6D;IAC7D,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CACjC,CACF,CAAC;AAEF,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACtC,wDAAwD;IACxD,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAED,sGAAsG;AACtG,MAAM,WAAW,kBAAmB,SAAQ,SAAS;IACnD,wFAAwF;IACxF,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,uEAAuE;IACvE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,uBAAuB,GAClC,OAAO,CAAC,uBAAuB,CAAC,CAoClC"}
|
|
@@ -17,7 +17,14 @@ async function s(o, s) {
|
|
|
17
17
|
skip: f,
|
|
18
18
|
orderDirection: p
|
|
19
19
|
}
|
|
20
|
-
})).quotes.map(
|
|
20
|
+
})).quotes.map((e) => {
|
|
21
|
+
let t = r(e), n = t.requestedOpenPrice ?? t.openedPrice;
|
|
22
|
+
return {
|
|
23
|
+
...t,
|
|
24
|
+
orderPrice: n,
|
|
25
|
+
orderNotional: t.quantity == null || n == null ? null : t.quantity * n / 10n ** 18n
|
|
26
|
+
};
|
|
27
|
+
}) };
|
|
21
28
|
}
|
|
22
29
|
//#endregion
|
|
23
30
|
export { o as POOL_OPEN_QUOTE_STATUSES, a as POOL_PENDING_QUOTE_STATUSES, s as getPoolQuotes };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-pool-quotes.js","names":[],"sources":["../../../src/pools/quotes/get-pool-quotes.ts"],"sourcesContent":["import type { Config } from \"../../core/config\";\nimport type { ChainIdParameter, Compute } from \"../../shared/types/properties\";\nimport { querySubgraph } from \"../../symmio-subgraph/query-subgraph\";\nimport type {\n PoolQuotesQuery,\n PoolQuotesQueryVariables,\n} from \"../../symmio-subgraph/types/generated/analytics/graphql\";\nimport { resolvePoolSource } from \"../resolve-pool-source\";\nimport type { PoolQuote } from \"../types\";\nimport { PoolQuotesDocument } from \"./query-document\";\nimport { toPoolQuote } from \"./to-pool-quote\";\n\n/** Page size when the caller does not specify one. */\nconst DEFAULT_PAGE_SIZE = 50;\n\n/**\n * `QuoteStatus` ordinals for a quote that is still pending — sent but not yet\n * opened. Short-lived: a solver accepts within seconds, so this is a \"pending\n * orders\" view, not what a pool's \"open quotes\" tab shows.\n *\n * Kept as raw ordinals because that is what the subgraph stores and filters on.\n */\nexport const POOL_PENDING_QUOTE_STATUSES: readonly number[] = [0, 2];\n\n/**\n * `QuoteStatus` ordinal for a quote that is open on-chain — a live position.\n * These are what a pool's \"open quotes\" tab shows, one row per position.\n */\nexport const POOL_OPEN_QUOTE_STATUSES: readonly number[] = [4];\n\n/**\n * Parameters for {@link getPoolQuotes}.\n */\nexport type GetPoolQuotesParameters = Compute<\n ChainIdParameter & {\n /**\n * The pool's solver market id. A pool with no `symbolId` is not tradable and\n * has no book — the action short-circuits to an empty list.\n */\n symbolId: number | null | undefined;\n /**\n * Raw `QuoteStatus` ordinals to include.\n * @default POOL_PENDING_QUOTE_STATUSES\n */\n quoteStatuses?: readonly number[];\n /** Page size. @default 50 */\n first?: number;\n /** Page offset. @default 0 */\n skip?: number;\n /** Sort direction on the quote timestamp. @default \"desc\" */\n orderDirection?: \"asc\" | \"desc\";\n }\n>;\n\n/** Return type of {@link getPoolQuotes}. */\nexport interface GetPoolQuotesReturnType {\n /** The pool's quote rows for the requested statuses. */\n quotes:
|
|
1
|
+
{"version":3,"file":"get-pool-quotes.js","names":[],"sources":["../../../src/pools/quotes/get-pool-quotes.ts"],"sourcesContent":["import type { Config } from \"../../core/config\";\nimport type { ChainIdParameter, Compute } from \"../../shared/types/properties\";\nimport { querySubgraph } from \"../../symmio-subgraph/query-subgraph\";\nimport type {\n PoolQuotesQuery,\n PoolQuotesQueryVariables,\n} from \"../../symmio-subgraph/types/generated/analytics/graphql\";\nimport { resolvePoolSource } from \"../resolve-pool-source\";\nimport type { PoolQuote } from \"../types\";\nimport { PoolQuotesDocument } from \"./query-document\";\nimport { toPoolQuote } from \"./to-pool-quote\";\n\n/** Page size when the caller does not specify one. */\nconst DEFAULT_PAGE_SIZE = 50;\n\n/**\n * `QuoteStatus` ordinals for a quote that is still pending — sent but not yet\n * opened. Short-lived: a solver accepts within seconds, so this is a \"pending\n * orders\" view, not what a pool's \"open quotes\" tab shows.\n *\n * Kept as raw ordinals because that is what the subgraph stores and filters on.\n */\nexport const POOL_PENDING_QUOTE_STATUSES: readonly number[] = [0, 2];\n\n/**\n * `QuoteStatus` ordinal for a quote that is open on-chain — a live position.\n * These are what a pool's \"open quotes\" tab shows, one row per position.\n */\nexport const POOL_OPEN_QUOTE_STATUSES: readonly number[] = [4];\n\n/**\n * Parameters for {@link getPoolQuotes}.\n */\nexport type GetPoolQuotesParameters = Compute<\n ChainIdParameter & {\n /**\n * The pool's solver market id. A pool with no `symbolId` is not tradable and\n * has no book — the action short-circuits to an empty list.\n */\n symbolId: number | null | undefined;\n /**\n * Raw `QuoteStatus` ordinals to include.\n * @default POOL_PENDING_QUOTE_STATUSES\n */\n quoteStatuses?: readonly number[];\n /** Page size. @default 50 */\n first?: number;\n /** Page offset. @default 0 */\n skip?: number;\n /** Sort direction on the quote timestamp. @default \"desc\" */\n orderDirection?: \"asc\" | \"desc\";\n }\n>;\n\n/** Return type of {@link getPoolQuotes}. */\nexport interface GetPoolQuotesReturnType {\n /** The pool's quote rows for the requested statuses. */\n quotes: PoolQuoteBookEntry[];\n}\n\n/** A normalized quote with requested-order metrics, in 18-decimal units; unknown inputs stay null. */\nexport interface PoolQuoteBookEntry extends PoolQuote {\n /** Requested price, otherwise opened price; an explicitly reported zero is retained. */\n orderPrice: bigint | null;\n /** Full requested quantity times orderPrice, scaled to 18 decimals. */\n orderNotional: bigint | null;\n}\n\n/**\n * Read a **pool's** quote book from the analytics subgraph.\n *\n * Scoped by the pool's market and the SYMMIO diamond its quotes were opened\n * against, with **no account filter** — so this returns every trader's quotes on\n * the pool, which is what a pool page shows. That makes it a different read from\n * the account-scoped `getSubAccountQuotes`, and `partyA` varies row to row.\n *\n * Which rows you get is entirely the `quoteStatuses` filter: pass\n * {@link POOL_OPEN_QUOTE_STATUSES} for the \"open quotes\" tab — every live\n * position on the market, one row each — or {@link POOL_PENDING_QUOTE_STATUSES}\n * (the default) for quotes sent but not yet accepted. Pending quotes are\n * short-lived, so that default usually yields a small or empty list.\n *\n * @param config - The SDK config.\n * @param parameters - The pool's `symbolId`, status filter, paging and sort.\n * @returns The quote rows; empty when `symbolId` is absent.\n * @throws {SymmError} when the chain is unsupported or has no analytics subgraph.\n * @throws {SymmApiError} when the subgraph request fails.\n *\n * @example\n * ```ts\n * const { quotes } = await getPoolQuotes(config, {\n * symbolId: 1,\n * quoteStatuses: POOL_OPEN_QUOTE_STATUSES,\n * });\n * ```\n */\nexport async function getPoolQuotes(\n config: Config,\n parameters: GetPoolQuotesParameters,\n): Promise<GetPoolQuotesReturnType> {\n const {\n chainId,\n symbolId,\n quoteStatuses = POOL_PENDING_QUOTE_STATUSES,\n first = DEFAULT_PAGE_SIZE,\n skip = 0,\n orderDirection = \"desc\",\n } = parameters;\n\n if (symbolId === null || symbolId === undefined) return { quotes: [] };\n\n const data = await querySubgraph<PoolQuotesQuery, PoolQuotesQueryVariables>(config, {\n chainId,\n document: PoolQuotesDocument,\n variables: {\n symbolId: String(symbolId),\n source: resolvePoolSource(config, chainId),\n quoteStatuses: [...quoteStatuses],\n first,\n skip,\n orderDirection,\n },\n });\n\n return {\n quotes: data.quotes.map((row) => {\n const quote = toPoolQuote(row);\n const orderPrice = quote.requestedOpenPrice ?? quote.openedPrice;\n return {\n ...quote,\n orderPrice,\n orderNotional: quote.quantity == null || orderPrice == null ? null : (quote.quantity * orderPrice) / 10n ** 18n,\n };\n }),\n };\n}\n"],"mappings":";;;;;AAaA,IAAM,IAAoB,IASb,IAAiD,CAAC,GAAG,CAAC,GAMtD,IAA8C,CAAC,CAAC;AAoE7D,eAAsB,EACpB,GACA,GACkC;CAClC,IAAM,EACJ,YACA,aACA,mBAAgB,GAChB,WAAQ,GACR,UAAO,GACP,oBAAiB,WACf;CAiBJ,OAfI,KAAa,OAAuC,EAAE,QAAQ,CAAC,EAAE,IAe9D,EACL,SAAQ,MAdS,EAAyD,GAAQ;EAClF;EACA,UAAU;EACV,WAAW;GACT,UAAU,OAAO,CAAQ;GACzB,QAAQ,EAAkB,GAAQ,CAAO;GACzC,eAAe,CAAC,GAAG,CAAa;GAChC;GACA;GACA;EACF;CACF,CAAC,GAGc,OAAO,KAAK,MAAQ;EAC/B,IAAM,IAAQ,EAAY,CAAG,GACvB,IAAa,EAAM,sBAAsB,EAAM;EACrD,OAAO;GACL,GAAG;GACH;GACA,eAAe,EAAM,YAAY,QAAQ,KAAc,OAAO,OAAQ,EAAM,WAAW,IAAc,OAAO;EAC9G;CACF,CAAC,EACH;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-document.d.ts","sourceRoot":"","sources":["../../../src/pools/quotes/query-document.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB;;;;;;;
|
|
1
|
+
{"version":3,"file":"query-document.d.ts","sourceRoot":"","sources":["../../../src/pools/quotes/query-document.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB;;;;;;;EAuD7B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { graphql as e } from "../../symmio-subgraph/types/generated/analytics/gql.js";
|
|
2
2
|
//#region src/pools/quotes/query-document.ts
|
|
3
|
-
var t = e("\n query PoolQuotes(\n $symbolId: BigInt!\n $source: Bytes!\n $quoteStatuses: [Int!]!\n $first: Int!\n $skip: Int!\n $orderDirection: OrderDirection!\n ) {\n quotes(\n first: $first\n skip: $skip\n orderBy: timestamp\n orderDirection: $orderDirection\n where: { symbolId: $symbolId, source: $source, quoteStatus_in: $quoteStatuses }\n ) {\n id\n quoteId\n quoteStatus\n positionType\n orderTypeOpen\n symbol\n symbolId\n partyA\n partyB\n quantity\n closedAmount\n quantityToClose\n openedPrice\n requestedOpenPrice\n averageClosedPrice\n closePrice\n initialOpenedPrice\n liquidateAmount\n liquidatePrice\n timestamp\n blockNumber\n }\n }\n");
|
|
3
|
+
var t = e("\n query PoolQuotes(\n $symbolId: BigInt!\n $source: Bytes!\n $quoteStatuses: [Int!]!\n $first: Int!\n $skip: Int!\n $orderDirection: OrderDirection!\n ) {\n quotes(\n first: $first\n skip: $skip\n orderBy: timestamp\n orderDirection: $orderDirection\n where: { symbolId: $symbolId, source: $source, quoteStatus_in: $quoteStatuses }\n ) {\n id\n quoteId\n quoteStatus\n positionType\n orderTypeOpen\n symbol\n symbolId\n partyA\n partyB\n quantity\n closedAmount\n quantityToClose\n openedPrice\n requestedOpenPrice\n averageClosedPrice\n closePrice\n initialOpenedPrice\n liquidateAmount\n liquidatePrice\n timestamp\n blockNumber\n timestampSendQuote\n timestampOpenPosition\n subAccount {\n id\n owner\n }\n closedPrice\n marketPrice\n tradingFee\n closeFee\n leverage\n initialCva\n initialPartyAmm\n initialLf\n userPaidFunding\n userReceivedFunding\n }\n }\n");
|
|
4
4
|
//#endregion
|
|
5
5
|
export { t as PoolQuotesDocument };
|
|
6
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-document.js","names":[],"sources":["../../../src/pools/quotes/query-document.ts"],"sourcesContent":["import { graphql } from \"../../symmio-subgraph/types/generated/analytics\";\n\n/**\n * A pool's own quote book, from the analytics subgraph.\n *\n * Scoped by `symbolId` **and** `source` — the SYMMIO diamond the quotes were\n * opened against — and filtered to the caller's `quoteStatus_in` set. There is\n * deliberately **no** `partyA` / `partyB` clause: a pool's book is every\n * trader's quotes on that market, not one account's, which is what makes this a\n * different read from the account-scoped `getQuoteHistory`.\n *\n * The document compiles to a typed query string via graphql-codegen.\n */\nexport const PoolQuotesDocument = graphql(`\n query PoolQuotes(\n $symbolId: BigInt!\n $source: Bytes!\n $quoteStatuses: [Int!]!\n $first: Int!\n $skip: Int!\n $orderDirection: OrderDirection!\n ) {\n quotes(\n first: $first\n skip: $skip\n orderBy: timestamp\n orderDirection: $orderDirection\n where: { symbolId: $symbolId, source: $source, quoteStatus_in: $quoteStatuses }\n ) {\n id\n quoteId\n quoteStatus\n positionType\n orderTypeOpen\n symbol\n symbolId\n partyA\n partyB\n quantity\n closedAmount\n quantityToClose\n openedPrice\n requestedOpenPrice\n averageClosedPrice\n closePrice\n initialOpenedPrice\n liquidateAmount\n liquidatePrice\n timestamp\n blockNumber\n }\n }\n`);\n"],"mappings":";;AAaA,IAAa,IAAqB,EAAQ,
|
|
1
|
+
{"version":3,"file":"query-document.js","names":[],"sources":["../../../src/pools/quotes/query-document.ts"],"sourcesContent":["import { graphql } from \"../../symmio-subgraph/types/generated/analytics\";\n\n/**\n * A pool's own quote book, from the analytics subgraph.\n *\n * Scoped by `symbolId` **and** `source` — the SYMMIO diamond the quotes were\n * opened against — and filtered to the caller's `quoteStatus_in` set. There is\n * deliberately **no** `partyA` / `partyB` clause: a pool's book is every\n * trader's quotes on that market, not one account's, which is what makes this a\n * different read from the account-scoped `getQuoteHistory`.\n *\n * The document compiles to a typed query string via graphql-codegen.\n */\nexport const PoolQuotesDocument = graphql(`\n query PoolQuotes(\n $symbolId: BigInt!\n $source: Bytes!\n $quoteStatuses: [Int!]!\n $first: Int!\n $skip: Int!\n $orderDirection: OrderDirection!\n ) {\n quotes(\n first: $first\n skip: $skip\n orderBy: timestamp\n orderDirection: $orderDirection\n where: { symbolId: $symbolId, source: $source, quoteStatus_in: $quoteStatuses }\n ) {\n id\n quoteId\n quoteStatus\n positionType\n orderTypeOpen\n symbol\n symbolId\n partyA\n partyB\n quantity\n closedAmount\n quantityToClose\n openedPrice\n requestedOpenPrice\n averageClosedPrice\n closePrice\n initialOpenedPrice\n liquidateAmount\n liquidatePrice\n timestamp\n blockNumber\n timestampSendQuote\n timestampOpenPosition\n subAccount {\n id\n owner\n }\n closedPrice\n marketPrice\n tradingFee\n closeFee\n leverage\n initialCva\n initialPartyAmm\n initialLf\n userPaidFunding\n userReceivedFunding\n }\n }\n`);\n"],"mappings":";;AAaA,IAAa,IAAqB,EAAQ,slCAuDzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-pool-quote.d.ts","sourceRoot":"","sources":["../../../src/pools/quotes/to-pool-quote.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yDAAyD,CAAC;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,mEAAmE;AACnE,KAAK,eAAe,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAuBzD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,eAAe,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"to-pool-quote.d.ts","sourceRoot":"","sources":["../../../src/pools/quotes/to-pool-quote.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yDAAyD,CAAC;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,mEAAmE;AACnE,KAAK,eAAe,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAuBzD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,eAAe,GAAG,SAAS,CAuC3D"}
|
|
@@ -14,6 +14,19 @@ function n(n) {
|
|
|
14
14
|
let r = e(n.symbolId);
|
|
15
15
|
return {
|
|
16
16
|
id: n.id,
|
|
17
|
+
timestampSendQuote: n.timestampSendQuote == null ? null : Number(n.timestampSendQuote),
|
|
18
|
+
timestampOpenPosition: n.timestampOpenPosition == null ? null : Number(n.timestampOpenPosition),
|
|
19
|
+
ownerAddress: n.subAccount?.owner ?? null,
|
|
20
|
+
closedPrice: e(n.closedPrice),
|
|
21
|
+
marketPrice: e(n.marketPrice),
|
|
22
|
+
tradingFee: e(n.tradingFee),
|
|
23
|
+
closeFee: e(n.closeFee),
|
|
24
|
+
leverage: e(n.leverage),
|
|
25
|
+
initialCva: e(n.initialCva),
|
|
26
|
+
initialPartyAmm: e(n.initialPartyAmm),
|
|
27
|
+
initialLf: e(n.initialLf),
|
|
28
|
+
userPaidFunding: e(n.userPaidFunding),
|
|
29
|
+
userReceivedFunding: e(n.userReceivedFunding),
|
|
17
30
|
quoteId: t(n.quoteId),
|
|
18
31
|
quoteStatus: n.quoteStatus,
|
|
19
32
|
positionType: n.positionType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-pool-quote.js","names":[],"sources":["../../../src/pools/quotes/to-pool-quote.ts"],"sourcesContent":["import type { PoolQuotesQuery } from \"../../symmio-subgraph/types/generated/analytics/graphql\";\nimport type { PoolQuote } from \"../types\";\n\n/** One raw `quotes` row as the pool-quotes document selects it. */\ntype RawPoolQuoteRow = PoolQuotesQuery[\"quotes\"][number];\n\n/**\n * Parse a subgraph decimal string into a `bigint`, or `null` when absent.\n *\n * The subgraph reports integers as strings, but a malformed or fractional value\n * would make `BigInt()` throw and take down a whole page of rows — so anything\n * unparseable becomes `null` rather than an exception.\n */\nfunction toBigIntOrNull(raw: string | null | undefined): bigint | null {\n if (raw === null || raw === undefined || raw.trim() === \"\") return null;\n try {\n return BigInt(raw);\n } catch {\n return null;\n }\n}\n\n/** Parse a required numeric string, defaulting an unparseable one to `0n`. */\nfunction toBigIntOrZero(raw: string | null | undefined): bigint {\n return toBigIntOrNull(raw) ?? 0n;\n}\n\n/**\n * Map one raw `quotes` row from the analytics subgraph into a {@link PoolQuote}.\n *\n * `symbolId` is narrowed to `number` because it indexes the solver's market\n * registry everywhere downstream; the subgraph reports it as a `BigInt` string.\n *\n * @param row - One row from the pool-quotes document.\n * @returns The normalized quote.\n */\nexport function toPoolQuote(row: RawPoolQuoteRow): PoolQuote {\n const symbolId = toBigIntOrNull(row.symbolId);\n\n return {\n id: row.id,\n quoteId: toBigIntOrZero(row.quoteId),\n quoteStatus: row.quoteStatus,\n positionType: row.positionType,\n orderTypeOpen: row.orderTypeOpen,\n symbol: row.symbol,\n symbolId: symbolId === null ? null : Number(symbolId),\n partyA: row.partyA,\n partyB: row.partyB,\n quantity: toBigIntOrNull(row.quantity),\n closedAmount: toBigIntOrNull(row.closedAmount),\n quantityToClose: toBigIntOrNull(row.quantityToClose),\n openedPrice: toBigIntOrNull(row.openedPrice),\n requestedOpenPrice: toBigIntOrNull(row.requestedOpenPrice),\n averageClosedPrice: toBigIntOrNull(row.averageClosedPrice),\n closePrice: toBigIntOrNull(row.closePrice),\n initialOpenedPrice: toBigIntOrNull(row.initialOpenedPrice),\n liquidateAmount: toBigIntOrNull(row.liquidateAmount),\n liquidatePrice: toBigIntOrNull(row.liquidatePrice),\n timestamp: Number(toBigIntOrZero(row.timestamp)),\n blockNumber: toBigIntOrZero(row.blockNumber),\n };\n}\n"],"mappings":";AAaA,SAAS,EAAe,GAA+C;CACrE,IAAI,KAAQ,QAA6B,EAAI,KAAK,MAAM,IAAI,OAAO;CACnE,IAAI;EACF,OAAO,OAAO,CAAG;CACnB,QAAQ;EACN,OAAO;CACT;AACF;AAGA,SAAS,EAAe,GAAwC;CAC9D,OAAO,EAAe,CAAG,KAAK;AAChC;AAWA,SAAgB,EAAY,GAAiC;CAC3D,IAAM,IAAW,EAAe,EAAI,QAAQ;CAE5C,OAAO;EACL,IAAI,EAAI;EACR,SAAS,EAAe,EAAI,OAAO;EACnC,aAAa,EAAI;EACjB,cAAc,EAAI;EAClB,eAAe,EAAI;EACnB,QAAQ,EAAI;EACZ,UAAU,MAAa,OAAO,OAAO,OAAO,CAAQ;EACpD,QAAQ,EAAI;EACZ,QAAQ,EAAI;EACZ,UAAU,EAAe,EAAI,QAAQ;EACrC,cAAc,EAAe,EAAI,YAAY;EAC7C,iBAAiB,EAAe,EAAI,eAAe;EACnD,aAAa,EAAe,EAAI,WAAW;EAC3C,oBAAoB,EAAe,EAAI,kBAAkB;EACzD,oBAAoB,EAAe,EAAI,kBAAkB;EACzD,YAAY,EAAe,EAAI,UAAU;EACzC,oBAAoB,EAAe,EAAI,kBAAkB;EACzD,iBAAiB,EAAe,EAAI,eAAe;EACnD,gBAAgB,EAAe,EAAI,cAAc;EACjD,WAAW,OAAO,EAAe,EAAI,SAAS,CAAC;EAC/C,aAAa,EAAe,EAAI,WAAW;CAC7C;AACF"}
|
|
1
|
+
{"version":3,"file":"to-pool-quote.js","names":[],"sources":["../../../src/pools/quotes/to-pool-quote.ts"],"sourcesContent":["import type { PoolQuotesQuery } from \"../../symmio-subgraph/types/generated/analytics/graphql\";\nimport type { PoolQuote } from \"../types\";\n\n/** One raw `quotes` row as the pool-quotes document selects it. */\ntype RawPoolQuoteRow = PoolQuotesQuery[\"quotes\"][number];\n\n/**\n * Parse a subgraph decimal string into a `bigint`, or `null` when absent.\n *\n * The subgraph reports integers as strings, but a malformed or fractional value\n * would make `BigInt()` throw and take down a whole page of rows — so anything\n * unparseable becomes `null` rather than an exception.\n */\nfunction toBigIntOrNull(raw: string | null | undefined): bigint | null {\n if (raw === null || raw === undefined || raw.trim() === \"\") return null;\n try {\n return BigInt(raw);\n } catch {\n return null;\n }\n}\n\n/** Parse a required numeric string, defaulting an unparseable one to `0n`. */\nfunction toBigIntOrZero(raw: string | null | undefined): bigint {\n return toBigIntOrNull(raw) ?? 0n;\n}\n\n/**\n * Map one raw `quotes` row from the analytics subgraph into a {@link PoolQuote}.\n *\n * `symbolId` is narrowed to `number` because it indexes the solver's market\n * registry everywhere downstream; the subgraph reports it as a `BigInt` string.\n *\n * @param row - One row from the pool-quotes document.\n * @returns The normalized quote.\n */\nexport function toPoolQuote(row: RawPoolQuoteRow): PoolQuote {\n const symbolId = toBigIntOrNull(row.symbolId);\n\n return {\n id: row.id,\n timestampSendQuote: row.timestampSendQuote == null ? null : Number(row.timestampSendQuote),\n timestampOpenPosition: row.timestampOpenPosition == null ? null : Number(row.timestampOpenPosition),\n ownerAddress: row.subAccount?.owner ?? null,\n closedPrice: toBigIntOrNull(row.closedPrice),\n marketPrice: toBigIntOrNull(row.marketPrice),\n tradingFee: toBigIntOrNull(row.tradingFee),\n closeFee: toBigIntOrNull(row.closeFee),\n leverage: toBigIntOrNull(row.leverage),\n initialCva: toBigIntOrNull(row.initialCva),\n initialPartyAmm: toBigIntOrNull(row.initialPartyAmm),\n initialLf: toBigIntOrNull(row.initialLf),\n userPaidFunding: toBigIntOrNull(row.userPaidFunding),\n userReceivedFunding: toBigIntOrNull(row.userReceivedFunding),\n quoteId: toBigIntOrZero(row.quoteId),\n quoteStatus: row.quoteStatus,\n positionType: row.positionType,\n orderTypeOpen: row.orderTypeOpen,\n symbol: row.symbol,\n symbolId: symbolId === null ? null : Number(symbolId),\n partyA: row.partyA,\n partyB: row.partyB,\n quantity: toBigIntOrNull(row.quantity),\n closedAmount: toBigIntOrNull(row.closedAmount),\n quantityToClose: toBigIntOrNull(row.quantityToClose),\n openedPrice: toBigIntOrNull(row.openedPrice),\n requestedOpenPrice: toBigIntOrNull(row.requestedOpenPrice),\n averageClosedPrice: toBigIntOrNull(row.averageClosedPrice),\n closePrice: toBigIntOrNull(row.closePrice),\n initialOpenedPrice: toBigIntOrNull(row.initialOpenedPrice),\n liquidateAmount: toBigIntOrNull(row.liquidateAmount),\n liquidatePrice: toBigIntOrNull(row.liquidatePrice),\n timestamp: Number(toBigIntOrZero(row.timestamp)),\n blockNumber: toBigIntOrZero(row.blockNumber),\n };\n}\n"],"mappings":";AAaA,SAAS,EAAe,GAA+C;CACrE,IAAI,KAAQ,QAA6B,EAAI,KAAK,MAAM,IAAI,OAAO;CACnE,IAAI;EACF,OAAO,OAAO,CAAG;CACnB,QAAQ;EACN,OAAO;CACT;AACF;AAGA,SAAS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24 @@
|
|
|
1
1
|
import { filterQueryOptions as e } from "../../shared/utils/query.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { getUserTotalReward as t } from "./get-user-total-reward.js";
|
|
3
|
+
import { getPoolRewardChart as n } from "./get-pool-reward-chart.js";
|
|
4
|
+
import { getPoolTotalReward as r } from "./get-pool-total-reward.js";
|
|
5
|
+
import { getUserRewardChart as i } from "./get-user-reward-chart.js";
|
|
6
6
|
//#region src/pools/rewards/query.ts
|
|
7
7
|
function a(t) {
|
|
8
8
|
return ["getPoolRewardChart", e(t)];
|
|
9
9
|
}
|
|
10
|
-
function o(e,
|
|
10
|
+
function o(e, t) {
|
|
11
11
|
return {
|
|
12
|
-
...
|
|
12
|
+
...t.query,
|
|
13
13
|
queryKey: a({
|
|
14
|
-
...
|
|
15
|
-
configKey: e.getChainConfigKey(
|
|
14
|
+
...t,
|
|
15
|
+
configKey: e.getChainConfigKey(t.chainId)
|
|
16
16
|
}),
|
|
17
|
-
enabled:
|
|
18
|
-
queryFn: () =>
|
|
19
|
-
chainId:
|
|
20
|
-
marketAddress:
|
|
21
|
-
marketChainId:
|
|
17
|
+
enabled: t.query?.enabled ?? !0,
|
|
18
|
+
queryFn: () => n(e, {
|
|
19
|
+
chainId: t.chainId,
|
|
20
|
+
marketAddress: t.marketAddress,
|
|
21
|
+
marketChainId: t.marketChainId
|
|
22
22
|
})
|
|
23
23
|
};
|
|
24
24
|
}
|
|
@@ -33,7 +33,7 @@ function c(e, t) {
|
|
|
33
33
|
configKey: e.getChainConfigKey(t.chainId)
|
|
34
34
|
}),
|
|
35
35
|
enabled: t.query?.enabled ?? !0,
|
|
36
|
-
queryFn: () =>
|
|
36
|
+
queryFn: () => r(e, {
|
|
37
37
|
chainId: t.chainId,
|
|
38
38
|
marketAddress: t.marketAddress,
|
|
39
39
|
marketChainId: t.marketChainId,
|
|
@@ -52,7 +52,7 @@ function u(e, t) {
|
|
|
52
52
|
configKey: e.getChainConfigKey(t.chainId)
|
|
53
53
|
}),
|
|
54
54
|
enabled: t.query?.enabled ?? !0,
|
|
55
|
-
queryFn: () =>
|
|
55
|
+
queryFn: () => i(e, {
|
|
56
56
|
chainId: t.chainId,
|
|
57
57
|
accessToken: t.accessToken
|
|
58
58
|
})
|
|
@@ -61,19 +61,19 @@ function u(e, t) {
|
|
|
61
61
|
function d(t) {
|
|
62
62
|
return ["getUserTotalReward", e(t)];
|
|
63
63
|
}
|
|
64
|
-
function f(e,
|
|
64
|
+
function f(e, n) {
|
|
65
65
|
return {
|
|
66
|
-
...
|
|
66
|
+
...n.query,
|
|
67
67
|
queryKey: d({
|
|
68
|
-
...
|
|
69
|
-
configKey: e.getChainConfigKey(
|
|
68
|
+
...n,
|
|
69
|
+
configKey: e.getChainConfigKey(n.chainId)
|
|
70
70
|
}),
|
|
71
|
-
enabled:
|
|
72
|
-
queryFn: () =>
|
|
73
|
-
chainId:
|
|
74
|
-
accessToken:
|
|
75
|
-
userAddress:
|
|
76
|
-
days:
|
|
71
|
+
enabled: n.query?.enabled ?? !0,
|
|
72
|
+
queryFn: () => t(e, {
|
|
73
|
+
chainId: n.chainId,
|
|
74
|
+
accessToken: n.accessToken,
|
|
75
|
+
userAddress: n.userAddress,
|
|
76
|
+
days: n.days
|
|
77
77
|
})
|
|
78
78
|
};
|
|
79
79
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { EnigmaMarketInfo, MarketVolume, RasaMarketInfo } from '../../solvers/market-info/types.js';
|
|
2
|
+
import { EnigmaNotionalCap, RasaNotionalCap } from '../../solvers/notional-cap/types.js';
|
|
3
|
+
import { PoolReadGap } from '../composition.js';
|
|
4
|
+
import { ListingMarket, ListingMarketDetail, PoolRewardPoint, PoolTransaction, UserPoolProfit } from '../types.js';
|
|
5
|
+
/** Normalized inputs to the statistics projection; failed reads stay null. */
|
|
6
|
+
export interface CalculatePoolStatisticsParameters {
|
|
7
|
+
/** Optional existing catalog snapshot; no additional search request is needed. */
|
|
8
|
+
listing?: Partial<ListingMarket> | null;
|
|
9
|
+
detail: Partial<ListingMarketDetail> | null;
|
|
10
|
+
pending: readonly Pick<PoolTransaction, "type" | "status" | "tokenAmount" | "usdcAmount">[] | null;
|
|
11
|
+
rewards: readonly PoolRewardPoint[] | null;
|
|
12
|
+
notionalCap: (Pick<EnigmaNotionalCap, "kind"> & Partial<Omit<EnigmaNotionalCap, "kind">>) | RasaNotionalCap | null;
|
|
13
|
+
marketInfo: (Pick<EnigmaMarketInfo, "kind"> & {
|
|
14
|
+
markets: readonly (Pick<MarketVolume, "symbolId"> & Partial<Omit<MarketVolume, "symbolId">>)[];
|
|
15
|
+
}) | RasaMarketInfo | null;
|
|
16
|
+
scope?: "pool" | "user";
|
|
17
|
+
profit?: UserPoolProfit | null;
|
|
18
|
+
priceUsd?: number;
|
|
19
|
+
/** Explicit LP fraction; null means unknown. Omission derives it from profit/detail. */
|
|
20
|
+
shareFraction?: number | null;
|
|
21
|
+
/** Already aggregated pending queue, in 18-decimal units. Never used for user scope. */
|
|
22
|
+
pendingTotals?: {
|
|
23
|
+
count: number;
|
|
24
|
+
tokenAmount: bigint | null;
|
|
25
|
+
usdcAmount: bigint | null;
|
|
26
|
+
} | null;
|
|
27
|
+
/** Normalized whole-percent rate from an existing pool snapshot. */
|
|
28
|
+
apy30dFallback?: bigint | null;
|
|
29
|
+
buybackRatioFallback?: number | null;
|
|
30
|
+
gaps?: readonly PoolReadGap[];
|
|
31
|
+
}
|
|
32
|
+
/** Project a statistics card from SDK reads without transport or UI assumptions.
|
|
33
|
+
* @param input - Detail, pending withdrawals, rewards, solver sources and optional user stake.
|
|
34
|
+
* @returns Unformatted statistics with null for unavailable values. Token amounts remain bigint.
|
|
35
|
+
*/
|
|
36
|
+
export declare function calculatePoolStatistics(input: CalculatePoolStatisticsParameters): {
|
|
37
|
+
tvl: number | null;
|
|
38
|
+
tokenAmount: bigint | null;
|
|
39
|
+
usdcAmount: bigint | null;
|
|
40
|
+
tokenUsdValue: number | null;
|
|
41
|
+
priceUsd: number | null;
|
|
42
|
+
pendingToken: bigint | null;
|
|
43
|
+
pendingUsdc: bigint | null;
|
|
44
|
+
pendingUsd: number | null;
|
|
45
|
+
pendingCount: number | null;
|
|
46
|
+
totalUsd: number | null;
|
|
47
|
+
tokenAfterPendingUsd: number | null;
|
|
48
|
+
pendingValuationComplete: boolean;
|
|
49
|
+
tokenPercent: number | null;
|
|
50
|
+
tvlAfterPending: number | null;
|
|
51
|
+
tokenAfterPending: bigint | null;
|
|
52
|
+
openInterest: number | null;
|
|
53
|
+
availableLong: number | null;
|
|
54
|
+
availableShort: number | null;
|
|
55
|
+
volume24h: number | null;
|
|
56
|
+
lifetimeVolume: number | null;
|
|
57
|
+
apy30d: number | null;
|
|
58
|
+
apyLifetime: number | null;
|
|
59
|
+
rewards24h: number | null;
|
|
60
|
+
rewards30d: number | null;
|
|
61
|
+
lifetimeRewards: number | null;
|
|
62
|
+
maintenanceTotal: number | null;
|
|
63
|
+
buybackRatio: number | null;
|
|
64
|
+
maxLeverage: number | null;
|
|
65
|
+
gaps: PoolReadGap[];
|
|
66
|
+
};
|
|
67
|
+
/** Flat statistics result, with raw amounts and human-unit USD/percentages. */
|
|
68
|
+
export type PoolStatistics = ReturnType<typeof calculatePoolStatistics>;
|
|
69
|
+
//# sourceMappingURL=calculate-pool-statistics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate-pool-statistics.d.ts","sourceRoot":"","sources":["../../../src/pools/statistics/calculate-pool-statistics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtG,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAC3F,OAAO,EAAS,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,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AChG,oEAAoE;IACpE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,IAAI,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;CAC/B;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0G/E;AACD,+EAA+E;AAC/E,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { units as e } from "../composition.js";
|
|
2
|
+
import { parseUnits as t } from "viem";
|
|
3
|
+
import { toDecimal as n } from "@symmio/utils";
|
|
4
|
+
//#region src/pools/statistics/calculate-pool-statistics.ts
|
|
5
|
+
function r(r) {
|
|
6
|
+
let { detail: i, profit: a } = r, o = r.scope === "user" ? r.shareFraction === void 0 ? a && (a.totalUsdcInPool ?? i?.totalUsdcInPool ?? 0n) > 0n ? a.userBalanceInUsdc * 10n ** 18n / (a.totalUsdcInPool ?? i.totalUsdcInPool) : null : r.shareFraction == null || !Number.isFinite(r.shareFraction) ? null : t(n(Math.min(1, Math.max(0, r.shareFraction))).toFixed(), 18) : 10n ** 18n, s = o == null ? null : o > 10n ** 18n ? 10n ** 18n : o < 0n ? 0n : o, c = (e) => e == null || s == null ? null : e * (s > 10n ** 18n ? 10n ** 18n : s < 0n ? 0n : s) / 10n ** 18n, l = c(i?.reportedTotalTokenInPool), u = c(i?.reportedTotalUsdcInPool), d = e(c(r.listing?.tvl ?? i?.tvl)), f = e(c(i?.tvl)), p = f == null || u == null ? null : Math.max(0, f - e(u)), m = l != null && l > 0n && p != null ? p / e(l) : r.priceUsd != null && Number.isFinite(r.priceUsd) && r.priceUsd >= 0 ? r.priceUsd : null, h = r.scope === "user" || r.pending == null ? null : r.pending.filter((e) => e.type === "withdraw" && e.status === "pending"), g = r.scope === "user" ? null : r.pendingTotals, _ = g ? g.tokenAmount : h == null || h.some((e) => e.tokenAmount == null) ? null : h.reduce((e, t) => e + t.tokenAmount, 0n), v = g ? g.usdcAmount : h == null || h.some((e) => e.usdcAmount == null) ? null : h.reduce((e, t) => e + t.usdcAmount, 0n), y = _ == null || v == null ? null : e(v) + e(_) * (m ?? 0), b = r.rewards?.reduce((e, t) => !e || t.timestamp > e.timestamp ? t : e, null), x = r.marketInfo?.kind === "enigma" ? r.marketInfo.markets.find((e) => e.symbolId === (i?.symbolId ?? r.listing?.symbolId)) : void 0, S = r.notionalCap?.kind === "enigma" && !r.notionalCap.error ? r.notionalCap : null, C = (e) => e == null || s == null ? null : e * Number(s) / 0xde0b6b3a7640000, w = l == null || _ == null ? null : l > _ ? l - _ : 0n, T = p == null || u == null ? null : p + e(u), E = e(r.listing?.openInterest) ?? S?.used, D = i?.legacyLifetimeReward == null || i.legacyLifetimeReward.trim() === "" ? null : Number(i.legacyLifetimeReward);
|
|
7
|
+
return {
|
|
8
|
+
tvl: d,
|
|
9
|
+
tokenAmount: l,
|
|
10
|
+
usdcAmount: u,
|
|
11
|
+
tokenUsdValue: p,
|
|
12
|
+
priceUsd: m,
|
|
13
|
+
pendingToken: _,
|
|
14
|
+
pendingUsdc: v,
|
|
15
|
+
pendingUsd: y,
|
|
16
|
+
pendingCount: g?.count ?? h?.length ?? null,
|
|
17
|
+
totalUsd: T,
|
|
18
|
+
tokenAfterPendingUsd: w == null ? null : e(w) * (m ?? 0),
|
|
19
|
+
pendingValuationComplete: _ != null && v != null && (_ === 0n || m != null),
|
|
20
|
+
tokenPercent: T != null && T > 0 && p != null ? p / T * 100 : null,
|
|
21
|
+
tvlAfterPending: d == null || y == null ? null : Math.max(0, d - y),
|
|
22
|
+
tokenAfterPending: w,
|
|
23
|
+
openInterest: C(E == null ? null : Math.max(E, 0)),
|
|
24
|
+
availableLong: S?.availableToLong == null ? null : Math.max(0, S.availableToLong),
|
|
25
|
+
availableShort: S?.availableToShort == null ? null : Math.max(0, S.availableToShort),
|
|
26
|
+
volume24h: C(x?.tradingVolume) ?? e(c(r.listing?.vol24h)),
|
|
27
|
+
lifetimeVolume: C(x?.lifetimeValue),
|
|
28
|
+
apy30d: e(r.listing?.aprByWindow?.d30 ?? r.listing?.apr ?? r.apy30dFallback ?? r.listing?.apy30d ?? i?.apy?.d30),
|
|
29
|
+
apyLifetime: e(r.listing?.apyLifetime ?? i?.apy?.lifetime),
|
|
30
|
+
rewards24h: e(c(b?.reward ?? i?.rewards?.h24 ?? r.listing?.reward24h)),
|
|
31
|
+
rewards30d: e(c(i?.rewards?.d30 ?? r.listing?.reward30d)),
|
|
32
|
+
lifetimeRewards: e(c(i?.rewards?.lifetime ?? r.listing?.rewardLifetime)) ?? C(D != null && Number.isFinite(D) ? D : null),
|
|
33
|
+
maintenanceTotal: e(c(i?.reportedMaintenanceFees)),
|
|
34
|
+
buybackRatio: i?.buybackRatio ?? r.buybackRatioFallback ?? null,
|
|
35
|
+
maxLeverage: r.listing?.maxLeverage != null && r.listing.maxLeverage > 0 ? r.listing.maxLeverage : i?.maxLeverage ?? null,
|
|
36
|
+
gaps: [...r.gaps ?? []]
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { r as calculatePoolStatistics };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=calculate-pool-statistics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate-pool-statistics.js","names":[],"sources":["../../../src/pools/statistics/calculate-pool-statistics.ts"],"sourcesContent":["import { toDecimal } from \"@symmio/utils\";\nimport { parseUnits } from \"viem\";\nimport type { EnigmaMarketInfo, MarketVolume, RasaMarketInfo } from \"../../solvers/market-info/types\";\nimport type { EnigmaNotionalCap, RasaNotionalCap } from \"../../solvers/notional-cap/types\";\nimport { units, type PoolReadGap } from \"../composition\";\nimport type { ListingMarket, ListingMarketDetail, PoolRewardPoint, PoolTransaction, UserPoolProfit } from \"../types\";\n\n/** Normalized inputs to the statistics projection; failed reads stay null. */\nexport interface CalculatePoolStatisticsParameters {\n /** Optional existing catalog snapshot; no additional search request is needed. */\n listing?: Partial<ListingMarket> | null;\n detail: Partial<ListingMarketDetail> | null;\n pending: readonly Pick<PoolTransaction, \"type\" | \"status\" | \"tokenAmount\" | \"usdcAmount\">[] | null;\n rewards: readonly PoolRewardPoint[] | null;\n notionalCap: (Pick<EnigmaNotionalCap, \"kind\"> & Partial<Omit<EnigmaNotionalCap, \"kind\">>) | RasaNotionalCap | null;\n marketInfo:\n | (Pick<EnigmaMarketInfo, \"kind\"> & {\n markets: readonly (Pick<MarketVolume, \"symbolId\"> & Partial<Omit<MarketVolume, \"symbolId\">>)[];\n })\n | RasaMarketInfo\n | null;\n scope?: \"pool\" | \"user\";\n profit?: UserPoolProfit | null;\n priceUsd?: number;\n /** Explicit LP fraction; null means unknown. Omission derives it from profit/detail. */\n shareFraction?: number | null;\n /** Already aggregated pending queue, in 18-decimal units. Never used for user scope. */\n pendingTotals?: { count: number; tokenAmount: bigint | null; usdcAmount: bigint | null } | null;\n /** Normalized whole-percent rate from an existing pool snapshot. */\n apy30dFallback?: bigint | null;\n buybackRatioFallback?: number | null;\n gaps?: readonly PoolReadGap[];\n}\n\n/** Project a statistics card from SDK reads without transport or UI assumptions.\n * @param input - Detail, pending withdrawals, rewards, solver sources and optional user stake.\n * @returns Unformatted statistics with null for unavailable values. Token amounts remain bigint.\n */\nexport function calculatePoolStatistics(input: CalculatePoolStatisticsParameters) {\n const { detail, profit } = input;\n const rawRatio =\n input.scope !== \"user\"\n ? 10n ** 18n\n : input.shareFraction !== undefined\n ? input.shareFraction == null || !Number.isFinite(input.shareFraction)\n ? null\n : parseUnits(toDecimal(Math.min(1, Math.max(0, input.shareFraction))).toFixed(), 18)\n : profit && (profit.totalUsdcInPool ?? detail?.totalUsdcInPool ?? 0n) > 0n\n ? (profit.userBalanceInUsdc * 10n ** 18n) / (profit.totalUsdcInPool ?? detail!.totalUsdcInPool!)\n : null;\n const ratio = rawRatio == null ? null : rawRatio > 10n ** 18n ? 10n ** 18n : rawRatio < 0n ? 0n : rawRatio;\n const scale = (amount: bigint | null | undefined) =>\n amount == null || ratio == null\n ? null\n : (amount * (ratio > 10n ** 18n ? 10n ** 18n : ratio < 0n ? 0n : ratio)) / 10n ** 18n;\n const tokenAmount = scale(detail?.reportedTotalTokenInPool);\n const usdcAmount = scale(detail?.reportedTotalUsdcInPool);\n const tvl = units(scale(input.listing?.tvl ?? detail?.tvl));\n const balanceTvl = units(scale(detail?.tvl));\n const tokenUsdValue = balanceTvl == null || usdcAmount == null ? null : Math.max(0, balanceTvl - units(usdcAmount)!);\n const priceUsd =\n tokenAmount != null && tokenAmount > 0n && tokenUsdValue != null\n ? tokenUsdValue / units(tokenAmount)!\n : input.priceUsd != null && Number.isFinite(input.priceUsd) && input.priceUsd >= 0\n ? input.priceUsd\n : null;\n const pendingRows =\n input.scope === \"user\" || input.pending == null\n ? null\n : input.pending.filter((row) => row.type === \"withdraw\" && row.status === \"pending\");\n const pendingTotals = input.scope === \"user\" ? null : input.pendingTotals;\n const pendingToken = pendingTotals\n ? pendingTotals.tokenAmount\n : pendingRows == null || pendingRows.some((row) => row.tokenAmount == null)\n ? null\n : pendingRows.reduce((sum, row) => sum + row.tokenAmount!, 0n);\n const pendingUsdc = pendingTotals\n ? pendingTotals.usdcAmount\n : pendingRows == null || pendingRows.some((row) => row.usdcAmount == null)\n ? null\n : pendingRows.reduce((sum, row) => sum + row.usdcAmount!, 0n);\n const pendingUsd =\n pendingToken == null || pendingUsdc == null ? null : units(pendingUsdc)! + units(pendingToken)! * (priceUsd ?? 0);\n const latestReward = input.rewards?.reduce<PoolRewardPoint | null>(\n (latest, row) => (!latest || row.timestamp > latest.timestamp ? row : latest),\n null,\n );\n const volume =\n input.marketInfo?.kind === \"enigma\"\n ? input.marketInfo.markets.find((row) => row.symbolId === (detail?.symbolId ?? input.listing?.symbolId))\n : undefined;\n const cap = input.notionalCap?.kind === \"enigma\" && !input.notionalCap.error ? input.notionalCap : null;\n const scaleNumber = (value: number | null | undefined) =>\n value == null || ratio == null ? null : (value * Number(ratio)) / 1e18;\n const tokenAfterPending =\n tokenAmount == null || pendingToken == null ? null : tokenAmount > pendingToken ? tokenAmount - pendingToken : 0n;\n const totalUsd = tokenUsdValue == null || usdcAmount == null ? null : tokenUsdValue + units(usdcAmount)!;\n const openInterest = units(input.listing?.openInterest) ?? cap?.used;\n const legacyReward =\n detail?.legacyLifetimeReward == null || detail.legacyLifetimeReward.trim() === \"\"\n ? null\n : Number(detail.legacyLifetimeReward);\n return {\n tvl,\n tokenAmount,\n usdcAmount,\n tokenUsdValue,\n priceUsd,\n pendingToken,\n pendingUsdc,\n pendingUsd,\n pendingCount: pendingTotals?.count ?? pendingRows?.length ?? null,\n totalUsd,\n tokenAfterPendingUsd: tokenAfterPending == null ? null : units(tokenAfterPending)! * (priceUsd ?? 0),\n pendingValuationComplete: pendingToken != null && pendingUsdc != null && (pendingToken === 0n || priceUsd != null),\n tokenPercent: totalUsd != null && totalUsd > 0 && tokenUsdValue != null ? (tokenUsdValue / totalUsd) * 100 : null,\n tvlAfterPending: tvl == null || pendingUsd == null ? null : Math.max(0, tvl - pendingUsd),\n tokenAfterPending,\n openInterest: scaleNumber(openInterest == null ? null : Math.max(openInterest, 0)),\n availableLong: cap?.availableToLong == null ? null : Math.max(0, cap.availableToLong),\n availableShort: cap?.availableToShort == null ? null : Math.max(0, cap.availableToShort),\n volume24h: scaleNumber(volume?.tradingVolume) ?? units(scale(input.listing?.vol24h)),\n lifetimeVolume: scaleNumber(volume?.lifetimeValue),\n apy30d: units(\n input.listing?.aprByWindow?.d30 ??\n input.listing?.apr ??\n input.apy30dFallback ??\n input.listing?.apy30d ??\n detail?.apy?.d30,\n ),\n apyLifetime: units(input.listing?.apyLifetime ?? detail?.apy?.lifetime),\n rewards24h: units(scale(latestReward?.reward ?? detail?.rewards?.h24 ?? input.listing?.reward24h)),\n rewards30d: units(scale(detail?.rewards?.d30 ?? input.listing?.reward30d)),\n lifetimeRewards:\n units(scale(detail?.rewards?.lifetime ?? input.listing?.rewardLifetime)) ??\n scaleNumber(legacyReward != null && Number.isFinite(legacyReward) ? legacyReward : null),\n maintenanceTotal: units(scale(detail?.reportedMaintenanceFees)),\n buybackRatio: detail?.buybackRatio ?? input.buybackRatioFallback ?? null,\n maxLeverage:\n input.listing?.maxLeverage != null && input.listing.maxLeverage > 0\n ? input.listing.maxLeverage\n : (detail?.maxLeverage ?? null),\n gaps: [...(input.gaps ?? [])],\n };\n}\n/** Flat statistics result, with raw amounts and human-unit USD/percentages. */\nexport type PoolStatistics = ReturnType<typeof calculatePoolStatistics>;\n"],"mappings":";;;;AAsCA,SAAgB,EAAwB,GAA0C;CAChF,IAAM,EAAE,WAAQ,cAAW,GACrB,IACJ,EAAM,UAAU,SAEZ,EAAM,kBAAkB,KAAA,IAItB,MAAW,EAAO,mBAAmB,GAAQ,mBAAmB,MAAM,KACnE,EAAO,oBAAoB,OAAO,OAAQ,EAAO,mBAAmB,EAAQ,mBAC7E,OALF,EAAM,iBAAiB,QAAQ,CAAC,OAAO,SAAS,EAAM,aAAa,IACjE,OACA,EAAW,EAAU,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,EAAM,aAAa,CAAC,CAAC,EAAE,QAAQ,GAAG,EAAE,IAJrF,OAAO,KAQP,IAAQ,KAAY,OAAO,OAAO,IAAW,OAAO,MAAM,OAAO,MAAM,IAAW,KAAK,KAAK,GAC5F,KAAS,MACb,KAAU,QAAQ,KAAS,OACvB,OACC,KAAU,IAAQ,OAAO,MAAM,OAAO,MAAM,IAAQ,KAAK,KAAK,KAAU,OAAO,KAChF,IAAc,EAAM,GAAQ,wBAAwB,GACpD,IAAa,EAAM,GAAQ,uBAAuB,GAClD,IAAM,EAAM,EAAM,EAAM,SAAS,OAAO,GAAQ,GAAG,CAAC,GACpD,IAAa,EAAM,EAAM,GAAQ,GAAG,CAAC,GACrC,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AAc,CAAC,KACvE,EAAY,KAAgB,QAAQ,OAAO,SAAS,CAAY,IAAI,IAAe,IAAI;EACzF,kBAAkB,EAAM,EAAM,GAAQ,uBAAuB,CAAC;EAC9D,cAAc,GAAQ,gBAAgB,EAAM,wBAAwB;EACpE,aACE,EAAM,SAAS,eAAe,QAAQ,EAAM,QAAQ,cAAc,IAC9D,EAAM,QAAQ,cACb,GAAQ,eAAe;EAC9B,MAAM,CAAC,GAAI,EAAM,QAAQ,CAAC,CAAE;CAC9B;AACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Config } from '../../core/config/index.js';
|
|
2
|
+
import { GetListingMarketDetailParameters } from '../market-detail/get-listing-market-detail.js';
|
|
3
|
+
import { CalculatePoolStatisticsParameters, PoolStatistics } from './calculate-pool-statistics.js';
|
|
4
|
+
/** Statistics identity and optional user scope. User scope requires authentication and a wallet cache scope. */
|
|
5
|
+
export type GetPoolStatisticsParameters = GetListingMarketDetailParameters & {
|
|
6
|
+
priceUsd?: number;
|
|
7
|
+
listing?: CalculatePoolStatisticsParameters["listing"];
|
|
8
|
+
/** Existing ledger fraction and display-snapshot fallbacks; no additional reads. */
|
|
9
|
+
shareFraction?: number | null;
|
|
10
|
+
apy30dFallback?: bigint | null;
|
|
11
|
+
buybackRatioFallback?: number | null;
|
|
12
|
+
} & ({
|
|
13
|
+
scope?: "pool";
|
|
14
|
+
accessToken?: never;
|
|
15
|
+
userAddress?: never;
|
|
16
|
+
} | {
|
|
17
|
+
scope: "user";
|
|
18
|
+
accessToken: string;
|
|
19
|
+
userAddress: string;
|
|
20
|
+
});
|
|
21
|
+
/** Result of getPoolStatistics. */
|
|
22
|
+
export type GetPoolStatisticsReturnType = PoolStatistics;
|
|
23
|
+
/** Read pool or personal statistics using shared listing and solver actions.
|
|
24
|
+
* @param config - SDK configuration.
|
|
25
|
+
* @param parameters - Pool identity and scope, plus an optional external price.
|
|
26
|
+
* @returns Flat statistics and explicit source gaps.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getPoolStatistics(config: Config, parameters: GetPoolStatisticsParameters): Promise<PoolStatistics>;
|
|
29
|
+
//# sourceMappingURL=get-pool-statistics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-pool-statistics.d.ts","sourceRoot":"","sources":["../../../src/pools/statistics/get-pool-statistics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,4CAA4C,CAAC;AAKpD,OAAO,EAEL,KAAK,iCAAiC,EACtC,KAAK,cAAc,EACpB,MAAM,6BAA6B,CAAC;AAErC,gHAAgH;AAChH,MAAM,MAAM,2BAA2B,GAAG,gCAAgC,GAAG;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,iCAAiC,CAAC,SAAS,CAAC,CAAC;IACvD,oFAAoF;IACpF,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC,GAAG,CACE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,KAAK,CAAC;IAAC,WAAW,CAAC,EAAE,KAAK,CAAA;CAAE,GAC5D;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAC9D,CAAC;AACJ,mCAAmC;AACnC,MAAM,MAAM,2BAA2B,GAAG,cAAc,CAAC;AAEzD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,2BAA2B,GACtC,OAAO,CAAC,cAAc,CAAC,CA+DzB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getMarketInfo as e } from "../../solvers/market-info/get-market-info.js";
|
|
2
|
+
import { getNotionalCapBySymbolId as t } from "../../solvers/notional-cap/get-notional-cap-by-symbol-id.js";
|
|
3
|
+
import { PoolTransactionStatus as n, PoolTransactionType as r } from "../types.js";
|
|
4
|
+
import { getListingMarketDetail as i } from "../market-detail/get-listing-market-detail.js";
|
|
5
|
+
import { readOptional as a, readPages as o } from "../composition.js";
|
|
6
|
+
import { getUserProfit as s } from "../profit/get-user-profit.js";
|
|
7
|
+
import { getPoolRewardChart as c } from "../rewards/get-pool-reward-chart.js";
|
|
8
|
+
import { calculatePoolStatistics as l } from "./calculate-pool-statistics.js";
|
|
9
|
+
import { getPoolTransactions as u } from "../transactions/get-pool-transactions.js";
|
|
10
|
+
//#region src/pools/statistics/get-pool-statistics.ts
|
|
11
|
+
async function d(d, f) {
|
|
12
|
+
let p = [], { chainId: m, tokenContractAddress: h, depositChain: g } = f, [_, v, y, b] = await Promise.all([
|
|
13
|
+
a(() => i(d, {
|
|
14
|
+
chainId: m,
|
|
15
|
+
tokenContractAddress: h,
|
|
16
|
+
depositChain: g
|
|
17
|
+
}), p, "detail"),
|
|
18
|
+
f.scope === "user" ? null : a(() => o(async (e) => {
|
|
19
|
+
let t = await u(d, {
|
|
20
|
+
chainId: m,
|
|
21
|
+
tokenAddress: h,
|
|
22
|
+
marketChainId: g,
|
|
23
|
+
transactionType: r.WITHDRAW,
|
|
24
|
+
transactionStatus: n.PENDING,
|
|
25
|
+
start: e,
|
|
26
|
+
size: 50
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
items: t.items,
|
|
30
|
+
total: t.count
|
|
31
|
+
};
|
|
32
|
+
}, (e) => e.transactionId, p, "pending"), p, "pending"),
|
|
33
|
+
a(() => c(d, {
|
|
34
|
+
chainId: m,
|
|
35
|
+
marketAddress: h,
|
|
36
|
+
marketChainId: g
|
|
37
|
+
}), p, "rewards"),
|
|
38
|
+
f.scope === "user" ? a(() => s(d, {
|
|
39
|
+
chainId: m,
|
|
40
|
+
tokenContractAddress: h,
|
|
41
|
+
accessToken: f.accessToken
|
|
42
|
+
}), p, "profit") : null
|
|
43
|
+
]), [x, S] = _?.symbolId == null ? [null, null] : await Promise.all([a(() => t(d, {
|
|
44
|
+
chainId: m,
|
|
45
|
+
symbolId: _.symbolId
|
|
46
|
+
}), p, "notionalCap"), a(() => e(d, { chainId: m }), p, "marketInfo")]);
|
|
47
|
+
return l({
|
|
48
|
+
...f,
|
|
49
|
+
detail: _,
|
|
50
|
+
pending: p.some((e) => e.source === "pending") ? null : v,
|
|
51
|
+
rewards: y,
|
|
52
|
+
profit: b,
|
|
53
|
+
notionalCap: x,
|
|
54
|
+
marketInfo: S,
|
|
55
|
+
gaps: p
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { d as getPoolStatistics };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=get-pool-statistics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-pool-statistics.js","names":[],"sources":["../../../src/pools/statistics/get-pool-statistics.ts"],"sourcesContent":["import type { Config } from \"../../core/config\";\nimport { getMarketInfo } from \"../../solvers/market-info/get-market-info\";\nimport { getNotionalCapBySymbolId } from \"../../solvers/notional-cap/get-notional-cap-by-symbol-id\";\nimport { readOptional, readPages, type PoolReadGap } from \"../composition\";\nimport {\n getListingMarketDetail,\n type GetListingMarketDetailParameters,\n} from \"../market-detail/get-listing-market-detail\";\nimport { getUserProfit } from \"../profit/get-user-profit\";\nimport { getPoolRewardChart } from \"../rewards/get-pool-reward-chart\";\nimport { getPoolTransactions } from \"../transactions/get-pool-transactions\";\nimport { PoolTransactionStatus, PoolTransactionType } from \"../types\";\nimport {\n calculatePoolStatistics,\n type CalculatePoolStatisticsParameters,\n type PoolStatistics,\n} from \"./calculate-pool-statistics\";\n\n/** Statistics identity and optional user scope. User scope requires authentication and a wallet cache scope. */\nexport type GetPoolStatisticsParameters = GetListingMarketDetailParameters & {\n priceUsd?: number;\n listing?: CalculatePoolStatisticsParameters[\"listing\"];\n /** Existing ledger fraction and display-snapshot fallbacks; no additional reads. */\n shareFraction?: number | null;\n apy30dFallback?: bigint | null;\n buybackRatioFallback?: number | null;\n} & (\n | { scope?: \"pool\"; accessToken?: never; userAddress?: never }\n | { scope: \"user\"; accessToken: string; userAddress: string }\n );\n/** Result of getPoolStatistics. */\nexport type GetPoolStatisticsReturnType = PoolStatistics;\n\n/** Read pool or personal statistics using shared listing and solver actions.\n * @param config - SDK configuration.\n * @param parameters - Pool identity and scope, plus an optional external price.\n * @returns Flat statistics and explicit source gaps.\n */\nexport async function getPoolStatistics(\n config: Config,\n parameters: GetPoolStatisticsParameters,\n): Promise<PoolStatistics> {\n const gaps: PoolReadGap[] = [];\n const { chainId, tokenContractAddress, depositChain } = parameters;\n const [detail, pending, rewards, profit] = await Promise.all([\n readOptional(() => getListingMarketDetail(config, { chainId, tokenContractAddress, depositChain }), gaps, \"detail\"),\n parameters.scope === \"user\"\n ? null\n : readOptional(\n () =>\n readPages(\n async (start) => {\n const page = await getPoolTransactions(config, {\n chainId,\n tokenAddress: tokenContractAddress,\n marketChainId: depositChain,\n transactionType: PoolTransactionType.WITHDRAW,\n transactionStatus: PoolTransactionStatus.PENDING,\n start,\n size: 50,\n });\n return { items: page.items, total: page.count };\n },\n (row) => row.transactionId,\n gaps,\n \"pending\",\n ),\n gaps,\n \"pending\",\n ),\n readOptional(\n () => getPoolRewardChart(config, { chainId, marketAddress: tokenContractAddress, marketChainId: depositChain }),\n gaps,\n \"rewards\",\n ),\n parameters.scope === \"user\"\n ? readOptional(\n () => getUserProfit(config, { chainId, tokenContractAddress, accessToken: parameters.accessToken }),\n gaps,\n \"profit\",\n )\n : null,\n ]);\n const [notionalCap, marketInfo] =\n detail?.symbolId == null\n ? [null, null]\n : await Promise.all([\n readOptional(\n () => getNotionalCapBySymbolId(config, { chainId, symbolId: detail.symbolId! }),\n gaps,\n \"notionalCap\",\n ),\n readOptional(() => getMarketInfo(config, { chainId }), gaps, \"marketInfo\"),\n ]);\n return calculatePoolStatistics({\n ...parameters,\n detail,\n pending: gaps.some((gap) => gap.source === \"pending\") ? null : pending,\n rewards,\n profit,\n notionalCap,\n marketInfo,\n gaps,\n });\n}\n"],"mappings":";;;;;;;;;;AAsCA,eAAsB,EACpB,GACA,GACyB;CACzB,IAAM,IAAsB,CAAC,GACvB,EAAE,YAAS,yBAAsB,oBAAiB,GAClD,CAAC,GAAQ,GAAS,GAAS,KAAU,MAAM,QAAQ,IAAI;EAC3D,QAAmB,EAAuB,GAAQ;GAAE;GAAS;GAAsB;EAAa,CAAC,GAAG,GAAM,QAAQ;EAClH,EAAW,UAAU,SACjB,OACA,QAEI,EACE,OAAO,MAAU;GACf,IAAM,IAAO,MAAM,EAAoB,GAAQ;IAC7C;IACA,cAAc;IACd,eAAe;IACf,iBAAiB,EAAoB;IACrC,mBAAmB,EAAsB;IACzC;IACA,MAAM;GACR,CAAC;GACD,OAAO;IAAE,OAAO,EAAK;IAAO,OAAO,EAAK;GAAM;EAChD,IACC,MAAQ,EAAI,eACb,GACA,SACF,GACF,GACA,SACF;EACJ,QACQ,EAAmB,GAAQ;GAAE;GAAS,eAAe;GAAsB,eAAe;EAAa,CAAC,GAC9G,GACA,SACF;EACA,EAAW,UAAU,SACjB,QACQ,EAAc,GAAQ;GAAE;GAAS;GAAsB,aAAa,EAAW;EAAY,CAAC,GAClG,GACA,QACF,IACA;CACN,CAAC,GACK,CAAC,GAAa,KAClB,GAAQ,YAAY,OAChB,CAAC,MAAM,IAAI,IACX,MAAM,QAAQ,IAAI,CAChB,QACQ,EAAyB,GAAQ;EAAE;EAAS,UAAU,EAAO;CAAU,CAAC,GAC9E,GACA,aACF,GACA,QAAmB,EAAc,GAAQ,EAAE,WAAQ,CAAC,GAAG,GAAM,YAAY,CAC3E,CAAC;CACP,OAAO,EAAwB;EAC7B,GAAG;EACH;EACA,SAAS,EAAK,MAAM,MAAQ,EAAI,WAAW,SAAS,IAAI,OAAO;EAC/D;EACA;EACA;EACA;EACA;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pools/statistics/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Config } from '../../core/config/index.js';
|
|
2
|
+
import { Compute, ConfigKeyParameter } from '../../shared/types/properties.js';
|
|
3
|
+
import { QueryParameter, SymmioQueryOptions } from '../../shared/types/query.js';
|
|
4
|
+
import { GetPoolStatisticsParameters, GetPoolStatisticsReturnType } from './get-pool-statistics.js';
|
|
5
|
+
/** Stable key for the composed core read. Credentials are excluded. */
|
|
6
|
+
export declare function getPoolStatisticsQueryKey(options: Compute<GetPoolStatisticsParameters & ConfigKeyParameter>): readonly ["getPoolStatistics", Record<string, unknown>];
|
|
7
|
+
/** Composed query key type. */
|
|
8
|
+
export type GetPoolStatisticsQueryKey = ReturnType<typeof getPoolStatisticsQueryKey>;
|
|
9
|
+
/** Query controls plus all required read inputs. */
|
|
10
|
+
export type GetPoolStatisticsOptions = GetPoolStatisticsParameters & QueryParameter<GetPoolStatisticsReturnType, Error, GetPoolStatisticsReturnType, GetPoolStatisticsQueryKey>;
|
|
11
|
+
/** Build options for non-React consumers; React composition uses the underlying primitive queries instead.
|
|
12
|
+
* @param config - SDK configuration.
|
|
13
|
+
* @param options - Required read inputs and optional query controls.
|
|
14
|
+
* @returns Typed query options with a credential-free key.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getPoolStatisticsQueryOptions(config: Config, options: GetPoolStatisticsOptions): SymmioQueryOptions<GetPoolStatisticsReturnType, Error, GetPoolStatisticsReturnType, GetPoolStatisticsQueryKey>;
|
|
17
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/pools/statistics/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnF,OAAO,EAEL,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EACjC,MAAM,uBAAuB,CAAC;AAC/B,uEAAuE;AACvE,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,2BAA2B,GAAG,kBAAkB,CAAC,2DAE3G;AACD,+BAA+B;AAC/B,MAAM,MAAM,yBAAyB,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;AACrF,oDAAoD;AACpD,MAAM,MAAM,wBAAwB,GAAG,2BAA2B,GAChE,cAAc,CAAC,2BAA2B,EAAE,KAAK,EAAE,2BAA2B,EAAE,yBAAyB,CAAC,CAAC;AAC7G;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wBAAwB,GAChC,kBAAkB,CAAC,2BAA2B,EAAE,KAAK,EAAE,2BAA2B,EAAE,yBAAyB,CAAC,CAShH"}
|