Skip to content

Commit f589348

Browse files
committed
feat: add voting weight and earned reward amount of Relay deposits
1 parent 52cbc66 commit f589348

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

contracts/RelaySugar.vy

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ struct LpVotes:
1414
lp: address
1515
weight: uint256
1616

17+
struct ManagedVenft:
18+
id: uint256
19+
amount: uint256
20+
earned: uint256
21+
1722
struct Relay:
1823
venft_id: uint256
1924
decimals: uint8
@@ -30,7 +35,7 @@ struct Relay:
3035
relay: address
3136
inactive: bool
3237
name: String[100]
33-
account_venft_ids: DynArray[uint256, MAX_RESULTS]
38+
account_venfts: DynArray[ManagedVenft, MAX_RESULTS]
3439

3540

3641
interface IERC20:
@@ -53,6 +58,11 @@ interface IVotingEscrow:
5358
def locked(_venft_id: uint256) -> (uint128, uint256, bool): view
5459
def ownerToNFTokenIdList(_account: address, _index: uint256) -> uint256: view
5560
def voted(_venft_id: uint256) -> bool: view
61+
def managedToLocked(_managed_venft_id: uint256) -> address: view
62+
def weights(_venft_id: uint256, _managed_venft_id: uint256) -> uint256: view
63+
64+
interface IReward:
65+
def earned(_token: address, _venft_id: uint256) -> uint256: view
5666

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

137-
account_venft_ids: DynArray[uint256, MAX_RESULTS] = empty(DynArray[uint256, MAX_RESULTS])
147+
account_venfts: DynArray[ManagedVenft, MAX_RESULTS] = empty(DynArray[ManagedVenft, MAX_RESULTS])
138148

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

145155
account_venft_manager_id: uint256 = self.ve.idToManaged(account_venft_id)
146156
if account_venft_manager_id == managed_id:
147-
account_venft_ids.append(account_venft_id)
157+
locked_reward: IReward = IReward(self.ve.managedToLocked(account_venft_manager_id))
158+
venft_weight: uint256 = self.ve.weights(account_venft_id, account_venft_manager_id)
159+
earned: uint256 = locked_reward.earned(self.token, account_venft_id)
160+
161+
account_venfts.append(ManagedVenft({
162+
id: account_venft_id,
163+
amount: venft_weight,
164+
earned: earned
165+
}))
148166

149167
votes: DynArray[LpVotes, MAX_PAIRS] = []
150168
amount: uint128 = self.ve.locked(managed_id)[0]
@@ -207,5 +225,5 @@ def _byAddress(_relay: address, _account: address) -> Relay:
207225
relay: _relay,
208226
inactive: inactive,
209227
name: relay.name(),
210-
account_venft_ids: account_venft_ids
228+
account_venfts: account_venfts
211229
})

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ The returned data/struct of type `Relay` values represent:
189189
* `relay` - Relay address
190190
* `inactive` - Relay active/inactive status
191191
* `name` - Relay name
192-
* `account_venft_ids` - token IDs of the account's deposits into this Relay
192+
* `account_venfts` - List of veNFTs deposited into this Relay by the account in the form of `ManagedVenft`
193193

194194
---
195195

0 commit comments

Comments
 (0)