Skip to content

Applying APY calculation correction #1867

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
23 changes: 12 additions & 11 deletions src/adaptors/usual/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ const CONFIG = {
DAO_PROJECTED_WEEKLY_REVENUE: 500000,
WEEKS_PER_YEAR: 52,
USUALX_BALANCES_BLACKLIST: [
'0x86E2a16A5aBC67467Ce502e3Dab511c909C185A8', // Pendle SY
'0xF9F7ee120E4Ce2b4500611952Df8C7470Af09816', // Uniswap USUALx/USUAL
'0x36dee1e8B4679c67d73C8361E943C3401aD77FE3', // Uniswap USUALx/USD0
'0xDe4b4eaF83b678017E1b3C455117E752fE4e70eA', // Uniswap USUALx/USDT
'0x06B964d96f5dCF7Eae9d7C559B09EDCe244d4B8E', // USUALx dead shares
'0x86E2a16A5aBC67467Ce502e3Dab511c909C185A8',
'0xF9F7ee120E4Ce2b4500611952Df8C7470Af09816',
'0x36dee1e8B4679c67d73C8361E943C3401aD77FE3',
'0xDe4b4eaF83b678017E1b3C455117E752fE4e70eA',
'0x06B964d96f5dCF7Eae9d7C559B09EDCe244d4B8E',
],
};

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,13 +87,15 @@ 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,
chain: chain.toLowerCase(),
abi: abi.find((abi) => abi.name === 'totalAssets'),
});
const totalAssets = output / CONFIG.SCALAR;

const rate =
(
await sdk.api.abi.call({
Expand Down Expand Up @@ -121,25 +126,21 @@ async function getUsualXAPY(chain, usualXPrice) {
rawUsualXTVL - (blacklistedBalances?.reduce((a, b) => a + b, 0) ?? 0);

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

const usualxApyReward = utils.aprToApy(usualXApr * 100);

const usualxMarketCap = usualXTVL * usualXPrice;

const revenueSwitchApr =
(CONFIG.DAO_PROJECTED_WEEKLY_REVENUE * CONFIG.WEEKS_PER_YEAR) /
usualxMarketCap;
const usualxApyRevenueSwitch = utils.aprToApy(
revenueSwitchApr * 100,
CONFIG.WEEKS_PER_YEAR
);
const usualxApyRevenueSwitch = utils.aprToApy(revenueSwitchApr * 100);

return {
usualxApyReward,
usualxApyRevenueSwitch,
rawUsualXTVL,
};
}

const apy = async () => {
const { data: rewardData } = await axios.get(
`${CONFIG.URLS.REWARD_RATE}${CONFIG.SYMBOL}`
Expand Down
Loading