Skip to content

Commit

Permalink
feat: add delegate ID to veNFT on VeSugar
Browse files Browse the repository at this point in the history
  • Loading branch information
ethzoomer committed Oct 26, 2023
1 parent 7aa3161 commit 693aa97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 18 additions & 5 deletions contracts/VeSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ struct VeNFT:
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 @@ -52,8 +59,10 @@ 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 IVetoGovernorVotes:
interface IGovernor:
def clock() -> uint48: view
def getVotes(_venft_id: uint256, _timepoint: uint256) -> uint256: view

Expand All @@ -63,7 +72,7 @@ voter: public(IVoter)
token: public(address)
ve: public(IVotingEscrow)
dist: public(IRewardsDistributor)
gov: public(IVetoGovernorVotes)
gov: public(IGovernor)

# Methods

Expand All @@ -76,7 +85,7 @@ def __init__(_voter: address, _rewards_distributor: address, _gov: address):
self.ve = IVotingEscrow(self.voter.ve())
self.token = self.ve.token()
self.dist = IRewardsDistributor(_rewards_distributor)
self.gov = IVetoGovernorVotes(_gov)
self.gov = IGovernor(_gov)

@external
@view
Expand Down Expand Up @@ -154,7 +163,10 @@ def _byId(_id: uint256) -> VeNFT:
last_voted: uint256 = 0

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

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

if self.ve.voted(_id):
last_voted = self.voter.lastVoted(_id)
Expand Down Expand Up @@ -195,5 +207,6 @@ def _byId(_id: uint256) -> VeNFT:
voted_at: last_voted,
votes: votes,
token: self.token,
permanent: perma
permanent: perma,
delegate_id: delegate_id
})
3 changes: 2 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 @@ -150,6 +150,7 @@ The returned data/struct of type `VeNFT` values represent:
`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

0 comments on commit 693aa97

Please sign in to comment.