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

Show how many tokens a user has delegated #82

Closed
wants to merge 2 commits into from
Closed

Conversation

EdNoepel
Copy link
Contributor

Enhancements

  • Update Account entity with a field showing how many tokens the user has delegated (to themselves, or to another delegated voter)
  • Update DelegateVotesChanged to reveal the delegator (user who delegated)

@@ -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
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@MikeHathaway MikeHathaway Dec 19, 2023

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

@EdNoepel EdNoepel marked this pull request as draft December 19, 2023 19:07
@@ -53,6 +53,7 @@ export function handleDelegateVotesChanged(
let entity = new DelegateVotesChanged(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.delegator = event.transaction.from
Copy link
Contributor Author

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!
Copy link
Contributor Author

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?

Copy link
Contributor

@MikeHathaway MikeHathaway Dec 19, 2023

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

Copy link
Contributor

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

@EdNoepel
Copy link
Contributor Author

This implementation does not make sense. There is no real concept of "number of tokens delegated".

@EdNoepel EdNoepel closed this Dec 20, 2023
@EdNoepel EdNoepel deleted the delegated-from branch December 20, 2023 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants