@cubee_ee/sdk 0.1.5 → 0.1.7
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/README.md +15 -2
- package/dist/clients/CubeBackendClient.d.ts +25 -1
- package/dist/clients/CubeBackendClient.d.ts.map +1 -1
- package/dist/clients/CubeBackendClient.js +8 -3
- package/dist/clients/CubeBackendClient.js.map +1 -1
- package/dist/clients/CubicPoolClient.d.ts +5 -2
- package/dist/clients/CubicPoolClient.d.ts.map +1 -1
- package/dist/clients/CubicPoolClient.js +6 -3
- package/dist/clients/CubicPoolClient.js.map +1 -1
- package/dist/clients/RpcClient.d.ts +18 -2
- package/dist/clients/RpcClient.d.ts.map +1 -1
- package/dist/clients/RpcClient.js +85 -14
- package/dist/clients/RpcClient.js.map +1 -1
- package/dist/clients/SingleTokenDepositClient.d.ts +4 -1
- package/dist/clients/SingleTokenDepositClient.d.ts.map +1 -1
- package/dist/clients/SingleTokenDepositClient.js +2 -1
- package/dist/clients/SingleTokenDepositClient.js.map +1 -1
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +16 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/networks.d.ts +2 -0
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +11 -1
- package/dist/config/networks.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/errors.js +1 -1
- package/dist/utils/errors.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/CubeBackendClient.ts +41 -5
- package/src/clients/CubicPoolClient.ts +11 -5
- package/src/clients/RpcClient.ts +123 -16
- package/src/clients/SingleTokenDepositClient.ts +10 -2
- package/src/config/index.ts +30 -2
- package/src/config/networks.ts +12 -0
- package/src/index.ts +11 -4
- package/src/utils/errors.ts +1 -1
package/dist/config/networks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_RPC_ENDPOINT = exports.NETWORK_PROGRAMS = void 0;
|
|
3
|
+
exports.DEFAULT_RPC_TIMEOUT_MS = exports.DEFAULT_RPC_ENDPOINTS = exports.DEFAULT_RPC_ENDPOINT = exports.NETWORK_PROGRAMS = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
exports.NETWORK_PROGRAMS = {
|
|
6
6
|
mainnet: {
|
|
@@ -28,4 +28,14 @@ exports.DEFAULT_RPC_ENDPOINT = {
|
|
|
28
28
|
devnet: "https://api.devnet.solana.com",
|
|
29
29
|
localnet: "http://127.0.0.1:8899",
|
|
30
30
|
};
|
|
31
|
+
exports.DEFAULT_RPC_ENDPOINTS = {
|
|
32
|
+
mainnet: [
|
|
33
|
+
"https://api.mainnet-beta.solana.com",
|
|
34
|
+
"https://solana-rpc.publicnode.com",
|
|
35
|
+
"https://solana.api.pocket.network",
|
|
36
|
+
],
|
|
37
|
+
devnet: ["https://api.devnet.solana.com"],
|
|
38
|
+
localnet: ["http://127.0.0.1:8899"],
|
|
39
|
+
};
|
|
40
|
+
exports.DEFAULT_RPC_TIMEOUT_MS = 2000;
|
|
31
41
|
//# sourceMappingURL=networks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networks.js","sourceRoot":"","sources":["../../src/config/networks.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAU/B,QAAA,gBAAgB,GAAqC;IAChE,OAAO,EAAE;QACP,SAAS,EAAE,IAAI,mBAAS,CAAC,8CAA8C,CAAC;QACxE,0EAA0E;QAC1E,qEAAqE;QACrE,wEAAwE;QACxE,oCAAoC;QACpC,oBAAoB,EAAE,IAAI,mBAAS,CACjC,8CAA8C,CAC/C;QACD,aAAa,EAAE,IAAI,mBAAS,CAC1B,8CAA8C,CAC/C;KACF;IACD,MAA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AA,oBAAoB,GAA4B;IAC3D,OAAO,EAAE,qCAAqC;IAC9C,MAAM,EAAE,+BAA+B;IACvC,QAAQ,EAAE,uBAAuB;CAClC,CAAC;AAEW,QAAA,qBAAqB,GAA8B;IAC9D,OAAO,EAAE;QACP,qCAAqC;QACrC,mCAAmC;QACnC,mCAAmC;KACpC;IACD,MAAM,EAAE,CAAC,+BAA+B,CAAC;IACzC,QAAQ,EAAE,CAAC,uBAAuB,CAAC;CACpC,CAAC;AAEW,QAAA,sBAAsB,GAAG,IAAK,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @cubee_ee/sdk — client library for the Cubic Pool AMM on Solana.
|
|
3
3
|
*
|
|
4
4
|
* Entry point barrel. Most consumers will want to import from this root:
|
|
5
5
|
*
|
|
6
6
|
* ```ts
|
|
7
|
-
* import { CubicPoolClient, CubeBackendClient, getConfig } from "@
|
|
7
|
+
* import { CubicPoolClient, CubeBackendClient, getConfig } from "@cubee_ee/sdk";
|
|
8
8
|
*
|
|
9
9
|
* const cfg = getConfig("mainnet", { backendEndpoint: "https://api.cube.fi" });
|
|
10
|
-
* const pool = new CubicPoolClient({ config: cfg, poolAddress
|
|
10
|
+
* const pool = new CubicPoolClient({ config: cfg, poolAddress });
|
|
11
11
|
* const info = await pool.sync();
|
|
12
12
|
* if (info.ok) console.log(info.data.tokens.map(t => t.metadata?.symbol));
|
|
13
13
|
* ```
|
|
@@ -20,7 +20,7 @@ export * from "./parsers";
|
|
|
20
20
|
export * from "./clients";
|
|
21
21
|
export * from "./idl";
|
|
22
22
|
export { getConfig, programId, CUBIC_POOL_SEED, BPT_MINT_SEED, STLD_HELPER_SEED, TREASURY_SEED, WEIGHT_SCALE, MIN_WEIGHT, MAX_WEIGHT, MIN_TOKENS, MAX_TOKENS, BPT_DECIMALS, SWAP_FEE_PRECISION, PROTOCOL_FEE_PRECISION, MAX_SWAP_FEE_RATE, MAX_PROTOCOL_FEE_RATE, MINIMUM_INITIAL_BPT, SLIPPAGE_PRECISION, MIN_SLIPPAGE_HBPS, } from "./config";
|
|
23
|
-
export { NETWORK_PROGRAMS, DEFAULT_RPC_ENDPOINT } from "./config/networks";
|
|
23
|
+
export { NETWORK_PROGRAMS, DEFAULT_RPC_ENDPOINT, DEFAULT_RPC_ENDPOINTS, DEFAULT_RPC_TIMEOUT_MS, } from "./config/networks";
|
|
24
24
|
export { KNOWN_TOKENS, resolveKnownToken } from "./config/tokens";
|
|
25
25
|
export { ok, err } from "./types/result";
|
|
26
26
|
export { ONE, mulDown, mulUp, divDown, divUp, complement, weightToFp, } from "./math/fixedPoint";
|
|
@@ -44,5 +44,5 @@ export type { CubeConfig, CubeConfigOverrides, ProgramIdKind, Network, NetworkPr
|
|
|
44
44
|
export type { SdkResult, SdkError, SdkErrorCode, PoolTokenInfo, PoolInfo, PoolSummary, SwapParams, SwapQuote, AddLiquidityParams, RemoveLiquidityParams, SingleTokenDepositParams, SingleTokenDepositQuote, BuiltTx, DeployPoolParams, CubicPoolEvent, PoolInitializedEvent, SwapEvent, LiquidityAddedEvent, LiquidityRemovedEvent, ProtocolFeesCollectedEvent, PoolEnabledUpdatedEvent, SwapsEnabledUpdatedEvent, SingleTokenDepositEvent, UnknownEvent, } from "./types";
|
|
45
45
|
export type { AllocationResult, } from "./math/singleToken";
|
|
46
46
|
export type { RawPoolAccount, RawMintAccount, } from "./parsers";
|
|
47
|
-
export type { RpcClientParams, CubeBackendClientParams, StatsKind, StatsWindow, StatsSeriesPoint, StatsSeries, PriceMap, LeaderboardEntry, LeaderboardResponse, LeaderboardUserStats, XpAccrualHistoryEntry, XpAccrualHistoryResponse, EpochHistoryEntry, LeaderboardEpochResponse, CubicPoolClientParams, SingleTokenDepositClientParams, PoolFactoryClientParams, InitializeConfigParams, } from "./clients";
|
|
47
|
+
export type { RpcClientParams, CubeBackendClientParams, StatsKind, StatsWindow, StatsSeriesPoint, StatsSeries, PriceMap, LeaderboardEntry, LeaderboardResponse, LeaderboardUserStats, XpAccrualHistoryEntry, XpAccrualHistoryResponse, EpochHistoryEntry, LeaderboardEpochResponse, SwapRouteEntry, SwapRouteResponse, CubicPoolClientParams, SingleTokenDepositClientParams, PoolFactoryClientParams, InitializeConfigParams, } from "./clients";
|
|
48
48
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AAItB,OAAO,EACL,SAAS,EACT,SAAS,EACT,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAClB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AAItB,OAAO,EACL,SAAS,EACT,SAAS,EACT,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EAC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CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,18 +17,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
21
|
-
exports.BorshReader = exports.parseCubicPoolEvents = exports.decodeMintAccount = exports.POOL_DISCRIMINATOR_LEN = exports.decodePoolAccount = exports.buildDeployPoolTx = exports.buildInitializeCubicPoolIx = exports.buildInitializeConfigIx = exports.buildSingleTokenDepositTx = exports.buildSingleTokenDepositIx = exports.buildRemoveLiquidityTx = exports.buildRemoveLiquidityIx = exports.buildAddLiquidityTx = exports.buildAddLiquidityIx = exports.buildSwapTx = exports.buildSwapIx = exports.AdminClient = exports.PoolFactoryClient = exports.SingleTokenDepositClient = exports.CubicPoolClient = void 0;
|
|
20
|
+
exports.priceImpactHbps = exports.lpBalances = exports.applySwapFee = exports.applySlippage = exports.computeTwoTokenOptimalAllocations = exports.computeAllocations = exports.capDepositAmountsToLpRatio = exports.calcSpotPrice = exports.validateWeights = exports.calcSpotOut = exports.calcTokensOutGivenBptIn = exports.calcBptOutGivenExactTokensIn = exports.calcOutGivenIn = exports.powFp = exports.expFp = exports.lnFp = exports.weightToFp = exports.complement = exports.divUp = exports.divDown = exports.mulUp = exports.mulDown = exports.ONE = exports.err = exports.ok = exports.resolveKnownToken = exports.KNOWN_TOKENS = exports.DEFAULT_RPC_TIMEOUT_MS = exports.DEFAULT_RPC_ENDPOINTS = exports.DEFAULT_RPC_ENDPOINT = exports.NETWORK_PROGRAMS = exports.MIN_SLIPPAGE_HBPS = exports.SLIPPAGE_PRECISION = exports.MINIMUM_INITIAL_BPT = exports.MAX_PROTOCOL_FEE_RATE = exports.MAX_SWAP_FEE_RATE = exports.PROTOCOL_FEE_PRECISION = exports.SWAP_FEE_PRECISION = exports.BPT_DECIMALS = exports.MAX_TOKENS = exports.MIN_TOKENS = exports.MAX_WEIGHT = exports.MIN_WEIGHT = exports.WEIGHT_SCALE = exports.TREASURY_SEED = exports.STLD_HELPER_SEED = exports.BPT_MINT_SEED = exports.CUBIC_POOL_SEED = exports.programId = exports.getConfig = void 0;
|
|
21
|
+
exports.BorshReader = exports.parseCubicPoolEvents = exports.decodeMintAccount = exports.POOL_DISCRIMINATOR_LEN = exports.decodePoolAccount = exports.buildDeployPoolTx = exports.buildInitializeCubicPoolIx = exports.buildInitializeConfigIx = exports.buildSingleTokenDepositTx = exports.buildSingleTokenDepositIx = exports.buildRemoveLiquidityTx = exports.buildRemoveLiquidityIx = exports.buildAddLiquidityTx = exports.buildAddLiquidityIx = exports.buildSwapTx = exports.buildSwapIx = exports.AdminClient = exports.PoolFactoryClient = exports.SingleTokenDepositClient = exports.CubicPoolClient = exports.CubeBackendClient = exports.RpcClient = void 0;
|
|
22
22
|
/**
|
|
23
|
-
* @
|
|
23
|
+
* @cubee_ee/sdk — client library for the Cubic Pool AMM on Solana.
|
|
24
24
|
*
|
|
25
25
|
* Entry point barrel. Most consumers will want to import from this root:
|
|
26
26
|
*
|
|
27
27
|
* ```ts
|
|
28
|
-
* import { CubicPoolClient, CubeBackendClient, getConfig } from "@
|
|
28
|
+
* import { CubicPoolClient, CubeBackendClient, getConfig } from "@cubee_ee/sdk";
|
|
29
29
|
*
|
|
30
30
|
* const cfg = getConfig("mainnet", { backendEndpoint: "https://api.cube.fi" });
|
|
31
|
-
* const pool = new CubicPoolClient({ config: cfg, poolAddress
|
|
31
|
+
* const pool = new CubicPoolClient({ config: cfg, poolAddress });
|
|
32
32
|
* const info = await pool.sync();
|
|
33
33
|
* if (info.ok) console.log(info.data.tokens.map(t => t.metadata?.symbol));
|
|
34
34
|
* ```
|
|
@@ -65,6 +65,8 @@ Object.defineProperty(exports, "MIN_SLIPPAGE_HBPS", { enumerable: true, get: fun
|
|
|
65
65
|
var networks_1 = require("./config/networks");
|
|
66
66
|
Object.defineProperty(exports, "NETWORK_PROGRAMS", { enumerable: true, get: function () { return networks_1.NETWORK_PROGRAMS; } });
|
|
67
67
|
Object.defineProperty(exports, "DEFAULT_RPC_ENDPOINT", { enumerable: true, get: function () { return networks_1.DEFAULT_RPC_ENDPOINT; } });
|
|
68
|
+
Object.defineProperty(exports, "DEFAULT_RPC_ENDPOINTS", { enumerable: true, get: function () { return networks_1.DEFAULT_RPC_ENDPOINTS; } });
|
|
69
|
+
Object.defineProperty(exports, "DEFAULT_RPC_TIMEOUT_MS", { enumerable: true, get: function () { return networks_1.DEFAULT_RPC_TIMEOUT_MS; } });
|
|
68
70
|
var tokens_1 = require("./config/tokens");
|
|
69
71
|
Object.defineProperty(exports, "KNOWN_TOKENS", { enumerable: true, get: function () { return tokens_1.KNOWN_TOKENS; } });
|
|
70
72
|
Object.defineProperty(exports, "resolveKnownToken", { enumerable: true, get: function () { return tokens_1.resolveKnownToken; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,iDAAiD;AACjD,sCAAsC;;;;;;;;;;;;;;;;;;AAEtC;;;;;;;;;;;;;GAaG;AAEH,2CAAyB;AACzB,0CAAwB;AACxB,0CAAwB;AACxB,yCAAuB;AACvB,4CAA0B;AAC1B,4CAA0B;AAC1B,wCAAsB;AAEtB,+EAA+E;AAC/E,yEAAyE;AACzE,mCAoBkB;AAnBhB,mGAAA,SAAS,OAAA;AACT,mGAAA,SAAS,OAAA;AACT,yGAAA,eAAe,OAAA;AACf,uGAAA,aAAa,OAAA;AACb,0GAAA,gBAAgB,OAAA;AAChB,uGAAA,aAAa,OAAA;AACb,sGAAA,YAAY,OAAA;AACZ,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,sGAAA,Y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AuB,OAAA;AACvB,yHAAA,0BAA0B,OAAA;AAC1B,gHAAA,iBAAiB,OAAA;AAEnB,qDAAkF;AAAzE,gHAAA,iBAAiB,OAAA;AAAE,qHAAA,sBAAsB,OAAA;AAClD,qDAA0D;AAAjD,gHAAA,iBAAiB,OAAA;AAC1B,2CAAwD;AAA/C,8GAAA,oBAAoB,OAAA;AAC7B,yCAA8C;AAArC,oGAAA,WAAW,OAAA"}
|
package/dist/utils/errors.js
CHANGED
|
@@ -41,7 +41,7 @@ function toSdkError(cause) {
|
|
|
41
41
|
if (/429|rate limit/i.test(msg)) {
|
|
42
42
|
return { code: "rpc_rate_limited", humanMessage: "RPC rate-limited — slow down", cause };
|
|
43
43
|
}
|
|
44
|
-
if (/fetch failed|ECONNREFUSED|ENOTFOUND/i.test(msg)) {
|
|
44
|
+
if (/fetch failed|ECONNREFUSED|ENOTFOUND|Proxy error|-32056|-32052|403/i.test(msg)) {
|
|
45
45
|
return { code: "rpc_unavailable", humanMessage: "RPC endpoint unreachable", cause };
|
|
46
46
|
}
|
|
47
47
|
if (/Account does not exist|account not found/i.test(msg)) {
|
package/dist/utils/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":";;AAyBA,gCA4BC;AAnDD,MAAM,kBAAkB,GAA4D;IAClF,iEAAiE;IACjE,IAAI,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,qBAAqB,EAAE;IAC/D,IAAI,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,qBAAqB,EAAE;IAC/D,IAAI,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,qCAAqC,EAAE;IAC/E,IAAI,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,0BAA0B,EAAE;IACpE,IAAI,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,OAAO,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,EAAE,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -36,6 +36,34 @@ export interface PriceMap {
|
|
|
36
36
|
[mint: string]: number;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
// ── Swap route types ──
|
|
40
|
+
|
|
41
|
+
export interface SwapRouteEntry {
|
|
42
|
+
poolAddress: string;
|
|
43
|
+
poolName: string;
|
|
44
|
+
amountIn: string;
|
|
45
|
+
expectedOut: string;
|
|
46
|
+
percentage: number;
|
|
47
|
+
swapFee: number;
|
|
48
|
+
tokenProgramIn: string;
|
|
49
|
+
tokenProgramOut: string;
|
|
50
|
+
tokenInIndex: number;
|
|
51
|
+
tokenOutIndex: number;
|
|
52
|
+
vaultIn: string | null;
|
|
53
|
+
vaultOut: string | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SwapRouteResponse {
|
|
57
|
+
routes: SwapRouteEntry[];
|
|
58
|
+
totalAmountIn: string;
|
|
59
|
+
totalExpectedOut: string;
|
|
60
|
+
effectivePrice: number;
|
|
61
|
+
priceImpact: number;
|
|
62
|
+
spotPrice: number;
|
|
63
|
+
/** Estimated XP earned from this swap (based on LP fees generated) */
|
|
64
|
+
estimatedXp: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
39
67
|
// ── Leaderboard types ──
|
|
40
68
|
|
|
41
69
|
export interface LeaderboardEntry {
|
|
@@ -180,13 +208,21 @@ export class CubeBackendClient {
|
|
|
180
208
|
return this.getDataField<T>(`/api/pools/${addr}/transactions?${qs.toString()}`);
|
|
181
209
|
}
|
|
182
210
|
|
|
183
|
-
getSwapRoute
|
|
211
|
+
getSwapRoute(
|
|
184
212
|
tokenIn: string,
|
|
185
213
|
tokenOut: string,
|
|
186
|
-
amountIn: string
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
214
|
+
amountIn: string,
|
|
215
|
+
decimalsIn: number = 9,
|
|
216
|
+
): Promise<SdkResult<SwapRouteResponse>> {
|
|
217
|
+
const qs = new URLSearchParams({
|
|
218
|
+
tokenIn,
|
|
219
|
+
tokenOut,
|
|
220
|
+
amountIn,
|
|
221
|
+
decimalsIn: String(decimalsIn),
|
|
222
|
+
});
|
|
223
|
+
return this.getDataField<SwapRouteResponse>(
|
|
224
|
+
`/api/pools/swap-route?${qs.toString()}`,
|
|
225
|
+
);
|
|
190
226
|
}
|
|
191
227
|
|
|
192
228
|
// ── Leaderboard ──
|
|
@@ -37,12 +37,15 @@ import { SingleTokenDepositClient } from "./SingleTokenDepositClient";
|
|
|
37
37
|
export interface CubicPoolClientParams {
|
|
38
38
|
config: CubeConfig;
|
|
39
39
|
poolAddress: PublicKey;
|
|
40
|
-
rpc
|
|
40
|
+
rpc?:
|
|
41
41
|
| RpcClient
|
|
42
42
|
| {
|
|
43
|
-
endpoint
|
|
43
|
+
endpoint?: string;
|
|
44
|
+
endpoints?: string[];
|
|
45
|
+
fallbackEndpoints?: string[];
|
|
44
46
|
apiKey?: string;
|
|
45
47
|
commitment?: Commitment;
|
|
48
|
+
timeoutMs?: number;
|
|
46
49
|
};
|
|
47
50
|
}
|
|
48
51
|
|
|
@@ -64,9 +67,12 @@ export class CubicPoolClient {
|
|
|
64
67
|
params.rpc instanceof RpcClient
|
|
65
68
|
? params.rpc
|
|
66
69
|
: new RpcClient({
|
|
67
|
-
endpoint: params.rpc
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
endpoint: params.rpc?.endpoint,
|
|
71
|
+
endpoints: params.rpc?.endpoints ?? (params.rpc?.endpoint ? undefined : params.config.defaults.rpcEndpoints),
|
|
72
|
+
fallbackEndpoints: params.rpc?.fallbackEndpoints,
|
|
73
|
+
apiKey: params.rpc?.apiKey,
|
|
74
|
+
commitment: params.rpc?.commitment ?? params.config.defaults.rpcCommitment,
|
|
75
|
+
timeoutMs: params.rpc?.timeoutMs ?? params.config.defaults.rpcTimeoutMs,
|
|
70
76
|
});
|
|
71
77
|
}
|
|
72
78
|
|
package/src/clients/RpcClient.ts
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { Commitment, Connection, PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { SdkResult } from "../types/result";
|
|
3
|
-
import {
|
|
3
|
+
import { RetryOptions } from "../utils/retry";
|
|
4
|
+
import { err, ok } from "../types/result";
|
|
5
|
+
import { toSdkError } from "../utils/errors";
|
|
4
6
|
|
|
5
7
|
export interface RpcClientParams {
|
|
6
|
-
endpoint
|
|
8
|
+
endpoint?: string;
|
|
9
|
+
/** Ordered endpoint list. If provided, it is used as-is. */
|
|
10
|
+
endpoints?: string[];
|
|
11
|
+
/** Extra endpoints appended after `endpoint`. Ignored when `endpoints` is set. */
|
|
12
|
+
fallbackEndpoints?: string[];
|
|
7
13
|
apiKey?: string;
|
|
8
14
|
commitment?: Commitment;
|
|
9
15
|
/** Optional headers (e.g. for Helius/Triton auth). */
|
|
10
16
|
headers?: Record<string, string>;
|
|
17
|
+
/** Per-endpoint timeout before the next RPC endpoint is tried. */
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
/** Backoff schedule between endpoint attempts. Defaults to no delay. */
|
|
20
|
+
backoffMs?: number[];
|
|
21
|
+
/** Test hook for injecting lightweight fake connections. */
|
|
22
|
+
connectionFactory?: (endpoint: string) => Pick<
|
|
23
|
+
Connection,
|
|
24
|
+
"getAccountInfo" | "getMultipleAccountsInfo" | "getSlot"
|
|
25
|
+
>;
|
|
11
26
|
}
|
|
12
27
|
|
|
13
28
|
/**
|
|
@@ -15,33 +30,51 @@ export interface RpcClientParams {
|
|
|
15
30
|
* human-readable error mapping. Every public method returns a SdkResult<T>.
|
|
16
31
|
*/
|
|
17
32
|
export class RpcClient {
|
|
18
|
-
readonly
|
|
33
|
+
readonly endpoints: string[];
|
|
34
|
+
private readonly connections: Array<Pick<
|
|
35
|
+
Connection,
|
|
36
|
+
"getAccountInfo" | "getMultipleAccountsInfo" | "getSlot"
|
|
37
|
+
>>;
|
|
19
38
|
private readonly defaultCommitment: Commitment;
|
|
39
|
+
private readonly timeoutMs: number;
|
|
40
|
+
private readonly backoffMs: number[];
|
|
41
|
+
private activeEndpointIndex = 0;
|
|
20
42
|
|
|
21
43
|
constructor(params: RpcClientParams) {
|
|
22
|
-
const endpoint = params.apiKey
|
|
23
|
-
? appendApiKey(params.endpoint, params.apiKey)
|
|
24
|
-
: params.endpoint;
|
|
25
44
|
this.defaultCommitment = params.commitment ?? "confirmed";
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
this.timeoutMs = params.timeoutMs ?? 2_000;
|
|
46
|
+
this.backoffMs = params.backoffMs ?? [];
|
|
47
|
+
this.endpoints = normalizeEndpoints(params);
|
|
48
|
+
if (this.endpoints.length === 0) {
|
|
49
|
+
throw new Error("RpcClient requires at least one endpoint");
|
|
50
|
+
}
|
|
51
|
+
this.connections = this.endpoints.map((endpoint) =>
|
|
52
|
+
params.connectionFactory
|
|
53
|
+
? params.connectionFactory(endpoint)
|
|
54
|
+
: new Connection(endpoint, {
|
|
55
|
+
commitment: this.defaultCommitment,
|
|
56
|
+
httpHeaders: params.headers,
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get connection(): Connection {
|
|
62
|
+
return this.connections[this.activeEndpointIndex] as Connection;
|
|
30
63
|
}
|
|
31
64
|
|
|
32
65
|
call<T>(
|
|
33
66
|
fn: (conn: Connection) => Promise<T>,
|
|
34
67
|
retry: RetryOptions = {}
|
|
35
68
|
): Promise<SdkResult<T>> {
|
|
36
|
-
return
|
|
69
|
+
return this.callWithFallback((conn) => fn(conn as Connection), retry);
|
|
37
70
|
}
|
|
38
71
|
|
|
39
72
|
getAccountInfo(
|
|
40
73
|
pk: PublicKey,
|
|
41
74
|
retry: RetryOptions = {}
|
|
42
75
|
): Promise<SdkResult<{ data: Buffer; owner: PublicKey; lamports: number } | null>> {
|
|
43
|
-
return
|
|
44
|
-
const info = await
|
|
76
|
+
return this.callWithFallback(async (conn) => {
|
|
77
|
+
const info = await conn.getAccountInfo(pk, this.defaultCommitment);
|
|
45
78
|
if (!info) return null;
|
|
46
79
|
return {
|
|
47
80
|
data: info.data,
|
|
@@ -55,15 +88,89 @@ export class RpcClient {
|
|
|
55
88
|
pks: PublicKey[],
|
|
56
89
|
retry: RetryOptions = {}
|
|
57
90
|
): Promise<SdkResult<(Buffer | null)[]>> {
|
|
58
|
-
return
|
|
59
|
-
const infos = await
|
|
91
|
+
return this.callWithFallback(async (conn) => {
|
|
92
|
+
const infos = await conn.getMultipleAccountsInfo(pks, this.defaultCommitment);
|
|
60
93
|
return infos.map((i) => (i ? i.data : null));
|
|
61
94
|
}, retry);
|
|
62
95
|
}
|
|
63
96
|
|
|
64
97
|
getSlot(retry: RetryOptions = {}): Promise<SdkResult<number>> {
|
|
65
|
-
return
|
|
98
|
+
return this.callWithFallback((conn) => conn.getSlot(this.defaultCommitment), retry);
|
|
66
99
|
}
|
|
100
|
+
|
|
101
|
+
private async callWithFallback<T>(
|
|
102
|
+
operation: (conn: Pick<Connection, "getAccountInfo" | "getMultipleAccountsInfo" | "getSlot">) => Promise<T>,
|
|
103
|
+
retry: RetryOptions = {}
|
|
104
|
+
): Promise<SdkResult<T>> {
|
|
105
|
+
const attempts = Math.max(1, retry.attempts ?? this.connections.length);
|
|
106
|
+
const timeoutMs = retry.timeoutMs ?? this.timeoutMs;
|
|
107
|
+
const shouldRetry = retry.shouldRetry ?? defaultShouldRetry;
|
|
108
|
+
let lastError: unknown;
|
|
109
|
+
|
|
110
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
111
|
+
const endpointIndex = (this.activeEndpointIndex + attempt) % this.connections.length;
|
|
112
|
+
try {
|
|
113
|
+
const data = await withTimeout(operation(this.connections[endpointIndex]), timeoutMs);
|
|
114
|
+
this.activeEndpointIndex = endpointIndex;
|
|
115
|
+
return ok(data);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
lastError = e;
|
|
118
|
+
if (!shouldRetry(e)) break;
|
|
119
|
+
if (attempt < attempts - 1) {
|
|
120
|
+
const delay = this.backoffMs[Math.min(attempt, this.backoffMs.length - 1)] ?? 0;
|
|
121
|
+
if (delay > 0) await sleep(delay);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const sdkError = toSdkError(lastError);
|
|
127
|
+
return err(sdkError.code, sdkError.humanMessage, lastError);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function normalizeEndpoints(params: RpcClientParams): string[] {
|
|
132
|
+
if (params.endpoints && params.endpoints.length > 0) {
|
|
133
|
+
return dedupe(params.endpoints);
|
|
134
|
+
}
|
|
135
|
+
const primary = params.endpoint
|
|
136
|
+
? params.apiKey
|
|
137
|
+
? appendApiKey(params.endpoint, params.apiKey)
|
|
138
|
+
: params.endpoint
|
|
139
|
+
: undefined;
|
|
140
|
+
return dedupe([primary, ...(params.fallbackEndpoints ?? [])].filter(Boolean) as string[]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function dedupe(endpoints: string[]): string[] {
|
|
144
|
+
return Array.from(new Set(endpoints));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function defaultShouldRetry(e: unknown): boolean {
|
|
148
|
+
const sdkError = toSdkError(e);
|
|
149
|
+
return (
|
|
150
|
+
sdkError.code === "rpc_timeout" ||
|
|
151
|
+
sdkError.code === "rpc_unavailable" ||
|
|
152
|
+
sdkError.code === "rpc_rate_limited"
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function sleep(ms: number): Promise<void> {
|
|
157
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function withTimeout<T>(p: Promise<T>, ms: number): Promise<T> {
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
const h = setTimeout(() => reject(new Error(`timed out after ${ms}ms`)), ms);
|
|
163
|
+
p.then(
|
|
164
|
+
(v) => {
|
|
165
|
+
clearTimeout(h);
|
|
166
|
+
resolve(v);
|
|
167
|
+
},
|
|
168
|
+
(e) => {
|
|
169
|
+
clearTimeout(h);
|
|
170
|
+
reject(e);
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
});
|
|
67
174
|
}
|
|
68
175
|
|
|
69
176
|
function appendApiKey(endpoint: string, apiKey: string): string {
|
|
@@ -17,7 +17,14 @@ export interface SingleTokenDepositClientParams {
|
|
|
17
17
|
config: CubeConfig;
|
|
18
18
|
poolAddress: PublicKey;
|
|
19
19
|
/** Optional — reuses an existing one if provided. */
|
|
20
|
-
rpc?: RpcClient | {
|
|
20
|
+
rpc?: RpcClient | {
|
|
21
|
+
endpoint?: string;
|
|
22
|
+
endpoints?: string[];
|
|
23
|
+
fallbackEndpoints?: string[];
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
commitment?: Commitment;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
};
|
|
21
28
|
/**
|
|
22
29
|
* Optional parent pool client — lets the deposit client reuse an already
|
|
23
30
|
* synced PoolInfo instead of making a fresh RPC round-trip.
|
|
@@ -48,8 +55,9 @@ export class SingleTokenDepositClient {
|
|
|
48
55
|
rpc:
|
|
49
56
|
params.rpc ??
|
|
50
57
|
{
|
|
51
|
-
|
|
58
|
+
endpoints: params.config.defaults.rpcEndpoints,
|
|
52
59
|
commitment: params.config.defaults.rpcCommitment,
|
|
60
|
+
timeoutMs: params.config.defaults.rpcTimeoutMs,
|
|
53
61
|
},
|
|
54
62
|
});
|
|
55
63
|
}
|
package/src/config/index.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { Commitment, PublicKey } from "@solana/web3.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
NETWORK_PROGRAMS,
|
|
4
|
+
NetworkPrograms,
|
|
5
|
+
Network,
|
|
6
|
+
DEFAULT_RPC_ENDPOINT,
|
|
7
|
+
DEFAULT_RPC_ENDPOINTS,
|
|
8
|
+
DEFAULT_RPC_TIMEOUT_MS,
|
|
9
|
+
} from "./networks";
|
|
3
10
|
import { TokenInfo } from "./tokens";
|
|
4
11
|
|
|
5
12
|
export * from "./networks";
|
|
@@ -14,6 +21,8 @@ export interface CubeConfig {
|
|
|
14
21
|
programs: NetworkPrograms;
|
|
15
22
|
defaults: {
|
|
16
23
|
rpcEndpoint: string;
|
|
24
|
+
rpcEndpoints: string[];
|
|
25
|
+
rpcTimeoutMs: number;
|
|
17
26
|
rpcCommitment: Commitment;
|
|
18
27
|
/** Used by helpers that prepend a ComputeBudget instruction. */
|
|
19
28
|
cuLimit: number;
|
|
@@ -32,6 +41,8 @@ export interface CubeConfig {
|
|
|
32
41
|
|
|
33
42
|
export interface CubeConfigOverrides {
|
|
34
43
|
rpcEndpoint?: string;
|
|
44
|
+
rpcEndpoints?: string[];
|
|
45
|
+
rpcTimeoutMs?: number;
|
|
35
46
|
rpcCommitment?: Commitment;
|
|
36
47
|
cuLimit?: number;
|
|
37
48
|
slippageHundredthsBps?: number;
|
|
@@ -41,11 +52,14 @@ export interface CubeConfigOverrides {
|
|
|
41
52
|
|
|
42
53
|
/** Build a CubeConfig for the named network with optional overrides. */
|
|
43
54
|
export function getConfig(network: Network, overrides: CubeConfigOverrides = {}): CubeConfig {
|
|
55
|
+
const rpcEndpoints = resolveRpcEndpoints(network, overrides);
|
|
44
56
|
return {
|
|
45
57
|
network,
|
|
46
58
|
programs: NETWORK_PROGRAMS[network],
|
|
47
59
|
defaults: {
|
|
48
|
-
rpcEndpoint: overrides.rpcEndpoint ?? DEFAULT_RPC_ENDPOINT[network],
|
|
60
|
+
rpcEndpoint: rpcEndpoints[0] ?? overrides.rpcEndpoint ?? DEFAULT_RPC_ENDPOINT[network],
|
|
61
|
+
rpcEndpoints,
|
|
62
|
+
rpcTimeoutMs: overrides.rpcTimeoutMs ?? DEFAULT_RPC_TIMEOUT_MS,
|
|
49
63
|
rpcCommitment: overrides.rpcCommitment ?? "confirmed",
|
|
50
64
|
cuLimit: overrides.cuLimit ?? 1_400_000,
|
|
51
65
|
slippageHundredthsBps: overrides.slippageHundredthsBps ?? 50_000,
|
|
@@ -55,6 +69,20 @@ export function getConfig(network: Network, overrides: CubeConfigOverrides = {})
|
|
|
55
69
|
};
|
|
56
70
|
}
|
|
57
71
|
|
|
72
|
+
function resolveRpcEndpoints(network: Network, overrides: CubeConfigOverrides): string[] {
|
|
73
|
+
if (overrides.rpcEndpoints && overrides.rpcEndpoints.length > 0) {
|
|
74
|
+
return dedupe(overrides.rpcEndpoints);
|
|
75
|
+
}
|
|
76
|
+
if (overrides.rpcEndpoint) {
|
|
77
|
+
return dedupe([overrides.rpcEndpoint, ...DEFAULT_RPC_ENDPOINTS[network]]);
|
|
78
|
+
}
|
|
79
|
+
return [...DEFAULT_RPC_ENDPOINTS[network]];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function dedupe(values: string[]): string[] {
|
|
83
|
+
return Array.from(new Set(values));
|
|
84
|
+
}
|
|
85
|
+
|
|
58
86
|
export const CUBIC_POOL_SEED = Buffer.from("cubic_pool");
|
|
59
87
|
export const BPT_MINT_SEED = Buffer.from("bpt_mint");
|
|
60
88
|
export const STLD_HELPER_SEED = Buffer.from("stld_helper");
|
package/src/config/networks.ts
CHANGED
|
@@ -47,3 +47,15 @@ export const DEFAULT_RPC_ENDPOINT: Record<Network, string> = {
|
|
|
47
47
|
devnet: "https://api.devnet.solana.com",
|
|
48
48
|
localnet: "http://127.0.0.1:8899",
|
|
49
49
|
};
|
|
50
|
+
|
|
51
|
+
export const DEFAULT_RPC_ENDPOINTS: Record<Network, string[]> = {
|
|
52
|
+
mainnet: [
|
|
53
|
+
"https://api.mainnet-beta.solana.com",
|
|
54
|
+
"https://solana-rpc.publicnode.com",
|
|
55
|
+
"https://solana.api.pocket.network",
|
|
56
|
+
],
|
|
57
|
+
devnet: ["https://api.devnet.solana.com"],
|
|
58
|
+
localnet: ["http://127.0.0.1:8899"],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const DEFAULT_RPC_TIMEOUT_MS = 2_000;
|
package/src/index.ts
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
// See LICENSE at the repository root.
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @
|
|
6
|
+
* @cubee_ee/sdk — client library for the Cubic Pool AMM on Solana.
|
|
7
7
|
*
|
|
8
8
|
* Entry point barrel. Most consumers will want to import from this root:
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
|
-
* import { CubicPoolClient, CubeBackendClient, getConfig } from "@
|
|
11
|
+
* import { CubicPoolClient, CubeBackendClient, getConfig } from "@cubee_ee/sdk";
|
|
12
12
|
*
|
|
13
13
|
* const cfg = getConfig("mainnet", { backendEndpoint: "https://api.cube.fi" });
|
|
14
|
-
* const pool = new CubicPoolClient({ config: cfg, poolAddress
|
|
14
|
+
* const pool = new CubicPoolClient({ config: cfg, poolAddress });
|
|
15
15
|
* const info = await pool.sync();
|
|
16
16
|
* if (info.ok) console.log(info.data.tokens.map(t => t.metadata?.symbol));
|
|
17
17
|
* ```
|
|
@@ -48,7 +48,12 @@ export {
|
|
|
48
48
|
SLIPPAGE_PRECISION,
|
|
49
49
|
MIN_SLIPPAGE_HBPS,
|
|
50
50
|
} from "./config";
|
|
51
|
-
export {
|
|
51
|
+
export {
|
|
52
|
+
NETWORK_PROGRAMS,
|
|
53
|
+
DEFAULT_RPC_ENDPOINT,
|
|
54
|
+
DEFAULT_RPC_ENDPOINTS,
|
|
55
|
+
DEFAULT_RPC_TIMEOUT_MS,
|
|
56
|
+
} from "./config/networks";
|
|
52
57
|
export { KNOWN_TOKENS, resolveKnownToken } from "./config/tokens";
|
|
53
58
|
export { ok, err } from "./types/result";
|
|
54
59
|
export {
|
|
@@ -154,6 +159,8 @@ export type {
|
|
|
154
159
|
XpAccrualHistoryResponse,
|
|
155
160
|
EpochHistoryEntry,
|
|
156
161
|
LeaderboardEpochResponse,
|
|
162
|
+
SwapRouteEntry,
|
|
163
|
+
SwapRouteResponse,
|
|
157
164
|
CubicPoolClientParams,
|
|
158
165
|
SingleTokenDepositClientParams,
|
|
159
166
|
PoolFactoryClientParams,
|
package/src/utils/errors.ts
CHANGED
|
@@ -41,7 +41,7 @@ export function toSdkError(cause: unknown): SdkError {
|
|
|
41
41
|
if (/429|rate limit/i.test(msg)) {
|
|
42
42
|
return { code: "rpc_rate_limited", humanMessage: "RPC rate-limited — slow down", cause };
|
|
43
43
|
}
|
|
44
|
-
if (/fetch failed|ECONNREFUSED|ENOTFOUND/i.test(msg)) {
|
|
44
|
+
if (/fetch failed|ECONNREFUSED|ENOTFOUND|Proxy error|-32056|-32052|403/i.test(msg)) {
|
|
45
45
|
return { code: "rpc_unavailable", humanMessage: "RPC endpoint unreachable", cause };
|
|
46
46
|
}
|
|
47
47
|
if (/Account does not exist|account not found/i.test(msg)) {
|