Skip to content

Commit

Permalink
VeSugar: skip (m)veNFTs gov amount.
Browse files Browse the repository at this point in the history
  • Loading branch information
stas committed Jan 10, 2025
1 parent 652693d commit be71785
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions contracts/VeSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ interface IVoter:
def usedWeights(_venft_id: uint256) -> uint256: view

interface IRewardsDistributor:
def ve() -> address: view
def claimable(_venft_id: uint256) -> uint256: view

interface IVotingEscrow:
Expand All @@ -56,6 +55,7 @@ interface IVotingEscrow:
def voted(_venft_id: uint256) -> bool: view
def delegates(_venft_id: uint256) -> uint256: view
def idToManaged(_venft_id: uint256) -> uint256: view
def escrowType(_venft_id: uint256) -> uint8: view

interface IGovernor:
def getVotes(_venft_id: uint256, _timepoint: uint256) -> uint256: view
Expand Down Expand Up @@ -156,8 +156,10 @@ def _byId(_id: uint256) -> VeNFT:
amount, expires_at, perma = staticcall self.ve.locked(_id)
last_voted: uint256 = 0
governance_amount: uint256 = 0
type: uint8 = staticcall self.ve.escrowType(_id)

if self.gov.address != empty(address):
# Skip gov amount fetching for (m)veNFTs
if self.gov.address != empty(address) and type < 2:
governance_amount = staticcall self.gov.getVotes(_id, block.timestamp)

delegate_id: uint256 = staticcall self.ve.delegates(_id)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_ve_sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ def test_byId(sugar_contract):
assert venft.voted_at > 0


@pytest.mark.skipif(int(CHAIN_ID) not in [10, 8453], reason="Only root chains")
def test_byId_managed(sugar_contract):
if int(CHAIN_ID) == 10:
venft = sugar_contract.byId(20264)
else:
venft = sugar_contract.byId(10298)

assert venft is not None
assert len(venft) == 14
assert venft.id is not None
assert venft.voted_at > 0
assert venft.governance_amount == 0


@pytest.mark.skipif(int(CHAIN_ID) not in [10, 8453], reason="Only root chains")
def test_byAccount(sugar_contract):
venft = sugar_contract.byId(1)
Expand Down

0 comments on commit be71785

Please sign in to comment.