feat: add @solisting/sdk helpers and unit tests

Add hand-written SDK helper files (pda.ts, listing.ts, order.ts) with
GPA-based account fetching, discriminator filters, PDA derivation helpers,
and escrow ID derivation. Add pda.test.ts with 4 unit tests (all passing).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
thesn10
2026-06-24 22:48:24 +02:00
parent 825dad30c0
commit b6722ee83b
4 changed files with 185 additions and 0 deletions

30
sdk/src/pda.ts Normal file
View File

@@ -0,0 +1,30 @@
import { address, getAddressEncoder, type Address, type ProgramDerivedAddress } from '@solana/kit'
import { findListingAccountPda, findOrderAccountPda } from './generated/solisting/src/generated/index.js'
const PROGRAM_ADDRESS = address('DzwUAbpRvqcbA8QsEkRbZeXG4TEho5782cMySodrUHBU')
export async function findListingPda(
seller: Address,
listingId: bigint,
): Promise<ProgramDerivedAddress> {
return findListingAccountPda({ seller, listingId }, { programAddress: PROGRAM_ADDRESS })
}
export async function findOrderPda(
listingAccount: Address,
buyer: Address,
orderId: bigint,
): Promise<ProgramDerivedAddress> {
return findOrderAccountPda({ listingAccount, buyer, orderId }, { programAddress: PROGRAM_ADDRESS })
}
/**
* Replicates the program's escrow_id derivation:
* u64::from_le_bytes(order_pda.to_bytes()[0..8])
* Must match exactly — used when building create_order instructions.
*/
export function deriveEscrowId(orderPda: Address): bigint {
const bytes = getAddressEncoder().encode(orderPda) // 32-byte Uint8Array
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
return view.getBigUint64(0, true) // little-endian, first 8 bytes
}