@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.js CHANGED
@@ -48,6 +48,34 @@ var SoftLiquidationLevel = /* @__PURE__ */ ((SoftLiquidationLevel2) => {
48
48
  return SoftLiquidationLevel2;
49
49
  })(SoftLiquidationLevel || {});
50
50
 
51
+ // src/types/withdraw.ts
52
+ var WithdrawStatus = /* @__PURE__ */ ((WithdrawStatus2) => {
53
+ WithdrawStatus2[WithdrawStatus2["PENDING"] = 0] = "PENDING";
54
+ WithdrawStatus2[WithdrawStatus2["PROVIDER_ACCEPTED"] = 1] = "PROVIDER_ACCEPTED";
55
+ WithdrawStatus2[WithdrawStatus2["PROVIDER_REJECTED"] = 2] = "PROVIDER_REJECTED";
56
+ WithdrawStatus2[WithdrawStatus2["COMPLETED"] = 3] = "COMPLETED";
57
+ WithdrawStatus2[WithdrawStatus2["CANCEL_REQUESTED"] = 4] = "CANCEL_REQUESTED";
58
+ WithdrawStatus2[WithdrawStatus2["CANCELLED"] = 5] = "CANCELLED";
59
+ WithdrawStatus2[WithdrawStatus2["SUSPENDED"] = 6] = "SUSPENDED";
60
+ return WithdrawStatus2;
61
+ })(WithdrawStatus || {});
62
+ var WithdrawSpeed = /* @__PURE__ */ ((WithdrawSpeed2) => {
63
+ WithdrawSpeed2["STANDARD"] = "standard";
64
+ WithdrawSpeed2["INSTANT"] = "instant";
65
+ return WithdrawSpeed2;
66
+ })(WithdrawSpeed || {});
67
+ var InstantWithdrawStatus = /* @__PURE__ */ ((InstantWithdrawStatus2) => {
68
+ InstantWithdrawStatus2["IDLE"] = "idle";
69
+ InstantWithdrawStatus2["INITIATING"] = "initiating";
70
+ InstantWithdrawStatus2["AWAITING_PROVIDER"] = "awaitingProvider";
71
+ InstantWithdrawStatus2["AWAITING_COOLDOWN"] = "awaitingCooldown";
72
+ InstantWithdrawStatus2["FINALIZING"] = "finalizing";
73
+ InstantWithdrawStatus2["COMPLETED"] = "completed";
74
+ InstantWithdrawStatus2["FAILED"] = "failed";
75
+ return InstantWithdrawStatus2;
76
+ })(InstantWithdrawStatus || {});
77
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
78
+
51
79
  // src/types/affiliate.ts
52
80
  var AffiliateFeeLevel = /* @__PURE__ */ ((AffiliateFeeLevel2) => {
53
81
  AffiliateFeeLevel2[AffiliateFeeLevel2["USER_SYMBOL"] = 0] = "USER_SYMBOL";
@@ -22866,6 +22894,181 @@ var SymmioDiamondABI = [
22866
22894
  }
22867
22895
  ];
22868
22896
 
22897
+ // src/abis/WithdrawFacet.ts
22898
+ var WithdrawFacetABI = [
22899
+ // ─── Mutations ──────────────────────────────────────────────────
22900
+ {
22901
+ type: "function",
22902
+ name: "initiateWithdraw",
22903
+ stateMutability: "nonpayable",
22904
+ inputs: [
22905
+ {
22906
+ name: "parts",
22907
+ type: "tuple[]",
22908
+ internalType: "struct WithdrawReceiverPart[]",
22909
+ components: [
22910
+ { name: "id", type: "uint256", internalType: "uint256" },
22911
+ { name: "amount", type: "uint256", internalType: "uint256" },
22912
+ { name: "chainId", type: "int256", internalType: "int256" },
22913
+ { name: "receiver", type: "bytes", internalType: "bytes" },
22914
+ { name: "virtualProvider", type: "address", internalType: "address" },
22915
+ { name: "expressProvider", type: "address", internalType: "address" }
22916
+ ]
22917
+ },
22918
+ { name: "speedUp", type: "bool", internalType: "bool" },
22919
+ { name: "data", type: "bytes", internalType: "bytes" }
22920
+ ],
22921
+ outputs: [
22922
+ { name: "requestId", type: "uint256", internalType: "uint256" },
22923
+ { name: "cooldownEndTime", type: "uint256", internalType: "uint256" }
22924
+ ]
22925
+ },
22926
+ {
22927
+ type: "function",
22928
+ name: "finalizeWithdrawRequest",
22929
+ stateMutability: "nonpayable",
22930
+ inputs: [
22931
+ { name: "user", type: "address", internalType: "address" },
22932
+ { name: "requestId", type: "uint256", internalType: "uint256" }
22933
+ ],
22934
+ outputs: []
22935
+ },
22936
+ {
22937
+ type: "function",
22938
+ name: "requestCancelWithdraw",
22939
+ stateMutability: "nonpayable",
22940
+ inputs: [{ name: "requestId", type: "uint256", internalType: "uint256" }],
22941
+ outputs: []
22942
+ },
22943
+ // ─── Views ──────────────────────────────────────────────────────
22944
+ {
22945
+ type: "function",
22946
+ name: "getWithdrawableTime",
22947
+ stateMutability: "view",
22948
+ inputs: [{ name: "user", type: "address", internalType: "address" }],
22949
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }]
22950
+ },
22951
+ {
22952
+ type: "function",
22953
+ name: "getLastWithdrawRequestId",
22954
+ stateMutability: "view",
22955
+ inputs: [{ name: "user", type: "address", internalType: "address" }],
22956
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }]
22957
+ },
22958
+ {
22959
+ type: "function",
22960
+ name: "isSpeedUpEligible",
22961
+ stateMutability: "view",
22962
+ inputs: [{ name: "user", type: "address", internalType: "address" }],
22963
+ outputs: [{ name: "", type: "bool", internalType: "bool" }]
22964
+ },
22965
+ {
22966
+ type: "function",
22967
+ name: "isExpressProviderRegistered",
22968
+ stateMutability: "view",
22969
+ inputs: [{ name: "provider", type: "address", internalType: "address" }],
22970
+ outputs: [{ name: "", type: "bool", internalType: "bool" }]
22971
+ },
22972
+ {
22973
+ type: "function",
22974
+ name: "isVirtualProviderRegistered",
22975
+ stateMutability: "view",
22976
+ inputs: [{ name: "provider", type: "address", internalType: "address" }],
22977
+ outputs: [{ name: "", type: "bool", internalType: "bool" }]
22978
+ },
22979
+ // ─── Events ─────────────────────────────────────────────────────
22980
+ {
22981
+ type: "event",
22982
+ name: "WithdrawInitiated",
22983
+ anonymous: false,
22984
+ inputs: [
22985
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
22986
+ { name: "user", type: "address", indexed: true, internalType: "address" },
22987
+ {
22988
+ name: "parts",
22989
+ type: "tuple[]",
22990
+ indexed: false,
22991
+ internalType: "struct WithdrawReceiverPart[]",
22992
+ components: [
22993
+ { name: "id", type: "uint256", internalType: "uint256" },
22994
+ { name: "amount", type: "uint256", internalType: "uint256" },
22995
+ { name: "chainId", type: "int256", internalType: "int256" },
22996
+ { name: "receiver", type: "bytes", internalType: "bytes" },
22997
+ { name: "virtualProvider", type: "address", internalType: "address" },
22998
+ { name: "expressProvider", type: "address", internalType: "address" }
22999
+ ]
23000
+ },
23001
+ { name: "speedUp", type: "bool", indexed: false, internalType: "bool" },
23002
+ { name: "providerData", type: "bytes", indexed: false, internalType: "bytes" },
23003
+ { name: "cooldownEndTime", type: "uint256", indexed: false, internalType: "uint256" }
23004
+ ]
23005
+ },
23006
+ {
23007
+ type: "event",
23008
+ name: "WithdrawAccepted",
23009
+ anonymous: false,
23010
+ inputs: [
23011
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
23012
+ { name: "user", type: "address", indexed: true, internalType: "address" }
23013
+ ]
23014
+ },
23015
+ {
23016
+ type: "event",
23017
+ name: "WithdrawFinalized",
23018
+ anonymous: false,
23019
+ inputs: [
23020
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
23021
+ { name: "user", type: "address", indexed: true, internalType: "address" }
23022
+ ]
23023
+ },
23024
+ {
23025
+ type: "event",
23026
+ name: "WithdrawCancelRequested",
23027
+ anonymous: false,
23028
+ inputs: [
23029
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
23030
+ { name: "user", type: "address", indexed: true, internalType: "address" }
23031
+ ]
23032
+ },
23033
+ {
23034
+ type: "event",
23035
+ name: "WithdrawCancelled",
23036
+ anonymous: false,
23037
+ inputs: [
23038
+ { name: "requestId", type: "uint256", indexed: true, internalType: "uint256" },
23039
+ { name: "user", type: "address", indexed: true, internalType: "address" }
23040
+ ]
23041
+ },
23042
+ {
23043
+ type: "event",
23044
+ name: "WithdrawRejected",
23045
+ anonymous: false,
23046
+ inputs: [
23047
+ { name: "requestId", type: "uint256", indexed: false, internalType: "uint256" },
23048
+ { name: "user", type: "address", indexed: false, internalType: "address" }
23049
+ ]
23050
+ },
23051
+ {
23052
+ type: "event",
23053
+ name: "WithdrawSuspended",
23054
+ anonymous: false,
23055
+ inputs: [
23056
+ { name: "requestId", type: "uint256", indexed: false, internalType: "uint256" },
23057
+ { name: "user", type: "address", indexed: false, internalType: "address" }
23058
+ ]
23059
+ },
23060
+ {
23061
+ type: "event",
23062
+ name: "WithdrawSpeedUpAccepted",
23063
+ anonymous: false,
23064
+ inputs: [
23065
+ { name: "requestId", type: "uint256", indexed: false, internalType: "uint256" },
23066
+ { name: "user", type: "address", indexed: false, internalType: "address" },
23067
+ { name: "newCooldown", type: "uint256", indexed: false, internalType: "uint256" }
23068
+ ]
23069
+ }
23070
+ ];
23071
+
22869
23072
  // src/abis/ClearingHouse.ts
22870
23073
  var ClearingHouseABI = [
22871
23074
  // ─── Liquidation Lifecycle ────────────────────────────────────
@@ -23658,27 +23861,149 @@ async function depositAndAllocate(walletClient, publicClient, multiAccount, para
23658
23861
  // src/actions/withdraw.ts
23659
23862
  var withdraw_exports = {};
23660
23863
  __export(withdraw_exports, {
23661
- prepareWithdraw: () => prepareWithdraw,
23662
- withdraw: () => withdraw
23864
+ buildClassicWithdrawPart: () => buildClassicWithdrawPart,
23865
+ buildExpressWithdrawPart: () => buildExpressWithdrawPart,
23866
+ buildWithdrawPart: () => buildWithdrawPart,
23867
+ finalizeWithdraw: () => finalizeWithdraw,
23868
+ initiateWithdraw: () => initiateWithdraw,
23869
+ prepareFinalizeWithdraw: () => prepareFinalizeWithdraw,
23870
+ prepareInitiateWithdraw: () => prepareInitiateWithdraw,
23871
+ prepareRequestCancelWithdraw: () => prepareRequestCancelWithdraw,
23872
+ requestCancelWithdraw: () => requestCancelWithdraw
23663
23873
  });
23664
- function prepareWithdraw(multiAccount, account, params) {
23665
- validateAmount(params.amount, "withdraw amount");
23666
- validateAddress(params.account, "account");
23874
+ function encodeCall(abi, functionName, args) {
23875
+ return viem.encodeFunctionData({
23876
+ abi,
23877
+ functionName,
23878
+ args
23879
+ });
23880
+ }
23881
+ function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
23667
23882
  const data = viem.encodeFunctionData({
23668
- abi: MultiAccountABI,
23669
- functionName: "withdrawFromAccount",
23670
- args: [params.account, params.amount]
23883
+ abi: accountDiamondAbi,
23884
+ functionName: "_call",
23885
+ args: [subAccount, callDatas]
23671
23886
  });
23672
23887
  return {
23673
- functionName: "withdrawFromAccount",
23674
- args: [params.account, params.amount],
23675
- config: { account, to: multiAccount, data, value: 0n }
23888
+ functionName: "_call",
23889
+ args: [subAccount, callDatas],
23890
+ data
23891
+ };
23892
+ }
23893
+
23894
+ // src/actions/withdraw.ts
23895
+ function buildClassicWithdrawPart(amount, chainId, receiver, partId = 0n) {
23896
+ return {
23897
+ id: partId,
23898
+ amount,
23899
+ chainId,
23900
+ receiver,
23901
+ virtualProvider: ZERO_ADDRESS,
23902
+ expressProvider: ZERO_ADDRESS
23903
+ };
23904
+ }
23905
+ function buildExpressWithdrawPart(amount, chainId, receiver, expressProvider, partId = 0n) {
23906
+ return {
23907
+ id: partId,
23908
+ amount,
23909
+ chainId,
23910
+ receiver,
23911
+ virtualProvider: ZERO_ADDRESS,
23912
+ expressProvider
23676
23913
  };
23677
23914
  }
23678
- async function withdraw(walletClient, publicClient, multiAccount, params) {
23915
+ function buildWithdrawPart(amount, chainId, receiver, option, partId = 0n) {
23916
+ if (option.speed === "instant" /* INSTANT */) {
23917
+ return buildExpressWithdrawPart(
23918
+ amount,
23919
+ chainId,
23920
+ receiver,
23921
+ option.expressProvider,
23922
+ partId
23923
+ );
23924
+ }
23925
+ return buildClassicWithdrawPart(amount, chainId, receiver, partId);
23926
+ }
23927
+ function validateParts(parts) {
23928
+ if (parts.length === 0) {
23929
+ throw new Error("initiateWithdraw: at least one withdraw part is required");
23930
+ }
23931
+ for (const part of parts) {
23932
+ validateAmount(part.amount, "withdraw part amount");
23933
+ if (part.expressProvider !== ZERO_ADDRESS && part.expressProvider === part.virtualProvider) {
23934
+ throw new Error(
23935
+ "initiateWithdraw: a single provider cannot be set as both express and virtual"
23936
+ );
23937
+ }
23938
+ }
23939
+ }
23940
+ function prepareInitiateWithdraw(multiAccount, account, subAccount, params) {
23941
+ validateParts(params.parts);
23942
+ const innerData = viem.encodeFunctionData({
23943
+ abi: WithdrawFacetABI,
23944
+ functionName: "initiateWithdraw",
23945
+ args: [params.parts, params.speedUp, params.providerData]
23946
+ });
23947
+ const proxy = wrapInProxyCall(MultiAccountABI, subAccount, [innerData]);
23948
+ return {
23949
+ functionName: "_call",
23950
+ args: proxy.args,
23951
+ config: { account, to: multiAccount, data: proxy.data, value: 0n }
23952
+ };
23953
+ }
23954
+ function prepareFinalizeWithdraw(multiAccount, account, subAccount, params) {
23955
+ validateAddress(params.user, "user");
23956
+ const innerData = viem.encodeFunctionData({
23957
+ abi: WithdrawFacetABI,
23958
+ functionName: "finalizeWithdrawRequest",
23959
+ args: [params.user, params.requestId]
23960
+ });
23961
+ const proxy = wrapInProxyCall(MultiAccountABI, subAccount, [innerData]);
23962
+ return {
23963
+ functionName: "_call",
23964
+ args: proxy.args,
23965
+ config: { account, to: multiAccount, data: proxy.data, value: 0n }
23966
+ };
23967
+ }
23968
+ function prepareRequestCancelWithdraw(multiAccount, account, subAccount, params) {
23969
+ const innerData = viem.encodeFunctionData({
23970
+ abi: WithdrawFacetABI,
23971
+ functionName: "requestCancelWithdraw",
23972
+ args: [params.requestId]
23973
+ });
23974
+ const proxy = wrapInProxyCall(MultiAccountABI, subAccount, [innerData]);
23975
+ return {
23976
+ functionName: "_call",
23977
+ args: proxy.args,
23978
+ config: { account, to: multiAccount, data: proxy.data, value: 0n }
23979
+ };
23980
+ }
23981
+ async function initiateWithdraw(walletClient, publicClient, multiAccount, subAccount, params) {
23679
23982
  const account = walletClient.account?.address;
23680
23983
  if (!account) throw new Error("Wallet client has no account");
23681
- const prepared = prepareWithdraw(multiAccount, account, params);
23984
+ const prepared = prepareInitiateWithdraw(multiAccount, account, subAccount, params);
23985
+ const gas = await publicClient.estimateGas(prepared.config);
23986
+ return walletClient.sendTransaction({
23987
+ ...prepared.config,
23988
+ gas: calculateGasMargin(gas),
23989
+ chain: walletClient.chain
23990
+ });
23991
+ }
23992
+ async function finalizeWithdraw(walletClient, publicClient, multiAccount, subAccount, params) {
23993
+ const account = walletClient.account?.address;
23994
+ if (!account) throw new Error("Wallet client has no account");
23995
+ const prepared = prepareFinalizeWithdraw(multiAccount, account, subAccount, params);
23996
+ const gas = await publicClient.estimateGas(prepared.config);
23997
+ return walletClient.sendTransaction({
23998
+ ...prepared.config,
23999
+ gas: calculateGasMargin(gas),
24000
+ chain: walletClient.chain
24001
+ });
24002
+ }
24003
+ async function requestCancelWithdraw(walletClient, publicClient, multiAccount, subAccount, params) {
24004
+ const account = walletClient.account?.address;
24005
+ if (!account) throw new Error("Wallet client has no account");
24006
+ const prepared = prepareRequestCancelWithdraw(multiAccount, account, subAccount, params);
23682
24007
  const gas = await publicClient.estimateGas(prepared.config);
23683
24008
  return walletClient.sendTransaction({
23684
24009
  ...prepared.config,
@@ -23697,27 +24022,6 @@ __export(allocate_exports, {
23697
24022
  prepareDeallocate: () => prepareDeallocate,
23698
24023
  prepareInternalTransfer: () => prepareInternalTransfer
23699
24024
  });
23700
- function encodeCall(abi, functionName, args) {
23701
- return viem.encodeFunctionData({
23702
- abi,
23703
- functionName,
23704
- args
23705
- });
23706
- }
23707
- function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
23708
- const data = viem.encodeFunctionData({
23709
- abi: accountDiamondAbi,
23710
- functionName: "_call",
23711
- args: [subAccount, callDatas]
23712
- });
23713
- return {
23714
- functionName: "_call",
23715
- args: [subAccount, callDatas],
23716
- data
23717
- };
23718
- }
23719
-
23720
- // src/actions/allocate.ts
23721
24025
  function prepareAllocate(multiAccount, account, subAccount, params) {
23722
24026
  validateAmount(params.amount, "allocate amount");
23723
24027
  const innerData = viem.encodeFunctionData({
@@ -24916,8 +25220,8 @@ function computeSymmNetDeposited(totals, decimals = 6) {
24916
25220
  return "0";
24917
25221
  }
24918
25222
  const deposit2 = parseRawCollateralUnits(totals.deposit);
24919
- const withdraw2 = parseRawCollateralUnits(totals.withdraw);
24920
- const value = deposit2 - withdraw2;
25223
+ const withdraw = parseRawCollateralUnits(totals.withdraw);
25224
+ const value = deposit2 - withdraw;
24921
25225
  const negative = value < 0n;
24922
25226
  const absolute = negative ? -value : value;
24923
25227
  const scale = 10n ** BigInt(decimals);
@@ -25093,6 +25397,7 @@ exports.DEFAULT_PRECISION = DEFAULT_PRECISION;
25093
25397
  exports.ERC20ABI = ERC20ABI;
25094
25398
  exports.FALLBACK_CHAIN_ID = FALLBACK_CHAIN_ID;
25095
25399
  exports.InstantCloseStatus = InstantCloseStatus;
25400
+ exports.InstantWithdrawStatus = InstantWithdrawStatus;
25096
25401
  exports.LIMIT_ORDER_DEADLINE = LIMIT_ORDER_DEADLINE;
25097
25402
  exports.LiquidationStatus = LiquidationStatus;
25098
25403
  exports.MARKET_ORDER_DEADLINE = MARKET_ORDER_DEADLINE;
@@ -25117,6 +25422,10 @@ exports.SupportedChainId = SupportedChainId;
25117
25422
  exports.SymmioDiamondABI = SymmioDiamondABI;
25118
25423
  exports.SymmioSDKError = SymmioSDKError;
25119
25424
  exports.V3_CHAIN_IDS = V3_CHAIN_IDS;
25425
+ exports.WithdrawFacetABI = WithdrawFacetABI;
25426
+ exports.WithdrawSpeed = WithdrawSpeed;
25427
+ exports.WithdrawStatus = WithdrawStatus;
25428
+ exports.ZERO_ADDRESS = ZERO_ADDRESS;
25120
25429
  exports.accountActions = account_exports;
25121
25430
  exports.adminActions = admin_exports;
25122
25431
  exports.allocateActions = allocate_exports;