Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/extended exports #36

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
de7e6b4
Add inverstor transaction list logic
AStox Dec 14, 2021
cc6febe
add UI
AStox Dec 14, 2021
7390a5f
Linting fixes
AStox Dec 14, 2021
7b174f8
Change wallet to address and sort subgraph query
AStox Dec 14, 2021
5ddec89
Update to use button components
AStox Dec 15, 2021
90e42e2
Add new columns
AStox Jan 25, 2022
256e468
set up issuer tax report export
AStox Sep 7, 2023
1775385
feat: fix interest accrued calculation, add tx fee sum
hieronx Jan 25, 2022
3b6a07d
feat: get year start and year end token prices
hieronx Jan 25, 2022
7a204b6
fix: linter warnings
hieronx Jan 25, 2022
cd86c29
feat: update tax report page
hieronx Jan 25, 2022
0ae5489
feat: convert token amounts into currency amounts
hieronx Jan 25, 2022
e08042b
fix: lint warning
hieronx Jan 26, 2022
7d39636
fix: lint
hieronx Jan 26, 2022
e3691eb
feat: add transfers to export
hieronx Jan 29, 2022
47659a8
feat: fix transfer order
hieronx Jan 29, 2022
609d0aa
feat: convert token amount to currency amounts for transfers
hieronx Jan 29, 2022
19845bb
feat: add token prices
hieronx Jan 29, 2022
8a4b327
feat: attempt to add transfers to cap gain calc
hieronx Jan 29, 2022
6cc5134
feat: add sorting
hieronx Jan 30, 2022
f1f3744
feat: add tx cost to investor transactions
hieronx Jan 31, 2022
f51c645
feat: add tx counts, balances on first/last day
hieronx Feb 1, 2022
f90b4f0
fix: lint
hieronx Feb 1, 2022
e095d35
fix symbol error
AStox Feb 1, 2022
36fef12
Add tokenAmount and currencyBalance columns to investor Txs
AStox Apr 6, 2022
268a8a6
Add token amounts to first and last days. Add 6 decimal sigfigs to ba…
AStox Apr 8, 2022
3719780
Make date range more dynamic
AStox Apr 8, 2022
ac32e45
Fix linter
hieronx May 2, 2022
21787f5
remove unrelated changes
AStox Sep 7, 2023
89d4280
update InvestorTransaction exports
AStox Jan 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions tinlake-ui/containers/PoolManagement/queries/InvestorTransactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import BN from 'bn.js'
import { csvName } from '.'
import { downloadCSV } from '../../../utils/export'
import { PoolData } from '../../../utils/usePool'
import { calculateCostInUsd, getAllTransactions, getAllTransfers } from './util'

const tokenSymbolIsJunior = (symbol: string) => symbol.slice(symbol.length - 3) === 'TIN'

export async function investorTransactions({ poolId }: { poolId: string; poolData: PoolData }) {
const transactions = await getAllTransactions(poolId)
console.log('1')
const transfers = await getAllTransfers(poolId)
console.log('2')

const headers: { [key: string]: string } = {
timestamp: 'Date',
pool: 'Pool',
owner: 'Account',
type: 'Transaction Type',
token: 'Token',
currencyAmount: 'Currency Amount',
tokenAmount: 'Token Amount',
currencyBalance: 'Currency Balance',
newBalance: 'Token Balance',
tokenPrice: 'Token Price',
transaction: 'Transaction Hash',
gasPrice: 'Gas Price',
gasUsed: 'Gas Used',
transactionCost: 'Transaction Cost (USD)',
}

const date = (timestamp: string) => new Date(parseInt(timestamp, 10) * 1000)
const formatDate = (timestamp: string) =>
`${date(timestamp).toISOString().substr(0, 10)} ${date(timestamp).toUTCString().substr(17)}`

const rows: string[][] = [
[...Object.keys(headers).map((key: string) => headers[key])],
...transactions.map((el: any) => [
el.timestamp ? formatDate(el.timestamp) : '-',
el.pool ? el.pool.shortName : '-',
el.owner ? el.owner.id : '-',
el.type,
el.symbol,
el.currencyAmount / 10 ** 18,
el.currencyAmount / 10 ** 18 / (el.tokenPrice / 10 ** 27),
(el.newBalance / 10 ** 18) * (el.tokenPrice / 10 ** 27),
el.newBalance / 10 ** 18,
el.tokenPrice / 10 ** 27,
el.transaction,
el.gasPrice / 10 ** 9,
el.gasUsed,
el.type === 'INVEST_EXECUTION' || el.type === 'REDEEM_EXECUTION'
? 0
: calculateCostInUsd(el.gasPrice, el.gasUsed, el.timestamp),
]),
...transfers.map((transfer: any) => [
formatDate(transfer.timestamp),
transfer.pool ? transfer.pool.shortName : '-',
transfer.to ? transfer.to : '-',
'TRANSFER_IN',
transfer.token ? transfer.token.symbol : '-',
new BN(transfer.amount)
.mul(
new BN(
tokenSymbolIsJunior(transfer.token.symbol) ? transfer.pool.juniorTokenPrice : transfer.pool.seniorTokenPrice
)
)
.div(new BN(10).pow(new BN(27 + 18)))
.toNumber(),
'-',
'-',
'-',
new BN(
tokenSymbolIsJunior(transfer.token.symbol) ? transfer.pool.juniorTokenPrice : transfer.pool.seniorTokenPrice
)
.div(new BN(10).pow(new BN(27 - 8)))
.toNumber() /
10 ** 8,
transfer.transaction,
transfer.gasPrice / 10 ** 9,
transfer.gasUsed,
calculateCostInUsd(transfer.gasPrice, transfer.gasUsed, transfer.timestamp),
]),
...transfers.map((transfer: any) => [
formatDate(transfer.timestamp),
transfer.pool ? transfer.pool.shortName : '-',
transfer.from ? transfer.from : '-',
'TRANSFER_OUT',
transfer.token ? transfer.token.symbol : '-',
new BN(transfer.amount)
.mul(
new BN(
tokenSymbolIsJunior(transfer.token.symbol) ? transfer.pool.juniorTokenPrice : transfer.pool.seniorTokenPrice
)
)
.div(new BN(10).pow(new BN(27 + 18)))
.toNumber(),
transfer.amount / 10 ** 18,
'-',
'-',
new BN(
tokenSymbolIsJunior(transfer.token.symbol) ? transfer.pool.juniorTokenPrice : transfer.pool.seniorTokenPrice
)
.div(new BN(10).pow(new BN(27 - 8)))
.toNumber() /
10 ** 8,
transfer.transaction,
transfer.gasPrice / 10 ** 9,
transfer.gasUsed,
calculateCostInUsd(transfer.gasPrice, transfer.gasUsed, transfer.timestamp),
]),
]

const sorted = rows.sort((a: string[], b: string[]) => {
return new Date(a[0]).getTime() - new Date(b[0]).getTime()
})

downloadCSV(sorted, csvName(`Investor Transaction List`))

return true
}
Loading
Loading