-
Notifications
You must be signed in to change notification settings - Fork 4
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
Show how many tokens a user has delegated #82
Conversation
@@ -62,10 +63,14 @@ export function handleDelegateVotesChanged( | |||
entity.blockTimestamp = event.block.timestamp | |||
entity.transactionHash = event.transaction.hash | |||
|
|||
const delegator = loadOrCreateAccount(entity.delegator) | |||
delegator.tokensDelegatedFrom = entity.newBalance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be new - prev? Current approach would reflect the total amount including others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no "others"; a user can only delegate their current balance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that DelegateVotesChanged
shows the new total delegated amount a delegate
has across all delegations. If so, setting delegator.tokensDelegatedFrom
would then show the total delegated amount available to the delegatee inclusive of the delegator and others.
const delegateId = addressToBytes(event.params.delegate) | ||
const delegate = loadOrCreateAccount(delegateId) | ||
delegate.tokensDelegated = delegate.tokensDelegated.plus(changeInBalance) | ||
delegate.tokensDelegatedTo = delegate.tokensDelegatedTo.plus(changeInBalance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this value just be equivalent to newBalance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I just renamed tokensDelegated
to tokensDelegatedTo
; no change in logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, but was just suggesting that we could simplify the logic by setting to just newBalance
, but not a big deal
src/mappings/ajna-token.ts
Outdated
@@ -53,6 +53,7 @@ export function handleDelegateVotesChanged( | |||
let entity = new DelegateVotesChanged( | |||
event.transaction.hash.concatI32(event.logIndex.toI32()) | |||
) | |||
entity.delegator = event.transaction.from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I got this line wrong; delegator should be event.transaction.to
.
@@ -53,6 +53,7 @@ export function handleDelegateVotesChanged( | |||
let entity = new DelegateVotesChanged( | |||
event.transaction.hash.concatI32(event.logIndex.toI32()) | |||
) | |||
entity.delegator = event.transaction.to! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot use from
because it's the sender, not the recipient. We cannot use to
because it is the token address. How do we determine the delegator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event is always emitted concurrently with DelegateChanged
or transfer
so we can try to look at the event emitted in the same block at the correct log index
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We adopted a similar approach for handling AuctionSettle
and AuctionNFTSettle
This implementation does not make sense. There is no real concept of "number of tokens delegated". |
Enhancements
Account
entity with a field showing how many tokens the user has delegated (to themselves, or to another delegated voter)DelegateVotesChanged
to reveal the delegator (user who delegated)