Skip to content

feat: add yuzu-finance adapter #1840

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

Merged
merged 4 commits into from
Apr 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/adaptors/yuzu-finance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const utils = require('../utils');

const YUZU_API_URL_BASE = 'https://mainnet-api.yuzu.finance/v1';

async function getPools() {
const pageSize = 100;
let currentPage = 1;
let allPools = [];

while (true) {
const response = await utils.getData(
`${YUZU_API_URL_BASE}/pools?page=${currentPage}&pageSize=${pageSize}`
);

if (!response?.data || response.data.length === 0) {
break;
}

allPools = allPools.concat(response.data);

// If we've fetched all pools, break
if (allPools.length >= response.total) {
break;
}

currentPage++;
}

return allPools;
}

async function getTokens() {
const response = await utils.getData(
`${YUZU_API_URL_BASE}/tokens?pageSize=100`
);

if (!response?.data) {
return [];
}

return response.data;
}

async function main() {
// We're not using on-chain RPC requests here due to the rate limiting and instability of both official and third party RPCs and using our own load-balanced API.
const pools = await getPools();
const tokens = await getTokens();

const defiLlamaPools = pools
.map((pool) => {
const token0 = tokens.find((token) => token.metadata === pool.token0);
const token1 = tokens.find((token) => token.metadata === pool.token1);
const symbol =
token0 && token1 ? `${token0.symbol}-${token1.symbol}` : 'unknown';

return {
pool: pool.poolAddr + '-move',
chain: utils.formatChain('move'),
project: 'yuzu-finance',
symbol,
tvlUsd: parseFloat(pool.tvl),
apyBase: pool.feeApr * 100,
apyReward: pool.rewardApr * 100,
// Ensure unique reward tokens since the frontend allows adding the same token multiple times
// This prevents duplicate rewards from appearing in the DefiLlama dashboard
rewardTokens: Array.from(
new Set(pool.rewardInfos?.map((reward) => reward.tokenMetadata) || [])
),
underlyingTokens: [pool.token0, pool.token1],
};
})
.filter(Boolean); // Remove null entries

return defiLlamaPools;
}

module.exports = {
timetravel: false,
apy: main,
url: `${YUZU_API_URL_BASE}/pools`,
};
Loading