Skip to content

Commit

Permalink
Merge pull request #75 from Decentraland-DAO/feat/net-txs
Browse files Browse the repository at this point in the history
feat: Net income/outcome
  • Loading branch information
ncomerci authored Oct 16, 2023
2 parents 3da7303 + b50a98f commit 930ca02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/entities/Tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ExportedTagType = Exclude<TagType, TagType.SECONDARY_SALE | TagType.SWAP |

export enum TagCategoryType {
CURATORS_COMMITTEE_PAYOUT,
DAO_COMMITTEE,
DAO_WALLETS_TRANSACTIONS,
DAO_COMMITTEE_COMPENSATION,
ESTATE_MARKETPLACE_SALES,
FACILITATION_PAYOUT,
Expand All @@ -68,7 +68,7 @@ export interface TagCategory {

const TAG_CATEGORIES: Record<keyof typeof TagCategoryType, TagCategory> = {
CURATORS_COMMITTEE_PAYOUT: { name: 'Wearable Curators Committee Payout', description: 'Transactions corresponding to the payout of compensations for members of the Wearables Curation Committee' },
DAO_COMMITTEE: { name: 'DAO Committee', description: 'Transactions between the DAO Treasury and the DAO Committee wallets (e.g. Transaction gas refunds)' },
DAO_WALLETS_TRANSACTIONS: { name: 'DAO Wallets Transactions', description: 'Transactions between the DAO Treasury and the DAO Committee wallets (e.g. Transaction gas refunds)' },
DAO_COMMITTEE_COMPENSATION: { name: 'DAO Committee Compensation', description: 'Transactions corresponding to the payout of compensations for members of the DAO Committee' },
ESTATE_MARKETPLACE_SALES: { name: 'ESTATE DCL Marketplace Sales Fee', description: 'Funds corresponding to the 2.5% fee applied to every ESTATE transaction (Minting or secondary)' },
FACILITATION_PAYOUT: { name: 'Community Facilitation Payout', description: 'Transactions corresponding to the payout for monthly compensations of the DAO Facilitator role' },
Expand Down Expand Up @@ -142,7 +142,7 @@ const TAG_CATEGORY_MAPPING: Record<ExportedTagType, TagCategory> = {
[TagType.OPENSEA]: TAG_CATEGORIES.OPENSEA_MARKETPLACE_FEE,
[TagType.CURATION_FEE]: TAG_CATEGORIES.WEARABLE_SUBMISSION_FEE,
[TagType.MATIC_MARKETPLACE]: TAG_CATEGORIES.WEARABLES_MINTING_FEE,
[TagType.DAO_COMMITTEE]: TAG_CATEGORIES.DAO_COMMITTEE,
[TagType.DAO_COMMITTEE]: TAG_CATEGORIES.DAO_WALLETS_TRANSACTIONS,
[TagType.DAO_COMMITTEE_PAYMENT]: TAG_CATEGORIES.DAO_COMMITTEE_COMPENSATION,
[TagType.GRANT]: TAG_CATEGORIES.GRANTS_PAYOUT,
[TagType.GRANT_REVENUE]: TAG_CATEGORIES.GRANTS_REVENUE,
Expand Down
30 changes: 25 additions & 5 deletions src/export-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BALANCES from '../public/balances.json'
import GRANTS from '../public/grants.json'
import TRANSACTIONS from '../public/transactions.json'
import { TagCategoryType, Tags } from './entities/Tags'
import { TagCategoryType, TagType, Tags } from './entities/Tags'
import { CurationCommittee, DAOCommittee, RevocationCommittee, SABCommittee } from './entities/Teams'
import { TransactionParsed } from './export-transactions'
import { BalanceDetails } from './interfaces/Api'
Expand Down Expand Up @@ -36,6 +36,23 @@ function getTxsDetails(txs: Record<string, TransactionDetails>): BalanceDetails[
return sortedDetails
}

function compensateBalances(fixedBalance: BalanceDetails[], subtractingBalance: BalanceDetails[]): BalanceDetails[] {
const balanceMap = new Map<string, BalanceDetails>()

fixedBalance.forEach(balance => {
balanceMap.set(balance.name, { ...balance })
})

subtractingBalance.forEach(balance => {
const existingBalance = balanceMap.get(balance.name)
if (existingBalance) {
existingBalance.value -= balance.value
}
})

return Array.from(balanceMap.values()).filter(balance => balance.value > 0)
}

const sumQuote = (txs: TransactionParsed[]) => txs.reduce((total, tx) => total + tx.quote, 0)

async function main() {
Expand Down Expand Up @@ -72,17 +89,20 @@ async function main() {
const incomeDetails = getTxsDetails(incomeTaggedTxs)
const expensesDetails = getTxsDetails(expensesTaggedTxs)

const netIncomeDetails = compensateBalances(incomeDetails, expensesDetails)
const netExpensesDetails = compensateBalances(expensesDetails, incomeDetails)

const data = {
'balances': BALANCES,
'income': {
'total': incomeDetails.reduce((acc, cur) => acc + cur.value, 0),
'total': netIncomeDetails.reduce((acc, cur) => acc + cur.value, 0),
'previous': incomeDelta,
'details': incomeDetails
'details': netIncomeDetails
},
'expenses': {
'total': expensesDetails.reduce((acc, cur) => acc + cur.value, 0),
'total': netExpensesDetails.reduce((acc, cur) => acc + cur.value, 0),
'previous': expensesDelta,
'details': expensesDetails
'details': netExpensesDetails
},
'funding': {
'total': totalFunding
Expand Down

0 comments on commit 930ca02

Please sign in to comment.