-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver11.js
49 lines (43 loc) · 1.72 KB
/
server11.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const moralisServices = require('./utils/moralisUtils');
const debankServices = require('./utils/debankUtils');
const calcCostBasis = require('./utils/algorithm');
const constants = require('./utils/constant');
const { writeToFile } = require('./utils');
WALLET_ADDRESS = '0x704111eDBee29D79a92c4F21e70A5396AEDCc44a';
moralisServices.startMoralisServer(async (started, err) => {
if (started) {
console.log('moralis server started successfully');
const walletCostBasis = await getWalletCostBasis();
writeToFile('final', walletCostBasis);
console.log(walletCostBasis);
} else {
console.log('moralis starting failed', err)
}
})
async function getWalletCostBasis() {
let result = [];
const protocolList = await debankServices.getProtocolListByDebank();
const chainList = (await debankServices.getWalletBalanceByDebank(WALLET_ADDRESS)).chain_list;
for (let i = 0; i < chainList.length; i++ ) {
const chain = chainList[i];
if (!constants.chainIdTable[chain.id]) continue;
if (chain.usd_value <= 0) continue;
const tokenListOfChain = await debankServices.getWalletTokenListByDebank(WALLET_ADDRESS, chain.id, true);
for (let j = 0; j < tokenListOfChain.length; j++) {
const token = tokenListOfChain[j];
console.log('chain = ', chain.id, 'token = ', token.id);
let tokenId = token.id;
if (tokenId.substr(0, 2) !== '0x') {
tokenId = constants.chainCoins[constants.chainIdTable[chain.id]].address;
}
const crrCostBasis = await calcCostBasis({
wallet: WALLET_ADDRESS,
token: tokenId,
// blockheight: 20138207,
chain: constants.chainIdTable[chain.id],
});
result = result.concat(crrCostBasis);
}
}
return result;
}