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 Nov 7, 2023
2 parents 4ecbead + 04f6b82 commit 8fde027
Show file tree
Hide file tree
Showing 32 changed files with 385 additions and 58 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

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

24 changes: 24 additions & 0 deletions projects/CofferCity/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const abi = {
"getSupportedTokens": "function getSupportedTokens() view returns (address[] supportedTokens)"
}

const config = {
kava: {
CofferCityKAVA: '0x860880862Ee1B74D00E2F94B1C81A67C2c58117E'
}
}

module.exports = {
methodology: 'Counts TVL of all the assets supported by the Coffer City smart contracts'
};

Object.keys(config).forEach(chain => {
module.exports[chain] = {
tvl: async (_, _b, _cb, { api, }) => {
const vaults = Object.values(config[chain])
const tokens = await api.multiCall({ abi: abi.getSupportedTokens, calls: vaults })
const ownerTokens = vaults.map((v, i) => [tokens[i], v])
return api.sumTokens({ ownerTokens })
}
}
})
4 changes: 3 additions & 1 deletion projects/aave/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function v3(chain) {
params = ['0x9E7B73ffD9D2026F3ff4212c29E209E09C8A91F5', undefined, ['0x99411FC17Ad1B56f49719E3850B2CDcc0f9bBFd8']]
else if (chain === 'base')
params = ['0x2f6571d3Eb9a4e350C68C36bCD2afe39530078E2', undefined, ['0x2d8A3C5677189723C4cB8873CfC9C8976FDF38Ac']]
else if (chain === 'xdai')
params = ['0x36616cf17557639614c1cdDb356b1B83fc0B2132', undefined, ['0x501B4c19dd9C2e06E94dA7b6D5Ed4ddA013EC741']]
const section = borrowed => aaveChainTvl(chain, ...params, borrowed, true);
return {
tvl: section(false),
Expand All @@ -20,7 +22,7 @@ function v3(chain) {
module.exports = {
methodology: `Counts the tokens locked in the contracts to be used as collateral to borrow or to earn yield. Borrowed coins are not counted towards the TVL, so only the coins actually locked in the contracts are counted. There's multiple reasons behind this but one of the main ones is to avoid inflating the TVL through cycled lending`,
avax: v3("avax"),
...["optimism", "fantom", "harmony", "arbitrum", "polygon", "ethereum", "metis", "base"].reduce((t, c) => ({ ...t, [c]: v3(c) }), {}),
...["optimism", "fantom", "harmony", "arbitrum", "polygon", "ethereum", "metis", "base", "xdai"].reduce((t, c) => ({ ...t, [c]: v3(c) }), {}),
hallmarks: [
[1659630089, "Start OP Rewards"],
[1650471689, "Start AVAX Rewards"]
Expand Down
4 changes: 2 additions & 2 deletions projects/blockswap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const { GraphQLClient, gql } = require('graphql-request');

const ethAddress = ADDRESSES.null

const lsd_subgraph = 'https://api.thegraph.com/subgraphs/name/stakehouse-dev/lsd'
const lsd_subgraph = 'https://lsd-subgraph.joinstakehouse.com'

const stakehouse_subgraph = 'https://api.thegraph.com/subgraphs/name/stakehouse-dev/stakehouse-protocol'
const stakehouse_subgraph = 'https://stakehouse-subgraph.joinstakehouse.com'

async function tvl(_, _1, _2, { api }) {
let balances = {};
Expand Down
14 changes: 14 additions & 0 deletions projects/davincigraph/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { fetchURL } = require("../helper/utils");

module.exports = {
timetravel: false,
methodology:
"The displayed value represents the Total Value Locked (TVL) in USD of all assets secured within the davincigraph token locker smart contracts, accessible at https://davincigraph.io/devs/locks/contracts",
fetch: async () => {
const response = await fetchURL(
"https://davincigraph.network/api/v1/locks/statistics"
);

return response.data.tvl.locked.liquidity;
},
};
5 changes: 5 additions & 0 deletions projects/eris-protocol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ const config = {
"terra1vklefn7n6cchn0u962w3gaszr4vf52wjvd4y95t2sydwpmpdtszsqvk9wy",
coinGeckoId: "lion-dao",
},
{
contract:
"terra186rpfczl7l2kugdsqqedegl4es4hp624phfc7ddy8my02a4e8lgq5rlx7y",
coinGeckoId: "capapult",
},
],
},
terra: {
Expand Down
20 changes: 9 additions & 11 deletions projects/friend3/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const { sumTokens2, nullAddress } = require("../helper/unwrapLPs");
const { nullAddress, sumTokensExport } = require("../helper/unwrapLPs");

const contract = "0x1e70972EC6c8a3FAe3aC34C9F3818eC46Eb3BD5D";

async function tvl(time, ethBlock, _b, { api }) {
return sumTokens2({ tokens: [nullAddress], owner: contract, api });
const config = {
bsc: '0x1e70972EC6c8a3FAe3aC34C9F3818eC46Eb3BD5D',
op_bnb: '0x2C5bF6f0953ffcDE678A35AB7d6CaEBC8B6b29F0',
}

module.exports = {
methodology: `We count the ETH on ${contract}`,
bsc: {
tvl,
},
};
Object.keys(config).forEach(chain => {
module.exports[chain] = {
tvl: sumTokensExport({ tokens: [nullAddress], owner: config[chain] })
}
})
34 changes: 27 additions & 7 deletions projects/gambit/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
const ADDRESSES = require('../helper/coreAssets.json')
const { sumTokensExport } = require("../helper/unwrapLPs");

const SimpleGToken = "0x0729e806f57CE71dA4464c6B2d313E517f41560b"; // SimpleGToken
const Treasury = "0x1fb8611064a09469F808263C398623A86e7Aa883"; // Treasury
const SimpleGToken = {
era: "0x0729e806f57CE71dA4464c6B2d313E517f41560b",
arbitrum: "0xAC29F414FB40BA4e29Ab8504a55cBfFD315D2430"
}
const Treasury = {
era: "0x1fb8611064a09469F808263C398623A86e7Aa883",
arbitrum: "0x15c80BbC0D05656002BD922BFbf46e185BCa5A9e"
}
const Staking = {
arbitrum: "0x05027E21F6cEfb38970f4e0c04cD6DacA15aCBcE",
}

const CNG_ADDRESS = {
ethereum: "0x5C1d9aA868a30795F92fAe903eDc9eFF269044bf",
arbitrum: "0x4e7e5023656863E26f50E2E6E59489A852C212c1",
}

module.exports = {
methodology: `Count the USDC that has been deposited on Gambit`,
era: {
tvl: sumTokensExport({ owners: [SimpleGToken, Treasury], tokens: [ADDRESSES.era.USDC], }),
},
methodology: `Count the USDC that has been deposited on Gambit`,
era: {
tvl: sumTokensExport({ owners: [SimpleGToken.era, Treasury.era], tokens: [ADDRESSES.era.USDC], }),
},
arbitrum: {
tvl: sumTokensExport({
owners: [SimpleGToken.arbitrum, Treasury.arbitrum],
tokens: [ADDRESSES.arbitrum.USDC_CIRCLE],
}),
staking: sumTokensExport({ owners: [Staking.arbitrum], tokens: [CNG_ADDRESS.arbitrum], }),
},
};

1 change: 1 addition & 0 deletions projects/helper/cex.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const defaultTokens = {
'0x25ec98773d7b4ced4cafab96a2a1c0945f145e10', // stUSDT
'0x3c3a81e81dc49A522A592e7622A7E711c06bf354', // MNT
'0x61e90a50137e1f645c9ef4a0d3a4f01477738406', // LOKA
'0x64d0f55Cd8C7133a9D7102b13987235F486F2224', // BORG
],
tron: [
nullAddress,
Expand Down
2 changes: 2 additions & 0 deletions projects/helper/chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"carbon",
"cardano",
"celo",
"chz",
"chihuahua",
"clover",
"clv",
Expand Down Expand Up @@ -66,6 +67,7 @@
"enuls",
"eos",
"eos_evm",
"eon",
"equilibrium",
"era",
"ergo",
Expand Down
9 changes: 1 addition & 8 deletions projects/helper/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@ const DEFAULTS = {
APTOS_RPC: 'https://aptos-mainnet.pontem.network',
SUI_RPC: 'https://fullnode.mainnet.sui.io/',
MULTIVERSX_RPC: 'https://api.multiversx.com',
ETHEREUMCLASSIC_RPC: 'https://etc.etcdesktop.com,https://etc.rivet.link',
CRAB_RPC: 'https://darwiniacrab-rpc.dwellir.com',
ANKR_API_KEY: '79258ce7f7ee046decc3b5292a24eb4bf7c910d7e39b691384c7ce0cfb839a01',
RENEC_RPC: "https://api-mainnet-beta.renec.foundation:8899/",
ZYX_RPC: "https://rpc-1.zyx.network",
EVMOS_RPC: "https://evmos-evm.publicnode.com",
NOVA_RPC: "https://connect.novanetwork.io",
ETHF_RPC: "https://rpc.etherfair.org",
SCROLL_RPC: "https://rpc-scroll.icecreamswap.com",
HECO_RPC: "https://http-mainnet-node.huobichain.com",
CHZ_RPC: "https://chiliz.publicnode.com,https://rpc.ankr.com/chiliz",
}

const ENV_KEYS = [
Expand Down
10 changes: 10 additions & 0 deletions projects/helper/tokenMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const fixBalancesTokens = {
[ADDRESSES.ethf.WETH]: { coingeckoId: 'ethereumfair', decimals: 18 },
[ADDRESSES.null]: { coingeckoId: 'ethereumfair', decimals: 18 },
},
chz: {
[ADDRESSES.null]: { coingeckoId: 'chiliz', decimals: 18 },
},
// Sample Code
ozone: {
// '0x83048f0bf34feed8ced419455a4320a735a92e9d': { coingeckoId: "ozonechain", decimals: 18 }, // was mapped to wrong chain
Expand All @@ -67,11 +70,18 @@ const fixBalancesTokens = {
elsm: {
'0xa801b1a7846156d4c81bd188f96bfcb621517611': { coingeckoId: 'vulcan-forged', decimals: 18 },
},
arbitrum: {
'0x4e7e5023656863E26f50E2E6E59489A852C212c1': { coingeckoId: 'changer', decimals: 18 },
},
bfc: {
[ADDRESSES.bfc.WBFC]: { coingeckoId: 'bifrost', decimals: 18},
[ADDRESSES.bfc.BIFI]: { coingeckoId: 'bifi', decimals: 18},
'0xB1f3A83597Bce2AD842c29bD750AE17afc474137': {coingeckoId: 'witch-token', decimals: 18},
'0x17102AC78a02a98fC78B0c29B7b0506f035A99E5': {coingeckoId: 'super-athletes-token', decimals: 18}
},
eon: {
'0xF5cB8652a84329A2016A386206761f455bCEDab6': {coingeckoId: 'zencash', decimals: 18},
'0x1d7fb99AED3C365B4DEf061B7978CE5055Dfc1e7': {coingeckoId: 'wrapped-bitcoin', decimals: 8},
}
}

Expand Down
3 changes: 2 additions & 1 deletion projects/helper/utils/solana/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { parseLido, parseLidoValidatorList } = require('./layouts/lido')
const { parsePhoenix } = require('./layouts/phoenix-dex')
const { RAYDIUM_LIQUIDITY_STATE_LAYOUT_CLMM, RAYDIUM_STABLE_STATE_LAYOUT_V1, } = require('./layouts/raydium-layout')
const { INVESTIN_FUND_DATA, } = require('./layouts/investin-layout')
const { MARKET_STATE_LAYOUT_V3, } = require('./layouts/openbook-layout')
const { MARKET_STATE_LAYOUT_V3, OPEN_ORDERS_LAYOUT_V2 } = require('./layouts/openbook-layout')
const { ReserveLayout, ReserveLayoutLarix, MintLayout, AccountLayout, TokenSwapLayout, ESOLStakePoolLayout, } = require('./layouts/mixed-layout')

const parseReserve = (info) => {
Expand Down Expand Up @@ -45,6 +45,7 @@ const customDecoders = {
ESOLStakePool: defaultParseLayout(ESOLStakePoolLayout),
investinFund: defaultParseLayout(INVESTIN_FUND_DATA),
openbook: defaultParseLayout(MARKET_STATE_LAYOUT_V3),
openbookOpenOrders: defaultParseLayout(OPEN_ORDERS_LAYOUT_V2),
// raydiumLPv4: defaultParseLayout(RAYDIUM_LIQUIDITY_STATE_LAYOUT_V4),
raydiumCLMM: defaultParseLayout(RAYDIUM_LIQUIDITY_STATE_LAYOUT_CLMM),
raydiumLPStable: defaultParseLayout(RAYDIUM_STABLE_STATE_LAYOUT_V1),
Expand Down
25 changes: 25 additions & 0 deletions projects/helper/utils/solana/layouts/openbook-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,33 @@ const MARKET_STATE_LAYOUT_V3 = struct([
blob(7),
]);

const OPEN_ORDERS_LAYOUT_V2 = struct([
blob(5),

accountFlagsLayout('accountFlags'),

publicKey('market'),
publicKey('owner'),

u64('baseTokenFree'),
u64('baseTokenTotal'),
u64('quoteTokenFree'),
u64('quoteTokenTotal'),

u128('freeSlotBits'),
u128('isBidBits'),

seq(u128(), 128, 'orders'),
seq(u64(), 128, 'clientIds'),

u64('referrerRebatesAccrued'),

blob(7),
]);


module.exports = {
MARKET_STATE_LAYOUT_V3,
OPEN_ORDERS_LAYOUT_V2
}

25 changes: 25 additions & 0 deletions projects/kai/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const sui = require("../helper/chain/sui");

const WHUSDCE_VAULT_ID =
"0x7a2f75a3e50fd5f72dfc2f8c9910da5eaa3a1486e4eb1e54a825c09d82214526";
const WHUSDCE_TYPE_ARG = '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN'

async function tvl(_, _1, _2, { api }) {
const res = await sui.getObject(WHUSDCE_VAULT_ID)

let tvl = BigInt(res.fields.free_balance)
for (const strategy of res.fields.strategies.fields.contents) {
tvl += BigInt(strategy.fields.value.fields.borrowed)
}
tvl += BigInt(res.fields.free_balance)

api.add(WHUSDCE_TYPE_ARG, Number(tvl))
}

module.exports = {
timetravel: false,
sui: {
tvl,
},
};

16 changes: 16 additions & 0 deletions projects/lendoraprotocol/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { compoundExports2 } = require("../helper/compound");
const { staking } = require('../helper/staking')

module.exports = {
scroll: compoundExports2({
comptroller: '0xA27CDE1F3dcaaF653624049Fc3b1a720eC1D4e91',
fetchBalances: true,
cether: '0xBC7fA7C2dF265d073Be6D1c88468AEB5c06ba07c',
}),
};

module.exports.scroll.staking = staking(
['0xca4fb5541D0f2899549e5f454155E1B34acc9379', '0x578E4f84663260e5C5c64d5310Dd76aA3CEC633c'],
'0x3e6c99915803631D200441CdF6D84786912b0871',
'scroll'
)
35 changes: 35 additions & 0 deletions projects/mango-markets-v4/deposits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { Program } = require("@project-serum/anchor");
const { getProvider, sumTokens2 } = require("../helper/solana");
const idl = require("./idl.json");

async function depositsTvl() {
const provider = getProvider();
const program = new Program(
idl,
"4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg",
provider,
);
const banks = await program.account.bank.all();
return sumTokens2({ tokenAccounts: banks.map((i) => i.account.vault) });
}
async function borrowed() {
const { api } = arguments[3];
const provider = getProvider();
const program = new Program(
idl,
"4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg",
provider,
);
const banks = await program.account.bank.all();
banks.forEach(({ account: i }) => {
api.add(
i.mint.toString(),
i.indexedBorrows.val.mul(i.borrowIndex.val).toString() / 2 ** (48 * 2),
);
});
}

module.exports = {
depositsTvl,
borrowed,
};
Loading

0 comments on commit 8fde027

Please sign in to comment.