Skip to content

Commit

Permalink
RewardsSugar: deploy script, docs, tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
stas committed Oct 26, 2024
1 parent 3145888 commit fa8681b
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 21 deletions.
4 changes: 4 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ TEST_ADDRESS_10=0xEeE7FB850D28f5cabd5f1EDF540646b5bEA17CE5
TEST_ALM_ADDRESS_10=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac

LP_SUGAR_ADDRESS_10=0x35F233BE126d7D08aB2D65E647E8c379b1FACF39
REWARDS_SUGAR_ADDRESS_10=
VE_SUGAR_ADDRESS_10=0x94f913362b232e31daB49a1aFB775cfd25DaA6a1
RELAY_SUGAR_ADDRESS_10=0xb8307e5842B9aeE75C704183F0355076aa74b4e2

Expand All @@ -34,6 +35,7 @@ TEST_ADDRESS_8453=0xEeE7FB850D28f5cabd5f1EDF540646b5bEA17CE5
TEST_ALM_ADDRESS_8453=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac

LP_SUGAR_ADDRESS_8453=0x63a73829C74e936C1D2EEbE64164694f16700138
REWARDS_SUGAR_ADDRESS_8453=
VE_SUGAR_ADDRESS_8453=0x4c5d3925fe65DFeB5A079485136e4De09cb664A5
RELAY_SUGAR_ADDRESS_8453=0x8932B5FE23C07Df06533F8f09E43e7cca6a24143

Expand All @@ -49,6 +51,7 @@ RELAY_REGISTRY_ADDRESSES_34443=
GOVERNOR_34443=0x1111111111111111111111111111111111111111

LP_SUGAR_ADDRESS_34443=
REWARDS_SUGAR_ADDRESS_34443=
VE_SUGAR_ADDRESS_34443=
RELAY_SUGAR_ADDRESS_34443=

Expand All @@ -64,5 +67,6 @@ RELAY_REGISTRY_ADDRESSES_60808=
GOVERNOR_60808=0x1111111111111111111111111111111111111111

LP_SUGAR_ADDRESS_60808=
REWARDS_SUGAR_ADDRESS_60808=
VE_SUGAR_ADDRESS_60808=
RELAY_SUGAR_ADDRESS_60808=
35 changes: 20 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ The returned data is a struct of type `Position` with the following values:

---

The pools token list (compiled from all the pools `token0`/`token1`) uses the type
`Token` with the following values:

* `token_address` - the token address
* `symbol` - the token symbol
* `decimals` - the token decimals
* `account_balance` - the provided account/wallet balance
* `listed` - indicates if the token was listed for gauge voting rewards

To fetch the token list this method is available:

* `tokens(_limit: uint256, _offset: uint256, _account: address, _oracle: address, _oracle_connectors: address[]) -> Token[]`

### veNFT and Pool Rewards Data

> [!NOTE]
> `RewardsSugar.vy` is deployed on:
> Optimism - ``
> Base - ``
For the pool epoch data we return, starting with most recent epoch, a struct of
type `LpEpoch` with the following values:

Expand All @@ -128,21 +148,6 @@ To fetch a list of latest epochs data for a every pool, this method is available

---

The pools token list (compiled from all the pools `token0`/`token1`) uses the type
`Token` with the following values:

* `token_address` - the token address
* `symbol` - the token symbol
* `decimals` - the token decimals
* `account_balance` - the provided account/wallet balance
* `listed` - indicates if the token was listed for gauge voting rewards

To fetch the token list this method is available:

* `tokens(_limit: uint256, _offset: uint256, _account: address, _oracle: address, _oracle_connectors: address[]) -> Token[]`

---

For the rewards, we return a struct of type `Reward` with the following
values:

Expand Down
21 changes: 15 additions & 6 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# SPDX-License-Identifier: BUSL-1.1
import os

from brownie import accounts, VeSugar, LpSugar, RelaySugar, FactoryRegistry
from brownie import accounts, VeSugar, LpSugar, RelaySugar, FactoryRegistry, RewardsSugar


def main():
contract_name = str(os.getenv('CONTRACT')).lower()
chain_id = os.getenv('CHAIN_ID')
account = None

if os.getenv('PROD'):
account = accounts.load('sugar')
else:
elif len(accounts) > 0:
account = accounts[0]

if 'lp' in contract_name:
Expand All @@ -23,26 +24,34 @@ def main():
{'from': account}
)

if 've' in contract_name:
elif 'rewards' in contract_name:
RewardsSugar.deploy(
os.getenv(f'VOTER_{chain_id}'),
os.getenv(f'REGISTRY_{chain_id}'),
os.getenv(f'CONVERTOR_{chain_id}'),
{'from': account}
)

elif 've' in contract_name:
VeSugar.deploy(
os.getenv(f'VOTER_{chain_id}'),
os.getenv(f'DIST_{chain_id}'),
os.getenv(f'GOVERNOR_{chain_id}'),
{'from': account}
)

if 'relay' in contract_name:
elif 'relay' in contract_name:
RelaySugar.deploy(
str(os.getenv(f'RELAY_REGISTRY_ADDRESSES_{chain_id}')).split(','),
os.getenv(f'VOTER_{chain_id}'),
{'from': account}
)

if 'registry' in contract_name:
elif 'registry' in contract_name:
FactoryRegistry.deploy(
str(os.getenv(f'FACTORIES_{chain_id}')).split(','),
{'from': account}
)

if 've' not in contract_name and 'lp' not in contract_name:
else:
print('Set the `CONTRACT` environment variable to deploy a contract.')
96 changes: 96 additions & 0 deletions tests/base/test_rewards_sugar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# SPDX-License-Identifier: BUSL-1.1
import os
import pytest
from collections import namedtuple

from web3.constants import ADDRESS_ZERO


@pytest.fixture
def sugar_contract(RewardsSugar, accounts):
# Since we depend on the rest of the protocol,
# we just point to an existing deployment
yield LpSugar.at(os.getenv('REWARDS_SUGAR_ADDRESS_8453'))


@pytest.fixture
def LpEpochStruct(sugar_contract):
method_output = sugar_contract.epochsByAddress.abi['outputs'][0]
members = list(map(lambda _e: _e['name'], method_output['components']))

yield namedtuple('LpEpochStruct', members)


@pytest.fixture
def LpEpochBribeStruct(sugar_contract):
lp_epoch_comp = sugar_contract.epochsByAddress.abi['outputs'][0]
pe_bribe_comp = lp_epoch_comp['components'][4]
members = list(map(lambda _e: _e['name'], pe_bribe_comp['components']))

yield namedtuple('LpEpochBribeStruct', members)


def test_initial_state(sugar_contract):
assert sugar_contract.voter() == os.getenv('VOTER_8453')
assert sugar_contract.registry() == os.getenv('REGISTRY_8453')


def test_epochsByAddress_limit_offset(
sugar_contract,
LpStruct,
LpEpochStruct,
LpEpochBribeStruct
):
first_lp = LpStruct(*sugar_contract.byIndex(0))
lp_epochs = list(map(
lambda _p: LpEpochStruct(*_p),
sugar_contract.epochsByAddress(20, 3, first_lp.lp)
))

assert lp_epochs is not None
assert len(lp_epochs) > 10

epoch = lp_epochs[1]
epoch_bribes = list(map(
lambda _b: LpEpochBribeStruct(*_b),
epoch.bribes
))
epoch_fees = list(map(
lambda _f: LpEpochBribeStruct(*_f),
epoch.fees
))

assert epoch.lp == first_lp.lp
assert epoch.votes > 0
assert epoch.emissions > 0

if len(epoch_bribes) > 0:
assert epoch_bribes[0].amount > 0

if len(epoch_fees) > 0:
assert epoch_fees[0].amount > 0


def test_epochsLatest_limit_offset(
sugar_contract,
LpStruct,
LpEpochStruct
):
second_lp = LpStruct(*sugar_contract.byIndex(1))
lp_epoch = list(map(
lambda _p: LpEpochStruct(*_p),
sugar_contract.epochsByAddress(1, 0, second_lp.lp)
))
latest_epoch = list(map(
lambda _p: LpEpochStruct(*_p),
sugar_contract.epochsLatest(1, 1)
))

assert lp_epoch is not None
assert len(latest_epoch) == 1

pepoch = LpEpochStruct(*lp_epoch[0])
lepoch = LpEpochStruct(*latest_epoch[0])

assert lepoch.lp == pepoch.lp
assert lepoch.ts == pepoch.ts

0 comments on commit fa8681b

Please sign in to comment.