Skip to content

Commit bc4fe6a

Browse files
committed
add ether rating
1 parent 9314c67 commit bc4fe6a

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

utils/getRating.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ const getTotalGasSpent = (gasSpent) => {
9696
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
9797
);
9898
}
99-
100-
const getEtherRating = (total, max) => {
99+
const getAssetRating = (total, max) => {
101100
const v = total * 0.6 + max * 0.4;
102101
return getNumberByRange(
103102
v,
@@ -106,6 +105,19 @@ const getEtherRating = (total, max) => {
106105
)
107106
}
108107

108+
const getEtherRating = (eth) => {
109+
const limit = 5;
110+
const highvalue = 30;
111+
if (eth > limit)
112+
return highvalue;
113+
return Math.floor(highvalue * eth / limit);
114+
/*return getNumberByRange(
115+
eth,
116+
[0, 0.00001, 0.1, 0.2, 0.5, 1, 2, 3, 4, 5],
117+
[0, 0, 1, 2, 5, 8, 12, 15, 20, 25, 30]
118+
)*/
119+
}
120+
109121
const getBscRating = (bsc) => {
110122
return getNumberByRange(
111123
bsc,
@@ -188,7 +200,7 @@ const getAaveRating = (aaveTotal) => {
188200

189201

190202
module.exports = { getTotalBlocksNumber, getTotalEth, getGweiRating,
191-
getAgeRating, getNonceRating, getTotalGasSpent,
203+
getAgeRating, getNonceRating, getTotalGasSpent, getAssetRating,
192204
getEtherRating, getBscRating, getUniswapRating, getSushiRating,
193205
getZoraRating, getCompoundRating, getYFIRating, getPickleRating,
194206
getWBTCRating, getCoverRating, getAaveRating}

utils/ratings.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { currentUnixTimestamp } = require("./time");
33
const { getFullDetail } = require('./zerion');
44
const { getDefiInfo } = require('./defiSDK');
55
const { getTotalBlocksNumber, getTotalEth, getGweiRating,
6-
getAgeRating, getNonceRating, getTotalGasSpent,
6+
getAgeRating, getNonceRating, getTotalGasSpent, getAssetRating,
77
getEtherRating, getBscRating, getUniswapRating, getSushiRating,
88
getZoraRating, getCompoundRating, getYFIRating,
99
getPickleRating, getWBTCRating, getCoverRating, getAaveRating } = require('./getRating');
@@ -77,8 +77,9 @@ const getAccountMainInfo = (account) => {
7777
maxNonce,
7878
Number(totalGasSpent),
7979
info.portfolio.total_value,
80-
info.portfolio.bsc_assets_value,
8180
info.max,
81+
info.portfolio.bsc_assets_value,
82+
info.eth,
8283
info.uniswap,
8384
info.sushi,
8485
info.zora,
@@ -107,6 +108,7 @@ const calculateRating = (
107108
totalValue,
108109
maxValue,
109110
bscValue,
111+
ethValue,
110112
uniswap,
111113
sushi,
112114
zora,
@@ -122,7 +124,8 @@ const calculateRating = (
122124
rating += getAgeRating(age); // 40
123125
rating += getNonceRating(maxNonce); // 40
124126
rating += getTotalGasSpent(totalGasSpent); // 50
125-
rating += getEtherRating(totalValue, maxValue); // 50
127+
rating += getAssetRating(totalValue, maxValue); // 50
128+
rating += getEtherRating(ethValue); // 30
126129
rating += getBscRating(bscValue); // 20
127130
rating += getUniswapRating(uniswap.sent + uniswap.received + uniswap.trading); //30
128131
rating += getSushiRating(sushi.sent + sushi.received + sushi.trading) // 30

utils/zerion.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ function get(socketNamespace, requestBody) {
3838
});
3939
}
4040

41-
const getAssets = (address) => {
42-
console.log("getAssets", address);
41+
const getTokenBalance = (tokenType, address) => {
42+
//console.log("getTokenBalance", address);
4343
const assetsSocket = {
4444
namespace: 'address',
4545
socket: io(`${BASE_URL}address`, {
@@ -65,12 +65,13 @@ const getAssets = (address) => {
6565
let total = 0;
6666
for(key in assets) {
6767
const item = assets[key];
68-
const {asset: { name, price, decimals }, quantity} = item;
68+
const {asset: { name, price, symbol, decimals }, quantity} = item;
69+
if (tokenType != symbol)
70+
continue;
6971
const q = quantity / Math.pow(10, decimals);
70-
if (price)
71-
total += price.value * q;
72+
return q;
7273
}
73-
return total;
74+
return 0;
7475
});
7576
}
7677

@@ -824,7 +825,8 @@ const getFullDetail = (address) => {
824825
getPickleTransactions(address),
825826
getWBTCTransactions(address),
826827
getCoverTransactions(address),
827-
getAaveTransactions(address)
828+
getAaveTransactions(address),
829+
getTokenBalance('ETH', address),
828830
]).then(res => {
829831
return {
830832
transactions: res[0],
@@ -838,19 +840,19 @@ const getFullDetail = (address) => {
838840
pickle: res[8],
839841
wbtc: res[9],
840842
cover: res[10],
841-
aave: res[11]
843+
aave: res[11],
844+
eth: res[12]
842845
}
843846
})
844847
}
845848

846849
//0x70e36f6bf80a52b3b46b3af8e106cc0ed743e8e4
847850
//0x638aF69053892CDD7Ad295fC2482d1a11Fe5a9B7
848851
//0xd4004f07d7b746103f2d9b4e5b5a540864526bec
849-
// getZoraTransactions("0x7A6d4a30f800c63965c68590e99C5b661948Aaa3").then(res => {
850-
// console.log(res);
851-
// });
852+
// getFullDetail("0x7a6d4a30f800c63965c68590e99c5b661948aaa3").then(res => {
853+
// console.log(res);
854+
// });
852855
module.exports = {
853-
getAssets,
854856
getLockedAssets,
855857
getMaxInHistory,
856858
getUniswapTransactions,

0 commit comments

Comments
 (0)