@coffer_so/sdk 1.0.0

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.
Files changed (228) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +283 -0
  3. package/dist/clients/AdminClient.d.ts +194 -0
  4. package/dist/clients/AdminClient.d.ts.map +1 -0
  5. package/dist/clients/AdminClient.js +482 -0
  6. package/dist/clients/AdminClient.js.map +1 -0
  7. package/dist/clients/CofferBackendClient.d.ts +877 -0
  8. package/dist/clients/CofferBackendClient.d.ts.map +1 -0
  9. package/dist/clients/CofferBackendClient.js +536 -0
  10. package/dist/clients/CofferBackendClient.js.map +1 -0
  11. package/dist/clients/CubeBackendClient.d.ts +877 -0
  12. package/dist/clients/CubeBackendClient.d.ts.map +1 -0
  13. package/dist/clients/CubeBackendClient.js +536 -0
  14. package/dist/clients/CubeBackendClient.js.map +1 -0
  15. package/dist/clients/CubicPoolClient.d.ts +120 -0
  16. package/dist/clients/CubicPoolClient.d.ts.map +1 -0
  17. package/dist/clients/CubicPoolClient.js +687 -0
  18. package/dist/clients/CubicPoolClient.js.map +1 -0
  19. package/dist/clients/PoolFactoryClient.d.ts +53 -0
  20. package/dist/clients/PoolFactoryClient.d.ts.map +1 -0
  21. package/dist/clients/PoolFactoryClient.js +91 -0
  22. package/dist/clients/PoolFactoryClient.js.map +1 -0
  23. package/dist/clients/RpcClient.d.ts +49 -0
  24. package/dist/clients/RpcClient.d.ts.map +1 -0
  25. package/dist/clients/RpcClient.js +135 -0
  26. package/dist/clients/RpcClient.js.map +1 -0
  27. package/dist/clients/SingleTokenDepositClient.d.ts +67 -0
  28. package/dist/clients/SingleTokenDepositClient.d.ts.map +1 -0
  29. package/dist/clients/SingleTokenDepositClient.js +105 -0
  30. package/dist/clients/SingleTokenDepositClient.js.map +1 -0
  31. package/dist/clients/contract-instructions.d.ts +24 -0
  32. package/dist/clients/contract-instructions.d.ts.map +1 -0
  33. package/dist/clients/contract-instructions.js +130 -0
  34. package/dist/clients/contract-instructions.js.map +1 -0
  35. package/dist/clients/index.d.ts +10 -0
  36. package/dist/clients/index.d.ts.map +1 -0
  37. package/dist/clients/index.js +26 -0
  38. package/dist/clients/index.js.map +1 -0
  39. package/dist/clients/quote-math.d.ts +15 -0
  40. package/dist/clients/quote-math.d.ts.map +1 -0
  41. package/dist/clients/quote-math.js +98 -0
  42. package/dist/clients/quote-math.js.map +1 -0
  43. package/dist/clients/tx-builders.d.ts +231 -0
  44. package/dist/clients/tx-builders.d.ts.map +1 -0
  45. package/dist/clients/tx-builders.js +861 -0
  46. package/dist/clients/tx-builders.js.map +1 -0
  47. package/dist/clients/versioned.d.ts +34 -0
  48. package/dist/clients/versioned.d.ts.map +1 -0
  49. package/dist/clients/versioned.js +55 -0
  50. package/dist/clients/versioned.js.map +1 -0
  51. package/dist/config/index.d.ts +65 -0
  52. package/dist/config/index.d.ts.map +1 -0
  53. package/dist/config/index.js +75 -0
  54. package/dist/config/index.js.map +1 -0
  55. package/dist/config/networks.d.ts +12 -0
  56. package/dist/config/networks.d.ts.map +1 -0
  57. package/dist/config/networks.js +51 -0
  58. package/dist/config/networks.js.map +1 -0
  59. package/dist/config/tokens.d.ts +19 -0
  60. package/dist/config/tokens.d.ts.map +1 -0
  61. package/dist/config/tokens.js +43 -0
  62. package/dist/config/tokens.js.map +1 -0
  63. package/dist/idl/cubic_pool.json +4203 -0
  64. package/dist/idl/index.d.ts +1769 -0
  65. package/dist/idl/index.d.ts.map +1 -0
  66. package/dist/idl/index.js +18 -0
  67. package/dist/idl/index.js.map +1 -0
  68. package/dist/idl/protocol_admin.json +2615 -0
  69. package/dist/idl/single_token_liquidity.json +1121 -0
  70. package/dist/index.d.ts +75 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +206 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/math/cubicMath.d.ts +40 -0
  75. package/dist/math/cubicMath.d.ts.map +1 -0
  76. package/dist/math/cubicMath.js +82 -0
  77. package/dist/math/cubicMath.js.map +1 -0
  78. package/dist/math/fixedPoint.d.ts +19 -0
  79. package/dist/math/fixedPoint.d.ts.map +1 -0
  80. package/dist/math/fixedPoint.js +86 -0
  81. package/dist/math/fixedPoint.js.map +1 -0
  82. package/dist/math/index.d.ts +9 -0
  83. package/dist/math/index.d.ts.map +1 -0
  84. package/dist/math/index.js +30 -0
  85. package/dist/math/index.js.map +1 -0
  86. package/dist/math/logExp.d.ts +6 -0
  87. package/dist/math/logExp.d.ts.map +1 -0
  88. package/dist/math/logExp.js +68 -0
  89. package/dist/math/logExp.js.map +1 -0
  90. package/dist/math/lpLoss.d.ts +44 -0
  91. package/dist/math/lpLoss.d.ts.map +1 -0
  92. package/dist/math/lpLoss.js +103 -0
  93. package/dist/math/lpLoss.js.map +1 -0
  94. package/dist/math/maxSelloff.d.ts +164 -0
  95. package/dist/math/maxSelloff.d.ts.map +1 -0
  96. package/dist/math/maxSelloff.js +397 -0
  97. package/dist/math/maxSelloff.js.map +1 -0
  98. package/dist/math/singleToken.d.ts +54 -0
  99. package/dist/math/singleToken.d.ts.map +1 -0
  100. package/dist/math/singleToken.js +188 -0
  101. package/dist/math/singleToken.js.map +1 -0
  102. package/dist/math/slippage.d.ts +13 -0
  103. package/dist/math/slippage.d.ts.map +1 -0
  104. package/dist/math/slippage.js +44 -0
  105. package/dist/math/slippage.js.map +1 -0
  106. package/dist/math/surgeFee.d.ts +24 -0
  107. package/dist/math/surgeFee.d.ts.map +1 -0
  108. package/dist/math/surgeFee.js +85 -0
  109. package/dist/math/surgeFee.js.map +1 -0
  110. package/dist/math/weightedMath.d.ts +20 -0
  111. package/dist/math/weightedMath.d.ts.map +1 -0
  112. package/dist/math/weightedMath.js +66 -0
  113. package/dist/math/weightedMath.js.map +1 -0
  114. package/dist/parsers/borsh.d.ts +28 -0
  115. package/dist/parsers/borsh.d.ts.map +1 -0
  116. package/dist/parsers/borsh.js +104 -0
  117. package/dist/parsers/borsh.js.map +1 -0
  118. package/dist/parsers/contracts.d.ts +26 -0
  119. package/dist/parsers/contracts.d.ts.map +1 -0
  120. package/dist/parsers/contracts.js +62 -0
  121. package/dist/parsers/contracts.js.map +1 -0
  122. package/dist/parsers/events.d.ts +3 -0
  123. package/dist/parsers/events.d.ts.map +1 -0
  124. package/dist/parsers/events.js +281 -0
  125. package/dist/parsers/events.js.map +1 -0
  126. package/dist/parsers/index.d.ts +6 -0
  127. package/dist/parsers/index.d.ts.map +1 -0
  128. package/dist/parsers/index.js +22 -0
  129. package/dist/parsers/index.js.map +1 -0
  130. package/dist/parsers/mintAccount.d.ts +24 -0
  131. package/dist/parsers/mintAccount.d.ts.map +1 -0
  132. package/dist/parsers/mintAccount.js +27 -0
  133. package/dist/parsers/mintAccount.js.map +1 -0
  134. package/dist/parsers/poolAccount.d.ts +141 -0
  135. package/dist/parsers/poolAccount.d.ts.map +1 -0
  136. package/dist/parsers/poolAccount.js +224 -0
  137. package/dist/parsers/poolAccount.js.map +1 -0
  138. package/dist/types/contracts.d.ts +1340 -0
  139. package/dist/types/contracts.d.ts.map +1 -0
  140. package/dist/types/contracts.js +3 -0
  141. package/dist/types/contracts.js.map +1 -0
  142. package/dist/types/events.d.ts +172 -0
  143. package/dist/types/events.d.ts.map +1 -0
  144. package/dist/types/events.js +3 -0
  145. package/dist/types/events.js.map +1 -0
  146. package/dist/types/index.d.ts +6 -0
  147. package/dist/types/index.d.ts.map +1 -0
  148. package/dist/types/index.js +22 -0
  149. package/dist/types/index.js.map +1 -0
  150. package/dist/types/pool.d.ts +149 -0
  151. package/dist/types/pool.d.ts.map +1 -0
  152. package/dist/types/pool.js +3 -0
  153. package/dist/types/pool.js.map +1 -0
  154. package/dist/types/result.d.ts +24 -0
  155. package/dist/types/result.d.ts.map +1 -0
  156. package/dist/types/result.js +11 -0
  157. package/dist/types/result.js.map +1 -0
  158. package/dist/types/tx.d.ts +261 -0
  159. package/dist/types/tx.d.ts.map +1 -0
  160. package/dist/types/tx.js +3 -0
  161. package/dist/types/tx.js.map +1 -0
  162. package/dist/utils/errors.d.ts +44 -0
  163. package/dist/utils/errors.d.ts.map +1 -0
  164. package/dist/utils/errors.js +192 -0
  165. package/dist/utils/errors.js.map +1 -0
  166. package/dist/utils/extensions.d.ts +98 -0
  167. package/dist/utils/extensions.d.ts.map +1 -0
  168. package/dist/utils/extensions.js +187 -0
  169. package/dist/utils/extensions.js.map +1 -0
  170. package/dist/utils/index.d.ts +5 -0
  171. package/dist/utils/index.d.ts.map +1 -0
  172. package/dist/utils/index.js +21 -0
  173. package/dist/utils/index.js.map +1 -0
  174. package/dist/utils/pda.d.ts +8 -0
  175. package/dist/utils/pda.d.ts.map +1 -0
  176. package/dist/utils/pda.js +27 -0
  177. package/dist/utils/pda.js.map +1 -0
  178. package/dist/utils/retry.d.ts +22 -0
  179. package/dist/utils/retry.d.ts.map +1 -0
  180. package/dist/utils/retry.js +62 -0
  181. package/dist/utils/retry.js.map +1 -0
  182. package/package.json +54 -0
  183. package/src/clients/AdminClient.ts +608 -0
  184. package/src/clients/CofferBackendClient.ts +1413 -0
  185. package/src/clients/CubicPoolClient.ts +719 -0
  186. package/src/clients/PoolFactoryClient.ts +110 -0
  187. package/src/clients/RpcClient.ts +195 -0
  188. package/src/clients/SingleTokenDepositClient.ts +143 -0
  189. package/src/clients/contract-instructions.ts +115 -0
  190. package/src/clients/index.ts +9 -0
  191. package/src/clients/quote-math.ts +81 -0
  192. package/src/clients/tx-builders.ts +1096 -0
  193. package/src/clients/versioned.ts +80 -0
  194. package/src/config/index.ts +111 -0
  195. package/src/config/networks.ts +71 -0
  196. package/src/config/tokens.ts +52 -0
  197. package/src/idl/cubic_pool.json +4203 -0
  198. package/src/idl/index.ts +13 -0
  199. package/src/idl/protocol_admin.json +2615 -0
  200. package/src/idl/single_token_liquidity.json +1121 -0
  201. package/src/index.ts +262 -0
  202. package/src/math/cubicMath.ts +92 -0
  203. package/src/math/fixedPoint.ts +71 -0
  204. package/src/math/index.ts +13 -0
  205. package/src/math/logExp.ts +61 -0
  206. package/src/math/lpLoss.ts +160 -0
  207. package/src/math/maxSelloff.ts +564 -0
  208. package/src/math/singleToken.ts +251 -0
  209. package/src/math/slippage.ts +38 -0
  210. package/src/math/surgeFee.ts +101 -0
  211. package/src/math/weightedMath.ts +64 -0
  212. package/src/parsers/borsh.ts +106 -0
  213. package/src/parsers/contracts.ts +64 -0
  214. package/src/parsers/events.ts +275 -0
  215. package/src/parsers/index.ts +5 -0
  216. package/src/parsers/mintAccount.ts +44 -0
  217. package/src/parsers/poolAccount.ts +372 -0
  218. package/src/types/contracts.ts +238 -0
  219. package/src/types/events.ts +198 -0
  220. package/src/types/index.ts +5 -0
  221. package/src/types/pool.ts +147 -0
  222. package/src/types/result.ts +51 -0
  223. package/src/types/tx.ts +278 -0
  224. package/src/utils/errors.ts +210 -0
  225. package/src/utils/extensions.ts +196 -0
  226. package/src/utils/index.ts +4 -0
  227. package/src/utils/pda.ts +58 -0
  228. package/src/utils/retry.ts +85 -0
@@ -0,0 +1,80 @@
1
+ import {
2
+ AddressLookupTableAccount,
3
+ Connection,
4
+ PublicKey,
5
+ TransactionInstruction,
6
+ TransactionMessage,
7
+ VersionedTransaction,
8
+ } from "@solana/web3.js";
9
+ import { PoolInfo } from "../types/pool";
10
+ import { BuiltTx } from "../types/tx";
11
+ import { SdkResult, err, ok } from "../types/result";
12
+
13
+ /**
14
+ * Compile a set of instructions into a `VersionedTransaction` (v0),
15
+ * optionally using a per-pool Address Lookup Table to shrink the wire
16
+ * size below the 1232-byte legacy ceiling.
17
+ *
18
+ * ALT inclusion rules:
19
+ * - If `lookupTable` is `PublicKey.default` (or undefined) → no ALT
20
+ * is referenced; the tx is v0 but uses only static account keys.
21
+ * - Otherwise → fetch the ALT via `connection.getAddressLookupTable`
22
+ * and include it. If the fetch fails, the function returns an
23
+ * `alt_fetch_failed` error rather than silently falling back.
24
+ *
25
+ * Wallets supporting the standard `signTransaction(Transaction |
26
+ * VersionedTransaction)` overload (Phantom, Solflare, Backpack, Glow,
27
+ * the wallet-adapter set since 2023) sign these without changes.
28
+ */
29
+ export async function buildVersionedTx(
30
+ conn: Connection,
31
+ payer: PublicKey,
32
+ instructions: TransactionInstruction[],
33
+ lookupTable: PublicKey | undefined,
34
+ ): Promise<SdkResult<{ tx: VersionedTransaction; alts: AddressLookupTableAccount[] }>> {
35
+ const alts: AddressLookupTableAccount[] = [];
36
+
37
+ if (lookupTable && !lookupTable.equals(PublicKey.default)) {
38
+ try {
39
+ const res = await conn.getAddressLookupTable(lookupTable);
40
+ if (!res.value) {
41
+ return err(
42
+ "alt_fetch_failed",
43
+ `Lookup table ${lookupTable.toBase58()} not found on-chain. ` +
44
+ "The pool advertises an ALT but the account is missing — " +
45
+ "the ALT may have been closed or the RPC is stale.",
46
+ );
47
+ }
48
+ alts.push(res.value);
49
+ } catch (e) {
50
+ return err(
51
+ "alt_fetch_failed",
52
+ `Failed to fetch lookup table ${lookupTable.toBase58()}`,
53
+ e,
54
+ );
55
+ }
56
+ }
57
+
58
+ const { blockhash } = await conn.getLatestBlockhash("confirmed");
59
+ const msg = new TransactionMessage({
60
+ payerKey: payer,
61
+ recentBlockhash: blockhash,
62
+ instructions,
63
+ }).compileToV0Message(alts);
64
+
65
+ return ok({ tx: new VersionedTransaction(msg), alts });
66
+ }
67
+
68
+ /**
69
+ * Convenience: take a SDK-built `BuiltTx` and a pool snapshot, produce
70
+ * a signed-ready `VersionedTransaction`. Picks up `pool.lookupTable`
71
+ * automatically.
72
+ */
73
+ export async function compileBuiltTx(
74
+ conn: Connection,
75
+ payer: PublicKey,
76
+ built: BuiltTx,
77
+ pool: Pick<PoolInfo, "lookupTable">,
78
+ ): Promise<SdkResult<{ tx: VersionedTransaction; alts: AddressLookupTableAccount[] }>> {
79
+ return buildVersionedTx(conn, payer, built.instructions, pool.lookupTable);
80
+ }
@@ -0,0 +1,111 @@
1
+ import { Commitment, PublicKey } from "@solana/web3.js";
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";
10
+ import { TokenInfo } from "./tokens";
11
+
12
+ export * from "./networks";
13
+ export * from "./tokens";
14
+
15
+ /**
16
+ * Root SDK configuration. Passed into every Client class at construction.
17
+ * Immutable after creation — rebuild if you need to switch networks.
18
+ */
19
+ export interface CofferConfig {
20
+ network: Network;
21
+ programs: NetworkPrograms;
22
+ defaults: {
23
+ rpcEndpoint: string;
24
+ rpcEndpoints: string[];
25
+ rpcTimeoutMs: number;
26
+ rpcCommitment: Commitment;
27
+ /** Used by helpers that prepend a ComputeBudget instruction. */
28
+ cuLimit: number;
29
+ /**
30
+ * Default slippage budget when the caller doesn't pass one. Units:
31
+ * hundredths of a basis point (matches cubic-pool's `swap_fee_rate`
32
+ * scale). 50_000 = 5%.
33
+ */
34
+ slippageHundredthsBps: number;
35
+ };
36
+ /** Optional token registry keyed by mint pubkey string. */
37
+ tokens?: Record<string, TokenInfo>;
38
+ /** Optional backend endpoint; consumed by CofferBackendClient. */
39
+ backendEndpoint?: string;
40
+ }
41
+
42
+ export interface CofferConfigOverrides {
43
+ rpcEndpoint?: string;
44
+ rpcEndpoints?: string[];
45
+ rpcTimeoutMs?: number;
46
+ rpcCommitment?: Commitment;
47
+ cuLimit?: number;
48
+ slippageHundredthsBps?: number;
49
+ backendEndpoint?: string;
50
+ tokens?: Record<string, TokenInfo>;
51
+ }
52
+
53
+ /** Build a CofferConfig for the named network with optional overrides. */
54
+ export function getConfig(network: Network, overrides: CofferConfigOverrides = {}): CofferConfig {
55
+ const rpcEndpoints = resolveRpcEndpoints(network, overrides);
56
+ return {
57
+ network,
58
+ programs: NETWORK_PROGRAMS[network],
59
+ defaults: {
60
+ rpcEndpoint: rpcEndpoints[0] ?? overrides.rpcEndpoint ?? DEFAULT_RPC_ENDPOINT[network],
61
+ rpcEndpoints,
62
+ rpcTimeoutMs: overrides.rpcTimeoutMs ?? DEFAULT_RPC_TIMEOUT_MS,
63
+ rpcCommitment: overrides.rpcCommitment ?? "confirmed",
64
+ cuLimit: overrides.cuLimit ?? 1_400_000,
65
+ slippageHundredthsBps: overrides.slippageHundredthsBps ?? 50_000,
66
+ },
67
+ tokens: overrides.tokens,
68
+ backendEndpoint: overrides.backendEndpoint,
69
+ };
70
+ }
71
+
72
+ function resolveRpcEndpoints(network: Network, overrides: CofferConfigOverrides): 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
+
86
+ export const CUBIC_POOL_SEED = Buffer.from("cubic_pool");
87
+ export const BPT_MINT_SEED = Buffer.from("bpt_mint");
88
+ export const STLD_HELPER_SEED = Buffer.from("stld_helper");
89
+ export const TREASURY_SEED = Buffer.from("treasury");
90
+
91
+ /** Contract-level constants mirrored from Rust. */
92
+ export const WEIGHT_SCALE = 10_000; // 100 %
93
+ export const MIN_WEIGHT = 100; // 1 %
94
+ export const MAX_WEIGHT = 9_900; // 99 %
95
+ export const MIN_TOKENS = 2;
96
+ export const MAX_TOKENS = 10;
97
+ export const BPT_DECIMALS = 9;
98
+ export const SWAP_FEE_PRECISION = 1_000_000; // 100 %
99
+ export const PROTOCOL_FEE_PRECISION = 10_000; // 100 %
100
+ export const PERCENT_SCALE = 10_000; // 100 % (max-selloff / surge-fee scale)
101
+ export const MAX_SWAP_FEE_RATE = 100_000; // 10 %
102
+ export const MAX_PROTOCOL_FEE_RATE = 5_000; // 50 %
103
+ export const MINIMUM_INITIAL_BPT = 1_000n;
104
+ export const SLIPPAGE_PRECISION = 1_000_000;
105
+ export const MIN_SLIPPAGE_HBPS = 10; // 0.001 %
106
+
107
+ export type ProgramIdKind = "cubicPool" | "singleTokenLiquidity" | "protocolAdmin";
108
+
109
+ export function programId(cfg: CofferConfig, kind: ProgramIdKind): PublicKey {
110
+ return cfg.programs[kind];
111
+ }
@@ -0,0 +1,71 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+
3
+ export type Network = "mainnet" | "devnet" | "localnet";
4
+
5
+ export interface NetworkPrograms {
6
+ cubicPool: PublicKey;
7
+ singleTokenLiquidity: PublicKey;
8
+ protocolAdmin: PublicKey;
9
+ }
10
+
11
+ export const NETWORK_PROGRAMS: Record<Network, NetworkPrograms> = {
12
+ mainnet: {
13
+ cubicPool: new PublicKey("8iQtGj9mcUfFUGaiCpPy89swC3s8YTC8FhVZWfgeZhwu"),
14
+ // TODO(mainnet): single_token_liquidity is NOT deployed on mainnet — this
15
+ // is the devnet program ID as a placeholder. Single-token deposit is
16
+ // disabled in the frontend. If/when stld ships on mainnet, replace this
17
+ // with the real mainnet program ID.
18
+ singleTokenLiquidity: new PublicKey(
19
+ "7BpdUH1tzTSXLuQNo6YpjJ8Eagw8AkrS6cnkxiJdCFS2",
20
+ ),
21
+ protocolAdmin: new PublicKey(
22
+ "3jiojHZbjJQ7QLMGSTjFwxVEmx4NtuRy34nLAmsJME81",
23
+ ),
24
+ },
25
+ devnet: {
26
+ // v5.1 (post-audit) copy deployed on devnet under our wallet. The original
27
+ // devnet CVKx/HJEi IDs are unusable: cubic_pool's was closed permanently
28
+ // and protocol_admin's has a non-ours upgrade authority.
29
+ //
30
+ // These binaries are built with devnet `declare_id`s AND a devnet
31
+ // `PROTOCOL_ADMIN_PROGRAM_ID` — cubic_pool pins that constant at compile
32
+ // time to derive the Treasury PDA, so a mainnet build would look for a
33
+ // Treasury that does not exist here.
34
+ cubicPool: new PublicKey("E6YAKuLAd8vBgJnXsVdPCFCdgUef6ZinfDst3JMxuhJJ"),
35
+ // stld IS deployed on devnet and shares its ID with mainnet, because its
36
+ // `declare_id` needed no devnet override.
37
+ singleTokenLiquidity: new PublicKey(
38
+ "7BpdUH1tzTSXLuQNo6YpjJ8Eagw8AkrS6cnkxiJdCFS2",
39
+ ),
40
+ protocolAdmin: new PublicKey(
41
+ "6bFDi7RrLJSbhBpJ2AjHAQfbzBiHGXQXND7no8gv8gux",
42
+ ),
43
+ },
44
+ localnet: {
45
+ cubicPool: new PublicKey("8iQtGj9mcUfFUGaiCpPy89swC3s8YTC8FhVZWfgeZhwu"),
46
+ singleTokenLiquidity: new PublicKey(
47
+ "7BpdUH1tzTSXLuQNo6YpjJ8Eagw8AkrS6cnkxiJdCFS2",
48
+ ),
49
+ protocolAdmin: new PublicKey(
50
+ "3jiojHZbjJQ7QLMGSTjFwxVEmx4NtuRy34nLAmsJME81",
51
+ ),
52
+ },
53
+ };
54
+
55
+ export const DEFAULT_RPC_ENDPOINT: Record<Network, string> = {
56
+ mainnet: "https://solana.drpc.org",
57
+ devnet: "https://api.devnet.solana.com",
58
+ localnet: "http://127.0.0.1:8899",
59
+ };
60
+
61
+ export const DEFAULT_RPC_ENDPOINTS: Record<Network, string[]> = {
62
+ mainnet: [
63
+ "https://solana.drpc.org",
64
+ "https://solana-rpc.publicnode.com",
65
+ "https://solana.api.pocket.network",
66
+ ],
67
+ devnet: ["https://api.devnet.solana.com"],
68
+ localnet: ["http://127.0.0.1:8899"],
69
+ };
70
+
71
+ export const DEFAULT_RPC_TIMEOUT_MS = 2_000;
@@ -0,0 +1,52 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+
3
+ /** Metadata describing a token. Populated by backend or local registry. */
4
+ export interface TokenInfo {
5
+ mint: PublicKey;
6
+ symbol: string;
7
+ name: string;
8
+ decimals: number;
9
+ logoUri?: string;
10
+ coingeckoId?: string;
11
+ }
12
+
13
+ /**
14
+ * Local fallback registry of well-known tokens. The backend registry takes
15
+ * precedence; this is used when the backend is unreachable.
16
+ */
17
+ export const KNOWN_TOKENS: Record<string, Omit<TokenInfo, "mint"> & { mint: string }> = {
18
+ SOL: {
19
+ mint: "So11111111111111111111111111111111111111112",
20
+ symbol: "SOL",
21
+ name: "Wrapped SOL",
22
+ decimals: 9,
23
+ logoUri:
24
+ "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png",
25
+ coingeckoId: "solana",
26
+ },
27
+ USDC: {
28
+ mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
29
+ symbol: "USDC",
30
+ name: "USD Coin",
31
+ decimals: 6,
32
+ logoUri:
33
+ "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png",
34
+ coingeckoId: "usd-coin",
35
+ },
36
+ USDT: {
37
+ mint: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
38
+ symbol: "USDT",
39
+ name: "Tether USD",
40
+ decimals: 6,
41
+ coingeckoId: "tether",
42
+ },
43
+ };
44
+
45
+ export function resolveKnownToken(mint: string): TokenInfo | undefined {
46
+ for (const t of Object.values(KNOWN_TOKENS)) {
47
+ if (t.mint === mint) {
48
+ return { ...t, mint: new PublicKey(t.mint) };
49
+ }
50
+ }
51
+ return undefined;
52
+ }