@symmio/trading-react 4.4.0 → 4.6.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/automatic-timelock-attempt.d.ts +11 -0
- package/dist/account-layer/automatic-timelock-attempt.d.ts.map +1 -0
- package/dist/account-layer/automatic-timelock-attempt.js +41 -0
- package/dist/account-layer/automatic-timelock-attempt.js.map +1 -0
- package/dist/account-layer/index.d.ts +9 -0
- package/dist/account-layer/index.d.ts.map +1 -1
- package/dist/account-layer/index.js +41 -32
- package/dist/account-layer/use-active-virtual-account-by-key.d.ts +33 -0
- package/dist/account-layer/use-active-virtual-account-by-key.d.ts.map +1 -0
- package/dist/account-layer/use-active-virtual-account-by-key.js +27 -0
- package/dist/account-layer/use-active-virtual-account-by-key.js.map +1 -0
- package/dist/account-layer/use-add-margin.d.ts +2 -2
- package/dist/account-layer/use-add-margin.d.ts.map +1 -1
- package/dist/account-layer/use-add-margin.js +28 -17
- package/dist/account-layer/use-add-margin.js.map +1 -1
- package/dist/account-layer/use-allocate.d.ts +2 -2
- package/dist/account-layer/use-allocate.d.ts.map +1 -1
- package/dist/account-layer/use-allocate.js +28 -17
- package/dist/account-layer/use-allocate.js.map +1 -1
- package/dist/account-layer/use-automatic-timelock-recovery.d.ts +25 -0
- package/dist/account-layer/use-automatic-timelock-recovery.d.ts.map +1 -0
- package/dist/account-layer/use-automatic-timelock-recovery.js +26 -0
- package/dist/account-layer/use-automatic-timelock-recovery.js.map +1 -0
- package/dist/account-layer/use-automatic-timelock.d.ts +48 -0
- package/dist/account-layer/use-automatic-timelock.d.ts.map +1 -0
- package/dist/account-layer/use-automatic-timelock.js +189 -0
- package/dist/account-layer/use-automatic-timelock.js.map +1 -0
- package/dist/account-layer/use-create-sub-accounts.d.ts +9 -4
- package/dist/account-layer/use-create-sub-accounts.d.ts.map +1 -1
- package/dist/account-layer/use-create-sub-accounts.js +11 -13
- package/dist/account-layer/use-create-sub-accounts.js.map +1 -1
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.d.ts +3 -3
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.d.ts.map +1 -1
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.js +32 -21
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.js.map +1 -1
- package/dist/account-layer/use-deallocate.d.ts +6 -5
- package/dist/account-layer/use-deallocate.d.ts.map +1 -1
- package/dist/account-layer/use-deallocate.js +33 -20
- package/dist/account-layer/use-deallocate.js.map +1 -1
- package/dist/account-layer/use-delete-sub-account.d.ts +2 -2
- package/dist/account-layer/use-delete-sub-account.d.ts.map +1 -1
- package/dist/account-layer/use-delete-sub-account.js +30 -19
- package/dist/account-layer/use-delete-sub-account.js.map +1 -1
- package/dist/account-layer/use-execute-account-calls.d.ts +7 -0
- package/dist/account-layer/use-execute-account-calls.d.ts.map +1 -0
- package/dist/account-layer/use-execute-account-calls.js +54 -0
- package/dist/account-layer/use-execute-account-calls.js.map +1 -0
- package/dist/account-layer/use-protected-function.d.ts +22 -0
- package/dist/account-layer/use-protected-function.d.ts.map +1 -0
- package/dist/account-layer/use-protected-function.js +68 -0
- package/dist/account-layer/use-protected-function.js.map +1 -0
- package/dist/account-layer/use-remove-margin.d.ts +2 -2
- package/dist/account-layer/use-remove-margin.d.ts.map +1 -1
- package/dist/account-layer/use-remove-margin.js +31 -20
- package/dist/account-layer/use-remove-margin.js.map +1 -1
- package/dist/account-layer/use-timelock-policy.d.ts +21 -0
- package/dist/account-layer/use-timelock-policy.d.ts.map +1 -0
- package/dist/account-layer/use-timelock-policy.js +112 -0
- package/dist/account-layer/use-timelock-policy.js.map +1 -0
- package/dist/account-layer/use-timelock-route.d.ts +75 -0
- package/dist/account-layer/use-timelock-route.d.ts.map +1 -0
- package/dist/account-layer/use-timelock-route.js +177 -0
- package/dist/account-layer/use-timelock-route.js.map +1 -0
- package/dist/account-layer/use-timelock.d.ts +102 -0
- package/dist/account-layer/use-timelock.d.ts.map +1 -0
- package/dist/account-layer/use-timelock.js +177 -0
- package/dist/account-layer/use-timelock.js.map +1 -0
- package/dist/account-layer/use-virtual-accounts-count-of-sub-account.d.ts +24 -0
- package/dist/account-layer/use-virtual-accounts-count-of-sub-account.d.ts.map +1 -0
- package/dist/account-layer/use-virtual-accounts-count-of-sub-account.js +27 -0
- package/dist/account-layer/use-virtual-accounts-count-of-sub-account.js.map +1 -0
- package/dist/account-layer/use-virtual-accounts-of-sub-account.d.ts +25 -0
- package/dist/account-layer/use-virtual-accounts-of-sub-account.d.ts.map +1 -0
- package/dist/account-layer/use-virtual-accounts-of-sub-account.js +27 -0
- package/dist/account-layer/use-virtual-accounts-of-sub-account.js.map +1 -0
- package/dist/candles/index.d.ts +2 -0
- package/dist/candles/index.d.ts.map +1 -1
- package/dist/candles/index.js +6 -4
- package/dist/candles/use-candle-history.d.ts +30 -0
- package/dist/candles/use-candle-history.d.ts.map +1 -0
- package/dist/candles/use-candle-history.js +66 -0
- package/dist/candles/use-candle-history.js.map +1 -0
- package/dist/candles/use-candle-stream.d.ts +5 -4
- package/dist/candles/use-candle-stream.d.ts.map +1 -1
- package/dist/candles/use-candle-stream.js +17 -10
- package/dist/candles/use-candle-stream.js.map +1 -1
- package/dist/candles/use-candles.js +2 -2
- package/dist/candles/use-candles.js.map +1 -1
- package/dist/candles/use-lowcap-candle-source.d.ts +19 -0
- package/dist/candles/use-lowcap-candle-source.d.ts.map +1 -0
- package/dist/candles/use-lowcap-candle-source.js +25 -0
- package/dist/candles/use-lowcap-candle-source.js.map +1 -0
- package/dist/errors/normalize-protected-write-error.d.ts +5 -0
- package/dist/errors/normalize-protected-write-error.d.ts.map +1 -0
- package/dist/errors/normalize-protected-write-error.js +43 -0
- package/dist/errors/normalize-protected-write-error.js.map +1 -0
- package/dist/errors/normalize-symm-error.d.ts.map +1 -1
- package/dist/errors/normalize-symm-error.js +56 -43
- package/dist/errors/normalize-symm-error.js.map +1 -1
- package/dist/errors/symmio-request-error.d.ts +5 -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/index.d.ts +3 -0
- package/dist/gasless/index.d.ts.map +1 -1
- package/dist/gasless/index.js +22 -19
- package/dist/gasless/invalidate-relay-reads.d.ts +3 -1
- package/dist/gasless/invalidate-relay-reads.d.ts.map +1 -1
- package/dist/gasless/invalidate-relay-reads.js +115 -60
- package/dist/gasless/invalidate-relay-reads.js.map +1 -1
- package/dist/gasless/use-approve-operational-fee-allowance.d.ts +37 -0
- package/dist/gasless/use-approve-operational-fee-allowance.d.ts.map +1 -0
- package/dist/gasless/use-approve-operational-fee-allowance.js +48 -0
- package/dist/gasless/use-approve-operational-fee-allowance.js.map +1 -0
- package/dist/gasless/use-approve-operational-fee.d.ts +2 -2
- package/dist/gasless/use-approve-operational-fee.d.ts.map +1 -1
- package/dist/gasless/use-approve-operational-fee.js +28 -17
- package/dist/gasless/use-approve-operational-fee.js.map +1 -1
- package/dist/gasless/use-gasless-batch-funding.d.ts +22 -0
- package/dist/gasless/use-gasless-batch-funding.d.ts.map +1 -0
- package/dist/gasless/use-gasless-batch-funding.js +27 -0
- package/dist/gasless/use-gasless-batch-funding.js.map +1 -0
- package/dist/gasless/use-gasless-margin-funding.d.ts +26 -0
- package/dist/gasless/use-gasless-margin-funding.d.ts.map +1 -0
- package/dist/gasless/use-gasless-margin-funding.js +27 -0
- package/dist/gasless/use-gasless-margin-funding.js.map +1 -0
- package/dist/gasless/use-relay-gasless-batch.d.ts +5 -4
- package/dist/gasless/use-relay-gasless-batch.d.ts.map +1 -1
- package/dist/gasless/use-relay-gasless-batch.js.map +1 -1
- package/dist/index.d.ts +14 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +275 -256
- package/dist/instant-layer/index.d.ts +2 -0
- package/dist/instant-layer/index.d.ts.map +1 -1
- package/dist/instant-layer/index.js +25 -23
- package/dist/instant-layer/invalidate-delegation-grant.d.ts +17 -0
- package/dist/instant-layer/invalidate-delegation-grant.d.ts.map +1 -0
- package/dist/instant-layer/invalidate-delegation-grant.js +26 -0
- package/dist/instant-layer/invalidate-delegation-grant.js.map +1 -0
- package/dist/instant-layer/use-grant-delegation.d.ts +3 -1
- package/dist/instant-layer/use-grant-delegation.d.ts.map +1 -1
- package/dist/instant-layer/use-grant-delegation.js +19 -28
- package/dist/instant-layer/use-grant-delegation.js.map +1 -1
- package/dist/instant-layer/use-grant-delegations.d.ts +44 -0
- package/dist/instant-layer/use-grant-delegations.d.ts.map +1 -0
- package/dist/instant-layer/use-grant-delegations.js +36 -0
- package/dist/instant-layer/use-grant-delegations.js.map +1 -0
- package/dist/instant-layer/use-instant-close-fees.js +8 -8
- package/dist/instant-layer/use-instant-open-inputs.js +8 -8
- package/dist/instant-layer/use-session-key-selectors.d.ts +5 -2
- package/dist/instant-layer/use-session-key-selectors.d.ts.map +1 -1
- package/dist/instant-layer/use-session-key-selectors.js +9 -5
- package/dist/instant-layer/use-session-key-selectors.js.map +1 -1
- package/dist/instant-layer/use-simulate-grant-delegations.d.ts +25 -0
- package/dist/instant-layer/use-simulate-grant-delegations.d.ts.map +1 -0
- package/dist/instant-layer/use-simulate-grant-delegations.js +29 -0
- package/dist/instant-layer/use-simulate-grant-delegations.js.map +1 -0
- package/dist/pools/use-listing-config.d.ts +3 -1
- package/dist/pools/use-listing-config.d.ts.map +1 -1
- package/dist/pools/use-listing-config.js.map +1 -1
- package/dist/provider/symmio-provider.d.ts +31 -4
- package/dist/provider/symmio-provider.d.ts.map +1 -1
- package/dist/provider/symmio-provider.js +12 -11
- package/dist/provider/symmio-provider.js.map +1 -1
- package/dist/solvers/timelock-capability-cache.d.ts +9 -0
- package/dist/solvers/timelock-capability-cache.d.ts.map +1 -0
- package/dist/solvers/timelock-capability-cache.js +79 -0
- package/dist/solvers/timelock-capability-cache.js.map +1 -0
- package/dist/solvers/use-solver-info.d.ts +5 -2
- package/dist/solvers/use-solver-info.d.ts.map +1 -1
- package/dist/solvers/use-solver-info.js +35 -11
- package/dist/solvers/use-solver-info.js.map +1 -1
- package/dist/transactions/write-types.d.ts +13 -1
- package/dist/transactions/write-types.d.ts.map +1 -1
- package/dist/withdraw/index.d.ts +3 -0
- package/dist/withdraw/index.d.ts.map +1 -1
- package/dist/withdraw/use-deallocate-debounce-time.d.ts +29 -0
- package/dist/withdraw/use-deallocate-debounce-time.d.ts.map +1 -0
- package/dist/withdraw/use-deallocate-debounce-time.js +27 -0
- package/dist/withdraw/use-deallocate-debounce-time.js.map +1 -0
- package/dist/withdraw/use-finalize-withdraw-request.d.ts.map +1 -1
- package/dist/withdraw/use-finalize-withdraw-request.js +13 -12
- package/dist/withdraw/use-finalize-withdraw-request.js.map +1 -1
- package/dist/withdraw/use-initiate-withdraw.d.ts +2 -2
- package/dist/withdraw/use-initiate-withdraw.d.ts.map +1 -1
- package/dist/withdraw/use-initiate-withdraw.js +29 -17
- package/dist/withdraw/use-initiate-withdraw.js.map +1 -1
- package/dist/withdraw/use-pending-withdraw-requests-batch.d.ts +19 -0
- package/dist/withdraw/use-pending-withdraw-requests-batch.d.ts.map +1 -0
- package/dist/withdraw/use-pending-withdraw-requests-batch.js +27 -0
- package/dist/withdraw/use-pending-withdraw-requests-batch.js.map +1 -0
- package/dist/withdraw/use-request-cancel-withdraw.d.ts.map +1 -1
- package/dist/withdraw/use-request-cancel-withdraw.js +14 -13
- package/dist/withdraw/use-request-cancel-withdraw.js.map +1 -1
- package/dist/withdraw/use-withdraw-cooldown-of.d.ts +33 -0
- package/dist/withdraw/use-withdraw-cooldown-of.d.ts.map +1 -0
- package/dist/withdraw/use-withdraw-cooldown-of.js +27 -0
- package/dist/withdraw/use-withdraw-cooldown-of.js.map +1 -0
- package/dist/withdraw/use-withdraw.d.ts +3 -3
- package/dist/withdraw/use-withdraw.d.ts.map +1 -1
- package/dist/withdraw/use-withdraw.js +57 -31
- package/dist/withdraw/use-withdraw.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-initiate-withdraw.d.ts","sourceRoot":"","sources":["../../src/withdraw/use-initiate-withdraw.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-initiate-withdraw.d.ts","sourceRoot":"","sources":["../../src/withdraw/use-initiate-withdraw.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,0BAA0B,EAChC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,OAAO,EAAsB,KAAK,gCAAgC,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9G;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,gCAAgC,CAAC;AAE7E,mEAAmE;AACnE,MAAM,MAAM,sBAAsB,GAAG,WAAW,CAAC;AAEjD,kDAAkD;AAClD,MAAM,MAAM,6BAA6B,GAAG,iBAAiB,CAC3D,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,CAC3B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,GAAE,6BAAkC,GAAG,6BAA6B,CAqDjH"}
|
|
@@ -3,36 +3,48 @@ import { useSymmioChainId as e } from "../provider/use-symmio-chain-id.js";
|
|
|
3
3
|
import { useSymmioConfig as t } from "../provider/use-symmio-config.js";
|
|
4
4
|
import { normalizeSymmError as n } from "../errors/normalize-symm-error.js";
|
|
5
5
|
import { resolveWriteResult as r } from "../transactions/resolve-write-result.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { normalizeProtectedWriteError as i } from "../errors/normalize-protected-write-error.js";
|
|
7
|
+
import { predicateMatch as a } from "../utils/predicate-match.js";
|
|
8
|
+
import { useAutomaticTimelock as o } from "../account-layer/use-automatic-timelock.js";
|
|
9
|
+
import { getLastWithdrawRequestIdQueryKey as s, getPendingWithdrawRequestsBatchQueryKey as c, getPendingWithdrawRequestsQueryKey as l, getWithdrawableTimeQueryKey as u, initiateWithdrawMutationOptions as d } from "@symmio/trading-core";
|
|
10
|
+
import { useMutation as f, useQueryClient as p } from "@tanstack/react-query";
|
|
9
11
|
//#region src/withdraw/use-initiate-withdraw.ts
|
|
10
|
-
function
|
|
11
|
-
let
|
|
12
|
-
return
|
|
13
|
-
mutationKey:
|
|
12
|
+
function m(m = {}) {
|
|
13
|
+
let h = t(m), g = e(), _ = p(), v = o(h, m.automaticTimelock), y = d(h);
|
|
14
|
+
return f({
|
|
15
|
+
mutationKey: y.mutationKey,
|
|
14
16
|
mutationFn: async (e) => {
|
|
17
|
+
let t = e.timelock;
|
|
15
18
|
try {
|
|
16
|
-
let
|
|
17
|
-
|
|
19
|
+
let n = e.chainId ?? g;
|
|
20
|
+
t = await v(e, {
|
|
21
|
+
account: e.account,
|
|
22
|
+
chainId: n,
|
|
23
|
+
functionName: "initiateWithdraw",
|
|
24
|
+
explicit: t
|
|
25
|
+
});
|
|
26
|
+
let i = await r(h, await y.mutationFn({
|
|
18
27
|
...e,
|
|
19
|
-
chainId:
|
|
28
|
+
chainId: n,
|
|
29
|
+
...t ? { timelock: t } : {}
|
|
20
30
|
}), {
|
|
21
|
-
chainId:
|
|
22
|
-
waitForReceipt:
|
|
23
|
-
confirmations:
|
|
31
|
+
chainId: n,
|
|
32
|
+
waitForReceipt: m.waitForReceipt,
|
|
33
|
+
confirmations: m.confirmations
|
|
24
34
|
});
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
return v.finish(e, i), i;
|
|
36
|
+
} catch (r) {
|
|
37
|
+
throw v.fail(e, r), t ? i(r, t) : n(r);
|
|
27
38
|
}
|
|
28
39
|
},
|
|
29
40
|
onSuccess: (e, t) => {
|
|
41
|
+
e.receipt && _.invalidateQueries({ predicate: a(c, { configKey: h.getChainConfigKey(t.chainId ?? g) }) });
|
|
30
42
|
let n = { user: t.account };
|
|
31
|
-
|
|
43
|
+
_.invalidateQueries({ predicate: a(l, n) }), _.invalidateQueries({ predicate: a(s, n) }), _.invalidateQueries({ predicate: a(u, n) });
|
|
32
44
|
}
|
|
33
45
|
});
|
|
34
46
|
}
|
|
35
47
|
//#endregion
|
|
36
|
-
export {
|
|
48
|
+
export { m as useInitiateWithdraw };
|
|
37
49
|
|
|
38
50
|
//# sourceMappingURL=use-initiate-withdraw.js.map
|
|
@@ -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
|
|
1
|
+
{"version":3,"file":"use-initiate-withdraw.js","names":[],"sources":["../../src/withdraw/use-initiate-withdraw.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getLastWithdrawRequestIdQueryKey,\n getPendingWithdrawRequestsBatchQueryKey,\n getPendingWithdrawRequestsQueryKey,\n getWithdrawableTimeQueryKey,\n initiateWithdrawMutationOptions,\n type InitiateWithdrawParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useAutomaticTimelock } from \"../account-layer/use-automatic-timelock\";\nimport { normalizeProtectedWriteError } from \"../errors/normalize-protected-write-error\";\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 AutomaticTimelockWriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/**\n * Parameters for {@link useInitiateWithdraw}.\n */\nexport type UseInitiateWithdrawParameters = AutomaticTimelockWriteParameters;\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 const automaticTimelock = useAutomaticTimelock(config, parameters.automaticTimelock);\n\n const base = initiateWithdrawMutationOptions(config);\n\n return useMutation<InitiateWithdrawResult, SymmioRequestError, InitiateWithdrawParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n let authorization = variables.timelock;\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n authorization = await automaticTimelock(variables, {\n account: variables.account,\n chainId: resolvedChainId,\n functionName: \"initiateWithdraw\",\n explicit: authorization,\n });\n const hash = await base.mutationFn({\n ...variables,\n chainId: resolvedChainId,\n ...(authorization ? { timelock: authorization } : {}),\n });\n const result = resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n const settled = await result;\n automaticTimelock.finish(variables, settled);\n return settled;\n } catch (err) {\n automaticTimelock.fail(variables, err);\n throw authorization ? normalizeProtectedWriteError(err, authorization) : normalizeSymmError(err);\n }\n },\n onSuccess: (result, variables) => {\n /** Broadcast-only callers own confirmation and the later batch refresh. */\n if (result.receipt) {\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getPendingWithdrawRequestsBatchQueryKey, {\n configKey: config.getChainConfigKey(variables.chainId ?? chainId),\n }),\n });\n }\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":";;;;;;;;;;;AAiDA,SAAgB,EAAoB,IAA4C,CAAC,GAAkC;CACjH,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAoB,EAAqB,GAAQ,EAAW,iBAAiB,GAE7E,IAAO,EAAgC,CAAM;CAEnD,OAAO,EAAoF;EACzF,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI,IAAgB,EAAU;GAC9B,IAAI;IACF,IAAM,IAAkB,EAAU,WAAW;IAC7C,IAAgB,MAAM,EAAkB,GAAW;KACjD,SAAS,EAAU;KACnB,SAAS;KACT,cAAc;KACd,UAAU;IACZ,CAAC;IAWD,IAAM,IAAU,MALD,EAAmB,GAAQ,MALvB,EAAK,WAAW;KACjC,GAAG;KACH,SAAS;KACT,GAAI,IAAgB,EAAE,UAAU,EAAc,IAAI,CAAC;IACrD,CAAC,GAC+C;KAC9C,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CACsB;IAEtB,OADA,EAAkB,OAAO,GAAW,CAAO,GACpC;GACT,SAAS,GAAK;IAEZ,MADA,EAAkB,KAAK,GAAW,CAAG,GAC/B,IAAgB,EAA6B,GAAK,CAAa,IAAI,EAAmB,CAAG;GACjG;EACF;EACA,YAAY,GAAQ,MAAc;GAEhC,AAAI,EAAO,WACT,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAyC,EACjE,WAAW,EAAO,kBAAkB,EAAU,WAAW,CAAO,EAClE,CAAC,EACH,CAAC;GAEH,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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConfigParameter, GetPendingWithdrawRequestsBatchOptions, GetPendingWithdrawRequestsBatchReturnType } from '@symmio/trading-core';
|
|
2
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
|
+
/** Inputs for complete multi-subaccount pending-withdrawal reads. */
|
|
5
|
+
export type UsePendingWithdrawRequestsBatchParameters = GetPendingWithdrawRequestsBatchOptions & ConfigParameter;
|
|
6
|
+
/** Query state and complete per-user pending requests. */
|
|
7
|
+
export type UsePendingWithdrawRequestsBatchReturnType = UseQueryResult<GetPendingWithdrawRequestsBatchReturnType, SymmioRequestError>;
|
|
8
|
+
/**
|
|
9
|
+
* Read every pending-withdrawal page for each distinct user. Empty users disable
|
|
10
|
+
* automatic reads; errors are normalized and never become partial empty balances.
|
|
11
|
+
* @param parameters - Users, optional page size, chain/config and query overrides.
|
|
12
|
+
* @returns The complete query result. Presentation and polling policy stay with the consumer.
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const pending = usePendingWithdrawRequestsBatch({ users: subAccounts, chainId });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function usePendingWithdrawRequestsBatch(parameters?: UsePendingWithdrawRequestsBatchParameters): UsePendingWithdrawRequestsBatchReturnType;
|
|
19
|
+
//# sourceMappingURL=use-pending-withdraw-requests-batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-pending-withdraw-requests-batch.d.ts","sourceRoot":"","sources":["../../src/withdraw/use-pending-withdraw-requests-batch.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,sCAAsC,EAC3C,KAAK,yCAAyC,EAC/C,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,qEAAqE;AACrE,MAAM,MAAM,yCAAyC,GAAG,sCAAsC,GAAG,eAAe,CAAC;AACjH,0DAA0D;AAC1D,MAAM,MAAM,yCAAyC,GAAG,cAAc,CACpE,yCAAyC,EACzC,kBAAkB,CACnB,CAAC;AACF;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,UAAU,GAAE,yCAA8C,GACzD,yCAAyC,CAiB3C"}
|
|
@@ -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 { getPendingWithdrawRequestsBatchQueryOptions as r } from "@symmio/trading-core";
|
|
6
|
+
import { useQuery as i } from "@tanstack/react-query";
|
|
7
|
+
//#region src/withdraw/use-pending-withdraw-requests-batch.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 usePendingWithdrawRequestsBatch };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=use-pending-withdraw-requests-batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-pending-withdraw-requests-batch.js","names":[],"sources":["../../src/withdraw/use-pending-withdraw-requests-batch.ts"],"sourcesContent":["\"use client\";\nimport {\n getPendingWithdrawRequestsBatchQueryOptions,\n type ConfigParameter,\n type GetPendingWithdrawRequestsBatchOptions,\n type GetPendingWithdrawRequestsBatchReturnType,\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/** Inputs for complete multi-subaccount pending-withdrawal reads. */\nexport type UsePendingWithdrawRequestsBatchParameters = GetPendingWithdrawRequestsBatchOptions & ConfigParameter;\n/** Query state and complete per-user pending requests. */\nexport type UsePendingWithdrawRequestsBatchReturnType = UseQueryResult<\n GetPendingWithdrawRequestsBatchReturnType,\n SymmioRequestError\n>;\n/**\n * Read every pending-withdrawal page for each distinct user. Empty users disable\n * automatic reads; errors are normalized and never become partial empty balances.\n * @param parameters - Users, optional page size, chain/config and query overrides.\n * @returns The complete query result. Presentation and polling policy stay with the consumer.\n * @example\n * ```tsx\n * const pending = usePendingWithdrawRequestsBatch({ users: subAccounts, chainId });\n * ```\n */\nexport function usePendingWithdrawRequestsBatch(\n parameters: UsePendingWithdrawRequestsBatchParameters = {},\n): UsePendingWithdrawRequestsBatchReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const options = getPendingWithdrawRequestsBatchQueryOptions(config, {\n ...parameters,\n chainId: parameters.chainId ?? chainId,\n });\n return useQuery({\n ...options,\n queryFn: async () => {\n try {\n return await options.queryFn();\n } catch (error) {\n throw normalizeSymmError(error);\n }\n },\n }) as UsePendingWithdrawRequestsBatchReturnType;\n}\n"],"mappings":";;;;;;;AA6BA,SAAgB,EACd,IAAwD,CAAC,GACd;CAC3C,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAU,EAA4C,GAAQ;EAClE,GAAG;EACH,SAAS,EAAW,WAAW;CACjC,CAAC;CACD,OAAO,EAAS;EACd,GAAG;EACH,SAAS,YAAY;GACnB,IAAI;IACF,OAAO,MAAM,EAAQ,QAAQ;GAC/B,SAAS,GAAO;IACd,MAAM,EAAmB,CAAK;GAChC;EACF;CACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-cancel-withdraw.d.ts","sourceRoot":"","sources":["../../src/withdraw/use-request-cancel-withdraw.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-request-cancel-withdraw.d.ts","sourceRoot":"","sources":["../../src/withdraw/use-request-cancel-withdraw.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,+BAA+B,EACrC,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;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG,eAAe,CAAC;AAEjE,wEAAwE;AACxE,MAAM,MAAM,2BAA2B,GAAG,WAAW,CAAC;AAEtD,uDAAuD;AACvD,MAAM,MAAM,kCAAkC,GAAG,iBAAiB,CAChE,2BAA2B,EAC3B,kBAAkB,EAClB,+BAA+B,CAChC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,GAAE,kCAAuC,GAClD,kCAAkC,CA4CpC"}
|
|
@@ -4,37 +4,38 @@ import { useSymmioConfig as t } from "../provider/use-symmio-config.js";
|
|
|
4
4
|
import { normalizeSymmError as n } from "../errors/normalize-symm-error.js";
|
|
5
5
|
import { resolveWriteResult as r } from "../transactions/resolve-write-result.js";
|
|
6
6
|
import { predicateMatch as i } from "../utils/predicate-match.js";
|
|
7
|
-
import { getAccountBalanceInfoQueryKey as a, getAccountBalanceOfQueryKey as o,
|
|
8
|
-
import { useMutation as
|
|
7
|
+
import { getAccountBalanceInfoQueryKey as a, getAccountBalanceOfQueryKey as o, getPendingWithdrawRequestsBatchQueryKey as s, getPendingWithdrawRequestsQueryKey as c, getWithdrawRequestsQueryKey as l, requestCancelWithdrawMutationOptions as u } from "@symmio/trading-core";
|
|
8
|
+
import { useMutation as d, useQueryClient as f } from "@tanstack/react-query";
|
|
9
9
|
//#region src/withdraw/use-request-cancel-withdraw.ts
|
|
10
|
-
function
|
|
11
|
-
let
|
|
12
|
-
return
|
|
13
|
-
mutationKey:
|
|
10
|
+
function p(p = {}) {
|
|
11
|
+
let m = t(p), h = e(), g = f(), _ = u(m);
|
|
12
|
+
return d({
|
|
13
|
+
mutationKey: _.mutationKey,
|
|
14
14
|
mutationFn: async (e) => {
|
|
15
15
|
try {
|
|
16
|
-
let t = e.chainId ??
|
|
17
|
-
return r(
|
|
16
|
+
let t = e.chainId ?? h;
|
|
17
|
+
return r(m, await _.mutationFn({
|
|
18
18
|
...e,
|
|
19
19
|
chainId: t
|
|
20
20
|
}), {
|
|
21
21
|
chainId: t,
|
|
22
|
-
waitForReceipt:
|
|
23
|
-
confirmations:
|
|
22
|
+
waitForReceipt: p.waitForReceipt,
|
|
23
|
+
confirmations: p.confirmations
|
|
24
24
|
});
|
|
25
25
|
} catch (e) {
|
|
26
26
|
throw n(e);
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
onSuccess: (e, t) => {
|
|
30
|
+
e.receipt && g.invalidateQueries({ predicate: i(s, { configKey: m.getChainConfigKey(t.chainId ?? h) }) });
|
|
30
31
|
let n = { account: t.account };
|
|
31
|
-
|
|
32
|
+
g.invalidateQueries({ predicate: i(a, n) }), g.invalidateQueries({ predicate: i(o, n) });
|
|
32
33
|
let r = { user: t.account };
|
|
33
|
-
|
|
34
|
+
g.invalidateQueries({ predicate: i(c, r) }), g.invalidateQueries({ predicate: i(l, r) });
|
|
34
35
|
}
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
//#endregion
|
|
38
|
-
export {
|
|
39
|
+
export { p as useRequestCancelWithdraw };
|
|
39
40
|
|
|
40
41
|
//# sourceMappingURL=use-request-cancel-withdraw.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-request-cancel-withdraw.js","names":[],"sources":["../../src/withdraw/use-request-cancel-withdraw.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getAccountBalanceInfoQueryKey,\n getAccountBalanceOfQueryKey,\n getPendingWithdrawRequestsQueryKey,\n getWithdrawRequestsQueryKey,\n requestCancelWithdrawMutationOptions,\n type RequestCancelWithdrawParameters,\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 useRequestCancelWithdraw}.\n */\nexport type UseRequestCancelWithdrawParameters = WriteParameters;\n\n/** Result returned by the {@link useRequestCancelWithdraw} mutation. */\nexport type RequestCancelWithdrawResult = WriteResult;\n\n/** Return type of {@link useRequestCancelWithdraw}. */\nexport type UseRequestCancelWithdrawReturnType = UseMutationResult<\n RequestCancelWithdrawResult,\n SymmioRequestError,\n RequestCancelWithdrawParameters\n>;\n\n/**\n * Request cancellation of a pending withdraw request (routed through the\n * AccountLayer `_call` proxy). On success (after the receipt), the subaccount's\n * balance reads (`balanceInfo`, `balanceOf`) and its pending-requests / requests\n * queries are invalidated — cancel returns the reserved funds to the available\n * balance.\n *\n * @example\n * ```tsx\n * const { mutate } = useRequestCancelWithdraw();\n * mutate({ account: \"0xsub…\", requestId: 1n });\n * ```\n */\nexport function useRequestCancelWithdraw(\n parameters: UseRequestCancelWithdrawParameters = {},\n): UseRequestCancelWithdrawReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = requestCancelWithdrawMutationOptions(config);\n\n return useMutation<RequestCancelWithdrawResult, SymmioRequestError, RequestCancelWithdrawParameters>({\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: (
|
|
1
|
+
{"version":3,"file":"use-request-cancel-withdraw.js","names":[],"sources":["../../src/withdraw/use-request-cancel-withdraw.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getAccountBalanceInfoQueryKey,\n getAccountBalanceOfQueryKey,\n getPendingWithdrawRequestsBatchQueryKey,\n getPendingWithdrawRequestsQueryKey,\n getWithdrawRequestsQueryKey,\n requestCancelWithdrawMutationOptions,\n type RequestCancelWithdrawParameters,\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 useRequestCancelWithdraw}.\n */\nexport type UseRequestCancelWithdrawParameters = WriteParameters;\n\n/** Result returned by the {@link useRequestCancelWithdraw} mutation. */\nexport type RequestCancelWithdrawResult = WriteResult;\n\n/** Return type of {@link useRequestCancelWithdraw}. */\nexport type UseRequestCancelWithdrawReturnType = UseMutationResult<\n RequestCancelWithdrawResult,\n SymmioRequestError,\n RequestCancelWithdrawParameters\n>;\n\n/**\n * Request cancellation of a pending withdraw request (routed through the\n * AccountLayer `_call` proxy). On success (after the receipt), the subaccount's\n * balance reads (`balanceInfo`, `balanceOf`) and its pending-requests / requests\n * queries are invalidated — cancel returns the reserved funds to the available\n * balance.\n *\n * @example\n * ```tsx\n * const { mutate } = useRequestCancelWithdraw();\n * mutate({ account: \"0xsub…\", requestId: 1n });\n * ```\n */\nexport function useRequestCancelWithdraw(\n parameters: UseRequestCancelWithdrawParameters = {},\n): UseRequestCancelWithdrawReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = requestCancelWithdrawMutationOptions(config);\n\n return useMutation<RequestCancelWithdrawResult, SymmioRequestError, RequestCancelWithdrawParameters>({\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 /** Broadcast-only callers own confirmation and the later batch refresh. */\n if (result.receipt) {\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getPendingWithdrawRequestsBatchQueryKey, {\n configKey: config.getChainConfigKey(variables.chainId ?? chainId),\n }),\n });\n }\n // Cancel returns the reserved funds to the subaccount's available balance and\n // removes the request — refetch balances + the withdraw lists (after the receipt).\n const balancePartial = { account: variables.account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceInfoQueryKey, balancePartial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceOfQueryKey, balancePartial) });\n\n const withdrawPartial = { user: variables.account };\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getPendingWithdrawRequestsQueryKey, withdrawPartial),\n });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getWithdrawRequestsQueryKey, withdrawPartial) });\n },\n });\n}\n"],"mappings":";;;;;;;;;AA+CA,SAAgB,EACd,IAAiD,CAAC,GACd;CACpC,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAE7B,IAAO,EAAqC,CAAM;CAExD,OAAO,EAA8F;EACnG,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,GAAQ,MAAc;GAEhC,AAAI,EAAO,WACT,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAyC,EACjE,WAAW,EAAO,kBAAkB,EAAU,WAAW,CAAO,EAClE,CAAC,EACH,CAAC;GAIH,IAAM,IAAiB,EAAE,SAAS,EAAU,QAAQ;GAEpD,AADA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA+B,CAAc,EAAE,CAAC,GAC/G,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA6B,CAAc,EAAE,CAAC;GAE7G,IAAM,IAAkB,EAAE,MAAM,EAAU,QAAQ;GAIlD,AAHA,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAoC,CAAe,EAC/E,CAAC,GACD,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA6B,CAAe,EAAE,CAAC;EAChH;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ConfigParameter, GetWithdrawCooldownOfOptions, GetWithdrawCooldownOfReturnType } 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 useWithdrawCooldownOf}: the core query options (`user`,
|
|
6
|
+
* optional chain id, TanStack `query` overrides) plus an optional `config`.
|
|
7
|
+
*/
|
|
8
|
+
export type UseWithdrawCooldownOfParameters = GetWithdrawCooldownOfOptions & ConfigParameter;
|
|
9
|
+
/** Return type of {@link useWithdrawCooldownOf}. */
|
|
10
|
+
export type UseWithdrawCooldownOfReturnType = UseQueryResult<GetWithdrawCooldownOfReturnType, SymmioRequestError>;
|
|
11
|
+
/**
|
|
12
|
+
* Read a subaccount's raw `withdrawCooldownOf` value: the core's stored
|
|
13
|
+
* `deallocateTimestamp`, in Unix seconds.
|
|
14
|
+
*
|
|
15
|
+
* Deallocation and internal credits to withdrawable balance stamp it; ordinary
|
|
16
|
+
* external deposits do not. It is **a timestamp, not a duration**, and not the
|
|
17
|
+
* time a withdrawal unlocks — use {@link useWithdrawableTime} to know when a
|
|
18
|
+
* withdrawal initiated now could be finalized. `chainId` defaults to the
|
|
19
|
+
* connected chain.
|
|
20
|
+
*
|
|
21
|
+
* Deallocation hooks (`useDeallocate`, `useDeallocateAndInitiateWithdraw`,
|
|
22
|
+
* `useWithdraw`) refresh this read once they succeed.
|
|
23
|
+
*
|
|
24
|
+
* @param parameters - The subaccount (`user`), optional chain id, query overrides and config.
|
|
25
|
+
* @returns The TanStack query result; `data` is the stored timestamp in seconds (`0n` when never stamped).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const { data: lastCredit } = useWithdrawCooldownOf({ user: subAccount });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function useWithdrawCooldownOf(parameters: UseWithdrawCooldownOfParameters): UseWithdrawCooldownOfReturnType;
|
|
33
|
+
//# sourceMappingURL=use-withdraw-cooldown-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-withdraw-cooldown-of.d.ts","sourceRoot":"","sources":["../../src/withdraw/use-withdraw-cooldown-of.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,4BAA4B,EACjC,KAAK,+BAA+B,EACrC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIzE;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,4BAA4B,GAAG,eAAe,CAAC;AAE7F,oDAAoD;AACpD,MAAM,MAAM,+BAA+B,GAAG,cAAc,CAAC,+BAA+B,EAAE,kBAAkB,CAAC,CAAC;AAElH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,+BAA+B,GAAG,+BAA+B,CAkBlH"}
|
|
@@ -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 { getWithdrawCooldownOfQueryOptions as r } from "@symmio/trading-core";
|
|
6
|
+
import { useQuery as i } from "@tanstack/react-query";
|
|
7
|
+
//#region src/withdraw/use-withdraw-cooldown-of.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 useWithdrawCooldownOf };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=use-withdraw-cooldown-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-withdraw-cooldown-of.js","names":[],"sources":["../../src/withdraw/use-withdraw-cooldown-of.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getWithdrawCooldownOfQueryOptions,\n type ConfigParameter,\n type GetWithdrawCooldownOfOptions,\n type GetWithdrawCooldownOfReturnType,\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/**\n * Parameters for {@link useWithdrawCooldownOf}: the core query options (`user`,\n * optional chain id, TanStack `query` overrides) plus an optional `config`.\n */\nexport type UseWithdrawCooldownOfParameters = GetWithdrawCooldownOfOptions & ConfigParameter;\n\n/** Return type of {@link useWithdrawCooldownOf}. */\nexport type UseWithdrawCooldownOfReturnType = UseQueryResult<GetWithdrawCooldownOfReturnType, SymmioRequestError>;\n\n/**\n * Read a subaccount's raw `withdrawCooldownOf` value: the core's stored\n * `deallocateTimestamp`, in Unix seconds.\n *\n * Deallocation and internal credits to withdrawable balance stamp it; ordinary\n * external deposits do not. It is **a timestamp, not a duration**, and not the\n * time a withdrawal unlocks — use {@link useWithdrawableTime} to know when a\n * withdrawal initiated now could be finalized. `chainId` defaults to the\n * connected chain.\n *\n * Deallocation hooks (`useDeallocate`, `useDeallocateAndInitiateWithdraw`,\n * `useWithdraw`) refresh this read once they succeed.\n *\n * @param parameters - The subaccount (`user`), optional chain id, query overrides and config.\n * @returns The TanStack query result; `data` is the stored timestamp in seconds (`0n` when never stamped).\n *\n * @example\n * ```tsx\n * const { data: lastCredit } = useWithdrawCooldownOf({ user: subAccount });\n * ```\n */\nexport function useWithdrawCooldownOf(parameters: UseWithdrawCooldownOfParameters): UseWithdrawCooldownOfReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const options = getWithdrawCooldownOfQueryOptions(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 UseWithdrawCooldownOfReturnType;\n}\n"],"mappings":";;;;;;;AA4CA,SAAgB,EAAsB,GAA8E;CAClH,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAU,EAAkC,GAAQ;EACxD,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"}
|
|
@@ -2,14 +2,14 @@ import { WithdrawAutoParameters } from '@symmio/trading-core';
|
|
|
2
2
|
import { UseMutationResult } from '@tanstack/react-query';
|
|
3
3
|
import { Address } from 'viem';
|
|
4
4
|
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
5
|
-
import {
|
|
5
|
+
import { AutomaticTimelockWriteParameters, WriteResult } from '../transactions/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* Parameters for {@link useWithdraw}. `account` (the subaccount) and `chainId` are
|
|
8
8
|
* read at hook time so the hook can resolve the subaccount's isolation type via
|
|
9
9
|
* {@link useSubAccount}; the per-withdraw inputs (`amount`, `receiver`, …) are the
|
|
10
10
|
* mutation variables.
|
|
11
11
|
*/
|
|
12
|
-
export type UseWithdrawParameters =
|
|
12
|
+
export type UseWithdrawParameters = AutomaticTimelockWriteParameters & {
|
|
13
13
|
/** The subaccount to withdraw from. The connected wallet must be its on-chain owner. */
|
|
14
14
|
account?: Address;
|
|
15
15
|
/** Target chain id. Defaults to the connected chain. */
|
|
@@ -46,7 +46,7 @@ export type UseWithdrawReturnType = UseMutationResult<WithdrawResult, SymmioRequ
|
|
|
46
46
|
* scale anything.
|
|
47
47
|
*
|
|
48
48
|
* On success, the subaccount's balance reads (`balanceInfo`, `balanceOf`) and its
|
|
49
|
-
* pending-requests / withdrawable-time reads are invalidated.
|
|
49
|
+
* pending-requests / withdrawable-time / withdraw-cooldown reads are invalidated.
|
|
50
50
|
*
|
|
51
51
|
* @remarks
|
|
52
52
|
* On the `CUSTOM` path the SDK fetches a fresh Muon uPnL signature for the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-withdraw.d.ts","sourceRoot":"","sources":["../../src/withdraw/use-withdraw.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-withdraw.d.ts","sourceRoot":"","sources":["../../src/withdraw/use-withdraw.ts"],"names":[],"mappings":"AAEA,OAAO,EAWL,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC5F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAKpC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,OAAO,EAAsB,KAAK,gCAAgC,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9G;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,gCAAgC,GAAG;IACrE,wFAAwF;IACxF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,sBAAsB,EAAE,SAAS,GAAG,eAAe,GAAG,SAAS,CAAC,CAAC;AAEzG,2DAA2D;AAC3D,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC;AAEzC,0CAA0C;AAC1C,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,cAAc,EAAE,kBAAkB,EAAE,oBAAoB,CAAC,CAAC;AAEhH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,WAAW,CAAC,UAAU,GAAE,qBAA0B,GAAG,qBAAqB,CA4GzF"}
|
|
@@ -3,48 +3,74 @@ import { useSymmioChainId as e } from "../provider/use-symmio-chain-id.js";
|
|
|
3
3
|
import { useSymmioConfig as t } from "../provider/use-symmio-config.js";
|
|
4
4
|
import { normalizeSymmError as n } from "../errors/normalize-symm-error.js";
|
|
5
5
|
import { resolveWriteResult as r } from "../transactions/resolve-write-result.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import { normalizeProtectedWriteError as i } from "../errors/normalize-protected-write-error.js";
|
|
7
|
+
import { predicateMatch as a } from "../utils/predicate-match.js";
|
|
8
|
+
import { useAutomaticTimelock as o } from "../account-layer/use-automatic-timelock.js";
|
|
9
|
+
import { useSubAccount as s } from "../account-layer/use-sub-account.js";
|
|
10
|
+
import { SubAccountIsolationType as c, SymmError as l, getAccountBalanceInfoQueryKey as u, getAccountBalanceOfQueryKey as d, getPendingWithdrawRequestsBatchQueryKey as f, getPendingWithdrawRequestsQueryKey as p, getSubAccountQueryOptions as m, getWithdrawCooldownOfQueryKey as h, getWithdrawableTimeQueryKey as g, withdrawAutoMutationOptions as _ } from "@symmio/trading-core";
|
|
11
|
+
import { useMutation as v, useQueryClient as y } from "@tanstack/react-query";
|
|
10
12
|
//#region src/withdraw/use-withdraw.ts
|
|
11
|
-
function
|
|
12
|
-
let
|
|
13
|
-
account:
|
|
14
|
-
chainId:
|
|
15
|
-
config:
|
|
16
|
-
}),
|
|
17
|
-
return
|
|
18
|
-
mutationKey:
|
|
13
|
+
function b(b = {}) {
|
|
14
|
+
let x = t(b), S = e(), C = y(), w = o(x, b.automaticTimelock, b.account), T = b.chainId ?? S, { data: E } = s({
|
|
15
|
+
account: b.account,
|
|
16
|
+
chainId: b.chainId,
|
|
17
|
+
config: b.config
|
|
18
|
+
}), D = E?.isolationType, O = _(x);
|
|
19
|
+
return v({
|
|
20
|
+
mutationKey: O.mutationKey,
|
|
19
21
|
mutationFn: async (e) => {
|
|
22
|
+
let t = e.timelock;
|
|
20
23
|
try {
|
|
21
|
-
let
|
|
22
|
-
if (!
|
|
23
|
-
|
|
24
|
+
let n = b.account;
|
|
25
|
+
if (!n) throw new l("validation", "MISSING_ACCOUNT", "useWithdraw: `account` must be set on the hook.");
|
|
26
|
+
!t && b.automaticTimelock !== !1 && await w.guard(e, {
|
|
27
|
+
account: n,
|
|
28
|
+
chainId: T
|
|
29
|
+
});
|
|
30
|
+
let i = D, a = x.getSolver({ chainId: T }), o = b.automaticTimelock !== !1 && x.getChainConfig(T).timelockSupported !== !1 && a.capabilities?.timelockApproval !== !1 && (typeof b.automaticTimelock == "object" || a.id === "enigma" || a.capabilities?.timelockApproval === !0);
|
|
31
|
+
!t && o && (i ??= (await C.fetchQuery({
|
|
32
|
+
...m(x, {
|
|
33
|
+
account: n,
|
|
34
|
+
chainId: T
|
|
35
|
+
}),
|
|
36
|
+
retry: !1
|
|
37
|
+
})).isolationType, t = i === c.CUSTOM ? await w.batch(e, {
|
|
38
|
+
account: n,
|
|
39
|
+
chainId: T,
|
|
40
|
+
functionNames: ["deallocate", "initiateWithdraw"]
|
|
41
|
+
}) : await w(e, {
|
|
42
|
+
account: n,
|
|
43
|
+
chainId: T,
|
|
44
|
+
functionName: "initiateWithdraw"
|
|
45
|
+
}));
|
|
46
|
+
let s = await r(x, await O.mutationFn({
|
|
24
47
|
...e,
|
|
25
|
-
account:
|
|
26
|
-
chainId:
|
|
27
|
-
isolationType:
|
|
48
|
+
account: n,
|
|
49
|
+
chainId: T,
|
|
50
|
+
isolationType: i,
|
|
51
|
+
...t ? { timelock: t } : {}
|
|
28
52
|
}), {
|
|
29
|
-
chainId:
|
|
30
|
-
waitForReceipt:
|
|
31
|
-
confirmations:
|
|
53
|
+
chainId: T,
|
|
54
|
+
waitForReceipt: b.waitForReceipt,
|
|
55
|
+
confirmations: b.confirmations
|
|
32
56
|
});
|
|
33
|
-
|
|
34
|
-
|
|
57
|
+
return w.finish(e, s), s;
|
|
58
|
+
} catch (r) {
|
|
59
|
+
throw w.fail(e, r), t ? i(r, t) : n(r);
|
|
35
60
|
}
|
|
36
61
|
},
|
|
37
|
-
onSuccess: () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
62
|
+
onSuccess: (e) => {
|
|
63
|
+
e.receipt && C.invalidateQueries({ predicate: a(f, { configKey: x.getChainConfigKey(T) }) });
|
|
64
|
+
let t = b.account;
|
|
65
|
+
if (!t) return;
|
|
66
|
+
let n = { account: t };
|
|
67
|
+
C.invalidateQueries({ predicate: a(u, n) }), C.invalidateQueries({ predicate: a(d, n) });
|
|
68
|
+
let r = { user: t };
|
|
69
|
+
C.invalidateQueries({ predicate: a(p, r) }), C.invalidateQueries({ predicate: a(g, r) }), C.invalidateQueries({ predicate: a(h, r) });
|
|
44
70
|
}
|
|
45
71
|
});
|
|
46
72
|
}
|
|
47
73
|
//#endregion
|
|
48
|
-
export {
|
|
74
|
+
export { b as useWithdraw };
|
|
49
75
|
|
|
50
76
|
//# sourceMappingURL=use-withdraw.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-withdraw.js","names":[],"sources":["../../src/withdraw/use-withdraw.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getAccountBalanceInfoQueryKey,\n getAccountBalanceOfQueryKey,\n getPendingWithdrawRequestsQueryKey,\n getWithdrawableTimeQueryKey,\n SymmError,\n withdrawAutoMutationOptions,\n type WithdrawAutoParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport type { Address } from \"viem\";\nimport { useSubAccount } from \"../account-layer/use-sub-account\";\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 useWithdraw}. `account` (the subaccount) and `chainId` are\n * read at hook time so the hook can resolve the subaccount's isolation type via\n * {@link useSubAccount}; the per-withdraw inputs (`amount`, `receiver`, …) are the\n * mutation variables.\n */\nexport type UseWithdrawParameters = WriteParameters & {\n /** The subaccount to withdraw from. The connected wallet must be its on-chain owner. */\n account?: Address;\n /** Target chain id. Defaults to the connected chain. */\n chainId?: number;\n};\n\n/**\n * Variables for the {@link useWithdraw} mutation — the per-withdraw inputs, with\n * `amount` in the **collateral token's decimals**. `account`, `chainId`, and\n * `isolationType` are supplied by the hook, so the caller never passes them (nor\n * `parts`). `upnlSig` is optional; on the `CUSTOM` path a fresh Muon uPnL signature\n * is fetched for the deallocate leg when omitted.\n */\nexport type UseWithdrawVariables = Omit<WithdrawAutoParameters, \"account\" | \"isolationType\" | \"chainId\">;\n\n/** Result returned by the {@link useWithdraw} mutation. */\nexport type WithdrawResult = WriteResult;\n\n/** Return type of {@link useWithdraw}. */\nexport type UseWithdrawReturnType = UseMutationResult<WithdrawResult, SymmioRequestError, UseWithdrawVariables>;\n\n/**\n * Withdraw from a subaccount from a **minimal, collateral-decimals input** — the\n * high-level entry point that hides isolation, parts, and amount scaling.\n *\n * Pass the `account` (and optional `chainId`) to the hook; call `mutate` with just\n * `{ amount, receiver }`. The hook reads the subaccount's `isolationType` with\n * {@link useSubAccount} (deduped with any other `useSubAccount` on the same key —\n * e.g. one already driving a balance display) and hands it to the SDK, so the core\n * action skips a redundant on-chain read and picks the path: a `CUSTOM`\n * (cross-margin) subaccount deallocates then initiates in one atomic transaction; a\n * `MARKET` / `MARKET_DIRECTION` (VA / lowcap) subaccount only initiates the withdraw\n * request. On a cache miss the core action resolves `isolationType` itself.\n *\n * `amount` is in the **collateral token's decimals** (e.g. 6 for USDC). The hook\n * builds the classic same-chain withdraw part from it and, on the `CUSTOM` path,\n * scales it to the 18-decimal amount the deallocate leg needs — the caller does not\n * scale anything.\n *\n * On success, the subaccount's balance reads (`balanceInfo`, `balanceOf`) and its\n * pending-requests / withdrawable-time reads are invalidated.\n *\n * @remarks\n * On the `CUSTOM` path the SDK fetches a fresh Muon uPnL signature for the\n * deallocate leg unless you pass one as `upnlSig`; that leg is subject to the\n * on-chain deallocate debounce. Failures surface as a normalized\n * {@link SymmioRequestError}. Reach for `useDeallocateAndInitiateWithdraw` /\n * `useInitiateWithdraw` when you already know the isolation and want to drive one\n * specific path, or need custom (multi-part / cross-chain) withdraw parts.\n *\n * @example\n * ```tsx\n * const { mutate } = useWithdraw({ account: \"0xsub…\" });\n * // amount in the collateral token's decimals (6-dec USDC → 1 USDC):\n * mutate({ amount: 1_000000n, receiver: \"0xabc…\" });\n * ```\n */\nexport function useWithdraw(parameters: UseWithdrawParameters = {}): UseWithdrawReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const resolvedChainId = parameters.chainId ?? chainId;\n\n // Resolve the subaccount's isolation type via the standard hook (deduped by\n // react-query with any other useSubAccount on the same key), so the core action\n // skips a redundant getSubAccount RPC.\n const { data: subAccount } = useSubAccount({\n account: parameters.account,\n chainId: parameters.chainId,\n config: parameters.config,\n });\n const isolationType = subAccount?.isolationType;\n\n const base = withdrawAutoMutationOptions(config);\n\n return useMutation<WithdrawResult, SymmioRequestError, UseWithdrawVariables>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const account = parameters.account;\n if (!account) {\n throw new SymmError(\"validation\", \"MISSING_ACCOUNT\", \"useWithdraw: `account` must be set on the hook.\");\n }\n const hash = await base.mutationFn({ ...variables, account, chainId: resolvedChainId, isolationType });\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: () => {\n const account = parameters.account;\n if (!account) return;\n\n const balancePartial = { account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceInfoQueryKey, balancePartial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceOfQueryKey, balancePartial) });\n\n const withdrawPartial = { user: account };\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getPendingWithdrawRequestsQueryKey, withdrawPartial),\n });\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getWithdrawableTimeQueryKey, withdrawPartial),\n });\n },\n });\n}\n"],"mappings":";;;;;;;;;;AAqFA,SAAgB,EAAY,IAAoC,CAAC,GAA0B;CACzF,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAkB,EAAW,WAAW,GAKxC,EAAE,MAAM,MAAe,EAAc;EACzC,SAAS,EAAW;EACpB,SAAS,EAAW;EACpB,QAAQ,EAAW;CACrB,CAAC,GACK,IAAgB,GAAY,eAE5B,IAAO,EAA4B,CAAM;CAE/C,OAAO,EAAsE;EAC3E,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,IAAM,IAAU,EAAW;IAC3B,IAAI,CAAC,GACH,MAAM,IAAI,EAAU,cAAc,mBAAmB,iDAAiD;IAGxG,OAAO,EAAmB,GAAQ,MADf,EAAK,WAAW;KAAE,GAAG;KAAW;KAAS,SAAS;KAAiB;IAAc,CAAC,GAC7D;KACtC,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CAAC;GACH,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,iBAAiB;GACf,IAAM,IAAU,EAAW;GAC3B,IAAI,CAAC,GAAS;GAEd,IAAM,IAAiB,EAAE,WAAQ;GAEjC,AADA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA+B,CAAc,EAAE,CAAC,GAC/G,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA6B,CAAc,EAAE,CAAC;GAE7G,IAAM,IAAkB,EAAE,MAAM,EAAQ;GAIxC,AAHA,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAoC,CAAe,EAC/E,CAAC,GACD,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAA6B,CAAe,EACxE,CAAC;EACH;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"use-withdraw.js","names":[],"sources":["../../src/withdraw/use-withdraw.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getAccountBalanceInfoQueryKey,\n getAccountBalanceOfQueryKey,\n getPendingWithdrawRequestsBatchQueryKey,\n getPendingWithdrawRequestsQueryKey,\n getSubAccountQueryOptions,\n getWithdrawableTimeQueryKey,\n getWithdrawCooldownOfQueryKey,\n SubAccountIsolationType,\n SymmError,\n withdrawAutoMutationOptions,\n type WithdrawAutoParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport type { Address } from \"viem\";\nimport { useAutomaticTimelock } from \"../account-layer/use-automatic-timelock\";\nimport { useSubAccount } from \"../account-layer/use-sub-account\";\nimport { normalizeProtectedWriteError } from \"../errors/normalize-protected-write-error\";\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 AutomaticTimelockWriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/**\n * Parameters for {@link useWithdraw}. `account` (the subaccount) and `chainId` are\n * read at hook time so the hook can resolve the subaccount's isolation type via\n * {@link useSubAccount}; the per-withdraw inputs (`amount`, `receiver`, …) are the\n * mutation variables.\n */\nexport type UseWithdrawParameters = AutomaticTimelockWriteParameters & {\n /** The subaccount to withdraw from. The connected wallet must be its on-chain owner. */\n account?: Address;\n /** Target chain id. Defaults to the connected chain. */\n chainId?: number;\n};\n\n/**\n * Variables for the {@link useWithdraw} mutation — the per-withdraw inputs, with\n * `amount` in the **collateral token's decimals**. `account`, `chainId`, and\n * `isolationType` are supplied by the hook, so the caller never passes them (nor\n * `parts`). `upnlSig` is optional; on the `CUSTOM` path a fresh Muon uPnL signature\n * is fetched for the deallocate leg when omitted.\n */\nexport type UseWithdrawVariables = Omit<WithdrawAutoParameters, \"account\" | \"isolationType\" | \"chainId\">;\n\n/** Result returned by the {@link useWithdraw} mutation. */\nexport type WithdrawResult = WriteResult;\n\n/** Return type of {@link useWithdraw}. */\nexport type UseWithdrawReturnType = UseMutationResult<WithdrawResult, SymmioRequestError, UseWithdrawVariables>;\n\n/**\n * Withdraw from a subaccount from a **minimal, collateral-decimals input** — the\n * high-level entry point that hides isolation, parts, and amount scaling.\n *\n * Pass the `account` (and optional `chainId`) to the hook; call `mutate` with just\n * `{ amount, receiver }`. The hook reads the subaccount's `isolationType` with\n * {@link useSubAccount} (deduped with any other `useSubAccount` on the same key —\n * e.g. one already driving a balance display) and hands it to the SDK, so the core\n * action skips a redundant on-chain read and picks the path: a `CUSTOM`\n * (cross-margin) subaccount deallocates then initiates in one atomic transaction; a\n * `MARKET` / `MARKET_DIRECTION` (VA / lowcap) subaccount only initiates the withdraw\n * request. On a cache miss the core action resolves `isolationType` itself.\n *\n * `amount` is in the **collateral token's decimals** (e.g. 6 for USDC). The hook\n * builds the classic same-chain withdraw part from it and, on the `CUSTOM` path,\n * scales it to the 18-decimal amount the deallocate leg needs — the caller does not\n * scale anything.\n *\n * On success, the subaccount's balance reads (`balanceInfo`, `balanceOf`) and its\n * pending-requests / withdrawable-time / withdraw-cooldown reads are invalidated.\n *\n * @remarks\n * On the `CUSTOM` path the SDK fetches a fresh Muon uPnL signature for the\n * deallocate leg unless you pass one as `upnlSig`; that leg is subject to the\n * on-chain deallocate debounce. Failures surface as a normalized\n * {@link SymmioRequestError}. Reach for `useDeallocateAndInitiateWithdraw` /\n * `useInitiateWithdraw` when you already know the isolation and want to drive one\n * specific path, or need custom (multi-part / cross-chain) withdraw parts.\n *\n * @example\n * ```tsx\n * const { mutate } = useWithdraw({ account: \"0xsub…\" });\n * // amount in the collateral token's decimals (6-dec USDC → 1 USDC):\n * mutate({ amount: 1_000000n, receiver: \"0xabc…\" });\n * ```\n */\nexport function useWithdraw(parameters: UseWithdrawParameters = {}): UseWithdrawReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const automaticTimelock = useAutomaticTimelock(config, parameters.automaticTimelock, parameters.account);\n const resolvedChainId = parameters.chainId ?? chainId;\n\n // Resolve the subaccount's isolation type via the standard hook (deduped by\n // react-query with any other useSubAccount on the same key), so the core action\n // skips a redundant getSubAccount RPC.\n const { data: subAccount } = useSubAccount({\n account: parameters.account,\n chainId: parameters.chainId,\n config: parameters.config,\n });\n const isolationType = subAccount?.isolationType;\n\n const base = withdrawAutoMutationOptions(config);\n\n return useMutation<WithdrawResult, SymmioRequestError, UseWithdrawVariables>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n let authorization = variables.timelock;\n try {\n const account = parameters.account;\n if (!account) {\n throw new SymmError(\"validation\", \"MISSING_ACCOUNT\", \"useWithdraw: `account` must be set on the hook.\");\n }\n if (!authorization && parameters.automaticTimelock !== false)\n await automaticTimelock.guard(variables, { account, chainId: resolvedChainId });\n let actualIsolation = isolationType;\n const solver = config.getSolver({ chainId: resolvedChainId });\n const shouldDiscover =\n parameters.automaticTimelock !== false &&\n config.getChainConfig(resolvedChainId).timelockSupported !== false &&\n solver.capabilities?.timelockApproval !== false &&\n (typeof parameters.automaticTimelock === \"object\" ||\n solver.id === \"enigma\" ||\n solver.capabilities?.timelockApproval === true);\n if (!authorization && shouldDiscover) {\n actualIsolation ??= (\n await queryClient.fetchQuery({\n ...getSubAccountQueryOptions(config, { account, chainId: resolvedChainId }),\n retry: false,\n })\n ).isolationType;\n authorization =\n actualIsolation === SubAccountIsolationType.CUSTOM\n ? await automaticTimelock.batch(variables, {\n account,\n chainId: resolvedChainId,\n functionNames: [\"deallocate\", \"initiateWithdraw\"],\n })\n : await automaticTimelock(variables, {\n account,\n chainId: resolvedChainId,\n functionName: \"initiateWithdraw\",\n });\n }\n const hash = await base.mutationFn({\n ...variables,\n account,\n chainId: resolvedChainId,\n isolationType: actualIsolation,\n ...(authorization ? { timelock: authorization } : {}),\n });\n const result = resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n const settled = await result;\n automaticTimelock.finish(variables, settled);\n return settled;\n } catch (err) {\n automaticTimelock.fail(variables, err);\n throw authorization ? normalizeProtectedWriteError(err, authorization) : normalizeSymmError(err);\n }\n },\n onSuccess: (result) => {\n /** Broadcast-only callers own confirmation and the later batch refresh. */\n if (result.receipt) {\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getPendingWithdrawRequestsBatchQueryKey, {\n configKey: config.getChainConfigKey(resolvedChainId),\n }),\n });\n }\n const account = parameters.account;\n if (!account) return;\n\n const balancePartial = { account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceInfoQueryKey, balancePartial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceOfQueryKey, balancePartial) });\n\n const withdrawPartial = { user: account };\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getPendingWithdrawRequestsQueryKey, withdrawPartial),\n });\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getWithdrawableTimeQueryKey, withdrawPartial),\n });\n /** The `CUSTOM` path deallocates first, which stamps the cooldown timestamp. */\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getWithdrawCooldownOfQueryKey, withdrawPartial),\n });\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;AA2FA,SAAgB,EAAY,IAAoC,CAAC,GAA0B;CACzF,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAoB,EAAqB,GAAQ,EAAW,mBAAmB,EAAW,OAAO,GACjG,IAAkB,EAAW,WAAW,GAKxC,EAAE,MAAM,MAAe,EAAc;EACzC,SAAS,EAAW;EACpB,SAAS,EAAW;EACpB,QAAQ,EAAW;CACrB,CAAC,GACK,IAAgB,GAAY,eAE5B,IAAO,EAA4B,CAAM;CAE/C,OAAO,EAAsE;EAC3E,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI,IAAgB,EAAU;GAC9B,IAAI;IACF,IAAM,IAAU,EAAW;IAC3B,IAAI,CAAC,GACH,MAAM,IAAI,EAAU,cAAc,mBAAmB,iDAAiD;IAExG,AAAI,CAAC,KAAiB,EAAW,sBAAsB,MACrD,MAAM,EAAkB,MAAM,GAAW;KAAE;KAAS,SAAS;IAAgB,CAAC;IAChF,IAAI,IAAkB,GAChB,IAAS,EAAO,UAAU,EAAE,SAAS,EAAgB,CAAC,GACtD,IACJ,EAAW,sBAAsB,MACjC,EAAO,eAAe,CAAe,EAAE,sBAAsB,MAC7D,EAAO,cAAc,qBAAqB,OACzC,OAAO,EAAW,qBAAsB,YACvC,EAAO,OAAO,YACd,EAAO,cAAc,qBAAqB;IAC9C,AAAI,CAAC,KAAiB,MACpB,OACE,MAAM,EAAY,WAAW;KAC3B,GAAG,EAA0B,GAAQ;MAAE;MAAS,SAAS;KAAgB,CAAC;KAC1E,OAAO;IACT,CAAC,GACD,eACF,IACE,MAAoB,EAAwB,SACxC,MAAM,EAAkB,MAAM,GAAW;KACvC;KACA,SAAS;KACT,eAAe,CAAC,cAAc,kBAAkB;IAClD,CAAC,IACD,MAAM,EAAkB,GAAW;KACjC;KACA,SAAS;KACT,cAAc;IAChB,CAAC;IAcT,IAAM,IAAU,MALD,EAAmB,GAAQ,MAPvB,EAAK,WAAW;KACjC,GAAG;KACH;KACA,SAAS;KACT,eAAe;KACf,GAAI,IAAgB,EAAE,UAAU,EAAc,IAAI,CAAC;IACrD,CAAC,GAC+C;KAC9C,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CACsB;IAEtB,OADA,EAAkB,OAAO,GAAW,CAAO,GACpC;GACT,SAAS,GAAK;IAEZ,MADA,EAAkB,KAAK,GAAW,CAAG,GAC/B,IAAgB,EAA6B,GAAK,CAAa,IAAI,EAAmB,CAAG;GACjG;EACF;EACA,YAAY,MAAW;GAErB,AAAI,EAAO,WACT,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAyC,EACjE,WAAW,EAAO,kBAAkB,CAAe,EACrD,CAAC,EACH,CAAC;GAEH,IAAM,IAAU,EAAW;GAC3B,IAAI,CAAC,GAAS;GAEd,IAAM,IAAiB,EAAE,WAAQ;GAEjC,AADA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA+B,CAAc,EAAE,CAAC,GAC/G,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA6B,CAAc,EAAE,CAAC;GAE7G,IAAM,IAAkB,EAAE,MAAM,EAAQ;GAQxC,AAPA,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAoC,CAAe,EAC/E,CAAC,GACD,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAA6B,CAAe,EACxE,CAAC,GAED,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAA+B,CAAe,EAC1E,CAAC;EACH;CACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symmio/trading-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
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",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@tanstack/react-query": "^5.100.0",
|
|
92
92
|
"decimal.js": "^10.4.3",
|
|
93
93
|
"zustand": "^5.0.0",
|
|
94
|
-
"@symmio/trading-core": "^4.
|
|
94
|
+
"@symmio/trading-core": "^4.5.0"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
97
|
"react": "^19.0.0",
|