-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add XOXNO Lending yield adapter (Stellar + MultiversX) #2753
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
mihaieremia
wants to merge
11
commits into
DefiLlama:master
Choose a base branch
from
mihaieremia:codex/xoxno-lending-yields
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.
+195
−5
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7e7d2a4
Add XOXNO lending yield adapter
mihaieremia 59c783b
fix(xoxno-lending): correct protocolId + add hub/spoke routing pools
mihaieremia a2e40fc
chore(xoxno-lending): drop fromAsset query from spoke URL fallback
mihaieremia 390a8ff
fix(xoxno-lending): allowlist routing rows so spoke reserves persist
mihaieremia 2f23de9
Merge branch 'master' into codex/xoxno-lending-yields
mihaieremia 9510872
Merge branch 'master' into codex/xoxno-lending-yields
mihaieremia 328d378
xoxno-lending: correct the User-Agent
mihaieremia e3c395d
xoxno-lending: restore the required User-Agent
mihaieremia 53efcb3
Merge branch 'master' into codex/xoxno-lending-yields
mihaieremia 46a6fdc
xoxno-lending: add MultiversX pools, and bound availableBorrowUsd by …
mihaieremia cb71089
ci: restore the pool table in adapter PR comments
mihaieremia 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
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,167 @@ | ||
| const API_BASE = 'https://api.xoxno.com'; | ||
| const HEADERS = { 'User-Agent': 'dune-analytics' }; | ||
| const REQUEST_TIMEOUT_MS = 5_000; | ||
|
|
||
| const CHAIN_CONFIGS = { | ||
| stellar: { | ||
| chain: 'Stellar', | ||
| exportPath: '/integrations/lending/stellar', | ||
| }, | ||
| elrond: { | ||
| // MultiversX is listed under its former name; 'MultiversX' is not a | ||
| // valid chain name. | ||
| chain: 'Elrond', | ||
| exportPath: '/integrations/lending/multiversx', | ||
| model: 'flat', | ||
| }, | ||
| }; | ||
|
|
||
| async function getExport(config) { | ||
| const response = await fetch(`${API_BASE}${config.exportPath}`, { | ||
| headers: HEADERS, | ||
| signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `XOXNO ${config.chain} lending export failed: ${response.status}` | ||
| ); | ||
| } | ||
|
|
||
| return response.json(); | ||
| } | ||
|
|
||
| function keepFinite(pool) { | ||
| return [ | ||
| pool.tvlUsd, | ||
| pool.apyBase, | ||
| pool.apyBaseBorrow, | ||
| pool.totalSupplyUsd, | ||
| pool.totalBorrowUsd, | ||
| ].every(Number.isFinite); | ||
| } | ||
|
|
||
| function decimalToPercent(value) { | ||
| return Number(value ?? 0) * 100; | ||
| } | ||
|
|
||
| async function apy() { | ||
| const pools = []; | ||
|
|
||
| for (const config of Object.values(CHAIN_CONFIGS)) { | ||
| const data = await getExport(config); | ||
| const chain = config.chain; | ||
| const chainSlug = chain.toLowerCase(); | ||
|
|
||
| if (config.model === 'flat') { | ||
| for (const market of Array.isArray(data.markets) ? data.markets : []) { | ||
| const cashUsd = Number(market.tvlCashUsd ?? 0); | ||
| pools.push({ | ||
| pool: `xoxno-lending-${chainSlug}-${market.poolId}`, | ||
| chain, | ||
| project: 'xoxno-lending', | ||
| symbol: market.symbol, | ||
| tvlUsd: cashUsd, | ||
| apyBase: decimalToPercent(market.supplyApy), | ||
| apyBaseBorrow: decimalToPercent(market.borrowApy), | ||
| totalSupplyUsd: Number(market.suppliedUsd ?? 0), | ||
| totalBorrowUsd: Number(market.borrowedUsd ?? 0), | ||
| availableBorrowUsd: cashUsd, | ||
| ltv: Number(market.ltv ?? 0), | ||
| borrowable: Boolean(market.borrowable), | ||
| underlyingTokens: [market.token], | ||
| borrowToken: market.token, | ||
| // No 1:1 pool token exists, and the handler's fallback only | ||
| // recognises 0x addresses. | ||
| token: null, | ||
| url: market.url, | ||
| }); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| const hubMarkets = Array.isArray(data.hubMarkets) ? data.hubMarkets : []; | ||
| const spokeMarkets = Array.isArray(data.spokeMarkets) | ||
| ? data.spokeMarkets | ||
| : []; | ||
|
|
||
| // Liquidity and APY live on the hub, so an asset on two hubs is two pools. | ||
| for (const market of hubMarkets) { | ||
| const tvlUsd = Number(market.tvlUsd ?? 0); | ||
| pools.push({ | ||
| pool: `xoxno-lending-${chainSlug}-${market.poolId}`, | ||
| chain, | ||
| project: 'xoxno-lending', | ||
| symbol: market.symbol, | ||
| poolMeta: market.hubName || `Hub ${market.hubId}`, | ||
| tvlUsd, | ||
| apyBase: decimalToPercent(market.supplyApy), | ||
| apyBaseBorrow: decimalToPercent(market.borrowApy), | ||
| totalSupplyUsd: Number(market.suppliedUsd ?? 0), | ||
| totalBorrowUsd: Number(market.borrowedUsd ?? 0), | ||
| availableBorrowUsd: tvlUsd, | ||
| underlyingTokens: [market.token], | ||
| borrowToken: market.token, | ||
| token: null, | ||
| url: | ||
| market.url || | ||
| `https://xoxno.com/defi/lending/hub/${market.hubId}`, | ||
| }); | ||
| } | ||
|
|
||
| // Spoke `availableBorrowUsd` is borrow-cap headroom, which routinely | ||
| // exceeds the liquidity actually present: XLM reported $5.25M against | ||
| // $1.5K of hub cash. | ||
| const hubCashUsd = new Map( | ||
| hubMarkets.map((market) => [ | ||
| `${market.hubId}-${market.token}`, | ||
| Number(market.tvlCashUsd ?? 0), | ||
| ]) | ||
| ); | ||
|
|
||
| // Spokes are the risk/routing layer with no APY of their own. Emitted as | ||
| // `routing_reserve`, which skips the finite/APY filter below. | ||
| for (const spoke of spokeMarkets) { | ||
| const pool = { | ||
| pool: `xoxno-lending-${chainSlug}-spoke-${spoke.poolId}`, | ||
| chain, | ||
| project: 'xoxno-lending', | ||
| symbol: spoke.symbol, | ||
| poolKind: 'routing_reserve', | ||
| poolMeta: `${spoke.hubName || `Hub ${spoke.hubId}`} / ${ | ||
| spoke.spokeName || `Spoke ${spoke.spokeId}` | ||
| }`, | ||
| ltv: Number(spoke.ltv ?? 0), | ||
| borrowable: Boolean(spoke.borrowable), | ||
| routeGroupKey: String(spoke.spokeId), | ||
| underlyingTokens: [spoke.token], | ||
| token: null, | ||
| url: | ||
| spoke.url || | ||
| `https://xoxno.com/defi/lending/spoke/${spoke.spokeId}/hub/${spoke.hubId}/${spoke.token}`, | ||
| }; | ||
|
|
||
| if (spoke.borrowable) { | ||
| pool.totalBorrowUsd = Number(spoke.totalBorrowUsd ?? 0); | ||
| pool.availableBorrowUsd = Math.min( | ||
| Number(spoke.availableBorrowUsd ?? 0), | ||
| hubCashUsd.get(`${spoke.hubId}-${spoke.token}`) ?? 0 | ||
| ); | ||
| pool.borrowToken = spoke.token; | ||
| } | ||
|
|
||
| pools.push(pool); | ||
| } | ||
| } | ||
|
|
||
| return pools.filter( | ||
| (pool) => pool.poolKind === 'routing_reserve' || keepFinite(pool) | ||
| ); | ||
| } | ||
|
|
||
| module.exports = { | ||
| protocolId: '8109', | ||
| timetravel: false, | ||
| apy, | ||
| url: 'https://xoxno.com/defi/lending', | ||
| }; | ||
|
mihaieremia marked this conversation as resolved.
|
||
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
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.