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

Add governance amount and delegate ID to VeSugar #32

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions contracts/VeSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ struct VeNFT:
decimals: uint8
amount: uint128
voting_amount: uint256
governance_amount: uint256
rebase_amount: uint256
expires_at: uint256
voted_at: uint256
votes: DynArray[LpVotes, MAX_PAIRS]
token: address
permanent: bool
delegate_id: uint256

struct Checkpoint:
from_timestamp: uint256
owner: address
delegated_balance: uint256
delegatee: uint256

# Our contracts / Interfaces

Expand All @@ -51,25 +59,33 @@ interface IVotingEscrow:
def locked(_venft_id: uint256) -> (uint128, uint256, bool): view
def ownerToNFTokenIdList(_account: address, _index: uint256) -> uint256: view
def voted(_venft_id: uint256) -> bool: view
def numCheckpoints(_venft_id: uint256) -> uint48: view
def checkpoints(_venft_id: uint256, _index: uint48) -> Checkpoint: view

interface IGovernor:
def clock() -> uint48: view
def getVotes(_venft_id: uint256, _timepoint: uint256) -> uint256: view

# Vars

voter: public(IVoter)
token: public(address)
ve: public(IVotingEscrow)
dist: public(IRewardsDistributor)
gov: public(IGovernor)

# Methods

@external
def __init__(_voter: address, _rewards_distributor: address):
def __init__(_voter: address, _rewards_distributor: address, _gov: address):
"""
@dev Sets up our external contract addresses
"""
self.voter = IVoter(_voter)
self.ve = IVotingEscrow(self.voter.ve())
self.token = self.ve.token()
self.dist = IRewardsDistributor(_rewards_distributor)
self.gov = IGovernor(_gov)

@external
@view
Expand Down Expand Up @@ -146,6 +162,12 @@ def _byId(_id: uint256) -> VeNFT:
amount, expires_at, perma = self.ve.locked(_id)
last_voted: uint256 = 0

timepoint: uint256 = convert(self.gov.clock(), uint256)
governance_amount: uint256 = self.gov.getVotes(_id, timepoint - 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was taking a closer look at this, do we actually need to call clock(), a simple block.timestamp should be enough, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ty. Adding


checkpoint_length: uint48 = self.ve.numCheckpoints(_id)
delegate_id: uint256 = self.ve.checkpoints(_id, checkpoint_length - 1).delegatee
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethzoomer shouldn't we be using the self.ve.delegates(_id) ?


if self.ve.voted(_id):
last_voted = self.voter.lastVoted(_id)

Expand Down Expand Up @@ -179,10 +201,12 @@ def _byId(_id: uint256) -> VeNFT:

amount: amount,
voting_amount: self.ve.balanceOfNFT(_id),
governance_amount: governance_amount,
rebase_amount: self.dist.claimable(_id),
expires_at: expires_at,
voted_at: last_voted,
votes: votes,
token: self.token,
permanent: perma
permanent: perma,
delegate_id: delegate_id
})
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ To fetch a list of rewards for a specific veNFT, this method is available:

### Vote-Escrow Locked NFT (veNFT) Data

`VeSugar.vy` is deployed at `0x0eCc2593E3a6A9be3628940Fa4D928CC257B588B`
`VeSugar.vy` is deployed at `0xc176b85C8c49120D95ed6B3942b700086A1ee2A3`

It allows fetching on-chain veNFT data (including the rewards accrued).
The returned data/struct of type `VeNFT` values represent:
Expand All @@ -142,13 +142,15 @@ The returned data/struct of type `VeNFT` values represent:
* `decimals` - veNFT token decimals
* `amount` - veNFT locked amount
* `voting_amount` - veNFT voting power
* `governance_amount` - veNFT voting power in governance
* `rebase_amount` - veNFT accrued reabses amount
* `expires_at` - veNFT lock expiration timestamp
* `voted_at` - veNFT last vote timestamp
* `votes` - veNFT list of pools with vote weights casted in the form of
`LpVotes`
* `token` - veNFT locked token address
* `permanent` - veNFT permanent lock enabled flag
* `delegate_id` - token ID of the veNFT being delegated to

The pool votes struct values represent:
* `lp` - the pool address
Expand Down
Loading