@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
57 lines • 2.23 kB
TypeScript
/**
* @purpose Discount authorization helper for server-side signing
* @module utils/discountAuth
*
* Convenience wrapper that fetches member nonce + vault automatically,
* then delegates to slyvault's createDiscountAuth for signing.
*/
import { type Address } from '@solana/kit';
import { type MessageSigner, type SerializedDiscountAuth } from '@wuwei-labs/slyvault';
import { type SdkConfig } from './config';
export interface CreateDiscountParams {
/** Affiliate member state PDA address */
memberAddress: Address | string;
/** Borrower wallet address (discount is bound to this address) */
contextKey: Address | string;
/** Discount basis points (10000 = 100%) */
discountBps: number;
/** Seconds from now until discount expires */
expirySeconds: number;
/**
* The discount authority signer
*
* Accepts:
* - A KeyPairSigner from @solana/kit
* - A Uint8Array or number[] of 64 bytes (secret key)
* - A JSON stringified keypair: "[1,2,3,...64 bytes]"
*/
discountAuthority: MessageSigner | Uint8Array | number[] | string;
}
/**
* Sign and serialize a discount authorization. Server-side helper that
* lets a designated authority pre-grant a fee discount, which the holder
* can later attach to a vault deposit to redeem.
*
* @param params - Discount parameters
* @param config - Optional SDK configuration overrides
* @returns SerializedDiscountAuth ready for JSON API response
*
* @example
* ```typescript
* // Server-side: create discount for a borrower
* const auth = await createDiscount({
* memberAddress: 'AFFILIATE_MEMBER_PDA',
* contextKey: borrowerWallet,
* discountBps: 500, // 5%
* expirySeconds: 300, // 5 minutes
* discountAuthority: process.env.DISCOUNT_KEY, // JSON keypair string
* });
*
* // Return via API — all fields are JSON-safe strings/numbers
* res.json(auth);
* ```
*/
export declare function createDiscount(params: CreateDiscountParams, config?: Partial<SdkConfig>): Promise<SerializedDiscountAuth>;
export { deserializeDiscountAuth } from '@wuwei-labs/slyvault';
export type { SerializedDiscountAuth, MessageSigner } from '@wuwei-labs/slyvault';
//# sourceMappingURL=discountAuth.d.ts.map