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
waynebruce0x authored Mar 29, 2022
2 parents 6546e5d + 0a29097 commit 8d5abd5
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions projects/cubo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ const chain = 'polygon'
const DAI = '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063'

const treasuryAddress = '0xb495ffc5acd7e2fd909c23c30d182e6719fbe9ec'
const daoContract = '0xb05d0da5253e77a8ad37232e8235c712e10edee8'
const oldDaoContract = '0xb05d0da5253e77a8ad37232e8235c712e10edee8'
const daoContract = '0xb8dc6634b7ac8ad3ae352ab92de51349e7b5e71c'

async function polygon_tvl(timestamp, ethBlock, { polygon: block }) {
const daoTokens = [DAI,].map(token => [token, daoContract,])
const daoTokens = [DAI,].map(token => [
[token, oldDaoContract,],
[token, daoContract,],
]).flat()

const balances = {}
const transformPolygonAddress = addr => `${chain}:${addr}`
Expand Down
17 changes: 17 additions & 0 deletions projects/diamond-coin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const sdk = require("@defillama/sdk");
const {pool2Exports} = require("../helper/pool2");

const token = "0xDDa0F0E1081b8d64aB1D64621eb2679F93086705";
const emissionRewardPool = "0xDDa0F0E1081b8d64aB1D64621eb2679F93086705";

const DiamondLPs = [
"0xf5e8B220843EC7114B91AfF0D25342c24eB953b5", // DIAMOND-FTM
"0x2f1569094CB256fB745901fa92e57aF011D32B2C" // BOMB-DIAMOND
]

module.exports = {
fantom: {
tvl: async () => ({}),
pool2: pool2Exports(emissionRewardPool, DiamondLPs, "fantom", addr=>`fantom:${addr}`)
}
}
16 changes: 10 additions & 6 deletions projects/hubble/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const axios = require("axios");
const BigNumber = require('bignumber.js');
const {toUSDTBalances} = require('../helper/balances');
const HUBBLE_API = "https://api.hubbleprotocol.io";

const client = axios.create({
Expand All @@ -7,19 +9,21 @@ const client = axios.create({

async function tvl() {
const metrics = await client.get("/metrics");
return metrics.data.totalValueLocked - metrics.data.hbb.staked * metrics.data.hbb.price;
const tvl = new BigNumber(metrics.data.totalValueLocked);
const staking = new BigNumber(metrics.data.hbb.staked).multipliedBy( metrics.data.hbb.price);
return toUSDTBalances(tvl.minus(staking));
}

async function staking() {
const metrics = await client.get("/metrics");
return metrics.data.hbb.staked * metrics.data.hbb.price;
const value = new BigNumber(metrics.data.hbb.staked).multipliedBy(metrics.data.hbb.price);
return toUSDTBalances(value)
}

module.exports = {
methodology: `To obtain the Hubble Protocol TVL we use the formula 'TVL = Total HBB Staked * Current HBB Price + Total Collateral Value + Total Stablecoin (USDH) in Stability Pool'.`,
solana: {
fetch: tvl,
tvl,
staking,
},
staking: { fetch: staking },
fetch: tvl
};
}
8 changes: 5 additions & 3 deletions projects/instadapp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const retry = require("./helper/retry");
const axios = require("axios");
const {toUSDTBalances} = require('./helper/balances')

async function fetch() {
const stats = (
Expand All @@ -9,15 +10,16 @@ async function fetch() {
)
).data.stats[0];

return stats.totalSupplied;
return toUSDTBalances(stats.totalSupplied);
}

module.exports = {
misrepresentedTokens: true,
doublecounted: true,
timetravel: false,
ethereum: {
fetch
tvl: fetch,
},
fetch

}
// node test.js projects/instadapp.js
14 changes: 14 additions & 0 deletions projects/laserswap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { calculateUsdUniTvl } = require("../helper/getUsdUniTvl");

module.exports = {
methodology: `Uses factory(0x23c7FA9A9f81B322684F25b8079e22C37e00b46b) address and whitelisted tokens address to find and price Liquidity Pool pairs`,
thundercore: {
tvl: calculateUsdUniTvl(
"0x23c7FA9A9f81B322684F25b8079e22C37e00b46b",
"thundercore",
"0x413cEFeA29F2d07B8F2acFA69d92466B9535f717",
[""],
"thunder-token"
),
},
};
51 changes: 30 additions & 21 deletions projects/loterra/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
const {fetchURL} = require('../helper/utils');
const { sumSingleBalance, TOKEN_LIST, getBalance, } = require('../helper/terra')

// Source: https://docs.loterra.io/resources/contract-addresses
const contracts = ["terra1e7hzp3tnsswpfcu6gt4wlgfm20lcsqqywhaagu", "terra1zcf0d95z02u2r923sgupp28mqrdwmt930gn8x5", "terra14mevcmeqt0n4myggt7c56l5fl0xw2hwa2mhlg0", "terra1q2k29wwcz055q4ftx4eucsq6tg9wtulprjg75w"]

async function tvl(){
const tokens = await Promise.all(contracts.map(contract=>fetchURL(`https://fcd.terra.dev/v1/bank/${contract}`)))
const total = tokens.map(data=>{
const ust = data.data.balance.find(t=>t.denom === "uusd")
if(ust === undefined){
return 0
}
return Number(ust.available)
})

return {
'terrausd': total.reduce((t, c)=>c+t)/1e6
}
const contracts = {
multiSig: 'terra1s4twvkqy0eel5saah64wxezpckm7v9535jjshy',
dogether: 'terra19h4xk8xxxew0ne6fuw0mvuf7ltmjmxjxssj5ts'
}

async function tvl(timestamp, ethBlock, { terra: block }) {
const balances = {}

// Add aUST tokens in the multi-sig
const aUSTBalance = await getBalance(TOKEN_LIST.anchorust, contracts.dogether, block)
sumSingleBalance(balances, TOKEN_LIST.anchorust, aUSTBalance)

return balances
}

async function treasury(timestamp, ethBlock, { terra: block }) {
const balances = {}

// Add aUST tokens in the multi-sig
const aUSTBalance = await getBalance(TOKEN_LIST.anchorust, contracts.multiSig, block)
sumSingleBalance(balances, TOKEN_LIST.anchorust, aUSTBalance)

return balances
}

module.exports = {
methodology: 'TVL counts the UST that is available as a prize on the protocol.',
terra:{
tvl
},
historical: false,
methodology: 'TVL counts the UST that is available as a prize on the protocol.',
terra: {
tvl,
treasury,
},
timetravel: false,
}
50 changes: 50 additions & 0 deletions projects/meanfinance/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
const sdk = require("@defillama/sdk");
const abi = require("./abi.json");
const { getChainTransform } = require("../helper/portedTokens")
const { request, gql } = require("graphql-request");

const GRAPH_URLS = {
polygon: 'https://api.thegraph.com/subgraphs/name/mean-finance/dca-v2-polygon',
optimism: 'https://api.thegraph.com/subgraphs/name/mean-finance/dca-v2-optimism'
}

const DCA_HUB_ADDRESSES = {
polygon: '0x230C63702D1B5034461ab2ca889a30E343D81349',
optimism: '0x230C63702D1B5034461ab2ca889a30E343D81349'
}

const query = gql`
query tokens {
tokens {
id
}
}`
;

const getTokensInChain = async (chain) => {
const result = await request(GRAPH_URLS[chain], query);
return result.tokens.map(({ id }) => id)
};

function getV2TvlObject(chain) {
return {
tvl: (_, __, chainBlocks) => getV2TVL(chain, chainBlocks[chain])
}
}

async function getV2TVL(chain, block) {
const balances = {};
const tokens = await getTokensInChain(chain)
const chainTransform = await getChainTransform(chain)
const hubAddress = DCA_HUB_ADDRESSES[chain]
for (const token of tokens) {
const balance = await sdk.api.erc20.balanceOf({
target: token,
owner: hubAddress,
block,
chain
})
sdk.util.sumSingleBalance(balances, chainTransform(token), balance.output);
}
return balances
}

//DCA Factory
const factoryAddress = "0xaC4a40a995f236E081424D966F1dFE014Fe0e98A";
Expand Down Expand Up @@ -40,4 +88,6 @@ module.exports = {
ethereum: {
tvl: ethTvl
},
optimism: getV2TvlObject('optimism'),
polygon: getV2TvlObject('polygon')
};
15 changes: 15 additions & 0 deletions projects/scion-finance/abis/scionVaultAbi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
totalHoldings: {
inputs: [],
name: "totalHoldings",
outputs: [
{
internalType: "uint256",
name: "totalUnderlyingHeld",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
},
};
10 changes: 10 additions & 0 deletions projects/scion-finance/addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const USDC = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";

module.exports = {
moonriver: [
{
ADDRESS: "0xc24D43093b44b7A9657571DDB79FEdf014eaef7d",
UNDERLYING: USDC,
},
],
};
39 changes: 39 additions & 0 deletions projects/scion-finance/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const sdk = require("@defillama/sdk");
const { getBlock } = require("../helper/getBlock");
const ADDRESSES = require("./addresses");
const scionVaultAbi = require("./abis/scionVaultAbi");

async function getVaultBalance(timestamp, chainBlocks, chain) {
const block = await getBlock(timestamp, chain, chainBlocks);
const balances = {};

const vaults = ADDRESSES[chain];

for (const vault of vaults) {
const { ADDRESS, UNDERLYING } = vault;

const totalHoldings = await sdk.api.abi.call({
abi: scionVaultAbi.totalHoldings,
chain,
target: ADDRESS,
block,
});

await sdk.util.sumSingleBalance(balances, UNDERLYING, totalHoldings.output);
}

return balances;
}

async function moonriver(timestamp, block, chainBlocks) {
return getVaultBalance(timestamp, chainBlocks, "moonriver");
}

module.exports = {
timetravel: true,
misrepresentedTokens: false,
methodology: "Measures the total value deposited in Scion vault contracts",
moonriver: {
tvl: moonriver,
},
};
13 changes: 8 additions & 5 deletions projects/sencha/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const utils = require('../helper/utils')
const {getTokenAccountBalance} = require('../helper/solana')
const {getTokenAccountBalance} = require('../helper/solana');
const { abi } = require('@defillama/sdk/build/api');
const abi = require("../sencha/abi.json")

async function tvl() {
// this is a list of token accounts that are reserves of a swap
// more details: https://github.com/senchahq/sencha-registry
const { data: senchaTokenAccounts } = await utils.fetchURL(
"https://raw.githubusercontent.com/SenchaHQ/sencha-registry/master/data/known-accounts.json"
);
const { data: senchaTokenAccounts } = abi;

const tvlResult = {};
await Promise.all(
Expand All @@ -26,5 +26,8 @@ module.exports = {
timetravel: false,
methodology:
"Sencha TVL is computed by iterating each known Sencha pool, then taking the value of each of the underlying tokens. Assets not listed on Coingecko are not counted.",
tvl,
solana: {
tvl,
}

};
39 changes: 39 additions & 0 deletions projects/sherpa-cash/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const sdk = require("@defillama/sdk");
const { getChainTransform } = require("../helper/portedTokens");

const ETHSherpaContracts = [
"0x6ceB170e3ec0fAfaE3Be5A02FEFb81F524FE85C5",
"0x7CE57f6a5a135eb1a8e9640Af1eff9665ade00D9",
"0xe1376DeF383D1656f5a40B6ba31F8C035BFc26Aa",
];
const WAVAX = "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7";

function getNativeTVL(contractAddresses, chain, token) {
return async function (timestamp, block, chainBlocks) {
const balances = {};
const chainTransform = await getChainTransform(chain);

for (const contract of contractAddresses) {
const result = (
await sdk.api.eth.getBalance({
target: contract,
block: chainBlocks[chain],
chain: chain,
})
).output;

sdk.util.sumSingleBalance(balances, chainTransform(token), result);
}

return balances;
};
}

module.exports = {
timetravel: true,
misrepresentedTokens: false,
methodology: "TVL consists of the sum of the balances of the Sherpa Cash privacy pools.",
avax: {
tvl: getNativeTVL(ETHSherpaContracts, "avax", WAVAX),
},
};
8 changes: 8 additions & 0 deletions projects/tempus.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const CHAIN_DATA = {
{
address: "0xc58b8DD0075f7ae7B1CF54a56F899D8b25a7712E",
token: USDC
},
{
address: "0x443297DE16C074fDeE19d2C9eCF40fdE2f5F62C2",
token: USDC
},
{
address: "0x7e0fc07280f47bac3D55815954e0f904c86f642E",
token: DAI
}
]
},
Expand Down
Loading

0 comments on commit 8d5abd5

Please sign in to comment.