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AA,EAAkB,CAAA;AAAA,MAClB;AAAA,KACJ;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,sBAAsB,MAAA,EAIV;AACd,IAAA,IAAI,CAAC,IAAA,CAAK,YAAA,IAAgB,CAAC,IAAA,CAAK,aAAa,OAAA,EAAS;AAClD,MAAA,MAAM,IAAI,MAAM,yCAAyC,CAAA;AAAA,IAC7D;AAIA,IAAA,OAAO,IAAA,CAAK,aAAa,aAAA,CAAc;AAAA,MACnC,SAAS,IAAA,CAAK,iBAAA;AAAA,MACd,GAAA,EAAKC,aAAA,CAAS,CAAC,sCAAsC,CAAC,CAAA;AAAA,MACtD,YAAA,EAAc,aAAA;AAAA,MACd,IAAA,EAAM,CAAC,MAAA,CAAO,SAAA,EAAW,OAAO,SAAS,CAAA;AAAA,MACzC,KAAA,EAAO,KAAK,YAAA,CAAa,KAAA;AAAA,MACzB,OAAA,EAAS,KAAK,YAAA,CAAa;AAAA,KAC9B,CAAA;AAAA,EACL;AACJ","file":"chunk-7VYOPNCI.cjs","sourcesContent":["\nimport { type Address, type PublicClient } from 'viem';\nimport { MySBTABI } from '@aastar/core';\n\n/**\n * Check if user holds MySBT token (identity verification).\n *\n * Does NOT swallow read errors: `balanceOf` returns 0 for a non-holder, so any\n * thrown error is an RPC/transport/contract failure — masking it as\n * `{ hasSBT: false }` would turn a transient RPC blip into a false \"no SBT\" and\n * wrongly fail eligibility checks. The error propagates so the caller can retry\n * or surface \"couldn't determine\" rather than \"no SBT\".\n */\nexport async function checkMySBT(\n    client: any,\n    sbtAddress: Address,\n    user: Address\n): Promise<{ hasSBT: boolean; balance: bigint }> {\n    const balance = await client.readContract({\n        address: sbtAddress,\n        abi: MySBTABI,\n        functionName: 'balanceOf',\n        args: [user]\n    }) as bigint;\n\n    return { hasSBT: balance > 0n, balance };\n}\n\n/**\n * Fetch MySBT token ID for a specific user.\n * MySBT exposes `getUserSBT(address) -> uint256` (alias of the `userToSBT`\n * mapping), which returns the user's tokenId or 0 when they hold no SBT.\n *\n * Returns the tokenId, or `null` ONLY for the genuine \"no SBT\" sentinel (id == 0).\n * Read errors are NOT swallowed (see {@link checkMySBT}): a transient RPC failure\n * must not be reported as \"no SBT\" (a false negative for eligibility). The error\n * propagates to the caller.\n */\nexport async function getMySBTId(\n    client: any,\n    sbtAddress: Address,\n    user: Address\n): Promise<bigint | null> {\n    const tokenId = await client.readContract({\n        address: sbtAddress,\n        abi: MySBTABI,\n        functionName: 'getUserSBT',\n        args: [user]\n    }) as bigint;\n\n    // tokenId 0 is the contract's sentinel for \"no SBT\" (ids start at 1).\n    return tokenId > 0n ? tokenId : null;\n}\n","\nexport * from './mysbt.js';\n\nimport { createAAStarPublicClient, ReputationSystemABI, type PublicClient, type WalletClient } from '@aastar/core';\nimport { type Address, type Hash, parseAbi } from 'viem';\n\nexport class ReputationClient {\n    /** @internal */\n    private walletClient?: WalletClient;\n\n    /**\n     * Initialize ReputationClient\n     * @param client The public client for queries\n     * @param reputationAddress The address of the reputation system contract\n     * @param walletClient Optional wallet client for write operations\n     */\n    constructor(\n        private client: PublicClient, \n        private reputationAddress: Address,\n        walletClient?: WalletClient\n    ) {\n        this.walletClient = walletClient;\n    }\n\n    /**\n     * Compute reputation score for a user\n     */\n    async computeScore(user: Address, communities: Address[], ruleIds: `0x${string}`[][], activities: bigint[][]): Promise<bigint> {\n        return this.client.readContract({\n            address: this.reputationAddress,\n            abi: ReputationSystemABI as any,\n            functionName: 'computeScore',\n            args: [user, communities, ruleIds, activities]\n        }) as Promise<bigint>;\n    }\n\n    /**\n     * Get global reputation score for a user\n     * @param user User address\n     * @returns Reputation score\n     */\n    async getGlobalReputation(user: Address): Promise<number> {\n        // Try to read score, if fails (e.g. invalid contract), return 0\n        try {\n            const score = await this.computeScore(user, [], [], []);\n            return Number(score);\n        } catch (e) {\n            console.warn('Failed to read reputation from contract, defaulting to 0');\n            return 0;\n        }\n    }\n\n    /**\n     * Get credit limit based on reputation\n     * @param user User address\n     * @returns Credit limit in wei (Mock logic closely tied to Reputation)\n     */\n    async getCreditLimit(user: Address): Promise<bigint> {\n        const reputation = await this.getGlobalReputation(user);\n        \n        // Dynamic Credit Limit Logic:\n        // Base: 0\n        // Score > 50: +0.01 ETH\n        // Score > 100: +0.05 ETH\n        let limit = 0n;\n        if (reputation > 50) limit += 10000000000000000n; // 0.01 ETH\n        if (reputation > 100) limit += 40000000000000000n; // +0.04 -> 0.05 ETH\n\n        return limit;\n    }\n\n    /**\n     * Get reputation score breakdown\n     * @param user User address\n     * @returns Detailed reputation breakdown (Mock implementation awaiting contract V4)\n     */\n    async getReputationBreakdown(user: Address): Promise<{\n        baseScore: number;\n        stakingBonus: number;\n        activityBonus: number;\n        penaltyDeduction: number;\n        total: number;\n    }> {\n        const total = await this.getGlobalReputation(user);\n        \n        // Heuristic breakdown\n        return {\n            baseScore: Math.floor(total * 0.5),\n            stakingBonus: Math.floor(total * 0.3),\n            activityBonus: Math.floor(total * 0.2),\n            penaltyDeduction: 0,\n            total\n        };\n    }\n\n    /**\n     * Submit reputation proof (off-chain data to on-chain)\n     * @param params Proof parameters\n     * @returns Transaction hash\n     */\n    async submitReputationProof(params: {\n        proofType: 'github' | 'twitter' | 'on-chain-activity';\n        proofData: string;\n        signature: Hash;\n    }): Promise<Hash> {\n        if (!this.walletClient || !this.walletClient.account) {\n            throw new Error(\"Wallet client required to submit proofs\");\n        }\n\n        // Using a generic 'submitProof' signature for now\n        // In reality this would target the ReputationOracle or similar\n        return this.walletClient.writeContract({\n            address: this.reputationAddress,\n            abi: parseAbi(['function submitProof(string,bytes32)']),\n            functionName: 'submitProof',\n            args: [params.proofData, params.signature],\n            chain: this.walletClient.chain,\n            account: this.walletClient.account\n        });\n    }\n}\n"]}