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