From a0d6b4cd5a2b67d746d347ae386482adac61b784 Mon Sep 17 00:00:00 2001 From: ZaK3939 Date: Sat, 18 Oct 2025 11:12:15 +0800 Subject: [PATCH 1/2] feat: Add Phi Protocol adapter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add DeFiLlama adapter for Phi Protocol - an open credentialing protocol for on-chain identity on Base network. - Supports PhiRewards, Cred, and PhiEthFactory core contracts - Dynamically tracks all hook and PhiEth token contracts deployed by PhiEthFactory - Uses correct PhiEthCreated event ABI based on actual transaction analysis - Efficient fromBlock starting from Cred contract deployment (block 20990053) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- projects/phi/index.js | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 projects/phi/index.js diff --git a/projects/phi/index.js b/projects/phi/index.js new file mode 100644 index 00000000000..b6b470f2dab --- /dev/null +++ b/projects/phi/index.js @@ -0,0 +1,86 @@ +const { sumTokensExport } = require('../helper/unwrapLPs'); +const { nullAddress } = require('../helper/unwrapLPs'); +const { getLogs } = require('../helper/cache/getLogs'); + +// Phi Protocol - On-chain identity and credentialing protocol +// Based on https://docs.phi.box/explore-phi/ + +const PHI_CONTRACTS = { + base: { + rewards: "0x4E6Ba9980E66DeD2141a6ab724A1FBbbcC0FD309", // PhiRewards contract + cred: "0xbe28Ee6415A82f3BE336097211bE79af6Ce9586c", // Cred contract + phiEthFactory: "0x7C9E79683D018830B3a8bfAA1C7eA1b4835007D0", // PhiEthFactory contract + fromBlock: 20990053, // Base deployment block - Cred contract deployment + } +}; + +async function getDeployedHooks(api, contracts) { + // Get all hook contracts deployed by PhiEthFactory + const logs = await getLogs({ + api, + target: contracts.phiEthFactory, + fromBlock: contracts.fromBlock, + eventAbi: 'event PhiEthCreated(address indexed phiEthToken, address indexed strategy, address indexed phiEthHook, address creator)', + onlyArgs: true, + }); + + // Extract PhiEth hook addresses and token addresses from factory events + const hookAddresses = logs.map(log => log.phiEthHook); + const tokenAddresses = logs.map(log => log.phiEthToken); + + return { hookAddresses, tokenAddresses }; +} + +async function tvl(api) { + const chain = api.chain; + const contracts = PHI_CONTRACTS[chain]; + + if (!contracts) { + return {}; + } + + // Phi Protocol TVL calculation + const tokensAndOwners = []; + + // Add ETH holdings from main contracts + if (contracts.rewards) { + tokensAndOwners.push([nullAddress, contracts.rewards]); + } + + if (contracts.phiEthFactory) { + tokensAndOwners.push([nullAddress, contracts.phiEthFactory]); + } + + // Get all deployed hook contracts and tokens from PhiEthFactory + try { + const { hookAddresses, tokenAddresses } = await getDeployedHooks(api, contracts); + + // Add ETH holdings from all deployed hook contracts + hookAddresses.forEach(hookAddress => { + tokensAndOwners.push([nullAddress, hookAddress]); + }); + + // Add ETH holdings from all deployed PhiEth token contracts + tokenAddresses.forEach(tokenAddress => { + tokensAndOwners.push([nullAddress, tokenAddress]); + }); + + } catch (error) { + // If we can't get factory events, continue with core contracts only + console.warn('Could not fetch deployed hooks:', error.message); + } + + return api.sumTokens({ tokensAndOwners }); +} + +module.exports = { + methodology: `Phi Protocol is an open credentialing protocol for on-chain identity. TVL is calculated by summing ETH held in core protocol contracts (PhiRewards, PhiEthFactory) and all hook contracts and PhiEth token contracts deployed by PhiEthFactory on Base network.`, + base: { + tvl, + }, + timetravel: false, + misrepresentedTokens: true, + hallmarks: [ + // Add significant events for Phi Protocol when available + ], +}; \ No newline at end of file From 5e4d14862a469b1273b57332b00fe6d08bdf37b3 Mon Sep 17 00:00:00 2001 From: ZaK3939 Date: Wed, 22 Oct 2025 15:17:10 +0800 Subject: [PATCH 2/2] refactor(phi): remove try-catch block for cleaner error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- projects/phi/index.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/projects/phi/index.js b/projects/phi/index.js index b6b470f2dab..79fa39afe36 100644 --- a/projects/phi/index.js +++ b/projects/phi/index.js @@ -52,23 +52,17 @@ async function tvl(api) { } // Get all deployed hook contracts and tokens from PhiEthFactory - try { - const { hookAddresses, tokenAddresses } = await getDeployedHooks(api, contracts); - - // Add ETH holdings from all deployed hook contracts - hookAddresses.forEach(hookAddress => { - tokensAndOwners.push([nullAddress, hookAddress]); - }); - - // Add ETH holdings from all deployed PhiEth token contracts - tokenAddresses.forEach(tokenAddress => { - tokensAndOwners.push([nullAddress, tokenAddress]); - }); - - } catch (error) { - // If we can't get factory events, continue with core contracts only - console.warn('Could not fetch deployed hooks:', error.message); - } + const { hookAddresses, tokenAddresses } = await getDeployedHooks(api, contracts); + + // Add ETH holdings from all deployed hook contracts + hookAddresses.forEach(hookAddress => { + tokensAndOwners.push([nullAddress, hookAddress]); + }); + + // Add ETH holdings from all deployed PhiEth token contracts + tokenAddresses.forEach(tokenAddress => { + tokensAndOwners.push([nullAddress, tokenAddress]); + }); return api.sumTokens({ tokensAndOwners }); }