diff --git a/projects/elocks/index.js b/projects/elocks/index.js index 271e64aad656..c58ccecdffaa 100644 --- a/projects/elocks/index.js +++ b/projects/elocks/index.js @@ -27,6 +27,37 @@ async function findTvl(chain, nft, block, api) { chain, }) len = Number(len); + //console.log("nft.ts", len); + + + /* + /// Using TVL GURU (on-chain price calcs) + + let calls = [] + for (let i = 1; i <= len; i++) { calls.push({ params: [i] }) } + let { output: lockaddrs } = await sdk.api.abi.multiCall({ + target: nft, + abi: IELOCKS.lockers, + calls, + chain, + }) + lockaddrs = lockaddrs.map(i=>i.output) + //console.log("lockaddrs",lockaddrs) + + const ltvls = ( + await sdk.api.abi.multiCall({ + abi: IELOCKS.tvl, + calls: lockaddrs.map((la) => ({ target: la })), + chain + }) + ).output.map((tvl) => Number(tvl.output)/1e18); + //console.log("ltvls",ltvls) + + return { tether: ltvls.reduce((a,b)=>a+b) }; + */ + + + /// Using DefiLlama pricing let calls = [] for (let i = 1; i <= len; i++) { calls.push({ params: [i] }) } @@ -36,10 +67,32 @@ async function findTvl(chain, nft, block, api) { calls, chain, }) - lpBalances = las.map(i=> ({token: i.output[0], balance: Number(i.output[1])/1e0}) ) - tokens = lpBalances.map(i=>i.token) - bals = lpBalances.map(i=>i.balance) + /* + /// Using { 0x123: 123, 0xtoken2: 456, ... } + + //las = las.map(i=> ({lpt: i.output[0], amt: Number(i.output[1])/1e0}) ) + las = las.map(i=> ({ [i.output[0].toLowerCase()] : Number(i.output[1])/1e0 }) ) + let lpamts = {}; + las.forEach(obj => { + for (let key in obj) { + if (lpamts[key]) { + lpamts[key] += obj[key]; + } else { + lpamts[key] = obj[key]; + } + } + }); + //console.log("las",las,lpamts) + console.log(await getTokenPrices(lpamts)) + return lpamts; + */ + let lpBalances = las.map(i=> ({token: i.output[0], balance: Number(i.output[1])/1e0}) ) + //console.log("las",las,lpBalances) + let tokens = lpBalances.map(i=>i.token) + let bals = lpBalances.map(i=>i.balance) api.addTokens(tokens, bals) + //return await sumUnknownTokens({ api, tokensAndOwners: [], useDefaultCoreAssets: true, lps: tokens, resolveLP: true, }) + //await unwrapUniswapLPs(lpBalances, chain) return await unwrapUniswapLPs(bals, lpBalances, block, chain) }