Skip to content

Commit c334001

Browse files
authored
Merge pull request #4 from zoracles/feat/new.rating.implement
Feat/new.rating.implement
2 parents e930328 + 32d91d7 commit c334001

File tree

5 files changed

+59
-39
lines changed

5 files changed

+59
-39
lines changed

sample.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
INFURA_URL=""
22
ETHERSCAN_KEY=""
3+
ZERION_KEY=""

utils/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ const Web3 = require("web3");
44
module.exports = {
55
web3: new Web3(process.env.INFURA_URL),
66
etherscanKey: process.env.ETHERSCAN_KEY,
7+
zerionKey: process.env.ZERION_KEY,
78
};

utils/getRating.js

Lines changed: 17 additions & 5 deletions
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,
@@ -133,8 +145,8 @@ const getSushiRating = (sushiTotal) => {
133145
const getZoraRating = (zoraTotal) => {
134146
return getNumberByRange(
135147
zoraTotal,
136-
[0, 1, 5, 10, 20, 30, 40, 50, 100, 200, 500, 1000],
137-
[0, 1, 2, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
148+
[0, 1, 10, 50, 100, 200, 300, 500, 700, 1000, 1500, 2000, 3000, 4000, 6000, 8000, 10000],
149+
[0, 1, 2, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100]
138150
)
139151
}
140152

@@ -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

Lines changed: 7 additions & 4 deletions
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,11 +124,12 @@ 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
129-
rating += getZoraRating(zora.sent + zora.received + zora.trading) // 50
132+
rating += getZoraRating(zora.sent + zora.received + zora.trading) // 100
130133
rating += getCompoundRating(comp.sent + comp.received + comp.trading) // 15
131134
rating += getYFIRating(yfi.sent + yfi.received + yfi.trading) // 60
132135
rating += getPickleRating(pickle.sent + pickle.received + pickle.trading) // 50

utils/zerion.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const io = require('socket.io-client');
22
const { default: BigNumber } = require("bignumber.js");
3-
const { zeronKey } = require("./config");
3+
const { zerionKey } = require("./config");
44
const FALLBACK_URL = 'wss://api-v4.zerion.io/';
55
const BASE_URL = FALLBACK_URL;
66

@@ -38,16 +38,16 @@ 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`, {
4646
transports: ['websocket'],
4747
timeout: 60000,
4848
query: {
4949
api_token:
50-
zeronKey ||
50+
zerionKey ||
5151
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
5252
},
5353
}),
@@ -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

@@ -83,7 +84,7 @@ const getLockedAssets = (address) => {
8384
timeout: 60000,
8485
query: {
8586
api_token:
86-
zeronKey ||
87+
zerionKey ||
8788
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
8889
},
8990
}),
@@ -115,7 +116,7 @@ const getMaxInHistory = (address) => {
115116
timeout: 60000,
116117
query: {
117118
api_token:
118-
zeronKey ||
119+
zerionKey ||
119120
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
120121
},
121122
}),
@@ -150,7 +151,7 @@ const getPortfolio = (address) => {
150151
timeout: 60000,
151152
query: {
152153
api_token:
153-
zeronKey ||
154+
zerionKey ||
154155
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
155156
},
156157
}),
@@ -177,7 +178,7 @@ const getTransactions = (address) => {
177178
timeout: 60000,
178179
query: {
179180
api_token:
180-
zeronKey ||
181+
zerionKey ||
181182
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
182183
},
183184
}),
@@ -207,7 +208,7 @@ const getUniswapTransactions = (address) => {
207208
timeout: 60000,
208209
query: {
209210
api_token:
210-
zeronKey ||
211+
zerionKey ||
211212
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
212213
},
213214
}),
@@ -275,7 +276,7 @@ const getSushiTransactions = (address) => {
275276
timeout: 60000,
276277
query: {
277278
api_token:
278-
zeronKey ||
279+
zerionKey ||
279280
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
280281
},
281282
}),
@@ -344,7 +345,7 @@ const getZoraTransactions = (address) => {
344345
timeout: 60000,
345346
query: {
346347
api_token:
347-
zeronKey ||
348+
zerionKey ||
348349
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
349350
},
350351
}),
@@ -412,7 +413,7 @@ const getCompoundTransactions = (address) => {
412413
timeout: 60000,
413414
query: {
414415
api_token:
415-
zeronKey ||
416+
zerionKey ||
416417
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
417418
},
418419
}),
@@ -480,7 +481,7 @@ const getYFITransactions = (address) => {
480481
timeout: 60000,
481482
query: {
482483
api_token:
483-
zeronKey ||
484+
zerionKey ||
484485
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
485486
},
486487
}),
@@ -549,7 +550,7 @@ const getPickleTransactions = (address) => {
549550
timeout: 60000,
550551
query: {
551552
api_token:
552-
zeronKey ||
553+
zerionKey ||
553554
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
554555
},
555556
}),
@@ -617,7 +618,7 @@ const getWBTCTransactions = (address) => {
617618
timeout: 60000,
618619
query: {
619620
api_token:
620-
zeronKey ||
621+
zerionKey ||
621622
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
622623
},
623624
}),
@@ -685,7 +686,7 @@ const getCoverTransactions = (address) => {
685686
timeout: 60000,
686687
query: {
687688
api_token:
688-
zeronKey ||
689+
zerionKey ||
689690
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
690691
},
691692
}),
@@ -745,15 +746,16 @@ const getCoverTransactions = (address) => {
745746

746747
const getAaveTransactions = (address) => {
747748
//console.log("getAaveTransactions", address);
748-
//Cover 0x80fB784B7eD66730e8b1DBd9820aFD29931aab03 Aave: LEND Token
749+
//0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9
750+
//Aave 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9 Aave: Lending Pool V2
749751
const assetsSocket = {
750752
namespace: 'address',
751753
socket: io(`${BASE_URL}address`, {
752754
transports: ['websocket'],
753755
timeout: 60000,
754756
query: {
755757
api_token:
756-
zeronKey ||
758+
zerionKey ||
757759
'Demo.ukEVQp6L5vfgxcz4sBke7XvS873GMYHy',
758760
},
759761
}),
@@ -765,7 +767,7 @@ const getAaveTransactions = (address) => {
765767
currency: 'usd',
766768
transactions_limit: 10000,
767769
transactions_offset: 0,
768-
transactions_search_query: '0x80fB784B7eD66730e8b1DBd9820aFD29931aab03'
770+
transactions_search_query: '0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9'
769771
},
770772
}).then(response => {
771773
const {payload} = response;
@@ -782,7 +784,7 @@ const getAaveTransactions = (address) => {
782784
return;
783785
changes.forEach(ast => {
784786
const {asset: {symbol, decimals}, value} = ast;
785-
if (symbol == 'LEND') {
787+
if (symbol == 'aSNX') {
786788
const token_value = value / Math.pow(10, decimals);
787789
switch(type) {
788790
case 'trade':
@@ -823,7 +825,8 @@ const getFullDetail = (address) => {
823825
getPickleTransactions(address),
824826
getWBTCTransactions(address),
825827
getCoverTransactions(address),
826-
getAaveTransactions(address)
828+
getAaveTransactions(address),
829+
getTokenBalance('ETH', address),
827830
]).then(res => {
828831
return {
829832
transactions: res[0],
@@ -837,19 +840,19 @@ const getFullDetail = (address) => {
837840
pickle: res[8],
838841
wbtc: res[9],
839842
cover: res[10],
840-
aave: res[11]
843+
aave: res[11],
844+
eth: res[12]
841845
}
842846
})
843847
}
844848

845849
//0x70e36f6bf80a52b3b46b3af8e106cc0ed743e8e4
846850
//0x638aF69053892CDD7Ad295fC2482d1a11Fe5a9B7
847851
//0xd4004f07d7b746103f2d9b4e5b5a540864526bec
848-
/*getFullDetail("0xf146E516258D277f493366Bd216D9B3c05e0c61C").then(res => {
849-
console.log(res);
850-
});*/
852+
getTransactions("0x7a6d4a30f800c63965c68590e99c5b661948aaa3").then(res => {
853+
console.log(res);
854+
});
851855
module.exports = {
852-
getAssets,
853856
getLockedAssets,
854857
getMaxInHistory,
855858
getUniswapTransactions,

0 commit comments

Comments
 (0)