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

feat: add voting weight and earned reward amount of Relay deposits #33

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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`
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll need to add the ManagedVenft struct to docs as well


---

Expand Down
Loading