Skip to content

Commit

Permalink
Merge branch 'DefiLlama:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabhmarathe authored Apr 28, 2023
2 parents d459e88 + 5a2e70b commit 8e61997
Show file tree
Hide file tree
Showing 21 changed files with 346 additions and 80 deletions.
7 changes: 6 additions & 1 deletion projects/0vix/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const matic = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
const chain = "polygon";

module.exports = {
hallmarks: [
[Math.floor(new Date('2023-04-28')/1e3), 'Protocol was hacked!'],
],
polygon: compoundExports(master0vix, chain, oMATIC, matic),
polygon_zkevm: compoundExports("0x6EA32f626e3A5c41547235ebBdf861526e11f482", "polygon_zkevm", "0xee1727f5074e747716637e1776b7f7c7133f16b1", "0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9"),
};
};

delete module.exports.polygon.borrowed
30 changes: 30 additions & 0 deletions projects/aboard-exchange/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//20230428 initial release: simple and clear
const { sumTokensExport } = require('../helper/unwrapLPs');

const ownerArbitrum = '0x7a08b29A7Ad4A19A5ECa0c82F5F082872488D135'; // contract address
const tokensArbitrum = [
'0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC
'0x0000000000000000000000000000000000000000', // ETH
'0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', // USDT
'0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f', // WBTC
];

const ownerAvalanche = '0xd8b0D18faE7eA29F2AD95d01FFb479E0021a9A5e'; // contract address
const tokensAvalanche = [
'0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E', // USDC
'0x0000000000000000000000000000000000000000', // AVAX
'0x152b9d0FdC40C096757F570A51E494bd4b943E50', // BTC.b
'0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB', // WETH.e
'0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7', // USDt
];

module.exports = {
methodology: "TVL is equal to users' deposits minus withdrawals",
start: 1641625200, // Jan-08-2022 07:00:00 AM +UTC
arbitrum: {
tvl: sumTokensExport({ owner:ownerArbitrum, tokens:tokensArbitrum })
},
avax: {
tvl: sumTokensExport({ owner:ownerAvalanche, tokens:tokensAvalanche })
},
};
2 changes: 1 addition & 1 deletion projects/avatr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { sumTokens2, nullAddress } = require("../helper/unwrapLPs");
const { getLogs } = require("../helper/cache/getLogs");
const { staking } = require("../helper/staking");

const FACTORY_CONTRACT = "0x9CAc6c4fDb0fCbbB1cA3064f7f6C3FAD22B0B92D";
const FACTORY_CONTRACT = "0x498B8f1E767E2A32ab68C1301F1e98b59a34dA94";
const WETH_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";

async function tvl(timestamp, block, chainBlocks, { api }) {
Expand Down
10 changes: 10 additions & 0 deletions projects/chronos/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { getUniTVL } = require('../helper/unknownTokens')


module.exports = {
misrepresentedTokens: true,
methodology: `Uses factory(0xCe9240869391928253Ed9cc9Bcb8cb98CB5B0722) address to count liquidity in pools as TVL.`,
arbitrum: {
tvl: getUniTVL({ factory: '0xCe9240869391928253Ed9cc9Bcb8cb98CB5B0722', useDefaultCoreAssets: true }),
}
};
2 changes: 1 addition & 1 deletion projects/helper/solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const blacklistedTokens = [

let connection, provider

const endpoint = env.SOLANA_RPC || "https://api.mainnet-beta.solana.com/"
const endpoint = env.SOLANA_RPC || "https://try-rpc.mainnet.solana.blockdaemon.tech"

function getConnection() {
if (!connection) connection = new Connection(endpoint)
Expand Down
27 changes: 27 additions & 0 deletions projects/hydradex-v3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { blockQuery } = require('../helper/http')
const { getBlock } = require('../hydradex/getHydraV3SubgraphTvl')

async function tvl(timestamp) {
const endpoint = 'https://graph.hydradex.org/subgraphs/name/v3-subgraph'
const block = +(await getBlock('https://graph.hydradex.org/subgraphs/name/blocklytics/ethereum-blocks', timestamp))
const query = `query ($block: Int){
factories (block: { number: $block }) {
totalValueLockedUSD
}
}`
const { factories: [{ totalValueLockedUSD }] } = await blockQuery(endpoint, query, {
api: {
getBlock: () => block,
block
}
})
return { tether: totalValueLockedUSD }
}

module.exports = {
misrepresentedTokens: true,
methodology: "We count liquidity on the dex, pulling data from subgraph",
hydra: {
tvl,
},
};
30 changes: 18 additions & 12 deletions projects/hydradex.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
const cloudscraper = require('cloudscraper')
const { blockQuery } = require('./helper/http')
const { getBlock } = require('./hydradex/getHydraV3SubgraphTvl')

async function fetch() {
const uri = 'https://info.hydradex.org/graphql'
const body = { "operationName": "Query", "variables": {}, "query": "query Query {\n hydraswapFactories(where: {id: \"5a2a927bea6c5f4a48d4e0116049c1e36d52a528\"}) {\n totalLiquidityUSD\n }\n}\n" }
const reserves = (
await cloudscraper.post(uri, {
json: body
})
)
return { tether: +reserves.data.hydraswapFactories[0].totalLiquidityUSD }
async function tvl(timestamp) {
const endpoint = 'https://info.hydradex.org/graphql'
const block = await getBlock(endpoint, timestamp)
const query = `query ($block: Float!){
hydraswapFactories (block: { number: $block }) {
totalLiquidityUSD
}
}`
const { hydraswapFactories: [{ totalLiquidityUSD }] } = await blockQuery(endpoint, query, {
api: {
getBlock: () => block,
block
}
})
return { tether: totalLiquidityUSD }
}

module.exports = {
misrepresentedTokens: true,
timetravel: false,
methodology: "We count liquidity on the dex, pulling data from subgraph",
hydra: {
tvl: fetch,
tvl,
},
};
8 changes: 1 addition & 7 deletions projects/hydradex/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
const { getExports } = require('../helper/heroku-api')

module.exports = {
timetravel: false,
misrepresentedTokens: true,
...getExports("hydradex", ['hydra']),
}
module.exports = require('../hydradex')
22 changes: 22 additions & 0 deletions projects/hydradex/getHydraV3SubgraphTvl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { graphQuery, } = require("../helper/http");

const HOURS_12 = 12 * 3600

async function getBlock(endpoint, timestamp) {
const params = {
timestamp_from: timestamp - HOURS_12,
timestamp_to: timestamp + HOURS_12,
}
const query = `query ($timestamp_to: Int, $timestamp_from: Int){
blocks (orderBy: "timestamp" first:1 orderDirection: "desc" where: { timestamp_lte: $timestamp_to timestamp_gte: $timestamp_from}) {
timestamp
number
}
}`
const { blocks } = await graphQuery(endpoint, query, params)
return blocks[0].number
}

module.exports = {
getBlock,
};
89 changes: 89 additions & 0 deletions projects/mt-gox/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const { cexExports } = require('../helper/cex')

const config = {
bitcoin: {
owners: [
"17Tf4bVQaCzwWrDWGRPC97RLCHnU4LY8Qr",
"1BzK87zuqidZn489Wb2oLSktrjKrX7TLKe",
"1Drshi4RAuvxk4T6Bkq959ZvLbvy7b1wvD",
"1EiiKCCnFgHjEvPZdu29qqgdBm8zTvpU3U",
"14p4w3TRCd6NMRSnzTmgdvQhNnbrAmzXmy",
"12KkeeRkiNS13GMbg7zos9KRn9ggvZtZgx",
"12T4oSNd4t9ty9fodgNd47TWhK35pAxDYN",
"15kNZcrhxeFZgVVLK2Yjzd69tRidbFdJEZ",
"1LS5EFRRMDgMQusW6zokQUHjzNUfy6HHCQ",
"1FrV9hv1AW34BGJvobJatyzUWYDWB9epRW",
"1HdKXsNQtzDcfB6PGM7DWTgX9vhBWsz1ak",
"1Fu4YgM3Y9CxvioGPqkSzkydAC8MVaPN1D",
"1G23Uzwj55k2A9TRwaTknqGav66oDTkWCu",
"1GkZQcDy8V6pmHFZqUBUBCnN9dc2hoWasD",
"1Hm6XDmhKCHz68wDEYTapN9MEanke8iwUk",
"15SeCwVCFx5cWyrcdD1Zp1D1zxjH2SELPg",
"15U4VsmWG1cdXAt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ZbEAz5y3QMnqFY8C5xqTdrjUwcA",
"1PRXQEoL8vzEzoJJ9hbtAP6NaV2daccAUn",
"1PxGTuJzDx1ceFHx4Z5CHaWuhiPBNovmZD",
"1NA3Tj4b1jtx9eGELe31Jw4DrzTqKP3ayH" //https://www.cryptoground.com/mtgox-cold-wallet-monitor/
],
},
}

module.exports = cexExports(config)
8 changes: 8 additions & 0 deletions projects/olympus/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const index = require('./index')

module.exports = {
ethereum: {
tvl: () => 0,
staking: index.ethereum.staking,
}
}
49 changes: 22 additions & 27 deletions projects/olympus/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const sdk = require("@defillama/sdk");
const { blockQuery } = require("../helper/http");
const env= require("../helper/env");
const env = require("../helper/env");
const BigNumber = require("bignumber.js");

const OlympusStakings = [
Expand All @@ -10,7 +10,7 @@ const OlympusStakings = [
"0xFd31c7d00Ca47653c6Ce64Af53c1571f9C36566a",
];

const OHM = "0x383518188c0c6d7730d91b2c03a03c837814a899";
const OHM = "0x383518188c0c6d7730d91b2c03a03c837814a899" // this is OHM v1

/** Map any staked assets without price feeds to those with price feeds.
* All balances are 1: 1 to their unstaked counterpart that has the price feed.
Expand Down Expand Up @@ -112,7 +112,7 @@ function sumBalancesByTokenAddress(arr) {
* #2. Call tokenRecords with block num from prev query
* #3. Sum values returned
***/
async function tvl(timestamp, block, _, { api }, poolsOnly = false) {
async function tvl(timestamp, block, _, { api }, isOwnTokensMode = false) {
const indexedBlockForEndpoint = await blockQuery(
subgraphUrls[api.chain],
getLatestBlockIndexed,
Expand All @@ -130,16 +130,16 @@ async function tvl(timestamp, block, _, { api }, poolsOnly = false) {
if (now - blockNum[0].timestamp > 3 * aDay) {
throw new Error("outdated");
}
const filteredTokenRecords = poolsOnly
? tokenRecords.filter((t) => t.category === "Protocol-Owned Liquidity")
: tokenRecords;
// const filteredTokenRecords = poolsOnly
// ? tokenRecords.filter((t) => t.category === "Protocol-Owned Liquidity")
// : tokenRecords;

/**
* iterates over filtered list from subgraph and returns any addresses
* that need to be normalized for pricing .
* See addressMap above
**/
const normalizedFilteredTokenRecords = filteredTokenRecords.map((token) => {
const normalizedFilteredTokenRecords = tokenRecords.map((token) => {
const normalizedAddress = addressMap[token.tokenAddress]
? addressMap[token.tokenAddress]
: token.tokenAddress;
Expand All @@ -149,27 +149,22 @@ async function tvl(timestamp, block, _, { api }, poolsOnly = false) {
const tokensToBalances = sumBalancesByTokenAddress(
normalizedFilteredTokenRecords
);
const balances = await Promise.all(
tokensToBalances.map(async (token, index) => {
const decimals = await sdk.api.abi.call({
abi: "erc20:decimals",
target: token.tokenAddress,
chain: api.chain,
});
return [
`${api.chain}:${token.tokenAddress}`,
Number(
BigNumber(token.balance)
.times(10 ** decimals.output)
.toFixed(0)
),
];
})
);
return Object.fromEntries(balances);
const tokens = tokensToBalances.map(i => i.tokenAddress)
const decimals = await api.multiCall({ abi: 'erc20:decimals', calls: tokens })
const ownTokens = new Set([
'0x0ab87046fBb341D058F17CBC4c1133F25a20a52f', // GOHM
'0x64aa3364f17a4d01c6f1751fd97c2bd3d7e7f1d5', // OHM
].map(i => i.toLowerCase()))
tokensToBalances.map(async (token, i) => {
if (ownTokens.has(token.tokenAddress.toLowerCase())) {
if (!isOwnTokensMode) return;
} else if (isOwnTokensMode) return;
api.add(token.tokenAddress, token.balance * 10 ** decimals[i])
})
return api.getBalances()
}

async function pool2(timestamp, block, _, { api }) {
async function ownTokens(timestamp, block, _, { api }) {
return tvl(timestamp, block, _, { api }, true);
}

Expand All @@ -181,7 +176,7 @@ module.exports = {
ethereum: {
staking,
tvl,
// pool2,
ownTokens,
},
arbitrum: {
tvl,
Expand Down
3 changes: 3 additions & 0 deletions projects/pepe-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const config = {
],
'0x0de7b091A21BD439bdB2DfbB63146D9cEa21Ea83'
]
],
bsc: [
[[nullAddress], '0xF1632012f6679Fcf464721433AFAAe9c11ad9e03'] // BNB
]
}
module.exports = {};
Expand Down
Loading

0 comments on commit 8e61997

Please sign in to comment.