Skip to content

Commit

Permalink
feat: add voting weight and earned reward amount of Relay deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
ethzoomer committed Nov 14, 2023
1 parent 52cbc66 commit f589348
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions contracts/RelaySugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ struct LpVotes:
lp: address
weight: uint256

struct ManagedVenft:
id: uint256
amount: uint256
earned: uint256

struct Relay:
venft_id: uint256
decimals: uint8
Expand All @@ -30,7 +35,7 @@ struct Relay:
relay: address
inactive: bool
name: String[100]
account_venft_ids: DynArray[uint256, MAX_RESULTS]
account_venfts: DynArray[ManagedVenft, MAX_RESULTS]


interface IERC20:
Expand All @@ -53,6 +58,11 @@ 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 managedToLocked(_managed_venft_id: uint256) -> address: view
def weights(_venft_id: uint256, _managed_venft_id: uint256) -> uint256: view

interface IReward:
def earned(_token: address, _venft_id: uint256) -> uint256: view

interface IRelayRegistry:
def getAll() -> DynArray[address, MAX_RELAYS]: view
Expand Down Expand Up @@ -134,7 +144,7 @@ def _byAddress(_relay: address, _account: address) -> Relay:
relay: IRelay = IRelay(_relay)
managed_id: uint256 = relay.mTokenId()

account_venft_ids: DynArray[uint256, MAX_RESULTS] = empty(DynArray[uint256, MAX_RESULTS])
account_venfts: DynArray[ManagedVenft, MAX_RESULTS] = empty(DynArray[ManagedVenft, MAX_RESULTS])

for venft_index in range(MAX_RESULTS):
account_venft_id: uint256 = self.ve.ownerToNFTokenIdList(_account, venft_index)
Expand All @@ -144,7 +154,15 @@ def _byAddress(_relay: address, _account: address) -> Relay:

account_venft_manager_id: uint256 = self.ve.idToManaged(account_venft_id)
if account_venft_manager_id == managed_id:
account_venft_ids.append(account_venft_id)
locked_reward: IReward = IReward(self.ve.managedToLocked(account_venft_manager_id))
venft_weight: uint256 = self.ve.weights(account_venft_id, account_venft_manager_id)
earned: uint256 = locked_reward.earned(self.token, account_venft_id)

account_venfts.append(ManagedVenft({
id: account_venft_id,
amount: venft_weight,
earned: earned
}))

votes: DynArray[LpVotes, MAX_PAIRS] = []
amount: uint128 = self.ve.locked(managed_id)[0]
Expand Down Expand Up @@ -207,5 +225,5 @@ def _byAddress(_relay: address, _account: address) -> Relay:
relay: _relay,
inactive: inactive,
name: relay.name(),
account_venft_ids: account_venft_ids
account_venfts: account_venfts
})
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ The returned data/struct of type `Relay` values represent:
* `relay` - Relay address
* `inactive` - Relay active/inactive status
* `name` - Relay name
* `account_venft_ids` - token IDs of the account's deposits into this Relay
* `account_venfts` - List of veNFTs deposited into this Relay by the account in the form of `ManagedVenft`

---

Expand Down

0 comments on commit f589348

Please sign in to comment.