@0xmonaco/core 1.1.7 → 1.1.9
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/api/fees/api.d.ts +2 -0
- package/dist/api/fees/api.js +2 -0
- package/dist/api/rfq/api.d.ts +7 -1
- package/dist/api/rfq/api.js +16 -1
- package/dist/api/sweeper/api.d.ts +109 -1
- package/dist/api/sweeper/api.js +225 -1
- package/dist/api/sweeper/hypercore.d.ts +103 -0
- package/dist/api/sweeper/hypercore.js +357 -0
- package/dist/api/sweeper/hyperevm.d.ts +50 -0
- package/dist/api/sweeper/hyperevm.js +282 -0
- package/dist/api/vault/api.d.ts +28 -0
- package/dist/api/vault/api.js +136 -42
- package/dist/coverage.d.ts +1 -0
- package/dist/coverage.js +1 -0
- package/dist/errors/errors.d.ts +44 -0
- package/dist/errors/errors.js +69 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/sdk.js +4 -0
- package/package.json +3 -3
package/dist/errors/errors.js
CHANGED
|
@@ -673,6 +673,14 @@ function getErrorSuggestion(statusCode, message, responseBody) {
|
|
|
673
673
|
retryable: false,
|
|
674
674
|
};
|
|
675
675
|
}
|
|
676
|
+
// A transfer stopped partway: its first moves stand, and sending it again would
|
|
677
|
+
// move the money again. Check BEFORE the generic 409.
|
|
678
|
+
if (responseBody?.code === "COLLATERAL_TRANSFER_STOPPED_PARTWAY") {
|
|
679
|
+
return {
|
|
680
|
+
suggestion: "The transfer stopped partway and the amount is where this message says. Do not retry it: move the amount from there.",
|
|
681
|
+
retryable: false,
|
|
682
|
+
};
|
|
683
|
+
}
|
|
676
684
|
// Conflict (409) - check BEFORE 500+ to avoid being shadowed
|
|
677
685
|
if (statusCode === StatusCodes.CONFLICT) {
|
|
678
686
|
return {
|
|
@@ -804,6 +812,64 @@ export class ContractError extends MonacoCoreError {
|
|
|
804
812
|
};
|
|
805
813
|
}
|
|
806
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
* Error thrown when the vault refuses a withdrawal because it exceeds the
|
|
817
|
+
* token's withdrawal rate limit (the contract's `WithdrawalRateLimited`
|
|
818
|
+
* revert).
|
|
819
|
+
*
|
|
820
|
+
* The vault caps how much withdrawals against recently confirmed roots can pay
|
|
821
|
+
* out at once, per token, and refills that allowance over time. A refused
|
|
822
|
+
* withdrawal is not lost: its balance is already debited and its index stays
|
|
823
|
+
* valid. Retry it with `sdk.vault.retryWithdrawal(withdrawalIndex)` once the
|
|
824
|
+
* limit has refilled, or once the withdrawal's root is a day old, when the limit
|
|
825
|
+
* no longer applies to it.
|
|
826
|
+
*
|
|
827
|
+
* @example
|
|
828
|
+
* ```typescript
|
|
829
|
+
* try {
|
|
830
|
+
* await sdk.vault.withdraw(assetId, amount);
|
|
831
|
+
* } catch (error) {
|
|
832
|
+
* if (error instanceof WithdrawalRateLimitedError) {
|
|
833
|
+
* // Keep error.withdrawalIndex and retry later.
|
|
834
|
+
* console.log(`${error.available} of ${error.amount} can be paid out now`);
|
|
835
|
+
* }
|
|
836
|
+
* }
|
|
837
|
+
* ```
|
|
838
|
+
*/
|
|
839
|
+
export class WithdrawalRateLimitedError extends ContractError {
|
|
840
|
+
/** The refused withdrawal's index; pass it to `retryWithdrawal`. */
|
|
841
|
+
withdrawalIndex;
|
|
842
|
+
/** The limited token's address (WSEI's for native withdrawals). */
|
|
843
|
+
token;
|
|
844
|
+
/** What the limit lets withdrawals pay out now, in the token's raw units. */
|
|
845
|
+
available;
|
|
846
|
+
/** The withdrawal's amount, in the token's raw units. */
|
|
847
|
+
amount;
|
|
848
|
+
constructor(withdrawalIndex, details) {
|
|
849
|
+
super(`Withdrawal ${withdrawalIndex} exceeds the vault's withdrawal rate limit for token ${details.token}: ` +
|
|
850
|
+
`${details.available} of its ${details.amount} can be paid out now. Its balance stays debited and its index stays valid: ` +
|
|
851
|
+
`retry with retryWithdrawal(${withdrawalIndex}) once the limit refills, or once the withdrawal's root is a day old.`, {
|
|
852
|
+
revertReason: "WithdrawalRateLimited",
|
|
853
|
+
contractAddress: details.contractAddress,
|
|
854
|
+
transactionHash: details.transactionHash,
|
|
855
|
+
cause: details.cause,
|
|
856
|
+
});
|
|
857
|
+
this.retryable = true;
|
|
858
|
+
this.withdrawalIndex = withdrawalIndex;
|
|
859
|
+
this.token = details.token;
|
|
860
|
+
this.available = details.available;
|
|
861
|
+
this.amount = details.amount;
|
|
862
|
+
}
|
|
863
|
+
toJSON() {
|
|
864
|
+
return {
|
|
865
|
+
...super.toJSON(),
|
|
866
|
+
withdrawalIndex: this.withdrawalIndex,
|
|
867
|
+
token: this.token,
|
|
868
|
+
available: this.available.toString(),
|
|
869
|
+
amount: this.amount.toString(),
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
}
|
|
807
873
|
/**
|
|
808
874
|
* Get suggestions for common contract errors
|
|
809
875
|
*/
|
|
@@ -812,6 +878,9 @@ function getContractErrorSuggestion(revertReason) {
|
|
|
812
878
|
return "Smart contract execution failed. Check transaction parameters and try again.";
|
|
813
879
|
}
|
|
814
880
|
const reason = revertReason.toLowerCase();
|
|
881
|
+
if (reason.includes("withdrawalratelimited")) {
|
|
882
|
+
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.";
|
|
883
|
+
}
|
|
815
884
|
if (reason.includes("insufficient allowance")) {
|
|
816
885
|
return "Token allowance is insufficient. Call sdk.vault.approve() to increase the token allowance for the vault contract.";
|
|
817
886
|
}
|
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.
|
|
3
|
+
"version": "1.1.9",
|
|
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.
|
|
23
|
-
"@0xmonaco/types": "1.1.
|
|
22
|
+
"@0xmonaco/contracts": "1.1.9",
|
|
23
|
+
"@0xmonaco/types": "1.1.9",
|
|
24
24
|
"@noble/curves": "^2.4.0",
|
|
25
25
|
"@noble/hashes": "^2.4.0",
|
|
26
26
|
"http-status-codes": "^2.3.0"
|