Skip to content

Commit

Permalink
Added new Cake operations
Browse files Browse the repository at this point in the history
  • Loading branch information
geldmacher committed Jan 27, 2022
1 parent fa6942c commit 3d84028
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ npm install -g cake-to-cointracking-converter

1. Get your [Cake transactions export](https://app.cakedefi.com/transactions)(CSV) for all coins and generate a CoinTracking import via CLI.

2. Example CLI command (More [options](#options) below):
```shell
2. Example CLI command (More [options](#options) below):
```shell
cake2ct --cake-csv "path\to\cake-export-file.csv" --ct-csv "path\to\cointracking-import-file.csv" --language "DE"
```

Expand All @@ -59,23 +59,29 @@ cake2ct --cake-csv "path\to\cake-export-file.csv" --ct-csv "path\to\cointracking

## Supported Cake operations

- Deposit
- Deposit (incl. DEX deposit)
- Withdrawal
- Withdrew for swap
- Withdrawal fee
- Paid swap fee
- Referral reward
- Referral signup bonus
- Entry staking wallet: Referral signup bonus
- Promotion bonus
- Lending reward
- Lending DFI Bonus
- Entry staking wallet: Lending DFI Bonus
- Confectionery Lending DFI Bonus
- Staking reward
- 5 years freezer reward
- 10 years freezer reward
- Freezer promotion bonus
- Entry staking wallet: Freezer promotion bonus
- Freezer staking bonus
- Freezer liquidity mining bonus
- Unstake fee
- Bonus/Airdrop
- Entry staking wallet: Bonus/Airdrop
- Add liquidity (d)X(X...)-YYY(Y)
- Remove liquidity (d)X(X...)-YYY(Y)
- Added liquidity
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cake-to-cointracking-converter",
"version": "4.6.0",
"version": "4.7.0",
"description": "CLI script to translate Cake export data to a valid CoinTracking import",
"main": "./processCsv.js",
"scripts": {
Expand Down
35 changes: 17 additions & 18 deletions services/augmentDexSwapRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Decimal.set({

/**
* Augment DEX Swap records
*
* @param {*} dexSwapRecords
*
* @param {*} dexSwapRecords
*/
const augmentDexSwapRecords = (dexSwapRecords) => {

Expand All @@ -25,7 +25,7 @@ const augmentDexSwapRecords = (dexSwapRecords) => {
});
}
});

const augmentedDexSwapRecords = [];
sortedDexSwapRecords.forEach(sortedDexSwapRecord => {
const augmentedDexSwapRecord = {
Expand All @@ -40,21 +40,20 @@ const augmentDexSwapRecords = (dexSwapRecords) => {
augmentedDexSwapRecord['Buy Coin/Asset'] = sortedDexSwapRecordRef['Coin/Asset'];
augmentedDexSwapRecord['Buy FIAT value'] = sortedDexSwapRecordRef['FIAT value'];
break;
case 'Unknown':
if(sortedDexSwapRecordRef['Transaction ID']){
augmentedDexSwapRecord['Sell Amount'] = sortedDexSwapRecordRef['Amount'];
augmentedDexSwapRecord['Sell Coin/Asset'] = sortedDexSwapRecordRef['Coin/Asset'];
augmentedDexSwapRecord['Sell FIAT value'] = sortedDexSwapRecordRef['FIAT value'];
} else {
augmentedDexSwapRecords.push({
'Date': sortedDexSwapRecordRef['Date'],
'Operation': 'Swap trade fee (DeFiChain DEX)',
'Reference': sortedDexSwapRecordRef['Reference'],
'Sell Amount': sortedDexSwapRecordRef['Amount'],
'Sell Coin/Asset': sortedDexSwapRecordRef['Coin/Asset'],
'Sell FIAT value': sortedDexSwapRecordRef['FIAT value']
});
}
case 'Withdrew for swap':
augmentedDexSwapRecord['Sell Amount'] = sortedDexSwapRecordRef['Amount'];
augmentedDexSwapRecord['Sell Coin/Asset'] = sortedDexSwapRecordRef['Coin/Asset'];
augmentedDexSwapRecord['Sell FIAT value'] = sortedDexSwapRecordRef['FIAT value'];
break;
case 'Paid swap fee':
augmentedDexSwapRecords.push({
'Date': sortedDexSwapRecordRef['Date'],
'Operation': 'Swap trade fee (DeFiChain DEX)',
'Reference': sortedDexSwapRecordRef['Reference'],
'Sell Amount': sortedDexSwapRecordRef['Amount'],
'Sell Coin/Asset': sortedDexSwapRecordRef['Coin/Asset'],
'Sell FIAT value': sortedDexSwapRecordRef['FIAT value']
});
break;
}
});
Expand Down
35 changes: 20 additions & 15 deletions services/generateCtRecordsFromCakeDataRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Decimal.set({

/**
* Translate Cake records to CoinTracking records
*
* @param {*} row
* @param {*} translatedCtTypes
* @param {*} useCtFiatValuation
* @param {*} noAutoStakeRewards
*
* @param {*} row
* @param {*} translatedCtTypes
* @param {*} useCtFiatValuation
* @param {*} noAutoStakeRewards
*/
const generateCtRecordsFromCakeDataRow = (row, translatedCtTypes, useCtFiatValuation, noAutoStakeRewards) => {

Expand Down Expand Up @@ -94,10 +94,10 @@ const generateCtRecordsFromCakeDataRow = (row, translatedCtTypes, useCtFiatValua
data['Sell Currency'] = row['Sell Coin/Asset'];
data['Sell Amount'] = row['Sell Amount'].replace('-','');
data['Sell Value in your Account Currency'] = useCtFiatValuation ? row['Sell FIAT value'].replace('-','') : '';
break;
break;
case 'Deposit':
// Deposit operations with a reference ID are handled via DeFiChain DEX
// Swap withdrawel and paid swap fee are part of this operation
// Swap withdrawel and paid swap fee are part of this operation. See "Withdrew for swap" and "Paid swap fee".
if(row['Related reference ID'] && row['Related reference ID'].length > 0){
dexSwapRecords.push(row);
} else {
Expand All @@ -108,7 +108,7 @@ const generateCtRecordsFromCakeDataRow = (row, translatedCtTypes, useCtFiatValua
data['Buy Value in your Account Currency'] = useCtFiatValuation ? '' : row['FIAT value'].replace('-','');
}
break;
case 'Withdrawal':
case 'Withdrawal':
data['Type'] = translatedCtTypes.withdrawal;
data['Trade-Group'] = 'Withdrawal';
data['Sell Currency'] = row['Coin/Asset'];
Expand All @@ -132,6 +132,7 @@ const generateCtRecordsFromCakeDataRow = (row, translatedCtTypes, useCtFiatValua
break;
case 'Lapis DFI Bonus':
case 'Lending DFI Bonus':
case 'Entry staking wallet: Lending DFI Bonus':
case 'Confectionery Lending DFI Bonus':
data['Type'] = translatedCtTypes.interest_income;
data['Trade-Group'] = 'Lending';
Expand All @@ -144,20 +145,23 @@ const generateCtRecordsFromCakeDataRow = (row, translatedCtTypes, useCtFiatValua
case '10 years freezer reward':
case 'Freezer staking bonus':
case 'Freezer promotion bonus':
case 'Entry staking wallet: Freezer promotion bonus':
data['Type'] = translatedCtTypes.staking;
data['Trade-Group'] = 'Staking';
data['Buy Currency'] = row['Coin/Asset'];
data['Buy Amount'] = row['Amount'].replace('-','');
data['Buy Value in your Account Currency'] = useCtFiatValuation ? '' : row['FIAT value'].replace('-','');
break;
case 'Unstake fee':
case 'Exit staking wallet fee':
data['Type'] = translatedCtTypes.other_fee;
data['Trade-Group'] = 'Staking';
data['Sell Currency'] = row['Coin/Asset'];
data['Sell Amount'] = row['Amount'].replace('-','');
data['Sell Value in your Account Currency'] = useCtFiatValuation ? '' : row['FIAT value'].replace('-','');
break;
case 'Bonus/Airdrop':
case 'Entry staking wallet: Bonus/Airdrop':
data['Type'] = translatedCtTypes.airdrop;
data['Trade-Group'] = 'Bonus/Airdrop';
data['Buy Currency'] = row['Coin/Asset'];
Expand All @@ -168,19 +172,20 @@ const generateCtRecordsFromCakeDataRow = (row, translatedCtTypes, useCtFiatValua
case 'Referral signup bonus':
case 'Signup bonus':
case 'Promotion bonus':
case 'Entry staking wallet: Referral signup bonus':
data['Type'] = translatedCtTypes.income;
data['Trade-Group'] = 'Referral';
data['Buy Currency'] = row['Coin/Asset'];
data['Buy Amount'] = row['Amount'].replace('-','');
data['Buy Value in your Account Currency'] = useCtFiatValuation ? '' : row['FIAT value'].replace('-','');
break;
break;
default:
let notHandledOperation = row['Operation'];
// Preserve LM related rows which are related to each other and transfer their data to another handling mechanism
if(
row['Operation'] === 'Added liquidity'
|| row['Operation'] === 'Removed liquidity'
|| /^Add liquidity (?:d)?[A-Z]+-[A-Z]{3,4}$/.test(row['Operation'])
row['Operation'] === 'Added liquidity'
|| row['Operation'] === 'Removed liquidity'
|| /^Add liquidity (?:d)?[A-Z]+-[A-Z]{3,4}$/.test(row['Operation'])
|| /^Remove liquidity (?:d)?[A-Z]+-[A-Z]{3,4}$/.test(row['Operation'])
){
lmRecords.push(row);
Expand All @@ -193,8 +198,8 @@ const generateCtRecordsFromCakeDataRow = (row, translatedCtTypes, useCtFiatValua
}
// Preserve DEX swap related rows which are related to each other and transfer their data to another handling mechanism
// Atm DEX swap operations consists out of 3 seperate operations
// One is marked as a normal Deposit, the other 2 are "Unknown" (Withdrawel + Fee)
if(row['Operation'] === 'Unknown' && row['Related reference ID'] && row['Related reference ID'].length > 0){
// One is marked as a normal Deposit, the other 2 are "Withdrew for swap" and "Paid swap fee"
if (row['Operation'] === 'Withdrew for swap' || row['Operation'] === 'Paid swap fee') {
dexSwapRecords.push(row);
notHandledOperation = '';
}
Expand Down Expand Up @@ -227,7 +232,7 @@ const generateCtRecordsFromCakeDataRow = (row, translatedCtTypes, useCtFiatValua
row['_error'] = error;
skippedRecords.push(row);
}

return [records, skippedRecords, lmRecords, swapRecords, discountRecords, dexSwapRecords];
}

Expand Down

0 comments on commit 3d84028

Please sign in to comment.