Skip to content

Commit

Permalink
Merge pull request #3 from DefiLlama/main
Browse files Browse the repository at this point in the history
Sync with origin
  • Loading branch information
AndrewAR2 authored Jan 16, 2024
2 parents d31bc29 + 5027360 commit 9f37ead
Show file tree
Hide file tree
Showing 441 changed files with 7,973 additions and 13,222 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commentResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
body = `The adapter at ${path} exports TVL:
\n \n ${file.substring(summaryIndex + 17).replaceAll('\n', '\n ')}`;
} else if (errorIndex != -1) {
body = `Error while running adapter at ${path}:
body = `Error while running adapter at ${path ?? ''}:
\n \n ${file.split(errorString)[1].replaceAll('\n', '\n ')}`;
} else
return;
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ jobs:
npm ci
# npm update @defillama/sdk
# fail if package.json or package-lock.json is changed
FILES_MODIFIED=${{ steps.file_changes.outputs.files_modified }}
if [[ $FILES_MODIFIED == *"package.json"* || $FILES_MODIFIED == *"package-lock.json"* ]]; then
echo "------ ERROR ------ > Please revert changes to package.json / package-lock.json" > /home/runner/work/DefiLlama-Adapters/DefiLlama-Adapters/output.txt
node ${{ github.workspace }}/.github/workflows/commentResult.js /home/runner/work/DefiLlama-Adapters/DefiLlama-Adapters/output.txt "${{ github.repository_owner }}" "${{ github.event.repository.name }}" "${{ github.event.number }}"
exit 1
fi
for i in $(echo $RUN_FILES | tr -d '"[]' | tr "," "\n")
do
{
Expand Down
9,391 changes: 2,245 additions & 7,146 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
"@defillama/sdk": "latest",
"@project-serum/anchor": "^0.26.0",
"@solana/web3.js": "^1.87.6",
"@solendprotocol/solend-sdk": "^0.6.2",
"@solendprotocol/solend-sdk": "^0.4.3",
"@supercharge/promise-pool": "^2.1.0",
"axios": "^0.27.2",
"axios": "^1.6.5",
"bignumber.js": "^9.0.1",
"blakejs": "^1.2.1",
"bn.js": "^5.2.1",
"borsh": "^0.7.0",
"curve25519-js": "^0.0.4",
"dotenv": "^8.6.0",
"ethers": "^5.6.5",
"ethers": "^6.0.0",
"graphql": "^16.6.0",
"graphql-request": "^4.0.0",
"hi-base32": "^0.5.1",
Expand All @@ -40,7 +40,7 @@
"p-limit": "^3.1.0",
"starknet": "^5.24.3",
"tron-format-address": "^0.1.8",
"typescript": "^4.7.4"
"typescript": "^5.0.0"
},
"overrides": {
"ansi-regex": "5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion projects/0vix/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
tvl: () => ({}),
borrowed: () => ({}),
},
// deadFrom: "2023-12-14",
deadFrom: "2023-12-14",
};

module.exports.polygon.borrowed = () => ({})
20 changes: 7 additions & 13 deletions projects/0xDAO/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const sanitize = require("./sanitizeWeb3Response.js");

const { standardPoolInfoAbi, addFundsInMasterChef } = require('../helper/masterchef')
const sdk = require('@defillama/sdk')
const { default: BigNumber } = require('bignumber.js')

const shareValue = "uint256:getShareValue"
const xSCREAM = "0xe3D17C7e840ec140a7A51ACA351a482231760824"
Expand Down Expand Up @@ -41,7 +40,7 @@ async function tvl(time, ethBlock, chainBlocks) {
abi: shareValue
})
sdk.util.sumSingleBalance(balances, transform("0xe0654C8e6fd4D733349ac7E09f6f23DA256bF475"),
BigNumber(screamShare.output).times(balances[transform(xSCREAM)]).div(1e18).toFixed(0))
screamShare.output *balances[transform(xSCREAM)] /1e18)
delete balances[transform(xSCREAM)]

const creditShare = await sdk.api.abi.call({
Expand All @@ -50,14 +49,14 @@ async function tvl(time, ethBlock, chainBlocks) {
abi: shareValue
})
sdk.util.sumSingleBalance(balances, transform("0x77128dfdd0ac859b33f44050c6fa272f34872b5e"),
BigNumber(creditShare.output).times(balances[transform(xCREDIT)]).div(1e18).toFixed(0))
creditShare.output * balances[transform(xCREDIT)] / 1e18)
delete balances[transform(xCREDIT)]

const tarotShare = await sdk.api.abi.call({
...calldata,
target: xTAROT,
abi: shareTarot,
params: balances[transform(xTAROT)]
params: sdk.util.convertToBigInt(balances[transform(xTAROT)])
})
sdk.util.sumSingleBalance(balances, transform("0xc5e2b037d30a390e62180970b3aa4e91868764cd"),
tarotShare.output)
Expand Down Expand Up @@ -95,10 +94,10 @@ async function tvl(time, ethBlock, chainBlocks) {
...pool.poolData,
...reserveData,
};
const shareOfTotalSupply = new BigNumber(newPool.totalSupply).div(newPool.poolData.totalSupply).toFixed()
const shareOfTotalSupply = newPool.totalSupply / newPool.poolData.totalSupply
newPool.shareOfTotalSupply = shareOfTotalSupply;
let token0Reserve = new BigNumber(newPool.poolData.token0Reserve).times(shareOfTotalSupply).toFixed(0);
let token1Reserve = new BigNumber(newPool.poolData.token1Reserve).times(shareOfTotalSupply).toFixed(0);
let token0Reserve = newPool.poolData.token0Reserve * shareOfTotalSupply
let token1Reserve = newPool.poolData.token1Reserve * shareOfTotalSupply
if (isNaN(token0Reserve)) {
token0Reserve = "0"
}
Expand Down Expand Up @@ -145,12 +144,7 @@ async function tvl(time, ethBlock, chainBlocks) {
// Add TVL from pools to balances
const addBalance = (tokenAddress, amount) => {
const fantomTokenAddress = `fantom:${tokenAddress}`
const existingBalance = balances[fantomTokenAddress];
if (existingBalance) {
balances[fantomTokenAddress] = new BigNumber(existingBalance).plus(amount).toFixed(0)
} else {
balances[fantomTokenAddress] = amount;
}
sdk.util.sumSingleBalance(balances, fantomTokenAddress, amount)
}
pools.forEach(pool => {
const token0 = pool.poolData.token0Address;
Expand Down
64 changes: 9 additions & 55 deletions projects/1beam/index.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,26 @@
const sdk = require('@defillama/sdk');
const { default: BigNumber } = require('bignumber.js');
const Abis = require('./abi.json');
const {getTokenId} = require('./utils')

const Contracts = {
moonbeam: {
pools: {
'ob3p': '0x04e274f709e1ae71aff4f994b4267143ec6a381a',
'ob3pbusd': '0x7e758319d46E0A053220e3728B3eE47a1979316a',
},
ignoredLps: ['0xe7a7dfb89f84a0cf850bcd399d0ec906ab232e9d'],
}
};

const poolTvl = async (chain, poolAddress, block) => {
const [balances, tokens] = await Promise.all([
sdk.api.abi.call({
target: poolAddress,
abi: Abis.getTokenBalances,
chain: chain,
block,
}),
sdk.api.abi.call({
target: poolAddress,
abi: Abis.getTokens,
chain: chain,
block,
}),
]);

const sum = {};

tokens.output.forEach((token, i) => {
if (
Contracts[chain].ignoredLps &&
Contracts[chain].ignoredLps.includes(token.toLowerCase())
) {
return;
}
const [symbol, decimals] = getTokenId(token.toLowerCase());
sum[symbol] = new BigNumber(balances.output[i]).div(new BigNumber(10).pow(decimals)).toNumber()
}

const moonbeamTvl = async (timestamp, ethBlock, chainBlocks, { api }) => {
const pools = Object.values(Contracts.moonbeam.pools)
const tokens = await api.multiCall({ abi: Abis.getTokens, calls: pools })
const bals = await api.multiCall({ abi: Abis.getTokenBalances, calls: pools })
tokens.forEach((token, i) => {
api.addTokens(token, bals[i])
});

return sum;
};

const moonbeamTvl = async (timestamp, ethBlock, chainBlocks) => {
let block = chainBlocks['moonbeam'];
const tvl = {};

for (let address of Object.values(Contracts.moonbeam.pools)) {
const balances = await poolTvl(
'moonbeam',
address,
block,
);

Object.entries(balances).forEach(([token, value]) => {
sdk.util.sumSingleBalance(tvl, token, value);
});
}

return tvl;
api.removeTokenBalance('0xe7a7dfb89f84a0cf850bcd399d0ec906ab232e9d')
};

module.exports = {
moonbeam: {
tvl: moonbeamTvl,
},

};
20 changes: 0 additions & 20 deletions projects/1beam/utils.js

This file was deleted.

2 changes: 1 addition & 1 deletion projects/1inch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Object.keys(config).forEach(chain => {
})
logs.forEach(i => ownerTokens.push([[i.token1, i.token2], i.mooniswap]))
}
return sumTokens2({ api, ownerTokens, blacklistedTokens, })
return sumTokens2({ api, ownerTokens, blacklistedTokens, sumChunkSize: 50, })
}
}
})
6 changes: 6 additions & 0 deletions projects/Chocoinu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { getUniTVL } = require('../helper/unknownTokens')

module.exports = {
misrepresentedTokens: true,
avax: { tvl: getUniTVL({ factory: '0x49a5044268A54467a94905d1458A88413695afc1', useDefaultCoreAssets: true, fetchBalances: true, }), },
}
12 changes: 5 additions & 7 deletions projects/CollectifDAO/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const {BigNumber} = require("@ethersproject/bignumber");
const {nullAddress} = require("../helper/tokenMapping");
const {get} = require("../helper/http");

Expand Down Expand Up @@ -32,19 +31,18 @@ module.exports = {
const minersOwners = await getMinersOwners();
const totalStaked = await api.call({abi: totalAssetsABI, target: COLLECTIF_LIQUID_STAKING_POOL_CONTRACT});

let totalCollateral = BigNumber.from(0);
let totalCollateral = 0

if (minersOwners && minersOwners.length > 0) {
const collaterals = await Promise.all(minersOwners.map(fetchCollateral));
totalCollateral = collaterals.reduce((acc, cur) => {
const [available, locked] = cur;
return acc.add(available).add(locked);
}, BigNumber.from(0));
return acc + +available + +locked
}, 0);
}

const tvl = BigNumber.from(totalStaked).add(totalCollateral).toString();

api.add(nullAddress, tvl)
api.add(nullAddress, totalStaked)
api.add(nullAddress, totalCollateral)
},
},
};
25 changes: 25 additions & 0 deletions projects/CreampanFinance/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const ADDRESSES = require('../helper/coreAssets.json')
const { queryV1Beta1 } = require("../helper/chain/cosmos");

const accounts = Object.values({
account1: 'cro1l3weyh4fkneyeatdh6jwp0u0t4qha22ycpnq7r',
account2: 'cro1zqvl7yj0zcqe7p0qnpg0sk94gpa38hzwz8shjn',
account3: 'cro1pduq0ga2ans0sspph6r5hcf77cqypz6de7n64y',
account4: 'cro1fncg0fsr8vt30qaqmzqxunnrkxr6a7xxkfpr7y',
account5: 'cro1hhfh6xaflg8zwhwvrs7sgur2pyfunjqeu8wsd6',
})

async function tvl(_, _1, _2, { api }) {
const data = await Promise.all(accounts.map(account => queryV1Beta1({ chain: 'cronos', url: `/staking/v1beta1/delegations/${account}`, })));
const factroy_contract_address = '0x66f5997b7810723aceeeb8a880846fc117081bd0';
data.map(i => i.delegation_responses).flat().forEach(i => api.add(ADDRESSES.cronos.WCRO, i.balance.amount * 1e10))
return api.sumTokens({ owner: factroy_contract_address, tokens: ['0x5c7f8a570d578ed84e63fdfa7b1ee72deae1ae23']})
}

module.exports = {
timetravel: false,
methodology: `The TVL is counted as the total delegated CRO and the flexible pool CRO. We query the crypto.org api for the delegations and sum up the CRO being delegated. We query the balanceOf the flexible pool address from WCRO contract`,
cronos: {
tvl,
}
}
38 changes: 38 additions & 0 deletions projects/DropCopy/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { getOwnerAllAccount, getTokenAccountBalance,getSolBalance } = require('../helper/solana')
const ADDRESSES = require('../helper/coreAssets.json')

const sdk = require('@defillama/sdk')
const { PublicKey } = require("@solana/web3.js")

const DROP = 'DropTpWcDmP7kVRUEoKSJaMVi62hGo9jp19Hz19JVsjh';
const PYTH = 'HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3';
const PARIMUTUEL_WALLET = 'DCa1Xir4zDEtz78beFcXCHUNXdeBnrxBiRuuapHrBE3F';
const PARIMUTUEL_ACCOUNT = 'mD62sAqPAiVbHGPTTeEianTYa1AytkKqqcxMvQxF3S3';

const predictionTokens = [
DROP,
PYTH
]
async function tvl(_, _1, _2, { api }) {

// get the total tokens deposited in the games
const tokensInAccount = await getOwnerAllAccount(PARIMUTUEL_WALLET);
tokensInAccount.forEach((pToken) => {
const total = pToken.uiAmount;
const tokenMint = pToken.mint;
// check to make sure it's one of the tokens used for predicting
if (predictionTokens.includes(tokenMint))
{
//sdk.log('#found',tokenMint)
api.add(tokenMint,total);
}
});
const sols = await getSolBalance(PARIMUTUEL_WALLET);
api.add(ADDRESSES.solana.SOL,sols);
}

module.exports = {
timetravel: false,
methodology: 'Count the number of tokens that are currently deposited in all the live prediction games',
solana: { tvl, },
}
4 changes: 4 additions & 0 deletions projects/Infernoswap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { uniTvlExport } = require('../helper/unknownTokens');

module.exports.hallmarks = [[1703808000, "Rug Pull"]]
module.exports = uniTvlExport('beam', '0x671235E91df0A21F319260F9e93Fc459519E163C', { fetchBalances: true})
3 changes: 3 additions & 0 deletions projects/Inufair/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { uniTvlExport } = require('../helper/unknownTokens');

module.exports = uniTvlExport('zkfair', '0x3582Ccde3F786229CE6Dbd88c5aDb86bF64DAA31', { fetchBalances: true, })
12 changes: 12 additions & 0 deletions projects/Liquify-Manta/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { getUniTVL } = require('../helper/unknownTokens.js')

module.exports = {
misrepresentedTokens: true,
manta:{
tvl: getUniTVL({
useDefaultCoreAssets: true,
hasStablePools: true,
factory: '0x951f08e103570C0385649B24bE892eefFb5Ce067',
}),
},
}
3 changes: 3 additions & 0 deletions projects/PoorExchange/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { uniTvlExport } = require('../helper/unknownTokens')

module.exports = uniTvlExport('arbitrum', '0x9fA0988D9e4b6362e0aaA02D1A09196a78c177e1', { fetchBalances: true, })
6 changes: 6 additions & 0 deletions projects/SquadSwap-v3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { uniV3Export } = require('../helper/uniswapV3')
const factory = '0x009c4ef7C0e0Dd6bd1ea28417c01Ea16341367c3'

module.exports = uniV3Export({
bsc: { factory, fromBlock: 34184408 }
})
19 changes: 19 additions & 0 deletions projects/SquadSwap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { stakings } = require("../helper/staking");
const { getUniTVL } = require('../helper/unknownTokens')
const masterchefV2Address = '0x2e881a10f682a3b2CBaaF8fc5A9a94E98D4879B4'; // SquadSwap's MasterChef V2 contract
const masterchefV3Address = '0x44eC8143EB368cAbB00c4EfF085AF276260202B5'; // SquadSwap's MasterChef V3 contract
const squadTokenAddress = '0x2d2567dec25c9795117228adc7fd58116d2e310c'; // SquadSwap token contract

module.exports = {
methodology: "TVL is calculated from total liquidity of SquadSwap's active pools",
bsc: {
tvl: getUniTVL({
factory: '0x1D9F43a6195054313ac1aE423B1f810f593b6ac1',
useDefaultCoreAssets: true,
}),
staking: stakings([
masterchefV2Address,
masterchefV3Address,
], squadTokenAddress)
}
};
Loading

0 comments on commit 9f37ead

Please sign in to comment.