UNPKG

@wuwei-labs/srsly

Version:
68 lines 2.66 kB
"use strict"; /** * @purpose Create a pending affiliate (Affiliate member) for SRSLY vault * * Wraps slyvault's initMember instruction with Affiliate type pre-configured. * Auto-fetches vault and nonce from parent member state. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.createAffiliate = createAffiliate; const kit_1 = require("@solana/kit"); const slyvault_1 = require("@wuwei-labs/slyvault"); const config_1 = require("../utils/config"); /** * Register a pending affiliate under a parent Normal member. The * affiliate must be activated via `approveAffiliate` before earnings flow. * * @param params - Affiliate creation parameters * @param config - Optional SDK configuration overrides * @returns Prepared instruction(s) * * @example * ```typescript * import { createAffiliate } from '@wuwei-labs/srsly'; * * // Create affiliate linked to parent member * const ix = await createAffiliate({ * affiliate: wallet, * parentMemberState: "PARENT_MEMBER_STATE_PDA", * discountAuthority: "OPTIONAL_DISCOUNT_SIGNER", // optional, defaults to main authority * // vault and nonce are auto-fetched from parent state * }); * ``` */ async function createAffiliate(params, config) { const finalConfig = (0, config_1.mergeConfig)(config); if (!params.affiliate) throw new Error('affiliate is required'); if (!params.parentMemberState) throw new Error('parentMemberState is required'); // Fetch parent member state to get vault and nonce const { data: parentState } = await (0, slyvault_1.fetchMember)((0, kit_1.address)(params.parentMemberState), finalConfig.rpcUrl); // Validate parent is Normal type with affiliateEnabled if (parentState.memberType.__kind !== 'Normal') { throw new Error('Parent member is not a Normal member type'); } if (!parentState.memberType.affiliateEnabled) { throw new Error('Parent member does not have affiliates enabled'); } // Get vault and nonce from parent state const vaultAddress = parentState.vault; const parentNonce = parentState.nonce; // Call slyvault initMember with Affiliate type pre-configured return (0, slyvault_1.initMember)({ member: params.affiliate, vault: vaultAddress, nonce: params.nonce, memberType: { __kind: 'Affiliate', parentMemberNonce: parentNonce, percentageBps: 0, claimableBalance: 0n, isActive: false, }, discountAuthority: params.discountAuthority, computeUnits: params.computeUnits, }); } //# sourceMappingURL=createAffiliate.js.map