@percolatorct/sdk 1.0.0-beta.15 → 1.0.0-beta.16

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.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Static market registry — bundled list of known Percolator slab addresses.
3
+ *
4
+ * This is the tier-3 fallback for `discoverMarkets()`: when both
5
+ * `getProgramAccounts` (tier 1) and the REST API (tier 2) are unavailable,
6
+ * the SDK falls back to this bundled list to bootstrap market discovery.
7
+ *
8
+ * The addresses are fetched on-chain via `getMarketsByAddress`
9
+ * (`getMultipleAccounts`), so all data is still verified on-chain. The static
10
+ * list only provides the *address directory* — no cached market data is used.
11
+ *
12
+ * ## Maintenance
13
+ *
14
+ * Update this list when new markets are deployed or old ones are retired.
15
+ * Run `scripts/update-static-markets.ts` to regenerate from a permissive RPC
16
+ * or the REST API.
17
+ *
18
+ * @module
19
+ */
20
+ import type { Network } from "../config/program-ids.js";
21
+ /**
22
+ * A single entry in the static market registry.
23
+ *
24
+ * Only the slab address (base58) is required. Optional metadata fields
25
+ * (`symbol`, `name`) are provided for debugging/logging purposes only —
26
+ * they are **not** used for on-chain data and may become stale.
27
+ */
28
+ export interface StaticMarketEntry {
29
+ /** Base58-encoded slab account address. */
30
+ slabAddress: string;
31
+ /** Optional human-readable symbol (e.g. "SOL-PERP"). */
32
+ symbol?: string;
33
+ /** Optional descriptive name. */
34
+ name?: string;
35
+ }
36
+ /**
37
+ * Get the bundled static market list for a given network.
38
+ *
39
+ * Returns the built-in list merged with any entries added via
40
+ * {@link registerStaticMarkets}. Duplicates (by `slabAddress`) are removed
41
+ * automatically — user-registered entries take precedence.
42
+ *
43
+ * @param network - Target network (`"mainnet"` or `"devnet"`)
44
+ * @returns Array of static market entries (may be empty if no markets are known)
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { getStaticMarkets } from "@percolator/sdk";
49
+ *
50
+ * const markets = getStaticMarkets("mainnet");
51
+ * console.log(`${markets.length} known mainnet slab addresses`);
52
+ * ```
53
+ */
54
+ export declare function getStaticMarkets(network: Network): StaticMarketEntry[];
55
+ /**
56
+ * Register additional static market entries at runtime.
57
+ *
58
+ * Use this to inject known slab addresses before calling `discoverMarkets()`
59
+ * so that tier-3 fallback has addresses to work with — especially useful
60
+ * right after mainnet launch when the bundled list may be empty.
61
+ *
62
+ * Entries are deduplicated by `slabAddress` — calling this multiple times
63
+ * with the same address is safe.
64
+ *
65
+ * @param network - Target network
66
+ * @param entries - One or more static market entries to register
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import { registerStaticMarkets } from "@percolator/sdk";
71
+ *
72
+ * registerStaticMarkets("mainnet", [
73
+ * { slabAddress: "ABC123...", symbol: "SOL-PERP" },
74
+ * { slabAddress: "DEF456...", symbol: "ETH-PERP" },
75
+ * ]);
76
+ * ```
77
+ */
78
+ export declare function registerStaticMarkets(network: Network, entries: StaticMarketEntry[]): void;
79
+ /**
80
+ * Clear all user-registered static market entries for a network.
81
+ *
82
+ * Useful in tests or when resetting state.
83
+ *
84
+ * @param network - Target network to clear (omit to clear all networks)
85
+ */
86
+ export declare function clearStaticMarkets(network?: Network): void;
@@ -0,0 +1,19 @@
1
+ import { Connection, PublicKey } from "@solana/web3.js";
2
+ /**
3
+ * Token2022 (Token Extensions) program ID.
4
+ */
5
+ export declare const TOKEN_2022_PROGRAM_ID: PublicKey;
6
+ /**
7
+ * Detect which token program owns a given mint account.
8
+ * Returns the owner program ID (TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID).
9
+ * Throws if the mint account doesn't exist.
10
+ */
11
+ export declare function detectTokenProgram(connection: Connection, mint: PublicKey): Promise<PublicKey>;
12
+ /**
13
+ * Check if a given token program ID is Token2022.
14
+ */
15
+ export declare function isToken2022(tokenProgramId: PublicKey): boolean;
16
+ /**
17
+ * Check if a given token program ID is the standard SPL Token program.
18
+ */
19
+ export declare function isStandardToken(tokenProgramId: PublicKey): boolean;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Input validation utilities for CLI commands.
3
+ * Provides descriptive error messages for invalid input.
4
+ */
5
+ import { PublicKey } from "@solana/web3.js";
6
+ export declare class ValidationError extends Error {
7
+ readonly field: string;
8
+ constructor(field: string, message: string);
9
+ }
10
+ /**
11
+ * Validate a public key string.
12
+ *
13
+ * @param value - Base58-encoded public key string.
14
+ * @param field - Field name for error messages.
15
+ * @returns Parsed `PublicKey` instance.
16
+ * @throws {@link ValidationError} if the string is not a valid base58 public key.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const key = validatePublicKey("11111111111111111111111111111111", "slab");
21
+ * ```
22
+ */
23
+ export declare function validatePublicKey(value: string, field: string): PublicKey;
24
+ /**
25
+ * Validate a non-negative integer index (u16 range for accounts).
26
+ *
27
+ * @param value - Decimal string representing the index.
28
+ * @param field - Field name for error messages.
29
+ * @returns Parsed integer in `[0, 65535]`.
30
+ * @throws {@link ValidationError} if the value is not a valid u16 integer.
31
+ */
32
+ export declare function validateIndex(value: string, field: string): number;
33
+ /**
34
+ * Validate a non-negative amount (u64 range).
35
+ *
36
+ * @param value - Decimal string representing the amount.
37
+ * @param field - Field name for error messages.
38
+ * @returns Parsed `bigint` in `[0, 2^64 - 1]`.
39
+ * @throws {@link ValidationError} if the value is negative or exceeds u64 max.
40
+ */
41
+ export declare function validateAmount(value: string, field: string): bigint;
42
+ /**
43
+ * Validate a u128 value.
44
+ */
45
+ export declare function validateU128(value: string, field: string): bigint;
46
+ /**
47
+ * Validate an i64 value.
48
+ */
49
+ export declare function validateI64(value: string, field: string): bigint;
50
+ /**
51
+ * Validate an i128 value (trade sizes).
52
+ */
53
+ export declare function validateI128(value: string, field: string): bigint;
54
+ /**
55
+ * Validate a basis points value (0–10000).
56
+ *
57
+ * @param value - Decimal string representing basis points.
58
+ * @param field - Field name for error messages.
59
+ * @returns Parsed integer in `[0, 10000]`.
60
+ * @throws {@link ValidationError} if the value exceeds 10000.
61
+ */
62
+ export declare function validateBps(value: string, field: string): number;
63
+ /**
64
+ * Validate a u64 value.
65
+ */
66
+ export declare function validateU64(value: string, field: string): bigint;
67
+ /**
68
+ * Validate a u16 value.
69
+ */
70
+ export declare function validateU16(value: string, field: string): number;
package/package.json CHANGED
@@ -1,24 +1,29 @@
1
1
  {
2
2
  "name": "@percolatorct/sdk",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.16",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
+ "engines": {
7
+ "node": ">=20.0.0"
8
+ },
6
9
  "main": "./dist/index.js",
7
10
  "types": "./dist/index.d.ts",
8
11
  "exports": {
9
12
  ".": {
13
+ "types": "./dist/index.d.ts",
10
14
  "import": "./dist/index.js",
11
15
  "require": "./dist/index.js",
12
- "default": "./dist/index.js",
13
- "types": "./dist/index.d.ts"
16
+ "default": "./dist/index.js"
14
17
  }
15
18
  },
16
19
  "files": [
17
20
  "dist"
18
21
  ],
19
22
  "scripts": {
20
- "build": "tsup",
21
- "test": "tsx test/abi.test.ts && tsx test/pda.test.ts && tsx test/slab.test.ts && tsx test/validation.test.ts && tsx test/dex-oracle.test.ts && tsx test/trading.test.ts && tsx test/warmup-leverage-cap.test.ts && tsx test/dynamic-fees.test.ts && tsx test/oracle.test.ts"
23
+ "build": "tsup && tsc --emitDeclarationOnly --declaration --outDir dist",
24
+ "test": "tsx test/abi.test.ts && tsx test/slab.test.ts && tsx test/validation.test.ts && tsx test/dex-oracle.test.ts && tsx test/trading.test.ts && tsx test/warmup-leverage-cap.test.ts && tsx test/dynamic-fees.test.ts && tsx test/oracle.test.ts && vitest run",
25
+ "lint": "tsc --noEmit",
26
+ "verify-layout": "tsx scripts/verify-layout.ts"
22
27
  },
23
28
  "dependencies": {
24
29
  "@solana/spl-token": "^0.4.14",
@@ -26,6 +31,7 @@
26
31
  },
27
32
  "devDependencies": {
28
33
  "@types/node": "^20.17.10",
34
+ "dotenv": "^17.4.1",
29
35
  "tsup": "^8.3.5",
30
36
  "tsx": "^4.21.0",
31
37
  "typescript": "^5.7.2",