@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
58 lines • 2 kB
TypeScript
/**
* @purpose Borrower account utilities for SRSLY
*
* Fetches borrower state data from the SRSLY program.
*/
import { type Address } from '@solana/kit';
import { type BorrowerState } from '../generated/codama/accounts';
/**
* Fetch borrower state from the SRSLY program
*
* Accepts either a borrower state PDA address OR a wallet address.
* If direct fetch fails, automatically derives the borrower state PDA
* from the address (treating it as a wallet) and retries.
*
* @param address - Borrower state address OR wallet address
* @param rpcUrl - Optional RPC endpoint URL. If not provided, uses RPC from global config
* @returns Borrower state with discounts, payment info, etc.
* @throws Error if borrower account not found or fetch fails
*
* @example
* ```typescript
* // Fetch by borrower state PDA address
* const borrower = await fetchBorrower('BorrowerStatePDA...');
*
* // Fetch by wallet address (auto-derives PDA)
* const borrower2 = await fetchBorrower('WalletAddress...');
*
* // With custom RPC
* const borrower3 = await fetchBorrower(
* 'WalletOrStateAddress...',
* 'https://api.devnet.solana.com'
* );
* ```
*/
export declare function fetchBorrower(address: Address | string, rpcUrl?: string): Promise<{
data: BorrowerState;
address: Address;
}>;
/**
* Fetch all borrower state accounts from the SRSLY program
*
* Uses getProgramAccounts with a discriminator filter to find all BorrowerState accounts.
*
* @param rpcUrl - Optional RPC endpoint URL. If not provided, uses RPC from global config
* @returns Array of borrower states with their addresses
*
* @example
* ```typescript
* const borrowers = await fetchAllBorrowers();
* console.log(`Found ${borrowers.length} borrowers`);
* borrowers.forEach(b => console.log(b.address, b.data.borrower));
* ```
*/
export declare function fetchAllBorrowers(rpcUrl?: string): Promise<Array<{
data: BorrowerState;
address: Address;
}>>;
//# sourceMappingURL=borrower.d.ts.map