Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit c61cd46
Author: YieldLend <[email protected]>
Date:   Mon Dec 11 09:39:31 2023 +0300

    Added yieldlend APRs (DefiLlama#1107)

commit f507abf
Author: slasher125 <[email protected]>
Date:   Fri Dec 8 11:44:26 2023 +0400

    update exclusion

commit 2624a03
Author: slasher125 <[email protected]>
Date:   Fri Dec 8 09:45:43 2023 +0400

    bedrock lsd fee

commit bb2138d
Author: slasher125 <[email protected]>
Date:   Thu Dec 7 18:59:39 2023 +0400

    update exclusion

commit 62ce642
Author: slasher125 <[email protected]>
Date:   Thu Dec 7 18:43:41 2023 +0400

    add uniETH to lsdhandler

commit 749d52e
Author: slasher125 <[email protected]>
Date:   Thu Dec 7 12:26:23 2023 +0400

    lsd rates afix

commit 9ab886f
Author: slasher125 <[email protected]>
Date:   Thu Dec 7 10:46:00 2023 +0400

    joe v2 add missing pools

commit 44f3c18
Author: Julien <[email protected]>
Date:   Thu Dec 7 07:39:48 2023 +0100

    fix: SmarDex farming APR reward was missing for L2 index 0 campaigns (DefiLlama#1103)

    * feat: smardex yield

    * fix:do not compound apr

    * fix: re-run test

    * fix: L2 farming do not skip campaign 0

commit 82312a2
Author: Integral <[email protected]>
Date:   Thu Dec 7 14:25:11 2023 +0800

    Add Integral Arbitrum pools (DefiLlama#1105)

commit 3634200
Author: Phil <[email protected]>
Date:   Wed Dec 6 23:23:47 2023 -0700

    Sommelier: Add Turbo stETH 2 Vault (DefiLlama#1104)

    * Sommelier: Add Turbo GHO

    * Edge case for apys

    * Sommelier: Add ETH Trend Growth vault

    * Add Turbo Steth

    * Add Turbo SOMM

    * Sommelier: Add Turbo EETH Vault

    * Sommelier: Add turbo steth 2 vault

commit 2dcc513
Author: slasher125 <[email protected]>
Date:   Wed Dec 6 17:50:24 2023 +0400

    stader peg fix

commit f175e9f
Author: slasher125 <[email protected]>
Date:   Tue Dec 5 17:15:08 2023 +0400

    lower case abra pool values

commit 18dd4d8
Author: Eugene Mormul <[email protected]>
Date:   Tue Dec 5 15:10:45 2023 +0200

    feat: primex-finance arbitrum contracts (DefiLlama#1091)

    * feat: arbitrum contracts

    * feat: remove apyRewardBorrow and apyReward in ePMX

commit dcfd130
Author: 0xmDreamy <[email protected]>
Date:   Tue Dec 5 14:10:03 2023 +0100

    feat(abracadabra): Add support for GM cauldrons (DefiLlama#1102)

commit 4be762f
Author: Fei Yang <[email protected]>
Date:   Tue Dec 5 21:05:20 2023 +1100

    add APY data for v2 vaults (DefiLlama#1100)

commit ee48890
Author: 0xmDreamy <[email protected]>
Date:   Tue Dec 5 10:55:10 2023 +0100

    fix(abracadabra): Update MIM2CRV farm pool details (DefiLlama#1101)

commit 5e6fc81
Author: slasher125 <[email protected]>
Date:   Mon Dec 4 11:32:32 2023 +0400

    thena fusion pool id fix

commit a1e8e3c
Author: 0xmDreamy <[email protected]>
Date:   Fri Dec 1 10:12:09 2023 +0100

    feat(abracadabra): Add support for Multi Reward Staking farms (DefiLlama#1097)

commit 851377f
Author: Michael Otis <[email protected]>
Date:   Wed Nov 29 23:57:52 2023 -0600

    Update APY calc and add dynamic rewards (DefiLlama#1096)

commit 1c313f6
Author: Larry the Cucumber <[email protected]>
Date:   Wed Nov 29 21:53:09 2023 -0800

    add reserve base APY (DefiLlama#1095)

commit 2313411
Author: slasher125 <[email protected]>
Date:   Thu Nov 30 09:23:20 2023 +0400

    stakedao swap api

commit feefd6c
Author: slasher125 <[email protected]>
Date:   Thu Nov 30 09:10:21 2023 +0400

    dfx-finance -> dfx-v2

commit 1b5f482
Author: slasher125 <[email protected]>
Date:   Wed Nov 29 18:54:01 2023 +0400

    fix

commit 03110ff
Author: charq <[email protected]>
Date:   Wed Nov 29 16:48:41 2023 +0800

    Change filter pool ID method (DefiLlama#1094)

    * add solv-funds

    * filter out  institution funds

    * Add poolMeta parameter

    * Change filter pool ID method

commit 3d9785a
Author: slasher125 <[email protected]>
Date:   Wed Nov 29 10:22:34 2023 +0400

    move gamma thena pools to thena fusion

commit 9c18e7f
Author: slasher125 <[email protected]>
Date:   Wed Nov 29 09:37:19 2023 +0400

    stakehouse value accruing

commit 6fab854
Author: slasher125 <[email protected]>
Date:   Mon Nov 27 22:28:13 2023 +0400

    remove yarn lock file

commit bcd507b
Author: André Sardo <[email protected]>
Date:   Mon Nov 27 06:15:42 2023 +0000

    feat: add astroport sei deployment (DefiLlama#1093)

commit f508361
Author: fayrume <[email protected]>
Date:   Mon Nov 27 10:14:50 2023 +0400

    added stablebase pools (DefiLlama#1092)

    Co-authored-by: root <[email protected]>

commit 0d038f8
Author: Alfred Gaillard <[email protected]>
Date:   Mon Nov 27 07:10:03 2023 +0100

    Amphor apy (DefiLlama#1090)

    * Added amphor apy

    * USDC and WSTETH vaults pools

commit ee18872
Author: slasher125 <[email protected]>
Date:   Fri Nov 24 11:15:55 2023 +0400

    impermax fix

commit d6f8b54
Author: slasher125 <[email protected]>
Date:   Fri Nov 24 10:48:09 2023 +0400

    betswirl fix

commit c70f95d
Author: slasher125 <[email protected]>
Date:   Fri Nov 24 10:44:18 2023 +0400

    update exclusion

commit 0385671
Author: slasher125 <[email protected]>
Date:   Fri Nov 24 10:21:19 2023 +0400

    equalizer fiz

commit 816f2d2
Author: Coopes <[email protected]>
Date:   Thu Nov 23 23:31:22 2023 -0600

    adding arb rewards (will last until february 15th, i will stage PR to remove slightly before then) (DefiLlama#1088)

    * adding arb rewards

    * fixing test

    * last fix

    * adding date based logic

commit d3194cc
Author: Phil <[email protected]>
Date:   Wed Nov 22 22:45:16 2023 -0700

    Sommelier: Add Turbo eETH Vault (DefiLlama#1089)

    * Sommelier: Add Turbo GHO

    * Edge case for apys

    * Sommelier: Add ETH Trend Growth vault

    * Add Turbo Steth

    * Add Turbo SOMM

    * Sommelier: Add Turbo EETH Vault

commit 924667f
Author: Jeff Wu <[email protected]>
Date:   Wed Nov 22 21:42:36 2023 -0800

    Feature: adding notional v3 yield (DefiLlama#1087)

    * fix: initial v3 yield

    * fix: first attempt at vaults

    * fix: note, fcash, pcash

    * fix: some vault changes

    * fix: update subgraph and apy
  • Loading branch information
asyx21 committed Dec 11, 2023
1 parent bcefea6 commit a927138
Show file tree
Hide file tree
Showing 33 changed files with 3,316 additions and 365 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ src/adaptors/list.js
Untitled.ipynb
.ipynb_checkpoints/
yarn-error.log
test.sql
test.sql
yarn.lock
1 change: 1 addition & 0 deletions src/adaptors/abracadabra/abis/MultiRewardsStaking.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"address","name":"_stakingToken","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ErrInvalidTokenAddress","type":"error"},{"inputs":[],"name":"ErrRewardAlreadyAdded","type":"error"},{"inputs":[],"name":"ErrRewardPeriodStillActive","type":"error"},{"inputs":[],"name":"ErrZeroAmount","type":"error"},{"inputs":[],"name":"ErrZeroDuration","type":"error"},{"inputs":[],"name":"NotAllowedOperator","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LogRecovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"LogRewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"rewardsToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"LogRewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"newDuration","type":"uint256"}],"name":"LogRewardsDurationUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LogStaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LogWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"","type":"address"},{"indexed":false,"internalType":"bool","name":"","type":"bool"}],"name":"OperatorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"},{"internalType":"uint256","name":"_rewardsDuration","type":"uint256"}],"name":"addReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"rewardToken","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"}],"name":"getRewardForDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"}],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"notifyRewardAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"operators","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"recover","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"rewardData","outputs":[{"components":[{"internalType":"uint256","name":"rewardsDuration","type":"uint256"},{"internalType":"uint256","name":"periodFinish","type":"uint256"},{"internalType":"uint256","name":"rewardRate","type":"uint256"},{"internalType":"uint256","name":"lastUpdateTime","type":"uint256"},{"internalType":"uint256","name":"rewardPerTokenStored","type":"uint256"}],"internalType":"struct MultiRewardsStaking.Reward","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"}],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardTokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"setOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"},{"internalType":"uint256","name":"_rewardsDuration","type":"uint256"}],"name":"setRewardsDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakingToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"userRewardPerTokenPaid","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]
61 changes: 42 additions & 19 deletions src/adaptors/abracadabra/cauldrons.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ const POOLS = {
address: '0x726413d7402ff180609d0ebc79506df8633701b1',
collateralPoolId: 'a4bcffaa-3b75-436c-b6c2-7b1c3840d041'
}, // magicGLP
{
version: 4,
address: '0x7962acfcfc2ccebc810045391d60040f635404fb',
collateralPoolId: '906b233c-8478-4b94-94e5-2d77e6c7c9e5',
symbol: "SOL-USDC",
}, // gmSOL
{
version: 4,
address: '0x2b02bBeAb8eCAb792d3F4DDA7a76f63Aa21934FA',
collateralPoolId: '61b4c35c-97f6-4c05-a5ff-aeb4426adf5b',
symbol: "ETH-USDC",
}, // gmETH
{
version: 4,
address: '0xD7659D913430945600dfe875434B6d80646d552A',
collateralPoolId: '5b8c0691-b9ff-4d82-97e4-19a1247e6dbf',
symbol: "WBTC.B-USDC",
}, // gmBTC
{
version: 4,
address: '0x4F9737E994da9811B8830775Fd73E2F1C8e40741',
collateralPoolId: 'f3fa942f-1867-4028-95ff-4eb76816cd07',
symbol: "ARB-USDC",
}, // gmARB
],
},
avax: {
Expand Down Expand Up @@ -221,11 +245,7 @@ const getMarketLensDetailsForCauldrons = (
const enrichMarketInfos = (cauldrons, marketInfos) =>
marketInfos
.map((marketInfo, i) => ({
cauldron: cauldrons[i].address,
maximumCollateralRatio: cauldrons[i].maximumCollateralRatio,
interestPerYear: cauldrons[i].interestPerYear,
cauldronMeta: cauldrons[i].cauldronMeta,
collateralPoolId: cauldrons[i].collateralPoolId,
...cauldrons[i],
...marketInfo,
}))
.map((enrichedMarketInfo) => _.omitBy(enrichedMarketInfo, _.isUndefined));
Expand Down Expand Up @@ -551,9 +571,9 @@ const marketInfoToPool = (chain, marketInfo, collateral, pricesObj) => {
const ltv = marketInfo.maximumCollateralRatio / 10000;

const pool = {
pool: `${marketInfo.cauldron}-${chain}`,
pool: `${marketInfo.address}-${chain}`,
chain: utils.formatChain(chain),
symbol: utils.formatSymbol(collateral.symbol),
symbol: marketInfo.symbol ?? utils.formatSymbol(collateral.symbol),
tvlUsd: totalSupplyUsd,
apyBaseBorrow,
totalSupplyUsd,
Expand Down Expand Up @@ -627,13 +647,13 @@ const getApy = async () => {
return Object.entries(marketInfos).flatMap(([chain, chainMarketInfos]) =>
chainMarketInfos.map((marketInfo) => {
const collateralAddress =
collaterals[chain][marketInfo.cauldron.toLowerCase()].toLowerCase();
collaterals[chain][marketInfo.address.toLowerCase()].toLowerCase();
const bentobox =
bentoboxes[chain][marketInfo.cauldron.toLowerCase()].toLowerCase();
bentoboxes[chain][marketInfo.address.toLowerCase()].toLowerCase();
const collateral = {
address: collateralAddress,
symbol: symbols[chain][marketInfo.cauldron.toLowerCase()],
decimals: decimals[chain][marketInfo.cauldron.toLowerCase()],
symbol: symbols[chain][marketInfo.address.toLowerCase()],
decimals: decimals[chain][marketInfo.address.toLowerCase()],
};

// Add negative strategy APY to collateral if there's one for the cauldron
Expand All @@ -646,6 +666,11 @@ const getApy = async () => {
marketInfo.collateralPoolId !== undefined
? _.find(apyObj, { pool: marketInfo.collateralPoolId })
: undefined;
if (collateralApy !== undefined) {
collateral.apyBase = collateralApy.apyBase;
} else {
collateral.apyBase = 0;
}
if (strategyDetails !== undefined) {
const strategy = strategyDetails.address.toLowerCase();
const targetPercentage = strategyDetails.strategyData.targetPercentage;
Expand All @@ -658,21 +683,19 @@ const getApy = async () => {
strategy,
]);
if (negativeInterestStrategyApy !== undefined) {
collateral.apyBase =
collateral.apyBase +=
(targetPercentage / 100) * -negativeInterestStrategyApy;
} else if (
strategyFee !== undefined &&
collateralApy !== undefined
) {
collateral.apyBase =
((collateralApy.apy * targetPercentage) / 100) *
collateral.apyBase +=
((collateralApy.apyReward * targetPercentage) / 100) *
(1 - strategyFee);
}
} else {
// No strategy to consider, so just use the apy from the pool if one exists.
if (collateralApy) {
collateral.apyBase = collateralApy.apy;
}
}
if (collateral.apyBase === 0) {
collateral.apyBase = undefined;
}

return {
Expand Down
13 changes: 8 additions & 5 deletions src/adaptors/abracadabra/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const cauldrons = require('./cauldrons');
const multiRewardFarms = require('./multi-reward-farms');
const farms = require('./farms');
const magicGlp = require('./magic-glp');

const getApy = async () => [
...(await cauldrons()),
...(await farms()),
...(await magicGlp()),
];
const getApy = async () =>
[
...(await cauldrons()),
...(await farms()),
...(await magicGlp()),
...(await multiRewardFarms()),
].map((i) => ({ ...i, pool: i.pool.toLowerCase() }));

module.exports = {
timetravel: false,
Expand Down
91 changes: 91 additions & 0 deletions src/adaptors/abracadabra/multi-reward-farms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const axios = require('axios');
const { utils: { formatUnits }, BigNumber } = require('ethers');
const sdk = require('@defillama/sdk');
const utils = require('../utils');
const MULTI_REWARDS_STAKING = require('./abis/MultiRewardsStaking.json');
const SECONDS_PER_YEAR = 31536000;

const FARMS = {
arbitrum: [{
address: "0x6d2070b13929Df15B13D96cFC509C574168988Cd",
stakingToken: "0x30dF229cefa463e991e29D42DB0bae2e122B2AC7",
stakingTokenPool: "0bf3cb38-1908-4d85-87c3-af62651d5a03",
rewardTokens: [
"0x912CE59144191C1204E64559FE8253a0e49E6548", // ARB
"0x3E6648C5a70A150A88bCE65F4aD4d506Fe15d2AF" // SPELL
],
symbol: "MIM/USDC/USDT",
underlyingTokens: [
"0xFEa7a6a0B346362BF88A9e4A88416B77a57D6c2A", // MIM
"0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8", // USDC
"0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", // USDT
],
url: "https://app.abracadabra.money/#/farm/4",
}],
}

const getApy = async () => {
const pools = await Promise.all(Object.entries(FARMS).map(async ([chain, chainFarms]) => {
const rewardDataCalls = chainFarms.flatMap(({ address, rewardTokens }) =>
rewardTokens.map((rewardToken) => ({
target: address,
params: [rewardToken]
})));
const [rewardDataResults, totalSupplyResults, prices, symbols, yieldPools] = await Promise.all([
sdk.api.abi.multiCall({
abi: MULTI_REWARDS_STAKING.find(({ name }) => name === "rewardData"),
calls: rewardDataCalls,
chain,
}).then((call => call.output)),
sdk.api.abi.multiCall({
abi: MULTI_REWARDS_STAKING.find(({ name }) => name === "totalSupply"),
calls: chainFarms.map(({ address }) => ({ target: address })),
chain
}).then((call => call.output.map((x) => [x.input.target.toLowerCase(), x])))
.then(Object.fromEntries),
utils.getPrices(chainFarms.flatMap(({ rewardTokens }) => rewardTokens), chain),
sdk.api.abi.multiCall({
abi: "erc20:symbol",
calls: chainFarms.map(({ stakingToken }) => ({
target: stakingToken
})),
chain
}).then((call => call.output.map((x) => [x.input.target.toLowerCase(), x])))
.then(Object.fromEntries),
axios.get('https://yields.llama.fi/pools').then((result) => result.data.data),
]);

const tvlUsdChainFarms = Object.fromEntries(chainFarms.map(({ address }) => {
const totalSupply = formatUnits(totalSupplyResults[address.toLowerCase()].output, 18);
const totalSupplyUsd = totalSupply; // Assume $1
return [address.toLowerCase(), totalSupplyUsd];
}))
const aprs = Object.fromEntries(chainFarms.map(({ address }) => [address.toLowerCase(), 0]));
rewardDataResults.forEach(({ input: { target: farm, params: [rewardToken] }, output: { rewardRate } }) => {
const rewardsPerYearRaw = BigNumber.from(rewardRate).mul(SECONDS_PER_YEAR);
const rewardsPerYear = formatUnits(rewardsPerYearRaw, 18);
const rewardsPerYearUsd = rewardsPerYear * prices.pricesByAddress[rewardToken.toLowerCase()];
const rewardApr = rewardsPerYearUsd / tvlUsdChainFarms[farm.toLowerCase()] * 100;

aprs[farm.toLowerCase()] = aprs[farm.toLowerCase()] + rewardApr;
});
return chainFarms.map(({ address, rewardTokens, stakingToken, stakingTokenPool, symbol, underlyingTokens, url }) => {
const stakingTokenYieldPool = yieldPools.find(({ pool }) => pool === stakingTokenPool);
return {
pool: `${address}-${chain}`,
chain: utils.formatChain(chain),
project: 'abracadabra',
tvlUsd: Number(tvlUsdChainFarms[address.toLowerCase()]),
symbol: symbol ?? utils.formatSymbol(symbols[stakingToken.toLowerCase()].output),
apyBase: stakingTokenYieldPool.apyBase,
apyReward: aprs[address.toLowerCase()],
rewardTokens,
underlyingTokens: underlyingTokens ?? stakingTokenYieldPool.underlyingTokens,
url,
}
});
}));
return pools.flat();
}

module.exports = getApy;
74 changes: 74 additions & 0 deletions src/adaptors/amphor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const utils = require('../utils');
const sdk = require('@defillama/sdk');

const poolsFunction = async () => {

// const wbtc = "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599";
const wsteth = "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0";
const prices = (await utils.getPrices([wsteth/*, wbtc*/], 'ethereum'))
.pricesByAddress;
const usdcVaultAddress = '0x3b022EdECD65b63288704a6fa33A8B9185b5096b';
const wstethVaultAddress = '0x2791EB5807D69Fe10C02eED6B4DC12baC0701744';

const ERC4626TotalAssets =
{
"inputs": [],
"name": "totalAssets",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
};

const wstethAprData = await utils.getData(
'https://app.amphor.io/api/apr?vaultSelected=ETH&networkId=1'
);
const wstethApy = ((1 + Number(wstethAprData.apr)/2600) ** (26) - 1) * 100;

const usdcAprData = await utils.getData(
'https://app.amphor.io/api/apr?vaultSelected=USDC&networkId=1'
);
const usdcApy = ((1 + Number(usdcAprData.apr)/2600) ** (26) - 1) * 100;

const usdcTotalAsset = await sdk.api.abi.call({
abi: ERC4626TotalAssets,
chain: 'ethereum',
target: usdcVaultAddress,
});
const wstethTotalAsset = await sdk.api.abi.call({
abi: ERC4626TotalAssets,
chain: 'ethereum',
target: wstethVaultAddress,
});

const usdcPool = {
pool: usdcVaultAddress,
chain: 'ethereum',
project: 'amphor',
symbol: utils.formatSymbol('USDC'),
tvlUsd: Number(usdcTotalAsset.output)/1e6,
apy: usdcApy,
};

const wstethPool = {
pool: wstethVaultAddress,
chain: 'ethereum',
project: 'amphor',
symbol: utils.formatSymbol('WSTETH'),
tvlUsd: (Number(wstethTotalAsset.output)/1e18) * prices[wsteth.toLowerCase()],
apy: wstethApy,
};

return [usdcPool, wstethPool];
};

module.exports = {
timetravel: false,
apy: poolsFunction,
url: 'https://app.amphor.io/earn',
};
Loading

0 comments on commit a927138

Please sign in to comment.