-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add phoenix-protocol (phUSD staking) #2682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gititGoro
wants to merge
2
commits into
DefiLlama:master
Choose a base branch
from
Behodler:add-phoenix-protocol
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+127
−0
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # phoenix-protocol | ||
|
|
||
| Surfaces the Phoenix Protocol phUSD staking pool (Ethereum mainnet) on DefiLlama yields. | ||
|
|
||
| Stakers deposit phUSD into the staking contract and earn two emission-based rewards: | ||
|
|
||
| - **USDC** — distributed via linear depletion. APY = `rewardBalance / depletionDuration` annualized, divided by USD TVL. | ||
| - **phUSD** — auto-minted to hit the contract's `desiredAPYBps` target. APY = `desiredAPYBps / 100` directly. | ||
|
|
||
| phUSD is priced from the Balancer V3 phUSD/sUSDS pool (50/50 weighted): the spot ratio gives phUSD-in-sUSDS, and the sUSDS ERC4626 `convertToAssets` rate converts to USDS (treated as $1). USDC is hardcoded to $1. If pricing fails, the adapter falls back to a $1 peg with a warning. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| const sdk = require('@defillama/sdk'); | ||
|
|
||
| const CHAIN = 'ethereum'; | ||
| const PHLIMBO = '0x3984eBC84d45a889dDAc595d13dc0aC2E54819F4'; | ||
| const PHUSD = '0xf3B5B661b92B75C71fA5Aba8Fd95D7514A9CD605'; | ||
| const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'; | ||
| const SUSDS = '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD'; | ||
| const BALANCER_POOL = '0x642BB6860b4776CC10b26B8f361Fd139E7f0db04'; | ||
| const BALANCER_VAULT = '0xbA1333333333a1BA1108E8412f11850A5C319bA9'; | ||
|
|
||
| const SECONDS_PER_YEAR = 31_536_000; | ||
|
|
||
| const getPoolTokensAbi = { | ||
| inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], | ||
| name: 'getPoolTokens', | ||
| outputs: [{ internalType: 'contract IERC20[]', name: '', type: 'address[]' }], | ||
| stateMutability: 'view', | ||
| type: 'function', | ||
| }; | ||
|
|
||
| const getCurrentLiveBalancesAbi = { | ||
| inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], | ||
| name: 'getCurrentLiveBalances', | ||
| outputs: [{ internalType: 'uint256[]', name: '', type: 'uint256[]' }], | ||
| stateMutability: 'view', | ||
| type: 'function', | ||
| }; | ||
|
|
||
| const callView = (target, abi, params) => | ||
| sdk.api.abi | ||
| .call({ target, abi, params, chain: CHAIN }) | ||
| .then((r) => r.output); | ||
|
|
||
| const getPhUsdPrice = async () => { | ||
| try { | ||
| const [tokens, balances, sharesToAssets] = await Promise.all([ | ||
| callView(BALANCER_VAULT, getPoolTokensAbi, BALANCER_POOL), | ||
| callView(BALANCER_VAULT, getCurrentLiveBalancesAbi, BALANCER_POOL), | ||
| callView(SUSDS, 'function convertToAssets(uint256) view returns (uint256)', [ | ||
| '1000000000000000000', | ||
| ]), | ||
| ]); | ||
|
|
||
| const lc = (a) => String(a).toLowerCase(); | ||
| const idxSusds = tokens.findIndex((t) => lc(t) === lc(SUSDS)); | ||
| const idxPhusd = tokens.findIndex((t) => lc(t) === lc(PHUSD)); | ||
| if (idxSusds < 0 || idxPhusd < 0) { | ||
| throw new Error('phUSD/sUSDS not found in Balancer pool'); | ||
| } | ||
|
|
||
| const sUsdsBalance = Number(balances[idxSusds]); | ||
| const phUsdBalance = Number(balances[idxPhusd]); | ||
| if (!(sUsdsBalance > 0) || !(phUsdBalance > 0)) { | ||
| throw new Error('Balancer pool has zero balance'); | ||
| } | ||
|
|
||
| const phUsdPriceInSUsds = sUsdsBalance / phUsdBalance; | ||
| const usdsPerSUsds = Number(sharesToAssets) / 1e18; | ||
| return phUsdPriceInSUsds * usdsPerSUsds; | ||
| } catch (err) { | ||
| console.warn( | ||
| `[phoenix-protocol] phUSD pricing failed (${err.message}); falling back to $1` | ||
| ); | ||
| return 1; | ||
| } | ||
| }; | ||
|
|
||
| const apy = async () => { | ||
| const [ | ||
| totalStaked, | ||
| desiredAPYBps, | ||
| rewardBalance, | ||
| depletionDuration, | ||
| phUsdPrice, | ||
| ] = await Promise.all([ | ||
| callView(PHLIMBO, 'uint256:totalStaked'), | ||
| callView(PHLIMBO, 'uint256:desiredAPYBps'), | ||
| callView(PHLIMBO, 'uint256:rewardBalance'), | ||
| callView(PHLIMBO, 'uint256:depletionDuration'), | ||
| getPhUsdPrice(), | ||
| ]); | ||
|
|
||
| const stakedAmount = Number(totalStaked) / 1e18; | ||
| const tvlUsd = stakedAmount * phUsdPrice; | ||
|
|
||
| let usdcApy = 0; | ||
| if (tvlUsd > 0 && Number(depletionDuration) > 0) { | ||
| const usdcPerYearUsd = | ||
| ((Number(rewardBalance) / Number(depletionDuration)) * SECONDS_PER_YEAR) / | ||
| 1e6; | ||
| usdcApy = (usdcPerYearUsd / tvlUsd) * 100; | ||
| } | ||
| const phusdApy = Number(desiredAPYBps) / 100; | ||
| const apyReward = usdcApy + phusdApy; | ||
|
|
||
| return [ | ||
| { | ||
| pool: `${PHLIMBO}-ethereum`.toLowerCase(), | ||
| chain: 'Ethereum', | ||
| project: 'phoenix-protocol', | ||
| symbol: 'phUSD', | ||
| tvlUsd, | ||
| apyBase: null, | ||
| apyReward, | ||
| rewardTokens: [USDC, PHUSD], | ||
| underlyingTokens: [PHUSD], | ||
| poolMeta: 'Staking', | ||
| url: 'https://phusd.behodler.io/staking', | ||
| }, | ||
| ]; | ||
| }; | ||
|
|
||
| module.exports = { | ||
| timetravel: false, | ||
| apy, | ||
| url: 'https://phusd.behodler.io/staking', | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.