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
buchaoqun authored Nov 23, 2024
2 parents d081754 + 650bb5a commit f7dbaf7
Show file tree
Hide file tree
Showing 65 changed files with 1,542 additions and 237 deletions.
13 changes: 6 additions & 7 deletions package-lock.json

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

73 changes: 73 additions & 0 deletions projects/BeetrootFinance/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

const { get } = require('../helper/http')
const ADDRESSES = require("../helper/coreAssets.json");
const { getJettonBalances } = require('../helper/chain/ton')

async function fetchVaultData(address) {
const url = 'https://api5.storm.tg/graphql';

const query = `
query VaultQuery($address: String!) {
getVault(address: $address) {
rate
}
}
`;

try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
operationName: 'VaultQuery',
variables: { address },
query
})
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const data = await response.json();
return data.data.getVault;
} catch (error) {
console.error('Error fetching vault data:', error);
throw error;
}
}

async function calculateTvl() {
const USDT_TLP_PRICE = (await get('https://tradoor.io/v3/lp/history/price?period=week')).data[0].price;

const vaultData = await fetchVaultData('0:33e9e84d7cbefff0d23b395875420e3a1ecb82e241692be89c7ea2bd27716b77');
const USDT_SLP_PRICE = vaultData?.rate / 1e9 || 0;

const balances = await getJettonBalances('0:c2f0c639b58e6b3cce8a145c73e7c7cc5044baa92b05c62fcf6da8a0d50b8edc');

const USDT_SLP_ADDRESS = '0:aea78c710ae94270dc263a870cf47b4360f53cc5ed38e3db502e9e9afb904b11';
const USDT_TLP_ADDRESS = '0:332c916f885a26051cb3a121f00c2bda459339eb103df36fe484df0b87b39384';

const USDT_SLP_BALANCE = balances[USDT_SLP_ADDRESS].balance / 1e9;
const USDT_TLP_BALANCE = balances[USDT_TLP_ADDRESS].balance / 1e9;

const tvl = ((USDT_TLP_PRICE * USDT_TLP_BALANCE) + (USDT_SLP_PRICE * USDT_SLP_BALANCE)) * 1e6;
return tvl;
}


async function tvl(api) {
const calculatedTvl = await calculateTvl();
api.add(ADDRESSES.ton.USDT, calculatedTvl);
}

module.exports = {
misrepresentedTokens: true,
timetravel: false,
methodology: `TVL calculation methodology consists of the delta between onchain USDT deposits and withdrawals`.trim(),
ton: {
tvl
}
}
9 changes: 9 additions & 0 deletions projects/Delea/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { sumTokensExport } = require("../helper/chain/ton");
const ADDRESSES = require("../helper/coreAssets.json");

module.exports = {
methodology: 'Counts Delea smartcontract balance as TVL.',
ton: {
tvl: sumTokensExport({ owners: ["EQB6rkS8xt3Ey4XugdVqQDe1vt4KJDh813_k2ceoONTCBnyD", "EQCwIIRKpuV9fQpQxdTMhLAO30MNHa6GOYd00TsySOOYtA9n", "EQA2OzCuP8-d_lN2MYxLv5WCNfpLH1NUuugppOZBZgNYn-aa", "EQCgGUMB_u1Gkrskw2o407Ig8ymQmfkxWuPW2d4INuQoPFJO"], tokens: [ADDRESSES.null]}),
}
}
19 changes: 19 additions & 0 deletions projects/acet/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const stakingAccounts = [
"0x64D2C3a33F5bc09Dc045f9A20fA4cA4f42215c0b",
"0xfb62ea552eeba8b00cc5db56ba8d7c50429c0001",
"0x38506a479E8959150466cE9253c19089fd0907D7",
];

const token = "0x9F3BCBE48E8b754F331Dfc694A894e8E686aC31D";

module.exports = {
bsc: {
tvl: async () => ({}),
staking: async (api) => {
return api.sumTokens({
tokensAndOwners: stakingAccounts.map((account) => [token, account]),
});
},
},
};

1 change: 1 addition & 0 deletions projects/alcor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async function wax() {
["alien.worlds", "TLM", "alien-worlds"],
["token.rfox", "USD", "redfox-labs"],
["usdt.alcor", "USDT", "usdt-alcor"],
["token.fusion", "LSWAX", "waxfusion-staked-wax"],
];
return await get_account_tvl(accounts, tokens, "wax");
}
Expand Down
46 changes: 31 additions & 15 deletions projects/alephium-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,42 @@ const sdk = require("@defillama/sdk");
const ADDRESSES = require('../helper/coreAssets.json')
const { sumTokensExport } = require('../helper/unwrapLPs');

const tokenBridgeAddress = '0x579a3bde631c3d8068cbfe3dc45b0f14ec18dd43'
const bridgedAlphAddress = '0x590f820444fa3638e022776752c5eef34e2f89a6'
const ethTokenBridgeAddress = '0x579a3bde631c3d8068cbfe3dc45b0f14ec18dd43'
const ethBridgedAlphAddress = '0x590f820444fa3638e022776752c5eef34e2f89a6'
const bscTokenBridgeAddress = '0x2971F580C34d3D584e0342741c6a622f69424dD8'
const bscBridgedAlphAddress = '0x8683BA2F8b0f69b2105f26f488bADe1d3AB4dec8'

async function tvl(ts, block) {
const totalBridgedAlphSupply = await sdk.api.erc20.totalSupply({ target: bridgedAlphAddress, block })
return {
alephium: totalBridgedAlphSupply.output / 1e18,
}
async function tvl(api) {
const ethApi = new sdk.ChainApi({ chain: 'ethereum', timestamp: api.timestamp })
const bscApi = new sdk.ChainApi({ chain: 'bsc', timestamp: api.timestamp })
await ethApi.getBlock()
await bscApi.getBlock()
const ethBal = await ethApi.call({ abi: 'erc20:totalSupply', target: ethBridgedAlphAddress })
const bscBal = await bscApi.call({ abi: 'erc20:totalSupply', target: bscBridgedAlphAddress })
api.addCGToken('alephium', (+ethBal + +bscBal) / 1e18)
}

module.exports = {
methodology: "Tracks funds locked in the Alephium Bridge Token contracts on Ethereum",
methodology: "Tracks funds locked in the Alephium Bridge Token contracts on Ethereum and Binance Smart Chain",
ethereum: {
tvl: sumTokensExport({ owner: tokenBridgeAddress, tokens: [
ADDRESSES.ethereum.WETH,
ADDRESSES.ethereum.USDT,
ADDRESSES.ethereum.USDC,
ADDRESSES.ethereum.WBTC,
ADDRESSES.ethereum.DAI
] }),
tvl: sumTokensExport({
owner: ethTokenBridgeAddress, tokens: [
ADDRESSES.ethereum.WETH,
ADDRESSES.ethereum.USDT,
ADDRESSES.ethereum.USDC,
ADDRESSES.ethereum.WBTC,
ADDRESSES.ethereum.DAI
]
}),
},
bsc: {
tvl: sumTokensExport({
owner: bscTokenBridgeAddress, tokens: [
ADDRESSES.bsc.WBNB,
ADDRESSES.bsc.USDC,
ADDRESSES.bsc.USDT
]
}),
},
alephium: {
tvl
Expand Down
18 changes: 15 additions & 3 deletions projects/aries-markets/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const sdk = require("@defillama/sdk");
const { default: BigNumber } = require("bignumber.js");
const { getResources, getTableData, } = require("../helper/chain/aptos");
const { transformBalances } = require("../helper/portedTokens");
const toHex = (str) => Buffer.from(str, 'utf-8').toString('hex');
Expand All @@ -11,7 +10,8 @@ async function _getResources() {
return resourcesCache
}
const extractCoinAddress = (str) => str.slice(str.indexOf("<") + 1, str.lastIndexOf(">"));
const reserveContrainerFilter = (i) => i.type.includes("0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::reserve::ReserveCoinContainer")
const reserveContrainerFilter = (i) => i.type.includes("0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::reserve::ReserveCoinContainer");
const faWrapperFilter = (i) => i.type.includes("0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::fa_to_coin_wrapper::WrapperCoinInfo");

module.exports = {
timetravel: false,
Expand All @@ -26,11 +26,20 @@ module.exports = {
lamports: i.data.underlying_coin.value,
tokenAddress: extractCoinAddress(i.type),
}));
const faWrappers = data.filter(faWrapperFilter)
.map((i) => ({
lamports: i.data.fa_amount,
faAddress: i.data.metadata.inner,
}));

coinContainers.forEach(({ lamports, tokenAddress }) => {
sdk.util.sumSingleBalance(balances, tokenAddress, lamports);
});

faWrappers.forEach(({ lamports, faAddress }) => {
sdk.util.sumSingleBalance(balances, faAddress, lamports);
});

return transformBalances("aptos", balances);
},
borrowed: async () => {
Expand Down Expand Up @@ -59,10 +68,13 @@ module.exports = {
});

const total_borrowed = BigInt(reserveStatus.total_borrowed.val) / BigInt(10 ** 18);

const faInfo = data.filter(faWrapperFilter).filter((i) => i.type.includes(coin_type));
const normalizedAddress = faInfo.length == 0 ? coin_type : faInfo[0].data.metadata.inner;

return {
lamports: total_borrowed.toString(),
tokenAddress: coin_type,
tokenAddress: normalizedAddress,
};
})
);
Expand Down
10 changes: 10 additions & 0 deletions projects/astherus-basis-trading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const USDF = "0x5A110fC00474038f6c02E89C707D638602EA44B5"

module.exports = {
bsc: {
tvl: async (api) => {
const supply = await api.call({ abi: 'erc20:totalSupply', target: USDF })
api.add(USDF, supply)
},
}
}
4 changes: 3 additions & 1 deletion projects/avalon-finance-usdalend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const { mergeExports } = require('../helper/utils')

//@note Main & Innovative Markets
const mainMarket = {
iotex: aaveExports('', '', undefined, ['0xDB52DD393e3a5e95d3B7C7e1C42cC06bb807A369'], { v3: true }),}
iotex: aaveExports('', '', undefined, ['0xDB52DD393e3a5e95d3B7C7e1C42cC06bb807A369'], { v3: true }),
}


module.exports = mergeExports(
mainMarket,
Expand Down
8 changes: 7 additions & 1 deletion projects/avalon-finance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const mainMarket = {
bsquared: aaveExports('', '', undefined, ['0x4Ea93E846b8C6E7b3D5a5BEDF4fe6B8AED58FCEe'], { v3: true }),
taiko: aaveExports('', '', undefined, ['0xF6Aa54a5b60c324602C9359E8221423793e5205d'], { v3: true }),
mode: aaveExports('', '', undefined, ['0xC5b05b7092257Ee3eEAf013198d30F1E8179B6C9'], { v3: true }),
klaytn: aaveExports('', '', undefined, ['0xddD3D480521bc027596e078BCd1b838d50Daa076'], { v3: true }), // Kaia V3 Main
zeta: aaveExports('', '', undefined, ['0xA34F1a928024E3609C8968fEA90C747e8D1fA20f'], { v3: true }), // Zetachain V3 Main
}

const innovativeMarket = {
Expand Down Expand Up @@ -68,7 +70,11 @@ const lbtcMarkets = {
bsc: aaveExports('', '', undefined, ['0x5b9b3C211B81627Cc6b46824CB26829F31A587dc'], { v3: true }),
}

const listaMarkets = {
bsc: aaveExports('', '', undefined, ['0x5157f63bE7808DEB090Eee7762e917745896A09E'], { v3: true }), // BSC - ListaDAO
}

module.exports = mergeExports(
mainMarket, innovativeMarket, solvMarkets, pumpBTCMarkets, unibtcMarkets, stbtcMarkets, otherProtocolTokenMarkets, obtcMarkets, ubtcMarkets, xaumMarkets, lbtcMarkets
mainMarket, innovativeMarket, solvMarkets, pumpBTCMarkets, unibtcMarkets, stbtcMarkets, otherProtocolTokenMarkets, obtcMarkets, ubtcMarkets, xaumMarkets, lbtcMarkets, listaMarkets,
)
module.exports.methodology = methodologies.lendingMarket
4 changes: 3 additions & 1 deletion projects/baklava-space/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const config = {
'0xf81Ac49CEeA834deC340aB08a544fB1E79d44c31',
'0xed1031885D7DE7DB78BE921F5FeAacD3f6E9a127',
'0x9bD9b6600eeE5f8318913cCb17BF836E1e9d2f4F',
'0x90011B2AB095c9a9f70a8eBEe21313FB3989029f' // CLM pool
'0x25F0Bc213ED49ABe3AD36CB8D0919A138d19b648',
'0x59639E20A17EaD110aaBAF249001Ab140917C18e',
'0x90011B2AB095c9a9f70a8eBEe21313FB3989029f' // CLM pool(Not calculated by defillama)
],
bsc: [
'0x6659B42C106222a50EE555F76BaD09b68EC056f9',
Expand Down
28 changes: 13 additions & 15 deletions projects/banx/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ADDRESSES = require('../helper/coreAssets.json')
const { Program, } = require("@project-serum/anchor");
const { Program } = require('@coral-xyz/anchor');
const { getConfig } = require('../helper/cache')
const { bs58 } = require('@project-serum/anchor/dist/cjs/utils/bytes');
const { getProvider } = require('../helper/solana')
Expand All @@ -11,28 +11,26 @@ async function getData() {
return data

async function getAllData() {
const programId = '4tdmkuY6EStxbS6Y8s5ueznL3VPMSugrvQuDeAHGZhSt'
const provider = getProvider()
const idl = await getConfig('banx-idl', 'https://api.banx.gg/idl')
const program = new Program(idl, programId, provider)
const program = new Program(idl, provider)

const bondOfferOffset = 32 + 8;
const bondTradeTxnOffset = 8;
const userVaultOffset = 8;
const [
bondOffers,
bondTradeTxn,
userVaults,
] = await Promise.all([
getFilteredAccounts(program, 'bondOfferV3', bondOfferOffset, [5, 7,]),
getFilteredAccounts(program, 'bondTradeTransactionV3', bondTradeTxnOffset, [2, 6, 9]),
])
getFilteredAccounts(program, 'bondTradeTransactionV3', bondTradeTxnOffset, [2, 6, 9, 13]),
getFilteredAccounts(program, 'userVault', userVaultOffset, [1]),
]);

// OffersSum is sum of sol in pools not yet lent out. The borrowedSum is the sum of SOL which has been borrowed and overcollaterized by the value of locked NFTs
const { offersSum, offersSumUsdc } = bondOffers.reduce(({ offersSum, offersSumUsdc }, offer) => {
if (offer.account.bondingCurve.bondingType.linearUsdc || offer.account.bondingCurve.bondingType.exponentialUsdc) {
return { offersSumUsdc: offersSumUsdc + (+offer.account.fundsSolOrTokenBalance) + Math.max(0, +offer.account.bidSettlement), offersSum };
const { escrowSum, escrowSumUsdc } = userVaults.reduce(({ escrowSum, escrowSumUsdc }, userVault) => {
if (userVault.account.lendingTokenType.usdc) {
return { escrowSum, escrowSumUsdc: escrowSumUsdc + (+userVault.account.offerLiquidityAmount) }
}
return { offersSum: offersSum + (+offer.account.fundsSolOrTokenBalance) + Math.max(0, +offer.account.bidSettlement), offersSumUsdc };
}, { offersSum: 0, offersSumUsdc: 0 });
return { escrowSum: escrowSum + (+userVault.account.offerLiquidityAmount), escrowSumUsdc }
}, { escrowSum: 0, escrowSumUsdc: 0 })

const { borrowedSum, borrowedSumUsdc } = bondTradeTxn.reduce(({ borrowedSum, borrowedSumUsdc }, bondTxn) => {
if (bondTxn.account.lendingToken.usdc) {
Expand All @@ -42,7 +40,7 @@ async function getData() {
}, { borrowedSum: 0, borrowedSumUsdc: 0 });


return { tvl: offersSum, tvlUsdc: offersSumUsdc, borrowed: borrowedSum, borrowedUsdc: borrowedSumUsdc }
return { tvl: escrowSum, tvlUsdc: escrowSumUsdc, borrowed: borrowedSum, borrowedUsdc: borrowedSumUsdc }
}
}

Expand Down
8 changes: 8 additions & 0 deletions projects/bitlayer-btc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { sumTokensExport } = require("../helper/sumTokens");
const { bitlayerBridge } = require("../helper/bitcoin-book");

module.exports = {
bitcoin: {
tvl: sumTokensExport({ owners: bitlayerBridge })
},
};
12 changes: 4 additions & 8 deletions projects/bountive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ const { multiCall } = require('../helper/chain/starknet')

const bountiveTokens = [
// BoSTRK: Bountive STRK
"0x05a0fff20829d60a0cdae2da18a32bd3de5c32f8d0109d2a0b59a88a7a77176e",
"0x018e009bbb035c506234e7a8eca6a7229adfd59a278ba3845285d28b03ed6d53",
// BoETH: Bountive ETH
"0x00d91e36ff68918b392c9cfc2e3f575526f69e04b97eb28142856fae3611fcf7",
"0x02fcaebd41710024e25b6dc646a62acb6560125a699a3f695b6adb54a180aaee",
// BoUSDC: Bountive USDC
"0x04ed6784fa5c11889851c2d13bbd80464e55605a90b5b664f9400df0fd6ef4a5",
"0x028a88bf75f1b10dc8552051a56fbdc732084af514f6065f4c67ea6d50204720",
// BoUSDT: Bountive USDT
"0x0753dc6f8fee7487fe3f32728c0f1af9df1f7a3d0443ef507eb79a974697be12",
// BoDAI: Bountive DAI
"0x06e32d47c49efb0243da8d456dc413f1dcf50ceea7be28ef520492eccfff2b43",
"0x0243d9a1cffc0b5ebbf549efd1232a96b1ef392fe595e91dd72103d5a8e7d847",
]

const underlyingsTokens = [
Expand All @@ -24,8 +22,6 @@ const underlyingsTokens = [
ADDRESSES.starknet.USDC,
// USDT
ADDRESSES.starknet.USDT,
// DAI
ADDRESSES.starknet.DAI,
]

async function tvl(api) {
Expand Down
Loading

0 comments on commit f7dbaf7

Please sign in to comment.