@symmio/trading-react 2.0.0 → 3.0.1-staging-20260926093035
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-deallocate-and-initiate-withdraw.d.ts +1 -1
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.js.map +1 -1
- package/dist/estimated-price/use-estimated-price.d.ts +6 -3
- package/dist/estimated-price/use-estimated-price.d.ts.map +1 -1
- package/dist/estimated-price/use-estimated-price.js +12 -9
- package/dist/estimated-price/use-estimated-price.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +169 -165
- package/dist/instant-layer/get-instant-open-funding-error.d.ts +5 -0
- package/dist/instant-layer/get-instant-open-funding-error.d.ts.map +1 -0
- package/dist/instant-layer/get-instant-open-funding-error.js +15 -0
- package/dist/instant-layer/get-instant-open-funding-error.js.map +1 -0
- package/dist/instant-layer/index.d.ts +4 -0
- package/dist/instant-layer/index.d.ts.map +1 -1
- package/dist/instant-layer/index.js +15 -11
- package/dist/instant-layer/use-instant-close-fees.d.ts +46 -0
- package/dist/instant-layer/use-instant-close-fees.d.ts.map +1 -0
- package/dist/instant-layer/use-instant-close-fees.js +83 -0
- package/dist/instant-layer/use-instant-close-fees.js.map +1 -0
- package/dist/instant-layer/use-instant-open-auto.d.ts +5 -0
- package/dist/instant-layer/use-instant-open-auto.d.ts.map +1 -1
- package/dist/instant-layer/use-instant-open-auto.js.map +1 -1
- package/dist/instant-layer/use-instant-open-fees.d.ts +66 -0
- package/dist/instant-layer/use-instant-open-fees.d.ts.map +1 -0
- package/dist/instant-layer/use-instant-open-fees.js +35 -0
- package/dist/instant-layer/use-instant-open-fees.js.map +1 -0
- package/dist/instant-layer/use-instant-open-inputs.d.ts +35 -0
- package/dist/instant-layer/use-instant-open-inputs.d.ts.map +1 -0
- package/dist/instant-layer/use-instant-open-inputs.js +134 -0
- package/dist/instant-layer/use-instant-open-inputs.js.map +1 -0
- package/dist/instant-layer/use-instant-open-with-tpsl.d.ts +6 -0
- package/dist/instant-layer/use-instant-open-with-tpsl.d.ts.map +1 -1
- package/dist/instant-layer/use-instant-open-with-tpsl.js.map +1 -1
- package/dist/instant-layer/use-instant-trade-required-selectors.d.ts +25 -0
- package/dist/instant-layer/use-instant-trade-required-selectors.d.ts.map +1 -0
- package/dist/instant-layer/use-instant-trade-required-selectors.js +13 -0
- package/dist/instant-layer/use-instant-trade-required-selectors.js.map +1 -0
- package/dist/instant-layer/use-prepare-instant-open-params.d.ts +69 -0
- package/dist/instant-layer/use-prepare-instant-open-params.d.ts.map +1 -0
- package/dist/instant-layer/use-prepare-instant-open-params.js +36 -0
- package/dist/instant-layer/use-prepare-instant-open-params.js.map +1 -0
- package/dist/margin/use-available-instant-open-margin.d.ts +3 -2
- package/dist/margin/use-available-instant-open-margin.d.ts.map +1 -1
- package/dist/margin/use-available-instant-open-margin.js +4 -5
- package/dist/margin/use-available-instant-open-margin.js.map +1 -1
- package/dist/price-service/index.js +4 -4
- package/dist/provider/symmio-provider.d.ts +1 -1
- package/dist/provider/symmio-provider.js.map +1 -1
- package/dist/rasa-solver/index.d.ts +0 -1
- package/dist/rasa-solver/index.d.ts.map +1 -1
- package/dist/solvers/index.d.ts +1 -0
- package/dist/solvers/index.d.ts.map +1 -1
- package/dist/solvers/use-solver-info.d.ts +14 -0
- package/dist/solvers/use-solver-info.d.ts.map +1 -0
- package/dist/solvers/use-solver-info.js +27 -0
- package/dist/solvers/use-solver-info.js.map +1 -0
- package/dist/solvers/use-solver-revenue.d.ts +7 -5
- package/dist/solvers/use-solver-revenue.d.ts.map +1 -1
- package/dist/solvers/use-solver-revenue.js +1 -1
- package/dist/solvers/use-solver-revenue.js.map +1 -1
- package/dist/withdraw/use-initiate-withdraw.d.ts +1 -1
- package/dist/withdraw/use-initiate-withdraw.js.map +1 -1
- package/package.json +2 -2
- package/dist/rasa-solver/use-add-solver-whitelist.d.ts +0 -21
- package/dist/rasa-solver/use-add-solver-whitelist.d.ts.map +0 -1
- package/dist/rasa-solver/use-add-solver-whitelist.js +0 -27
- package/dist/rasa-solver/use-add-solver-whitelist.js.map +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ConfigParameter, PrepareInstantOpenParamsOptions, PrepareInstantOpenParamsReturnType } from '@symmio/trading-core';
|
|
2
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
|
+
/**
|
|
5
|
+
* Parameters for {@link usePrepareInstantOpenParams}: the same trade intent the
|
|
6
|
+
* submit takes (`subAccountAddress`, `from`, `market`, `positionType`,
|
|
7
|
+
* `initialMargin` **or** `fund`, optional `availableBalance` for automatic sizing,
|
|
8
|
+
* `leverage`, optional `slippage` / pre-fetched
|
|
9
|
+
* data, TanStack `query` overrides) plus an optional `config`.
|
|
10
|
+
*/
|
|
11
|
+
export type UsePrepareInstantOpenParamsParameters = PrepareInstantOpenParamsOptions & ConfigParameter;
|
|
12
|
+
/**
|
|
13
|
+
* Return type of {@link usePrepareInstantOpenParams}: the query result carrying
|
|
14
|
+
* the prepared {@link PrepareInstantOpenParamsReturnType}, plus the dry-run estimate the
|
|
15
|
+
* params were built with.
|
|
16
|
+
*/
|
|
17
|
+
export type UsePrepareInstantOpenParamsReturnType = UseQueryResult<PrepareInstantOpenParamsReturnType, SymmioRequestError> & {
|
|
18
|
+
/**
|
|
19
|
+
* The dry-run estimate the preview was built with (`null` when unavailable;
|
|
20
|
+
* `undefined` while pending or on a non-lowcap solver). Forward it as
|
|
21
|
+
* `estimatedOpenPrice` to the submit so its `margin.amount` — whose settlement leg tracks the estimate — matches this
|
|
22
|
+
* preview bit-for-bit.
|
|
23
|
+
*/
|
|
24
|
+
estimatedOpenPrice: string | null | undefined;
|
|
25
|
+
/** Synchronous input error. Display before query.error; dependent queries stay disabled. */
|
|
26
|
+
validationError: SymmioRequestError | undefined;
|
|
27
|
+
/** True when all inputs and the current preparation have settled; gate submission on this. */
|
|
28
|
+
isReady: boolean;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Live-preview the exact {@link PrepareInstantOpenParamsReturnType} an instant-open submit
|
|
32
|
+
* will sign — `order` (price + quantity), `lockedParam`, `margin.amount`, and
|
|
33
|
+
* `solverFeeCaps` — by running `prepareInstantOpenParams` as a read.
|
|
34
|
+
* `prepareInstantOpenParams` neither signs nor submits, so this is safe to run
|
|
35
|
+
* live; drive a "quote preview" from it and what the user sees is bit-for-bit
|
|
36
|
+
* what `sendQuote` receives, with no separate local recomputation to drift.
|
|
37
|
+
*
|
|
38
|
+
* Like {@link useInstantOpenFees}, it **pre-fetches every input through its own
|
|
39
|
+
* cached queries** (market metadata, mark price, locked params, on-chain fee
|
|
40
|
+
* rates, solver info, and the lowcap dry-run estimate) and passes them in as
|
|
41
|
+
* prefills, so the query function is pure and does no per-render network. Previous data is kept
|
|
42
|
+
* while inputs move, so a mark-price tick updates the numbers in place.
|
|
43
|
+
*
|
|
44
|
+
* For bit-for-bit parity on `margin.amount`, forward {@link
|
|
45
|
+
* UsePrepareInstantOpenParamsReturnType.estimatedOpenPrice} to the submit call
|
|
46
|
+
* (`useInstantOpenAuto` / `useInstantOpenWithTpSl`) as `estimatedOpenPrice`, so
|
|
47
|
+
* both the preview and the send provision settlement at the same estimate. The
|
|
48
|
+
* full-balance sizing decision and quantity also depend on that estimate.
|
|
49
|
+
* Gate submission on `isReady` while inputs or the estimate are settling.
|
|
50
|
+
* Display `validationError ?? error`; input errors are synchronous, including offline.
|
|
51
|
+
* A disabled hook or empty input remains idle without input validation.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* const preview = usePrepareInstantOpenParams({
|
|
56
|
+
* subAccountAddress,
|
|
57
|
+
* from: sessionKey,
|
|
58
|
+
* market: { id: symbolId },
|
|
59
|
+
* positionType,
|
|
60
|
+
* initialMargin,
|
|
61
|
+
* leverage,
|
|
62
|
+
* slippage,
|
|
63
|
+
* });
|
|
64
|
+
* // preview.data?.order.quantity — the exact leveraged quantity (wei) the send signs
|
|
65
|
+
* // submit: mutate({ …, estimatedOpenPrice: preview.estimatedOpenPrice })
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function usePrepareInstantOpenParams(parameters: UsePrepareInstantOpenParamsParameters): UsePrepareInstantOpenParamsReturnType;
|
|
69
|
+
//# sourceMappingURL=use-prepare-instant-open-params.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-prepare-instant-open-params.d.ts","sourceRoot":"","sources":["../../src/instant-layer/use-prepare-instant-open-params.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,+BAA+B,EACpC,KAAK,kCAAkC,EACxC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE;;;;;;GAMG;AACH,MAAM,MAAM,qCAAqC,GAAG,+BAA+B,GAAG,eAAe,CAAC;AAEtG;;;;GAIG;AACH,MAAM,MAAM,qCAAqC,GAAG,cAAc,CAChE,kCAAkC,EAClC,kBAAkB,CACnB,GAAG;IACF;;;;;OAKG;IACH,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9C,4FAA4F;IAC5F,eAAe,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAChD,8FAA8F;IAC9F,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,qCAAqC,GAChD,qCAAqC,CA4BvC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { normalizeSymmError as e } from "../errors/normalize-symm-error.js";
|
|
3
|
+
import { useInstantOpenInputs as t } from "./use-instant-open-inputs.js";
|
|
4
|
+
import { prepareInstantOpenParamsQueryOptions as n } from "@symmio/trading-core";
|
|
5
|
+
import { useQuery as r } from "@tanstack/react-query";
|
|
6
|
+
//#region src/instant-layer/use-prepare-instant-open-params.ts
|
|
7
|
+
function i(i) {
|
|
8
|
+
let a = t(i, "prepare", i.query?.enabled !== !1), o = n(a.config, {
|
|
9
|
+
...i,
|
|
10
|
+
...a.prefills,
|
|
11
|
+
query: {
|
|
12
|
+
...i.query,
|
|
13
|
+
enabled: a.ready,
|
|
14
|
+
placeholderData: (e) => a.validationError === void 0 ? e : void 0
|
|
15
|
+
}
|
|
16
|
+
}), s = r({
|
|
17
|
+
...o,
|
|
18
|
+
queryFn: async () => {
|
|
19
|
+
try {
|
|
20
|
+
return await o.queryFn();
|
|
21
|
+
} catch (t) {
|
|
22
|
+
throw e(t);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
...s,
|
|
28
|
+
validationError: a.validationError,
|
|
29
|
+
estimatedOpenPrice: a.prefills.estimatedOpenPrice,
|
|
30
|
+
isReady: a.ready && s.isSuccess && !s.isFetching && !s.isPlaceholderData
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { i as usePrepareInstantOpenParams };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=use-prepare-instant-open-params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-prepare-instant-open-params.js","names":[],"sources":["../../src/instant-layer/use-prepare-instant-open-params.ts"],"sourcesContent":["\"use client\";\n\nimport {\n prepareInstantOpenParamsQueryOptions,\n type ConfigParameter,\n type PrepareInstantOpenParamsOptions,\n type PrepareInstantOpenParamsReturnType,\n} from \"@symmio/trading-core\";\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useInstantOpenInputs } from \"./use-instant-open-inputs\";\n\n/**\n * Parameters for {@link usePrepareInstantOpenParams}: the same trade intent the\n * submit takes (`subAccountAddress`, `from`, `market`, `positionType`,\n * `initialMargin` **or** `fund`, optional `availableBalance` for automatic sizing,\n * `leverage`, optional `slippage` / pre-fetched\n * data, TanStack `query` overrides) plus an optional `config`.\n */\nexport type UsePrepareInstantOpenParamsParameters = PrepareInstantOpenParamsOptions & ConfigParameter;\n\n/**\n * Return type of {@link usePrepareInstantOpenParams}: the query result carrying\n * the prepared {@link PrepareInstantOpenParamsReturnType}, plus the dry-run estimate the\n * params were built with.\n */\nexport type UsePrepareInstantOpenParamsReturnType = UseQueryResult<\n PrepareInstantOpenParamsReturnType,\n SymmioRequestError\n> & {\n /**\n * The dry-run estimate the preview was built with (`null` when unavailable;\n * `undefined` while pending or on a non-lowcap solver). Forward it as\n * `estimatedOpenPrice` to the submit so its `margin.amount` — whose settlement leg tracks the estimate — matches this\n * preview bit-for-bit.\n */\n estimatedOpenPrice: string | null | undefined;\n /** Synchronous input error. Display before query.error; dependent queries stay disabled. */\n validationError: SymmioRequestError | undefined;\n /** True when all inputs and the current preparation have settled; gate submission on this. */\n isReady: boolean;\n};\n\n/**\n * Live-preview the exact {@link PrepareInstantOpenParamsReturnType} an instant-open submit\n * will sign — `order` (price + quantity), `lockedParam`, `margin.amount`, and\n * `solverFeeCaps` — by running `prepareInstantOpenParams` as a read.\n * `prepareInstantOpenParams` neither signs nor submits, so this is safe to run\n * live; drive a \"quote preview\" from it and what the user sees is bit-for-bit\n * what `sendQuote` receives, with no separate local recomputation to drift.\n *\n * Like {@link useInstantOpenFees}, it **pre-fetches every input through its own\n * cached queries** (market metadata, mark price, locked params, on-chain fee\n * rates, solver info, and the lowcap dry-run estimate) and passes them in as\n * prefills, so the query function is pure and does no per-render network. Previous data is kept\n * while inputs move, so a mark-price tick updates the numbers in place.\n *\n * For bit-for-bit parity on `margin.amount`, forward {@link\n * UsePrepareInstantOpenParamsReturnType.estimatedOpenPrice} to the submit call\n * (`useInstantOpenAuto` / `useInstantOpenWithTpSl`) as `estimatedOpenPrice`, so\n * both the preview and the send provision settlement at the same estimate. The\n * full-balance sizing decision and quantity also depend on that estimate.\n * Gate submission on `isReady` while inputs or the estimate are settling.\n * Display `validationError ?? error`; input errors are synchronous, including offline.\n * A disabled hook or empty input remains idle without input validation.\n *\n * @example\n * ```tsx\n * const preview = usePrepareInstantOpenParams({\n * subAccountAddress,\n * from: sessionKey,\n * market: { id: symbolId },\n * positionType,\n * initialMargin,\n * leverage,\n * slippage,\n * });\n * // preview.data?.order.quantity — the exact leveraged quantity (wei) the send signs\n * // submit: mutate({ …, estimatedOpenPrice: preview.estimatedOpenPrice })\n * ```\n */\nexport function usePrepareInstantOpenParams(\n parameters: UsePrepareInstantOpenParamsParameters,\n): UsePrepareInstantOpenParamsReturnType {\n const inputs = useInstantOpenInputs(parameters, \"prepare\", parameters.query?.enabled !== false);\n const options = prepareInstantOpenParamsQueryOptions(inputs.config, {\n ...parameters,\n ...inputs.prefills,\n query: {\n ...parameters.query,\n enabled: inputs.ready,\n placeholderData: (previous) => (inputs.validationError === undefined ? previous : undefined),\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<PrepareInstantOpenParamsReturnType, SymmioRequestError>;\n\n return {\n ...query,\n validationError: inputs.validationError,\n estimatedOpenPrice: inputs.prefills.estimatedOpenPrice,\n isReady: inputs.ready && query.isSuccess && !query.isFetching && !query.isPlaceholderData,\n };\n}\n"],"mappings":";;;;;;AAkFA,SAAgB,EACd,GACuC;CACvC,IAAM,IAAS,EAAqB,GAAY,WAAW,EAAW,OAAO,YAAY,EAAK,GACxF,IAAU,EAAqC,EAAO,QAAQ;EAClE,GAAG;EACH,GAAG,EAAO;EACV,OAAO;GACL,GAAG,EAAW;GACd,SAAS,EAAO;GAChB,kBAAkB,MAAc,EAAO,oBAAoB,KAAA,IAAY,IAAW,KAAA;EACpF;CACF,CAAC,GACK,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;EACL,GAAG;EACH,iBAAiB,EAAO;EACxB,oBAAoB,EAAO,SAAS;EACpC,SAAS,EAAO,SAAS,EAAM,aAAa,CAAC,EAAM,cAAc,CAAC,EAAM;CAC1E;AACF"}
|
|
@@ -41,9 +41,10 @@ export interface UseAvailableInstantOpenMarginReturnType {
|
|
|
41
41
|
* type:
|
|
42
42
|
*
|
|
43
43
|
* - **VA isolations** (`POSITION` / `MARKET` / `MARKET_DIRECTION`): the
|
|
44
|
-
* sub-account's available balance shaved for
|
|
44
|
+
* sub-account's available balance shaved for the open fee and — SHORT only — a
|
|
45
45
|
* worst-case slippage fill (`calculateAvailableInstantOpenMargin` over
|
|
46
|
-
* {@link useAccountBalanceOf} + {@link useFeeForUser}).
|
|
46
|
+
* {@link useAccountBalanceOf} + {@link useFeeForUser}). The close fee is
|
|
47
|
+
* charged at close, so it is not reserved here.
|
|
47
48
|
* - **`CUSTOM` (cross-margin)** — trades execute on the sub-account directly:
|
|
48
49
|
* `calculateAvailableForOrder` over the live `balanceInfoOfPartyA` snapshot
|
|
49
50
|
* and the account's SDK-computed uPnL ({@link useAccountUpnl} — Σ
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-available-instant-open-margin.d.ts","sourceRoot":"","sources":["../../src/margin/use-available-instant-open-margin.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,YAAY,EAEZ,KAAK,eAAe,EACpB,KAAK,QAAQ,EACd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAA4B,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAI9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAqBzE,4DAA4D;AAC5D,MAAM,WAAW,uCAAwC,SAAQ,eAAe;IAC9E,yEAAyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,YAAY,EAAE,YAAY,CAAC;IAC3B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,4DAA4D;AAC5D,MAAM,WAAW,uCAAuC;IACtD,iFAAiF;IACjF,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,sHAAsH;IACtH,eAAe,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,SAAS,EAAE,OAAO,CAAC;IACnB,wDAAwD;IACxD,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACjC,qFAAqF;IACrF,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED
|
|
1
|
+
{"version":3,"file":"use-available-instant-open-margin.d.ts","sourceRoot":"","sources":["../../src/margin/use-available-instant-open-margin.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,YAAY,EAEZ,KAAK,eAAe,EACpB,KAAK,QAAQ,EACd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAA4B,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAI9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAqBzE,4DAA4D;AAC5D,MAAM,WAAW,uCAAwC,SAAQ,eAAe;IAC9E,yEAAyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,YAAY,EAAE,YAAY,CAAC;IAC3B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,4DAA4D;AAC5D,MAAM,WAAW,uCAAuC;IACtD,iFAAiF;IACjF,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,sHAAsH;IACtH,eAAe,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,SAAS,EAAE,OAAO,CAAC;IACnB,wDAAwD;IACxD,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACjC,qFAAqF;IACrF,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,uCAAuC,GAClD,uCAAuC,CAwHzC"}
|
|
@@ -3,8 +3,8 @@ import { useSymmioConfig as e } from "../provider/use-symmio-config.js";
|
|
|
3
3
|
import { useAccountBalanceInfo as t } from "../account-layer/use-account-balance-info.js";
|
|
4
4
|
import { useAccountBalanceOf as n } from "../account-layer/use-account-balance-of.js";
|
|
5
5
|
import { useSubAccount as r } from "../account-layer/use-sub-account.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { useFeeForUser as i } from "../fees/use-fee-for-user.js";
|
|
7
|
+
import { useAccountUpnl as a } from "../quotes/use-account-upnl.js";
|
|
8
8
|
import { SubAccountIsolationType as o, calculateAvailableForOrder as s, calculateAvailableInstantOpenMargin as c } from "@symmio/trading-core";
|
|
9
9
|
import { useCallback as l, useMemo as u } from "react";
|
|
10
10
|
import { formatUnits as d, zeroAddress as f } from "viem";
|
|
@@ -31,7 +31,7 @@ function h(h) {
|
|
|
31
31
|
config: C,
|
|
32
32
|
live: !0,
|
|
33
33
|
query: { enabled: D && !O }
|
|
34
|
-
}), A =
|
|
34
|
+
}), A = i({
|
|
35
35
|
user: g ?? f,
|
|
36
36
|
symbolId: _ ?? 0,
|
|
37
37
|
chainId: S,
|
|
@@ -43,7 +43,7 @@ function h(h) {
|
|
|
43
43
|
config: C,
|
|
44
44
|
live: !0,
|
|
45
45
|
query: { enabled: O && !!g }
|
|
46
|
-
}), M =
|
|
46
|
+
}), M = a({
|
|
47
47
|
account: g,
|
|
48
48
|
chainId: S,
|
|
49
49
|
solverId: x,
|
|
@@ -97,7 +97,6 @@ function h(h) {
|
|
|
97
97
|
let r = c({
|
|
98
98
|
balance: N,
|
|
99
99
|
openFee: L.openFee,
|
|
100
|
-
closeFee: L.closeFee,
|
|
101
100
|
slippageFractionWei: p(b),
|
|
102
101
|
leverage: v,
|
|
103
102
|
positionType: y
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-available-instant-open-margin.js","names":[],"sources":["../../src/margin/use-available-instant-open-margin.ts"],"sourcesContent":["\"use client\";\n\nimport {\n calculateAvailableForOrder,\n calculateAvailableInstantOpenMargin,\n PositionType,\n SubAccountIsolationType,\n type ConfigParameter,\n type SolverId,\n} from \"@symmio/trading-core\";\nimport { useCallback, useMemo } from \"react\";\nimport { formatUnits, zeroAddress, type Address } from \"viem\";\nimport { useAccountBalanceInfo } from \"../account-layer/use-account-balance-info\";\nimport { useAccountBalanceOf } from \"../account-layer/use-account-balance-of\";\nimport { useSubAccount } from \"../account-layer/use-sub-account\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useFeeForUser } from \"../fees/use-fee-for-user\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { useAccountUpnl } from \"../quotes/use-account-upnl\";\n\n/** Convert a slippage percent (e.g. `5`) to an 18-decimal fraction (`5e16`). */\nfunction slippagePercentToFractionWei(slippage: number): bigint {\n return BigInt(Math.round(slippage * 1e16));\n}\n\n/**\n * **Rasa-specific policy**: the fraction of a cross-margin account's\n * `availableForOrder` a new open may spend, in basis points (90%). The\n * remaining 10% stays as a safety buffer so a fill at a slightly worse price\n * or a fee charge cannot tip the account straight into deficiency.\n *\n * Applied only when the resolved solver is Rasa — a future cross-margin solver\n * spends 100% unless its vendor mandates its own buffer.\n */\nconst RASA_SPENDABLE_BPS = 9_000n;\n\n/** Parameters for {@link useAvailableInstantOpenMargin}. */\nexport interface UseAvailableInstantOpenMarginParameters extends ConfigParameter {\n /** SubAccount to spend margin from. The hook is idle until it is set. */\n account?: Address;\n /** Market symbol id, for the fee lookup. Idle until it is set. */\n symbolId?: bigint | number;\n /** Requested leverage (integer ≥ 1). */\n leverage: number;\n /** LONG skips the slippage cap; SHORT applies it. */\n positionType: PositionType;\n /** Slippage percent, e.g. `5`. */\n slippage: number;\n /**\n * Solver whose markets and price provider value the cross-margin uPnL.\n * Defaults to the chain's default solver. The margin **model** is not chosen\n * here — it follows the sub-account's isolation type.\n */\n solverId?: SolverId;\n /** Optional chain override; defaults to the connected chain. */\n chainId?: number;\n}\n\n/** Return type of {@link useAvailableInstantOpenMargin}. */\nexport interface UseAvailableInstantOpenMarginReturnType {\n /** Spendable margin in 18-decimal wei; `undefined` until balance + fees load. */\n availableMarginWei: bigint | undefined;\n /** {@link UseAvailableInstantOpenMarginReturnType.availableMarginWei} as a decimal string; `\"0\"` when unavailable. */\n availableMargin: string;\n /** `true` while the underlying balance / fee reads are loading. */\n isLoading: boolean;\n /** First error from the balance / fee reads, if any. */\n error: SymmioRequestError | null;\n /** Refetch the underlying balance + fee reads (e.g. after an open/close settles). */\n refetch: () => Promise<void>;\n}\n\n/**\n * Maximum initial margin an instant open can spend for `account` on a market —\n * **the** margin hook. The margin model follows the sub-account's isolation\n * type:\n *\n * - **VA isolations** (`POSITION` / `MARKET` / `MARKET_DIRECTION`): the\n * sub-account's available balance shaved for fees and — SHORT only — a\n * worst-case slippage fill (`calculateAvailableInstantOpenMargin` over\n * {@link useAccountBalanceOf} + {@link useFeeForUser}).\n * - **`CUSTOM` (cross-margin)** — trades execute on the sub-account directly:\n * `calculateAvailableForOrder` over the live `balanceInfoOfPartyA` snapshot\n * and the account's SDK-computed uPnL ({@link useAccountUpnl} — Σ\n * per-position uPnL against live mark prices), clamped at zero. **On the\n * Rasa solver only**, 90% of it is spendable — a 10% buffer stays reserved\n * (see `RASA_SPENDABLE_BPS`); other cross-margin solvers spend 100%.\n *\n * Every read is live: balances refetch on on-chain settle notifications and\n * the cross-margin uPnL streams off the price socket, so the `Max` chip tracks\n * trades and the market without manual refreshes. Wire the result to the trade\n * form's `Max` chip and gate submit on it.\n *\n * @example\n * ```tsx\n * const { availableMargin, availableMarginWei } = useAvailableInstantOpenMargin({\n * account: subAccount,\n * symbolId: market.symbolId,\n * leverage,\n * positionType,\n * slippage,\n * });\n * ```\n */\nexport function useAvailableInstantOpenMargin(\n parameters: UseAvailableInstantOpenMarginParameters,\n): UseAvailableInstantOpenMarginReturnType {\n const { account, symbolId, leverage, positionType, slippage, solverId, chainId, config } = parameters;\n\n // The 10% spend buffer is a RASA policy, not a cross-margin-model rule —\n // resolved by solver id so a future cross-margin solver is unaffected.\n const resolvedConfig = useSymmioConfig(parameters);\n const isRasaSolver = resolvedConfig.getSolver({ chainId, solverId }).id === \"rasa\";\n\n // The margin model follows the sub-account's isolation: `CUSTOM` trades on\n // the sub-account directly (cross-margin); the VA isolations spend the\n // sub-account's available balance. Isolation is fixed at creation, so this\n // read caches indefinitely.\n const subAccountQuery = useSubAccount({\n account: account ?? zeroAddress,\n chainId,\n config,\n query: { enabled: Boolean(account), staleTime: Infinity },\n });\n const isolationType = account !== undefined ? subAccountQuery.data?.isolationType : undefined;\n const isolationKnown = isolationType !== undefined;\n const isCrossMargin = isolationType === SubAccountIsolationType.CUSTOM;\n\n // `live` keeps the margin fresh: balances refetch when an open/close settles\n // on-chain, so the Max chip drops without a manual refresh.\n const balanceQuery = useAccountBalanceOf({\n account,\n chainId,\n config,\n live: true,\n query: { enabled: isolationKnown && !isCrossMargin },\n });\n const feeQuery = useFeeForUser({\n user: account ?? zeroAddress,\n symbolId: symbolId ?? 0,\n chainId,\n config,\n query: { enabled: isolationKnown && !isCrossMargin && Boolean(account && symbolId !== undefined) },\n });\n const balanceInfoQuery = useAccountBalanceInfo({\n account,\n chainId,\n config,\n live: true,\n query: { enabled: isCrossMargin && Boolean(account) },\n });\n const accountUpnl = useAccountUpnl({ account, chainId, solverId, config, enabled: isCrossMargin, live: true });\n const { data: balance, isLoading: balanceLoading, error: balanceError, refetch: refetchBalance } = balanceQuery;\n const { data: fees, isLoading: feeLoading, error: feeError, refetch: refetchFees } = feeQuery;\n const {\n data: balanceInfo,\n isLoading: balanceInfoLoading,\n error: balanceInfoError,\n refetch: refetchBalanceInfo,\n } = balanceInfoQuery;\n const { upnl, isLoading: upnlLoading, refetch: refetchUpnl } = accountUpnl;\n\n const refetch = useCallback(async () => {\n if (isCrossMargin) {\n await Promise.all([refetchBalanceInfo(), refetchUpnl()]);\n return;\n }\n await Promise.all([refetchBalance(), refetchFees()]);\n }, [isCrossMargin, refetchBalance, refetchFees, refetchBalanceInfo, refetchUpnl]);\n\n return useMemo<UseAvailableInstantOpenMarginReturnType>(() => {\n const isolationLoading = Boolean(account) && !isolationKnown;\n\n if (isCrossMargin) {\n const isLoading = balanceInfoLoading || upnlLoading;\n const error = balanceInfoError ?? null;\n\n if (balanceInfo === undefined || upnl === undefined) {\n return { availableMarginWei: undefined, availableMargin: \"0\", isLoading, error, refetch };\n }\n const available = calculateAvailableForOrder({ balanceInfo, upnl });\n const clamped = available > 0n ? available : 0n;\n // Rasa-only 10% spend buffer — see RASA_SPENDABLE_BPS.\n const availableMarginWei = isRasaSolver ? (clamped * RASA_SPENDABLE_BPS) / 10_000n : clamped;\n return { availableMarginWei, availableMargin: formatUnits(availableMarginWei, 18), isLoading, error, refetch };\n }\n\n const isLoading = isolationLoading || balanceLoading || feeLoading;\n const error = balanceError ?? feeError ?? null;\n\n if (!isolationKnown || balance === undefined || fees === undefined) {\n return { availableMarginWei: undefined, availableMargin: \"0\", isLoading, error, refetch };\n }\n\n const availableMarginWei = calculateAvailableInstantOpenMargin({\n balance,\n openFee: fees.openFee,\n closeFee: fees.closeFee,\n slippageFractionWei: slippagePercentToFractionWei(slippage),\n leverage,\n positionType,\n });\n\n return { availableMarginWei, availableMargin: formatUnits(availableMarginWei, 18), isLoading, error, refetch };\n }, [\n account,\n isolationKnown,\n isCrossMargin,\n isRasaSolver,\n balance,\n balanceLoading,\n balanceError,\n fees,\n feeLoading,\n feeError,\n balanceInfo,\n balanceInfoLoading,\n balanceInfoError,\n upnl,\n upnlLoading,\n slippage,\n leverage,\n positionType,\n refetch,\n ]);\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"use-available-instant-open-margin.js","names":[],"sources":["../../src/margin/use-available-instant-open-margin.ts"],"sourcesContent":["\"use client\";\n\nimport {\n calculateAvailableForOrder,\n calculateAvailableInstantOpenMargin,\n PositionType,\n SubAccountIsolationType,\n type ConfigParameter,\n type SolverId,\n} from \"@symmio/trading-core\";\nimport { useCallback, useMemo } from \"react\";\nimport { formatUnits, zeroAddress, type Address } from \"viem\";\nimport { useAccountBalanceInfo } from \"../account-layer/use-account-balance-info\";\nimport { useAccountBalanceOf } from \"../account-layer/use-account-balance-of\";\nimport { useSubAccount } from \"../account-layer/use-sub-account\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useFeeForUser } from \"../fees/use-fee-for-user\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { useAccountUpnl } from \"../quotes/use-account-upnl\";\n\n/** Convert a slippage percent (e.g. `5`) to an 18-decimal fraction (`5e16`). */\nfunction slippagePercentToFractionWei(slippage: number): bigint {\n return BigInt(Math.round(slippage * 1e16));\n}\n\n/**\n * **Rasa-specific policy**: the fraction of a cross-margin account's\n * `availableForOrder` a new open may spend, in basis points (90%). The\n * remaining 10% stays as a safety buffer so a fill at a slightly worse price\n * or a fee charge cannot tip the account straight into deficiency.\n *\n * Applied only when the resolved solver is Rasa — a future cross-margin solver\n * spends 100% unless its vendor mandates its own buffer.\n */\nconst RASA_SPENDABLE_BPS = 9_000n;\n\n/** Parameters for {@link useAvailableInstantOpenMargin}. */\nexport interface UseAvailableInstantOpenMarginParameters extends ConfigParameter {\n /** SubAccount to spend margin from. The hook is idle until it is set. */\n account?: Address;\n /** Market symbol id, for the fee lookup. Idle until it is set. */\n symbolId?: bigint | number;\n /** Requested leverage (integer ≥ 1). */\n leverage: number;\n /** LONG skips the slippage cap; SHORT applies it. */\n positionType: PositionType;\n /** Slippage percent, e.g. `5`. */\n slippage: number;\n /**\n * Solver whose markets and price provider value the cross-margin uPnL.\n * Defaults to the chain's default solver. The margin **model** is not chosen\n * here — it follows the sub-account's isolation type.\n */\n solverId?: SolverId;\n /** Optional chain override; defaults to the connected chain. */\n chainId?: number;\n}\n\n/** Return type of {@link useAvailableInstantOpenMargin}. */\nexport interface UseAvailableInstantOpenMarginReturnType {\n /** Spendable margin in 18-decimal wei; `undefined` until balance + fees load. */\n availableMarginWei: bigint | undefined;\n /** {@link UseAvailableInstantOpenMarginReturnType.availableMarginWei} as a decimal string; `\"0\"` when unavailable. */\n availableMargin: string;\n /** `true` while the underlying balance / fee reads are loading. */\n isLoading: boolean;\n /** First error from the balance / fee reads, if any. */\n error: SymmioRequestError | null;\n /** Refetch the underlying balance + fee reads (e.g. after an open/close settles). */\n refetch: () => Promise<void>;\n}\n\n/**\n * Maximum initial margin an instant open can spend for `account` on a market —\n * **the** margin hook. The margin model follows the sub-account's isolation\n * type:\n *\n * - **VA isolations** (`POSITION` / `MARKET` / `MARKET_DIRECTION`): the\n * sub-account's available balance shaved for the open fee and — SHORT only — a\n * worst-case slippage fill (`calculateAvailableInstantOpenMargin` over\n * {@link useAccountBalanceOf} + {@link useFeeForUser}). The close fee is\n * charged at close, so it is not reserved here.\n * - **`CUSTOM` (cross-margin)** — trades execute on the sub-account directly:\n * `calculateAvailableForOrder` over the live `balanceInfoOfPartyA` snapshot\n * and the account's SDK-computed uPnL ({@link useAccountUpnl} — Σ\n * per-position uPnL against live mark prices), clamped at zero. **On the\n * Rasa solver only**, 90% of it is spendable — a 10% buffer stays reserved\n * (see `RASA_SPENDABLE_BPS`); other cross-margin solvers spend 100%.\n *\n * Every read is live: balances refetch on on-chain settle notifications and\n * the cross-margin uPnL streams off the price socket, so the `Max` chip tracks\n * trades and the market without manual refreshes. Wire the result to the trade\n * form's `Max` chip and gate submit on it.\n *\n * @example\n * ```tsx\n * const { availableMargin, availableMarginWei } = useAvailableInstantOpenMargin({\n * account: subAccount,\n * symbolId: market.symbolId,\n * leverage,\n * positionType,\n * slippage,\n * });\n * ```\n */\nexport function useAvailableInstantOpenMargin(\n parameters: UseAvailableInstantOpenMarginParameters,\n): UseAvailableInstantOpenMarginReturnType {\n const { account, symbolId, leverage, positionType, slippage, solverId, chainId, config } = parameters;\n\n // The 10% spend buffer is a RASA policy, not a cross-margin-model rule —\n // resolved by solver id so a future cross-margin solver is unaffected.\n const resolvedConfig = useSymmioConfig(parameters);\n const isRasaSolver = resolvedConfig.getSolver({ chainId, solverId }).id === \"rasa\";\n\n // The margin model follows the sub-account's isolation: `CUSTOM` trades on\n // the sub-account directly (cross-margin); the VA isolations spend the\n // sub-account's available balance. Isolation is fixed at creation, so this\n // read caches indefinitely.\n const subAccountQuery = useSubAccount({\n account: account ?? zeroAddress,\n chainId,\n config,\n query: { enabled: Boolean(account), staleTime: Infinity },\n });\n const isolationType = account !== undefined ? subAccountQuery.data?.isolationType : undefined;\n const isolationKnown = isolationType !== undefined;\n const isCrossMargin = isolationType === SubAccountIsolationType.CUSTOM;\n\n // `live` keeps the margin fresh: balances refetch when an open/close settles\n // on-chain, so the Max chip drops without a manual refresh.\n const balanceQuery = useAccountBalanceOf({\n account,\n chainId,\n config,\n live: true,\n query: { enabled: isolationKnown && !isCrossMargin },\n });\n const feeQuery = useFeeForUser({\n user: account ?? zeroAddress,\n symbolId: symbolId ?? 0,\n chainId,\n config,\n query: { enabled: isolationKnown && !isCrossMargin && Boolean(account && symbolId !== undefined) },\n });\n const balanceInfoQuery = useAccountBalanceInfo({\n account,\n chainId,\n config,\n live: true,\n query: { enabled: isCrossMargin && Boolean(account) },\n });\n const accountUpnl = useAccountUpnl({ account, chainId, solverId, config, enabled: isCrossMargin, live: true });\n const { data: balance, isLoading: balanceLoading, error: balanceError, refetch: refetchBalance } = balanceQuery;\n const { data: fees, isLoading: feeLoading, error: feeError, refetch: refetchFees } = feeQuery;\n const {\n data: balanceInfo,\n isLoading: balanceInfoLoading,\n error: balanceInfoError,\n refetch: refetchBalanceInfo,\n } = balanceInfoQuery;\n const { upnl, isLoading: upnlLoading, refetch: refetchUpnl } = accountUpnl;\n\n const refetch = useCallback(async () => {\n if (isCrossMargin) {\n await Promise.all([refetchBalanceInfo(), refetchUpnl()]);\n return;\n }\n await Promise.all([refetchBalance(), refetchFees()]);\n }, [isCrossMargin, refetchBalance, refetchFees, refetchBalanceInfo, refetchUpnl]);\n\n return useMemo<UseAvailableInstantOpenMarginReturnType>(() => {\n const isolationLoading = Boolean(account) && !isolationKnown;\n\n if (isCrossMargin) {\n const isLoading = balanceInfoLoading || upnlLoading;\n const error = balanceInfoError ?? null;\n\n if (balanceInfo === undefined || upnl === undefined) {\n return { availableMarginWei: undefined, availableMargin: \"0\", isLoading, error, refetch };\n }\n const available = calculateAvailableForOrder({ balanceInfo, upnl });\n const clamped = available > 0n ? available : 0n;\n // Rasa-only 10% spend buffer — see RASA_SPENDABLE_BPS.\n const availableMarginWei = isRasaSolver ? (clamped * RASA_SPENDABLE_BPS) / 10_000n : clamped;\n return { availableMarginWei, availableMargin: formatUnits(availableMarginWei, 18), isLoading, error, refetch };\n }\n\n const isLoading = isolationLoading || balanceLoading || feeLoading;\n const error = balanceError ?? feeError ?? null;\n\n if (!isolationKnown || balance === undefined || fees === undefined) {\n return { availableMarginWei: undefined, availableMargin: \"0\", isLoading, error, refetch };\n }\n\n const availableMarginWei = calculateAvailableInstantOpenMargin({\n balance,\n openFee: fees.openFee,\n // Close fee is charged at close from the position, not reserved from the\n // open budget, so it is not shaved here.\n slippageFractionWei: slippagePercentToFractionWei(slippage),\n leverage,\n positionType,\n });\n\n return { availableMarginWei, availableMargin: formatUnits(availableMarginWei, 18), isLoading, error, refetch };\n }, [\n account,\n isolationKnown,\n isCrossMargin,\n isRasaSolver,\n balance,\n balanceLoading,\n balanceError,\n fees,\n feeLoading,\n feeError,\n balanceInfo,\n balanceInfoLoading,\n balanceInfoError,\n upnl,\n upnlLoading,\n slippage,\n leverage,\n positionType,\n refetch,\n ]);\n}\n"],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { usePrices as e } from "./use-prices.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { usePriceByName as t } from "./use-price-by-name.js";
|
|
3
|
+
import { useEnigmaPriceByName as n } from "./use-enigma-price-by-name.js";
|
|
4
|
+
import { useEnigmaPriceByMarketId as r } from "./use-enigma-price-by-market-id.js";
|
|
5
5
|
import { usePriceByMarketId as i } from "./use-price-by-market-id.js";
|
|
6
6
|
import { useBinanceHealth as a } from "./use-binance-health.js";
|
|
7
7
|
import { useBinancePremiumIndex as o } from "./use-binance-premium-index.js";
|
|
@@ -14,4 +14,4 @@ import { useEnigmaPriceServicePricesByNames as f } from "./use-enigma-price-serv
|
|
|
14
14
|
import { useEnigmaPriceServiceSymbolsInfo as p } from "./use-enigma-price-service-symbols-info.js";
|
|
15
15
|
import { useEnigmaPrices as m } from "./use-enigma-prices.js";
|
|
16
16
|
import { useMarkPrices as h } from "./use-mark-prices.js";
|
|
17
|
-
export { a as useBinanceHealth, o as useBinancePremiumIndex, s as useBinancePrices, c as useBinanceSymbolsInfo,
|
|
17
|
+
export { a as useBinanceHealth, o as useBinancePremiumIndex, s as useBinancePrices, c as useBinanceSymbolsInfo, r as useEnigmaPriceByMarketId, n as useEnigmaPriceByName, l as useEnigmaPriceServiceHealth, u as useEnigmaPriceServiceMetadata, d as useEnigmaPriceServicePricesByAddresses, f as useEnigmaPriceServicePricesByNames, p as useEnigmaPriceServiceSymbolsInfo, m as useEnigmaPrices, h as useMarkPrices, i as usePriceByMarketId, t as usePriceByName, e as usePrices };
|
|
@@ -50,7 +50,7 @@ export interface SymmioProviderProps {
|
|
|
50
50
|
* ```tsx
|
|
51
51
|
* <WagmiProvider config={wagmiConfig}>
|
|
52
52
|
* <QueryClientProvider client={queryClient}>
|
|
53
|
-
* <SymmioProvider symmioConfig={{ [SymmioSupportedChainId.
|
|
53
|
+
* <SymmioProvider symmioConfig={{ [SymmioSupportedChainId.ARBITRUM]: { addresses: { affiliatesAddress: "0x…" } } }}>
|
|
54
54
|
* <App />
|
|
55
55
|
* </SymmioProvider>
|
|
56
56
|
* </QueryClientProvider>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symmio-provider.js","names":[],"sources":["../../src/provider/symmio-provider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createConfig,\n listSupportedChains,\n SymmError,\n type Config,\n type CreateConfigParameters,\n type GetWalletClientFn,\n} from \"@symmio/trading-core\";\nimport { useMemo, type ReactNode } from \"react\";\nimport type { PublicClient } from \"viem\";\nimport { useChainId, useConfig } from \"wagmi\";\nimport { getPublicClient, getWalletClient } from \"wagmi/actions\";\nimport { SymmioConfigContext } from \"./symmio-config-context\";\n\n/**\n * Props for {@link SymmioProvider}.\n */\nexport interface SymmioProviderProps {\n /** React subtree that may use SYMMIO SDK hooks. */\n children: ReactNode;\n /**\n * Per-chain SYMMIO configuration, keyed by chain id — deep-merged onto the\n * SDK's built-in defaults (addresses, subgraphs, solver, …).\n *\n * **Required.** Every supported chain must set a non-zero\n * `addresses.affiliatesAddress` — your frontend's on-chain affiliate (your\n * identity in SYMMIO on that chain), attached to every quote so the protocol\n * attributes the trade to you and routes your fee share. Affiliate addresses\n * are per chain (a registration on one chain is not valid on another). The\n * provider throws `AFFILIATE_ADDRESS_REQUIRED` (via `createConfig`) for any\n * supported chain missing it, so trades can never silently fall back to the\n * built-in default affiliate and lose attribution.\n */\n symmioConfig: CreateConfigParameters[\"symmioConfig\"];\n /**\n * Fallback chain used when a hook or action omits `chainId` **and** the\n * connected wallet is not on a supported SYMMIO chain (or is disconnected).\n * When the wallet *is* on a supported chain, that chain becomes the default\n * instead — so a no-arg `config.getChainConfig()` always follows the active\n * chain. Defaults to the SDK's first supported chain.\n */\n defaultChainId?: number;\n /**\n * Custom wallet-client resolver. Receives `{ chainId, from? }` from the SDK\n * and returns the wallet client to sign with. Use this to plug in\n * session-key, multi-signer, or any non-wagmi flow — the resolver decides.\n *\n * When omitted, the provider falls back to wagmi's connected wallet (ignores\n * `from`).\n */\n getWalletClient?: GetWalletClientFn;\n}\n\n/**\n * Provides the SYMMIO {@link Config} to descendant hooks. The config's viem\n * clients are resolved from the host's wagmi config, so this is the only place\n * the SDK touches wagmi.\n *\n * **Mount order matters**: this reads wagmi context and (transitively) the\n * host's `@tanstack/react-query` `QueryClient`. Both must be mounted **outside**\n * `SymmioProvider`:\n *\n * ```tsx\n * <WagmiProvider config={wagmiConfig}>\n * <QueryClientProvider client={queryClient}>\n * <SymmioProvider symmioConfig={{ [SymmioSupportedChainId.
|
|
1
|
+
{"version":3,"file":"symmio-provider.js","names":[],"sources":["../../src/provider/symmio-provider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createConfig,\n listSupportedChains,\n SymmError,\n type Config,\n type CreateConfigParameters,\n type GetWalletClientFn,\n} from \"@symmio/trading-core\";\nimport { useMemo, type ReactNode } from \"react\";\nimport type { PublicClient } from \"viem\";\nimport { useChainId, useConfig } from \"wagmi\";\nimport { getPublicClient, getWalletClient } from \"wagmi/actions\";\nimport { SymmioConfigContext } from \"./symmio-config-context\";\n\n/**\n * Props for {@link SymmioProvider}.\n */\nexport interface SymmioProviderProps {\n /** React subtree that may use SYMMIO SDK hooks. */\n children: ReactNode;\n /**\n * Per-chain SYMMIO configuration, keyed by chain id — deep-merged onto the\n * SDK's built-in defaults (addresses, subgraphs, solver, …).\n *\n * **Required.** Every supported chain must set a non-zero\n * `addresses.affiliatesAddress` — your frontend's on-chain affiliate (your\n * identity in SYMMIO on that chain), attached to every quote so the protocol\n * attributes the trade to you and routes your fee share. Affiliate addresses\n * are per chain (a registration on one chain is not valid on another). The\n * provider throws `AFFILIATE_ADDRESS_REQUIRED` (via `createConfig`) for any\n * supported chain missing it, so trades can never silently fall back to the\n * built-in default affiliate and lose attribution.\n */\n symmioConfig: CreateConfigParameters[\"symmioConfig\"];\n /**\n * Fallback chain used when a hook or action omits `chainId` **and** the\n * connected wallet is not on a supported SYMMIO chain (or is disconnected).\n * When the wallet *is* on a supported chain, that chain becomes the default\n * instead — so a no-arg `config.getChainConfig()` always follows the active\n * chain. Defaults to the SDK's first supported chain.\n */\n defaultChainId?: number;\n /**\n * Custom wallet-client resolver. Receives `{ chainId, from? }` from the SDK\n * and returns the wallet client to sign with. Use this to plug in\n * session-key, multi-signer, or any non-wagmi flow — the resolver decides.\n *\n * When omitted, the provider falls back to wagmi's connected wallet (ignores\n * `from`).\n */\n getWalletClient?: GetWalletClientFn;\n}\n\n/**\n * Provides the SYMMIO {@link Config} to descendant hooks. The config's viem\n * clients are resolved from the host's wagmi config, so this is the only place\n * the SDK touches wagmi.\n *\n * **Mount order matters**: this reads wagmi context and (transitively) the\n * host's `@tanstack/react-query` `QueryClient`. Both must be mounted **outside**\n * `SymmioProvider`:\n *\n * ```tsx\n * <WagmiProvider config={wagmiConfig}>\n * <QueryClientProvider client={queryClient}>\n * <SymmioProvider symmioConfig={{ [SymmioSupportedChainId.ARBITRUM]: { addresses: { affiliatesAddress: \"0x…\" } } }}>\n * <App />\n * </SymmioProvider>\n * </QueryClientProvider>\n * </WagmiProvider>\n * ```\n *\n * The SDK never mounts wagmi or a `QueryClient` for the host — those (which\n * connectors, which RPC URLs, which shared `QueryClient`) belong to the host.\n */\nexport function SymmioProvider({\n children,\n symmioConfig,\n defaultChainId,\n getWalletClient: getWalletClientProp,\n}: SymmioProviderProps) {\n const wagmiConfig = useConfig();\n const connectedChainId = useChainId();\n\n // Track the connected wallet's chain as the config default whenever it is a\n // supported SYMMIO chain, so a no-arg `config.getChainConfig()` — and any hook\n // that omits `chainId` — resolves to the ACTIVE chain rather than a hardcoded\n // first chain. Single fix for the whole class of \"reads the wrong chain's\n // addresses after switching\". Falls back to the explicit `defaultChainId` prop\n // (then the SDK's first supported chain) when the wallet is on an unsupported\n // chain or disconnected.\n const effectiveDefaultChainId = listSupportedChains().some((id) => id === connectedChainId)\n ? connectedChainId\n : defaultChainId;\n\n const config = useMemo<Config>(\n () =>\n createConfig({\n symmioConfig,\n defaultChainId: effectiveDefaultChainId,\n getClient: ({ chainId } = {}): PublicClient => {\n const client = getPublicClient(wagmiConfig, { chainId });\n\n if (!client)\n throw new SymmError(\n \"config\",\n \"NO_PUBLIC_CLIENT\",\n `No public client available for chain ${chainId ?? \"(default)\"}.`,\n );\n return client;\n },\n getWalletClient:\n getWalletClientProp ??\n (async ({ chainId }) => {\n try {\n return await getWalletClient(wagmiConfig, { chainId });\n } catch (err) {\n throw new SymmError(\n \"config\",\n \"NO_WALLET_CONNECTED\",\n \"No connected wallet. Connect a wallet before sending transactions.\",\n { cause: err instanceof Error ? err : undefined },\n );\n }\n }),\n }),\n [symmioConfig, effectiveDefaultChainId, getWalletClientProp, wagmiConfig],\n );\n\n return <SymmioConfigContext.Provider value={config}>{children}</SymmioConfigContext.Provider>;\n}\n"],"mappings":";;;;;;;;AA6EA,SAAgB,EAAe,EAC7B,aACA,iBACA,mBACA,iBAAiB,KACK;CACtB,IAAM,IAAc,EAAU,GACxB,IAAmB,EAAW,GAS9B,IAA0B,EAAoB,EAAE,MAAM,MAAO,MAAO,CAAgB,IACtF,IACA,GAEE,IAAS,QAEX,EAAa;EACX;EACA,gBAAgB;EAChB,YAAY,EAAE,eAAY,CAAC,MAAoB;GAC7C,IAAM,IAAS,EAAgB,GAAa,EAAE,WAAQ,CAAC;GAEvD,IAAI,CAAC,GACH,MAAM,IAAI,EACR,UACA,oBACA,wCAAwC,KAAW,YAAY,EACjE;GACF,OAAO;EACT;EACA,iBACE,MACC,OAAO,EAAE,iBAAc;GACtB,IAAI;IACF,OAAO,MAAM,EAAgB,GAAa,EAAE,WAAQ,CAAC;GACvD,SAAS,GAAK;IACZ,MAAM,IAAI,EACR,UACA,uBACA,sEACA,EAAE,OAAO,aAAe,QAAQ,IAAM,KAAA,EAAU,CAClD;GACF;EACF;CACJ,CAAC,GACH;EAAC;EAAc;EAAyB;EAAqB;CAAW,CAC1E;CAEA,OAAO,kBAAC,EAAoB,UAArB;EAA8B,OAAO;EAAS;CAAuC,CAAA;AAC9F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rasa-solver/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rasa-solver/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC"}
|
package/dist/solvers/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/solvers/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/solvers/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConfigParameter, GetSolverInfoData, GetSolverInfoOptions } from '@symmio/trading-core';
|
|
2
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
|
+
/** Parameters for {@link useSolverInfo}. */
|
|
5
|
+
export type UseSolverInfoParameters = GetSolverInfoOptions & ConfigParameter;
|
|
6
|
+
/** Return type of {@link useSolverInfo}. */
|
|
7
|
+
export type UseSolverInfoReturnType = UseQueryResult<GetSolverInfoData, SymmioRequestError>;
|
|
8
|
+
/**
|
|
9
|
+
* Read the solver's static fee configuration via the Enigma-only `/info`
|
|
10
|
+
* endpoint. Fails with `UNSUPPORTED_BY_SOLVER` when the resolved solver is not
|
|
11
|
+
* an `enigma` solver.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useSolverInfo(parameters?: UseSolverInfoParameters): UseSolverInfoReturnType;
|
|
14
|
+
//# sourceMappingURL=use-solver-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-solver-info.d.ts","sourceRoot":"","sources":["../../src/solvers/use-solver-info.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIzE,4CAA4C;AAC5C,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,GAAG,eAAe,CAAC;AAE7E,4CAA4C;AAC5C,MAAM,MAAM,uBAAuB,GAAG,cAAc,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;AAE5F;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,GAAE,uBAA4B,GAAG,uBAAuB,CAkB/F"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { getSolverInfoQueryOptions as r } from "@symmio/trading-core";
|
|
6
|
+
import { useQuery as i } from "@tanstack/react-query";
|
|
7
|
+
//#region src/solvers/use-solver-info.ts
|
|
8
|
+
function a(a = {}) {
|
|
9
|
+
let o = t(a), s = e(), c = r(o, {
|
|
10
|
+
...a,
|
|
11
|
+
chainId: a.chainId ?? s
|
|
12
|
+
});
|
|
13
|
+
return i({
|
|
14
|
+
...c,
|
|
15
|
+
queryFn: async () => {
|
|
16
|
+
try {
|
|
17
|
+
return await c.queryFn();
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw n(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { a as useSolverInfo };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=use-solver-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-solver-info.js","names":[],"sources":["../../src/solvers/use-solver-info.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getSolverInfoQueryOptions,\n type ConfigParameter,\n type GetSolverInfoData,\n type GetSolverInfoOptions,\n} from \"@symmio/trading-core\";\nimport { useQuery, type UseQueryResult } 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\";\n\n/** Parameters for {@link useSolverInfo}. */\nexport type UseSolverInfoParameters = GetSolverInfoOptions & ConfigParameter;\n\n/** Return type of {@link useSolverInfo}. */\nexport type UseSolverInfoReturnType = UseQueryResult<GetSolverInfoData, SymmioRequestError>;\n\n/**\n * Read the solver's static fee configuration via the Enigma-only `/info`\n * endpoint. Fails with `UNSUPPORTED_BY_SOLVER` when the resolved solver is not\n * an `enigma` solver.\n */\nexport function useSolverInfo(parameters: UseSolverInfoParameters = {}): UseSolverInfoReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const options = getSolverInfoQueryOptions(config, {\n ...parameters,\n chainId: parameters.chainId ?? chainId,\n });\n\n return useQuery({\n ...options,\n queryFn: async () => {\n try {\n return await options.queryFn();\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n }) as UseSolverInfoReturnType;\n}\n"],"mappings":";;;;;;;AAyBA,SAAgB,EAAc,IAAsC,CAAC,GAA4B;CAC/F,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAU,EAA0B,GAAQ;EAChD,GAAG;EACH,SAAS,EAAW,WAAW;CACjC,CAAC;CAED,OAAO,EAAS;EACd,GAAG;EACH,SAAS,YAAY;GACnB,IAAI;IACF,OAAO,MAAM,EAAQ,QAAQ;GAC/B,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;CACF,CAAC;AACH"}
|
|
@@ -6,21 +6,23 @@ export type UseSolverRevenueParameters = GetSolverRevenueOptions & ConfigParamet
|
|
|
6
6
|
/** Return type of {@link useSolverRevenue}: revenue totals for the window. */
|
|
7
7
|
export type UseSolverRevenueReturnType = UseQueryResult<GetSolverRevenueReturnType, SymmioRequestError>;
|
|
8
8
|
/**
|
|
9
|
-
* Read revenue totals from the connected chain's solver
|
|
10
|
-
* default**, or for a single market when `symbolId` is passed.
|
|
9
|
+
* Read one market's revenue totals from the connected chain's solver.
|
|
11
10
|
*
|
|
12
11
|
* The result splits into a hedger-fee share and a funding share whose sum is
|
|
13
12
|
* `totalRevenue`, all as plain dollar numbers. `recordCount` separates "this
|
|
14
13
|
* window earned nothing" from "there is no data for this window".
|
|
15
14
|
*
|
|
15
|
+
* `symbolId` is required: the current solver generation serves revenue **per
|
|
16
|
+
* market only** — the protocol-wide `/revenue` aggregate no longer exists.
|
|
17
|
+
*
|
|
16
18
|
* Enigma-only; a rasa-kind solver fails with `UNSUPPORTED_BY_SOLVER`. Errors are
|
|
17
19
|
* normalized to {@link SymmioRequestError}.
|
|
18
20
|
*
|
|
19
21
|
* @example
|
|
20
22
|
* ```tsx
|
|
21
|
-
* const lifetime = useSolverRevenue();
|
|
22
|
-
* const day = useSolverRevenue({ timeRange: "24h" });
|
|
23
|
+
* const lifetime = useSolverRevenue({ symbolId: 1 });
|
|
24
|
+
* const day = useSolverRevenue({ symbolId: 1, timeRange: "24h" });
|
|
23
25
|
* ```
|
|
24
26
|
*/
|
|
25
|
-
export declare function useSolverRevenue(parameters
|
|
27
|
+
export declare function useSolverRevenue(parameters: UseSolverRevenueParameters): UseSolverRevenueReturnType;
|
|
26
28
|
//# sourceMappingURL=use-solver-revenue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-solver-revenue.d.ts","sourceRoot":"","sources":["../../src/solvers/use-solver-revenue.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAChC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIzE,iGAAiG;AACjG,MAAM,MAAM,0BAA0B,GAAG,uBAAuB,GAAG,eAAe,CAAC;AAEnF,8EAA8E;AAC9E,MAAM,MAAM,0BAA0B,GAAG,cAAc,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,CAAC;AAExG
|
|
1
|
+
{"version":3,"file":"use-solver-revenue.d.ts","sourceRoot":"","sources":["../../src/solvers/use-solver-revenue.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAChC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIzE,iGAAiG;AACjG,MAAM,MAAM,0BAA0B,GAAG,uBAAuB,GAAG,eAAe,CAAC;AAEnF,8EAA8E;AAC9E,MAAM,MAAM,0BAA0B,GAAG,cAAc,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,CAAC;AAExG;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,0BAA0B,GAAG,0BAA0B,CAkBnG"}
|
|
@@ -5,7 +5,7 @@ import { normalizeSymmError as n } from "../errors/normalize-symm-error.js";
|
|
|
5
5
|
import { getSolverRevenueQueryOptions as r } from "@symmio/trading-core";
|
|
6
6
|
import { useQuery as i } from "@tanstack/react-query";
|
|
7
7
|
//#region src/solvers/use-solver-revenue.ts
|
|
8
|
-
function a(a
|
|
8
|
+
function a(a) {
|
|
9
9
|
let o = t(a), s = e(), c = r(o, {
|
|
10
10
|
...a,
|
|
11
11
|
chainId: a.chainId ?? s
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-solver-revenue.js","names":[],"sources":["../../src/solvers/use-solver-revenue.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getSolverRevenueQueryOptions,\n type ConfigParameter,\n type GetSolverRevenueOptions,\n type GetSolverRevenueReturnType,\n} from \"@symmio/trading-core\";\nimport { useQuery, type UseQueryResult } 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\";\n\n/** Parameters for {@link useSolverRevenue}: the core query options plus an optional `config`. */\nexport type UseSolverRevenueParameters = GetSolverRevenueOptions & ConfigParameter;\n\n/** Return type of {@link useSolverRevenue}: revenue totals for the window. */\nexport type UseSolverRevenueReturnType = UseQueryResult<GetSolverRevenueReturnType, SymmioRequestError>;\n\n/**\n * Read revenue totals from the connected chain's solver
|
|
1
|
+
{"version":3,"file":"use-solver-revenue.js","names":[],"sources":["../../src/solvers/use-solver-revenue.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getSolverRevenueQueryOptions,\n type ConfigParameter,\n type GetSolverRevenueOptions,\n type GetSolverRevenueReturnType,\n} from \"@symmio/trading-core\";\nimport { useQuery, type UseQueryResult } 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\";\n\n/** Parameters for {@link useSolverRevenue}: the core query options plus an optional `config`. */\nexport type UseSolverRevenueParameters = GetSolverRevenueOptions & ConfigParameter;\n\n/** Return type of {@link useSolverRevenue}: revenue totals for the window. */\nexport type UseSolverRevenueReturnType = UseQueryResult<GetSolverRevenueReturnType, SymmioRequestError>;\n\n/**\n * Read one market's revenue totals from the connected chain's solver.\n *\n * The result splits into a hedger-fee share and a funding share whose sum is\n * `totalRevenue`, all as plain dollar numbers. `recordCount` separates \"this\n * window earned nothing\" from \"there is no data for this window\".\n *\n * `symbolId` is required: the current solver generation serves revenue **per\n * market only** — the protocol-wide `/revenue` aggregate no longer exists.\n *\n * Enigma-only; a rasa-kind solver fails with `UNSUPPORTED_BY_SOLVER`. Errors are\n * normalized to {@link SymmioRequestError}.\n *\n * @example\n * ```tsx\n * const lifetime = useSolverRevenue({ symbolId: 1 });\n * const day = useSolverRevenue({ symbolId: 1, timeRange: \"24h\" });\n * ```\n */\nexport function useSolverRevenue(parameters: UseSolverRevenueParameters): UseSolverRevenueReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const options = getSolverRevenueQueryOptions(config, {\n ...parameters,\n chainId: parameters.chainId ?? chainId,\n });\n\n return useQuery({\n ...options,\n queryFn: async () => {\n try {\n return await options.queryFn();\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n }) as UseSolverRevenueReturnType;\n}\n"],"mappings":";;;;;;;AAuCA,SAAgB,EAAiB,GAAoE;CACnG,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAU,EAA6B,GAAQ;EACnD,GAAG;EACH,SAAS,EAAW,WAAW;CACjC,CAAC;CAED,OAAO,EAAS;EACd,GAAG;EACH,SAAS,YAAY;GACnB,IAAI;IACF,OAAO,MAAM,EAAQ,QAAQ;GAC/B,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;CACF,CAAC;AACH"}
|
|
@@ -21,7 +21,7 @@ export type UseInitiateWithdrawReturnType = UseMutationResult<InitiateWithdrawRe
|
|
|
21
21
|
* ```tsx
|
|
22
22
|
* import { createClassicWithdrawPart } from "@symmio/trading-core";
|
|
23
23
|
* const { mutate } = useInitiateWithdraw();
|
|
24
|
-
* mutate({ account: "0xsub…", parts: [createClassicWithdrawPart({ id: 0n, amount, receiver, chainId:
|
|
24
|
+
* mutate({ account: "0xsub…", parts: [createClassicWithdrawPart({ id: 0n, amount, receiver, chainId: 42161n })] });
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
export declare function useInitiateWithdraw(parameters?: UseInitiateWithdrawParameters): UseInitiateWithdrawReturnType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-initiate-withdraw.js","names":[],"sources":["../../src/withdraw/use-initiate-withdraw.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getLastWithdrawRequestIdQueryKey,\n getPendingWithdrawRequestsQueryKey,\n getWithdrawableTimeQueryKey,\n initiateWithdrawMutationOptions,\n type InitiateWithdrawParameters,\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/**\n * Parameters for {@link useInitiateWithdraw}.\n */\nexport type UseInitiateWithdrawParameters = WriteParameters;\n\n/** Result returned by the {@link useInitiateWithdraw} mutation. */\nexport type InitiateWithdrawResult = WriteResult;\n\n/** Return type of {@link useInitiateWithdraw}. */\nexport type UseInitiateWithdrawReturnType = UseMutationResult<\n InitiateWithdrawResult,\n SymmioRequestError,\n InitiateWithdrawParameters\n>;\n\n/**\n * Open a withdraw request for a subaccount (the SDK routes it through the\n * AccountLayer `_call` proxy). The full input surface is exposed via the mutation\n * variables — `parts`, `speedUp`, `providerData`. On success, the subaccount's\n * pending-requests, last-request-id, and withdrawable-time queries are\n * invalidated.\n *\n * @example\n * ```tsx\n * import { createClassicWithdrawPart } from \"@symmio/trading-core\";\n * const { mutate } = useInitiateWithdraw();\n * mutate({ account: \"0xsub…\", parts: [createClassicWithdrawPart({ id: 0n, amount, receiver, chainId:
|
|
1
|
+
{"version":3,"file":"use-initiate-withdraw.js","names":[],"sources":["../../src/withdraw/use-initiate-withdraw.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getLastWithdrawRequestIdQueryKey,\n getPendingWithdrawRequestsQueryKey,\n getWithdrawableTimeQueryKey,\n initiateWithdrawMutationOptions,\n type InitiateWithdrawParameters,\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/**\n * Parameters for {@link useInitiateWithdraw}.\n */\nexport type UseInitiateWithdrawParameters = WriteParameters;\n\n/** Result returned by the {@link useInitiateWithdraw} mutation. */\nexport type InitiateWithdrawResult = WriteResult;\n\n/** Return type of {@link useInitiateWithdraw}. */\nexport type UseInitiateWithdrawReturnType = UseMutationResult<\n InitiateWithdrawResult,\n SymmioRequestError,\n InitiateWithdrawParameters\n>;\n\n/**\n * Open a withdraw request for a subaccount (the SDK routes it through the\n * AccountLayer `_call` proxy). The full input surface is exposed via the mutation\n * variables — `parts`, `speedUp`, `providerData`. On success, the subaccount's\n * pending-requests, last-request-id, and withdrawable-time queries are\n * invalidated.\n *\n * @example\n * ```tsx\n * import { createClassicWithdrawPart } from \"@symmio/trading-core\";\n * const { mutate } = useInitiateWithdraw();\n * mutate({ account: \"0xsub…\", parts: [createClassicWithdrawPart({ id: 0n, amount, receiver, chainId: 42161n })] });\n * ```\n */\nexport function useInitiateWithdraw(parameters: UseInitiateWithdrawParameters = {}): UseInitiateWithdrawReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = initiateWithdrawMutationOptions(config);\n\n return useMutation<InitiateWithdrawResult, SymmioRequestError, InitiateWithdrawParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({\n account: variables.account,\n parts: variables.parts,\n speedUp: variables.speedUp,\n providerData: variables.providerData,\n simulateBeforeWrite: variables.simulateBeforeWrite,\n chainId: resolvedChainId,\n });\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 const partial = { user: variables.account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPendingWithdrawRequestsQueryKey, partial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getLastWithdrawRequestIdQueryKey, partial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getWithdrawableTimeQueryKey, partial) });\n },\n });\n}\n"],"mappings":";;;;;;;;;AA8CA,SAAgB,EAAoB,IAA4C,CAAC,GAAkC;CACjH,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAE7B,IAAO,EAAgC,CAAM;CAEnD,OAAO,EAAoF;EACzF,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,IAAM,IAAkB,EAAU,WAAW;IAS7C,OAAO,EAAmB,GAAQ,MARf,EAAK,WAAW;KACjC,SAAS,EAAU;KACnB,OAAO,EAAU;KACjB,SAAS,EAAU;KACnB,cAAc,EAAU;KACxB,qBAAqB,EAAU;KAC/B,SAAS;IACX,CAAC,GACuC;KACtC,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CAAC;GACH,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,YAAY,GAAS,MAAc;GACjC,IAAM,IAAU,EAAE,MAAM,EAAU,QAAQ;GAG1C,AAFA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAoC,CAAO,EAAE,CAAC,GAC7G,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAkC,CAAO,EAAE,CAAC,GAC3G,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA6B,CAAO,EAAE,CAAC;EACxG;CACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symmio/trading-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1-staging-20260926093035",
|
|
4
4
|
"description": "React adapter for the SYMMIO SDK. Hooks, providers, and React-bound ergonomics on top of @symmio/trading-core.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/SYMM-IO/Trading-SDK/tree/main/packages/trading-react#readme",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"@tanstack/react-query": "^5.100.0",
|
|
88
88
|
"decimal.js": "^10.4.3",
|
|
89
89
|
"zustand": "^5.0.0",
|
|
90
|
-
"@symmio/trading-core": "^
|
|
90
|
+
"@symmio/trading-core": "^3.0.1-staging-20260926093035"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"react": "^19.0.0",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AddSolverWhitelistParameters, AddSolverWhitelistReturnType, ConfigParameter } from '@symmio/trading-core';
|
|
2
|
-
import { UseMutationResult } from '@tanstack/react-query';
|
|
3
|
-
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
|
-
/** Parameters for {@link useAddSolverWhitelist}. */
|
|
5
|
-
export type UseAddSolverWhitelistParameters = ConfigParameter;
|
|
6
|
-
/** Return type of {@link useAddSolverWhitelist}. */
|
|
7
|
-
export type UseAddSolverWhitelistReturnType = UseMutationResult<AddSolverWhitelistReturnType, SymmioRequestError, AddSolverWhitelistParameters>;
|
|
8
|
-
/**
|
|
9
|
-
* Add an address to the solver's whitelist via the Rasa-only
|
|
10
|
-
* `/add-sub-address-in-whitelist` endpoint. A mutation — it changes
|
|
11
|
-
* solver-side state. Fails with `UNSUPPORTED_BY_SOLVER` when the resolved
|
|
12
|
-
* solver is not a `rasa` solver.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```tsx
|
|
16
|
-
* const { mutate } = useAddSolverWhitelist();
|
|
17
|
-
* <button onClick={() => mutate({ address })}>Whitelist</button>
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function useAddSolverWhitelist(parameters?: UseAddSolverWhitelistParameters): UseAddSolverWhitelistReturnType;
|
|
21
|
-
//# sourceMappingURL=use-add-solver-whitelist.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-add-solver-whitelist.d.ts","sourceRoot":"","sources":["../../src/rasa-solver/use-add-solver-whitelist.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,EACjC,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIzE,oDAAoD;AACpD,MAAM,MAAM,+BAA+B,GAAG,eAAe,CAAC;AAE9D,oDAAoD;AACpD,MAAM,MAAM,+BAA+B,GAAG,iBAAiB,CAC7D,4BAA4B,EAC5B,kBAAkB,EAClB,4BAA4B,CAC7B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,GAAE,+BAAoC,GAC/C,+BAA+B,CAejC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
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 { addSolverWhitelistMutationOptions as r } from "@symmio/trading-core";
|
|
6
|
-
import { useMutation as i } from "@tanstack/react-query";
|
|
7
|
-
//#region src/rasa-solver/use-add-solver-whitelist.ts
|
|
8
|
-
function a(a = {}) {
|
|
9
|
-
let o = t(a), s = e(), c = r(o);
|
|
10
|
-
return i({
|
|
11
|
-
mutationKey: c.mutationKey,
|
|
12
|
-
mutationFn: async (e) => {
|
|
13
|
-
try {
|
|
14
|
-
return await c.mutationFn({
|
|
15
|
-
...e,
|
|
16
|
-
chainId: e.chainId ?? s
|
|
17
|
-
});
|
|
18
|
-
} catch (e) {
|
|
19
|
-
throw n(e);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { a as useAddSolverWhitelist };
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=use-add-solver-whitelist.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-add-solver-whitelist.js","names":[],"sources":["../../src/rasa-solver/use-add-solver-whitelist.ts"],"sourcesContent":["\"use client\";\n\nimport {\n addSolverWhitelistMutationOptions,\n type AddSolverWhitelistParameters,\n type AddSolverWhitelistReturnType,\n type ConfigParameter,\n} from \"@symmio/trading-core\";\nimport { useMutation, 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\";\n\n/** Parameters for {@link useAddSolverWhitelist}. */\nexport type UseAddSolverWhitelistParameters = ConfigParameter;\n\n/** Return type of {@link useAddSolverWhitelist}. */\nexport type UseAddSolverWhitelistReturnType = UseMutationResult<\n AddSolverWhitelistReturnType,\n SymmioRequestError,\n AddSolverWhitelistParameters\n>;\n\n/**\n * Add an address to the solver's whitelist via the Rasa-only\n * `/add-sub-address-in-whitelist` endpoint. A mutation — it changes\n * solver-side state. Fails with `UNSUPPORTED_BY_SOLVER` when the resolved\n * solver is not a `rasa` solver.\n *\n * @example\n * ```tsx\n * const { mutate } = useAddSolverWhitelist();\n * <button onClick={() => mutate({ address })}>Whitelist</button>\n * ```\n */\nexport function useAddSolverWhitelist(\n parameters: UseAddSolverWhitelistParameters = {},\n): UseAddSolverWhitelistReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const base = addSolverWhitelistMutationOptions(config);\n\n return useMutation<AddSolverWhitelistReturnType, SymmioRequestError, AddSolverWhitelistParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n return await base.mutationFn({ ...variables, chainId: variables.chainId ?? chainId });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n });\n}\n"],"mappings":";;;;;;;AAoCA,SAAgB,EACd,IAA8C,CAAC,GACd;CACjC,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAO,EAAkC,CAAM;CAErD,OAAO,EAA4F;EACjG,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,OAAO,MAAM,EAAK,WAAW;KAAE,GAAG;KAAW,SAAS,EAAU,WAAW;IAAQ,CAAC;GACtF,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;CACF,CAAC;AACH"}
|