Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 9d00f9f

Browse files
committed
implemented Account.tokensDelegatedFrom
1 parent 042f40a commit 9d00f9f

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

schema.graphql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ type Account @entity {
231231
rewardsClaimed: BigDecimal!
232232
# voting state for each distribution period
233233
distributionPeriodVotes: [DistributionPeriodVote!]!
234-
# amount of tokens delegated to this account
235-
tokensDelegated: BigDecimal!
234+
# amount of tokens delegated by this user to a single delegated voter
235+
tokensDelegatedFrom: BigDecimal!
236+
# cumulative amount of tokens delegated from multiple users to this voter
237+
tokensDelegatedTo: BigDecimal!
236238

237239
# positions associated with the account
238240
positions: [Position!]!
@@ -961,6 +963,7 @@ type DelegateChanged @entity(immutable: true) {
961963

962964
type DelegateVotesChanged @entity(immutable: true) {
963965
id: Bytes!
966+
delegator: Bytes! # address
964967
delegate: Bytes! # address
965968
previousBalance: BigDecimal! # uint256
966969
newBalance: BigDecimal! # uint256

src/mappings/ajna-token.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function handleDelegateVotesChanged(
5353
let entity = new DelegateVotesChanged(
5454
event.transaction.hash.concatI32(event.logIndex.toI32())
5555
)
56+
entity.delegator = event.transaction.from
5657
entity.delegate = event.params.delegate
5758
entity.previousBalance = wadToDecimal(event.params.previousBalance)
5859
entity.newBalance = wadToDecimal(event.params.newBalance)
@@ -62,10 +63,14 @@ export function handleDelegateVotesChanged(
6263
entity.blockTimestamp = event.block.timestamp
6364
entity.transactionHash = event.transaction.hash
6465

66+
const delegator = loadOrCreateAccount(entity.delegator)
67+
delegator.tokensDelegatedFrom = entity.newBalance
68+
6569
const delegateId = addressToBytes(event.params.delegate)
6670
const delegate = loadOrCreateAccount(delegateId)
67-
delegate.tokensDelegated = delegate.tokensDelegated.plus(changeInBalance)
71+
delegate.tokensDelegatedTo = delegate.tokensDelegatedTo.plus(changeInBalance)
6872

73+
delegator.save()
6974
delegate.save()
7075
entity.save()
7176
}

src/utils/account.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export function loadOrCreateAccount(accountId: Bytes): Account {
2424
account.delegatedFrom = []
2525
account.rewardsClaimed = ZERO_BD
2626
account.distributionPeriodVotes = []
27-
account.tokensDelegated = ZERO_BD
27+
account.tokensDelegatedFrom = ZERO_BD
28+
account.tokensDelegatedTo = ZERO_BD
2829

2930
account.txCount = ZERO_BI
3031
}

0 commit comments

Comments
 (0)