@epicentral/sos-sdk 0.2.7 → 0.2.8

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.
@@ -1,4 +1,6 @@
1
1
  import { address, type Address } from "@solana/kit";
2
+ import { fetchAddressLookupTable } from "@solana-program/address-lookup-table";
3
+ import { PROGRAM_ID } from "./program";
2
4
  import type { KitRpc } from "./types";
3
5
 
4
6
  export const LOOKUP_TABLE_ADDRESSES: Record<"devnet" | "mainnet", Address | null> = {
@@ -30,3 +32,81 @@ export async function getLookupTableAccount(
30
32
  const result = await rpcWithLookupTable.getAddressLookupTable(lookupTableAddress).send();
31
33
  return result.value ?? null;
32
34
  }
35
+
36
+ /** Result of verifying that a lookup table is correct for the current option program */
37
+ export interface VerifyLookupTableResult {
38
+ /** True if the lookup table exists on-chain and contains the current program ID */
39
+ valid: boolean;
40
+ /** Whether the lookup table account was found on-chain */
41
+ foundOnChain: boolean;
42
+ /** Whether the Option Program ID is present in the table's addresses */
43
+ programIdInTable: boolean;
44
+ /** If valid is false, addresses that were required but missing from the table */
45
+ missingAddresses?: Address[];
46
+ /** Human-readable reason when valid is false */
47
+ reason?: string;
48
+ }
49
+
50
+ /**
51
+ * Verifies that the given lookup table is correct for the current Option Program.
52
+ * Ensures:
53
+ * 1. The lookup table exists on-chain
54
+ * 2. The table contains the current program ID (from client/program)
55
+ *
56
+ * Use this before sending transactions to avoid using a stale or wrong ALT.
57
+ *
58
+ * @param rpc - RPC client (must support getAddressLookupTable)
59
+ * @param lookupTableAddress - ALT address to verify (e.g. from getLookupTableAddressForNetwork)
60
+ * @param requiredAddresses - Optional extra addresses that must be in the table (e.g. key PDAs). PROGRAM_ID is always required.
61
+ * @returns Verification result with valid flag and details
62
+ */
63
+ export async function verifyLookupTableForProgram(
64
+ rpc: KitRpc,
65
+ lookupTableAddress: Address | null,
66
+ requiredAddresses?: Address[]
67
+ ): Promise<VerifyLookupTableResult> {
68
+ if (!lookupTableAddress) {
69
+ return {
70
+ valid: false,
71
+ foundOnChain: false,
72
+ programIdInTable: false,
73
+ reason: "No lookup table address configured for this network",
74
+ };
75
+ }
76
+
77
+ let tableAddresses: Address[];
78
+ try {
79
+ const { data } = await fetchAddressLookupTable(rpc, lookupTableAddress);
80
+ tableAddresses = data.addresses as Address[];
81
+ } catch {
82
+ return {
83
+ valid: false,
84
+ foundOnChain: false,
85
+ programIdInTable: false,
86
+ reason: "Lookup table not found on-chain or RPC error",
87
+ };
88
+ }
89
+
90
+ const programIdStr = PROGRAM_ID;
91
+ const set = new Set(tableAddresses.map((a) => (typeof a === "string" ? a : String(a))));
92
+ const programIdInTable = set.has(programIdStr);
93
+
94
+ const required = requiredAddresses ?? [];
95
+ const allRequired = [programIdStr as Address, ...required];
96
+ const missingAddresses = allRequired.filter(
97
+ (addr) => !set.has(typeof addr === "string" ? addr : String(addr))
98
+ );
99
+
100
+ const valid = programIdInTable && missingAddresses.length === 0;
101
+
102
+ return {
103
+ valid,
104
+ foundOnChain: true,
105
+ programIdInTable,
106
+ ...(missingAddresses.length > 0 && { missingAddresses: missingAddresses as Address[] }),
107
+ ...(!valid &&
108
+ (!programIdInTable
109
+ ? { reason: "Lookup table does not contain the current Option Program ID" }
110
+ : { reason: `Lookup table is missing required addresses: ${missingAddresses.join(", ")}` })),
111
+ };
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epicentral/sos-sdk",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "private": false,
5
5
  "description": "Solana Option Standard SDK. The frontend-first SDK for Native Options Trading on Solana. Created by Epicentral Labs.",
6
6
  "type": "module",