@symmio/trading-react 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account-layer/use-account-balance-of.d.ts +5 -4
- package/dist/account-layer/use-account-balance-of.d.ts.map +1 -1
- package/dist/account-layer/use-account-balance-of.js.map +1 -1
- package/dist/account-layer/use-add-margin.d.ts.map +1 -1
- package/dist/account-layer/use-add-margin.js +1 -3
- package/dist/account-layer/use-add-margin.js.map +1 -1
- package/dist/account-layer/use-allocate.d.ts.map +1 -1
- package/dist/account-layer/use-allocate.js +1 -3
- package/dist/account-layer/use-allocate.js.map +1 -1
- package/dist/account-layer/use-cancel-registration.d.ts.map +1 -1
- package/dist/account-layer/use-cancel-registration.js +1 -2
- package/dist/account-layer/use-cancel-registration.js.map +1 -1
- package/dist/account-layer/use-create-sub-accounts.d.ts.map +1 -1
- package/dist/account-layer/use-create-sub-accounts.js +1 -3
- package/dist/account-layer/use-create-sub-accounts.js.map +1 -1
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.d.ts.map +1 -1
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.js +1 -6
- package/dist/account-layer/use-deallocate-and-initiate-withdraw.js.map +1 -1
- package/dist/account-layer/use-deallocate.d.ts.map +1 -1
- package/dist/account-layer/use-deallocate.js +1 -3
- package/dist/account-layer/use-deallocate.js.map +1 -1
- package/dist/account-layer/use-delete-sub-account.d.ts.map +1 -1
- package/dist/account-layer/use-delete-sub-account.js +1 -2
- package/dist/account-layer/use-delete-sub-account.js.map +1 -1
- package/dist/account-layer/use-deposit-and-allocate.d.ts.map +1 -1
- package/dist/account-layer/use-deposit-and-allocate.js +1 -3
- package/dist/account-layer/use-deposit-and-allocate.js.map +1 -1
- package/dist/account-layer/use-deposit.d.ts.map +1 -1
- package/dist/account-layer/use-deposit.js +1 -3
- package/dist/account-layer/use-deposit.js.map +1 -1
- package/dist/account-layer/use-edit-account-name.d.ts.map +1 -1
- package/dist/account-layer/use-edit-account-name.js +1 -3
- package/dist/account-layer/use-edit-account-name.js.map +1 -1
- package/dist/account-layer/use-remove-margin.d.ts.map +1 -1
- package/dist/account-layer/use-remove-margin.js +1 -3
- package/dist/account-layer/use-remove-margin.js.map +1 -1
- package/dist/account-layer/use-request-to-register-affiliate.d.ts.map +1 -1
- package/dist/account-layer/use-request-to-register-affiliate.js +1 -2
- package/dist/account-layer/use-request-to-register-affiliate.js.map +1 -1
- package/dist/collateral/use-approve-collateral.d.ts.map +1 -1
- package/dist/collateral/use-approve-collateral.js +1 -2
- package/dist/collateral/use-approve-collateral.js.map +1 -1
- package/dist/errors/normalize-symm-error.d.ts.map +1 -1
- package/dist/errors/normalize-symm-error.js +1 -0
- package/dist/errors/normalize-symm-error.js.map +1 -1
- package/dist/errors/symmio-request-error.d.ts +19 -0
- package/dist/errors/symmio-request-error.d.ts.map +1 -1
- package/dist/errors/symmio-request-error.js +2 -1
- package/dist/errors/symmio-request-error.js.map +1 -1
- package/dist/gasless/gasless-relay-types.d.ts +115 -0
- package/dist/gasless/gasless-relay-types.d.ts.map +1 -0
- package/dist/gasless/gasless-relay-types.js +9 -0
- package/dist/gasless/gasless-relay-types.js.map +1 -0
- package/dist/gasless/index.d.ts +21 -0
- package/dist/gasless/index.d.ts.map +1 -0
- package/dist/gasless/index.js +21 -0
- package/dist/gasless/invalidate-relay-reads.d.ts +96 -0
- package/dist/gasless/invalidate-relay-reads.d.ts.map +1 -0
- package/dist/gasless/invalidate-relay-reads.js +107 -0
- package/dist/gasless/invalidate-relay-reads.js.map +1 -0
- package/dist/gasless/use-approve-operational-fee.d.ts +38 -0
- package/dist/gasless/use-approve-operational-fee.d.ts.map +1 -0
- package/dist/gasless/use-approve-operational-fee.js +37 -0
- package/dist/gasless/use-approve-operational-fee.js.map +1 -0
- package/dist/gasless/use-debounced-batch.d.ts +22 -0
- package/dist/gasless/use-debounced-batch.d.ts.map +1 -0
- package/dist/gasless/use-debounced-batch.js +27 -0
- package/dist/gasless/use-debounced-batch.js.map +1 -0
- package/dist/gasless/use-gasless-batch-fee-quote.d.ts +48 -0
- package/dist/gasless/use-gasless-batch-fee-quote.d.ts.map +1 -0
- package/dist/gasless/use-gasless-batch-fee-quote.js +33 -0
- package/dist/gasless/use-gasless-batch-fee-quote.js.map +1 -0
- package/dist/gasless/use-gasless-deposit-policy.d.ts +28 -0
- package/dist/gasless/use-gasless-deposit-policy.d.ts.map +1 -0
- package/dist/gasless/use-gasless-deposit-policy.js +27 -0
- package/dist/gasless/use-gasless-deposit-policy.js.map +1 -0
- package/dist/gasless/use-gasless-fee-quote.d.ts +25 -0
- package/dist/gasless/use-gasless-fee-quote.d.ts.map +1 -0
- package/dist/gasless/use-gasless-fee-quote.js +27 -0
- package/dist/gasless/use-gasless-fee-quote.js.map +1 -0
- package/dist/gasless/use-gasless-relay-confirmation.d.ts +72 -0
- package/dist/gasless/use-gasless-relay-confirmation.d.ts.map +1 -0
- package/dist/gasless/use-gasless-relay-confirmation.js +148 -0
- package/dist/gasless/use-gasless-relay-confirmation.js.map +1 -0
- package/dist/gasless/use-gasless-request-stream.d.ts +34 -0
- package/dist/gasless/use-gasless-request-stream.d.ts.map +1 -0
- package/dist/gasless/use-gasless-request-stream.js +86 -0
- package/dist/gasless/use-gasless-request-stream.js.map +1 -0
- package/dist/gasless/use-gasless-request-transactions.d.ts +42 -0
- package/dist/gasless/use-gasless-request-transactions.d.ts.map +1 -0
- package/dist/gasless/use-gasless-request-transactions.js +28 -0
- package/dist/gasless/use-gasless-request-transactions.js.map +1 -0
- package/dist/gasless/use-gasless-request.d.ts +56 -0
- package/dist/gasless/use-gasless-request.d.ts.map +1 -0
- package/dist/gasless/use-gasless-request.js +51 -0
- package/dist/gasless/use-gasless-request.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-address.d.ts +24 -0
- package/dist/gasless/use-gasless-wallet-address.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-address.js +27 -0
- package/dist/gasless/use-gasless-wallet-address.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-creation-fee.d.ts +29 -0
- package/dist/gasless/use-gasless-wallet-creation-fee.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-creation-fee.js +27 -0
- package/dist/gasless/use-gasless-wallet-creation-fee.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-execute-selectors.d.ts +44 -0
- package/dist/gasless/use-gasless-wallet-execute-selectors.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-execute-selectors.js +19 -0
- package/dist/gasless/use-gasless-wallet-execute-selectors.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-execute.d.ts +51 -0
- package/dist/gasless/use-gasless-wallet-execute.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-execute.js +44 -0
- package/dist/gasless/use-gasless-wallet-execute.js.map +1 -0
- package/dist/gasless/use-gasless-wallet-nonce.d.ts +27 -0
- package/dist/gasless/use-gasless-wallet-nonce.d.ts.map +1 -0
- package/dist/gasless/use-gasless-wallet-nonce.js +27 -0
- package/dist/gasless/use-gasless-wallet-nonce.js.map +1 -0
- package/dist/gasless/use-operational-fee-allowance.d.ts +23 -0
- package/dist/gasless/use-operational-fee-allowance.d.ts.map +1 -0
- package/dist/gasless/use-operational-fee-allowance.js +27 -0
- package/dist/gasless/use-operational-fee-allowance.js.map +1 -0
- package/dist/gasless/use-relay-gasless-batch.d.ts +48 -0
- package/dist/gasless/use-relay-gasless-batch.d.ts.map +1 -0
- package/dist/gasless/use-relay-gasless-batch.js +44 -0
- package/dist/gasless/use-relay-gasless-batch.js.map +1 -0
- package/dist/gasless/use-relay-instant-operations.d.ts +43 -0
- package/dist/gasless/use-relay-instant-operations.d.ts.map +1 -0
- package/dist/gasless/use-relay-instant-operations.js +44 -0
- package/dist/gasless/use-relay-instant-operations.js.map +1 -0
- package/dist/gasless/use-resubmit-gasless-request.d.ts +39 -0
- package/dist/gasless/use-resubmit-gasless-request.d.ts.map +1 -0
- package/dist/gasless/use-resubmit-gasless-request.js +56 -0
- package/dist/gasless/use-resubmit-gasless-request.js.map +1 -0
- package/dist/gasless/use-settle-gasless-deposit-existing-account.d.ts +41 -0
- package/dist/gasless/use-settle-gasless-deposit-existing-account.d.ts.map +1 -0
- package/dist/gasless/use-settle-gasless-deposit-existing-account.js +47 -0
- package/dist/gasless/use-settle-gasless-deposit-existing-account.js.map +1 -0
- package/dist/gasless/use-settle-gasless-deposit-new-account.d.ts +48 -0
- package/dist/gasless/use-settle-gasless-deposit-new-account.d.ts.map +1 -0
- package/dist/gasless/use-settle-gasless-deposit-new-account.js +48 -0
- package/dist/gasless/use-settle-gasless-deposit-new-account.js.map +1 -0
- package/dist/gasless/use-supports-gasless-service.d.ts +22 -0
- package/dist/gasless/use-supports-gasless-service.d.ts.map +1 -0
- package/dist/gasless/use-supports-gasless-service.js +13 -0
- package/dist/gasless/use-supports-gasless-service.js.map +1 -0
- package/dist/index.d.ts +29 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +251 -221
- package/dist/instant-layer/index.d.ts +7 -0
- package/dist/instant-layer/index.d.ts.map +1 -1
- package/dist/instant-layer/index.js +26 -19
- package/dist/instant-layer/use-active-delegations.d.ts +31 -0
- package/dist/instant-layer/use-active-delegations.d.ts.map +1 -0
- package/dist/instant-layer/use-active-delegations.js +23 -0
- package/dist/instant-layer/use-active-delegations.js.map +1 -0
- package/dist/instant-layer/use-are-delegations-active.d.ts +100 -0
- package/dist/instant-layer/use-are-delegations-active.d.ts.map +1 -0
- package/dist/instant-layer/use-are-delegations-active.js +60 -0
- package/dist/instant-layer/use-are-delegations-active.js.map +1 -0
- package/dist/instant-layer/use-finalize-revoke-delegation.d.ts +32 -0
- package/dist/instant-layer/use-finalize-revoke-delegation.d.ts.map +1 -0
- package/dist/instant-layer/use-finalize-revoke-delegation.js +45 -0
- package/dist/instant-layer/use-finalize-revoke-delegation.js.map +1 -0
- package/dist/instant-layer/use-grant-delegation.d.ts +12 -2
- package/dist/instant-layer/use-grant-delegation.d.ts.map +1 -1
- package/dist/instant-layer/use-grant-delegation.js +27 -20
- package/dist/instant-layer/use-grant-delegation.js.map +1 -1
- package/dist/instant-layer/use-initiate-revoke-delegation.d.ts +32 -0
- package/dist/instant-layer/use-initiate-revoke-delegation.d.ts.map +1 -0
- package/dist/instant-layer/use-initiate-revoke-delegation.js +45 -0
- package/dist/instant-layer/use-initiate-revoke-delegation.js.map +1 -0
- package/dist/instant-layer/use-pending-revocation.d.ts +119 -0
- package/dist/instant-layer/use-pending-revocation.d.ts.map +1 -0
- package/dist/instant-layer/use-pending-revocation.js +73 -0
- package/dist/instant-layer/use-pending-revocation.js.map +1 -0
- package/dist/instant-layer/use-revocation-cooldown.d.ts +24 -0
- package/dist/instant-layer/use-revocation-cooldown.d.ts.map +1 -0
- package/dist/instant-layer/use-revocation-cooldown.js +23 -0
- package/dist/instant-layer/use-revocation-cooldown.js.map +1 -0
- package/dist/instant-layer/use-session-key-selectors.d.ts +53 -0
- package/dist/instant-layer/use-session-key-selectors.d.ts.map +1 -0
- package/dist/instant-layer/use-session-key-selectors.js +25 -0
- package/dist/instant-layer/use-session-key-selectors.js.map +1 -0
- package/dist/margin/use-available-instant-open-margin.js +8 -8
- package/dist/markets/index.d.ts +1 -0
- package/dist/markets/index.d.ts.map +1 -1
- package/dist/markets/index.js +3 -2
- package/dist/markets/use-funding-fees-of-party-b.d.ts +47 -0
- package/dist/markets/use-funding-fees-of-party-b.d.ts.map +1 -0
- package/dist/markets/use-funding-fees-of-party-b.js +27 -0
- package/dist/markets/use-funding-fees-of-party-b.js.map +1 -0
- package/dist/provider/create-session-key-wallet-client-resolver.d.ts +68 -0
- package/dist/provider/create-session-key-wallet-client-resolver.d.ts.map +1 -0
- package/dist/provider/create-session-key-wallet-client-resolver.js +51 -0
- package/dist/provider/create-session-key-wallet-client-resolver.js.map +1 -0
- package/dist/provider/index.d.ts +1 -0
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +5 -4
- package/dist/provider/symmio-provider.d.ts +7 -2
- package/dist/provider/symmio-provider.d.ts.map +1 -1
- package/dist/provider/symmio-provider.js +10 -7
- package/dist/provider/symmio-provider.js.map +1 -1
- package/dist/quotes/index.d.ts +2 -0
- package/dist/quotes/index.d.ts.map +1 -1
- package/dist/quotes/use-account-upnl.js +9 -9
- package/dist/quotes/use-close-quote-group.js +13 -13
- package/dist/quotes/use-force-cancel-close-request.d.ts.map +1 -1
- package/dist/quotes/use-force-cancel-close-request.js +1 -4
- package/dist/quotes/use-force-cancel-close-request.js.map +1 -1
- package/dist/quotes/use-force-cancel-quote.d.ts.map +1 -1
- package/dist/quotes/use-force-cancel-quote.js +1 -4
- package/dist/quotes/use-force-cancel-quote.js.map +1 -1
- package/dist/quotes/use-force-close.d.ts +2 -1
- package/dist/quotes/use-force-close.d.ts.map +1 -1
- package/dist/quotes/use-force-close.js +14 -12
- package/dist/quotes/use-force-close.js.map +1 -1
- package/dist/quotes/use-limit-orders.js +9 -9
- package/dist/quotes/use-managed-quotes.d.ts.map +1 -1
- package/dist/quotes/use-managed-quotes.js +103 -103
- package/dist/quotes/use-managed-quotes.js.map +1 -1
- package/dist/quotes/use-party-a-open-positions.js +5 -5
- package/dist/quotes/use-quote-group-funding-history.d.ts +10 -7
- package/dist/quotes/use-quote-group-funding-history.d.ts.map +1 -1
- package/dist/quotes/use-quote-group-funding-history.js.map +1 -1
- package/dist/quotes/use-quote-group-funding.d.ts +4 -2
- package/dist/quotes/use-quote-group-funding.d.ts.map +1 -1
- package/dist/quotes/use-quote-group-funding.js.map +1 -1
- package/dist/quotes/use-quote-pending-funding.d.ts +62 -0
- package/dist/quotes/use-quote-pending-funding.d.ts.map +1 -0
- package/dist/quotes/use-quote-pending-funding.js +31 -0
- package/dist/quotes/use-quote-pending-funding.js.map +1 -0
- package/dist/quotes/use-quotes-funding.d.ts +4 -2
- package/dist/quotes/use-quotes-funding.d.ts.map +1 -1
- package/dist/quotes/use-quotes-funding.js.map +1 -1
- package/dist/quotes/use-quotes-pending-funding.d.ts +92 -0
- package/dist/quotes/use-quotes-pending-funding.d.ts.map +1 -0
- package/dist/quotes/use-quotes-pending-funding.js +94 -0
- package/dist/quotes/use-quotes-pending-funding.js.map +1 -0
- package/dist/quotes/use-request-to-cancel-close-request.d.ts.map +1 -1
- package/dist/quotes/use-request-to-cancel-close-request.js +1 -4
- package/dist/quotes/use-request-to-cancel-close-request.js.map +1 -1
- package/dist/quotes/use-request-to-cancel-quote.d.ts.map +1 -1
- package/dist/quotes/use-request-to-cancel-quote.js +1 -4
- package/dist/quotes/use-request-to-cancel-quote.js.map +1 -1
- package/dist/transactions/index.js +3 -3
- package/dist/transactions/resolve-write-result.d.ts +53 -2
- package/dist/transactions/resolve-write-result.d.ts.map +1 -1
- package/dist/transactions/resolve-write-result.js +52 -9
- package/dist/transactions/resolve-write-result.js.map +1 -1
- package/dist/transactions/write-types.d.ts +19 -1
- package/dist/transactions/write-types.d.ts.map +1 -1
- package/dist/utils/predicate-match.d.ts +7 -4
- package/dist/utils/predicate-match.d.ts.map +1 -1
- package/dist/utils/predicate-match.js +5 -5
- package/dist/utils/predicate-match.js.map +1 -1
- package/dist/withdraw/use-finalize-withdraw-request.d.ts.map +1 -1
- package/dist/withdraw/use-finalize-withdraw-request.js +1 -3
- package/dist/withdraw/use-finalize-withdraw-request.js.map +1 -1
- package/dist/withdraw/use-initiate-withdraw.d.ts.map +1 -1
- package/dist/withdraw/use-initiate-withdraw.js +1 -5
- package/dist/withdraw/use-initiate-withdraw.js.map +1 -1
- package/dist/withdraw/use-request-cancel-withdraw.d.ts.map +1 -1
- package/dist/withdraw/use-request-cancel-withdraw.js +1 -3
- package/dist/withdraw/use-request-cancel-withdraw.js.map +1 -1
- package/dist/withdraw/use-withdraw.d.ts.map +1 -1
- package/dist/withdraw/use-withdraw.js +2 -1
- package/dist/withdraw/use-withdraw.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { SymmError as e } from "@symmio/trading-core";
|
|
2
|
+
import { createWalletClient as t, custom as n, http as r } from "viem";
|
|
3
|
+
import { getClient as i, getWalletClient as a } from "wagmi/actions";
|
|
4
|
+
//#region src/provider/create-session-key-wallet-client-resolver.ts
|
|
5
|
+
function o(e, t) {
|
|
6
|
+
return e.toLowerCase() === t.toLowerCase();
|
|
7
|
+
}
|
|
8
|
+
function s(t, n) {
|
|
9
|
+
let r = t.chains.find((e) => e.id === n);
|
|
10
|
+
if (!r) throw new e("config", "UNSUPPORTED_CHAIN", `Chain ${n} is not registered in the wagmi config, so no session-key wallet client can be built for it.`);
|
|
11
|
+
return r;
|
|
12
|
+
}
|
|
13
|
+
function c(e, t, a) {
|
|
14
|
+
if (a) return a(t);
|
|
15
|
+
let o = i(e, { chainId: t });
|
|
16
|
+
return o ? n({ request: o.transport.request }) : r();
|
|
17
|
+
}
|
|
18
|
+
function l(e) {
|
|
19
|
+
let { account: n, chainId: r, wagmiConfig: i, transport: a } = e;
|
|
20
|
+
return t({
|
|
21
|
+
account: n,
|
|
22
|
+
chain: s(i, r),
|
|
23
|
+
transport: c(i, r, a)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function u(t, n) {
|
|
27
|
+
try {
|
|
28
|
+
return await a(t, { chainId: n });
|
|
29
|
+
} catch (t) {
|
|
30
|
+
throw new e("config", "NO_WALLET_CONNECTED", "No connected wallet. Connect a wallet before sending transactions.", { cause: t instanceof Error ? t : void 0 });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function d(t) {
|
|
34
|
+
let { getSessionAccount: n, wagmiConfig: r, transport: i } = t;
|
|
35
|
+
return async ({ chainId: t, from: a }) => {
|
|
36
|
+
let s = n();
|
|
37
|
+
if (a && s && o(a, s.address)) return l({
|
|
38
|
+
account: s,
|
|
39
|
+
chainId: t,
|
|
40
|
+
wagmiConfig: r,
|
|
41
|
+
transport: i
|
|
42
|
+
});
|
|
43
|
+
let c = await u(r, t);
|
|
44
|
+
if (a && !o(a, c.account.address)) throw new e("config", "SESSION_SIGNER_UNAVAILABLE", `Cannot sign as ${a}: it is neither the connected wallet (${c.account.address}) nor the loaded session key (${s ? s.address : "none loaded"}). Load the session key for that address, or the action would be signed by the wrong signer.`);
|
|
45
|
+
return c;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { d as createSessionKeyWalletClientResolver };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=create-session-key-wallet-client-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-session-key-wallet-client-resolver.js","names":[],"sources":["../../src/provider/create-session-key-wallet-client-resolver.ts"],"sourcesContent":["import { SymmError, type GetWalletClientFn, type SymmioWalletClient } from \"@symmio/trading-core\";\nimport { createWalletClient, custom, http, type Account, type Address, type Chain, type Transport } from \"viem\";\nimport type { Config as WagmiConfig } from \"wagmi\";\nimport { getClient, getWalletClient } from \"wagmi/actions\";\n\n/**\n * Parameters for {@link createSessionKeyWalletClientResolver}.\n */\nexport interface CreateSessionKeyWalletClientResolverParameters {\n /** Returns the session-key account to sign with, or null when no key is loaded. */\n getSessionAccount: () => Account | null;\n /** The wagmi config used to resolve the connected wallet and the target chain. */\n wagmiConfig: WagmiConfig;\n /** Optional per-chain transport override for the session-key client. Defaults to wagmi's transport for that chain. */\n transport?: (chainId: number) => Transport;\n}\n\n/**\n * Case-insensitive address comparison. Addresses reach the SDK from many\n * sources (contract reads, notifications, user input) with inconsistent EIP-55\n * checksumming, so equality must never depend on casing.\n */\nfunction isSameAddress(left: Address, right: Address): boolean {\n return left.toLowerCase() === right.toLowerCase();\n}\n\n/**\n * Resolve the viem `Chain` object for `chainId` from the wagmi config.\n *\n * @throws {SymmError} `UNSUPPORTED_CHAIN` when the wagmi config knows no such chain.\n */\nfunction resolveChain(wagmiConfig: WagmiConfig, chainId: number): Chain {\n const chain = wagmiConfig.chains.find((candidate) => candidate.id === chainId);\n\n if (!chain)\n throw new SymmError(\n \"config\",\n \"UNSUPPORTED_CHAIN\",\n `Chain ${chainId} is not registered in the wagmi config, so no session-key wallet client can be built for it.`,\n );\n return chain;\n}\n\n/**\n * Resolve the transport the session-key client should use for `chainId`.\n *\n * Prefers the transport the host already configured in wagmi for that chain —\n * reached through the supported `getClient` accessor — so the session key talks\n * to the app's own RPCs (custom endpoints, API keys, fallbacks, batching)\n * instead of viem's public default. A bare `http()` is only the last resort for\n * a chain wagmi has no client for.\n */\nfunction resolveTransport(\n wagmiConfig: WagmiConfig,\n chainId: number,\n override?: (chainId: number) => Transport,\n): Transport {\n if (override) return override(chainId);\n\n const client = getClient(wagmiConfig, { chainId });\n if (!client) return http();\n\n /**\n * `client.transport` is an already-instantiated transport, not a transport\n * factory, so it cannot be handed to `createWalletClient` directly. Wrapping\n * its EIP-1193 `request` in `custom` re-packages it as a factory while keeping\n * every configured behavior (URL, headers, retries, fallback order) intact.\n */\n return custom({ request: client.transport.request });\n}\n\n/**\n * Build the wallet client that signs with the loaded session-key account.\n */\nfunction createSessionKeyClient(parameters: {\n account: Account;\n chainId: number;\n wagmiConfig: WagmiConfig;\n transport?: (chainId: number) => Transport;\n}): SymmioWalletClient {\n const { account, chainId, wagmiConfig, transport } = parameters;\n\n return createWalletClient({\n account,\n chain: resolveChain(wagmiConfig, chainId),\n transport: resolveTransport(wagmiConfig, chainId, transport),\n });\n}\n\n/**\n * Resolve the wagmi-connected wallet client, normalizing wagmi's own failure\n * into the SDK's `NO_WALLET_CONNECTED` error.\n *\n * @throws {SymmError} `NO_WALLET_CONNECTED` when no wallet is connected.\n */\nasync function getConnectedWalletClient(wagmiConfig: WagmiConfig, chainId: number): Promise<SymmioWalletClient> {\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/**\n * Build a {@link GetWalletClientFn} that routes the SDK's `from` hint to a\n * session-key signer, falling back to the wagmi-connected wallet.\n *\n * Pass the result as `SymmioProvider`'s `getWalletClient` prop. Every SDK write\n * that can be relayed gaslessly asks the resolver for a signer and passes the\n * `from` address it wants; with this resolver installed, a `from` that matches\n * the loaded session key is signed in-memory with **no wallet prompt**, while\n * any other `from` (typically the account owner) keeps using the connected\n * wallet.\n *\n * The session-key client is bound to the transport the host configured in wagmi\n * for that chain, so it uses the app's RPCs rather than viem's public defaults.\n *\n * Unlike the provider's default resolver, an unresolvable `from` is a loud\n * error: it never falls back to prompting the connected wallet, because the\n * owner is also authorized on-chain and the write would silently succeed with\n * the wrong signer.\n *\n * The factory takes a `getSessionAccount` callback rather than a session-key\n * manager on purpose — `@symmio/trading-react` must not depend on\n * `@symmio/session-key`, and the callback is read fresh on every call so\n * loading, rotating, or clearing the key needs no new resolver.\n *\n * @param parameters - See {@link CreateSessionKeyWalletClientResolverParameters}.\n * @returns A resolver suitable for `SymmioProvider`'s `getWalletClient` prop.\n * @throws {SymmError} `UNSUPPORTED_CHAIN` when the requested chain is not in the\n * wagmi config, `SESSION_SIGNER_UNAVAILABLE` when `from` matches neither the\n * loaded session key nor the connected wallet, and `NO_WALLET_CONNECTED` when\n * the fallback path finds no connected wallet.\n *\n * @example\n * ```tsx\n * function Providers({ children }: { children: ReactNode }) {\n * const wagmiConfig = useConfig();\n * const getWalletClient = useMemo(\n * () =>\n * createSessionKeyWalletClientResolver({\n * wagmiConfig,\n * getSessionAccount: () => sessionKeyManager.getAccount(),\n * }),\n * [wagmiConfig],\n * );\n *\n * return (\n * <SymmioProvider symmioConfig={symmioConfig} getWalletClient={getWalletClient}>\n * {children}\n * </SymmioProvider>\n * );\n * }\n * ```\n */\nexport function createSessionKeyWalletClientResolver(\n parameters: CreateSessionKeyWalletClientResolverParameters,\n): GetWalletClientFn {\n const { getSessionAccount, wagmiConfig, transport } = parameters;\n\n return async ({ chainId, from }) => {\n const sessionAccount = getSessionAccount();\n\n if (from && sessionAccount && isSameAddress(from, sessionAccount.address))\n return createSessionKeyClient({ account: sessionAccount, chainId, wagmiConfig, transport });\n\n /**\n * `from` is a hint, and the account owner is a legitimate value for it — an\n * owner `from` resolves here through the connected wallet and must not\n * throw. Only a `from` that matches neither available signer is an error.\n */\n const walletClient = await getConnectedWalletClient(wagmiConfig, chainId);\n\n if (from && !isSameAddress(from, walletClient.account.address))\n throw new SymmError(\n \"config\",\n \"SESSION_SIGNER_UNAVAILABLE\",\n `Cannot sign as ${from}: it is neither the connected wallet (${walletClient.account.address}) nor the loaded session key (${sessionAccount ? sessionAccount.address : \"none loaded\"}). Load the session key for that address, or the action would be signed by the wrong signer.`,\n );\n\n return walletClient;\n };\n}\n"],"mappings":";;;;AAsBA,SAAS,EAAc,GAAe,GAAyB;CAC7D,OAAO,EAAK,YAAY,MAAM,EAAM,YAAY;AAClD;AAOA,SAAS,EAAa,GAA0B,GAAwB;CACtE,IAAM,IAAQ,EAAY,OAAO,MAAM,MAAc,EAAU,OAAO,CAAO;CAE7E,IAAI,CAAC,GACH,MAAM,IAAI,EACR,UACA,qBACA,SAAS,EAAQ,6FACnB;CACF,OAAO;AACT;AAWA,SAAS,EACP,GACA,GACA,GACW;CACX,IAAI,GAAU,OAAO,EAAS,CAAO;CAErC,IAAM,IAAS,EAAU,GAAa,EAAE,WAAQ,CAAC;CASjD,OARK,IAQE,EAAO,EAAE,SAAS,EAAO,UAAU,QAAQ,CAAC,IAR/B,EAAK;AAS3B;AAKA,SAAS,EAAuB,GAKT;CACrB,IAAM,EAAE,YAAS,YAAS,gBAAa,iBAAc;CAErD,OAAO,EAAmB;EACxB;EACA,OAAO,EAAa,GAAa,CAAO;EACxC,WAAW,EAAiB,GAAa,GAAS,CAAS;CAC7D,CAAC;AACH;AAQA,eAAe,EAAyB,GAA0B,GAA8C;CAC9G,IAAI;EACF,OAAO,MAAM,EAAgB,GAAa,EAAE,WAAQ,CAAC;CACvD,SAAS,GAAK;EACZ,MAAM,IAAI,EACR,UACA,uBACA,sEACA,EAAE,OAAO,aAAe,QAAQ,IAAM,KAAA,EAAU,CAClD;CACF;AACF;AAsDA,SAAgB,EACd,GACmB;CACnB,IAAM,EAAE,sBAAmB,gBAAa,iBAAc;CAEtD,OAAO,OAAO,EAAE,YAAS,cAAW;EAClC,IAAM,IAAiB,EAAkB;EAEzC,IAAI,KAAQ,KAAkB,EAAc,GAAM,EAAe,OAAO,GACtE,OAAO,EAAuB;GAAE,SAAS;GAAgB;GAAS;GAAa;EAAU,CAAC;EAO5F,IAAM,IAAe,MAAM,EAAyB,GAAa,CAAO;EAExE,IAAI,KAAQ,CAAC,EAAc,GAAM,EAAa,QAAQ,OAAO,GAC3D,MAAM,IAAI,EACR,UACA,8BACA,kBAAkB,EAAK,wCAAwC,EAAa,QAAQ,QAAQ,gCAAgC,IAAiB,EAAe,UAAU,cAAc,6FACtL;EAEF,OAAO;CACT;AACF"}
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { createSessionKeyWalletClientResolver, type CreateSessionKeyWalletClientResolverParameters, } from './create-session-key-wallet-client-resolver.js';
|
|
1
2
|
export { SymmioProvider, type SymmioProviderProps } from './symmio-provider.js';
|
|
2
3
|
export { useSymmioChainId } from './use-symmio-chain-id.js';
|
|
3
4
|
export { useSymmioConfig, type UseSymmioConfigParameters } from './use-symmio-config.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oCAAoC,EACpC,KAAK,8CAA8C,GACpD,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/provider/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { createSessionKeyWalletClientResolver as e } from "./create-session-key-wallet-client-resolver.js";
|
|
2
|
+
import { SymmioProvider as t } from "./symmio-provider.js";
|
|
3
|
+
import { useSymmioChainId as n } from "./use-symmio-chain-id.js";
|
|
4
|
+
import { useSymmioConfig as r } from "./use-symmio-config.js";
|
|
5
|
+
export { t as SymmioProvider, e as createSessionKeyWalletClientResolver, n as useSymmioChainId, r as useSymmioConfig };
|
|
@@ -32,9 +32,14 @@ export interface SymmioProviderProps {
|
|
|
32
32
|
* Custom wallet-client resolver. Receives `{ chainId, from? }` from the SDK
|
|
33
33
|
* and returns the wallet client to sign with. Use this to plug in
|
|
34
34
|
* session-key, multi-signer, or any non-wagmi flow — the resolver decides.
|
|
35
|
+
* {@link createSessionKeyWalletClientResolver} builds the session-key one.
|
|
35
36
|
*
|
|
36
|
-
* When omitted, the provider
|
|
37
|
-
* `from`
|
|
37
|
+
* When omitted, the provider signs with wagmi's connected wallet. That default
|
|
38
|
+
* can only honor a `from` that *is* the connected account: any other `from`
|
|
39
|
+
* (a session key, another signer) throws `SESSION_SIGNER_UNAVAILABLE` rather
|
|
40
|
+
* than silently prompting the connected wallet instead — the owner is also
|
|
41
|
+
* authorized on-chain, so such a write would otherwise succeed with the wrong
|
|
42
|
+
* signer and no way to notice.
|
|
38
43
|
*/
|
|
39
44
|
getWalletClient?: GetWalletClientFn;
|
|
40
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symmio-provider.d.ts","sourceRoot":"","sources":["../../src/provider/symmio-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"symmio-provider.d.ts","sourceRoot":"","sources":["../../src/provider/symmio-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EAEvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAMhD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;;;;;;;;;OAYG;IACH,YAAY,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;IACrD;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,eAAe,EAAE,mBAAmB,GACrC,EAAE,mBAAmB,+BAsErB"}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { SymmioConfigContext as e } from "./symmio-config-context.js";
|
|
3
3
|
import { SymmError as t, createConfig as n, listSupportedChains as r } from "@symmio/trading-core";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { getPublicClient as i, getWalletClient as a } from "wagmi/actions";
|
|
5
|
+
import { useMemo as o } from "react";
|
|
6
|
+
import { useChainId as s, useConfig as c } from "wagmi";
|
|
7
7
|
import { jsx as l } from "react/jsx-runtime";
|
|
8
8
|
//#region src/provider/symmio-provider.tsx
|
|
9
9
|
function u({ children: u, symmioConfig: d, defaultChainId: f, getWalletClient: p }) {
|
|
10
|
-
let m =
|
|
10
|
+
let m = c(), h = s(), g = r().some((e) => e === h) ? h : f, _ = o(() => n({
|
|
11
11
|
symmioConfig: d,
|
|
12
12
|
defaultChainId: g,
|
|
13
13
|
getClient: ({ chainId: e } = {}) => {
|
|
14
|
-
let n =
|
|
14
|
+
let n = i(m, { chainId: e });
|
|
15
15
|
if (!n) throw new t("config", "NO_PUBLIC_CLIENT", `No public client available for chain ${e ?? "(default)"}.`);
|
|
16
16
|
return n;
|
|
17
17
|
},
|
|
18
|
-
getWalletClient: p ?? (async ({ chainId: e }) => {
|
|
18
|
+
getWalletClient: p ?? (async ({ chainId: e, from: n }) => {
|
|
19
|
+
let r;
|
|
19
20
|
try {
|
|
20
|
-
|
|
21
|
+
r = await a(m, { chainId: e });
|
|
21
22
|
} catch (e) {
|
|
22
23
|
throw new t("config", "NO_WALLET_CONNECTED", "No connected wallet. Connect a wallet before sending transactions.", { cause: e instanceof Error ? e : void 0 });
|
|
23
24
|
}
|
|
25
|
+
if (n && n.toLowerCase() !== r.account.address.toLowerCase()) throw new t("config", "SESSION_SIGNER_UNAVAILABLE", `This action asked to sign as ${n}, but the default wallet-client resolver can only sign with the wagmi-connected wallet (${r.account.address}). Pass SymmioProvider a \`getWalletClient\` built by \`createSessionKeyWalletClientResolver\` to route session-key signers.`);
|
|
26
|
+
return r;
|
|
24
27
|
})
|
|
25
28
|
}), [
|
|
26
29
|
d,
|
|
@@ -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
|
|
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 type SymmioWalletClient,\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 * {@link createSessionKeyWalletClientResolver} builds the session-key one.\n *\n * When omitted, the provider signs with wagmi's connected wallet. That default\n * can only honor a `from` that *is* the connected account: any other `from`\n * (a session key, another signer) throws `SESSION_SIGNER_UNAVAILABLE` rather\n * than silently prompting the connected wallet instead — the owner is also\n * authorized on-chain, so such a write would otherwise succeed with the wrong\n * signer and no way to notice.\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, from }) => {\n let walletClient: SymmioWalletClient;\n\n try {\n walletClient = 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 * `from` is never forwarded to wagmi as `account` — a session key is\n * not a wagmi-connected account, so wagmi would reject it or\n * mis-resolve it. Instead the resolved signer is checked against the\n * request. Dropping a `from` it cannot honor would be silent: the\n * account owner is authorized on-chain for the same calls, so the\n * write succeeds after an unexpected wallet prompt and nothing looks\n * broken.\n */\n if (from && from.toLowerCase() !== walletClient.account.address.toLowerCase())\n throw new SymmError(\n \"config\",\n \"SESSION_SIGNER_UNAVAILABLE\",\n `This action asked to sign as ${from}, but the default wallet-client resolver can only sign with the wagmi-connected wallet (${walletClient.account.address}). Pass SymmioProvider a \\`getWalletClient\\` built by \\`createSessionKeyWalletClientResolver\\` to route session-key signers.`,\n );\n\n return walletClient;\n }),\n }),\n [symmioConfig, effectiveDefaultChainId, getWalletClientProp, wagmiConfig],\n );\n\n return <SymmioConfigContext.Provider value={config}>{children}</SymmioConfigContext.Provider>;\n}\n"],"mappings":";;;;;;;;AAmFA,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,YAAS,cAAW;GAC5B,IAAI;GAEJ,IAAI;IACF,IAAe,MAAM,EAAgB,GAAa,EAAE,WAAQ,CAAC;GAC/D,SAAS,GAAK;IACZ,MAAM,IAAI,EACR,UACA,uBACA,sEACA,EAAE,OAAO,aAAe,QAAQ,IAAM,KAAA,EAAU,CAClD;GACF;GAWA,IAAI,KAAQ,EAAK,YAAY,MAAM,EAAa,QAAQ,QAAQ,YAAY,GAC1E,MAAM,IAAI,EACR,UACA,8BACA,gCAAgC,EAAK,0FAA0F,EAAa,QAAQ,QAAQ,6HAC9J;GAEF,OAAO;EACT;CACJ,CAAC,GACH;EAAC;EAAc;EAAyB;EAAqB;CAAW,CAC1E;CAEA,OAAO,kBAAC,EAAoB,UAArB;EAA8B,OAAO;EAAS;CAAuC,CAAA;AAC9F"}
|
package/dist/quotes/index.d.ts
CHANGED
|
@@ -20,10 +20,12 @@ export * from './use-quote-group-funding.js';
|
|
|
20
20
|
export * from './use-quote-group-funding-history.js';
|
|
21
21
|
export * from './use-quote-group-margin-risk.js';
|
|
22
22
|
export * from './use-quote-history.js';
|
|
23
|
+
export * from './use-quote-pending-funding.js';
|
|
23
24
|
export * from './use-quote-platform-fee.js';
|
|
24
25
|
export * from './use-quote-price-history.js';
|
|
25
26
|
export * from './use-quote-upnl-and-pnl.js';
|
|
26
27
|
export * from './use-quotes-funding.js';
|
|
28
|
+
export * from './use-quotes-pending-funding.js';
|
|
27
29
|
export * from './use-request-to-cancel-close-request.js';
|
|
28
30
|
export * from './use-request-to-cancel-quote.js';
|
|
29
31
|
export * from './use-subgraph-query.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/quotes/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uCAAuC,CAAC;AACtD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/quotes/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uCAAuC,CAAC;AACtD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC"}
|
|
@@ -3,8 +3,8 @@ import { useMarkets as e } from "../markets/use-markets.js";
|
|
|
3
3
|
import { usePrices as t } from "../price-service/use-prices.js";
|
|
4
4
|
import { useManagedQuotes as n } from "./use-managed-quotes.js";
|
|
5
5
|
import { calculateQuoteUpnlWei as r, isActivePosition as i } from "@symmio/trading-core";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { parseUnits as a } from "viem";
|
|
7
|
+
import { useCallback as o, useMemo as s } from "react";
|
|
8
8
|
//#region src/quotes/use-account-upnl.ts
|
|
9
9
|
function c(c = {}) {
|
|
10
10
|
let { account: l, chainId: u, solverId: d, enabled: f = !0, live: p = !1, ...m } = c, h = n({
|
|
@@ -16,13 +16,13 @@ function c(c = {}) {
|
|
|
16
16
|
...m,
|
|
17
17
|
chainId: u,
|
|
18
18
|
solverId: d
|
|
19
|
-
}), { refetch: _ } = h, { refetch: v } = g, y =
|
|
19
|
+
}), { refetch: _ } = h, { refetch: v } = g, y = o(async () => {
|
|
20
20
|
_(), await v();
|
|
21
|
-
}, [_, v]), b =
|
|
21
|
+
}, [_, v]), b = s(() => h.quotes.filter((e) => i(e) && e.openQuantity > 0n && (e.openedPrice ?? e.requestedOpenPrice) > 0n), [h.quotes]), x = s(() => {
|
|
22
22
|
let e = /* @__PURE__ */ new Map();
|
|
23
23
|
for (let t of g.data ?? []) t.symbolId !== void 0 && t.name && e.set(String(t.symbolId), t.name);
|
|
24
24
|
return e;
|
|
25
|
-
}, [g.data]), S =
|
|
25
|
+
}, [g.data]), S = s(() => {
|
|
26
26
|
let e = /* @__PURE__ */ new Set();
|
|
27
27
|
for (let t of b) {
|
|
28
28
|
let n = x.get(String(t.symbolId));
|
|
@@ -37,15 +37,15 @@ function c(c = {}) {
|
|
|
37
37
|
enabled: f && S.length > 0
|
|
38
38
|
});
|
|
39
39
|
return {
|
|
40
|
-
upnl:
|
|
40
|
+
upnl: s(() => {
|
|
41
41
|
if (b.length === 0) return 0n;
|
|
42
42
|
let e = 0n;
|
|
43
43
|
for (let t of b) {
|
|
44
44
|
let n = x.get(String(t.symbolId)), i = n ? C[n]?.markPrice : void 0;
|
|
45
45
|
if (i === void 0) return;
|
|
46
|
-
let
|
|
46
|
+
let o;
|
|
47
47
|
try {
|
|
48
|
-
|
|
48
|
+
o = a(i, 18);
|
|
49
49
|
} catch {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
@@ -53,7 +53,7 @@ function c(c = {}) {
|
|
|
53
53
|
positionType: t.positionType,
|
|
54
54
|
openQuantity: t.openQuantity,
|
|
55
55
|
openedPrice: t.openedPrice ?? t.requestedOpenPrice,
|
|
56
|
-
markPrice:
|
|
56
|
+
markPrice: o
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
return e;
|
|
@@ -5,8 +5,8 @@ import { normalizeSymmError as n } from "../errors/normalize-symm-error.js";
|
|
|
5
5
|
import { useNotifications as r } from "../websocket/use-notifications.js";
|
|
6
6
|
import { predicateMatch as i } from "../utils/predicate-match.js";
|
|
7
7
|
import { NotificationType as a, getInstantClosesQueryKey as o, instantCloseBulkAutoMutationOptions as s, planGroupClose as c, toGroupCloseCandidates as l } from "@symmio/trading-core";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { formatUnits as u } from "viem";
|
|
9
|
+
import { useCallback as d, useMemo as f, useRef as p, useState as m } from "react";
|
|
10
10
|
import { useQueryClient as h } from "@tanstack/react-query";
|
|
11
11
|
//#region src/quotes/use-close-quote-group.ts
|
|
12
12
|
var g = 18, _ = new Set(["FillMarketOrderInstantClose", "FillLimitOrderClose"]), v = {
|
|
@@ -16,9 +16,9 @@ var g = 18, _ = new Set(["FillMarketOrderInstantClose", "FillLimitOrderClose"]),
|
|
|
16
16
|
targetQuantity: 0n
|
|
17
17
|
};
|
|
18
18
|
function y(y = {}) {
|
|
19
|
-
let b = t(y), x = e(), S = h(), [C, w] =
|
|
19
|
+
let b = t(y), x = e(), S = h(), [C, w] = m(v), T = p(v), E = p(!1), [D, O] = m(), k = p(void 0), A = d((e) => {
|
|
20
20
|
T.current = e, w(e);
|
|
21
|
-
}, []), j =
|
|
21
|
+
}, []), j = d((e) => {
|
|
22
22
|
let t = T.current, r = t.steps.findIndex((t) => t.status === "closing" && String(t.quoteId) === e.quoteId);
|
|
23
23
|
if (r < 0) return;
|
|
24
24
|
let i = e.type === a.SUCCESS && e.lastSeenAction !== null && _.has(e.lastSeenAction), o = e.type === a.FAILED;
|
|
@@ -58,14 +58,14 @@ function y(y = {}) {
|
|
|
58
58
|
enabled: !!D && C.steps.some((e) => e.status === "closing"),
|
|
59
59
|
onNotification: j
|
|
60
60
|
});
|
|
61
|
-
let M =
|
|
61
|
+
let M = d(async (e) => {
|
|
62
62
|
if (E.current || T.current.steps.some((e) => e.status === "closing")) return {
|
|
63
63
|
ok: !1,
|
|
64
64
|
closedQuantity: 0n,
|
|
65
65
|
steps: [],
|
|
66
66
|
error: n(/* @__PURE__ */ Error("A group close is already in flight."))
|
|
67
67
|
};
|
|
68
|
-
let { group: t, targetQuantity: r, minAcceptableQuoteValue: a, slippage:
|
|
68
|
+
let { group: t, targetQuantity: r, minAcceptableQuoteValue: a, slippage: d, markPrice: f, from: p, notificationsAccount: m } = e, h = e.chainId ?? x, _ = c(l(t.quotes, a), r);
|
|
69
69
|
if (!_.feasible) return A({
|
|
70
70
|
status: "failed",
|
|
71
71
|
steps: [],
|
|
@@ -87,7 +87,7 @@ function y(y = {}) {
|
|
|
87
87
|
}));
|
|
88
88
|
E.current = !0;
|
|
89
89
|
let C = v.get(y[0].key);
|
|
90
|
-
k.current = h, O(
|
|
90
|
+
k.current = h, O(m ?? C.vaAddress ?? C.partyA), A({
|
|
91
91
|
status: "closing",
|
|
92
92
|
steps: y.map((e) => ({
|
|
93
93
|
...e,
|
|
@@ -106,12 +106,12 @@ function y(y = {}) {
|
|
|
106
106
|
market: { id: Number(t.symbolId) },
|
|
107
107
|
positionType: t.positionType,
|
|
108
108
|
quoteId: e.quoteId,
|
|
109
|
-
quantityToClose:
|
|
110
|
-
slippage:
|
|
111
|
-
markPrice:
|
|
109
|
+
quantityToClose: u(e.closeQuantity, g),
|
|
110
|
+
slippage: d,
|
|
111
|
+
markPrice: f
|
|
112
112
|
};
|
|
113
113
|
}),
|
|
114
|
-
from:
|
|
114
|
+
from: p,
|
|
115
115
|
chainId: h
|
|
116
116
|
});
|
|
117
117
|
} catch (e) {
|
|
@@ -150,9 +150,9 @@ function y(y = {}) {
|
|
|
150
150
|
b,
|
|
151
151
|
x,
|
|
152
152
|
S
|
|
153
|
-
]), N =
|
|
153
|
+
]), N = d(() => {
|
|
154
154
|
E.current || (k.current = void 0, O(void 0), A(v));
|
|
155
|
-
}, [A]), P =
|
|
155
|
+
}, [A]), P = f(() => C.targetQuantity <= 0n ? 0 : Number(C.closedQuantity * 10000n / C.targetQuantity) / 100, [C.closedQuantity, C.targetQuantity]);
|
|
156
156
|
return {
|
|
157
157
|
close: M,
|
|
158
158
|
reset: N,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-force-cancel-close-request.d.ts","sourceRoot":"","sources":["../../src/quotes/use-force-cancel-close-request.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,iCAAiC,EACvC,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,yDAAyD;AACzD,MAAM,MAAM,oCAAoC,GAAG,eAAe,CAAC;AAEnE,0EAA0E;AAC1E,MAAM,MAAM,6BAA6B,GAAG,WAAW,CAAC;AAExD,yDAAyD;AACzD,MAAM,MAAM,oCAAoC,GAAG,iBAAiB,CAClE,6BAA6B,EAC7B,kBAAkB,EAClB,iCAAiC,CAClC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,GAAE,oCAAyC,GACpD,oCAAoC,
|
|
1
|
+
{"version":3,"file":"use-force-cancel-close-request.d.ts","sourceRoot":"","sources":["../../src/quotes/use-force-cancel-close-request.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,iCAAiC,EACvC,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,yDAAyD;AACzD,MAAM,MAAM,oCAAoC,GAAG,eAAe,CAAC;AAEnE,0EAA0E;AAC1E,MAAM,MAAM,6BAA6B,GAAG,WAAW,CAAC;AAExD,yDAAyD;AACzD,MAAM,MAAM,oCAAoC,GAAG,iBAAiB,CAClE,6BAA6B,EAC7B,kBAAkB,EAClB,iCAAiC,CAClC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,GAAE,oCAAyC,GACpD,oCAAoC,CA6BtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-force-cancel-close-request.js","names":[],"sources":["../../src/quotes/use-force-cancel-close-request.ts"],"sourcesContent":["\"use client\";\n\nimport {\n forceCancelCloseRequestMutationOptions,\n getPartyAOpenPositionsQueryKey,\n type ForceCancelCloseRequestParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useForceCancelCloseRequest}. */\nexport type UseForceCancelCloseRequestParameters = WriteParameters;\n\n/** Result returned by the {@link useForceCancelCloseRequest} mutation. */\nexport type ForceCancelCloseRequestResult = WriteResult;\n\n/** Return type of {@link useForceCancelCloseRequest}. */\nexport type UseForceCancelCloseRequestReturnType = UseMutationResult<\n ForceCancelCloseRequestResult,\n SymmioRequestError,\n ForceCancelCloseRequestParameters\n>;\n\n/**\n * Force-cancel a stalled pending close (`forceCancelCloseRequest`, routed through\n * the AccountLayer `_call` proxy). Only valid once the quote is\n * `CANCEL_CLOSE_PENDING` (partyA already called `requestToCancelCloseRequest` and\n * partyB never acted) **and** the force-cancel-close cooldown has elapsed — see\n * {@link useCoolDownsOfMA} (index 2) plus the quote's `statusModifyTimestamp`. The\n * quote returns to `OPENED`. On success (after the receipt) the subaccount's\n * open-positions read is invalidated.\n *\n * @example\n * ```tsx\n * const { mutate } = useForceCancelCloseRequest();\n * mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useForceCancelCloseRequest(\n parameters: UseForceCancelCloseRequestParameters = {},\n): UseForceCancelCloseRequestReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = forceCancelCloseRequestMutationOptions(config);\n\n return useMutation<ForceCancelCloseRequestResult, SymmioRequestError, ForceCancelCloseRequestParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({
|
|
1
|
+
{"version":3,"file":"use-force-cancel-close-request.js","names":[],"sources":["../../src/quotes/use-force-cancel-close-request.ts"],"sourcesContent":["\"use client\";\n\nimport {\n forceCancelCloseRequestMutationOptions,\n getPartyAOpenPositionsQueryKey,\n type ForceCancelCloseRequestParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useForceCancelCloseRequest}. */\nexport type UseForceCancelCloseRequestParameters = WriteParameters;\n\n/** Result returned by the {@link useForceCancelCloseRequest} mutation. */\nexport type ForceCancelCloseRequestResult = WriteResult;\n\n/** Return type of {@link useForceCancelCloseRequest}. */\nexport type UseForceCancelCloseRequestReturnType = UseMutationResult<\n ForceCancelCloseRequestResult,\n SymmioRequestError,\n ForceCancelCloseRequestParameters\n>;\n\n/**\n * Force-cancel a stalled pending close (`forceCancelCloseRequest`, routed through\n * the AccountLayer `_call` proxy). Only valid once the quote is\n * `CANCEL_CLOSE_PENDING` (partyA already called `requestToCancelCloseRequest` and\n * partyB never acted) **and** the force-cancel-close cooldown has elapsed — see\n * {@link useCoolDownsOfMA} (index 2) plus the quote's `statusModifyTimestamp`. The\n * quote returns to `OPENED`. On success (after the receipt) the subaccount's\n * open-positions read is invalidated.\n *\n * @example\n * ```tsx\n * const { mutate } = useForceCancelCloseRequest();\n * mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useForceCancelCloseRequest(\n parameters: UseForceCancelCloseRequestParameters = {},\n): UseForceCancelCloseRequestReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = forceCancelCloseRequestMutationOptions(config);\n\n return useMutation<ForceCancelCloseRequestResult, SymmioRequestError, ForceCancelCloseRequestParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({ ...variables, chainId: resolvedChainId });\n return resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: (_result, variables) => {\n // The force-cancel returns the position to OPENED — refetch the owning\n // partyA's open positions so the status updates.\n const partial = { partyA: variables.account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPartyAOpenPositionsQueryKey, partial) });\n },\n });\n}\n"],"mappings":";;;;;;;;;AA2CA,SAAgB,EACd,IAAmD,CAAC,GACd;CACtC,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAE7B,IAAO,EAAuC,CAAM;CAE1D,OAAO,EAAkG;EACvG,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,IAAM,IAAkB,EAAU,WAAW;IAE7C,OAAO,EAAmB,GAAQ,MADf,EAAK,WAAW;KAAE,GAAG;KAAW,SAAS;IAAgB,CAAC,GACrC;KACtC,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CAAC;GACH,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,YAAY,GAAS,MAAc;GAGjC,IAAM,IAAU,EAAE,QAAQ,EAAU,QAAQ;GAC5C,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAgC,CAAO,EAAE,CAAC;EAC3G;CACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-force-cancel-quote.d.ts","sourceRoot":"","sources":["../../src/quotes/use-force-cancel-quote.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,0BAA0B,EAChC,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,kDAAkD;AAClD,MAAM,MAAM,6BAA6B,GAAG,eAAe,CAAC;AAE5D,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,
|
|
1
|
+
{"version":3,"file":"use-force-cancel-quote.d.ts","sourceRoot":"","sources":["../../src/quotes/use-force-cancel-quote.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,0BAA0B,EAChC,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,kDAAkD;AAClD,MAAM,MAAM,6BAA6B,GAAG,eAAe,CAAC;AAE5D,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,CA4CjH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-force-cancel-quote.js","names":[],"sources":["../../src/quotes/use-force-cancel-quote.ts"],"sourcesContent":["\"use client\";\n\nimport {\n forceCancelQuoteMutationOptions,\n getPartyAOpenPositionsQueryKey,\n getPartyAPendingQuotesQueryKey,\n getPendingQuotesQueryKey,\n getQuoteQueryKey,\n type ForceCancelQuoteParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { invalidateAccountBalances, predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useForceCancelQuote}. */\nexport type UseForceCancelQuoteParameters = WriteParameters;\n\n/** Result returned by the {@link useForceCancelQuote} mutation. */\nexport type ForceCancelQuoteResult = WriteResult;\n\n/** Return type of {@link useForceCancelQuote}. */\nexport type UseForceCancelQuoteReturnType = UseMutationResult<\n ForceCancelQuoteResult,\n SymmioRequestError,\n ForceCancelQuoteParameters\n>;\n\n/**\n * Force-cancel a stalled quote (`forceCancelQuote`, routed through the\n * AccountLayer `_call` proxy). Only valid once the quote is `CANCEL_PENDING`\n * (partyA already called `requestToCancelQuote` on a `LOCKED` order) **and** the\n * force-cancel cooldown has elapsed — see {@link useCoolDownsOfMA} (index 1) plus\n * the quote's `statusModifyTimestamp`. On success (after the receipt) the\n * subaccount's pending-quotes reads are invalidated so the order drops out.\n *\n * @example\n * ```tsx\n * const { mutate } = useForceCancelQuote();\n * mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useForceCancelQuote(parameters: UseForceCancelQuoteParameters = {}): UseForceCancelQuoteReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = forceCancelQuoteMutationOptions(config);\n\n return useMutation<ForceCancelQuoteResult, SymmioRequestError, ForceCancelQuoteParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({
|
|
1
|
+
{"version":3,"file":"use-force-cancel-quote.js","names":[],"sources":["../../src/quotes/use-force-cancel-quote.ts"],"sourcesContent":["\"use client\";\n\nimport {\n forceCancelQuoteMutationOptions,\n getPartyAOpenPositionsQueryKey,\n getPartyAPendingQuotesQueryKey,\n getPendingQuotesQueryKey,\n getQuoteQueryKey,\n type ForceCancelQuoteParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { invalidateAccountBalances, predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useForceCancelQuote}. */\nexport type UseForceCancelQuoteParameters = WriteParameters;\n\n/** Result returned by the {@link useForceCancelQuote} mutation. */\nexport type ForceCancelQuoteResult = WriteResult;\n\n/** Return type of {@link useForceCancelQuote}. */\nexport type UseForceCancelQuoteReturnType = UseMutationResult<\n ForceCancelQuoteResult,\n SymmioRequestError,\n ForceCancelQuoteParameters\n>;\n\n/**\n * Force-cancel a stalled quote (`forceCancelQuote`, routed through the\n * AccountLayer `_call` proxy). Only valid once the quote is `CANCEL_PENDING`\n * (partyA already called `requestToCancelQuote` on a `LOCKED` order) **and** the\n * force-cancel cooldown has elapsed — see {@link useCoolDownsOfMA} (index 1) plus\n * the quote's `statusModifyTimestamp`. On success (after the receipt) the\n * subaccount's pending-quotes reads are invalidated so the order drops out.\n *\n * @example\n * ```tsx\n * const { mutate } = useForceCancelQuote();\n * mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useForceCancelQuote(parameters: UseForceCancelQuoteParameters = {}): UseForceCancelQuoteReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = forceCancelQuoteMutationOptions(config);\n\n return useMutation<ForceCancelQuoteResult, SymmioRequestError, ForceCancelQuoteParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({ ...variables, chainId: resolvedChainId });\n return resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: (_result, variables) => {\n // The force-cancelled quote leaves the pending set — refetch the pending\n // reads (full quotes + ids), the open positions for this partyA, and the\n // quote's own `getQuote` hydration (the read carrying `quoteStatus`) after the\n // receipt, so managed-quotes drops the now-terminal quote.\n const partial = { partyA: variables.account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPendingQuotesQueryKey, partial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPartyAPendingQuotesQueryKey, partial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPartyAOpenPositionsQueryKey, partial) });\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getQuoteQueryKey, { quoteId: variables.quoteId }),\n });\n /**\n * A force-cancel refunds the open trading fee and releases both parties'\n * pending locked balances in the same transaction, so every balance read is now\n * stale.\n */\n invalidateAccountBalances(queryClient, {\n configKey: config.getChainConfigKey(variables.chainId ?? chainId),\n });\n },\n });\n}\n"],"mappings":";;;;;;;;;;AA6CA,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;IAE7C,OAAO,EAAmB,GAAQ,MADf,EAAK,WAAW;KAAE,GAAG;KAAW,SAAS;IAAgB,CAAC,GACrC;KACtC,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CAAC;GACH,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,YAAY,GAAS,MAAc;GAKjC,IAAM,IAAU,EAAE,QAAQ,EAAU,QAAQ;GAY5C,AAXA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA0B,CAAO,EAAE,CAAC,GACnG,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAgC,CAAO,EAAE,CAAC,GACzG,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAgC,CAAO,EAAE,CAAC,GACzG,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAkB,EAAE,SAAS,EAAU,QAAQ,CAAC,EAC5E,CAAC,GAMD,EAA0B,GAAa,EACrC,WAAW,EAAO,kBAAkB,EAAU,WAAW,CAAO,EAClE,CAAC;EACH;CACF,CAAC;AACH"}
|
|
@@ -14,7 +14,8 @@ export type UseForceCloseReturnType = UseMutationResult<ForceCloseResult, Symmio
|
|
|
14
14
|
* eligibility, find a price window from reference candles, fetch the Muon
|
|
15
15
|
* `HighLowPriceSig`, preflight the gap, and send `forceClosePosition` through the
|
|
16
16
|
* AccountLayer `_call` proxy. On success (after the receipt) the subaccount's
|
|
17
|
-
* open-positions read is invalidated so the row updates
|
|
17
|
+
* open-positions read is invalidated so the row updates, and so are the chain's
|
|
18
|
+
* pending-funding reads, since the close settles the position's accrued funding.
|
|
18
19
|
*
|
|
19
20
|
* Throws (normalized) on ineligibility (`FORCE_CLOSE_NOT_ELIGIBLE`), the market
|
|
20
21
|
* not having hit the price (`FORCE_CLOSE_PRICE_NOT_REACHED`), or a contract
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-force-close.d.ts","sourceRoot":"","sources":["../../src/quotes/use-force-close.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-force-close.d.ts","sourceRoot":"","sources":["../../src/quotes/use-force-close.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,wBAAwB,EAC9B,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,4CAA4C;AAC5C,MAAM,MAAM,uBAAuB,GAAG,eAAe,CAAC;AAEtD,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAE3C,4CAA4C;AAC5C,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,wBAAwB,CAAC,CAAC;AAExH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,UAAU,GAAE,uBAA4B,GAAG,uBAAuB,CAoC/F"}
|
|
@@ -4,23 +4,23 @@ 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 { forceCloseAutoMutationOptions as a, getPartyAOpenPositionsQueryKey as o } from "@symmio/trading-core";
|
|
8
|
-
import { useMutation as
|
|
7
|
+
import { forceCloseAutoMutationOptions as a, getPartyAOpenPositionsQueryKey as o, getQuotePendingFundingQueryKey as s } from "@symmio/trading-core";
|
|
8
|
+
import { useMutation as c, useQueryClient as l } from "@tanstack/react-query";
|
|
9
9
|
//#region src/quotes/use-force-close.ts
|
|
10
|
-
function
|
|
11
|
-
let
|
|
12
|
-
return
|
|
13
|
-
mutationKey:
|
|
10
|
+
function u(u = {}) {
|
|
11
|
+
let d = t(u), f = e(), p = l(), m = a(d);
|
|
12
|
+
return c({
|
|
13
|
+
mutationKey: m.mutationKey,
|
|
14
14
|
mutationFn: async (e) => {
|
|
15
15
|
try {
|
|
16
|
-
let t = e.chainId ??
|
|
17
|
-
return r(
|
|
16
|
+
let t = e.chainId ?? f;
|
|
17
|
+
return r(d, await m.mutationFn({
|
|
18
18
|
...e,
|
|
19
19
|
chainId: t
|
|
20
20
|
}), {
|
|
21
21
|
chainId: t,
|
|
22
|
-
waitForReceipt:
|
|
23
|
-
confirmations:
|
|
22
|
+
waitForReceipt: u.waitForReceipt,
|
|
23
|
+
confirmations: u.confirmations
|
|
24
24
|
});
|
|
25
25
|
} catch (e) {
|
|
26
26
|
throw n(e);
|
|
@@ -28,11 +28,13 @@ function l(l = {}) {
|
|
|
28
28
|
},
|
|
29
29
|
onSuccess: (e, t) => {
|
|
30
30
|
let n = { partyA: t.account };
|
|
31
|
-
|
|
31
|
+
p.invalidateQueries({ predicate: i(o, n) });
|
|
32
|
+
let r = { configKey: d.getChainConfigKey(t.chainId ?? f) };
|
|
33
|
+
p.invalidateQueries({ predicate: i(s, r) });
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
//#endregion
|
|
36
|
-
export {
|
|
38
|
+
export { u as useForceClose };
|
|
37
39
|
|
|
38
40
|
//# sourceMappingURL=use-force-close.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-force-close.js","names":[],"sources":["../../src/quotes/use-force-close.ts"],"sourcesContent":["\"use client\";\n\nimport {\n forceCloseAutoMutationOptions,\n getPartyAOpenPositionsQueryKey,\n type ForceCloseAutoParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useForceClose}. */\nexport type UseForceCloseParameters = WriteParameters;\n\n/** Result returned by the {@link useForceClose} mutation. */\nexport type ForceCloseResult = WriteResult;\n\n/** Return type of {@link useForceClose}. */\nexport type UseForceCloseReturnType = UseMutationResult<ForceCloseResult, SymmioRequestError, ForceCloseAutoParameters>;\n\n/**\n * Force-close a stalled `CLOSE_PENDING` **limit** position end-to-end from just a\n * `quoteId` (`forceCloseAuto`): read the quote + force-close params, gate on\n * eligibility, find a price window from reference candles, fetch the Muon\n * `HighLowPriceSig`, preflight the gap, and send `forceClosePosition` through the\n * AccountLayer `_call` proxy. On success (after the receipt) the subaccount's\n * open-positions read is invalidated so the row updates.\n *\n * Throws (normalized) on ineligibility (`FORCE_CLOSE_NOT_ELIGIBLE`), the market\n * not having hit the price (`FORCE_CLOSE_PRICE_NOT_REACHED`), or a contract\n * revert. Gate the button first with {@link useForceCloseEligibility}.\n *\n * @example\n * ```tsx\n * const forceClose = useForceClose();\n * forceClose.mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useForceClose(parameters: UseForceCloseParameters = {}): UseForceCloseReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = forceCloseAutoMutationOptions(config);\n\n return useMutation<ForceCloseResult, SymmioRequestError, ForceCloseAutoParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({ ...variables, chainId: resolvedChainId });\n return resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: (_result, variables) => {\n // The force-close transitions the position — refetch the owning partyA's\n // open positions so the status updates.\n const partial = { partyA: variables.account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPartyAOpenPositionsQueryKey, partial) });\n },\n });\n}\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"use-force-close.js","names":[],"sources":["../../src/quotes/use-force-close.ts"],"sourcesContent":["\"use client\";\n\nimport {\n forceCloseAutoMutationOptions,\n getPartyAOpenPositionsQueryKey,\n getQuotePendingFundingQueryKey,\n type ForceCloseAutoParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useForceClose}. */\nexport type UseForceCloseParameters = WriteParameters;\n\n/** Result returned by the {@link useForceClose} mutation. */\nexport type ForceCloseResult = WriteResult;\n\n/** Return type of {@link useForceClose}. */\nexport type UseForceCloseReturnType = UseMutationResult<ForceCloseResult, SymmioRequestError, ForceCloseAutoParameters>;\n\n/**\n * Force-close a stalled `CLOSE_PENDING` **limit** position end-to-end from just a\n * `quoteId` (`forceCloseAuto`): read the quote + force-close params, gate on\n * eligibility, find a price window from reference candles, fetch the Muon\n * `HighLowPriceSig`, preflight the gap, and send `forceClosePosition` through the\n * AccountLayer `_call` proxy. On success (after the receipt) the subaccount's\n * open-positions read is invalidated so the row updates, and so are the chain's\n * pending-funding reads, since the close settles the position's accrued funding.\n *\n * Throws (normalized) on ineligibility (`FORCE_CLOSE_NOT_ELIGIBLE`), the market\n * not having hit the price (`FORCE_CLOSE_PRICE_NOT_REACHED`), or a contract\n * revert. Gate the button first with {@link useForceCloseEligibility}.\n *\n * @example\n * ```tsx\n * const forceClose = useForceClose();\n * forceClose.mutate({ account: \"0xsub…\", quoteId: 42n });\n * ```\n */\nexport function useForceClose(parameters: UseForceCloseParameters = {}): UseForceCloseReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n\n const base = forceCloseAutoMutationOptions(config);\n\n return useMutation<ForceCloseResult, SymmioRequestError, ForceCloseAutoParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const resolvedChainId = variables.chainId ?? chainId;\n const hash = await base.mutationFn({ ...variables, chainId: resolvedChainId });\n return resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: (_result, variables) => {\n // The force-close transitions the position — refetch the owning partyA's\n // open positions so the status updates.\n const partial = { partyA: variables.account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getPartyAOpenPositionsQueryKey, partial) });\n /**\n * The close settles the funding the position had accrued, so its pending-funding\n * read is stale. That key carries only the id set, not the partyA, so scope it\n * by the chain config instead.\n */\n const fundingScope = { configKey: config.getChainConfigKey(variables.chainId ?? chainId) };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getQuotePendingFundingQueryKey, fundingScope) });\n },\n });\n}\n"],"mappings":";;;;;;;;;AA4CA,SAAgB,EAAc,IAAsC,CAAC,GAA4B;CAC/F,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAE7B,IAAO,EAA8B,CAAM;CAEjD,OAAO,EAA4E;EACjF,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,IAAM,IAAkB,EAAU,WAAW;IAE7C,OAAO,EAAmB,GAAQ,MADf,EAAK,WAAW;KAAE,GAAG;KAAW,SAAS;IAAgB,CAAC,GACrC;KACtC,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CAAC;GACH,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,YAAY,GAAS,MAAc;GAGjC,IAAM,IAAU,EAAE,QAAQ,EAAU,QAAQ;GAC5C,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAgC,CAAO,EAAE,CAAC;GAMzG,IAAM,IAAe,EAAE,WAAW,EAAO,kBAAkB,EAAU,WAAW,CAAO,EAAE;GACzF,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAgC,CAAY,EAAE,CAAC;EAChH;CACF,CAAC;AACH"}
|
|
@@ -6,8 +6,8 @@ import { SETTLE_REFETCH_DELAYS_MS as r } from "../websocket/is-settle-notificati
|
|
|
6
6
|
import { useNotifications as i } from "../websocket/use-notifications.js";
|
|
7
7
|
import { useInstantOpens as a } from "../instant-layer/use-instant-opens.js";
|
|
8
8
|
import { NotificationType as o, OrderType as s, getPendingQuotesQueryOptions as c, isCancelAction as l, isOpenAnchorAction as u, reconcileQuotes as d } from "@symmio/trading-core";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { zeroAddress as f } from "viem";
|
|
10
|
+
import { useCallback as p, useEffect as m, useMemo as h, useRef as g, useState as _ } from "react";
|
|
11
11
|
import { useQuery as v } from "@tanstack/react-query";
|
|
12
12
|
//#region src/quotes/use-limit-orders.ts
|
|
13
13
|
var y = 200;
|
|
@@ -25,21 +25,21 @@ function b(b = {}) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}), j = a({
|
|
28
|
-
partyA: D ??
|
|
28
|
+
partyA: D ?? f,
|
|
29
29
|
chainId: E,
|
|
30
30
|
config: C.config,
|
|
31
31
|
query: { enabled: O }
|
|
32
|
-
}), [M, N] =
|
|
32
|
+
}), [M, N] = _([]), { refetch: P } = A, { status: F } = i({
|
|
33
33
|
account: D,
|
|
34
34
|
chainId: E,
|
|
35
35
|
config: C.config,
|
|
36
36
|
enabled: !!(x && D) && O,
|
|
37
|
-
onNotification:
|
|
37
|
+
onNotification: p((e) => {
|
|
38
38
|
N((t) => [...t, e].slice(-y));
|
|
39
39
|
let t = l(e.lastSeenAction), n = e.type === o.SUCCESS && u(e.lastSeenAction);
|
|
40
40
|
if (!(!t && !n)) for (let e of r) setTimeout(() => void P(), e);
|
|
41
41
|
}, [P])
|
|
42
|
-
}), I =
|
|
42
|
+
}), I = g([]), L = h(() => {
|
|
43
43
|
if (!D) return {
|
|
44
44
|
quotes: [],
|
|
45
45
|
pendingAnchors: []
|
|
@@ -61,16 +61,16 @@ function b(b = {}) {
|
|
|
61
61
|
M,
|
|
62
62
|
S
|
|
63
63
|
]);
|
|
64
|
-
|
|
64
|
+
m(() => {
|
|
65
65
|
I.current = L.pendingAnchors;
|
|
66
66
|
}, [L]);
|
|
67
|
-
let R =
|
|
67
|
+
let R = h(() => L.quotes.filter((e) => e.orderType === S), [L, S]), z = A.error ?? j.error ?? null;
|
|
68
68
|
return {
|
|
69
69
|
quotes: R,
|
|
70
70
|
isLoading: O && (A.isLoading || j.isLoading),
|
|
71
71
|
isError: A.isError || j.isError,
|
|
72
72
|
error: z,
|
|
73
|
-
refetch:
|
|
73
|
+
refetch: p(() => {
|
|
74
74
|
A.refetch(), j.refetch();
|
|
75
75
|
}, [A, j]),
|
|
76
76
|
socketStatus: F
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-managed-quotes.d.ts","sourceRoot":"","sources":["../../src/quotes/use-managed-quotes.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-managed-quotes.d.ts","sourceRoot":"","sources":["../../src/quotes/use-managed-quotes.ts"],"names":[],"mappings":"AAEA,OAAO,EAuBL,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAGhD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AA+GzE;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,iFAAiF;IACjF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sGAAsG;IACtG,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,wFAAwF;IACxF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0FAA0F;IAC1F,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,qFAAqF;IACrF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6FAA6F;IAC7F,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gGAAgG;IAChG,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,qFAAqF;IACrF,aAAa,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IACnC,qDAAqD;IACrD,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACpC,2GAA2G;IAC3G,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,yEAAyE;IACzE,SAAS,EAAE,OAAO,CAAC;IACnB,iFAAiF;IACjF,UAAU,EAAE,OAAO,CAAC;IACpB,0FAA0F;IAC1F,YAAY,EAAE,YAAY,CAAC;IAC3B,qEAAqE;IACrE,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACjC,yDAAyD;IACzD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,0BAA0B,GAAG,sBAAsB,CAwuB/F"}
|