mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-04-29 13:25:30 +08:00
Add borrowed to maple protocol
This commit is contained in:
@@ -69,5 +69,18 @@
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
"principalOut": {
|
||||
"inputs": [],
|
||||
"name": "principalOut",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
const sdk = require("@defillama/sdk");
|
||||
const abi = require("./abi.json");
|
||||
const { sumTokensAndLPsSharedOwners } = require("../helper/unwrapLPs");
|
||||
const { sumTokensAndLPsSharedOwners, sumTokens2 } = require("../helper/unwrapLPs");
|
||||
const { staking, } = require("../helper/staking")
|
||||
|
||||
const PoolFactory = "0x2Cd79F7f8b38B9c0D80EA6B230441841A31537eC";
|
||||
|
||||
const MapleTreasury = "0xa9466EaBd096449d650D5AEB0dD3dA6F52FD0B19";
|
||||
const USDC = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
|
||||
const chain = 'ethereum'
|
||||
|
||||
/*** Treasury ***/
|
||||
const Treasury = async (timestamp, ethBlock, chainBlocks) => {
|
||||
@@ -24,55 +26,79 @@ const Treasury = async (timestamp, ethBlock, chainBlocks) => {
|
||||
};
|
||||
|
||||
/*** Ethereum TVL Portions ***/
|
||||
const ethTvl = async (timestamp, ethBlock, chainBlocks) => {
|
||||
const balances = {};
|
||||
|
||||
const ethTvl = async (timestamp, block) => {
|
||||
const poolsCreated = (
|
||||
await sdk.api.abi.call({
|
||||
abi: abi.poolsCreated,
|
||||
target: PoolFactory,
|
||||
block: ethBlock
|
||||
block
|
||||
})
|
||||
).output;
|
||||
const calls = []
|
||||
|
||||
for (let i = 0; i < poolsCreated; i++) {
|
||||
const pool = (
|
||||
await sdk.api.abi.call({
|
||||
abi: abi.pools,
|
||||
target: PoolFactory,
|
||||
params: i,
|
||||
block: ethBlock
|
||||
})
|
||||
).output;
|
||||
for (let i = 0; i < poolsCreated; i++)
|
||||
calls.push({ params: i })
|
||||
|
||||
const { output: pools } = await sdk.api.abi.multiCall({
|
||||
target: PoolFactory,
|
||||
abi: abi.pools,
|
||||
calls,
|
||||
chain, block,
|
||||
})
|
||||
|
||||
const assetOfLiquidity = (
|
||||
await sdk.api.abi.call({
|
||||
abi: abi.liquidityAsset,
|
||||
target: pool,
|
||||
block: ethBlock
|
||||
})
|
||||
).output;
|
||||
const { output: assetOfLiquidity } = await sdk.api.abi.multiCall({
|
||||
abi: abi.liquidityAsset,
|
||||
calls: pools.map(i => ({ target: i.output })),
|
||||
chain, block,
|
||||
})
|
||||
|
||||
const locker = (
|
||||
await sdk.api.abi.call({
|
||||
abi: abi.liquidityLocker,
|
||||
target: pool,
|
||||
block: ethBlock
|
||||
})
|
||||
).output;
|
||||
const { output: locker } = await sdk.api.abi.multiCall({
|
||||
abi: abi.liquidityLocker,
|
||||
calls: pools.map(i => ({ target: i.output })),
|
||||
chain, block,
|
||||
})
|
||||
|
||||
let locked = (
|
||||
await sdk.api.erc20.balanceOf({
|
||||
owner: locker,
|
||||
target: assetOfLiquidity,
|
||||
block: ethBlock,
|
||||
})
|
||||
).output;
|
||||
const toa = assetOfLiquidity.map(({ output }, i) => [output, locker[i].output])
|
||||
|
||||
sdk.util.sumSingleBalance(balances, assetOfLiquidity, locked);
|
||||
}
|
||||
return sumTokens2({ tokensAndOwners: toa, block})
|
||||
};
|
||||
|
||||
return balances;
|
||||
|
||||
const borrowed = async (timestamp, block) => {
|
||||
const poolsCreated = (
|
||||
await sdk.api.abi.call({
|
||||
abi: abi.poolsCreated,
|
||||
target: PoolFactory,
|
||||
block
|
||||
})
|
||||
).output;
|
||||
const calls = []
|
||||
|
||||
for (let i = 0; i < poolsCreated; i++)
|
||||
calls.push({ params: i })
|
||||
|
||||
const { output: pools } = await sdk.api.abi.multiCall({
|
||||
target: PoolFactory,
|
||||
abi: abi.pools,
|
||||
calls,
|
||||
chain, block,
|
||||
})
|
||||
|
||||
const { output: assetOfLiquidity } = await sdk.api.abi.multiCall({
|
||||
abi: abi.liquidityAsset,
|
||||
calls: pools.map(i => ({ target: i.output })),
|
||||
chain, block,
|
||||
})
|
||||
|
||||
const { output: principalOut } = await sdk.api.abi.multiCall({
|
||||
abi: abi.principalOut,
|
||||
calls: pools.map(i => ({ target: i.output })),
|
||||
chain, block,
|
||||
})
|
||||
|
||||
const balances = {}
|
||||
assetOfLiquidity.forEach(({ output}, i) => sdk.util.sumSingleBalance(balances, output, principalOut[i].output))
|
||||
return balances
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
@@ -80,6 +106,8 @@ module.exports = {
|
||||
ethereum: {
|
||||
tvl: ethTvl,
|
||||
treasury: Treasury,
|
||||
staking: staking('0x4937a209d4cdbd3ecd48857277cfd4da4d82914c', '0x33349b282065b0284d756f0577fb39c158f935e6'),
|
||||
borrowed,
|
||||
},
|
||||
methodology:
|
||||
"We count liquidity by USDC deposited on the pools through PoolFactory contract",
|
||||
|
||||
Reference in New Issue
Block a user