-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
2,976 additions
and
348 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -13,4 +13,5 @@ src/adaptors/list.js | |
Untitled.ipynb | ||
.ipynb_checkpoints/ | ||
yarn-error.log | ||
test.sql | ||
test.sql | ||
yarn.lock |
This file contains 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 @@ | ||
[{"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"}] |
This file contains 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 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 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,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; |
This file contains 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,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', | ||
}; |
Oops, something went wrong.