@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.js
CHANGED
|
@@ -2664,24 +2664,288 @@ function useSymmDepositAndAllocateMutation(params = {}, options) {
|
|
|
2664
2664
|
}
|
|
2665
2665
|
});
|
|
2666
2666
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
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) {
|
|
2670
2846
|
const data = viem.encodeFunctionData({
|
|
2671
|
-
abi:
|
|
2672
|
-
functionName: "
|
|
2673
|
-
args: [
|
|
2847
|
+
abi: accountDiamondAbi,
|
|
2848
|
+
functionName: "_call",
|
|
2849
|
+
args: [subAccount, callDatas]
|
|
2674
2850
|
});
|
|
2675
2851
|
return {
|
|
2676
|
-
functionName: "
|
|
2677
|
-
args: [
|
|
2678
|
-
|
|
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 }
|
|
2679
2921
|
};
|
|
2680
2922
|
}
|
|
2681
|
-
async function
|
|
2923
|
+
async function initiateWithdraw(walletClient, publicClient, multiAccount, subAccount, params) {
|
|
2682
2924
|
const account = walletClient.account?.address;
|
|
2683
2925
|
if (!account) throw new Error("Wallet client has no account");
|
|
2684
|
-
const prepared =
|
|
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) {
|
|
2935
|
+
const account = walletClient.account?.address;
|
|
2936
|
+
if (!account) throw new Error("Wallet client has no account");
|
|
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);
|
|
2685
2949
|
const gas = await publicClient.estimateGas(prepared.config);
|
|
2686
2950
|
return walletClient.sendTransaction({
|
|
2687
2951
|
...prepared.config,
|
|
@@ -2691,26 +2955,201 @@ async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
|
2691
2955
|
}
|
|
2692
2956
|
|
|
2693
2957
|
// src/react/hooks/use-symm-withdraw.ts
|
|
2694
|
-
function
|
|
2958
|
+
function useResolvedWithdrawConfig(params) {
|
|
2695
2959
|
const { chainId, symmioConfig } = useSymmContext();
|
|
2696
|
-
const { publicClient, walletClient } = params;
|
|
2697
|
-
const queryClient = reactQuery.useQueryClient();
|
|
2698
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);
|
|
2699
2971
|
return reactQuery.useMutation({
|
|
2700
2972
|
...withSymmMutationConfig(options?.mutation, {
|
|
2701
|
-
onSuccess: () =>
|
|
2702
|
-
invalidateBalances(queryClient);
|
|
2703
|
-
}
|
|
2973
|
+
onSuccess: () => invalidateBalances(queryClient)
|
|
2704
2974
|
}),
|
|
2705
|
-
mutationFn: async ({
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2975
|
+
mutationFn: async (vars) => {
|
|
2976
|
+
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
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
|
+
});
|
|
2984
|
+
}
|
|
2985
|
+
});
|
|
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) => {
|
|
2709
2995
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
2710
|
-
|
|
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
|
+
});
|
|
2711
3019
|
}
|
|
2712
3020
|
});
|
|
2713
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
|
+
}
|
|
2714
3153
|
|
|
2715
3154
|
// src/abis/SymmioDiamond.ts
|
|
2716
3155
|
var SymmioDiamondABI = [
|
|
@@ -25096,18 +25535,6 @@ var SymmioDiamondABI = [
|
|
|
25096
25535
|
type: "function"
|
|
25097
25536
|
}
|
|
25098
25537
|
];
|
|
25099
|
-
function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
|
|
25100
|
-
const data = viem.encodeFunctionData({
|
|
25101
|
-
abi: accountDiamondAbi,
|
|
25102
|
-
functionName: "_call",
|
|
25103
|
-
args: [subAccount, callDatas]
|
|
25104
|
-
});
|
|
25105
|
-
return {
|
|
25106
|
-
functionName: "_call",
|
|
25107
|
-
args: [subAccount, callDatas],
|
|
25108
|
-
data
|
|
25109
|
-
};
|
|
25110
|
-
}
|
|
25111
25538
|
|
|
25112
25539
|
// src/actions/allocate.ts
|
|
25113
25540
|
function prepareAllocate(multiAccount, account, subAccount, params) {
|
|
@@ -26102,8 +26529,8 @@ function computeSymmNetDeposited(totals, decimals = 6) {
|
|
|
26102
26529
|
return "0";
|
|
26103
26530
|
}
|
|
26104
26531
|
const deposit2 = parseRawCollateralUnits(totals.deposit);
|
|
26105
|
-
const
|
|
26106
|
-
const value = deposit2 -
|
|
26532
|
+
const withdraw = parseRawCollateralUnits(totals.withdraw);
|
|
26533
|
+
const value = deposit2 - withdraw;
|
|
26107
26534
|
const negative = value < 0n;
|
|
26108
26535
|
const absolute = negative ? -value : value;
|
|
26109
26536
|
const scale = 10n ** BigInt(decimals);
|
|
@@ -27957,14 +28384,17 @@ exports.useSymmDelegation = useSymmDelegation;
|
|
|
27957
28384
|
exports.useSymmDepositAndAllocateMutation = useSymmDepositAndAllocateMutation;
|
|
27958
28385
|
exports.useSymmDepositMutation = useSymmDepositMutation;
|
|
27959
28386
|
exports.useSymmEditAccountNameMutation = useSymmEditAccountNameMutation;
|
|
28387
|
+
exports.useSymmFinalizeWithdraw = useSymmFinalizeWithdraw;
|
|
27960
28388
|
exports.useSymmFunding = useSymmFunding;
|
|
27961
28389
|
exports.useSymmFundingHistory = useSymmFundingHistory;
|
|
27962
28390
|
exports.useSymmFundingPayments = useSymmFundingPayments;
|
|
27963
28391
|
exports.useSymmHedgerMarketById = useSymmHedgerMarketById;
|
|
27964
28392
|
exports.useSymmHedgerMarketBySymbol = useSymmHedgerMarketBySymbol;
|
|
27965
28393
|
exports.useSymmHedgerMarkets = useSymmHedgerMarkets;
|
|
28394
|
+
exports.useSymmInitiateWithdraw = useSymmInitiateWithdraw;
|
|
27966
28395
|
exports.useSymmInstantTradeEnsureReadyMutation = useSymmInstantTradeEnsureReadyMutation;
|
|
27967
28396
|
exports.useSymmInstantTradeExecuteMutation = useSymmInstantTradeExecuteMutation;
|
|
28397
|
+
exports.useSymmInstantWithdraw = useSymmInstantWithdraw;
|
|
27968
28398
|
exports.useSymmInternalTransferCollateralMutation = useSymmInternalTransferCollateralMutation;
|
|
27969
28399
|
exports.useSymmLockedParams = useSymmLockedParams;
|
|
27970
28400
|
exports.useSymmMarkReadNotificationMutation = useSymmMarkReadNotificationMutation;
|
|
@@ -27979,6 +28409,7 @@ exports.useSymmPerformanceOverlays = useSymmPerformanceOverlays;
|
|
|
27979
28409
|
exports.useSymmPortfolio = useSymmPortfolio;
|
|
27980
28410
|
exports.useSymmPositions = useSymmPositions;
|
|
27981
28411
|
exports.useSymmProposeRevokeDelegationMutation = useSymmProposeRevokeDelegationMutation;
|
|
28412
|
+
exports.useSymmRequestCancelWithdraw = useSymmRequestCancelWithdraw;
|
|
27982
28413
|
exports.useSymmRevokeDelegationMutation = useSymmRevokeDelegationMutation;
|
|
27983
28414
|
exports.useSymmSetTpslMutation = useSymmSetTpslMutation;
|
|
27984
28415
|
exports.useSymmSetTriggerConfigMutation = useSymmSetTriggerConfigMutation;
|