@pear-protocol/symmio-client 0.3.18 → 0.3.20
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 +15 -480
- package/dist/index.d.ts +15 -480
- package/dist/index.js +87 -370
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -366
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +11 -146
- package/dist/react/index.d.ts +11 -146
- package/dist/react/index.js +81 -492
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +83 -490
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -1718,6 +1718,12 @@ function validateAddress(address, name) {
|
|
|
1718
1718
|
return address;
|
|
1719
1719
|
}
|
|
1720
1720
|
function validateAmount(amount, name) {
|
|
1721
|
+
if (typeof amount !== "bigint") {
|
|
1722
|
+
throw new SymmioSDKError(
|
|
1723
|
+
`${name} must be a bigint, got ${amount === void 0 ? "undefined" : typeof amount} (${amount})`,
|
|
1724
|
+
"INVALID_AMOUNT"
|
|
1725
|
+
);
|
|
1726
|
+
}
|
|
1721
1727
|
if (amount <= 0n) {
|
|
1722
1728
|
throw new SymmioSDKError(
|
|
1723
1729
|
`${name} must be a positive amount, got ${amount}`,
|
|
@@ -2664,288 +2670,24 @@ function useSymmDepositAndAllocateMutation(params = {}, options) {
|
|
|
2664
2670
|
}
|
|
2665
2671
|
});
|
|
2666
2672
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
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) {
|
|
2673
|
+
function prepareWithdraw(multiAccount, account, params) {
|
|
2674
|
+
validateAmount(params.amount, "withdraw amount");
|
|
2675
|
+
validateAddress(params.account, "account");
|
|
2846
2676
|
const data = viem.encodeFunctionData({
|
|
2847
|
-
abi:
|
|
2848
|
-
functionName: "
|
|
2849
|
-
args: [
|
|
2850
|
-
});
|
|
2851
|
-
return {
|
|
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]
|
|
2677
|
+
abi: MultiAccountABI,
|
|
2678
|
+
functionName: "withdrawFromAccount",
|
|
2679
|
+
args: [params.account, params.amount]
|
|
2915
2680
|
});
|
|
2916
|
-
const proxy = wrapInProxyCall(MultiAccountABI, subAccount, [innerData]);
|
|
2917
2681
|
return {
|
|
2918
|
-
functionName: "
|
|
2919
|
-
args:
|
|
2920
|
-
config: { account, to: multiAccount, data
|
|
2682
|
+
functionName: "withdrawFromAccount",
|
|
2683
|
+
args: [params.account, params.amount],
|
|
2684
|
+
config: { account, to: multiAccount, data, value: 0n }
|
|
2921
2685
|
};
|
|
2922
2686
|
}
|
|
2923
|
-
async function
|
|
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) {
|
|
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) {
|
|
2687
|
+
async function withdraw(walletClient, publicClient, multiAccount, params) {
|
|
2946
2688
|
const account = walletClient.account?.address;
|
|
2947
2689
|
if (!account) throw new Error("Wallet client has no account");
|
|
2948
|
-
const prepared =
|
|
2690
|
+
const prepared = prepareWithdraw(multiAccount, account, params);
|
|
2949
2691
|
const gas = await publicClient.estimateGas(prepared.config);
|
|
2950
2692
|
return walletClient.sendTransaction({
|
|
2951
2693
|
...prepared.config,
|
|
@@ -2955,201 +2697,26 @@ async function requestCancelWithdraw(walletClient, publicClient, multiAccount, s
|
|
|
2955
2697
|
}
|
|
2956
2698
|
|
|
2957
2699
|
// src/react/hooks/use-symm-withdraw.ts
|
|
2958
|
-
function
|
|
2700
|
+
function useSymmWithdraw(params = {}, options) {
|
|
2959
2701
|
const { chainId, symmioConfig } = useSymmContext();
|
|
2960
|
-
const
|
|
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);
|
|
2971
|
-
return reactQuery.useMutation({
|
|
2972
|
-
...withSymmMutationConfig(options?.mutation, {
|
|
2973
|
-
onSuccess: () => invalidateBalances(queryClient)
|
|
2974
|
-
}),
|
|
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) => {
|
|
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) {
|
|
2702
|
+
const { publicClient, walletClient } = params;
|
|
3006
2703
|
const queryClient = reactQuery.useQueryClient();
|
|
3007
|
-
const
|
|
2704
|
+
const multiAccount = symmioConfig?.multiAccountAddress ?? getAddress(MULTI_ACCOUNT_ADDRESS, chainId, "MultiAccount");
|
|
3008
2705
|
return reactQuery.useMutation({
|
|
3009
2706
|
...withSymmMutationConfig(options?.mutation, {
|
|
3010
|
-
onSuccess: () =>
|
|
2707
|
+
onSuccess: () => {
|
|
2708
|
+
invalidateBalances(queryClient);
|
|
2709
|
+
}
|
|
3011
2710
|
}),
|
|
3012
|
-
mutationFn: async (
|
|
2711
|
+
mutationFn: async ({
|
|
2712
|
+
account,
|
|
2713
|
+
amount
|
|
2714
|
+
}) => {
|
|
3013
2715
|
if (!walletClient || !publicClient) throw new Error("Clients not available");
|
|
3014
|
-
|
|
3015
|
-
if (!subAccount) throw new Error("subAccount required");
|
|
3016
|
-
return requestCancelWithdraw(walletClient, publicClient, multiAccount, subAccount, {
|
|
3017
|
-
requestId: vars.requestId
|
|
3018
|
-
});
|
|
2716
|
+
return withdraw(walletClient, publicClient, multiAccount, { account, amount });
|
|
3019
2717
|
}
|
|
3020
2718
|
});
|
|
3021
2719
|
}
|
|
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
|
-
}
|
|
3153
2720
|
|
|
3154
2721
|
// src/abis/SymmioDiamond.ts
|
|
3155
2722
|
var SymmioDiamondABI = [
|
|
@@ -25535,6 +25102,18 @@ var SymmioDiamondABI = [
|
|
|
25535
25102
|
type: "function"
|
|
25536
25103
|
}
|
|
25537
25104
|
];
|
|
25105
|
+
function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
|
|
25106
|
+
const data = viem.encodeFunctionData({
|
|
25107
|
+
abi: accountDiamondAbi,
|
|
25108
|
+
functionName: "_call",
|
|
25109
|
+
args: [subAccount, callDatas]
|
|
25110
|
+
});
|
|
25111
|
+
return {
|
|
25112
|
+
functionName: "_call",
|
|
25113
|
+
args: [subAccount, callDatas],
|
|
25114
|
+
data
|
|
25115
|
+
};
|
|
25116
|
+
}
|
|
25538
25117
|
|
|
25539
25118
|
// src/actions/allocate.ts
|
|
25540
25119
|
function prepareAllocate(multiAccount, account, subAccount, params) {
|
|
@@ -25652,17 +25231,29 @@ function normalizeSignParams(raw) {
|
|
|
25652
25231
|
return raw ?? {};
|
|
25653
25232
|
}
|
|
25654
25233
|
function unwrapMuonResult(result) {
|
|
25655
|
-
const
|
|
25656
|
-
if (!
|
|
25234
|
+
const envelope = result["result"];
|
|
25235
|
+
if (!envelope) {
|
|
25657
25236
|
throw new SymmioSDKError("Invalid Muon response: missing result", "MUON_PARSE_ERROR");
|
|
25658
25237
|
}
|
|
25659
|
-
const
|
|
25238
|
+
const meta = envelope["data"] ?? {};
|
|
25660
25239
|
return {
|
|
25661
|
-
|
|
25662
|
-
|
|
25663
|
-
|
|
25240
|
+
envelope,
|
|
25241
|
+
meta,
|
|
25242
|
+
computed: meta["result"] ?? {},
|
|
25243
|
+
signParams: normalizeSignParams(meta["signParams"] ?? envelope["signParams"]),
|
|
25244
|
+
signatures: meta["signatures"] ?? envelope["signatures"] ?? [],
|
|
25245
|
+
init: meta["init"] ?? envelope["init"]
|
|
25664
25246
|
};
|
|
25665
25247
|
}
|
|
25248
|
+
function requireBigInt(value, field) {
|
|
25249
|
+
if (value === void 0 || value === null || value === "") {
|
|
25250
|
+
throw new SymmioSDKError(
|
|
25251
|
+
`Invalid Muon response: missing "${field}"`,
|
|
25252
|
+
"MUON_PARSE_ERROR"
|
|
25253
|
+
);
|
|
25254
|
+
}
|
|
25255
|
+
return BigInt(value);
|
|
25256
|
+
}
|
|
25666
25257
|
function extractSchnorrSign(signParams, signatures, init) {
|
|
25667
25258
|
const inline = signParams["sigs"];
|
|
25668
25259
|
if (inline?.signature !== void 0) {
|
|
@@ -25692,41 +25283,43 @@ function extractSchnorrSign(signParams, signatures, init) {
|
|
|
25692
25283
|
nonce: nonceAddress
|
|
25693
25284
|
};
|
|
25694
25285
|
}
|
|
25695
|
-
function gatewaySigOf(signatures) {
|
|
25286
|
+
function gatewaySigOf(envelope, signatures) {
|
|
25287
|
+
const shield = envelope["shieldSignature"] ?? envelope["nodeSignature"] ?? envelope["gatewaySignature"];
|
|
25288
|
+
if (typeof shield === "string" && shield.length > 0) return shield;
|
|
25696
25289
|
return signatures?.[0]?.["signature"] ?? "0x";
|
|
25697
25290
|
}
|
|
25698
25291
|
function parseSingleUpnlSig(result) {
|
|
25699
|
-
const { signParams, signatures, init } = unwrapMuonResult(result);
|
|
25292
|
+
const { signParams, signatures, init, envelope, meta, computed } = unwrapMuonResult(result);
|
|
25700
25293
|
return {
|
|
25701
|
-
reqId: signParams["reqId"],
|
|
25702
|
-
timestamp:
|
|
25703
|
-
upnl:
|
|
25704
|
-
gatewaySignature: gatewaySigOf(signatures),
|
|
25294
|
+
reqId: signParams["reqId"] ?? envelope["reqId"],
|
|
25295
|
+
timestamp: requireBigInt(signParams["timestamp"] ?? meta["timestamp"], "timestamp"),
|
|
25296
|
+
upnl: requireBigInt(signParams["upnl"] ?? computed["uPnl"], "upnl"),
|
|
25297
|
+
gatewaySignature: gatewaySigOf(envelope, signatures),
|
|
25705
25298
|
sigs: extractSchnorrSign(signParams, signatures, init)
|
|
25706
25299
|
};
|
|
25707
25300
|
}
|
|
25708
25301
|
function parseSingleUpnlAndPriceSig(result) {
|
|
25709
|
-
const { signParams, signatures, init } = unwrapMuonResult(result);
|
|
25302
|
+
const { signParams, signatures, init, envelope, meta, computed } = unwrapMuonResult(result);
|
|
25710
25303
|
return {
|
|
25711
|
-
reqId: signParams["reqId"],
|
|
25712
|
-
timestamp:
|
|
25713
|
-
upnl:
|
|
25714
|
-
price:
|
|
25715
|
-
gatewaySignature: gatewaySigOf(signatures),
|
|
25304
|
+
reqId: signParams["reqId"] ?? envelope["reqId"],
|
|
25305
|
+
timestamp: requireBigInt(signParams["timestamp"] ?? meta["timestamp"], "timestamp"),
|
|
25306
|
+
upnl: requireBigInt(signParams["upnl"] ?? computed["uPnl"], "upnl"),
|
|
25307
|
+
price: requireBigInt(signParams["price"] ?? computed["price"], "price"),
|
|
25308
|
+
gatewaySignature: gatewaySigOf(envelope, signatures),
|
|
25716
25309
|
sigs: extractSchnorrSign(signParams, signatures, init)
|
|
25717
25310
|
};
|
|
25718
25311
|
}
|
|
25719
25312
|
function parseBatchSig(result) {
|
|
25720
|
-
const { signParams, signatures, init } = unwrapMuonResult(result);
|
|
25721
|
-
const prices = signParams["prices"];
|
|
25722
|
-
const symbolIds = signParams["symbolIds"];
|
|
25313
|
+
const { signParams, signatures, init, envelope, meta, computed } = unwrapMuonResult(result);
|
|
25314
|
+
const prices = signParams["prices"] ?? computed["prices"];
|
|
25315
|
+
const symbolIds = signParams["symbolIds"] ?? computed["symbolIds"];
|
|
25723
25316
|
return {
|
|
25724
|
-
reqId: signParams["reqId"],
|
|
25725
|
-
timestamp:
|
|
25726
|
-
upnl:
|
|
25317
|
+
reqId: signParams["reqId"] ?? envelope["reqId"],
|
|
25318
|
+
timestamp: requireBigInt(signParams["timestamp"] ?? meta["timestamp"], "timestamp"),
|
|
25319
|
+
upnl: requireBigInt(signParams["upnl"] ?? computed["uPnl"], "upnl"),
|
|
25727
25320
|
prices: (prices ?? []).map((p) => BigInt(p)),
|
|
25728
25321
|
symbolIds: (symbolIds ?? []).map((s) => BigInt(s)),
|
|
25729
|
-
gatewaySignature: gatewaySigOf(signatures),
|
|
25322
|
+
gatewaySignature: gatewaySigOf(envelope, signatures),
|
|
25730
25323
|
sigs: extractSchnorrSign(signParams, signatures, init)
|
|
25731
25324
|
};
|
|
25732
25325
|
}
|
|
@@ -26529,8 +26122,8 @@ function computeSymmNetDeposited(totals, decimals = 6) {
|
|
|
26529
26122
|
return "0";
|
|
26530
26123
|
}
|
|
26531
26124
|
const deposit2 = parseRawCollateralUnits(totals.deposit);
|
|
26532
|
-
const
|
|
26533
|
-
const value = deposit2 -
|
|
26125
|
+
const withdraw2 = parseRawCollateralUnits(totals.withdraw);
|
|
26126
|
+
const value = deposit2 - withdraw2;
|
|
26534
26127
|
const negative = value < 0n;
|
|
26535
26128
|
const absolute = negative ? -value : value;
|
|
26536
26129
|
const scale = 10n ** BigInt(decimals);
|
|
@@ -28384,17 +27977,14 @@ exports.useSymmDelegation = useSymmDelegation;
|
|
|
28384
27977
|
exports.useSymmDepositAndAllocateMutation = useSymmDepositAndAllocateMutation;
|
|
28385
27978
|
exports.useSymmDepositMutation = useSymmDepositMutation;
|
|
28386
27979
|
exports.useSymmEditAccountNameMutation = useSymmEditAccountNameMutation;
|
|
28387
|
-
exports.useSymmFinalizeWithdraw = useSymmFinalizeWithdraw;
|
|
28388
27980
|
exports.useSymmFunding = useSymmFunding;
|
|
28389
27981
|
exports.useSymmFundingHistory = useSymmFundingHistory;
|
|
28390
27982
|
exports.useSymmFundingPayments = useSymmFundingPayments;
|
|
28391
27983
|
exports.useSymmHedgerMarketById = useSymmHedgerMarketById;
|
|
28392
27984
|
exports.useSymmHedgerMarketBySymbol = useSymmHedgerMarketBySymbol;
|
|
28393
27985
|
exports.useSymmHedgerMarkets = useSymmHedgerMarkets;
|
|
28394
|
-
exports.useSymmInitiateWithdraw = useSymmInitiateWithdraw;
|
|
28395
27986
|
exports.useSymmInstantTradeEnsureReadyMutation = useSymmInstantTradeEnsureReadyMutation;
|
|
28396
27987
|
exports.useSymmInstantTradeExecuteMutation = useSymmInstantTradeExecuteMutation;
|
|
28397
|
-
exports.useSymmInstantWithdraw = useSymmInstantWithdraw;
|
|
28398
27988
|
exports.useSymmInternalTransferCollateralMutation = useSymmInternalTransferCollateralMutation;
|
|
28399
27989
|
exports.useSymmLockedParams = useSymmLockedParams;
|
|
28400
27990
|
exports.useSymmMarkReadNotificationMutation = useSymmMarkReadNotificationMutation;
|
|
@@ -28409,7 +27999,6 @@ exports.useSymmPerformanceOverlays = useSymmPerformanceOverlays;
|
|
|
28409
27999
|
exports.useSymmPortfolio = useSymmPortfolio;
|
|
28410
28000
|
exports.useSymmPositions = useSymmPositions;
|
|
28411
28001
|
exports.useSymmProposeRevokeDelegationMutation = useSymmProposeRevokeDelegationMutation;
|
|
28412
|
-
exports.useSymmRequestCancelWithdraw = useSymmRequestCancelWithdraw;
|
|
28413
28002
|
exports.useSymmRevokeDelegationMutation = useSymmRevokeDelegationMutation;
|
|
28414
28003
|
exports.useSymmSetTpslMutation = useSymmSetTpslMutation;
|
|
28415
28004
|
exports.useSymmSetTriggerConfigMutation = useSymmSetTriggerConfigMutation;
|