Skip to content

Commit ea9c54c

Browse files
author
Ricky
committed
feat: process decimal and symbol in tg alert
1 parent 11bc4c3 commit ea9c54c

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

index-v2.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ for (const topics of [ topics_for_all]) {
5252

5353
// console.log(log_option);)
5454
let tokenMap = {};
55-
let saved_token_address = [];
5655

5756
const log_subscription = web3.eth.subscribe('logs', log_option, (err,res) => {
5857
if (err) console.error(err);
@@ -69,13 +68,11 @@ for (const topics of [ topics_for_all]) {
6968
}
7069

7170
// console.log(decodedLog);
72-
// const alert_msg = handle_msg(log, decodedLog);
73-
// alert_tg(alert_msg);
7471

72+
73+
const token_address = log.address;
7574
try{
76-
const token_address = log.address;
77-
if (!(log.address in tokenMap)){
78-
saved_token_address.push(log.address);
75+
if (!(token_address in tokenMap)){
7976
const token_contract = new web3.eth.Contract(erc20abi, token_address);
8077
tokenMap[token_address] = {
8178
'decimals': await token_contract.methods.decimals().call(),
@@ -84,23 +81,29 @@ for (const topics of [ topics_for_all]) {
8481
}
8582
} catch (err) {logDebug('This is not an ERC20 transactions');}
8683

87-
for (const address in checksum_whaleAddress){
88-
const check_arr = [decodedLog['from'], decodedLog['to']]
89-
if (check_arr.includes(address)) {
90-
console.log(decodedLog)
84+
const tokenInfo = tokenMap[token_address];
85+
const alert_msg = handle_msg(log, decodedLog, tokenInfo);
86+
alert_tg(alert_msg);
87+
console.log(alert_msg)
88+
89+
90+
// for (const address in checksum_whaleAddress){
91+
// const check_arr = [decodedLog['from'], decodedLog['to']]
92+
// if (check_arr.includes(address)) {
93+
// console.log(decodedLog)
9194

92-
// TODO list
95+
// // TODO list
9396

94-
// get the value decimals (ERC-20)
95-
// map back the address to whale name
96-
// format the telegram message (remove space between lines, add etherscan link, )
97+
// // get the value decimals (ERC-20) (done)
98+
// // map back the address to whale name
99+
// // format the telegram message (remove space between lines, add etherscan link, )
97100

98-
// push the telegram message into a list
99-
// remove the message when alert message is sent, sleep 0.5s to protect tg api
100-
// run a thread to check if there is item in list or not
101+
// // push the telegram message into a list
102+
// // remove the message when alert message is sent, sleep 0.5s to protect tg api
103+
// // run a thread to check if there is item in list or not
101104

102-
}
103-
}
105+
// }
106+
// }
104107

105108
} catch (err) {console.log(err)}
106109
})

tools/tg-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ dotenv.config()
55

66
// Telegram Related Functions
77

8-
export const handle_msg = function (log, decodedLog) {
8+
export const handle_msg = function (log, decodedLog, tokenInfo) {
99
const msg = `
1010
\ntime: ${Date().toLocaleString()}
1111
\nfrom: ${decodedLog.from}
1212
\nto: ${decodedLog.to}
13-
\nvalue: ${decodedLog.value}`
13+
\nvalue: ${decodedLog.value * 10 ** (-tokenInfo.decimals)} ${tokenInfo.symbol}`
1414

1515
return msg
1616
}

0 commit comments

Comments
 (0)