Skip to content

Update index.js #1870

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

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 13 additions & 5 deletions src/adaptors/usual/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const CONFIG = {
'0x06B964d96f5dCF7Eae9d7C559B09EDCe244d4B8E', // USUALx dead shares
],
};

async function getTokenSupply(chain, address) {
const params = {
chain: chain.toLowerCase(),
Expand All @@ -43,6 +44,7 @@ async function getTokenSupply(chain, address) {
const { output } = await sdk.api.abi.call(params);
return output / CONFIG.SCALAR;
}

async function getTokenBalance(chain, address, user) {
const params = {
target: address,
Expand All @@ -54,6 +56,7 @@ async function getTokenBalance(chain, address, user) {
const { output } = await sdk.api.abi.call(params);
return output / CONFIG.SCALAR;
}

async function getTokenPrice(chain, address) {
const priceKey = `${chain.toLowerCase()}:${address}`;
const { data } = await axios.get(`${CONFIG.URLS.LLAMA_PRICE}${priceKey}`);
Expand Down Expand Up @@ -84,6 +87,7 @@ async function getChainData(chainConfig) {
const price = await getTokenPrice(chainConfig.CHAIN, chainConfig.USD0PP);
return { supply, price };
}

async function getUsualXAPY(chain, usualXPrice) {
const { output } = await sdk.api.abi.call({
target: CONFIG.USUALX_TOKEN,
Expand Down Expand Up @@ -122,7 +126,8 @@ async function getUsualXAPY(chain, usualXPrice) {

const usualXApr = (rate * CONFIG.DAYS_PER_YEAR) / totalAssets;

const usualxApyReward = utils.aprToApy(usualXApr * 100);
// Applying weekly compounding only to USUALx apyReward
const usualxApyReward = utils.aprToApy(usualXApr * 100, CONFIG.WEEKS_PER_YEAR); // Weekly compounding for apyReward

const usualxMarketCap = usualXTVL * usualXPrice;

Expand All @@ -140,14 +145,17 @@ async function getUsualXAPY(chain, usualXPrice) {
rawUsualXTVL,
};
}

const apy = async () => {
const { data: rewardData } = await axios.get(
`${CONFIG.URLS.REWARD_RATE}${CONFIG.SYMBOL}`
);
const reward = rewardData.rewards.find(
(e) => CONFIG.USUAL_TOKEN.toLowerCase() === e.rewardToken.toLowerCase()
);
const apyReward = utils.aprToApy(reward.apr * 100, CONFIG.WEEKS_PER_YEAR);

// No weekly compounding for USD0++
const apyReward = reward.apr * 100; // Direct APR-to-APY conversion without weekly compounding

const ethData = await getChainData(CONFIG.ETHEREUM);
const arbData = await getChainData(CONFIG.ARBITRUM);
Expand All @@ -166,14 +174,14 @@ const apy = async () => {
CONFIG.ETHEREUM.CHAIN,
CONFIG.ETHEREUM.USD0PP,
ethData.supply * ethData.price,
apyReward,
apyReward, // Corrected to USD0++ APY
CONFIG.ETHEREUM.USD0
),
createPoolData(
CONFIG.ARBITRUM.CHAIN,
CONFIG.ARBITRUM.USD0PP,
arbData.supply * arbData.price,
apyReward,
apyReward, // Corrected for Arbitrum USD0++
CONFIG.ARBITRUM.USD0
),
{
Expand All @@ -182,7 +190,7 @@ const apy = async () => {
project: 'usual',
symbol: 'USUALx',
tvlUsd: rawUsualXTVL * usualxPrice,
apyBase: usualxApyReward,
apyBase: usualxApyReward, // Weekly compounding for USUALx APY
apyReward: usualxApyRevenueSwitch,
rewardTokens: [CONFIG.ETHEREUM.USD0],
underlyingTokens: [CONFIG.USUAL_TOKEN],
Expand Down
Loading