-
Notifications
You must be signed in to change notification settings - Fork 7k
Update surf-liquid TVL adapter with V2/V3 vault support and staking #18401
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
rohansingh4
wants to merge
4
commits into
DefiLlama:main
Choose a base branch
from
rohansingh4:update-surf-liquid-tvl
base: main
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.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f124e99
Update surf-liquid TVL adapter with V2/V3 vault support and staking
rohansingh4 e90db2a
Merge staking into TVL for a single combined metric
rohansingh4 ccfb280
Move SURF staking back to separate export, add V3 hallmark
rohansingh4 241a0d7
Add doublecounted/misrepresentedTokens flags, harden V2 guard
rohansingh4 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 |
|---|---|---|
| @@ -1,24 +1,78 @@ | ||
| const target = "0x1D283b668F947E03E8ac8ce8DA5505020434ea0E"; | ||
| const V2_FACTORY = "0x1D283b668F947E03E8ac8ce8DA5505020434ea0E"; | ||
| const V3_FACTORY = "0xf1d64dee9f8e109362309a4bfbb523c8e54fa1aa"; | ||
| const SURF_STAKING = "0xB0fDFc081310A5914c2d2c97e7582F4De12FA9d6"; | ||
| const SURF_TOKEN = "0xcdca2eaae4a8a6b83d7a3589946c2301040dafbf"; | ||
| const USDC = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"; | ||
| const WETH = "0x4200000000000000000000000000000000000006"; | ||
| const CBBTC = "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf"; | ||
| const ASSETS = [USDC, WETH, CBBTC]; | ||
| const ZERO_ADDR = "0x0000000000000000000000000000000000000000"; | ||
|
|
||
| async function tvl(api) { | ||
| const tokensAndOwners = []; | ||
|
|
||
| // V2 Vaults: enumerate via factory, read Morpho ERC-4626 positions | ||
| const totalV2 = await api.call({ abi: "uint256:getTotalVaults", target: V2_FACTORY }); | ||
| const v2Infos = await api.multiCall({ | ||
| abi: "function getVaultInfo(uint256) view returns (address, address, address, uint256, bytes32, uint256)", | ||
| calls: [...Array(Number(totalV2)).keys()].map((i) => ({ target: V2_FACTORY, params: [i] })), | ||
| }); | ||
| const v2Owners = v2Infos.map((info) => info[0]); | ||
| const v2MorphoVaults = await api.multiCall({ | ||
| abi: "address:currentVault", | ||
| calls: v2Owners.map((target) => ({ target })), | ||
| }); | ||
| for (let i = 0; i < v2Owners.length; i++) { | ||
| if (v2MorphoVaults[i] !== ZERO_ADDR) { | ||
| tokensAndOwners.push([v2MorphoVaults[i], v2Owners[i]]); | ||
| } | ||
| } | ||
|
|
||
| // V3 Vaults: discover via event logs, read Morpho ERC-4626 positions per asset | ||
| const currentBlock = api.block || await api.getBlock(); | ||
| const v3Logs = await api.getLogs({ | ||
| target: V3_FACTORY, | ||
| eventAbi: "event VaultDeployed(address indexed vaultAddress, address indexed owner, address indexed pool, bytes32 marketId, uint256 chainId)", | ||
| onlyArgs: true, | ||
| fromBlock: 38856207, | ||
| toBlock: currentBlock, | ||
| }); | ||
| const v3Vaults = v3Logs.map((l) => l.vaultAddress); | ||
|
|
||
| for (const asset of ASSETS) { | ||
| const morphoVaults = await api.multiCall({ | ||
| abi: "function assetToVault(address) view returns (address)", | ||
| calls: v3Vaults.map((vault) => ({ target: vault, params: [asset] })), | ||
| }); | ||
| for (let i = 0; i < v3Vaults.length; i++) { | ||
| if (morphoVaults[i] && morphoVaults[i] !== ZERO_ADDR) { | ||
| tokensAndOwners.push([morphoVaults[i], v3Vaults[i]]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| await api.sumTokens({ tokensAndOwners }); | ||
| } | ||
|
|
||
| async function staking(api) { | ||
| // SURF staking contract | ||
| const totalStaked = await api.call({ abi: "uint256:totalStaked", target: SURF_STAKING }); | ||
| api.add(SURF_TOKEN, totalStaked); | ||
|
|
||
| // CreatorBid SURF subscriptions (SURF locked in the token contract) | ||
| const subscribed = await api.call({ | ||
| abi: "function balanceOf(address) view returns (uint256)", | ||
| target: SURF_TOKEN, | ||
| params: [SURF_TOKEN], | ||
| }); | ||
| api.add(SURF_TOKEN, subscribed); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please move the SURF token tracking back under the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, also when will numbers be updated and depreciation tag removed? |
||
| } | ||
|
|
||
| module.exports = { | ||
| methodology: "Counts the morpho deposits of each Surf Liquid vault.", | ||
| methodology: "TVL counts Morpho vault deposits across V2 and V3 Surf Liquid vaults. Staking includes SURF staked and SURF subscriptions.", | ||
| hallmarks: [["2025-11-30", "V3 factory launched"]], | ||
| base: { | ||
| tvl: async (api) => { | ||
| const vaults = await api.call({ abi: "uint256:getTotalVaults", target }); | ||
| const vaultInfos = await api.multiCall({ | ||
| abi: "function getVaultInfo(uint256) view returns (address, address, address, uint256, bytes32, uint256)", | ||
| calls: [...Array(Number(vaults)).keys()].map((i) => ({ target, params: [i] })), | ||
| }); | ||
| const owners = vaultInfos.map(info => info[0]) | ||
| const morphoVaults = await api.multiCall({ | ||
| abi: "address:currentVault", | ||
| calls: owners.map(target => ({ target })) | ||
| }) | ||
|
|
||
| await api.sumTokens({ | ||
| tokens: [...new Set(morphoVaults)], | ||
| owners | ||
| }) | ||
| }, | ||
| tvl, | ||
| staking, | ||
| }, | ||
RohanNero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
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.