@pear-protocol/symmio-client 0.3.17 → 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.
- package/dist/index.d.mts +479 -14
- package/dist/index.d.ts +479 -14
- package/dist/index.js +345 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +341 -37
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +146 -11
- package/dist/react/index.d.ts +146 -11
- package/dist/react/index.js +467 -36
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +465 -38
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -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() {
|
|
@@ -2662,24 +2662,288 @@ function useSymmDepositAndAllocateMutation(params = {}, options) {
|
|
|
2662
2662
|
}
|
|
2663
2663
|
});
|
|
2664
2664
|
}
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
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) {
|
|
2668
2844
|
const data = encodeFunctionData({
|
|
2669
|
-
abi:
|
|
2670
|
-
functionName: "
|
|
2671
|
-
args: [
|
|
2845
|
+
abi: accountDiamondAbi,
|
|
2846
|
+
functionName: "_call",
|
|
2847
|
+
args: [subAccount, callDatas]
|
|
2672
2848
|
});
|
|
2673
2849
|
return {
|
|
2674
|
-
functionName: "
|
|
2675
|
-
args: [
|
|
2676
|
-
|
|
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 }
|
|
2677
2919
|
};
|
|
2678
2920
|
}
|
|
2679
|
-
async function
|
|
2921
|
+
async function initiateWithdraw(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
2680
2922
|
const account = walletClient.account?.address;
|
|
2681
2923
|
if (!account) throw new Error("Wallet client has no account");
|
|
2682
|
-
const prepared =
|
|
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) {
|
|
2933
|
+
const account = walletClient.account?.address;
|
|
2934
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
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);
|
|
2683
2947
|
const gas = await publicClient.estimateGas(prepared.config);
|
|
2684
2948
|
return walletClient.sendTransaction({
|
|
2685
2949
|
...prepared.config,
|
|
@@ -2689,26 +2953,201 @@ async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
|
2689
2953
|
}
|
|
2690
2954
|
|
|
2691
2955
|
// src/react/hooks/use-symm-withdraw.ts
|
|
2692
|
-
function
|
|
2956
|
+
function useResolvedWithdrawConfig(params) {
|
|
2693
2957
|
const { chainId, symmioConfig } = useSymmContext();
|
|
2694
|
-
const { publicClient, walletClient } = params;
|
|
2695
|
-
const queryClient = useQueryClient();
|
|
2696
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);
|
|
2697
2969
|
return useMutation({
|
|
2698
2970
|
...withSymmMutationConfig(options?.mutation, {
|
|
2699
|
-
onSuccess: () =>
|
|
2700
|
-
invalidateBalances(queryClient);
|
|
2701
|
-
}
|
|
2971
|
+
onSuccess: () => invalidateBalances(queryClient)
|
|
2702
2972
|
}),
|
|
2703
|
-
mutationFn: async ({
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2973
|
+
mutationFn: async (vars) => {
|
|
2974
|
+
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
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
|
+
});
|
|
2982
|
+
}
|
|
2983
|
+
});
|
|
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) => {
|
|
2707
2993
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
2708
|
-
|
|
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
|
+
});
|
|
2709
3017
|
}
|
|
2710
3018
|
});
|
|
2711
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
|
+
}
|
|
2712
3151
|
|
|
2713
3152
|
// src/abis/SymmioDiamond.ts
|
|
2714
3153
|
var SymmioDiamondABI = [
|
|
@@ -25094,18 +25533,6 @@ var SymmioDiamondABI = [
|
|
|
25094
25533
|
type: "function"
|
|
25095
25534
|
}
|
|
25096
25535
|
];
|
|
25097
|
-
function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
|
|
25098
|
-
const data = 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
25536
|
|
|
25110
25537
|
// src/actions/allocate.ts
|
|
25111
25538
|
function prepareAllocate(multiAccount, account, subAccount, params) {
|
|
@@ -26100,8 +26527,8 @@ function computeSymmNetDeposited(totals, decimals = 6) {
|
|
|
26100
26527
|
return "0";
|
|
26101
26528
|
}
|
|
26102
26529
|
const deposit2 = parseRawCollateralUnits(totals.deposit);
|
|
26103
|
-
const
|
|
26104
|
-
const value = deposit2 -
|
|
26530
|
+
const withdraw = parseRawCollateralUnits(totals.withdraw);
|
|
26531
|
+
const value = deposit2 - withdraw;
|
|
26105
26532
|
const negative = value < 0n;
|
|
26106
26533
|
const absolute = negative ? -value : value;
|
|
26107
26534
|
const scale = 10n ** BigInt(decimals);
|
|
@@ -27910,6 +28337,6 @@ function getSymmErrorMessage(error) {
|
|
|
27910
28337
|
return "An unexpected error occurred.";
|
|
27911
28338
|
}
|
|
27912
28339
|
|
|
27913
|
-
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, useSymmMarketPositioning, 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 };
|
|
27914
28341
|
//# sourceMappingURL=index.mjs.map
|
|
27915
28342
|
//# sourceMappingURL=index.mjs.map
|