@pear-protocol/symmio-client 0.3.16 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 ────────────────────────────────────
@@ -23282,6 +23485,7 @@ var SymmioSDKError = class extends Error {
23282
23485
  this.code = code;
23283
23486
  this.name = "SymmioSDKError";
23284
23487
  }
23488
+ code;
23285
23489
  };
23286
23490
  function validateAddress(address, name) {
23287
23491
  if (!viem.isAddress(address)) {
@@ -23657,27 +23861,149 @@ async function depositAndAllocate(walletClient, publicClient, multiAccount, para
23657
23861
  // src/actions/withdraw.ts
23658
23862
  var withdraw_exports = {};
23659
23863
  __export(withdraw_exports, {
23660
- prepareWithdraw: () => prepareWithdraw,
23661
- 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
23662
23873
  });
23663
- function prepareWithdraw(multiAccount, account, params) {
23664
- validateAmount(params.amount, "withdraw amount");
23665
- 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) {
23666
23882
  const data = viem.encodeFunctionData({
23667
- abi: MultiAccountABI,
23668
- functionName: "withdrawFromAccount",
23669
- args: [params.account, params.amount]
23883
+ abi: accountDiamondAbi,
23884
+ functionName: "_call",
23885
+ args: [subAccount, callDatas]
23670
23886
  });
23671
23887
  return {
23672
- functionName: "withdrawFromAccount",
23673
- args: [params.account, params.amount],
23674
- 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
23675
23913
  };
23676
23914
  }
23677
- 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) {
23678
23982
  const account = walletClient.account?.address;
23679
23983
  if (!account) throw new Error("Wallet client has no account");
23680
- 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);
23681
24007
  const gas = await publicClient.estimateGas(prepared.config);
23682
24008
  return walletClient.sendTransaction({
23683
24009
  ...prepared.config,
@@ -23696,27 +24022,6 @@ __export(allocate_exports, {
23696
24022
  prepareDeallocate: () => prepareDeallocate,
23697
24023
  prepareInternalTransfer: () => prepareInternalTransfer
23698
24024
  });
23699
- function encodeCall(abi, functionName, args) {
23700
- return viem.encodeFunctionData({
23701
- abi,
23702
- functionName,
23703
- args
23704
- });
23705
- }
23706
- function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
23707
- const data = viem.encodeFunctionData({
23708
- abi: accountDiamondAbi,
23709
- functionName: "_call",
23710
- args: [subAccount, callDatas]
23711
- });
23712
- return {
23713
- functionName: "_call",
23714
- args: [subAccount, callDatas],
23715
- data
23716
- };
23717
- }
23718
-
23719
- // src/actions/allocate.ts
23720
24025
  function prepareAllocate(multiAccount, account, subAccount, params) {
23721
24026
  validateAmount(params.amount, "allocate amount");
23722
24027
  const innerData = viem.encodeFunctionData({
@@ -24915,8 +25220,8 @@ function computeSymmNetDeposited(totals, decimals = 6) {
24915
25220
  return "0";
24916
25221
  }
24917
25222
  const deposit2 = parseRawCollateralUnits(totals.deposit);
24918
- const withdraw2 = parseRawCollateralUnits(totals.withdraw);
24919
- const value = deposit2 - withdraw2;
25223
+ const withdraw = parseRawCollateralUnits(totals.withdraw);
25224
+ const value = deposit2 - withdraw;
24920
25225
  const negative = value < 0n;
24921
25226
  const absolute = negative ? -value : value;
24922
25227
  const scale = 10n ** BigInt(decimals);
@@ -25092,6 +25397,7 @@ exports.DEFAULT_PRECISION = DEFAULT_PRECISION;
25092
25397
  exports.ERC20ABI = ERC20ABI;
25093
25398
  exports.FALLBACK_CHAIN_ID = FALLBACK_CHAIN_ID;
25094
25399
  exports.InstantCloseStatus = InstantCloseStatus;
25400
+ exports.InstantWithdrawStatus = InstantWithdrawStatus;
25095
25401
  exports.LIMIT_ORDER_DEADLINE = LIMIT_ORDER_DEADLINE;
25096
25402
  exports.LiquidationStatus = LiquidationStatus;
25097
25403
  exports.MARKET_ORDER_DEADLINE = MARKET_ORDER_DEADLINE;
@@ -25116,6 +25422,10 @@ exports.SupportedChainId = SupportedChainId;
25116
25422
  exports.SymmioDiamondABI = SymmioDiamondABI;
25117
25423
  exports.SymmioSDKError = SymmioSDKError;
25118
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;
25119
25429
  exports.accountActions = account_exports;
25120
25430
  exports.adminActions = admin_exports;
25121
25431
  exports.allocateActions = allocate_exports;