From 46467b910c0ad9ef3787c4d7f9802e5a6701307b Mon Sep 17 00:00:00 2001 From: Zoomer <87513793+ethzoomer@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:47:26 -0500 Subject: [PATCH 1/9] Add governance amount and delegate ID to VeSugar (#32) * feat: add governance amount to VeSugar veNFT * feat: add delegate ID to veNFT on VeSugar * Fix: use delegates function to fetch delegation * refactor: use block.timestamp for timepoint --- contracts/VeSugar.vy | 18 ++++++++++++++++-- readme.md | 4 +++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/contracts/VeSugar.vy b/contracts/VeSugar.vy index 3fc43e7..035a5ac 100644 --- a/contracts/VeSugar.vy +++ b/contracts/VeSugar.vy @@ -20,12 +20,14 @@ struct VeNFT: decimals: uint8 amount: uint128 voting_amount: uint256 + governance_amount: uint256 rebase_amount: uint256 expires_at: uint256 voted_at: uint256 votes: DynArray[LpVotes, MAX_PAIRS] token: address permanent: bool + delegate_id: uint256 # Our contracts / Interfaces @@ -51,6 +53,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 delegates(_venft_id: uint256) -> uint256: view + +interface IGovernor: + def getVotes(_venft_id: uint256, _timepoint: uint256) -> uint256: view # Vars @@ -58,11 +64,12 @@ voter: public(IVoter) token: public(address) ve: public(IVotingEscrow) dist: public(IRewardsDistributor) +gov: public(IGovernor) # Methods @external -def __init__(_voter: address, _rewards_distributor: address): +def __init__(_voter: address, _rewards_distributor: address, _gov: address): """ @dev Sets up our external contract addresses """ @@ -70,6 +77,7 @@ def __init__(_voter: address, _rewards_distributor: address): self.ve = IVotingEscrow(self.voter.ve()) self.token = self.ve.token() self.dist = IRewardsDistributor(_rewards_distributor) + self.gov = IGovernor(_gov) @external @view @@ -146,6 +154,10 @@ def _byId(_id: uint256) -> VeNFT: amount, expires_at, perma = self.ve.locked(_id) last_voted: uint256 = 0 + governance_amount: uint256 = self.gov.getVotes(_id, block.timestamp) + + delegate_id: uint256 = self.ve.delegates(_id) + if self.ve.voted(_id): last_voted = self.voter.lastVoted(_id) @@ -179,10 +191,12 @@ def _byId(_id: uint256) -> VeNFT: amount: amount, voting_amount: self.ve.balanceOfNFT(_id), + governance_amount: governance_amount, rebase_amount: self.dist.claimable(_id), expires_at: expires_at, voted_at: last_voted, votes: votes, token: self.token, - permanent: perma + permanent: perma, + delegate_id: delegate_id }) diff --git a/readme.md b/readme.md index d3e258e..4aaedce 100644 --- a/readme.md +++ b/readme.md @@ -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 `0x86651B1E97428689EAc93bDE47B294CfB887408c` It allows fetching on-chain veNFT data (including the rewards accrued). The returned data/struct of type `VeNFT` values represent: @@ -142,6 +142,7 @@ The returned data/struct of type `VeNFT` values represent: * `decimals` - veNFT token decimals * `amount` - veNFT locked amount * `voting_amount` - veNFT voting power + * `governance_amount` - veNFT voting power in governance * `rebase_amount` - veNFT accrued reabses amount * `expires_at` - veNFT lock expiration timestamp * `voted_at` - veNFT last vote timestamp @@ -149,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 From 52cbc665a4654f977bd9066a3edc9df3419aefdb Mon Sep 17 00:00:00 2001 From: Zoomer <87513793+ethzoomer@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:47:39 -0500 Subject: [PATCH 2/9] Add last used voting amount for Relay (#31) * feat: add last used voting amount to Relay * feat: point readme to latest RelaySugar release * Point readme to latest RelaySugar release --- contracts/RelaySugar.vy | 2 ++ readme.md | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/RelaySugar.vy b/contracts/RelaySugar.vy index 294679f..2286c01 100644 --- a/contracts/RelaySugar.vy +++ b/contracts/RelaySugar.vy @@ -19,6 +19,7 @@ struct Relay: decimals: uint8 amount: uint128 voting_amount: uint256 + used_voting_amount: uint256 voted_at: uint256 votes: DynArray[LpVotes, MAX_PAIRS] token: address @@ -195,6 +196,7 @@ def _byAddress(_relay: address, _account: address) -> Relay: decimals: self.ve.decimals(), amount: amount, voting_amount: self.ve.balanceOfNFT(managed_id), + used_voting_amount: vote_weight, voted_at: last_voted, votes: votes, token: relay.token(), diff --git a/readme.md b/readme.md index 4aaedce..3e56736 100644 --- a/readme.md +++ b/readme.md @@ -169,7 +169,7 @@ The available methods are: ### Relay Data -`RelaySugar.vy` is deployed at `0xeBf8F5818D429785A584693599b695AFc3BeE3c6` +`RelaySugar.vy` is deployed at `0xeEc6dD356508d3f30503bd15317b6D7671410e8e` It allows fetching Relay autocompounder/autoconverter data. The returned data/struct of type `Relay` values represent: @@ -178,6 +178,7 @@ The returned data/struct of type `Relay` values represent: * `decimals` - Relay veNFT token decimals * `amount` - Relay veNFT locked amount * `voting_amount` - Relay veNFT voting power + * `used_voting_amount` - Relay veNFT voting power used for last vote * `voted_at` - Relay veNFT last vote timestamp * `votes` - Relay veNFT list of pools with vote weights casted in the form of `LpVotes` From c3f2a8d08efbc9a4b2a8acea44e91443509d3706 Mon Sep 17 00:00:00 2001 From: Zoomer <87513793+ethzoomer@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:53:48 -0600 Subject: [PATCH 3/9] feat: add voting weight and earned reward amount of Relay deposits (#33) * feat: add voting weight and earned reward amount of Relay deposits * docs: add managed venft struct to readme * docs: add latest RelaySugar deployment to readme --- contracts/RelaySugar.vy | 26 ++++++++++++++++++++++---- readme.md | 9 +++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/contracts/RelaySugar.vy b/contracts/RelaySugar.vy index 2286c01..e37dda8 100644 --- a/contracts/RelaySugar.vy +++ b/contracts/RelaySugar.vy @@ -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 @@ -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: @@ -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 @@ -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) @@ -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] @@ -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 }) diff --git a/readme.md b/readme.md index 3e56736..1e16dab 100644 --- a/readme.md +++ b/readme.md @@ -169,7 +169,7 @@ The available methods are: ### Relay Data -`RelaySugar.vy` is deployed at `0xeEc6dD356508d3f30503bd15317b6D7671410e8e` +`RelaySugar.vy` is deployed at `0xd4A12f507dfcfeE01E54736A7E0676B136f69667` It allows fetching Relay autocompounder/autoconverter data. The returned data/struct of type `Relay` values represent: @@ -189,7 +189,12 @@ 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` + +The managed veNFT deposit struct values represent: + * `id` - the token ID of the veNFT + * `amount` - the weight of the veNFT + * `earned` - earned emissions of the veNFT --- From c30be94655b2505671867e47e92f3bca59cf25fc Mon Sep 17 00:00:00 2001 From: Zoomer <87513793+ethzoomer@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:43:14 -0600 Subject: [PATCH 4/9] feat: calculate updated claimable unstaked fees in LpSugar (#34) * feat: calculate updated claimable unstaked fees in LpSugar * perf: only calculate claimable unstaked fees if nonzero account * fix: pool decimals int conversion * docs: add latest LpSugar deployment to readme --- contracts/LpSugar.vy | 28 ++++++++++++++++++++++++---- readme.md | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/contracts/LpSugar.vy b/contracts/LpSugar.vy index 1b96d1e..8df9cec 100644 --- a/contracts/LpSugar.vy +++ b/contracts/LpSugar.vy @@ -107,6 +107,10 @@ interface IPool: def reserve1() -> uint256: view def claimable0(_account: address) -> uint256: view def claimable1(_account: address) -> uint256: view + def supplyIndex0(_account: address) -> uint256: view + def supplyIndex1(_account: address) -> uint256: view + def index0() -> uint256: view + def index1() -> uint256: view def totalSupply() -> uint256: view def symbol() -> String[100]: view def decimals() -> uint8: view @@ -353,6 +357,22 @@ def _byData(_data: address[3], _account: address) -> Lp: token0: IERC20 = IERC20(pool.token0()) token1: IERC20 = IERC20(pool.token1()) gauge_alive: bool = self.voter.isAlive(gauge.address) + decimals: uint8 = pool.decimals() + claimable0: uint256 = 0 + claimable1: uint256 = 0 + acc_balance: uint256 = 0 + + if _account != empty(address): + acc_balance = pool.balanceOf(_account) + claimable0 = pool.claimable0(_account) + claimable1 = pool.claimable1(_account) + claimable_delta0: uint256 = pool.index0() - pool.supplyIndex0(_account) + claimable_delta1: uint256 = pool.index1() - pool.supplyIndex1(_account) + + if claimable_delta0 > 0: + claimable0 += (acc_balance * claimable_delta0) / 10**convert(decimals, uint256) + if claimable_delta1 > 0: + claimable1 += (acc_balance * claimable_delta1) / 10**convert(decimals, uint256) if gauge.address != empty(address): acc_staked = gauge.balanceOf(_account) @@ -366,17 +386,17 @@ def _byData(_data: address[3], _account: address) -> Lp: return Lp({ lp: _data[1], symbol: pool.symbol(), - decimals: pool.decimals(), + decimals: decimals, stable: is_stable, total_supply: pool.totalSupply(), token0: token0.address, reserve0: pool.reserve0(), - claimable0: pool.claimable0(_account), + claimable0: claimable0, token1: token1.address, reserve1: pool.reserve1(), - claimable1: pool.claimable1(_account), + claimable1: claimable1, gauge: gauge.address, gauge_total_supply: gauge_total_supply, @@ -389,7 +409,7 @@ def _byData(_data: address[3], _account: address) -> Lp: emissions: emissions, emissions_token: emissions_token, - account_balance: pool.balanceOf(_account), + account_balance: acc_balance, account_earned: earned, account_staked: acc_staked, diff --git a/readme.md b/readme.md index 1e16dab..ea5d021 100644 --- a/readme.md +++ b/readme.md @@ -35,7 +35,7 @@ Below is the list of datasets we support. ### Liquidity Pools Data -`LpSugar.vy` is deployed at `0xa1f09427fa89b92e9b4e4c7003508c8614f19791` +`LpSugar.vy` is deployed at `0x43479F2FF090A787E4e70d91f4485c7A75B0a964` It allows fetching on-chain pools data. The returned data/struct of type `Lp` values represent: From 91d0ff38dfad043976355384b9c6f50413e00eeb Mon Sep 17 00:00:00 2001 From: Zoomer <87513793+ethzoomer@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:33:48 -0600 Subject: [PATCH 5/9] feat: add fee level to forSwaps struct (#35) * feat: add fee level to forSwaps struct * docs: add latest LpSugar deployment to readme --- contracts/LpSugar.vy | 7 +++++-- readme.md | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/contracts/LpSugar.vy b/contracts/LpSugar.vy index 8df9cec..2f58a17 100644 --- a/contracts/LpSugar.vy +++ b/contracts/LpSugar.vy @@ -27,6 +27,7 @@ struct SwapLp: token0: address token1: address factory: address + pool_fee: uint256 struct Lp: lp: address @@ -233,14 +234,16 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]: pool_addr: address = factory.allPools(pindex) pool: IPool = IPool(pool_addr) + is_stable: bool = pool.stable() if pool.reserve0() > 0: pools.append(SwapLp({ lp: pool_addr, - stable: pool.stable(), + stable: is_stable, token0: pool.token0(), token1: pool.token1(), - factory: factory.address + factory: factory.address, + pool_fee: factory.getFee(pool_addr, is_stable) })) return pools diff --git a/readme.md b/readme.md index ea5d021..61fcec3 100644 --- a/readme.md +++ b/readme.md @@ -35,7 +35,7 @@ Below is the list of datasets we support. ### Liquidity Pools Data -`LpSugar.vy` is deployed at `0x43479F2FF090A787E4e70d91f4485c7A75B0a964` +`LpSugar.vy` is deployed at `0x6A4a8e26D9bA37515F331de7fbA2c6852f55128E` It allows fetching on-chain pools data. The returned data/struct of type `Lp` values represent: From cf9098d707f873b74ab456006b23ec0c726795f9 Mon Sep 17 00:00:00 2001 From: Zoomer <87513793+ethzoomer@users.noreply.github.com> Date: Fri, 17 Nov 2023 09:05:34 -0600 Subject: [PATCH 6/9] fix: use last voted timestamp of m_veNFT for Relay deposited veNFTs (#36) * fix: use last voted timestamp of m_veNFT for Relay deposited veNFTs * docs: add latest VeSugar deployment to readme --- contracts/VeSugar.vy | 5 +++++ readme.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/contracts/VeSugar.vy b/contracts/VeSugar.vy index 035a5ac..9cea98f 100644 --- a/contracts/VeSugar.vy +++ b/contracts/VeSugar.vy @@ -54,6 +54,7 @@ interface IVotingEscrow: def ownerToNFTokenIdList(_account: address, _index: uint256) -> uint256: view def voted(_venft_id: uint256) -> bool: view def delegates(_venft_id: uint256) -> uint256: view + def idToManaged(_venft_id: uint256) -> uint256: view interface IGovernor: def getVotes(_venft_id: uint256, _timepoint: uint256) -> uint256: view @@ -160,6 +161,10 @@ def _byId(_id: uint256) -> VeNFT: if self.ve.voted(_id): last_voted = self.voter.lastVoted(_id) + else: + managed_id: uint256 = self.ve.idToManaged(_id) + if managed_id != 0: + last_voted = self.voter.lastVoted(managed_id) vote_weight: uint256 = self.voter.usedWeights(_id) # Since we don't have a way to see how many pools we voted... diff --git a/readme.md b/readme.md index 61fcec3..40c8d57 100644 --- a/readme.md +++ b/readme.md @@ -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 `0x86651B1E97428689EAc93bDE47B294CfB887408c` +`VeSugar.vy` is deployed at `0xAED3DE5586acd2Aba23F5FB8811e9A7ffaF80773` It allows fetching on-chain veNFT data (including the rewards accrued). The returned data/struct of type `VeNFT` values represent: From 313fa0c51d51fe9903140817cce7e9525b5e8a14 Mon Sep 17 00:00:00 2001 From: Zoomer <87513793+ethzoomer@users.noreply.github.com> Date: Fri, 17 Nov 2023 12:46:16 -0600 Subject: [PATCH 7/9] fix: don't inherit Relay's last voted timestamp on VeSugar (#37) --- contracts/VeSugar.vy | 7 ++----- readme.md | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/contracts/VeSugar.vy b/contracts/VeSugar.vy index 9cea98f..7347c19 100644 --- a/contracts/VeSugar.vy +++ b/contracts/VeSugar.vy @@ -158,13 +158,10 @@ def _byId(_id: uint256) -> VeNFT: governance_amount: uint256 = self.gov.getVotes(_id, block.timestamp) delegate_id: uint256 = self.ve.delegates(_id) + managed_id: uint256 = self.ve.idToManaged(_id) - if self.ve.voted(_id): + if managed_id != 0 or self.ve.voted(_id): last_voted = self.voter.lastVoted(_id) - else: - managed_id: uint256 = self.ve.idToManaged(_id) - if managed_id != 0: - last_voted = self.voter.lastVoted(managed_id) vote_weight: uint256 = self.voter.usedWeights(_id) # Since we don't have a way to see how many pools we voted... diff --git a/readme.md b/readme.md index 40c8d57..371094c 100644 --- a/readme.md +++ b/readme.md @@ -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 `0xAED3DE5586acd2Aba23F5FB8811e9A7ffaF80773` +`VeSugar.vy` is deployed at `0x37403dBd6f1b583ea244F7956fF9e37EF45c63eB` It allows fetching on-chain veNFT data (including the rewards accrued). The returned data/struct of type `VeNFT` values represent: From 2339bccb07fabb2d2bfc5ab18cac9904696ecfa0 Mon Sep 17 00:00:00 2001 From: Zoomer <87513793+ethzoomer@users.noreply.github.com> Date: Sun, 17 Dec 2023 20:37:44 -0600 Subject: [PATCH 8/9] feat: add list of registries to RelaySugar constructor (#40) * feat: add list of registries to RelaySugar constructor * docs: add latest RelaySugar deployment to readme --- contracts/RelaySugar.vy | 34 ++++++++++++++++++++-------------- readme.md | 2 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/contracts/RelaySugar.vy b/contracts/RelaySugar.vy index e37dda8..1f37c5a 100644 --- a/contracts/RelaySugar.vy +++ b/contracts/RelaySugar.vy @@ -8,6 +8,7 @@ MAX_RELAYS: constant(uint256) = 50 MAX_RESULTS: constant(uint256) = 1000 MAX_PAIRS: constant(uint256) = 30 +MAX_REGISTRIES: constant(uint256) = 20 WEEK: constant(uint256) = 7 * 24 * 60 * 60 struct LpVotes: @@ -81,17 +82,17 @@ interface IRelay: def getRoleMember(_role: bytes32, _index: uint256) -> address: view # Vars -registry: public(IRelayRegistry) +registries: public(DynArray[address, MAX_REGISTRIES]) voter: public(IVoter) ve: public(IVotingEscrow) token: public(address) @external -def __init__(_registry: address, _voter: address): +def __init__(_registries: DynArray[address, MAX_REGISTRIES], _voter: address): """ @dev Set up our external registry and voter contracts """ - self.registry = IRelayRegistry(_registry) + self.registries = _registries self.voter = IVoter(_voter) self.ve = IVotingEscrow(self.voter.ve()) self.token = self.ve.token() @@ -113,21 +114,26 @@ def _relays(_account: address) -> DynArray[Relay, MAX_RELAYS]: @return Array of Relay structs """ relays: DynArray[Relay, MAX_RELAYS] = empty(DynArray[Relay, MAX_RELAYS]) - factories: DynArray[address, MAX_RELAYS] = self.registry.getAll() - - for factory_index in range(0, MAX_RELAYS): - if factory_index == len(factories): + for registry_index in range(0, MAX_REGISTRIES): + if registry_index == len(self.registries): break + + relay_registry: IRelayRegistry = IRelayRegistry(self.registries[registry_index]) + factories: DynArray[address, MAX_RELAYS] = relay_registry.getAll() - relay_factory: IRelayFactory = IRelayFactory(factories[factory_index]) - addresses: DynArray[address, MAX_RELAYS] = relay_factory.relays() - - for index in range(0, MAX_RELAYS): - if index == len(addresses): + for factory_index in range(0, MAX_RELAYS): + if factory_index == len(factories): break - relay: Relay = self._byAddress(addresses[index], _account) - relays.append(relay) + relay_factory: IRelayFactory = IRelayFactory(factories[factory_index]) + addresses: DynArray[address, MAX_RELAYS] = relay_factory.relays() + + for index in range(0, MAX_RELAYS): + if index == len(addresses): + break + + relay: Relay = self._byAddress(addresses[index], _account) + relays.append(relay) return relays diff --git a/readme.md b/readme.md index 371094c..aeb17d2 100644 --- a/readme.md +++ b/readme.md @@ -169,7 +169,7 @@ The available methods are: ### Relay Data -`RelaySugar.vy` is deployed at `0xd4A12f507dfcfeE01E54736A7E0676B136f69667` +`RelaySugar.vy` is deployed at `0x062185EEF2726EFc11880856CD356FA2Ac2B38Ff` It allows fetching Relay autocompounder/autoconverter data. The returned data/struct of type `Relay` values represent: From bc690bb96a11293d0e8550b823833739f5ef53ce Mon Sep 17 00:00:00 2001 From: Zoomer <87513793+ethzoomer@users.noreply.github.com> Date: Tue, 16 Jan 2024 09:47:32 -0600 Subject: [PATCH 9/9] SOL-271: fix Sugar tests (#42) * test: fix VeSugar + RelaySugar tests * ci: fix cython pyyaml conflict --- Dockerfile | 3 ++- env.example | 6 +++--- tests/test_relay_sugar.py | 7 ++++--- tests/test_ve_sugar.py | 26 ++++---------------------- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9ab15ca..0343570 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,8 @@ RUN npm install -g ganache COPY . /app WORKDIR /app -RUN pip install --no-cache-dir -r requirements.txt +RUN pip install "cython<3.0.0" && pip install --no-build-isolation pyyaml==5.4.1 +RUN pip install -r requirements.txt RUN brownie networks modify optimism-test host=https://goerli.optimism.io RUN brownie networks modify optimism-main host=https://optimism-mainnet.wallet.coinbase.com diff --git a/env.example b/env.example index cba4d85..c2451eb 100644 --- a/env.example +++ b/env.example @@ -3,6 +3,6 @@ REGISTRY_ADDRESS=0xF4c67CdEAaB8360370F41514d06e32CcD8aA1d7B DIST_ADDRESS=0x9D4736EC60715e71aFe72973f7885DCBC21EA99b CONVERTOR_ADDRESS=0x585Af0b397AC42dbeF7f18395426BF878634f18D LP_SUGAR_ADDRESS=0x6eDCAb198EAdDBDA3865f813A83F6bC9012F16e9 -VE_SUGAR_ADDRESS=0x0eCc2593E3a6A9be3628940Fa4D928CC257B588B -RELAY_SUGAR_ADDRESS=0x7f609cf1a99318652859aED5B00C7F5F187E0077 -RELAY_REGISTRY_ADDRESS=0xBC3dc970f891ffdd3049FA3a649985CC6626d486 +VE_SUGAR_ADDRESS=0x37403dBd6f1b583ea244F7956fF9e37EF45c63eB +RELAY_SUGAR_ADDRESS=0x062185EEF2726EFc11880856CD356FA2Ac2B38Ff +RELAY_REGISTRY_ADDRESS=0xe9F00f2e61CB0c6fb00A2e457546aCbF0fC303C2 diff --git a/tests/test_relay_sugar.py b/tests/test_relay_sugar.py index b7479e0..38815c8 100644 --- a/tests/test_relay_sugar.py +++ b/tests/test_relay_sugar.py @@ -23,8 +23,9 @@ def RelayStruct(sugar_contract): def test_initial_state(sugar_contract): assert sugar_contract.voter() == os.getenv('VOTER_ADDRESS') - assert sugar_contract.registry() == \ - os.getenv('RELAY_REGISTRY_ADDRESS') + assert sugar_contract.registries(0) == os.getenv('RELAY_REGISTRY_ADDRESS') + assert sugar_contract.ve() is not None + assert sugar_contract.token() is not None def test_all(sugar_contract, RelayStruct): @@ -33,4 +34,4 @@ def test_all(sugar_contract, RelayStruct): sugar_contract.all(ADDRESS_ZERO) )) - assert relays is not None + assert len(relays) > 5 diff --git a/tests/test_ve_sugar.py b/tests/test_ve_sugar.py index 301a9e3..77fc40d 100644 --- a/tests/test_ve_sugar.py +++ b/tests/test_ve_sugar.py @@ -12,14 +12,6 @@ def sugar_contract(VeSugar, accounts): yield VeSugar.at(os.getenv('VE_SUGAR_ADDRESS')) -@pytest.fixture -def RewardStruct(sugar_contract): - method_output = sugar_contract.rewards.abi['outputs'][0] - members = list(map(lambda _e: _e['name'], method_output['components'])) - - yield namedtuple('RewardStruct', members) - - @pytest.fixture def VeNFTStruct(sugar_contract): method_output = sugar_contract.byId.abi['outputs'][0] @@ -30,8 +22,8 @@ def VeNFTStruct(sugar_contract): def test_initial_state(sugar_contract): assert sugar_contract.voter() == os.getenv('VOTER_ADDRESS') - assert sugar_contract.rewards_distributor() == \ - os.getenv('REWARDS_DIST_ADDRESS') + assert sugar_contract.dist() == \ + os.getenv('DIST_ADDRESS') assert sugar_contract.ve() is not None @@ -39,11 +31,10 @@ def test_byId(sugar_contract, VeNFTStruct): venft = VeNFTStruct(*sugar_contract.byId(1)) assert venft is not None - assert len(venft) == 11 + assert len(venft) == 13 assert venft.id is not None assert len(venft.votes) > 0 assert venft.voted_at > 0 - assert venft.attachments > 0 def test_byAccount(sugar_contract, VeNFTStruct): @@ -54,7 +45,7 @@ def test_byAccount(sugar_contract, VeNFTStruct): )) assert venft is not None - assert len(venft) == 11 + assert len(venft) == 13 assert venft.account == acc_venft[0].account @@ -92,12 +83,3 @@ def test_all_limit_offset(sugar_contract, VeNFTStruct): assert venft1.id == second_venft.id assert venft1.account == second_venft.account - - -def test_rewards(sugar_contract, RewardStruct): - rewards = list(map( - lambda _r: RewardStruct(*_r), - sugar_contract.rewards(100, 0, 1) - )) - - assert len(rewards) > 0