@pear-protocol/symmio-client 0.3.16 → 0.3.18

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.
@@ -5,7 +5,7 @@ import { create } from 'zustand';
5
5
  import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
6
6
  import { jsx } from 'react/jsx-runtime';
7
7
  import { SiweMessage } from 'siwe';
8
- import { isAddress, encodeFunctionData } from 'viem';
8
+ import { parseEventLogs, isAddress, encodeFunctionData } from 'viem';
9
9
 
10
10
  var SymmContext = createContext(null);
11
11
  function useSymmContext() {
@@ -631,6 +631,7 @@ var symmKeys = {
631
631
  triggerOrders: (params) => ["symm", "triggerOrders", params],
632
632
  triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
633
633
  markets: (chainId, search, pageSize) => ["symm", "markets", chainId, search, pageSize],
634
+ marketPositioning: (chainId, market) => ["symm", "marketPositioning", chainId, market],
634
635
  hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
635
636
  hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
636
637
  lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
@@ -1703,6 +1704,7 @@ var SymmioSDKError = class extends Error {
1703
1704
  this.code = code;
1704
1705
  this.name = "SymmioSDKError";
1705
1706
  }
1707
+ code;
1706
1708
  };
1707
1709
  function validateAddress(address, name) {
1708
1710
  if (!isAddress(address)) {
@@ -2660,24 +2662,288 @@ function useSymmDepositAndAllocateMutation(params = {}, options) {
2660
2662
  }
2661
2663
  });
2662
2664
  }
2663
- function prepareWithdraw(multiAccount, account, params) {
2664
- validateAmount(params.amount, "withdraw amount");
2665
- validateAddress(params.account, "account");
2665
+
2666
+ // src/abis/WithdrawFacet.ts
2667
+ var WithdrawFacetABI = [
2668
+ // ─── Mutations ──────────────────────────────────────────────────
2669
+ {
2670
+ type: "function",
2671
+ name: "initiateWithdraw",
2672
+ stateMutability: "nonpayable",
2673
+ inputs: [
2674
+ {
2675
+ name: "parts",
2676
+ type: "tuple[]",
2677
+ internalType: "struct WithdrawReceiverPart[]",
2678
+ components: [
2679
+ { name: "id", type: "uint256", internalType: "uint256" },
2680
+ { name: "amount", type: "uint256", internalType: "uint256" },
2681
+ { name: "chainId", type: "int256", internalType: "int256" },
2682
+ { name: "receiver", type: "bytes", internalType: "bytes" },
2683
+ { name: "virtualProvider", type: "address", internalType: "address" },
2684
+ { name: "expressProvider", type: "address", internalType: "address" }
2685
+ ]
2686
+ },
2687
+ { name: "speedUp", type: "bool", internalType: "bool" },
2688
+ { name: "data", type: "bytes", internalType: "bytes" }
2689
+ ],
2690
+ outputs: [
2691
+ { name: "requestId", type: "uint256", internalType: "uint256" },
2692
+ { name: "cooldownEndTime", type: "uint256", internalType: "uint256" }
2693
+ ]
2694
+ },
2695
+ {
2696
+ type: "function",
2697
+ name: "finalizeWithdrawRequest",
2698
+ stateMutability: "nonpayable",
2699
+ inputs: [
2700
+ { name: "user", type: "address", internalType: "address" },
2701
+ { name: "requestId", type: "uint256", internalType: "uint256" }
2702
+ ],
2703
+ outputs: []
2704
+ },
2705
+ {
2706
+ type: "function",
2707
+ name: "requestCancelWithdraw",
2708
+ stateMutability: "nonpayable",
2709
+ inputs: [{ name: "requestId", type: "uint256", internalType: "uint256" }],
2710
+ outputs: []
2711
+ },
2712
+ // ─── Views ──────────────────────────────────────────────────────
2713
+ {
2714
+ type: "function",
2715
+ name: "getWithdrawableTime",
2716
+ stateMutability: "view",
2717
+ inputs: [{ name: "user", type: "address", internalType: "address" }],
2718
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }]
2719
+ },
2720
+ {
2721
+ type: "function",
2722
+ name: "getLastWithdrawRequestId",
2723
+ stateMutability: "view",
2724
+ inputs: [{ name: "user", type: "address", internalType: "address" }],
2725
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }]
2726
+ },
2727
+ {
2728
+ type: "function",
2729
+ name: "isSpeedUpEligible",
2730
+ stateMutability: "view",
2731
+ inputs: [{ name: "user", type: "address", internalType: "address" }],
2732
+ outputs: [{ name: "", type: "bool", internalType: "bool" }]
2733
+ },
2734
+ {
2735
+ type: "function",
2736
+ name: "isExpressProviderRegistered",
2737
+ stateMutability: "view",
2738
+ inputs: [{ name: "provider", type: "address", internalType: "address" }],
2739
+ outputs: [{ name: "", type: "bool", internalType: "bool" }]
2740
+ },
2741
+ {
2742
+ type: "function",
2743
+ name: "isVirtualProviderRegistered",
2744
+ stateMutability: "view",
2745
+ inputs: [{ name: "provider", type: "address", internalType: "address" }],
2746
+ outputs: [{ name: "", type: "bool", internalType: "bool" }]
2747
+ },
2748
+ // ─── Events ─────────────────────────────────────────────────────
2749
+ {
2750
+ type: "event",
2751
+ name: "WithdrawInitiated",
2752
+ anonymous: false,
2753
+ inputs: [
2754
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
2755
+ { name: "user", type: "address", indexed: true, internalType: "address" },
2756
+ {
2757
+ name: "parts",
2758
+ type: "tuple[]",
2759
+ indexed: false,
2760
+ internalType: "struct WithdrawReceiverPart[]",
2761
+ components: [
2762
+ { name: "id", type: "uint256", internalType: "uint256" },
2763
+ { name: "amount", type: "uint256", internalType: "uint256" },
2764
+ { name: "chainId", type: "int256", internalType: "int256" },
2765
+ { name: "receiver", type: "bytes", internalType: "bytes" },
2766
+ { name: "virtualProvider", type: "address", internalType: "address" },
2767
+ { name: "expressProvider", type: "address", internalType: "address" }
2768
+ ]
2769
+ },
2770
+ { name: "speedUp", type: "bool", indexed: false, internalType: "bool" },
2771
+ { name: "providerData", type: "bytes", indexed: false, internalType: "bytes" },
2772
+ { name: "cooldownEndTime", type: "uint256", indexed: false, internalType: "uint256" }
2773
+ ]
2774
+ },
2775
+ {
2776
+ type: "event",
2777
+ name: "WithdrawAccepted",
2778
+ anonymous: false,
2779
+ inputs: [
2780
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
2781
+ { name: "user", type: "address", indexed: true, internalType: "address" }
2782
+ ]
2783
+ },
2784
+ {
2785
+ type: "event",
2786
+ name: "WithdrawFinalized",
2787
+ anonymous: false,
2788
+ inputs: [
2789
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
2790
+ { name: "user", type: "address", indexed: true, internalType: "address" }
2791
+ ]
2792
+ },
2793
+ {
2794
+ type: "event",
2795
+ name: "WithdrawCancelRequested",
2796
+ anonymous: false,
2797
+ inputs: [
2798
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
2799
+ { name: "user", type: "address", indexed: true, internalType: "address" }
2800
+ ]
2801
+ },
2802
+ {
2803
+ type: "event",
2804
+ name: "WithdrawCancelled",
2805
+ anonymous: false,
2806
+ inputs: [
2807
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
2808
+ { name: "user", type: "address", indexed: true, internalType: "address" }
2809
+ ]
2810
+ },
2811
+ {
2812
+ type: "event",
2813
+ name: "WithdrawRejected",
2814
+ anonymous: false,
2815
+ inputs: [
2816
+ { name: "requestId", type: "uint256", indexed: false, internalType: "uint256" },
2817
+ { name: "user", type: "address", indexed: false, internalType: "address" }
2818
+ ]
2819
+ },
2820
+ {
2821
+ type: "event",
2822
+ name: "WithdrawSuspended",
2823
+ anonymous: false,
2824
+ inputs: [
2825
+ { name: "requestId", type: "uint256", indexed: false, internalType: "uint256" },
2826
+ { name: "user", type: "address", indexed: false, internalType: "address" }
2827
+ ]
2828
+ },
2829
+ {
2830
+ type: "event",
2831
+ name: "WithdrawSpeedUpAccepted",
2832
+ anonymous: false,
2833
+ inputs: [
2834
+ { name: "requestId", type: "uint256", indexed: false, internalType: "uint256" },
2835
+ { name: "user", type: "address", indexed: false, internalType: "address" },
2836
+ { name: "newCooldown", type: "uint256", indexed: false, internalType: "uint256" }
2837
+ ]
2838
+ }
2839
+ ];
2840
+
2841
+ // src/types/withdraw.ts
2842
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
2843
+ function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
2666
2844
  const data = encodeFunctionData({
2667
- abi: MultiAccountABI,
2668
- functionName: "withdrawFromAccount",
2669
- args: [params.account, params.amount]
2845
+ abi: accountDiamondAbi,
2846
+ functionName: "_call",
2847
+ args: [subAccount, callDatas]
2670
2848
  });
2671
2849
  return {
2672
- functionName: "withdrawFromAccount",
2673
- args: [params.account, params.amount],
2674
- config: { account, to: multiAccount, data, value: 0n }
2850
+ functionName: "_call",
2851
+ args: [subAccount, callDatas],
2852
+ data
2853
+ };
2854
+ }
2855
+
2856
+ // src/actions/withdraw.ts
2857
+ function buildExpressWithdrawPart(amount, chainId, receiver, expressProvider, partId = 0n) {
2858
+ return {
2859
+ id: partId,
2860
+ amount,
2861
+ chainId,
2862
+ receiver,
2863
+ virtualProvider: ZERO_ADDRESS,
2864
+ expressProvider
2865
+ };
2866
+ }
2867
+ function validateParts(parts) {
2868
+ if (parts.length === 0) {
2869
+ throw new Error("initiateWithdraw: at least one withdraw part is required");
2870
+ }
2871
+ for (const part of parts) {
2872
+ validateAmount(part.amount, "withdraw part amount");
2873
+ if (part.expressProvider !== ZERO_ADDRESS && part.expressProvider === part.virtualProvider) {
2874
+ throw new Error(
2875
+ "initiateWithdraw: a single provider cannot be set as both express and virtual"
2876
+ );
2877
+ }
2878
+ }
2879
+ }
2880
+ function prepareInitiateWithdraw(multiAccount, account, subAccount, params) {
2881
+ validateParts(params.parts);
2882
+ const innerData = encodeFunctionData({
2883
+ abi: WithdrawFacetABI,
2884
+ functionName: "initiateWithdraw",
2885
+ args: [params.parts, params.speedUp, params.providerData]
2886
+ });
2887
+ const proxy = wrapInProxyCall(MultiAccountABI, subAccount, [innerData]);
2888
+ return {
2889
+ functionName: "_call",
2890
+ args: proxy.args,
2891
+ config: { account, to: multiAccount, data: proxy.data, value: 0n }
2892
+ };
2893
+ }
2894
+ function prepareFinalizeWithdraw(multiAccount, account, subAccount, params) {
2895
+ validateAddress(params.user, "user");
2896
+ const innerData = encodeFunctionData({
2897
+ abi: WithdrawFacetABI,
2898
+ functionName: "finalizeWithdrawRequest",
2899
+ args: [params.user, params.requestId]
2900
+ });
2901
+ const proxy = wrapInProxyCall(MultiAccountABI, subAccount, [innerData]);
2902
+ return {
2903
+ functionName: "_call",
2904
+ args: proxy.args,
2905
+ config: { account, to: multiAccount, data: proxy.data, value: 0n }
2906
+ };
2907
+ }
2908
+ function prepareRequestCancelWithdraw(multiAccount, account, subAccount, params) {
2909
+ const innerData = encodeFunctionData({
2910
+ abi: WithdrawFacetABI,
2911
+ functionName: "requestCancelWithdraw",
2912
+ args: [params.requestId]
2913
+ });
2914
+ const proxy = wrapInProxyCall(MultiAccountABI, subAccount, [innerData]);
2915
+ return {
2916
+ functionName: "_call",
2917
+ args: proxy.args,
2918
+ config: { account, to: multiAccount, data: proxy.data, value: 0n }
2675
2919
  };
2676
2920
  }
2677
- async function withdraw(walletClient, publicClient, multiAccount, params) {
2921
+ async function initiateWithdraw(walletClient, publicClient, multiAccount, subAccount, params) {
2922
+ const account = walletClient.account?.address;
2923
+ if (!account) throw new Error("Wallet client has no account");
2924
+ const prepared = prepareInitiateWithdraw(multiAccount, account, subAccount, params);
2925
+ const gas = await publicClient.estimateGas(prepared.config);
2926
+ return walletClient.sendTransaction({
2927
+ ...prepared.config,
2928
+ gas: calculateGasMargin(gas),
2929
+ chain: walletClient.chain
2930
+ });
2931
+ }
2932
+ async function finalizeWithdraw(walletClient, publicClient, multiAccount, subAccount, params) {
2678
2933
  const account = walletClient.account?.address;
2679
2934
  if (!account) throw new Error("Wallet client has no account");
2680
- const prepared = prepareWithdraw(multiAccount, account, params);
2935
+ const prepared = prepareFinalizeWithdraw(multiAccount, account, subAccount, params);
2936
+ const gas = await publicClient.estimateGas(prepared.config);
2937
+ return walletClient.sendTransaction({
2938
+ ...prepared.config,
2939
+ gas: calculateGasMargin(gas),
2940
+ chain: walletClient.chain
2941
+ });
2942
+ }
2943
+ async function requestCancelWithdraw(walletClient, publicClient, multiAccount, subAccount, params) {
2944
+ const account = walletClient.account?.address;
2945
+ if (!account) throw new Error("Wallet client has no account");
2946
+ const prepared = prepareRequestCancelWithdraw(multiAccount, account, subAccount, params);
2681
2947
  const gas = await publicClient.estimateGas(prepared.config);
2682
2948
  return walletClient.sendTransaction({
2683
2949
  ...prepared.config,
@@ -2687,26 +2953,201 @@ async function withdraw(walletClient, publicClient, multiAccount, params) {
2687
2953
  }
2688
2954
 
2689
2955
  // src/react/hooks/use-symm-withdraw.ts
2690
- function useSymmWithdraw(params = {}, options) {
2956
+ function useResolvedWithdrawConfig(params) {
2691
2957
  const { chainId, symmioConfig } = useSymmContext();
2692
- const { publicClient, walletClient } = params;
2693
- const queryClient = useQueryClient();
2694
2958
  const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
2959
+ return {
2960
+ multiAccount,
2961
+ publicClient: params.publicClient,
2962
+ walletClient: params.walletClient,
2963
+ contextSubAccount: params.subAccount
2964
+ };
2965
+ }
2966
+ function useSymmInitiateWithdraw(params = {}, options) {
2967
+ const queryClient = useQueryClient();
2968
+ const { multiAccount, publicClient, walletClient, contextSubAccount } = useResolvedWithdrawConfig(params);
2695
2969
  return useMutation({
2696
2970
  ...withSymmMutationConfig(options?.mutation, {
2697
- onSuccess: () => {
2698
- invalidateBalances(queryClient);
2699
- }
2971
+ onSuccess: () => invalidateBalances(queryClient)
2700
2972
  }),
2701
- mutationFn: async ({
2702
- account,
2703
- amount
2704
- }) => {
2973
+ mutationFn: async (vars) => {
2705
2974
  if (!walletClient || !publicClient) throw new Error("Clients not available");
2706
- return withdraw(walletClient, publicClient, multiAccount, { account, amount });
2975
+ const subAccount = vars.subAccount ?? contextSubAccount;
2976
+ if (!subAccount) throw new Error("subAccount required");
2977
+ return initiateWithdraw(walletClient, publicClient, multiAccount, subAccount, {
2978
+ parts: vars.parts,
2979
+ speedUp: vars.speedUp,
2980
+ providerData: vars.providerData
2981
+ });
2707
2982
  }
2708
2983
  });
2709
2984
  }
2985
+ function useSymmFinalizeWithdraw(params = {}, options) {
2986
+ const queryClient = useQueryClient();
2987
+ const { multiAccount, publicClient, walletClient, contextSubAccount } = useResolvedWithdrawConfig(params);
2988
+ return useMutation({
2989
+ ...withSymmMutationConfig(options?.mutation, {
2990
+ onSuccess: () => invalidateBalances(queryClient)
2991
+ }),
2992
+ mutationFn: async (vars) => {
2993
+ if (!walletClient || !publicClient) throw new Error("Clients not available");
2994
+ const subAccount = vars.subAccount ?? contextSubAccount;
2995
+ if (!subAccount) throw new Error("subAccount required");
2996
+ return finalizeWithdraw(walletClient, publicClient, multiAccount, subAccount, {
2997
+ user: vars.user,
2998
+ requestId: vars.requestId
2999
+ });
3000
+ }
3001
+ });
3002
+ }
3003
+ function useSymmRequestCancelWithdraw(params = {}, options) {
3004
+ const queryClient = useQueryClient();
3005
+ const { multiAccount, publicClient, walletClient, contextSubAccount } = useResolvedWithdrawConfig(params);
3006
+ return useMutation({
3007
+ ...withSymmMutationConfig(options?.mutation, {
3008
+ onSuccess: () => invalidateBalances(queryClient)
3009
+ }),
3010
+ mutationFn: async (vars) => {
3011
+ if (!walletClient || !publicClient) throw new Error("Clients not available");
3012
+ const subAccount = vars.subAccount ?? contextSubAccount;
3013
+ if (!subAccount) throw new Error("subAccount required");
3014
+ return requestCancelWithdraw(walletClient, publicClient, multiAccount, subAccount, {
3015
+ requestId: vars.requestId
3016
+ });
3017
+ }
3018
+ });
3019
+ }
3020
+ function useSymmWithdraw(params = {}) {
3021
+ return {
3022
+ initiate: useSymmInitiateWithdraw(params),
3023
+ finalize: useSymmFinalizeWithdraw(params),
3024
+ requestCancel: useSymmRequestCancelWithdraw(params)
3025
+ };
3026
+ }
3027
+ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
3028
+ function useSymmInstantWithdraw(params = {}) {
3029
+ const queryClient = useQueryClient();
3030
+ const { chainId, symmioConfig } = useSymmContext();
3031
+ const { multiAccount, publicClient, walletClient, contextSubAccount } = useResolvedWithdrawConfig(params);
3032
+ const diamond = params.diamond ?? symmioConfig?.symmioDiamondAddress ?? getAddress(SYMMIO_DIAMOND_ADDRESS, chainId, "SymmioDiamond");
3033
+ const providerTimeoutMs = params.providerAcceptanceTimeoutMs ?? 6e4;
3034
+ const pollIntervalMs = params.pollIntervalMs ?? 3e3;
3035
+ const [status, setStatus] = useState("idle" /* IDLE */);
3036
+ const [requestId, setRequestId] = useState();
3037
+ const [txHashes, setTxHashes] = useState({});
3038
+ const [error, setError] = useState();
3039
+ const reset = useCallback(() => {
3040
+ setStatus("idle" /* IDLE */);
3041
+ setRequestId(void 0);
3042
+ setTxHashes({});
3043
+ setError(void 0);
3044
+ }, []);
3045
+ const withdraw = useCallback(
3046
+ async (vars) => {
3047
+ setError(void 0);
3048
+ setRequestId(void 0);
3049
+ setTxHashes({});
3050
+ try {
3051
+ if (!walletClient || !publicClient) throw new Error("Clients not available");
3052
+ const subAccount = vars.subAccount ?? contextSubAccount;
3053
+ if (!subAccount) throw new Error("subAccount required");
3054
+ setStatus("initiating" /* INITIATING */);
3055
+ const part = buildExpressWithdrawPart(
3056
+ vars.amount,
3057
+ vars.chainId,
3058
+ vars.receiver,
3059
+ vars.expressProvider,
3060
+ vars.partId ?? 0n
3061
+ );
3062
+ const initiateHash = await initiateWithdraw(
3063
+ walletClient,
3064
+ publicClient,
3065
+ multiAccount,
3066
+ subAccount,
3067
+ {
3068
+ parts: [part],
3069
+ speedUp: vars.speedUp ?? false,
3070
+ providerData: vars.providerData ?? "0x"
3071
+ }
3072
+ );
3073
+ setTxHashes({ initiate: initiateHash });
3074
+ const initiateReceipt = await publicClient.waitForTransactionReceipt({
3075
+ hash: initiateHash
3076
+ });
3077
+ const [initiated] = parseEventLogs({
3078
+ abi: WithdrawFacetABI,
3079
+ eventName: "WithdrawInitiated",
3080
+ logs: initiateReceipt.logs
3081
+ });
3082
+ if (!initiated) {
3083
+ throw new Error("WithdrawInitiated event not found in initiate receipt");
3084
+ }
3085
+ const reqId = initiated.args.requestId;
3086
+ const cooldownEndTime = initiated.args.cooldownEndTime;
3087
+ setRequestId(reqId);
3088
+ setStatus("awaitingProvider" /* AWAITING_PROVIDER */);
3089
+ const acceptanceDeadline = Date.now() + providerTimeoutMs;
3090
+ let fromBlock = initiateReceipt.blockNumber;
3091
+ let accepted = false;
3092
+ while (Date.now() < acceptanceDeadline) {
3093
+ const events = await publicClient.getContractEvents({
3094
+ address: diamond,
3095
+ abi: WithdrawFacetABI,
3096
+ eventName: "WithdrawAccepted",
3097
+ args: { requestId: reqId, user: subAccount },
3098
+ fromBlock,
3099
+ toBlock: "latest"
3100
+ });
3101
+ if (events.length > 0) {
3102
+ accepted = true;
3103
+ break;
3104
+ }
3105
+ await sleep(pollIntervalMs);
3106
+ }
3107
+ if (!accepted) {
3108
+ throw new Error(
3109
+ `Express provider did not accept within ${providerTimeoutMs}ms (requestId=${reqId})`
3110
+ );
3111
+ }
3112
+ setStatus("awaitingCooldown" /* AWAITING_COOLDOWN */);
3113
+ const nowSec = Math.floor(Date.now() / 1e3);
3114
+ const remainingSec = Number(cooldownEndTime) - nowSec;
3115
+ if (remainingSec > 0) {
3116
+ await sleep((remainingSec + 1) * 1e3);
3117
+ }
3118
+ setStatus("finalizing" /* FINALIZING */);
3119
+ const finalizeHash = await finalizeWithdraw(
3120
+ walletClient,
3121
+ publicClient,
3122
+ multiAccount,
3123
+ subAccount,
3124
+ { user: subAccount, requestId: reqId }
3125
+ );
3126
+ setTxHashes((t) => ({ ...t, finalize: finalizeHash }));
3127
+ await publicClient.waitForTransactionReceipt({ hash: finalizeHash });
3128
+ setStatus("completed" /* COMPLETED */);
3129
+ invalidateBalances(queryClient);
3130
+ return { requestId: reqId, initiateHash, finalizeHash };
3131
+ } catch (e) {
3132
+ const err = e instanceof Error ? e : new Error(String(e));
3133
+ setError(err);
3134
+ setStatus("failed" /* FAILED */);
3135
+ throw err;
3136
+ }
3137
+ },
3138
+ [
3139
+ walletClient,
3140
+ publicClient,
3141
+ multiAccount,
3142
+ diamond,
3143
+ contextSubAccount,
3144
+ providerTimeoutMs,
3145
+ pollIntervalMs,
3146
+ queryClient
3147
+ ]
3148
+ );
3149
+ return { withdraw, status, requestId, txHashes, error, reset };
3150
+ }
2710
3151
 
2711
3152
  // src/abis/SymmioDiamond.ts
2712
3153
  var SymmioDiamondABI = [
@@ -25092,18 +25533,6 @@ var SymmioDiamondABI = [
25092
25533
  type: "function"
25093
25534
  }
25094
25535
  ];
25095
- function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
25096
- const data = encodeFunctionData({
25097
- abi: accountDiamondAbi,
25098
- functionName: "_call",
25099
- args: [subAccount, callDatas]
25100
- });
25101
- return {
25102
- functionName: "_call",
25103
- args: [subAccount, callDatas],
25104
- data
25105
- };
25106
- }
25107
25536
 
25108
25537
  // src/actions/allocate.ts
25109
25538
  function prepareAllocate(multiAccount, account, subAccount, params) {
@@ -26098,8 +26527,8 @@ function computeSymmNetDeposited(totals, decimals = 6) {
26098
26527
  return "0";
26099
26528
  }
26100
26529
  const deposit2 = parseRawCollateralUnits(totals.deposit);
26101
- const withdraw2 = parseRawCollateralUnits(totals.withdraw);
26102
- const value = deposit2 - withdraw2;
26530
+ const withdraw = parseRawCollateralUnits(totals.withdraw);
26531
+ const value = deposit2 - withdraw;
26103
26532
  const negative = value < 0n;
26104
26533
  const absolute = negative ? -value : value;
26105
26534
  const scale = 10n ** BigInt(decimals);
@@ -26157,7 +26586,7 @@ function useSymmAccountOverview(params) {
26157
26586
  chainId: params.chainId,
26158
26587
  query: {
26159
26588
  ...params.query,
26160
- enabled: upnlReady && (params.query?.enabled ?? true)
26589
+ enabled: params.query?.enabled ?? true
26161
26590
  }
26162
26591
  });
26163
26592
  const data = useMemo(() => {
@@ -26679,6 +27108,34 @@ function useSymmMarkets(params) {
26679
27108
  enabled: internalEnabled && (params?.query?.enabled ?? true)
26680
27109
  });
26681
27110
  }
27111
+ function normalizeMarket(market) {
27112
+ if (Array.isArray(market)) {
27113
+ const markets = market.map((marketName2) => marketName2.trim()).filter((marketName2) => marketName2.length > 0);
27114
+ return markets.length > 0 ? markets : void 0;
27115
+ }
27116
+ const marketName = market?.trim();
27117
+ return marketName ? marketName : void 0;
27118
+ }
27119
+ function hasMarket(market) {
27120
+ return Array.isArray(market) ? market.length > 0 : market !== void 0;
27121
+ }
27122
+ function useSymmMarketPositioning(params) {
27123
+ const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
27124
+ const chainId = params?.chainId ?? ctxChainId;
27125
+ const market = normalizeMarket(params?.market);
27126
+ const internalEnabled = !!symmCoreClient && hasMarket(market);
27127
+ return useQuery({
27128
+ ...params?.query,
27129
+ queryKey: symmKeys.marketPositioning(chainId, market),
27130
+ queryFn: () => {
27131
+ if (!hasMarket(market)) {
27132
+ throw new Error("Market is required to fetch positioning");
27133
+ }
27134
+ return symmCoreClient.markets.getPositioning({ chainId, market });
27135
+ },
27136
+ enabled: internalEnabled && (params?.query?.enabled ?? true)
27137
+ });
27138
+ }
26682
27139
  function useSymmHedgerMarketById(params) {
26683
27140
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
26684
27141
  const { id } = params;
@@ -26784,7 +27241,9 @@ async function fetch24hrTicker(symbol) {
26784
27241
  return {
26785
27242
  lastPrice: parseFloat(data.lastPrice),
26786
27243
  openPrice: parseFloat(data.openPrice),
26787
- priceChangePercent: parseFloat(data.priceChangePercent)
27244
+ priceChangePercent: parseFloat(data.priceChangePercent),
27245
+ volume: parseFloat(data.volume),
27246
+ quoteVolume: parseFloat(data.quoteVolume)
26788
27247
  };
26789
27248
  }
26790
27249
  async function fetch24hrTickers() {
@@ -26798,7 +27257,9 @@ async function fetch24hrTickers() {
26798
27257
  result[item.symbol] = {
26799
27258
  lastPrice: parseFloat(item.lastPrice),
26800
27259
  openPrice: parseFloat(item.openPrice),
26801
- priceChangePercent: parseFloat(item.priceChangePercent)
27260
+ priceChangePercent: parseFloat(item.priceChangePercent),
27261
+ volume: parseFloat(item.volume),
27262
+ quoteVolume: parseFloat(item.quoteVolume)
26802
27263
  };
26803
27264
  }
26804
27265
  return result;
@@ -26834,7 +27295,11 @@ function useSymmTokenSelectionMarkets(params) {
26834
27295
  return;
26835
27296
  }
26836
27297
  const ticker = allTickers[binanceSymbol];
26837
- tickerSnapshots[symbol] = ticker ? { openPrice: ticker.openPrice } : null;
27298
+ tickerSnapshots[symbol] = ticker ? {
27299
+ openPrice: ticker.openPrice,
27300
+ volume: ticker.volume,
27301
+ quoteVolume: ticker.quoteVolume
27302
+ } : null;
26838
27303
  });
26839
27304
  return { tickerSnapshots };
26840
27305
  },
@@ -26844,21 +27309,30 @@ function useSymmTokenSelectionMarkets(params) {
26844
27309
  });
26845
27310
  const markets = useMemo(() => {
26846
27311
  const snapshots = priceQuery.data?.tickerSnapshots ?? {};
26847
- return baseMarkets.map((market) => {
27312
+ return baseMarkets.map((market, index) => {
26848
27313
  const symbol = market.symbol ?? "";
26849
27314
  const markPrice = symbol ? liveMarkPrices[symbol] ?? null : null;
26850
- const prevDayPrice = symbol ? snapshots[symbol]?.openPrice ?? null : null;
27315
+ const ticker = symbol ? snapshots[symbol] ?? null : null;
27316
+ const prevDayPrice = ticker?.openPrice ?? null;
26851
27317
  const priceChange24h = markPrice != null && prevDayPrice != null ? markPrice - prevDayPrice : null;
26852
27318
  const priceChange24hPercent = markPrice != null && prevDayPrice != null && prevDayPrice !== 0 ? (markPrice - prevDayPrice) / prevDayPrice * 100 : null;
26853
27319
  return {
26854
- ...market,
26855
- collateralToken: "USDC",
26856
- markPrice,
26857
- prevDayPrice,
26858
- priceChange24h,
26859
- priceChange24hPercent
27320
+ market: {
27321
+ ...market,
27322
+ collateralToken: "USDC",
27323
+ markPrice,
27324
+ prevDayPrice,
27325
+ priceChange24h,
27326
+ priceChange24hPercent,
27327
+ volume24h: ticker?.volume ?? null,
27328
+ quoteVolume24h: ticker?.quoteVolume ?? null
27329
+ },
27330
+ index
26860
27331
  };
26861
- });
27332
+ }).sort((a, b) => {
27333
+ const volumeDelta = (b.market.quoteVolume24h ?? 0) - (a.market.quoteVolume24h ?? 0);
27334
+ return volumeDelta === 0 ? a.index - b.index : volumeDelta;
27335
+ }).map(({ market }) => market);
26862
27336
  }, [baseMarkets, liveMarkPrices, priceQuery.data]);
26863
27337
  const marketsBySymbol = useMemo(
26864
27338
  () => new Map(
@@ -27863,6 +28337,6 @@ function getSymmErrorMessage(error) {
27863
28337
  return "An unexpected error occurred.";
27864
28338
  }
27865
28339
 
27866
- export { SymmProvider, computeSymmAccountOverview, computeSymmAccountOverviewFromData, computeSymmNetDeposited, computeSymmPositionUpnl, computeSymmPositionsUpnl, getSymmAccountBalanceInfo, getSymmAccountData, getSymmErrorMessage, normalizeSymmUpnlWebSocketMessage, symmKeys, useBinanceMarkPriceStore, useSymmAccountCurrentPnl, useSymmAccountData, useSymmAccountOverview, useSymmAccountSummary, useSymmAccountsApi, useSymmAccountsLength, useSymmAccountsQuery, useSymmAccountsWithPositions, useSymmAllocateCollateralMutation, useSymmApprovalQuery, useSymmApproveMutation, useSymmAuth, useSymmAvailableMargin, useSymmBalances, useSymmCancelClose, useSymmCancelOpenMutation, useSymmCancelTpslMutation, useSymmCancelTwapOrderMutation, useSymmChartCandles, useSymmChartSelection, useSymmClearTriggerConfigMutation, useSymmCloseAllPositionsMutation, useSymmCloseOrder, useSymmClosePositionMutation, useSymmContext, useSymmCoreClient, useSymmCreateAccountMutation, useSymmDeallocateCollateralMutation, useSymmDelegateAccessMutation, useSymmDelegation, useSymmDepositAndAllocateMutation, useSymmDepositMutation, useSymmEditAccountNameMutation, useSymmFunding, useSymmFundingHistory, useSymmFundingPayments, useSymmHedgerMarketById, useSymmHedgerMarketBySymbol, useSymmHedgerMarkets, useSymmInstantTradeEnsureReadyMutation, useSymmInstantTradeExecuteMutation, useSymmInternalTransferCollateralMutation, useSymmLockedParams, useSymmMarkReadNotificationMutation, useSymmMarkets, useSymmNotificationsQuery, useSymmOpenBasketMutation, useSymmOpenOrders, useSymmPendingIds, useSymmPendingInstantOpens, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmProposeRevokeDelegationMutation, useSymmRevokeDelegationMutation, useSymmSetTpslMutation, useSymmSetTriggerConfigMutation, useSymmSignTermsMutation, useSymmSignatureQuery, useSymmTokenMarkPrice, useSymmTokenSelectionMarkets, useSymmTokenSelectionMetadata, useSymmTpslOrders, useSymmTradeHistory, useSymmTriggerConfigQuery, useSymmTriggerOrders, useSymmTwapOrder, useSymmTwapOrdersQuery, useSymmUnreadCountQuery, useSymmUpdatePositionMutation, useSymmUpnlWebSocket, useSymmWithdraw, useSymmWsStore };
28340
+ export { SymmProvider, computeSymmAccountOverview, computeSymmAccountOverviewFromData, computeSymmNetDeposited, computeSymmPositionUpnl, computeSymmPositionsUpnl, getSymmAccountBalanceInfo, getSymmAccountData, getSymmErrorMessage, normalizeSymmUpnlWebSocketMessage, symmKeys, useBinanceMarkPriceStore, useSymmAccountCurrentPnl, useSymmAccountData, useSymmAccountOverview, useSymmAccountSummary, useSymmAccountsApi, useSymmAccountsLength, useSymmAccountsQuery, useSymmAccountsWithPositions, useSymmAllocateCollateralMutation, useSymmApprovalQuery, useSymmApproveMutation, useSymmAuth, useSymmAvailableMargin, useSymmBalances, useSymmCancelClose, useSymmCancelOpenMutation, useSymmCancelTpslMutation, useSymmCancelTwapOrderMutation, useSymmChartCandles, useSymmChartSelection, useSymmClearTriggerConfigMutation, useSymmCloseAllPositionsMutation, useSymmCloseOrder, useSymmClosePositionMutation, useSymmContext, useSymmCoreClient, useSymmCreateAccountMutation, useSymmDeallocateCollateralMutation, useSymmDelegateAccessMutation, useSymmDelegation, useSymmDepositAndAllocateMutation, useSymmDepositMutation, useSymmEditAccountNameMutation, useSymmFinalizeWithdraw, useSymmFunding, useSymmFundingHistory, useSymmFundingPayments, useSymmHedgerMarketById, useSymmHedgerMarketBySymbol, useSymmHedgerMarkets, useSymmInitiateWithdraw, useSymmInstantTradeEnsureReadyMutation, useSymmInstantTradeExecuteMutation, useSymmInstantWithdraw, useSymmInternalTransferCollateralMutation, useSymmLockedParams, useSymmMarkReadNotificationMutation, useSymmMarketPositioning, useSymmMarkets, useSymmNotificationsQuery, useSymmOpenBasketMutation, useSymmOpenOrders, useSymmPendingIds, useSymmPendingInstantOpens, useSymmPerformanceOverlays, useSymmPortfolio, useSymmPositions, useSymmProposeRevokeDelegationMutation, useSymmRequestCancelWithdraw, useSymmRevokeDelegationMutation, useSymmSetTpslMutation, useSymmSetTriggerConfigMutation, useSymmSignTermsMutation, useSymmSignatureQuery, useSymmTokenMarkPrice, useSymmTokenSelectionMarkets, useSymmTokenSelectionMetadata, useSymmTpslOrders, useSymmTradeHistory, useSymmTriggerConfigQuery, useSymmTriggerOrders, useSymmTwapOrder, useSymmTwapOrdersQuery, useSymmUnreadCountQuery, useSymmUpdatePositionMutation, useSymmUpnlWebSocket, useSymmWithdraw, useSymmWsStore };
27867
28341
  //# sourceMappingURL=index.mjs.map
27868
28342
  //# sourceMappingURL=index.mjs.map