@cubee_ee/sdk 0.2.1 → 0.2.3
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/clients/CubicPoolClient.d.ts.map +1 -1
- package/dist/clients/CubicPoolClient.js +11 -6
- package/dist/clients/CubicPoolClient.js.map +1 -1
- package/dist/config/networks.js +2 -2
- package/dist/config/networks.js.map +1 -1
- package/dist/idl/cubic_pool.json +110 -1097
- package/dist/idl/index.d.ts +2 -242
- package/dist/idl/index.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +8 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +57 -17
- package/dist/utils/errors.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/CubicPoolClient.ts +19 -6
- package/src/config/networks.ts +8 -8
- package/src/idl/cubic_pool.json +110 -1097
- package/src/utils/errors.ts +60 -17
package/src/utils/errors.ts
CHANGED
|
@@ -1,23 +1,61 @@
|
|
|
1
|
+
import cubicPoolIdl from "../idl/cubic_pool.json";
|
|
1
2
|
import { SdkError, SdkErrorCode } from "../types/result";
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
const ANCHOR_NAME_TO_SDK: Record<string, SdkErrorCode> = {
|
|
5
|
+
InvalidTokenCount: "invalid_input",
|
|
6
|
+
InvalidTokenIndex: "invalid_input",
|
|
7
|
+
InvalidWeights: "invalid_input",
|
|
8
|
+
InvalidVirtualBalances: "invalid_input",
|
|
9
|
+
InsufficientLiquidity: "insufficient_funds",
|
|
10
|
+
SlippageExceeded: "slippage_exceeded",
|
|
11
|
+
InvalidAmounts: "invalid_input",
|
|
12
|
+
InsufficientBptOut: "slippage_exceeded",
|
|
13
|
+
InsufficientTokensOut: "slippage_exceeded",
|
|
14
|
+
FeeRateMaxExceeded: "invalid_input",
|
|
15
|
+
ProtocolFeeRateMaxExceeded: "invalid_input",
|
|
16
|
+
MathOverflow: "math_overflow",
|
|
17
|
+
MathUnderflow: "math_overflow",
|
|
18
|
+
DivisionByZero: "math_overflow",
|
|
19
|
+
TokenMintMismatch: "invalid_input",
|
|
20
|
+
InvalidTokenDecimals: "invalid_input",
|
|
21
|
+
AmountOutExceedsBalance: "invalid_input",
|
|
22
|
+
InvalidBptAmount: "invalid_input",
|
|
23
|
+
Unauthorized: "invalid_input",
|
|
24
|
+
InvalidMint: "invalid_input",
|
|
25
|
+
PoolDisabled: "pool_disabled",
|
|
26
|
+
SwapsDisabled: "swaps_disabled",
|
|
27
|
+
PoolMustBeDisabled: "invalid_input",
|
|
28
|
+
ZeroAmount: "invalid_input",
|
|
29
|
+
ZeroFeeAmount: "invalid_input",
|
|
30
|
+
BannedExtension: "invalid_input",
|
|
31
|
+
TokenProgramMismatch: "invalid_input",
|
|
32
|
+
UserTokenAccountOwnerMismatch: "invalid_input",
|
|
33
|
+
InitialLiquidityTooSmall: "invalid_input",
|
|
34
|
+
InvalidTokenProgram: "invalid_input",
|
|
35
|
+
InvalidVault: "invalid_input",
|
|
36
|
+
InvalidSourceOwner: "invalid_input",
|
|
37
|
+
WouldBreakRentExempt: "invalid_input",
|
|
38
|
+
PoolAdminDisabled: "invalid_input",
|
|
39
|
+
ProtocolAdminUnset: "invalid_input",
|
|
40
|
+
NoPendingAdmin: "invalid_input",
|
|
41
|
+
NotPendingAdmin: "invalid_input",
|
|
42
|
+
InvalidPendingAdmin: "invalid_input",
|
|
43
|
+
ProtocolAdminNotTreasury: "invalid_input",
|
|
19
44
|
};
|
|
20
45
|
|
|
46
|
+
const CONTRACT_ERROR_MAP: Record<number, { code: SdkErrorCode; message: string }> =
|
|
47
|
+
Object.fromEntries(
|
|
48
|
+
(cubicPoolIdl.errors as Array<{ code: number; name: string; msg: string }>).map(
|
|
49
|
+
(anchorError) => [
|
|
50
|
+
anchorError.code,
|
|
51
|
+
{
|
|
52
|
+
code: ANCHOR_NAME_TO_SDK[anchorError.name] ?? "invalid_input",
|
|
53
|
+
message: anchorError.msg,
|
|
54
|
+
},
|
|
55
|
+
]
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
|
|
21
59
|
/**
|
|
22
60
|
* Convert a raw error (possibly from Anchor, web3.js, or fetch) into a
|
|
23
61
|
* cleanly-typed SdkError. Used by safeCall wrappers so callers always
|
|
@@ -39,7 +77,7 @@ export function toSdkError(cause: unknown): SdkError {
|
|
|
39
77
|
return { code: "rpc_timeout", humanMessage: "RPC timed out", cause };
|
|
40
78
|
}
|
|
41
79
|
if (/429|rate limit/i.test(msg)) {
|
|
42
|
-
return { code: "rpc_rate_limited", humanMessage: "RPC rate-limited
|
|
80
|
+
return { code: "rpc_rate_limited", humanMessage: "RPC rate-limited - slow down", cause };
|
|
43
81
|
}
|
|
44
82
|
if (/fetch failed|ECONNREFUSED|ENOTFOUND|Proxy error|-32056|-32052|403/i.test(msg)) {
|
|
45
83
|
return { code: "rpc_unavailable", humanMessage: "RPC endpoint unreachable", cause };
|
|
@@ -76,3 +114,8 @@ function extractErrorCode(msg: string): number | null {
|
|
|
76
114
|
if (dec) return parseInt(dec[1], 10);
|
|
77
115
|
return null;
|
|
78
116
|
}
|
|
117
|
+
|
|
118
|
+
/** @internal Exported for tests */
|
|
119
|
+
export function contractErrorMapForTests(): typeof CONTRACT_ERROR_MAP {
|
|
120
|
+
return CONTRACT_ERROR_MAP;
|
|
121
|
+
}
|