@0xmonaco/core 1.1.6 → 1.1.8

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.
@@ -804,6 +804,64 @@ export class ContractError extends MonacoCoreError {
804
804
  };
805
805
  }
806
806
  }
807
+ /**
808
+ * Error thrown when the vault refuses a withdrawal because it exceeds the
809
+ * token's withdrawal rate limit (the contract's `WithdrawalRateLimited`
810
+ * revert).
811
+ *
812
+ * The vault caps how much withdrawals against recently confirmed roots can pay
813
+ * out at once, per token, and refills that allowance over time. A refused
814
+ * withdrawal is not lost: its balance is already debited and its index stays
815
+ * valid. Retry it with `sdk.vault.retryWithdrawal(withdrawalIndex)` once the
816
+ * limit has refilled, or once the withdrawal's root is a day old, when the limit
817
+ * no longer applies to it.
818
+ *
819
+ * @example
820
+ * ```typescript
821
+ * try {
822
+ * await sdk.vault.withdraw(assetId, amount);
823
+ * } catch (error) {
824
+ * if (error instanceof WithdrawalRateLimitedError) {
825
+ * // Keep error.withdrawalIndex and retry later.
826
+ * console.log(`${error.available} of ${error.amount} can be paid out now`);
827
+ * }
828
+ * }
829
+ * ```
830
+ */
831
+ export class WithdrawalRateLimitedError extends ContractError {
832
+ /** The refused withdrawal's index; pass it to `retryWithdrawal`. */
833
+ withdrawalIndex;
834
+ /** The limited token's address (WSEI's for native withdrawals). */
835
+ token;
836
+ /** What the limit lets withdrawals pay out now, in the token's raw units. */
837
+ available;
838
+ /** The withdrawal's amount, in the token's raw units. */
839
+ amount;
840
+ constructor(withdrawalIndex, details) {
841
+ super(`Withdrawal ${withdrawalIndex} exceeds the vault's withdrawal rate limit for token ${details.token}: ` +
842
+ `${details.available} of its ${details.amount} can be paid out now. Its balance stays debited and its index stays valid: ` +
843
+ `retry with retryWithdrawal(${withdrawalIndex}) once the limit refills, or once the withdrawal's root is a day old.`, {
844
+ revertReason: "WithdrawalRateLimited",
845
+ contractAddress: details.contractAddress,
846
+ transactionHash: details.transactionHash,
847
+ cause: details.cause,
848
+ });
849
+ this.retryable = true;
850
+ this.withdrawalIndex = withdrawalIndex;
851
+ this.token = details.token;
852
+ this.available = details.available;
853
+ this.amount = details.amount;
854
+ }
855
+ toJSON() {
856
+ return {
857
+ ...super.toJSON(),
858
+ withdrawalIndex: this.withdrawalIndex,
859
+ token: this.token,
860
+ available: this.available.toString(),
861
+ amount: this.amount.toString(),
862
+ };
863
+ }
864
+ }
807
865
  /**
808
866
  * Get suggestions for common contract errors
809
867
  */
@@ -812,6 +870,9 @@ function getContractErrorSuggestion(revertReason) {
812
870
  return "Smart contract execution failed. Check transaction parameters and try again.";
813
871
  }
814
872
  const reason = revertReason.toLowerCase();
873
+ if (reason.includes("withdrawalratelimited")) {
874
+ return "The vault's withdrawal rate limit for this token is spent for now. Retry with sdk.vault.retryWithdrawal(withdrawalIndex) once it refills, or once the withdrawal's root is a day old.";
875
+ }
815
876
  if (reason.includes("insufficient allowance")) {
816
877
  return "Token allowance is insufficient. Call sdk.vault.approve() to increase the token allowance for the vault contract.";
817
878
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { createMonacoWebSocket, type MonacoWebSocket, type MonacoWebSocketOptions } from "./api/websocket";
2
- export { APIError, ContractError, InvalidConfigError, InvalidStateError, MonacoCoreError } from "./errors";
2
+ export { APIError, ContractError, InvalidConfigError, InvalidStateError, MonacoCoreError, WithdrawalRateLimitedError } from "./errors";
3
3
  export { resolveApiUrl, resolveWsUrl } from "./networks";
4
4
  export { createMonacoSDK, MonacoSDKImpl as MonacoSDK } from "./sdk";
5
5
  export { ALL_MAGNITUDES, calculateValidMagnitudes, MAX_BUCKETS_ALLOWED, MIN_BUCKETS_ALLOWED, } from "./utils";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { createMonacoWebSocket } from "./api/websocket";
2
- export { APIError, ContractError, InvalidConfigError, InvalidStateError, MonacoCoreError } from "./errors";
2
+ export { APIError, ContractError, InvalidConfigError, InvalidStateError, MonacoCoreError, WithdrawalRateLimitedError } from "./errors";
3
3
  export { resolveApiUrl, resolveWsUrl } from "./networks";
4
4
  export { createMonacoSDK, MonacoSDKImpl as MonacoSDK } from "./sdk";
5
5
  export { ALL_MAGNITUDES, calculateValidMagnitudes, MAX_BUCKETS_ALLOWED, MIN_BUCKETS_ALLOWED, } from "./utils";
package/dist/sdk.js CHANGED
@@ -171,6 +171,9 @@ export class MonacoSDKImpl {
171
171
  this.subAccounts = configureSigning(new SubAccountsAPIImpl(apiUrl));
172
172
  this.faucet = configureSigning(new FaucetAPIImpl(apiUrl));
173
173
  this.sweeper = configureSigning(new SweeperAPIImpl(apiUrl));
174
+ if (this.walletClient) {
175
+ this.sweeper.setWalletClient(this.walletClient);
176
+ }
174
177
  this.managedMarkets = configureSigning(new ManagedMarketsAPIImpl(apiUrl));
175
178
  this.pulse = configureSigning(new PulseAPIImpl(apiUrl));
176
179
  this.compliance = configureSigning(new ComplianceAPIImpl(apiUrl));
@@ -377,6 +380,7 @@ export class MonacoSDKImpl {
377
380
  // Update APIs that depend on wallet client
378
381
  this.auth.setWalletClient(walletClient);
379
382
  this.vault.setWalletClient(walletClient);
383
+ this.sweeper.setWalletClient(walletClient);
380
384
  }
381
385
  /**
382
386
  * Get the current account address
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/core",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "type": "module",
5
5
  "homepage": "https://docs.0xmonaco.com/sdk/typescript",
6
6
  "main": "./dist/index.js",
@@ -19,8 +19,8 @@
19
19
  "viem": "^2.45.2"
20
20
  },
21
21
  "dependencies": {
22
- "@0xmonaco/contracts": "1.1.6",
23
- "@0xmonaco/types": "1.1.6",
22
+ "@0xmonaco/contracts": "1.1.8",
23
+ "@0xmonaco/types": "1.1.8",
24
24
  "@noble/curves": "^2.4.0",
25
25
  "@noble/hashes": "^2.4.0",
26
26
  "http-status-codes": "^2.3.0"