Skip to content

Commit 0f54344

Browse files
buchaoqung1nt0kiqwen-solvAn-Haijun
authored
add projects solvbtc bitcion network (DefiLlama#11474)
Co-authored-by: g1nt0ki <[email protected]> Co-authored-by: qwen-solv <[email protected]> Co-authored-by: hja <[email protected]>
1 parent dfeaf5f commit 0f54344

File tree

2 files changed

+43
-262
lines changed

2 files changed

+43
-262
lines changed

projects/solv-protocol-funds/index.js

Lines changed: 25 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -30,103 +30,24 @@ async function tvl(api) {
3030
await vaultBalance(api, graphData);
3131
await otherDeposit(api, address);
3232
await ceffuBalance(api, address, graphData);
33-
34-
return api.getBalances();
3533
}
3634

37-
async function borrowed(api) {
38-
const network = api.chain;
39-
40-
const graphData = await getGraphData(api.timestamp, network, api);
41-
if (graphData.pools.length > 0) {
42-
const poolLists = graphData.pools;
43-
44-
let address = (await getConfig('solv-protocol/funds', addressUrl));
45-
const depositAddress = filterDepositAddress(network, address);
46-
47-
let fofFundPoolId = [];
48-
if (address[network] && address[network]["fofFund"]) {
49-
fofFundPoolId = address[network]["fofFund"];
50-
}
51-
52-
let pools = [];
53-
for (const pool of poolLists) {
54-
if (depositAddress.length == 0 && depositAddress.indexOf(pool.vault) == -1 && fofFundPoolId.indexOf(pool.poolId) == -1) {
55-
pools.push(pool);
56-
}
57-
}
58-
59-
const poolConcretes = await concrete(pools, api);
60-
const nav = await api.multiCall({
61-
abi: abi.getSubscribeNav,
62-
calls: pools.map((index) => ({
63-
target: index.navOracle,
64-
params: [index.poolId, api.timestamp * 1000]
65-
})),
66-
})
67-
68-
const poolTotalValues = await api.multiCall({
69-
abi: abi.slotTotalValue,
70-
calls: pools.map((index) => ({
71-
target: poolConcretes[index.contractAddress],
72-
params: [index.openFundShareSlot]
73-
})),
74-
})
75-
76-
const poolBaseInfos = await api.multiCall({
77-
abi: abi.slotBaseInfo,
78-
calls: pools.map((index) => ({
79-
target: poolConcretes[index.contractAddress],
80-
params: [index.openFundShareSlot]
81-
})),
82-
})
83-
84-
const poolDecimalList = await api.multiCall({
85-
abi: abi.decimals,
86-
calls: poolBaseInfos.map(i => i[1]),
87-
})
88-
89-
let vaults = {};
90-
for (const key in pools) {
91-
if (poolBaseInfos[key][1] && pools[key]["vault"]) {
92-
vaults[`${pools[key]["vault"].toLowerCase()}-${poolBaseInfos[key][1].toLowerCase()}`] = [poolBaseInfos[key][1], pools[key]["vault"]]
93-
}
94-
}
95-
96-
const symbols = await api.multiCall({
97-
abi: abi.symbol,
98-
calls: poolBaseInfos.map((index) => ({
99-
target: index[1]
100-
})),
101-
})
102-
103-
const balances = await api.multiCall({
104-
abi: abi.balanceOf,
105-
calls: Object.values(vaults).map((index) => ({
106-
target: index[0],
107-
params: [index[1]]
108-
})),
109-
})
35+
const solvbtcListUrl = 'https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/main/solvbtc.json';
36+
async function getSolvBTCVAddresses(api) {
37+
let solvbtc = (await getConfig('solv-protocol/solvbtc', solvbtcListUrl));
11038

111-
let vaultbalances = {};
112-
for (let i = 0; i < Object.keys(vaults).length; i++) {
113-
vaultbalances[Object.keys(vaults)[i]] = balances[i];
114-
}
115-
for (let i = 0; i < poolTotalValues.length; i++) {
116-
const decimals = poolDecimalList[i];
117-
let balance = BigNumber(poolTotalValues[i]).div(BigNumber(10).pow(18 - decimals)).times(BigNumber(nav[i].nav_).div(BigNumber(10).pow(decimals))).toNumber();
118-
if (pools[i]['vault'] && poolBaseInfos[i][1] && vaultbalances[`${pools[i]['vault'].toLowerCase()}-${poolBaseInfos[i][1].toLowerCase()}`]) {
119-
balance = BigNumber(balance).minus(vaultbalances[`${pools[i]['vault'].toLowerCase()}-${poolBaseInfos[i][1].toLowerCase()}`]).toNumber();
120-
vaultbalances[`${pools[i]['vault'].toLowerCase()}-${poolBaseInfos[i][1].toLowerCase()}`] = undefined
121-
}
122-
if (balance > 0) {
123-
if (symbols[i] !== "SolvBTC") {
124-
api.add(poolBaseInfos[i][1], balance)
125-
}
126-
}
39+
const blacklisted = {}
40+
if (!solvbtc[api.chain] || !solvbtc[api.chain]["otherDeposit"]) {
41+
return blacklisted
42+
}
43+
let otherDeposit = solvbtc[api.chain]["otherDeposit"];
44+
for (const deposit of otherDeposit["depositAddress"]) {
45+
for (const tokenAddress of otherDeposit["tokens"]) {
46+
const key = `${tokenAddress}-${deposit}`.toLowerCase()
47+
blacklisted[key] = true
12748
}
12849
}
129-
return api.getBalances()
50+
return blacklisted
13051
}
13152

13253
async function otherDeposit(api, address) {
@@ -328,27 +249,17 @@ async function vaultBalance(api, graphData) {
328249
vaults[`${poolBaseInfos[key][1].toLowerCase()}-${poolLists[key]["vault"].toLowerCase()}`] = [poolBaseInfos[key][1], poolLists[key]["vault"]]
329250
}
330251
}
331-
332-
const symbols = await api.multiCall({
333-
abi: abi.symbol,
334-
calls: Object.values(vaults).map((index) => ({
335-
target: index[0]
336-
})),
252+
const tokens = Object.values(vaults).map(([token]) => token)
253+
254+
const symbols = await api.multiCall({ abi: abi.symbol, calls: tokens, })
255+
const blacklisted = await getSolvBTCVAddresses(api)
256+
const blacklistedTokens = tokens.filter((token, i) => symbols[i].toLowerCase().includes('solvbtc'))
257+
const tokensAndOwners = Object.values(vaults).filter(([token, owner]) => {
258+
const key = `${token}-${owner}`.toLowerCase()
259+
return !blacklisted[key] && !blacklistedTokens.includes(token)
337260
})
338-
339-
const balances = await api.multiCall({
340-
abi: abi.balanceOf,
341-
calls: Object.values(vaults).map((index) => ({
342-
target: index[0],
343-
params: [index[1]]
344-
})),
345-
})
346-
347-
for (const key in balances) {
348-
if (symbols[key] !== "SolvBTC") {
349-
api.add(Object.values(vaults)[key][0], balances[key])
350-
}
351-
}
261+
262+
return api.sumTokens({ tokensAndOwners, blacklistedTokens, })
352263
}
353264
}
354265

@@ -357,7 +268,7 @@ async function ceffuBalance(api, address, graphData) {
357268
return;
358269
}
359270
let ceffuData = address[api.chain]["ceffu"];
360-
271+
361272
let pools = [];
362273
for (const graph of graphData.pools) {
363274
if (graph['openFundShareSlot'] == ceffuData['slot']) {
@@ -479,40 +390,10 @@ async function getGraphData(timestamp, chain, api) {
479390
};
480391
}
481392

482-
function filterDepositAddress(network, address) {
483-
let depositAddresses = [];
484-
if (address[network]) {
485-
if (address[network]["gm"]) {
486-
for (let depositAddress of address[network]["gm"]["depositAddress"]) {
487-
depositAddresses.push(depositAddress.toLowerCase())
488-
}
489-
}
490-
if (address[network]["mux"]) {
491-
depositAddresses.push(address[network]["mux"]["account"].toLowerCase())
492-
}
493-
if (address[network]["klp"]) {
494-
for (let poolAddress of address[network]["klp"]["klpPool"]) {
495-
depositAddresses.push(poolAddress.toLowerCase())
496-
}
497-
}
498-
if (address[network]["iziswap"]) {
499-
for (let owner of address[network]["iziswap"]["owner"]) {
500-
depositAddresses.push(owner.toLowerCase())
501-
}
502-
}
503-
if (address[network]["lendle"]) {
504-
depositAddresses.push(address[network]["lendle"]["account"]["user"].toLowerCase())
505-
}
506-
}
507-
508-
return depositAddresses;
509-
}
510-
511393

512394
// node test.js projects/solv-protocol-funds
513395
['ethereum', 'bsc', 'polygon', 'arbitrum', 'mantle', 'merlin'].forEach(chain => {
514396
module.exports[chain] = {
515-
tvl,
516-
borrowed
397+
tvl
517398
}
518399
})

projects/solvbtc/index.js

Lines changed: 18 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const abi = require("./abi.json");
2+
const sdk = require('@defillama/sdk');
23
const { getConfig } = require("../helper/cache");
34
const { cachedGraphQuery } = require("../helper/cache");
45
const { sumTokens2, } = require("../helper/unwrapLPs");
6+
const { sumTokensExport, } = require('../helper/sumTokens');
57

68
// The Graph
79
const graphUrlList = {
@@ -14,30 +16,15 @@ const graphUrlList = {
1416

1517
const solvbtcListUrl = 'https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/main/solvbtc.json';
1618

19+
const bitcionOwners = [
20+
'bc1pjrxeuc9f3zqtx92s3mnf6202894jzufswur957l6s04rjns6dumsyh6u89',
21+
'bc1qdpwl80flfh3k6h6sumzwgws3ephkrmx307hk64'
22+
]
23+
1724
async function tvl(api) {
1825
let solvbtc = (await getConfig('solv-protocol/solvbtc', solvbtcListUrl));
1926

20-
await gm(api, solvbtc)
21-
await vaultBalance(api, solvbtc);
2227
await otherDeposit(api, solvbtc);
23-
24-
return api.getBalances();
25-
}
26-
27-
async function gm(api, solvbtc) {
28-
if (!solvbtc[api.chain] || !solvbtc[api.chain]["gm"]) {
29-
return;
30-
}
31-
let gm = solvbtc[api.chain]["gm"];
32-
33-
let tokens = []
34-
for (const pool of gm["depositAddress"]) {
35-
for (const address of gm["gmTokens"]) {
36-
tokens.push({ address, pool })
37-
}
38-
}
39-
40-
await sumTokens2({ api, tokensAndOwners: tokens.map(i => [i.address, i.pool]), permitFailure: true });
4128
}
4229

4330
async function otherDeposit(api, solvbtc) {
@@ -46,112 +33,25 @@ async function otherDeposit(api, solvbtc) {
4633
}
4734
let otherDeposit = solvbtc[api.chain]["otherDeposit"];
4835

49-
let tokens = []
36+
let tokensAndOwners = []
5037
for (const deposit of otherDeposit["depositAddress"]) {
5138
for (const tokenAddress of otherDeposit["tokens"]) {
52-
tokens.push({ tokenAddress, deposit })
39+
tokensAndOwners.push([tokenAddress, deposit])
5340
}
5441
}
5542

56-
await sumTokens2({ api, tokensAndOwners: tokens.map(i => [i.tokenAddress, i.deposit]), permitFailure: true });
43+
await sumTokens2({ api, tokensAndOwners, permitFailure: true });
5744
}
5845

59-
async function concrete(slots, api) {
60-
var slotsList = [];
61-
var only = {};
62-
for (var i = 0; i < slots.length; i++) {
63-
if (!only[slots[i].contractAddress]) {
64-
slotsList.push(slots[i]);
65-
only[slots[i].contractAddress] = true;
66-
}
67-
}
68-
69-
const concreteLists = await api.multiCall({
70-
calls: slotsList.map((index) => index.contractAddress),
71-
abi: abi.concrete,
72-
})
73-
74-
let concretes = {};
75-
for (var k = 0; k < concreteLists.length; k++) {
76-
concretes[slotsList[k].contractAddress] = concreteLists[k];
77-
}
78-
79-
return concretes;
80-
}
81-
82-
async function vaultBalance(api, solvbtc) {
83-
if (!solvbtc[api.chain] || !solvbtc[api.chain]["slot"]) {
84-
return;
85-
}
86-
let slot = solvbtc[api.chain]["slot"];
87-
88-
const graphData = await getGraphData(api.timestamp, api.chain, api, slot);
89-
if (graphData.pools.length > 0) {
90-
const poolLists = graphData.pools;
91-
92-
const poolConcretes = await concrete(poolLists, api);
93-
94-
const poolBaseInfos = await api.multiCall({
95-
abi: abi.slotBaseInfo,
96-
calls: poolLists.map((index) => ({
97-
target: poolConcretes[index.contractAddress],
98-
params: [index.openFundShareSlot]
99-
})),
100-
})
101-
102-
let vaults = {};
103-
for (const key in poolLists) {
104-
if (poolBaseInfos[key][1] && poolLists[key]["vault"]) {
105-
vaults[`${poolBaseInfos[key][1].toLowerCase()}-${poolLists[key]["vault"].toLowerCase()}`] = [poolBaseInfos[key][1], poolLists[key]["vault"]]
106-
}
46+
// node test.js projects/solvbtc
47+
['bitcoin', 'ethereum', 'bsc', 'polygon', 'arbitrum', 'mantle', 'merlin'].forEach(chain => {
48+
if (chain == 'bitcoin') {
49+
module.exports[chain] = {
50+
tvl: sumTokensExport({ owners: bitcionOwners }),
10751
}
108-
109-
const balances = await api.multiCall({
110-
abi: abi.balanceOf,
111-
calls: Object.values(vaults).map((index) => ({
112-
target: index[0],
113-
params: [index[1]]
114-
})),
115-
})
116-
117-
for (const key in balances) {
118-
api.add(Object.values(vaults)[key][0], balances[key])
52+
} else {
53+
module.exports[chain] = {
54+
tvl
11955
}
12056
}
121-
}
122-
123-
124-
async function getGraphData(timestamp, chain, api, slot) {
125-
126-
const slotDataQuery = `query PoolOrderInfos {
127-
poolOrderInfos(first: 1000 where:{fundraisingEndTime_gt:${timestamp}, openFundShareSlot_in: ${JSON.stringify(slot)}}) {
128-
marketContractAddress
129-
contractAddress
130-
navOracle
131-
poolId
132-
vault
133-
openFundShareSlot
134-
}
135-
}`;
136-
137-
let data;
138-
if (graphUrlList[chain]) {
139-
data = (await cachedGraphQuery(`solv-protocol/funds-graph-data/${chain}`, graphUrlList[chain], slotDataQuery, { api, }));
140-
}
141-
142-
let poolList = [];
143-
if (data != undefined && data.poolOrderInfos != undefined) {
144-
poolList = data.poolOrderInfos;
145-
}
146-
147-
return {
148-
pools: poolList
149-
};
150-
}
151-
152-
// node test.js projects/solvbtc
153-
['ethereum', 'bsc', 'polygon', 'arbitrum', 'mantle', 'merlin'].forEach(chain => {
154-
module.exports[chain] = {
155-
tvl
156-
}
15757
})

0 commit comments

Comments
 (0)