-
Notifications
You must be signed in to change notification settings - Fork 1
/
cakedefi.ts
59 lines (55 loc) · 1.59 KB
/
cakedefi.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Plugin, { TRANSACTION_TYPE } from './common/plugin';
export default class CakeDefi extends Plugin {
public getNames(): string[] {
return ['cakedefi'];
}
// Date,Operation,Amount,Coin/Asset,FIAT value,FIAT currency,Transaction ID,Withdrawal address,Reference,Related reference ID
convertRow(line: string[]): Promise<string[] | null> {
const type = this._getType(line[1]);
if (type === TRANSACTION_TYPE.UNKNOWN) {
return Promise.resolve(null);
}
const date = new Date(Date.parse(line[0]));
const coin = line[3];
const amount = parseFloat(line[2]);
const total = parseFloat(line[4]);
const row = this.toRow(
date,
type,
'Cake Defi',
'DeFiChain',
coin,
amount,
0,
total
);
return Promise.resolve(row);
}
private _getType(input: string): TRANSACTION_TYPE {
if (input.includes('Liquidity mining reward')) {
return TRANSACTION_TYPE.LIQUIDITY_MINING;
}
if (input.includes('Lending reward')) {
return TRANSACTION_TYPE.LENDING;
}
if (
input.includes('Staking reward') ||
input.includes('Freezer staking bonus')
) {
return TRANSACTION_TYPE.STAKING;
}
if (input.includes('Signup bonus')) {
return TRANSACTION_TYPE.GIFT;
}
if (input.includes('Deposit')) {
return TRANSACTION_TYPE.DEPOSIT;
}
if (input.includes('Withdrawal')) {
return TRANSACTION_TYPE.WITHDRAW;
}
if (input.includes('Swapped in') || input.includes('Swapped out')) {
return TRANSACTION_TYPE.TRADING;
}
return TRANSACTION_TYPE.UNKNOWN;
}
}