Skip to content

Commit

Permalink
Merge and paginate direct delegators (#169)
Browse files Browse the repository at this point in the history
* add direct delegatees to delegations table

* parallelize delegatees queries

* simple merge direct delegators

* paginate delegators

* use separate function for getting advanced delegators

* optimisations

* solve infinite scroll and tbody

* fix container height

* cache getCurrentAdvancedDelegators

* fix import

* fix import

* fix merge conflicts

* multi-tenancy

* fix getProxy return type

* fix types

* fix setProxy type

* fix num_of_delegators parsing

* fix infinite scroller

* add transaction_hashes to delegatees views

* repair prisma

* fix prisma schema

* fix voting_power parsing breaks when no data

* fix: environment scoping

* put back query time logging

* delegators query optimization

* set query logging based on env variable

* use better naming for muting query logging: defalt to false

* fix delegators query

* remove console.log

* refactor

* apply jeff's refactor

* refactor

* clean up

---------

Co-authored-by: ferrodri <f.rodriguez.hervias@gmail.com>
  • Loading branch information
stepandel and ferrodri authored Jul 22, 2024
1 parent d0290f7 commit 5367f18
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 213 deletions.
51 changes: 30 additions & 21 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,12 @@ view OptimismVoterStats {
}

view OptimismDelegatees {
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
contract String? @db.VarChar(42)
transaction_hash String? @db.VarChar(66)
@@map("delegatees")
@@schema("optimism")
Expand All @@ -485,10 +487,12 @@ view OptimismDelegateChangedEvents {
}

view ensDelegatees {
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
contract String? @db.VarChar(42)
transaction_hash String? @db.VarChar(66)
@@map("delegatees")
@@schema("ens")
Expand Down Expand Up @@ -688,10 +692,12 @@ chain_id Int
}

view etherfiDelegatees {
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
contract String? @db.VarChar(42)
transaction_hash String? @db.VarChar(66)
@@map("delegatees")
@@schema("etherfi")
Expand Down Expand Up @@ -881,10 +887,12 @@ view etherfiDelegateChangedEvents {
}

view uniswapDelegatees {
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
contract String? @db.VarChar(42)
transaction_hash String? @db.VarChar(66)
@@map("delegatees")
@@schema("uniswap")
Expand Down Expand Up @@ -1773,11 +1781,12 @@ view cyberDelegateChangedEvents {
}

view cyberDelegatees {
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
contract String @db.VarChar(42)
delegator String @unique
delegatee String
block_number BigInt
balance Decimal @db.Decimal
contract String? @db.VarChar(42)
transaction_hash String? @db.VarChar(66)
@@schema("cyber")
@@map("delegatees")
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/common/delegates/getDelegates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ async function getDelegate(addressOrENSName: string): Promise<Delegate> {
citizen: delegate?.citizen || false,
votingPower: {
total: totalVotingPower.toString(),
direct: delegate?.voting_power.toString() || "0",
direct: delegate?.voting_power?.toString() || "0",
advanced: delegate?.advanced_vp?.toFixed(0) || "0",
},
votingPowerRelativeToVotableSupply: Number(
Expand All @@ -415,7 +415,7 @@ async function getDelegate(addressOrENSName: string): Promise<Delegate> {
// Use cached amount when recalculation is expensive
cachedNumOfDelegators < 1000n
? BigInt(
(await numOfDelegatesQuery)?.[0]?.num_of_delegators.toString() ||
(await numOfDelegatesQuery)?.[0]?.num_of_delegators?.toString() ||
"0"
)
: cachedNumOfDelegators,
Expand Down
Loading

0 comments on commit 5367f18

Please sign in to comment.