@pear-protocol/symmio-client 0.3.18 → 0.3.19

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,34 +48,6 @@ 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
-
79
51
  // src/types/affiliate.ts
80
52
  var AffiliateFeeLevel = /* @__PURE__ */ ((AffiliateFeeLevel2) => {
81
53
  AffiliateFeeLevel2[AffiliateFeeLevel2["USER_SYMBOL"] = 0] = "USER_SYMBOL";
@@ -22894,181 +22866,6 @@ var SymmioDiamondABI = [
22894
22866
  }
22895
22867
  ];
22896
22868
 
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
-
23072
22869
  // src/abis/ClearingHouse.ts
23073
22870
  var ClearingHouseABI = [
23074
22871
  // ─── Liquidation Lifecycle ────────────────────────────────────
@@ -23497,6 +23294,12 @@ function validateAddress(address, name) {
23497
23294
  return address;
23498
23295
  }
23499
23296
  function validateAmount(amount, name) {
23297
+ if (typeof amount !== "bigint") {
23298
+ throw new SymmioSDKError(
23299
+ `${name} must be a bigint, got ${amount === void 0 ? "undefined" : typeof amount} (${amount})`,
23300
+ "INVALID_AMOUNT"
23301
+ );
23302
+ }
23500
23303
  if (amount <= 0n) {
23501
23304
  throw new SymmioSDKError(
23502
23305
  `${name} must be a positive amount, got ${amount}`,
@@ -23522,6 +23325,12 @@ function validateDeadline(deadline) {
23522
23325
  }
23523
23326
  }
23524
23327
  function validateQuantity(quantity) {
23328
+ if (typeof quantity !== "bigint") {
23329
+ throw new SymmioSDKError(
23330
+ `Quantity must be a bigint, got ${quantity === void 0 ? "undefined" : typeof quantity} (${quantity})`,
23331
+ "INVALID_QUANTITY"
23332
+ );
23333
+ }
23525
23334
  if (quantity <= 0n) {
23526
23335
  throw new SymmioSDKError(
23527
23336
  `Quantity must be positive, got ${quantity}`,
@@ -23861,149 +23670,27 @@ async function depositAndAllocate(walletClient, publicClient, multiAccount, para
23861
23670
  // src/actions/withdraw.ts
23862
23671
  var withdraw_exports = {};
23863
23672
  __export(withdraw_exports, {
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
23673
+ prepareWithdraw: () => prepareWithdraw,
23674
+ withdraw: () => withdraw
23873
23675
  });
23874
- function encodeCall(abi, functionName, args) {
23875
- return viem.encodeFunctionData({
23876
- abi,
23877
- functionName,
23878
- args
23879
- });
23880
- }
23881
- function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
23676
+ function prepareWithdraw(multiAccount, account, params) {
23677
+ validateAmount(params.amount, "withdraw amount");
23678
+ validateAddress(params.account, "account");
23882
23679
  const data = viem.encodeFunctionData({
23883
- abi: accountDiamondAbi,
23884
- functionName: "_call",
23885
- args: [subAccount, callDatas]
23886
- });
23887
- return {
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
23913
- };
23914
- }
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]
23680
+ abi: MultiAccountABI,
23681
+ functionName: "withdrawFromAccount",
23682
+ args: [params.account, params.amount]
23973
23683
  });
23974
- const proxy = wrapInProxyCall(MultiAccountABI, subAccount, [innerData]);
23975
23684
  return {
23976
- functionName: "_call",
23977
- args: proxy.args,
23978
- config: { account, to: multiAccount, data: proxy.data, value: 0n }
23685
+ functionName: "withdrawFromAccount",
23686
+ args: [params.account, params.amount],
23687
+ config: { account, to: multiAccount, data, value: 0n }
23979
23688
  };
23980
23689
  }
23981
- async function initiateWithdraw(walletClient, publicClient, multiAccount, subAccount, params) {
23982
- const account = walletClient.account?.address;
23983
- if (!account) throw new Error("Wallet client has no account");
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) {
23690
+ async function withdraw(walletClient, publicClient, multiAccount, params) {
23993
23691
  const account = walletClient.account?.address;
23994
23692
  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);
23693
+ const prepared = prepareWithdraw(multiAccount, account, params);
24007
23694
  const gas = await publicClient.estimateGas(prepared.config);
24008
23695
  return walletClient.sendTransaction({
24009
23696
  ...prepared.config,
@@ -24022,6 +23709,27 @@ __export(allocate_exports, {
24022
23709
  prepareDeallocate: () => prepareDeallocate,
24023
23710
  prepareInternalTransfer: () => prepareInternalTransfer
24024
23711
  });
23712
+ function encodeCall(abi, functionName, args) {
23713
+ return viem.encodeFunctionData({
23714
+ abi,
23715
+ functionName,
23716
+ args
23717
+ });
23718
+ }
23719
+ function wrapInProxyCall(accountDiamondAbi, subAccount, callDatas) {
23720
+ const data = viem.encodeFunctionData({
23721
+ abi: accountDiamondAbi,
23722
+ functionName: "_call",
23723
+ args: [subAccount, callDatas]
23724
+ });
23725
+ return {
23726
+ functionName: "_call",
23727
+ args: [subAccount, callDatas],
23728
+ data
23729
+ };
23730
+ }
23731
+
23732
+ // src/actions/allocate.ts
24025
23733
  function prepareAllocate(multiAccount, account, subAccount, params) {
24026
23734
  validateAmount(params.amount, "allocate amount");
24027
23735
  const innerData = viem.encodeFunctionData({
@@ -25220,8 +24928,8 @@ function computeSymmNetDeposited(totals, decimals = 6) {
25220
24928
  return "0";
25221
24929
  }
25222
24930
  const deposit2 = parseRawCollateralUnits(totals.deposit);
25223
- const withdraw = parseRawCollateralUnits(totals.withdraw);
25224
- const value = deposit2 - withdraw;
24931
+ const withdraw2 = parseRawCollateralUnits(totals.withdraw);
24932
+ const value = deposit2 - withdraw2;
25225
24933
  const negative = value < 0n;
25226
24934
  const absolute = negative ? -value : value;
25227
24935
  const scale = 10n ** BigInt(decimals);
@@ -25397,7 +25105,6 @@ exports.DEFAULT_PRECISION = DEFAULT_PRECISION;
25397
25105
  exports.ERC20ABI = ERC20ABI;
25398
25106
  exports.FALLBACK_CHAIN_ID = FALLBACK_CHAIN_ID;
25399
25107
  exports.InstantCloseStatus = InstantCloseStatus;
25400
- exports.InstantWithdrawStatus = InstantWithdrawStatus;
25401
25108
  exports.LIMIT_ORDER_DEADLINE = LIMIT_ORDER_DEADLINE;
25402
25109
  exports.LiquidationStatus = LiquidationStatus;
25403
25110
  exports.MARKET_ORDER_DEADLINE = MARKET_ORDER_DEADLINE;
@@ -25422,10 +25129,6 @@ exports.SupportedChainId = SupportedChainId;
25422
25129
  exports.SymmioDiamondABI = SymmioDiamondABI;
25423
25130
  exports.SymmioSDKError = SymmioSDKError;
25424
25131
  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;
25429
25132
  exports.accountActions = account_exports;
25430
25133
  exports.adminActions = admin_exports;
25431
25134
  exports.allocateActions = allocate_exports;