@symmio/trading-react 3.0.0 → 3.1.0
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/account-layer/use-account-balance-of.d.ts +5 -4
- package/dist/account-layer/use-account-balance-of.d.ts.map +1 -1
- package/dist/account-layer/use-account-balance-of.js.map +1 -1
- package/dist/account-layer/use-add-margin.d.ts.map +1 -1
- package/dist/account-layer/use-add-margin.js +1 -3
- package/dist/account-layer/use-add-margin.js.map +1 -1
- package/dist/account-layer/use-allocate.d.ts.map +1 -1
- package/dist/account-layer/use-allocate.js +1 -3
- package/dist/account-layer/use-allocate.js.map +1 -1
- package/dist/account-layer/use-cancel-registration.d.ts.map +1 -1
- package/dist/account-layer/use-cancel-registration.js +1 -2
- package/dist/account-layer/use-cancel-registration.js.map +1 -1
- package/dist/account-layer/use-create-sub-accounts.d.ts.map +1 -1
- package/dist/account-layer/use-create-sub-accounts.js +1 -3
- package/dist/account-layer/use-create-sub-accounts.js.map +1 -1
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.d.ts.map +1 -1
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.js +1 -6
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.js.map +1 -1
- package/dist/account-layer/use-deallocate.d.ts.map +1 -1
- package/dist/account-layer/use-deallocate.js +1 -3
- package/dist/account-layer/use-deallocate.js.map +1 -1
- package/dist/account-layer/use-delete-sub-account.d.ts.map +1 -1
- package/dist/account-layer/use-delete-sub-account.js +1 -2
- package/dist/account-layer/use-delete-sub-account.js.map +1 -1
- package/dist/account-layer/use-deposit-and-allocate.d.ts.map +1 -1
- package/dist/account-layer/use-deposit-and-allocate.js +1 -3
- package/dist/account-layer/use-deposit-and-allocate.js.map +1 -1
- package/dist/account-layer/use-deposit.d.ts.map +1 -1
- package/dist/account-layer/use-deposit.js +1 -3
- package/dist/account-layer/use-deposit.js.map +1 -1
- package/dist/account-layer/use-edit-account-name.d.ts.map +1 -1
- package/dist/account-layer/use-edit-account-name.js +1 -3
- package/dist/account-layer/use-edit-account-name.js.map +1 -1
- package/dist/account-layer/use-remove-margin.d.ts.map +1 -1
- package/dist/account-layer/use-remove-margin.js +1 -3
- package/dist/account-layer/use-remove-margin.js.map +1 -1
- package/dist/account-layer/use-request-to-register-affiliate.d.ts.map +1 -1
- package/dist/account-layer/use-request-to-register-affiliate.js +1 -2
- package/dist/account-layer/use-request-to-register-affiliate.js.map +1 -1
- package/dist/collateral/use-approve-collateral.d.ts.map +1 -1
- package/dist/collateral/use-approve-collateral.js +1 -2
- package/dist/collateral/use-approve-collateral.js.map +1 -1
- package/dist/errors/normalize-symm-error.d.ts.map +1 -1
- package/dist/errors/normalize-symm-error.js +1 -0
- package/dist/errors/normalize-symm-error.js.map +1 -1
- package/dist/errors/symmio-request-error.d.ts +19 -0
- package/dist/errors/symmio-request-error.d.ts.map +1 -1
- package/dist/errors/symmio-request-error.js +2 -1
- package/dist/errors/symmio-request-error.js.map +1 -1
- package/dist/gasless/gasless-relay-types.d.ts +115 -0
- package/dist/gasless/gasless-relay-types.d.ts.map +1 -0
- package/dist/gasless/gasless-relay-types.js +9 -0
- package/dist/gasless/gasless-relay-types.js.map +1 -0
- package/dist/gasless/index.d.ts +21 -0
- package/dist/gasless/index.d.ts.map +1 -0
- package/dist/gasless/index.js +21 -0
- package/dist/gasless/invalidate-relay-reads.d.ts +96 -0
- package/dist/gasless/invalidate-relay-reads.d.ts.map +1 -0
- package/dist/gasless/invalidate-relay-reads.js +107 -0
- package/dist/gasless/invalidate-relay-reads.js.map +1 -0
- package/dist/gasless/use-approve-operational-fee.d.ts +38 -0
- package/dist/gasless/use-approve-operational-fee.d.ts.map +1 -0
- package/dist/gasless/use-approve-operational-fee.js +37 -0
- package/dist/gasless/use-approve-operational-fee.js.map +1 -0
- package/dist/gasless/use-debounced-batch.d.ts +22 -0
- package/dist/gasless/use-debounced-batch.d.ts.map +1 -0
- package/dist/gasless/use-debounced-batch.js +27 -0
- package/dist/gasless/use-debounced-batch.js.map +1 -0
- package/dist/gasless/use-gasless-batch-fee-quote.d.ts +48 -0
- package/dist/gasless/use-gasless-batch-fee-quote.d.ts.map +1 -0
- package/dist/gasless/use-gasless-batch-fee-quote.js +33 -0
- package/dist/gasless/use-gasless-batch-fee-quote.js.map +1 -0
- package/dist/gasless/use-gasless-deposit-policy.d.ts +28 -0
- package/dist/gasless/use-gasless-deposit-policy.d.ts.map +1 -0
- package/dist/gasless/use-gasless-deposit-policy.js +27 -0
- package/dist/gasless/use-gasless-deposit-policy.js.map +1 -0
- package/dist/gasless/use-gasless-fee-quote.d.ts +25 -0
- package/dist/gasless/use-gasless-fee-quote.d.ts.map +1 -0
- package/dist/gasless/use-gasless-fee-quote.js +27 -0
- package/dist/gasless/use-gasless-fee-quote.js.map +1 -0
- package/dist/gasless/use-gasless-relay-confirmation.d.ts +72 -0
- package/dist/gasless/use-gasless-relay-confirmation.d.ts.map +1 -0
- package/dist/gasless/use-gasless-relay-confirmation.js +148 -0
- package/dist/gasless/use-gasless-relay-confirmation.js.map +1 -0
- package/dist/gasless/use-gasless-request-stream.d.ts +34 -0
- package/dist/gasless/use-gasless-request-stream.d.ts.map +1 -0
- package/dist/gasless/use-gasless-request-stream.js +86 -0
- package/dist/gasless/use-gasless-request-stream.js.map +1 -0
- package/dist/gasless/use-gasless-request-transactions.d.ts +42 -0
- package/dist/gasless/use-gasless-request-transactions.d.ts.map +1 -0
- package/dist/gasless/use-gasless-request-transactions.js +28 -0
- package/dist/gasless/use-gasless-request-transactions.js.map +1 -0
- package/dist/gasless/use-gasless-request.d.ts +56 -0
- package/dist/gasless/use-gasless-request.d.ts.map +1 -0
- package/dist/gasless/use-gasless-request.js +51 -0
- package/dist/gasless/use-gasless-request.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-address.d.ts +24 -0
- package/dist/gasless/use-gasless-wallet-address.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-address.js +27 -0
- package/dist/gasless/use-gasless-wallet-address.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-creation-fee.d.ts +29 -0
- package/dist/gasless/use-gasless-wallet-creation-fee.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-creation-fee.js +27 -0
- package/dist/gasless/use-gasless-wallet-creation-fee.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-execute-selectors.d.ts +44 -0
- package/dist/gasless/use-gasless-wallet-execute-selectors.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-execute-selectors.js +19 -0
- package/dist/gasless/use-gasless-wallet-execute-selectors.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-execute.d.ts +51 -0
- package/dist/gasless/use-gasless-wallet-execute.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-execute.js +44 -0
- package/dist/gasless/use-gasless-wallet-execute.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-nonce.d.ts +27 -0
- package/dist/gasless/use-gasless-wallet-nonce.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-nonce.js +27 -0
- package/dist/gasless/use-gasless-wallet-nonce.js.map +1 -0
- package/dist/gasless/use-operational-fee-allowance.d.ts +23 -0
- package/dist/gasless/use-operational-fee-allowance.d.ts.map +1 -0
- package/dist/gasless/use-operational-fee-allowance.js +27 -0
- package/dist/gasless/use-operational-fee-allowance.js.map +1 -0
- package/dist/gasless/use-relay-gasless-batch.d.ts +48 -0
- package/dist/gasless/use-relay-gasless-batch.d.ts.map +1 -0
- package/dist/gasless/use-relay-gasless-batch.js +44 -0
- package/dist/gasless/use-relay-gasless-batch.js.map +1 -0
- package/dist/gasless/use-relay-instant-operations.d.ts +43 -0
- package/dist/gasless/use-relay-instant-operations.d.ts.map +1 -0
- package/dist/gasless/use-relay-instant-operations.js +44 -0
- package/dist/gasless/use-relay-instant-operations.js.map +1 -0
- package/dist/gasless/use-resubmit-gasless-request.d.ts +39 -0
- package/dist/gasless/use-resubmit-gasless-request.d.ts.map +1 -0
- package/dist/gasless/use-resubmit-gasless-request.js +56 -0
- package/dist/gasless/use-resubmit-gasless-request.js.map +1 -0
- package/dist/gasless/use-settle-gasless-deposit-existing-account.d.ts +41 -0
- package/dist/gasless/use-settle-gasless-deposit-existing-account.d.ts.map +1 -0
- package/dist/gasless/use-settle-gasless-deposit-existing-account.js +47 -0
- package/dist/gasless/use-settle-gasless-deposit-existing-account.js.map +1 -0
- package/dist/gasless/use-settle-gasless-deposit-new-account.d.ts +48 -0
- package/dist/gasless/use-settle-gasless-deposit-new-account.d.ts.map +1 -0
- package/dist/gasless/use-settle-gasless-deposit-new-account.js +48 -0
- package/dist/gasless/use-settle-gasless-deposit-new-account.js.map +1 -0
- package/dist/gasless/use-supports-gasless-service.d.ts +22 -0
- package/dist/gasless/use-supports-gasless-service.d.ts.map +1 -0
- package/dist/gasless/use-supports-gasless-service.js +13 -0
- package/dist/gasless/use-supports-gasless-service.js.map +1 -0
- package/dist/index.d.ts +29 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +251 -221
- package/dist/instant-layer/index.d.ts +7 -0
- package/dist/instant-layer/index.d.ts.map +1 -1
- package/dist/instant-layer/index.js +26 -19
- package/dist/instant-layer/use-active-delegations.d.ts +31 -0
- package/dist/instant-layer/use-active-delegations.d.ts.map +1 -0
- package/dist/instant-layer/use-active-delegations.js +23 -0
- package/dist/instant-layer/use-active-delegations.js.map +1 -0
- package/dist/instant-layer/use-are-delegations-active.d.ts +100 -0
- package/dist/instant-layer/use-are-delegations-active.d.ts.map +1 -0
- package/dist/instant-layer/use-are-delegations-active.js +60 -0
- package/dist/instant-layer/use-are-delegations-active.js.map +1 -0
- package/dist/instant-layer/use-finalize-revoke-delegation.d.ts +32 -0
- package/dist/instant-layer/use-finalize-revoke-delegation.d.ts.map +1 -0
- package/dist/instant-layer/use-finalize-revoke-delegation.js +45 -0
- package/dist/instant-layer/use-finalize-revoke-delegation.js.map +1 -0
- package/dist/instant-layer/use-grant-delegation.d.ts +12 -2
- package/dist/instant-layer/use-grant-delegation.d.ts.map +1 -1
- package/dist/instant-layer/use-grant-delegation.js +27 -20
- package/dist/instant-layer/use-grant-delegation.js.map +1 -1
- package/dist/instant-layer/use-initiate-revoke-delegation.d.ts +32 -0
- package/dist/instant-layer/use-initiate-revoke-delegation.d.ts.map +1 -0
- package/dist/instant-layer/use-initiate-revoke-delegation.js +45 -0
- package/dist/instant-layer/use-initiate-revoke-delegation.js.map +1 -0
- package/dist/instant-layer/use-pending-revocation.d.ts +119 -0
- package/dist/instant-layer/use-pending-revocation.d.ts.map +1 -0
- package/dist/instant-layer/use-pending-revocation.js +73 -0
- package/dist/instant-layer/use-pending-revocation.js.map +1 -0
- package/dist/instant-layer/use-revocation-cooldown.d.ts +24 -0
- package/dist/instant-layer/use-revocation-cooldown.d.ts.map +1 -0
- package/dist/instant-layer/use-revocation-cooldown.js +23 -0
- package/dist/instant-layer/use-revocation-cooldown.js.map +1 -0
- package/dist/instant-layer/use-session-key-selectors.d.ts +53 -0
- package/dist/instant-layer/use-session-key-selectors.d.ts.map +1 -0
- package/dist/instant-layer/use-session-key-selectors.js +25 -0
- package/dist/instant-layer/use-session-key-selectors.js.map +1 -0
- package/dist/margin/use-available-instant-open-margin.js +8 -8
- package/dist/markets/index.d.ts +1 -0
- package/dist/markets/index.d.ts.map +1 -1
- package/dist/markets/index.js +3 -2
- package/dist/markets/use-funding-fees-of-party-b.d.ts +47 -0
- package/dist/markets/use-funding-fees-of-party-b.d.ts.map +1 -0
- package/dist/markets/use-funding-fees-of-party-b.js +27 -0
- package/dist/markets/use-funding-fees-of-party-b.js.map +1 -0
- package/dist/provider/create-session-key-wallet-client-resolver.d.ts +68 -0
- package/dist/provider/create-session-key-wallet-client-resolver.d.ts.map +1 -0
- package/dist/provider/create-session-key-wallet-client-resolver.js +51 -0
- package/dist/provider/create-session-key-wallet-client-resolver.js.map +1 -0
- package/dist/provider/index.d.ts +1 -0
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +5 -4
- package/dist/provider/symmio-provider.d.ts +7 -2
- package/dist/provider/symmio-provider.d.ts.map +1 -1
- package/dist/provider/symmio-provider.js +10 -7
- package/dist/provider/symmio-provider.js.map +1 -1
- package/dist/quotes/index.d.ts +2 -0
- package/dist/quotes/index.d.ts.map +1 -1
- package/dist/quotes/use-account-upnl.js +9 -9
- package/dist/quotes/use-close-quote-group.js +13 -13
- package/dist/quotes/use-force-cancel-close-request.d.ts.map +1 -1
- package/dist/quotes/use-force-cancel-close-request.js +1 -4
- package/dist/quotes/use-force-cancel-close-request.js.map +1 -1
- package/dist/quotes/use-force-cancel-quote.d.ts.map +1 -1
- package/dist/quotes/use-force-cancel-quote.js +1 -4
- package/dist/quotes/use-force-cancel-quote.js.map +1 -1
- package/dist/quotes/use-force-close.d.ts +2 -1
- package/dist/quotes/use-force-close.d.ts.map +1 -1
- package/dist/quotes/use-force-close.js +14 -12
- package/dist/quotes/use-force-close.js.map +1 -1
- package/dist/quotes/use-limit-orders.js +9 -9
- package/dist/quotes/use-managed-quotes.d.ts.map +1 -1
- package/dist/quotes/use-managed-quotes.js +103 -103
- package/dist/quotes/use-managed-quotes.js.map +1 -1
- package/dist/quotes/use-party-a-open-positions.js +5 -5
- package/dist/quotes/use-quote-group-funding-history.d.ts +10 -7
- package/dist/quotes/use-quote-group-funding-history.d.ts.map +1 -1
- package/dist/quotes/use-quote-group-funding-history.js.map +1 -1
- package/dist/quotes/use-quote-group-funding.d.ts +4 -2
- package/dist/quotes/use-quote-group-funding.d.ts.map +1 -1
- package/dist/quotes/use-quote-group-funding.js.map +1 -1
- package/dist/quotes/use-quote-pending-funding.d.ts +62 -0
- package/dist/quotes/use-quote-pending-funding.d.ts.map +1 -0
- package/dist/quotes/use-quote-pending-funding.js +31 -0
- package/dist/quotes/use-quote-pending-funding.js.map +1 -0
- package/dist/quotes/use-quotes-funding.d.ts +4 -2
- package/dist/quotes/use-quotes-funding.d.ts.map +1 -1
- package/dist/quotes/use-quotes-funding.js.map +1 -1
- package/dist/quotes/use-quotes-pending-funding.d.ts +92 -0
- package/dist/quotes/use-quotes-pending-funding.d.ts.map +1 -0
- package/dist/quotes/use-quotes-pending-funding.js +94 -0
- package/dist/quotes/use-quotes-pending-funding.js.map +1 -0
- package/dist/quotes/use-request-to-cancel-close-request.d.ts.map +1 -1
- package/dist/quotes/use-request-to-cancel-close-request.js +1 -4
- package/dist/quotes/use-request-to-cancel-close-request.js.map +1 -1
- package/dist/quotes/use-request-to-cancel-quote.d.ts.map +1 -1
- package/dist/quotes/use-request-to-cancel-quote.js +1 -4
- package/dist/quotes/use-request-to-cancel-quote.js.map +1 -1
- package/dist/transactions/index.js +3 -3
- package/dist/transactions/resolve-write-result.d.ts +53 -2
- package/dist/transactions/resolve-write-result.d.ts.map +1 -1
- package/dist/transactions/resolve-write-result.js +52 -9
- package/dist/transactions/resolve-write-result.js.map +1 -1
- package/dist/transactions/write-types.d.ts +19 -1
- package/dist/transactions/write-types.d.ts.map +1 -1
- package/dist/utils/predicate-match.d.ts +7 -4
- package/dist/utils/predicate-match.d.ts.map +1 -1
- package/dist/utils/predicate-match.js +5 -5
- package/dist/utils/predicate-match.js.map +1 -1
- package/dist/withdraw/use-finalize-withdraw-request.d.ts.map +1 -1
- package/dist/withdraw/use-finalize-withdraw-request.js +1 -3
- package/dist/withdraw/use-finalize-withdraw-request.js.map +1 -1
- package/dist/withdraw/use-initiate-withdraw.d.ts.map +1 -1
- package/dist/withdraw/use-initiate-withdraw.js +1 -5
- package/dist/withdraw/use-initiate-withdraw.js.map +1 -1
- package/dist/withdraw/use-request-cancel-withdraw.d.ts.map +1 -1
- package/dist/withdraw/use-request-cancel-withdraw.js +1 -3
- package/dist/withdraw/use-request-cancel-withdraw.js.map +1 -1
- package/dist/withdraw/use-withdraw.d.ts.map +1 -1
- package/dist/withdraw/use-withdraw.js +2 -1
- package/dist/withdraw/use-withdraw.js.map +1 -1
- package/package.json +6 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-quotes-funding.js","names":[],"sources":["../../src/quotes/use-quotes-funding.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getQuoteFundingQueryOptions,\n type ConfigParameter,\n type GetQuoteFundingOptions,\n type QuoteFundingData,\n} from \"@symmio/trading-core\";\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useMemo } from \"react\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\n\n/** Minimum quote shape `useQuotesFunding` needs: just the on-chain id. */\nexport interface QuotesFundingInputQuote {\n /** On-chain quote id. Off-chain (pending) rows pass `undefined` and are skipped. */\n quoteId?: bigint;\n}\n\n/**\n * Parameters for {@link useQuotesFunding}.\n */\nexport interface UseQuotesFundingParameters extends Omit<GetQuoteFundingOptions, \"quoteIds\">, ConfigParameter {\n /**\n * Quotes (or quote-id-bearing rows) to read funding for. Off-chain rows\n * (`quoteId === undefined`) are silently skipped. The resolved on-chain ids are\n * de-duplicated and fetched in a single subgraph round-trip, so listing the\n * same quote twice costs one request and contributes to the sums once.\n */\n quotes: readonly QuotesFundingInputQuote[];\n}\n\n/**\n * Return type of {@link useQuotesFunding}.\n */\nexport interface UseQuotesFundingReturnType {\n /**\n * Funding row per input quote, aligned 1:1 with `quotes` and in input order —\n * `rows.length === quotes.length` on every path, including while loading and\n * when nothing on-chain was requested. An entry is `null` for an off-chain row\n * (no `quoteId`) or for an id the subgraph has not surfaced yet.\n */\n rows: Array<QuoteFundingData | null>;\n /**\n * Σ funding paid across the resolved rows (wei). Summed over the **distinct**\n * on-chain ids, so a quote listed twice contributes once.\n */\n paid: bigint;\n /**\n * Σ funding received across the resolved rows (wei). Summed over the\n * **distinct** on-chain ids, so a quote listed twice contributes once.\n */\n received: bigint;\n /**\n * Σ `received − paid` across the resolved rows (wei). **Positive = the position\n * earned funding**; negative = it paid for it. A lower bound while\n * `missingQuoteIds` is non-empty.\n */\n netReceived: bigint;\n /**\n * Requested on-chain ids that have no funding row yet. While the query is in\n * flight — and if it fails — this is **every** requested id, since nothing has\n * resolved; once it settles it is the subset the subgraph did not return\n * (indexing lag). Always empty when no on-chain ids were requested.\n */\n missingQuoteIds: bigint[];\n /** `true` while the underlying subgraph query is loading. */\n isLoading: boolean;\n /** Normalized request error, when one occurred. */\n error: SymmioRequestError | null;\n}\n\n/**\n * Batch-read funding totals for a list of quotes from the analytics subgraph in\n * a single round-trip and aggregate them into running sums for the group.\n *\n * The hook is the canonical entry point for both single-quote details panels\n * ({@link useQuoteFunding} delegates here with a 1-element list) and grouped\n * quote cards (which want `Σ netReceived`). Off-chain rows are skipped silently,\n * and duplicate ids are fetched — and summed — exactly once.\n *\n * **Sign convention** — `netReceived = received − paid`, the P&L perspective, so\n * a **positive** value means the position **earned** funding. This matches\n * `QuoteFundingData.netReceived` and the uPnL folds, and is the inverse of the\n * cost-positive on-chain `int256`. A \"green = income\" UI renders it directly.\n *\n * **Settled to date only** — the totals cover funding the protocol has already\n * charged and the analytics subgraph has indexed. Funding accrued since a\n * quote's last funding charge is not
|
|
1
|
+
{"version":3,"file":"use-quotes-funding.js","names":[],"sources":["../../src/quotes/use-quotes-funding.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getQuoteFundingQueryOptions,\n type ConfigParameter,\n type GetQuoteFundingOptions,\n type QuoteFundingData,\n} from \"@symmio/trading-core\";\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useMemo } from \"react\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\n\n/** Minimum quote shape `useQuotesFunding` needs: just the on-chain id. */\nexport interface QuotesFundingInputQuote {\n /** On-chain quote id. Off-chain (pending) rows pass `undefined` and are skipped. */\n quoteId?: bigint;\n}\n\n/**\n * Parameters for {@link useQuotesFunding}.\n */\nexport interface UseQuotesFundingParameters extends Omit<GetQuoteFundingOptions, \"quoteIds\">, ConfigParameter {\n /**\n * Quotes (or quote-id-bearing rows) to read funding for. Off-chain rows\n * (`quoteId === undefined`) are silently skipped. The resolved on-chain ids are\n * de-duplicated and fetched in a single subgraph round-trip, so listing the\n * same quote twice costs one request and contributes to the sums once.\n */\n quotes: readonly QuotesFundingInputQuote[];\n}\n\n/**\n * Return type of {@link useQuotesFunding}.\n */\nexport interface UseQuotesFundingReturnType {\n /**\n * Funding row per input quote, aligned 1:1 with `quotes` and in input order —\n * `rows.length === quotes.length` on every path, including while loading and\n * when nothing on-chain was requested. An entry is `null` for an off-chain row\n * (no `quoteId`) or for an id the subgraph has not surfaced yet.\n */\n rows: Array<QuoteFundingData | null>;\n /**\n * Σ funding paid across the resolved rows (wei). Summed over the **distinct**\n * on-chain ids, so a quote listed twice contributes once.\n */\n paid: bigint;\n /**\n * Σ funding received across the resolved rows (wei). Summed over the\n * **distinct** on-chain ids, so a quote listed twice contributes once.\n */\n received: bigint;\n /**\n * Σ `received − paid` across the resolved rows (wei). **Positive = the position\n * earned funding**; negative = it paid for it. A lower bound while\n * `missingQuoteIds` is non-empty.\n */\n netReceived: bigint;\n /**\n * Requested on-chain ids that have no funding row yet. While the query is in\n * flight — and if it fails — this is **every** requested id, since nothing has\n * resolved; once it settles it is the subset the subgraph did not return\n * (indexing lag). Always empty when no on-chain ids were requested.\n */\n missingQuoteIds: bigint[];\n /** `true` while the underlying subgraph query is loading. */\n isLoading: boolean;\n /** Normalized request error, when one occurred. */\n error: SymmioRequestError | null;\n}\n\n/**\n * Batch-read funding totals for a list of quotes from the analytics subgraph in\n * a single round-trip and aggregate them into running sums for the group.\n *\n * The hook is the canonical entry point for both single-quote details panels\n * ({@link useQuoteFunding} delegates here with a 1-element list) and grouped\n * quote cards (which want `Σ netReceived`). Off-chain rows are skipped silently,\n * and duplicate ids are fetched — and summed — exactly once.\n *\n * **Sign convention** — `netReceived = received − paid`, the P&L perspective, so\n * a **positive** value means the position **earned** funding. This matches\n * `QuoteFundingData.netReceived` and the uPnL folds, and is the inverse of the\n * cost-positive on-chain `int256`. A \"green = income\" UI renders it directly.\n *\n * **Settled to date only** — the totals cover funding the protocol has already\n * charged and the analytics subgraph has indexed. Funding accrued since a\n * quote's last funding charge is not in the subgraph and is therefore not\n * included — read it on-chain with {@link useQuotesPendingFunding}. The two\n * come from different sources at different heights, so do not add them into a\n * lifetime total.\n *\n * @param parameters - The quotes to read funding for, plus optional chain/config overrides.\n * @returns Per-quote rows aligned with `quotes`, the aggregate sums, and query state.\n *\n * @example\n * ```tsx\n * const { rows, netReceived, missingQuoteIds, isLoading } = useQuotesFunding({ quotes: group.quotes });\n * // `netReceived > 0n` → the position earned funding across the resolved rows.\n * ```\n */\nexport function useQuotesFunding(parameters: UseQuotesFundingParameters): UseQuotesFundingReturnType {\n const { quotes, ...rest } = parameters;\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n\n const onchainQuoteIds = useMemo(() => {\n const seen = new Set<string>();\n const ids: bigint[] = [];\n for (const quote of quotes) {\n if (quote.quoteId === undefined) continue;\n const key = quote.quoteId.toString();\n if (seen.has(key)) continue;\n seen.add(key);\n ids.push(quote.quoteId);\n }\n return ids;\n }, [quotes]);\n\n const options = getQuoteFundingQueryOptions(config, {\n ...rest,\n chainId: rest.chainId ?? chainId,\n quoteIds: onchainQuoteIds,\n });\n\n const query = useQuery({\n ...options,\n queryFn: async () => {\n try {\n return await options.queryFn();\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n }) as UseQueryResult<{ rows: QuoteFundingData[]; missingQuoteIds: bigint[] }, SymmioRequestError>;\n\n return useMemo(() => {\n /** Nothing on-chain to read: the query is disabled, but `rows` still owes one entry per input quote. */\n if (onchainQuoteIds.length === 0) {\n return {\n rows: quotes.map(() => null),\n paid: 0n,\n received: 0n,\n netReceived: 0n,\n missingQuoteIds: [],\n isLoading: false,\n error: null,\n };\n }\n\n const data = query.data;\n if (!data) {\n return {\n rows: quotes.map(() => null),\n paid: 0n,\n received: 0n,\n netReceived: 0n,\n /** In flight (or failed): nothing resolved, so every requested id is still outstanding. */\n missingQuoteIds: [...onchainQuoteIds],\n isLoading: query.isLoading,\n error: query.error ?? null,\n };\n }\n\n /** First row wins per id — a repeated row for the same quote must not double-count. */\n const byQuoteId = new Map<string, QuoteFundingData>();\n for (const row of data.rows) {\n const key = row.quoteId.toString();\n if (!byQuoteId.has(key)) byQuoteId.set(key, row);\n }\n\n let paid = 0n;\n let received = 0n;\n /** Fold over the de-duped ids, never over `quotes` — the same id listed twice is fetched once and must sum once. */\n for (const quoteId of onchainQuoteIds) {\n const row = byQuoteId.get(quoteId.toString());\n if (row === undefined) continue;\n paid += row.paid;\n received += row.received;\n }\n\n /** Built by lookup afterwards, so the 1:1 alignment with `quotes` is independent of the fold. */\n const rows = quotes.map((quote) =>\n quote.quoteId === undefined ? null : (byQuoteId.get(quote.quoteId.toString()) ?? null),\n );\n\n return {\n rows,\n paid,\n received,\n /** Derived from the sums so the aggregate keeps the row-level `netReceived = received − paid` invariant. */\n netReceived: received - paid,\n missingQuoteIds: data.missingQuoteIds,\n isLoading: query.isLoading,\n error: query.error ?? null,\n };\n }, [onchainQuoteIds, quotes, query.data, query.isLoading, query.error]);\n}\n"],"mappings":";;;;;;;;AAwGA,SAAgB,EAAiB,GAAoE;CACnG,IAAM,EAAE,WAAQ,GAAG,MAAS,GACtB,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAE3B,IAAkB,QAAc;EACpC,IAAM,oBAAO,IAAI,IAAY,GACvB,IAAgB,CAAC;EACvB,KAAK,IAAM,KAAS,GAAQ;GAC1B,IAAI,EAAM,YAAY,KAAA,GAAW;GACjC,IAAM,IAAM,EAAM,QAAQ,SAAS;GAC/B,EAAK,IAAI,CAAG,MAChB,EAAK,IAAI,CAAG,GACZ,EAAI,KAAK,EAAM,OAAO;EACxB;EACA,OAAO;CACT,GAAG,CAAC,CAAM,CAAC,GAEL,IAAU,EAA4B,GAAQ;EAClD,GAAG;EACH,SAAS,EAAK,WAAW;EACzB,UAAU;CACZ,CAAC,GAEK,IAAQ,EAAS;EACrB,GAAG;EACH,SAAS,YAAY;GACnB,IAAI;IACF,OAAO,MAAM,EAAQ,QAAQ;GAC/B,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;CACF,CAAC;CAED,OAAO,QAAc;EAEnB,IAAI,EAAgB,WAAW,GAC7B,OAAO;GACL,MAAM,EAAO,UAAU,IAAI;GAC3B,MAAM;GACN,UAAU;GACV,aAAa;GACb,iBAAiB,CAAC;GAClB,WAAW;GACX,OAAO;EACT;EAGF,IAAM,IAAO,EAAM;EACnB,IAAI,CAAC,GACH,OAAO;GACL,MAAM,EAAO,UAAU,IAAI;GAC3B,MAAM;GACN,UAAU;GACV,aAAa;GAEb,iBAAiB,CAAC,GAAG,CAAe;GACpC,WAAW,EAAM;GACjB,OAAO,EAAM,SAAS;EACxB;EAIF,IAAM,oBAAY,IAAI,IAA8B;EACpD,KAAK,IAAM,KAAO,EAAK,MAAM;GAC3B,IAAM,IAAM,EAAI,QAAQ,SAAS;GACjC,AAAK,EAAU,IAAI,CAAG,KAAG,EAAU,IAAI,GAAK,CAAG;EACjD;EAEA,IAAI,IAAO,IACP,IAAW;EAEf,KAAK,IAAM,KAAW,GAAiB;GACrC,IAAM,IAAM,EAAU,IAAI,EAAQ,SAAS,CAAC;GACxC,MAAQ,KAAA,MACZ,KAAQ,EAAI,MACZ,KAAY,EAAI;EAClB;EAOA,OAAO;GACL,MALW,EAAO,KAAK,MACvB,EAAM,YAAY,KAAA,IAAY,OAAQ,EAAU,IAAI,EAAM,QAAQ,SAAS,CAAC,KAAK,IAIjF;GACA;GACA;GAEA,aAAa,IAAW;GACxB,iBAAiB,EAAK;GACtB,WAAW,EAAM;GACjB,OAAO,EAAM,SAAS;EACxB;CACF,GAAG;EAAC;EAAiB;EAAQ,EAAM;EAAM,EAAM;EAAW,EAAM;CAAK,CAAC;AACxE"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ConfigParameter, GetQuotePendingFundingOptions, QuotePendingFunding, UnifiedQuote } from '@symmio/trading-core';
|
|
2
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for {@link useQuotesPendingFunding}: the core query options minus
|
|
5
|
+
* `quoteIds` (derived from `quotes`) — chain id, batch size and TanStack `query`
|
|
6
|
+
* overrides — plus an optional `config`.
|
|
7
|
+
*/
|
|
8
|
+
export interface UseQuotesPendingFundingParameters extends Omit<GetQuotePendingFundingOptions, "quoteIds">, ConfigParameter {
|
|
9
|
+
/**
|
|
10
|
+
* Quotes to read (a `UnifiedQuote[]` fits). Only rows with a `quoteId` and a
|
|
11
|
+
* known active `quoteStatus` are read (see {@link isActiveQuoteStatus}); every
|
|
12
|
+
* other row is skipped and gets a `null` entry in `rows`. The readable ids are
|
|
13
|
+
* de-duplicated, so listing the same quote twice reads it once and sums it once.
|
|
14
|
+
*/
|
|
15
|
+
quotes: readonly Pick<UnifiedQuote, "quoteId" | "quoteStatus">[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Return type of {@link useQuotesPendingFunding}.
|
|
19
|
+
*/
|
|
20
|
+
export interface UseQuotesPendingFundingReturnType {
|
|
21
|
+
/**
|
|
22
|
+
* One entry per input quote, aligned by index — `rows.length === quotes.length`
|
|
23
|
+
* on every path. An entry is `null` for a row that is not read (no `quoteId`, or
|
|
24
|
+
* a status that is unknown or not an active position) or until the read resolves.
|
|
25
|
+
*/
|
|
26
|
+
rows: readonly (QuotePendingFunding | null)[];
|
|
27
|
+
/**
|
|
28
|
+
* Σ `pendingNetReceived` over the **distinct** ids read, income-positive
|
|
29
|
+
* (`> 0n` the positions will receive funding, `< 0n` they owe it), 18-decimal
|
|
30
|
+
* collateral units. `undefined` until the read has resolved every one of those
|
|
31
|
+
* ids (like `useAccountUpnl`), so a partial sum is never mistaken for the total;
|
|
32
|
+
* `0n` when no quote is readable.
|
|
33
|
+
*/
|
|
34
|
+
pendingNetReceived?: bigint;
|
|
35
|
+
/** `true` while the first read is in flight (no data yet). */
|
|
36
|
+
isLoading: boolean;
|
|
37
|
+
/** `true` while any read is in flight, including a background refetch. */
|
|
38
|
+
isFetching: boolean;
|
|
39
|
+
/** Normalized request error, when the read failed. */
|
|
40
|
+
error: SymmioRequestError | null;
|
|
41
|
+
/** Re-read the pending funding now. */
|
|
42
|
+
refetch: () => void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Read the **pending** (accrued, not yet settled) accumulated funding of a list of
|
|
46
|
+
* quotes from the SYMMIO core diamond, per quote and as one total.
|
|
47
|
+
*
|
|
48
|
+
* Wraps core's `getQuotePendingFunding`, which reads the diamond view
|
|
49
|
+
* `getQuoteFundingDebts` and negates it, so every amount is **income-positive**
|
|
50
|
+
* like the rest of the SDK's funding amounts: `pendingNetReceived > 0n` means the
|
|
51
|
+
* position will receive funding, `< 0n` means it owes it. Each value is what the
|
|
52
|
+
* contract would settle if the quote were charged in the block the RPC ran the
|
|
53
|
+
* call against; it moves in whole-epoch steps and also changes when the solver
|
|
54
|
+
* updates its rates or the quote is charged, partially closed or liquidated. It is
|
|
55
|
+
* `0n` for pairs whose accumulated funding has not started.
|
|
56
|
+
*
|
|
57
|
+
* **Only active positions are read.** A row needs a `quoteId` and a known
|
|
58
|
+
* `quoteStatus` that is `OPENED`, `CLOSE_PENDING`, `CANCEL_CLOSE_PENDING` or
|
|
59
|
+
* `LIQUIDATED_PENDING` ({@link isActiveQuoteStatus}); anything else — an off-chain
|
|
60
|
+
* row, a `LOCKED` or `EXPIRED` quote, a row whose status is not known yet — is
|
|
61
|
+
* never sent and reads `null`. Readable ids are de-duplicated and read in core's
|
|
62
|
+
* sequential batches (`batchSize`, default 25); each batch is its own `eth_call`,
|
|
63
|
+
* so with more than one batch the rows can come from adjacent blocks.
|
|
64
|
+
*
|
|
65
|
+
* **No default polling.** The value grows with time even when nothing happens on
|
|
66
|
+
* the quote, and no event announces that — pass `query.refetchInterval` to keep it
|
|
67
|
+
* fresh. {@link useManagedQuotes} invalidates it together with its on-chain quote
|
|
68
|
+
* reads, and {@link useForceClose} after its receipt.
|
|
69
|
+
*
|
|
70
|
+
* **Settled vs pending.** Funding already charged is read from the analytics
|
|
71
|
+
* subgraph with {@link useQuotesFunding}. The two come from different sources at
|
|
72
|
+
* different heights, so do not add them into a lifetime total. A Muon-signed uPnL
|
|
73
|
+
* already includes accumulated funding — do not net pending funding against it.
|
|
74
|
+
*
|
|
75
|
+
* `chainId` defaults to the connected chain. Errors are normalized to
|
|
76
|
+
* {@link SymmioRequestError}.
|
|
77
|
+
*
|
|
78
|
+
* @param parameters - The quotes to read, plus optional chain id, batch size, TanStack `query` overrides and `config`.
|
|
79
|
+
* @returns Per-quote rows aligned with `quotes`, the total, and query state.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```tsx
|
|
83
|
+
* const { quotes } = useManagedQuotes({ partyA: subAccount });
|
|
84
|
+
* const { rows, pendingNetReceived, isLoading } = useQuotesPendingFunding({
|
|
85
|
+
* quotes,
|
|
86
|
+
* query: { refetchInterval: 60_000 },
|
|
87
|
+
* });
|
|
88
|
+
* // `pendingNetReceived > 0n` → the open positions will receive funding when it settles.
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function useQuotesPendingFunding(parameters: UseQuotesPendingFundingParameters): UseQuotesPendingFundingReturnType;
|
|
92
|
+
//# sourceMappingURL=use-quotes-pending-funding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-quotes-pending-funding.d.ts","sourceRoot":"","sources":["../../src/quotes/use-quotes-pending-funding.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,6BAA6B,EAElC,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIzE;;;;GAIG;AACH,MAAM,WAAW,iCACf,SAAQ,IAAI,CAAC,6BAA6B,EAAE,UAAU,CAAC,EAAE,eAAe;IACxE;;;;;OAKG;IACH,MAAM,EAAE,SAAS,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,aAAa,CAAC,EAAE,CAAC;CAClE;AAED;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD;;;;OAIG;IACH,IAAI,EAAE,SAAS,CAAC,mBAAmB,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,8DAA8D;IAC9D,SAAS,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,UAAU,EAAE,OAAO,CAAC;IACpB,sDAAsD;IACtD,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACjC,uCAAuC;IACvC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAaD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,iCAAiC,GAC5C,iCAAiC,CAyGnC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSymmioChainId as e } from "../provider/use-symmio-chain-id.js";
|
|
3
|
+
import { useSymmioConfig as t } from "../provider/use-symmio-config.js";
|
|
4
|
+
import { normalizeSymmError as n } from "../errors/normalize-symm-error.js";
|
|
5
|
+
import { getQuotePendingFundingQueryOptions as r, isActiveQuoteStatus as i } from "@symmio/trading-core";
|
|
6
|
+
import { useCallback as a, useMemo as o } from "react";
|
|
7
|
+
import { useQuery as s } from "@tanstack/react-query";
|
|
8
|
+
//#region src/quotes/use-quotes-pending-funding.ts
|
|
9
|
+
function c(e) {
|
|
10
|
+
if (!(e.quoteId === void 0 || e.quoteStatus === void 0)) return i(e.quoteStatus) ? e.quoteId : void 0;
|
|
11
|
+
}
|
|
12
|
+
function l(i) {
|
|
13
|
+
let { quotes: l, ...u } = i, d = t(i), f = e(), p = o(() => {
|
|
14
|
+
let e = /* @__PURE__ */ new Set(), t = [];
|
|
15
|
+
for (let n of l) {
|
|
16
|
+
let r = c(n);
|
|
17
|
+
if (r === void 0) continue;
|
|
18
|
+
let i = r.toString();
|
|
19
|
+
e.has(i) || (e.add(i), t.push(r));
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
}, [l]), m = r(d, {
|
|
23
|
+
...u,
|
|
24
|
+
chainId: u.chainId ?? f,
|
|
25
|
+
quoteIds: p
|
|
26
|
+
}), h = s({
|
|
27
|
+
...m,
|
|
28
|
+
queryFn: async () => {
|
|
29
|
+
try {
|
|
30
|
+
return await m.queryFn();
|
|
31
|
+
} catch (e) {
|
|
32
|
+
throw n(e);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}), { refetch: g } = h, _ = a(() => {
|
|
36
|
+
g();
|
|
37
|
+
}, [g]);
|
|
38
|
+
return o(() => {
|
|
39
|
+
if (p.length === 0) return {
|
|
40
|
+
rows: l.map(() => null),
|
|
41
|
+
pendingNetReceived: 0n,
|
|
42
|
+
isLoading: !1,
|
|
43
|
+
isFetching: !1,
|
|
44
|
+
error: null,
|
|
45
|
+
refetch: _
|
|
46
|
+
};
|
|
47
|
+
let e = h.data;
|
|
48
|
+
if (!e) return {
|
|
49
|
+
rows: l.map(() => null),
|
|
50
|
+
pendingNetReceived: void 0,
|
|
51
|
+
isLoading: h.isLoading,
|
|
52
|
+
isFetching: h.isFetching,
|
|
53
|
+
error: h.error ?? null,
|
|
54
|
+
refetch: _
|
|
55
|
+
};
|
|
56
|
+
let t = /* @__PURE__ */ new Map();
|
|
57
|
+
for (let n of e) {
|
|
58
|
+
let e = n.quoteId.toString();
|
|
59
|
+
t.has(e) || t.set(e, n);
|
|
60
|
+
}
|
|
61
|
+
let n = 0n, r = !0;
|
|
62
|
+
for (let e of p) {
|
|
63
|
+
let i = t.get(e.toString());
|
|
64
|
+
if (i === void 0) {
|
|
65
|
+
r = !1;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
n += i.pendingNetReceived;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
rows: l.map((e) => {
|
|
72
|
+
let n = c(e);
|
|
73
|
+
return n === void 0 ? null : t.get(n.toString()) ?? null;
|
|
74
|
+
}),
|
|
75
|
+
pendingNetReceived: r ? n : void 0,
|
|
76
|
+
isLoading: h.isLoading,
|
|
77
|
+
isFetching: h.isFetching,
|
|
78
|
+
error: h.error ?? null,
|
|
79
|
+
refetch: _
|
|
80
|
+
};
|
|
81
|
+
}, [
|
|
82
|
+
p,
|
|
83
|
+
l,
|
|
84
|
+
h.data,
|
|
85
|
+
h.isLoading,
|
|
86
|
+
h.isFetching,
|
|
87
|
+
h.error,
|
|
88
|
+
_
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { l as useQuotesPendingFunding };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=use-quotes-pending-funding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-quotes-pending-funding.js","names":[],"sources":["../../src/quotes/use-quotes-pending-funding.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getQuotePendingFundingQueryOptions,\n isActiveQuoteStatus,\n type ConfigParameter,\n type GetQuotePendingFundingOptions,\n type GetQuotePendingFundingReturnType,\n type QuotePendingFunding,\n type UnifiedQuote,\n} from \"@symmio/trading-core\";\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useCallback, useMemo } from \"react\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\n\n/**\n * Parameters for {@link useQuotesPendingFunding}: the core query options minus\n * `quoteIds` (derived from `quotes`) — chain id, batch size and TanStack `query`\n * overrides — plus an optional `config`.\n */\nexport interface UseQuotesPendingFundingParameters\n extends Omit<GetQuotePendingFundingOptions, \"quoteIds\">, ConfigParameter {\n /**\n * Quotes to read (a `UnifiedQuote[]` fits). Only rows with a `quoteId` and a\n * known active `quoteStatus` are read (see {@link isActiveQuoteStatus}); every\n * other row is skipped and gets a `null` entry in `rows`. The readable ids are\n * de-duplicated, so listing the same quote twice reads it once and sums it once.\n */\n quotes: readonly Pick<UnifiedQuote, \"quoteId\" | \"quoteStatus\">[];\n}\n\n/**\n * Return type of {@link useQuotesPendingFunding}.\n */\nexport interface UseQuotesPendingFundingReturnType {\n /**\n * One entry per input quote, aligned by index — `rows.length === quotes.length`\n * on every path. An entry is `null` for a row that is not read (no `quoteId`, or\n * a status that is unknown or not an active position) or until the read resolves.\n */\n rows: readonly (QuotePendingFunding | null)[];\n /**\n * Σ `pendingNetReceived` over the **distinct** ids read, income-positive\n * (`> 0n` the positions will receive funding, `< 0n` they owe it), 18-decimal\n * collateral units. `undefined` until the read has resolved every one of those\n * ids (like `useAccountUpnl`), so a partial sum is never mistaken for the total;\n * `0n` when no quote is readable.\n */\n pendingNetReceived?: bigint;\n /** `true` while the first read is in flight (no data yet). */\n isLoading: boolean;\n /** `true` while any read is in flight, including a background refetch. */\n isFetching: boolean;\n /** Normalized request error, when the read failed. */\n error: SymmioRequestError | null;\n /** Re-read the pending funding now. */\n refetch: () => void;\n}\n\n/**\n * The quote's on-chain id when its pending funding is meaningful to read — it has\n * an id and a **known, active** on-chain status — else `undefined`. The diamond\n * view does not check status, so a quote a solver locked but never opened would\n * otherwise read as a large, growing and meaningless amount.\n */\nfunction readableQuoteId(quote: Pick<UnifiedQuote, \"quoteId\" | \"quoteStatus\">): bigint | undefined {\n if (quote.quoteId === undefined || quote.quoteStatus === undefined) return undefined;\n return isActiveQuoteStatus(quote.quoteStatus) ? quote.quoteId : undefined;\n}\n\n/**\n * Read the **pending** (accrued, not yet settled) accumulated funding of a list of\n * quotes from the SYMMIO core diamond, per quote and as one total.\n *\n * Wraps core's `getQuotePendingFunding`, which reads the diamond view\n * `getQuoteFundingDebts` and negates it, so every amount is **income-positive**\n * like the rest of the SDK's funding amounts: `pendingNetReceived > 0n` means the\n * position will receive funding, `< 0n` means it owes it. Each value is what the\n * contract would settle if the quote were charged in the block the RPC ran the\n * call against; it moves in whole-epoch steps and also changes when the solver\n * updates its rates or the quote is charged, partially closed or liquidated. It is\n * `0n` for pairs whose accumulated funding has not started.\n *\n * **Only active positions are read.** A row needs a `quoteId` and a known\n * `quoteStatus` that is `OPENED`, `CLOSE_PENDING`, `CANCEL_CLOSE_PENDING` or\n * `LIQUIDATED_PENDING` ({@link isActiveQuoteStatus}); anything else — an off-chain\n * row, a `LOCKED` or `EXPIRED` quote, a row whose status is not known yet — is\n * never sent and reads `null`. Readable ids are de-duplicated and read in core's\n * sequential batches (`batchSize`, default 25); each batch is its own `eth_call`,\n * so with more than one batch the rows can come from adjacent blocks.\n *\n * **No default polling.** The value grows with time even when nothing happens on\n * the quote, and no event announces that — pass `query.refetchInterval` to keep it\n * fresh. {@link useManagedQuotes} invalidates it together with its on-chain quote\n * reads, and {@link useForceClose} after its receipt.\n *\n * **Settled vs pending.** Funding already charged is read from the analytics\n * subgraph with {@link useQuotesFunding}. The two come from different sources at\n * different heights, so do not add them into a lifetime total. A Muon-signed uPnL\n * already includes accumulated funding — do not net pending funding against it.\n *\n * `chainId` defaults to the connected chain. Errors are normalized to\n * {@link SymmioRequestError}.\n *\n * @param parameters - The quotes to read, plus optional chain id, batch size, TanStack `query` overrides and `config`.\n * @returns Per-quote rows aligned with `quotes`, the total, and query state.\n *\n * @example\n * ```tsx\n * const { quotes } = useManagedQuotes({ partyA: subAccount });\n * const { rows, pendingNetReceived, isLoading } = useQuotesPendingFunding({\n * quotes,\n * query: { refetchInterval: 60_000 },\n * });\n * // `pendingNetReceived > 0n` → the open positions will receive funding when it settles.\n * ```\n */\nexport function useQuotesPendingFunding(\n parameters: UseQuotesPendingFundingParameters,\n): UseQuotesPendingFundingReturnType {\n const { quotes, ...rest } = parameters;\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n\n const readableQuoteIds = useMemo(() => {\n const seen = new Set<string>();\n const ids: bigint[] = [];\n for (const quote of quotes) {\n const quoteId = readableQuoteId(quote);\n if (quoteId === undefined) continue;\n const key = quoteId.toString();\n if (seen.has(key)) continue;\n seen.add(key);\n ids.push(quoteId);\n }\n return ids;\n }, [quotes]);\n\n const options = getQuotePendingFundingQueryOptions(config, {\n ...rest,\n chainId: rest.chainId ?? chainId,\n quoteIds: readableQuoteIds,\n });\n\n const query = useQuery({\n ...options,\n queryFn: async () => {\n try {\n return await options.queryFn();\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n }) as UseQueryResult<GetQuotePendingFundingReturnType, SymmioRequestError>;\n\n const { refetch: refetchQuery } = query;\n const refetch = useCallback(() => {\n void refetchQuery();\n }, [refetchQuery]);\n\n return useMemo(() => {\n /** Nothing readable: the query is disabled, but `rows` still owes one entry per input quote. */\n if (readableQuoteIds.length === 0) {\n return {\n rows: quotes.map(() => null),\n pendingNetReceived: 0n,\n isLoading: false,\n isFetching: false,\n error: null,\n refetch,\n };\n }\n\n const data = query.data;\n if (!data) {\n return {\n rows: quotes.map(() => null),\n pendingNetReceived: undefined,\n isLoading: query.isLoading,\n isFetching: query.isFetching,\n error: query.error ?? null,\n refetch,\n };\n }\n\n /** First row wins per id — a repeated row for the same quote must not double-count. */\n const byQuoteId = new Map<string, QuotePendingFunding>();\n for (const row of data) {\n const key = row.quoteId.toString();\n if (!byQuoteId.has(key)) byQuoteId.set(key, row);\n }\n\n /**\n * Fold over the de-duped ids, never over `quotes` — the same id listed twice is\n * read once and must sum once. An id the data does not cover (caller-supplied\n * `placeholderData` from another id set, or a view that answered short) leaves the\n * total unresolved rather than silently partial.\n */\n let total = 0n;\n let complete = true;\n for (const quoteId of readableQuoteIds) {\n const row = byQuoteId.get(quoteId.toString());\n if (row === undefined) {\n complete = false;\n break;\n }\n total += row.pendingNetReceived;\n }\n\n /** Built by lookup afterwards, so the 1:1 alignment with `quotes` is independent of the fold. */\n const rows = quotes.map((quote) => {\n const quoteId = readableQuoteId(quote);\n return quoteId === undefined ? null : (byQuoteId.get(quoteId.toString()) ?? null);\n });\n\n return {\n rows,\n pendingNetReceived: complete ? total : undefined,\n isLoading: query.isLoading,\n isFetching: query.isFetching,\n error: query.error ?? null,\n refetch,\n };\n }, [readableQuoteIds, quotes, query.data, query.isLoading, query.isFetching, query.error, refetch]);\n}\n"],"mappings":";;;;;;;;AAoEA,SAAS,EAAgB,GAA0E;CAC7F,QAAM,YAAY,KAAA,KAAa,EAAM,gBAAgB,KAAA,IACzD,OAAO,EAAoB,EAAM,WAAW,IAAI,EAAM,UAAU,KAAA;AAClE;AAiDA,SAAgB,EACd,GACmC;CACnC,IAAM,EAAE,WAAQ,GAAG,MAAS,GACtB,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAE3B,IAAmB,QAAc;EACrC,IAAM,oBAAO,IAAI,IAAY,GACvB,IAAgB,CAAC;EACvB,KAAK,IAAM,KAAS,GAAQ;GAC1B,IAAM,IAAU,EAAgB,CAAK;GACrC,IAAI,MAAY,KAAA,GAAW;GAC3B,IAAM,IAAM,EAAQ,SAAS;GACzB,EAAK,IAAI,CAAG,MAChB,EAAK,IAAI,CAAG,GACZ,EAAI,KAAK,CAAO;EAClB;EACA,OAAO;CACT,GAAG,CAAC,CAAM,CAAC,GAEL,IAAU,EAAmC,GAAQ;EACzD,GAAG;EACH,SAAS,EAAK,WAAW;EACzB,UAAU;CACZ,CAAC,GAEK,IAAQ,EAAS;EACrB,GAAG;EACH,SAAS,YAAY;GACnB,IAAI;IACF,OAAO,MAAM,EAAQ,QAAQ;GAC/B,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;CACF,CAAC,GAEK,EAAE,SAAS,MAAiB,GAC5B,IAAU,QAAkB;EAChC,EAAkB;CACpB,GAAG,CAAC,CAAY,CAAC;CAEjB,OAAO,QAAc;EAEnB,IAAI,EAAiB,WAAW,GAC9B,OAAO;GACL,MAAM,EAAO,UAAU,IAAI;GAC3B,oBAAoB;GACpB,WAAW;GACX,YAAY;GACZ,OAAO;GACP;EACF;EAGF,IAAM,IAAO,EAAM;EACnB,IAAI,CAAC,GACH,OAAO;GACL,MAAM,EAAO,UAAU,IAAI;GAC3B,oBAAoB,KAAA;GACpB,WAAW,EAAM;GACjB,YAAY,EAAM;GAClB,OAAO,EAAM,SAAS;GACtB;EACF;EAIF,IAAM,oBAAY,IAAI,IAAiC;EACvD,KAAK,IAAM,KAAO,GAAM;GACtB,IAAM,IAAM,EAAI,QAAQ,SAAS;GACjC,AAAK,EAAU,IAAI,CAAG,KAAG,EAAU,IAAI,GAAK,CAAG;EACjD;EAQA,IAAI,IAAQ,IACR,IAAW;EACf,KAAK,IAAM,KAAW,GAAkB;GACtC,IAAM,IAAM,EAAU,IAAI,EAAQ,SAAS,CAAC;GAC5C,IAAI,MAAQ,KAAA,GAAW;IACrB,IAAW;IACX;GACF;GACA,KAAS,EAAI;EACf;EAQA,OAAO;GACL,MANW,EAAO,KAAK,MAAU;IACjC,IAAM,IAAU,EAAgB,CAAK;IACrC,OAAO,MAAY,KAAA,IAAY,OAAQ,EAAU,IAAI,EAAQ,SAAS,CAAC,KAAK;GAC9E,CAGE;GACA,oBAAoB,IAAW,IAAQ,KAAA;GACvC,WAAW,EAAM;GACjB,YAAY,EAAM;GAClB,OAAO,EAAM,SAAS;GACtB;EACF;CACF,GAAG;EAAC;EAAkB;EAAQ,EAAM;EAAM,EAAM;EAAW,EAAM;EAAY,EAAM;EAAO;CAAO,CAAC;AACpG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-to-cancel-close-request.d.ts","sourceRoot":"","sources":["../../src/quotes/use-request-to-cancel-close-request.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,qCAAqC,EAC3C,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,OAAO,EAAsB,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG7F,6DAA6D;AAC7D,MAAM,MAAM,wCAAwC,GAAG,eAAe,CAAC;AAEvE,8EAA8E;AAC9E,MAAM,MAAM,iCAAiC,GAAG,WAAW,CAAC;AAE5D,6DAA6D;AAC7D,MAAM,MAAM,wCAAwC,GAAG,iBAAiB,CACtE,iCAAiC,EACjC,kBAAkB,EAClB,qCAAqC,CACtC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,GAAE,wCAA6C,GACxD,wCAAwC,
|
|
1
|
+
{"version":3,"file":"use-request-to-cancel-close-request.d.ts","sourceRoot":"","sources":["../../src/quotes/use-request-to-cancel-close-request.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,qCAAqC,EAC3C,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,OAAO,EAAsB,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG7F,6DAA6D;AAC7D,MAAM,MAAM,wCAAwC,GAAG,eAAe,CAAC;AAEvE,8EAA8E;AAC9E,MAAM,MAAM,iCAAiC,GAAG,WAAW,CAAC;AAE5D,6DAA6D;AAC7D,MAAM,MAAM,wCAAwC,GAAG,iBAAiB,CACtE,iCAAiC,EACjC,kBAAkB,EAClB,qCAAqC,CACtC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,GAAE,wCAA6C,GACxD,wCAAwC,CA6B1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-to-cancel-close-request.js","names":[],"sources":["../../src/quotes/use-request-to-cancel-close-request.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getPartyAOpenPositionsQueryKey,\n requestToCancelCloseRequestMutationOptions,\n type RequestToCancelCloseRequestParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useRequestToCancelCloseRequest}. */\nexport type UseRequestToCancelCloseRequestParameters = WriteParameters;\n\n/** Result returned by the {@link useRequestToCancelCloseRequest} mutation. */\nexport type RequestToCancelCloseRequestResult = WriteResult;\n\n/** Return type of {@link useRequestToCancelCloseRequest}. */\nexport type UseRequestToCancelCloseRequestReturnType = UseMutationResult<\n RequestToCancelCloseRequestResult,\n SymmioRequestError,\n RequestToCancelCloseRequestParameters\n>;\n\n/**\n * Cancel a pending close (`requestToCancelCloseRequest`, routed through the\n * AccountLayer `_call` proxy) — how a partyA backs out of a resting close (e.g.\n * a limit close) while the quote is `CLOSE_PENDING`. If partyB accepts, the quote\n * returns to `OPENED`; if partyB stalls it enters `CANCEL_CLOSE_PENDING`, which\n * {@link useForceCancelCloseRequest} escalates once the cooldown passes. On\n * success (after the receipt) the subaccount's open-positions read is invalidated\n * so the row's status refreshes.\n *\n * @example\n * ```tsx\n * const { mutate } = useRequestToCancelCloseRequest();\n * mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useRequestToCancelCloseRequest(\n parameters: UseRequestToCancelCloseRequestParameters = {},\n): UseRequestToCancelCloseRequestReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = requestToCancelCloseRequestMutationOptions(config);\n\n return useMutation<RequestToCancelCloseRequestResult, SymmioRequestError, RequestToCancelCloseRequestParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({
|
|
1
|
+
{"version":3,"file":"use-request-to-cancel-close-request.js","names":[],"sources":["../../src/quotes/use-request-to-cancel-close-request.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getPartyAOpenPositionsQueryKey,\n requestToCancelCloseRequestMutationOptions,\n type RequestToCancelCloseRequestParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useRequestToCancelCloseRequest}. */\nexport type UseRequestToCancelCloseRequestParameters = WriteParameters;\n\n/** Result returned by the {@link useRequestToCancelCloseRequest} mutation. */\nexport type RequestToCancelCloseRequestResult = WriteResult;\n\n/** Return type of {@link useRequestToCancelCloseRequest}. */\nexport type UseRequestToCancelCloseRequestReturnType = UseMutationResult<\n RequestToCancelCloseRequestResult,\n SymmioRequestError,\n RequestToCancelCloseRequestParameters\n>;\n\n/**\n * Cancel a pending close (`requestToCancelCloseRequest`, routed through the\n * AccountLayer `_call` proxy) — how a partyA backs out of a resting close (e.g.\n * a limit close) while the quote is `CLOSE_PENDING`. If partyB accepts, the quote\n * returns to `OPENED`; if partyB stalls it enters `CANCEL_CLOSE_PENDING`, which\n * {@link useForceCancelCloseRequest} escalates once the cooldown passes. On\n * success (after the receipt) the subaccount's open-positions read is invalidated\n * so the row's status refreshes.\n *\n * @example\n * ```tsx\n * const { mutate } = useRequestToCancelCloseRequest();\n * mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useRequestToCancelCloseRequest(\n parameters: UseRequestToCancelCloseRequestParameters = {},\n): UseRequestToCancelCloseRequestReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = requestToCancelCloseRequestMutationOptions(config);\n\n return useMutation<RequestToCancelCloseRequestResult, SymmioRequestError, RequestToCancelCloseRequestParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({ ...variables, chainId: resolvedChainId });\n return resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: (_result, variables) => {\n // The close-cancel flips the position out of CLOSE_PENDING — refetch the\n // owning partyA's open positions so the status updates.\n const partial = { partyA: variables.account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPartyAOpenPositionsQueryKey, partial) });\n },\n });\n}\n"],"mappings":";;;;;;;;;AA2CA,SAAgB,EACd,IAAuD,CAAC,GACd;CAC1C,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAE7B,IAAO,EAA2C,CAAM;CAE9D,OAAO,EAA0G;EAC/G,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,IAAM,IAAkB,EAAU,WAAW;IAE7C,OAAO,EAAmB,GAAQ,MADf,EAAK,WAAW;KAAE,GAAG;KAAW,SAAS;IAAgB,CAAC,GACrC;KACtC,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CAAC;GACH,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,YAAY,GAAS,MAAc;GAGjC,IAAM,IAAU,EAAE,QAAQ,EAAU,QAAQ;GAC5C,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAgC,CAAO,EAAE,CAAC;EAC3G;CACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-to-cancel-quote.d.ts","sourceRoot":"","sources":["../../src/quotes/use-request-to-cancel-quote.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,8BAA8B,EACpC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,OAAO,EAAsB,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG7F,sDAAsD;AACtD,MAAM,MAAM,iCAAiC,GAAG,eAAe,CAAC;AAEhE,uEAAuE;AACvE,MAAM,MAAM,0BAA0B,GAAG,WAAW,CAAC;AAErD,sDAAsD;AACtD,MAAM,MAAM,iCAAiC,GAAG,iBAAiB,CAC/D,0BAA0B,EAC1B,kBAAkB,EAClB,8BAA8B,CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,GAAE,iCAAsC,GACjD,iCAAiC,
|
|
1
|
+
{"version":3,"file":"use-request-to-cancel-quote.d.ts","sourceRoot":"","sources":["../../src/quotes/use-request-to-cancel-quote.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,8BAA8B,EACpC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,OAAO,EAAsB,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG7F,sDAAsD;AACtD,MAAM,MAAM,iCAAiC,GAAG,eAAe,CAAC;AAEhE,uEAAuE;AACvE,MAAM,MAAM,0BAA0B,GAAG,WAAW,CAAC;AAErD,sDAAsD;AACtD,MAAM,MAAM,iCAAiC,GAAG,iBAAiB,CAC/D,0BAA0B,EAC1B,kBAAkB,EAClB,8BAA8B,CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,GAAE,iCAAsC,GACjD,iCAAiC,CAqDnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-to-cancel-quote.js","names":[],"sources":["../../src/quotes/use-request-to-cancel-quote.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getPartyAPendingQuotesQueryKey,\n getPendingQuotesQueryKey,\n getQuoteQueryKey,\n requestToCancelQuoteMutationOptions,\n type RequestToCancelQuoteParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { invalidateAccountBalances, predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useRequestToCancelQuote}. */\nexport type UseRequestToCancelQuoteParameters = WriteParameters;\n\n/** Result returned by the {@link useRequestToCancelQuote} mutation. */\nexport type RequestToCancelQuoteResult = WriteResult;\n\n/** Return type of {@link useRequestToCancelQuote}. */\nexport type UseRequestToCancelQuoteReturnType = UseMutationResult<\n RequestToCancelQuoteResult,\n SymmioRequestError,\n RequestToCancelQuoteParameters\n>;\n\n/**\n * Cancel a pending quote (`requestToCancelQuote`, routed through the AccountLayer\n * `_call` proxy) — how a partyA cancels a resting **LIMIT order**. On success\n * (after the receipt), the subaccount's pending-quotes reads and the quote's own\n * `getQuote` read are invalidated.\n *\n * The order only leaves the list immediately when it was `PENDING` (unlocked): the\n * contract cancels it outright. A `LOCKED` order instead moves to `CANCEL_PENDING`\n * and **stays** in `partyAPendingQuotes` until the solver calls\n * `acceptCancelRequest` — a transaction this mutation never sees and the\n * notifications stream never announces. `useManagedQuotes` and `useLimitOrders`\n * chase that on-chain, so a list fed by either drops the row on its own; a consumer\n * reading `getPartyAPendingQuotes` directly has to poll.\n *\n * @example\n * ```tsx\n * const { mutate } = useRequestToCancelQuote();\n * mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useRequestToCancelQuote(\n parameters: UseRequestToCancelQuoteParameters = {},\n): UseRequestToCancelQuoteReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = requestToCancelQuoteMutationOptions(config);\n\n return useMutation<RequestToCancelQuoteResult, SymmioRequestError, RequestToCancelQuoteParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({
|
|
1
|
+
{"version":3,"file":"use-request-to-cancel-quote.js","names":[],"sources":["../../src/quotes/use-request-to-cancel-quote.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getPartyAPendingQuotesQueryKey,\n getPendingQuotesQueryKey,\n getQuoteQueryKey,\n requestToCancelQuoteMutationOptions,\n type RequestToCancelQuoteParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { invalidateAccountBalances, predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useRequestToCancelQuote}. */\nexport type UseRequestToCancelQuoteParameters = WriteParameters;\n\n/** Result returned by the {@link useRequestToCancelQuote} mutation. */\nexport type RequestToCancelQuoteResult = WriteResult;\n\n/** Return type of {@link useRequestToCancelQuote}. */\nexport type UseRequestToCancelQuoteReturnType = UseMutationResult<\n RequestToCancelQuoteResult,\n SymmioRequestError,\n RequestToCancelQuoteParameters\n>;\n\n/**\n * Cancel a pending quote (`requestToCancelQuote`, routed through the AccountLayer\n * `_call` proxy) — how a partyA cancels a resting **LIMIT order**. On success\n * (after the receipt), the subaccount's pending-quotes reads and the quote's own\n * `getQuote` read are invalidated.\n *\n * The order only leaves the list immediately when it was `PENDING` (unlocked): the\n * contract cancels it outright. A `LOCKED` order instead moves to `CANCEL_PENDING`\n * and **stays** in `partyAPendingQuotes` until the solver calls\n * `acceptCancelRequest` — a transaction this mutation never sees and the\n * notifications stream never announces. `useManagedQuotes` and `useLimitOrders`\n * chase that on-chain, so a list fed by either drops the row on its own; a consumer\n * reading `getPartyAPendingQuotes` directly has to poll.\n *\n * @example\n * ```tsx\n * const { mutate } = useRequestToCancelQuote();\n * mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useRequestToCancelQuote(\n parameters: UseRequestToCancelQuoteParameters = {},\n): UseRequestToCancelQuoteReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = requestToCancelQuoteMutationOptions(config);\n\n return useMutation<RequestToCancelQuoteResult, SymmioRequestError, RequestToCancelQuoteParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({ ...variables, chainId: resolvedChainId });\n return resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: (_result, variables) => {\n /**\n * Refetch both pending reads (full quotes + ids) for this partyA, plus the\n * per-id `getQuote` hydration — that is the read carrying `quoteStatus`, so\n * without it a `useManagedQuotes` consumer keeps rendering the pre-cancel\n * status even after the id list refreshes.\n *\n * This fires on the receipt of the **request**, which only proves the quote\n * reached `CANCEL_PENDING` when it was `LOCKED`. The transaction that ends the\n * order is the solver's `acceptCancelRequest`, which is not announced on the\n * notifications stream; `useManagedQuotes` / `useLimitOrders` chase it from the\n * cancel notification instead.\n */\n const partial = { partyA: variables.account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPendingQuotesQueryKey, partial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPartyAPendingQuotesQueryKey, partial) });\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getQuoteQueryKey, { quoteId: variables.quoteId }),\n });\n /**\n * Cancelling a `PENDING` quote refunds its open trading fee and releases the\n * margin it had reserved in the same transaction, so every balance read is now\n * stale. On the `LOCKED` branch nothing moves yet — the refund happens inside\n * the solver's later `acceptCancelRequest`, which no frame announces; the\n * cancel-confirm chase in `useManagedQuotes` re-reads the balances for that.\n */\n invalidateAccountBalances(queryClient, {\n configKey: config.getChainConfigKey(variables.chainId ?? chainId),\n });\n },\n });\n}\n"],"mappings":";;;;;;;;;;AAkDA,SAAgB,EACd,IAAgD,CAAC,GACd;CACnC,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAE7B,IAAO,EAAoC,CAAM;CAEvD,OAAO,EAA4F;EACjG,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,IAAM,IAAkB,EAAU,WAAW;IAE7C,OAAO,EAAmB,GAAQ,MADf,EAAK,WAAW;KAAE,GAAG;KAAW,SAAS;IAAgB,CAAC,GACrC;KACtC,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CAAC;GACH,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,YAAY,GAAS,MAAc;GAajC,IAAM,IAAU,EAAE,QAAQ,EAAU,QAAQ;GAa5C,AAZA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA0B,CAAO,EAAE,CAAC,GACnG,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAgC,CAAO,EAAE,CAAC,GACzG,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAkB,EAAE,SAAS,EAAU,QAAQ,CAAC,EAC5E,CAAC,GAQD,EAA0B,GAAa,EACrC,WAAW,EAAO,kBAAkB,EAAU,WAAW,CAAO,EAClE,CAAC;EACH;CACF,CAAC;AACH"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useTransactionsStore as
|
|
3
|
-
export { e as
|
|
1
|
+
import { TransactionRevertedError as e, resolveWriteResult as t } from "./resolve-write-result.js";
|
|
2
|
+
import { useTransactionsStore as n } from "./use-transactions-store.js";
|
|
3
|
+
export { e as TransactionRevertedError, t as resolveWriteResult, n as useTransactionsStore };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Config } from '@symmio/trading-core';
|
|
2
|
-
import { Hash } from 'viem';
|
|
2
|
+
import { Hash, TransactionReceipt } from 'viem';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
3
4
|
import { WriteResult } from './write-types.js';
|
|
4
5
|
/**
|
|
5
6
|
* Options for {@link resolveWriteResult}.
|
|
@@ -18,16 +19,66 @@ interface ResolveWriteResultOptions {
|
|
|
18
19
|
/** Confirmations to wait for when `waitForReceipt` is true. Defaults to `1`. */
|
|
19
20
|
confirmations?: number;
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* The error every write hook throws when its transaction was mined but reverted
|
|
24
|
+
* on-chain.
|
|
25
|
+
*
|
|
26
|
+
* A subclass of {@link SymmioRequestError} with `kind: "contract-revert"`, so
|
|
27
|
+
* existing consumer branches (`error.kind === "contract-revert"`) keep working
|
|
28
|
+
* unchanged and {@link normalizeSymmError} passes it through untouched. It adds
|
|
29
|
+
* the `hash` and the mined `receipt` on top, so a UI can link the failure to a
|
|
30
|
+
* block explorer and read `gasUsed` / `blockNumber` without unwrapping `cause`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const { error } = useAllocate();
|
|
35
|
+
* if (error instanceof TransactionRevertedError) {
|
|
36
|
+
* return <a href={`${explorer}/tx/${error.hash}`}>Transaction reverted</a>;
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class TransactionRevertedError extends SymmioRequestError {
|
|
41
|
+
/** The reverted transaction's hash. */
|
|
42
|
+
readonly hash: Hash;
|
|
43
|
+
/** The mined receipt whose `status` is `"reverted"`. */
|
|
44
|
+
readonly receipt: TransactionReceipt;
|
|
45
|
+
/**
|
|
46
|
+
* @param options - The submitted hash and the mined receipt that reported the revert.
|
|
47
|
+
*/
|
|
48
|
+
constructor(options: {
|
|
49
|
+
hash: Hash;
|
|
50
|
+
receipt: TransactionReceipt;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
21
53
|
/**
|
|
22
54
|
* Shared tail of every write hook's `mutationFn`. Given a submitted transaction
|
|
23
55
|
* `hash`, either return it immediately (`waitForReceipt: false`) or poll for the
|
|
24
56
|
* mined receipt and return both. Applies the package-wide write defaults
|
|
25
57
|
* (`waitForReceipt: true`, `confirmations: 1`).
|
|
26
58
|
*
|
|
59
|
+
* A mined-but-reverted transaction is a **failure**, not a result: it throws
|
|
60
|
+
* {@link TransactionRevertedError} instead of returning, so the hook's
|
|
61
|
+
* `onSuccess` (and its cache invalidation) never runs for a write that applied
|
|
62
|
+
* nothing.
|
|
63
|
+
*
|
|
64
|
+
* **A relayed write waits on its request, not on its first hash.** When the
|
|
65
|
+
* dispatcher relayed the write, the hash it returned is only the relayer's
|
|
66
|
+
* first broadcast: a gas bump or a stuck nonce makes the service replace it,
|
|
67
|
+
* and waiting on a replaced hash waits forever. So a relayed write is followed
|
|
68
|
+
* through `confirmGaslessRequest`, which resolves on the terminal record, and
|
|
69
|
+
* the result reports that record's hash plus `gasless: { requestId,
|
|
70
|
+
* broadcastHash }`. A relay that ends `reverted` / `failed` / `rejected` throws
|
|
71
|
+
* the typed gasless error carrying the record, instead of
|
|
72
|
+
* {@link TransactionRevertedError}, because the relayer's verdict names the
|
|
73
|
+
* cause and a receipt for the replaced hash may not exist at all.
|
|
74
|
+
*
|
|
27
75
|
* @param config - The SDK config (its `getClient` resolves the polling client).
|
|
28
76
|
* @param hash - The submitted transaction hash.
|
|
29
77
|
* @param options - Chain id and receipt-wait behavior.
|
|
30
|
-
* @returns The hash, plus the receipt when `waitForReceipt` is enabled.
|
|
78
|
+
* @returns The hash, plus the receipt when `waitForReceipt` is enabled, plus `gasless` for a relayed write.
|
|
79
|
+
* @throws {TransactionRevertedError} when the mined receipt's `status` is `"reverted"`.
|
|
80
|
+
* @throws {SymmApiError} `GASLESS_RELAY_REVERTED` / `GASLESS_RELAY_FAILED` /
|
|
81
|
+
* `GASLESS_RELAY_REJECTED` when a relayed write's request ends non-succeeded.
|
|
31
82
|
*
|
|
32
83
|
* @example
|
|
33
84
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-write-result.d.ts","sourceRoot":"","sources":["../../src/transactions/resolve-write-result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"resolve-write-result.d.ts","sourceRoot":"","sources":["../../src/transactions/resolve-write-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EAEZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;GAEG;AACH,UAAU,yBAAyB;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,wBAAyB,SAAQ,kBAAkB;IAC9D,uCAAuC;IACvC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IAErC;;OAEG;gBACS,OAAO,EAAE;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,kBAAkB,CAAA;KAAE;CASjE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,WAAW,CAAC,CAmBtB"}
|
|
@@ -1,15 +1,58 @@
|
|
|
1
|
+
import { SymmioRequestError as e } from "../errors/symmio-request-error.js";
|
|
2
|
+
import { confirmGaslessRequest as t, getGaslessWriteRequest as n } from "@symmio/trading-core";
|
|
1
3
|
//#region src/transactions/resolve-write-result.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
var r = class extends e {
|
|
5
|
+
hash;
|
|
6
|
+
receipt;
|
|
7
|
+
constructor(e) {
|
|
8
|
+
super({
|
|
9
|
+
kind: "contract-revert",
|
|
10
|
+
code: "TRANSACTION_REVERTED",
|
|
11
|
+
message: `Transaction ${e.hash} was mined but reverted on-chain — no state change was applied.`
|
|
12
|
+
}), this.hash = e.hash, this.receipt = e.receipt;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
async function i(e, t, i = {}) {
|
|
16
|
+
let { chainId: s, waitForReceipt: c = !0, confirmations: l = 1 } = i, u = n(e, { hash: t });
|
|
17
|
+
if (!c) return u ? {
|
|
18
|
+
hash: t,
|
|
19
|
+
gasless: a(u)
|
|
10
20
|
} : { hash: t };
|
|
21
|
+
if (u) return o(e, u, l);
|
|
22
|
+
let d = await e.getClient({ chainId: s }).waitForTransactionReceipt({
|
|
23
|
+
hash: t,
|
|
24
|
+
confirmations: l
|
|
25
|
+
});
|
|
26
|
+
if (d?.status === "reverted") throw new r({
|
|
27
|
+
hash: t,
|
|
28
|
+
receipt: d
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
hash: t,
|
|
32
|
+
receipt: d
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function a(e) {
|
|
36
|
+
return {
|
|
37
|
+
requestId: e.requestId,
|
|
38
|
+
broadcastHash: e.broadcastHash
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function o(e, n, r) {
|
|
42
|
+
let i = await t(e, {
|
|
43
|
+
chainId: n.chainId,
|
|
44
|
+
requestId: n.requestId,
|
|
45
|
+
service: n.service,
|
|
46
|
+
until: "receipt",
|
|
47
|
+
receiptConfirmations: r
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
hash: i.txHash,
|
|
51
|
+
receipt: i.receipt,
|
|
52
|
+
gasless: a(n)
|
|
53
|
+
};
|
|
11
54
|
}
|
|
12
55
|
//#endregion
|
|
13
|
-
export {
|
|
56
|
+
export { r as TransactionRevertedError, i as resolveWriteResult };
|
|
14
57
|
|
|
15
58
|
//# sourceMappingURL=resolve-write-result.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-write-result.js","names":[],"sources":["../../src/transactions/resolve-write-result.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"resolve-write-result.js","names":[],"sources":["../../src/transactions/resolve-write-result.ts"],"sourcesContent":["import {\n confirmGaslessRequest,\n getGaslessWriteRequest,\n type Config,\n type GaslessWriteRequest,\n} from \"@symmio/trading-core\";\nimport type { Hash, TransactionReceipt } from \"viem\";\nimport { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport type { WriteResult } from \"./write-types\";\n\n/**\n * Options for {@link resolveWriteResult}.\n */\ninterface ResolveWriteResultOptions {\n /**\n * Chain the transaction was submitted on. Resolves the public client that\n * polls for the receipt; omit to use the config's default chain.\n */\n chainId?: number;\n /**\n * Resolve only after the receipt is mined (default `true`). When `false`,\n * resolve immediately with just the hash.\n */\n waitForReceipt?: boolean;\n /** Confirmations to wait for when `waitForReceipt` is true. Defaults to `1`. */\n confirmations?: number;\n}\n\n/**\n * The error every write hook throws when its transaction was mined but reverted\n * on-chain.\n *\n * A subclass of {@link SymmioRequestError} with `kind: \"contract-revert\"`, so\n * existing consumer branches (`error.kind === \"contract-revert\"`) keep working\n * unchanged and {@link normalizeSymmError} passes it through untouched. It adds\n * the `hash` and the mined `receipt` on top, so a UI can link the failure to a\n * block explorer and read `gasUsed` / `blockNumber` without unwrapping `cause`.\n *\n * @example\n * ```ts\n * const { error } = useAllocate();\n * if (error instanceof TransactionRevertedError) {\n * return <a href={`${explorer}/tx/${error.hash}`}>Transaction reverted</a>;\n * }\n * ```\n */\nexport class TransactionRevertedError extends SymmioRequestError {\n /** The reverted transaction's hash. */\n readonly hash: Hash;\n /** The mined receipt whose `status` is `\"reverted\"`. */\n readonly receipt: TransactionReceipt;\n\n /**\n * @param options - The submitted hash and the mined receipt that reported the revert.\n */\n constructor(options: { hash: Hash; receipt: TransactionReceipt }) {\n super({\n kind: \"contract-revert\",\n code: \"TRANSACTION_REVERTED\",\n message: `Transaction ${options.hash} was mined but reverted on-chain — no state change was applied.`,\n });\n this.hash = options.hash;\n this.receipt = options.receipt;\n }\n}\n\n/**\n * Shared tail of every write hook's `mutationFn`. Given a submitted transaction\n * `hash`, either return it immediately (`waitForReceipt: false`) or poll for the\n * mined receipt and return both. Applies the package-wide write defaults\n * (`waitForReceipt: true`, `confirmations: 1`).\n *\n * A mined-but-reverted transaction is a **failure**, not a result: it throws\n * {@link TransactionRevertedError} instead of returning, so the hook's\n * `onSuccess` (and its cache invalidation) never runs for a write that applied\n * nothing.\n *\n * **A relayed write waits on its request, not on its first hash.** When the\n * dispatcher relayed the write, the hash it returned is only the relayer's\n * first broadcast: a gas bump or a stuck nonce makes the service replace it,\n * and waiting on a replaced hash waits forever. So a relayed write is followed\n * through `confirmGaslessRequest`, which resolves on the terminal record, and\n * the result reports that record's hash plus `gasless: { requestId,\n * broadcastHash }`. A relay that ends `reverted` / `failed` / `rejected` throws\n * the typed gasless error carrying the record, instead of\n * {@link TransactionRevertedError}, because the relayer's verdict names the\n * cause and a receipt for the replaced hash may not exist at all.\n *\n * @param config - The SDK config (its `getClient` resolves the polling client).\n * @param hash - The submitted transaction hash.\n * @param options - Chain id and receipt-wait behavior.\n * @returns The hash, plus the receipt when `waitForReceipt` is enabled, plus `gasless` for a relayed write.\n * @throws {TransactionRevertedError} when the mined receipt's `status` is `\"reverted\"`.\n * @throws {SymmApiError} `GASLESS_RELAY_REVERTED` / `GASLESS_RELAY_FAILED` /\n * `GASLESS_RELAY_REJECTED` when a relayed write's request ends non-succeeded.\n *\n * @example\n * ```ts\n * const hash = await base.mutationFn({ ...variables, chainId });\n * return resolveWriteResult(config, hash, { chainId, waitForReceipt, confirmations });\n * ```\n */\nexport async function resolveWriteResult(\n config: Config,\n hash: Hash,\n options: ResolveWriteResultOptions = {},\n): Promise<WriteResult> {\n const { chainId, waitForReceipt = true, confirmations = 1 } = options;\n const relayed = getGaslessWriteRequest(config, { hash });\n\n if (!waitForReceipt) {\n return relayed ? { hash, gasless: relayedHandle(relayed) } : { hash };\n }\n if (relayed) return resolveRelayedWriteResult(config, relayed, confirmations);\n const receipt = await config.getClient({ chainId }).waitForTransactionReceipt({ hash, confirmations });\n /**\n * Load-bearing, do not \"simplify\" away: viem does **not** throw for a reverted\n * transaction. `waitForTransactionReceipt` resolves normally and reports the\n * failure only through `receipt.status === \"reverted\"`. Without this explicit\n * check the shared write tail returns a success result for a transaction that\n * changed nothing, and every write hook — gasless and wallet alike — fires\n * `onSuccess`, invalidates its caches, and renders the write as applied.\n */\n if (receipt?.status === \"reverted\") throw new TransactionRevertedError({ hash, receipt });\n return { hash, receipt };\n}\n\n/** The part of a relay a write result carries: the durable id, and the hash that was shown. */\nfunction relayedHandle(relayed: GaslessWriteRequest): NonNullable<WriteResult[\"gasless\"]> {\n return { requestId: relayed.requestId, broadcastHash: relayed.broadcastHash };\n}\n\n/**\n * Follow a relayed write to its terminal record and report the hash that\n * actually mined. The receipt comes from *this config's* client, so the\n * invalidation that follows re-reads a node that has seen the block.\n */\nasync function resolveRelayedWriteResult(\n config: Config,\n relayed: GaslessWriteRequest,\n confirmations: number,\n): Promise<WriteResult> {\n const confirmed = await confirmGaslessRequest(config, {\n chainId: relayed.chainId,\n requestId: relayed.requestId,\n service: relayed.service,\n until: \"receipt\",\n receiptConfirmations: confirmations,\n });\n return { hash: confirmed.txHash, receipt: confirmed.receipt, gasless: relayedHandle(relayed) };\n}\n"],"mappings":";;;AA8CA,IAAa,IAAb,cAA8C,EAAmB;CAE/D;CAEA;CAKA,YAAY,GAAsD;EAOhE,AANA,MAAM;GACJ,MAAM;GACN,MAAM;GACN,SAAS,eAAe,EAAQ,KAAK;EACvC,CAAC,GACD,KAAK,OAAO,EAAQ,MACpB,KAAK,UAAU,EAAQ;CACzB;AACF;AAsCA,eAAsB,EACpB,GACA,GACA,IAAqC,CAAC,GAChB;CACtB,IAAM,EAAE,YAAS,oBAAiB,IAAM,mBAAgB,MAAM,GACxD,IAAU,EAAuB,GAAQ,EAAE,QAAK,CAAC;CAEvD,IAAI,CAAC,GACH,OAAO,IAAU;EAAE;EAAM,SAAS,EAAc,CAAO;CAAE,IAAI,EAAE,QAAK;CAEtE,IAAI,GAAS,OAAO,EAA0B,GAAQ,GAAS,CAAa;CAC5E,IAAM,IAAU,MAAM,EAAO,UAAU,EAAE,WAAQ,CAAC,EAAE,0BAA0B;EAAE;EAAM;CAAc,CAAC;CASrG,IAAI,GAAS,WAAW,YAAY,MAAM,IAAI,EAAyB;EAAE;EAAM;CAAQ,CAAC;CACxF,OAAO;EAAE;EAAM;CAAQ;AACzB;AAGA,SAAS,EAAc,GAAmE;CACxF,OAAO;EAAE,WAAW,EAAQ;EAAW,eAAe,EAAQ;CAAc;AAC9E;AAOA,eAAe,EACb,GACA,GACA,GACsB;CACtB,IAAM,IAAY,MAAM,EAAsB,GAAQ;EACpD,SAAS,EAAQ;EACjB,WAAW,EAAQ;EACnB,SAAS,EAAQ;EACjB,OAAO;EACP,sBAAsB;CACxB,CAAC;CACD,OAAO;EAAE,MAAM,EAAU;EAAQ,SAAS,EAAU;EAAS,SAAS,EAAc,CAAO;CAAE;AAC/F"}
|
|
@@ -20,9 +20,27 @@ export interface WriteParameters extends ConfigParameter {
|
|
|
20
20
|
* mined receipt when `waitForReceipt` is enabled.
|
|
21
21
|
*/
|
|
22
22
|
export interface WriteResult {
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* The transaction hash the write landed on. For a relayed (gasless) write
|
|
25
|
+
* this is the **terminal** hash the request actually mined, which is not
|
|
26
|
+
* necessarily the relayer's first broadcast — see
|
|
27
|
+
* {@link WriteResult.gasless}.
|
|
28
|
+
*/
|
|
24
29
|
hash: Hash;
|
|
25
30
|
/** The mined receipt, present when `waitForReceipt` is enabled. */
|
|
26
31
|
receipt?: TransactionReceipt;
|
|
32
|
+
/**
|
|
33
|
+
* Present only when the write was relayed through GaslessQ instead of the
|
|
34
|
+
* wallet. The `requestId` is the workflow's stable handle — persist it, it is
|
|
35
|
+
* what survives a replaced transaction and a reload — while `broadcastHash`
|
|
36
|
+
* is the relayer's first attempt, kept so a UI that already showed it can
|
|
37
|
+
* reconcile.
|
|
38
|
+
*/
|
|
39
|
+
gasless?: {
|
|
40
|
+
/** Stable service tracking id of the relay request. */
|
|
41
|
+
requestId: string;
|
|
42
|
+
/** The relayer's first broadcast hash, which `hash` may supersede. */
|
|
43
|
+
broadcastHash: Hash;
|
|
44
|
+
};
|
|
27
45
|
}
|
|
28
46
|
//# sourceMappingURL=write-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-types.d.ts","sourceRoot":"","sources":["../../src/transactions/write-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAErD;;;;;GAKG;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B
|
|
1
|
+
{"version":3,"file":"write-types.d.ts","sourceRoot":"","sources":["../../src/transactions/write-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAErD;;;;;GAKG;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,IAAI,EAAE,IAAI,CAAC;IACX,mEAAmE;IACnE,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE;QACR,uDAAuD;QACvD,SAAS,EAAE,MAAM,CAAC;QAClB,sEAAsE;QACtE,aAAa,EAAE,IAAI,CAAC;KACrB,CAAC;CACH"}
|
|
@@ -5,13 +5,16 @@ import { Query, QueryKey } from '@tanstack/react-query';
|
|
|
5
5
|
*
|
|
6
6
|
* A cache entry matches when:
|
|
7
7
|
* 1. its key's leading tag equals the factory's tag (the key's first segment), and
|
|
8
|
-
* 2. for every field
|
|
9
|
-
* equal value. Omitted fields match anything.
|
|
8
|
+
* 2. for every field the partial sets, the key's trailing options object has an
|
|
9
|
+
* equal value. Omitted (or `undefined`) fields match anything.
|
|
10
10
|
*
|
|
11
11
|
* Both the partial and the stored keys are run through the same factory, so
|
|
12
12
|
* `bigint` values are compared in the decimal-string form the factory emits.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* A default the factory fills in for an omitted field (an omitted gasless
|
|
14
|
+
* `walletId` keys as `0n`) is not compared, so leaving that field out still
|
|
15
|
+
* matches every value of it. This enables "invalidate every subaccount query for
|
|
16
|
+
* `user`, regardless of pagination or chain" — which TanStack's leading-prefix
|
|
17
|
+
* matching can't express.
|
|
15
18
|
*
|
|
16
19
|
* @param keyFn - A core query-key factory, e.g. `getUserSubAccountsQueryKey`.
|
|
17
20
|
* @param partial - Fields to match on. Omit to match every entry from `keyFn`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predicate-match.d.ts","sourceRoot":"","sources":["../../src/utils/predicate-match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAE7D
|
|
1
|
+
{"version":3,"file":"predicate-match.d.ts","sourceRoot":"","sources":["../../src/utils/predicate-match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,EACnD,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,SAAS,OAAO,EAAE,EAChD,OAAO,CAAC,EAAE,OAAO,GAChB,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,OAAO,CAuB9D"}
|