-
Notifications
You must be signed in to change notification settings - Fork 1
/
etherscan.ts
39 lines (36 loc) · 1.3 KB
/
etherscan.ts
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
import Plugin, { TRANSACTION_TYPE } from './common/plugin';
export default class Etherscan extends Plugin {
getNames(): string[] {
return ['etherscan', 'polygonscan'];
}
// "Txhash","UnixTimestamp","DateTime","From","To","Value","ContractAddress","TokenName","TokenSymbol"
// "Txhash","UnixTimestamp","DateTime","From","To","TokenValue","USDValueDayOfTx","ContractAddress","TokenName","TokenSymbol"
// "Txhash","Blockno","UnixTimestamp","DateTime","From","To","TokenValue","USDValueDayOfTx","ContractAddress","TokenName","TokenSymbol"
async convertRow(line: string[]): Promise<string[] | null> {
const csvToken = line[10] || line[9] || line[8];
const csvTimestamp = line[2];
const csvAmount = line[6];
if (!csvToken || !csvTimestamp) {
console.warn(
`Token (${csvToken}) or timestamp (${csvTimestamp}) not found!)`
);
return null;
}
const timestamp = parseInt(csvTimestamp);
const date = new Date(timestamp * 1000);
const price = await this._api.getPrice(csvToken, date);
if (!price || price.price <= 0) {
return null;
}
const amount = parseFloat(csvAmount);
return this.toRow(
date,
TRANSACTION_TYPE.MINING,
'Etherscan',
price.coin.name,
price.coin.symbol,
amount,
price.price
);
}
}