Skip to content

Commit

Permalink
refactor: include base/mode/bob
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrovalido committed Oct 6, 2024
1 parent 1f377f8 commit 2e26ccf
Show file tree
Hide file tree
Showing 9 changed files with 452 additions and 43 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ jobs:
- name: Builds the Docker image
run: docker build ./ -t velodrome/sugar

- name: Runs code QA and tests
run: docker run --rm --env-file=env.example -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test --network=optimism-main'
- name: Runs code QA and tests for optimism
run: docker run --rm --env-file=env.example -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test tests/optimism/**.py --network=optimism-main'
- name: Runs code QA and tests for base
run: docker run --rm --env-file=env.example -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test tests/base/**.py --network=base-main'
- name: Runs code QA and sugar factory registry tests
run: docker run --rm --env-file=env.example -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test tests/test_factory_registry.py'
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ RUN pip install -r requirements.txt

RUN brownie networks modify optimism-test host=https://sepolia.optimism.io
RUN brownie networks modify optimism-main host=https://optimism-mainnet.wallet.coinbase.com

RUN brownie networks modify base-main host=https://mainnet.base.org

RUN brownie networks add Bob bob-main host=https://rpc.gobob.xyz/ chainid=60808
RUN brownie networks add Mode mode-main host=https://mainnet.mode.network chainid=34443
77 changes: 47 additions & 30 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,44 +1,61 @@
VOTER_ADDRESS=0x41C914ee0c7E1A5edCD0295623e6dC557B5aBf3C
DIST_ADDRESS=0x9D4736EC60715e71aFe72973f7885DCBC21EA99b
GOVERNOR_ADDRESS=0x1F82e10D58aEf03DeA2e478029fB0387A1cbE989
RELAY_REGISTRY_ADDRESSES=0xe9F00f2e61CB0c6fb00A2e457546aCbF0fC303C2,0x6b1253B116B5919932399295C75116d33F8EfF96

LP_SUGAR_ADDRESS=0x0937DA94887472239Ada5483c6DBd2904FfD4ACF
VE_SUGAR_ADDRESS=0x94f913362b232e31daB49a1aFB775cfd25DaA6a1
RELAY_SUGAR_ADDRESS=0xb8307e5842B9aeE75C704183F0355076aa74b4e2

# For testing purposes
TEST_FACTORY_ADDRESS=0xCc0bDDB707055e04e497aB22a59c2aF4391cd12F
TEST_ADDRESS=0xEeE7FB850D28f5cabd5f1EDF540646b5bEA17CE5
TEST_ALM_ADDRESS=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac

CHAIN=optimism
CHAIN_ID=10
CONTRACT='lp'

#OPTIMISM
OPTIMISM_REGISTRY=0xF4c67CdEAaB8360370F41514d06e32CcD8aA1d7B
OPTIMISM_VOTER=0x41C914ee0c7E1A5edCD0295623e6dC557B5aBf3C
OPTIMISM_CONVERTOR=0x585Af0b397AC42dbeF7f18395426BF878634f18D
OPTIMISM_SLIPSTREAM_HELPER=0x5Bd7E2221C2d59c99e6A9Cd18D80A5F4257D0f32
OPTIMISM_ALM_FACTORY=0xeD8b81E3fF6c54951621715F5992CA52007D88bA
VOTER_10=0x41C914ee0c7E1A5edCD0295623e6dC557B5aBf3C
REGISTRY_10=0xF4c67CdEAaB8360370F41514d06e32CcD8aA1d7B
CONVERTOR_10=0x585Af0b397AC42dbeF7f18395426BF878634f18D
SLIPSTREAM_HELPER_10=0x5Bd7E2221C2d59c99e6A9Cd18D80A5F4257D0f32
ALM_FACTORY_10=0xeD8b81E3fF6c54951621715F5992CA52007D88bA
DIST_10=0x9D4736EC60715e71aFe72973f7885DCBC21EA99b
RELAY_REGISTRY_ADDRESSES_10=0xe9F00f2e61CB0c6fb00A2e457546aCbF0fC303C2,0x6b1253B116B5919932399295C75116d33F8EfF96
GOVERNOR_10=0x1F82e10D58aEf03DeA2e478029fB0387A1cbE989

LP_SUGAR_ADDRESS_10=0x0937DA94887472239Ada5483c6DBd2904FfD4ACF
VE_SUGAR_ADDRESS_10=0x94f913362b232e31daB49a1aFB775cfd25DaA6a1
RELAY_SUGAR_ADDRESS_10=0xb8307e5842B9aeE75C704183F0355076aa74b4e2

#BASE
BASE_REGISTRY=0x5C3F18F06CC09CA1910767A34a20F771039E37C0
BASE_VOTER=0x16613524e02ad97eDfeF371bC883F2F5d6C480A5
BASE_CONVERTOR=0x1111111111111111111111111111111111111111
BASE_SLIPSTREAM_HELPER=0x6d2D739bf37dFd93D804523c2dfA948EAf32f8E1
BASE_ALM_FACTORY=0x5B1b1aaC71bDca9Ed1dCb2AA357f678584db4029
VOTER_8453=0x16613524e02ad97eDfeF371bC883F2F5d6C480A5
REGISTRY_8453=0x5C3F18F06CC09CA1910767A34a20F771039E37C0
CONVERTOR_8453=0x1111111111111111111111111111111111111111
SLIPSTREAM_HELPER_8453=0x6d2D739bf37dFd93D804523c2dfA948EAf32f8E1
ALM_FACTORY_8453=0x5B1b1aaC71bDca9Ed1dCb2AA357f678584db4029
DIST_8453=0x227f65131A261548b057215bB1D5Ab2997964C7d
RELAY_REGISTRY_ADDRESSES_8453=0x05e41604B9463e2224227053980dfF3f57fb6dB5,0xD308aBCe663302d3b86b36d332CEFd8A4F62C5Ed
GOVERNOR_8453=0x94C012A23A8A65A6f40608dA30534a46a433F410

LP_SUGAR_ADDRESS_8453=0x51f290CCCD6a54Af00b38edDd59212dE068B8A4b
VE_SUGAR_ADDRESS_8453=0x4c5d3925fe65DFeB5A079485136e4De09cb664A5
RELAY_SUGAR_ADDRESS_8453=0x8932B5FE23C07Df06533F8f09E43e7cca6a24143

#MODE
MODE_REGISTRY=0x0000000000000000000000000000000000000000
MODE_VOTER=0x0000000000000000000000000000000000000000
MODE_CONVERTOR=0x1111111111111111111111111111111111111111
MODE_SLIPSTREAM_HELPER=0x0000000000000000000000000000000000000000
MODE_ALM_FACTORY=0x0000000000000000000000000000000000000000
VOTER_34443=0x0000000000000000000000000000000000000000
REGISTRY_34443=0x7e9f5D93C590c45A54faC774baf9AdD6CA94a295
CONVERTOR_34443=0x1111111111111111111111111111111111111111
SLIPSTREAM_HELPER_34443=0x0000000000000000000000000000000000000000
ALM_FACTORY_34443=0x0000000000000000000000000000000000000000
DIST_34443=0x0000000000000000000000000000000000000000
RELAY_REGISTRY_ADDRESSES_34443=

LP_SUGAR_ADDRESS_34443=
VE_SUGAR_ADDRESS_34443=
RELAY_SUGAR_ADDRESS_34443=

#BOB
BOB_REGISTRY=0x0000000000000000000000000000000000000000
BOB_VOTER=0x0000000000000000000000000000000000000000
BOB_CONVERTOR=0x1111111111111111111111111111111111111111
BOB_SLIPSTREAM_HELPER=0x0000000000000000000000000000000000000000
BOB_ALM_FACTORY=0x0000000000000000000000000000000000000000
VOTER_60808=0x0000000000000000000000000000000000000000
REGISTRY_60808=0x0000000000000000000000000000000000000000
CONVERTOR_60808=0x1111111111111111111111111111111111111111
SLIPSTREAM_HELPER_60808=0x0000000000000000000000000000000000000000
ALM_FACTORY_60808=0x0000000000000000000000000000000000000000
DIST_60808=0x0000000000000000000000000000000000000000
RELAY_REGISTRY_ADDRESSES_60808=

LP_SUGAR_ADDRESS_60808=
VE_SUGAR_ADDRESS_60808=
RELAY_SUGAR_ADDRESS_60808=
260 changes: 260 additions & 0 deletions tests/base/test_lp_sugar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
# 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(LpSugar, accounts):
# Since we depend on the rest of the protocol,
# we just point to an existing deployment
yield LpSugar.at(os.getenv('LP_SUGAR_ADDRESS_8453'))


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

yield namedtuple('TokenStruct', members)


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

yield namedtuple('LpStruct', members)


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

yield namedtuple('SwapLpStruct', members)


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

yield namedtuple('PositionStruct', members)


@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_byIndex(sugar_contract, LpStruct):
lp = LpStruct(*sugar_contract.byIndex(0))

assert lp is not None
assert len(lp) == 27
assert lp.lp is not None
assert lp.gauge != ADDRESS_ZERO


def test_forSwaps(sugar_contract, SwapLpStruct, LpStruct):
first_lp = LpStruct(*sugar_contract.byIndex(0))
second_lp = LpStruct(*sugar_contract.byIndex(1))
swap_lps = list(map(
lambda _p: SwapLpStruct(*_p),
sugar_contract.forSwaps(10, 1)
))

assert swap_lps is not None
assert len(swap_lps) > 1

lp1, lp2 = swap_lps[0:2]

assert lp1.lp == first_lp.lp

assert lp2.lp == second_lp.lp


def test_tokens(sugar_contract, TokenStruct, LpStruct):
first_lp = LpStruct(*sugar_contract.byIndex(0))
second_lp = LpStruct(*sugar_contract.byIndex(1))
tokens = list(map(
lambda _p: TokenStruct(*_p),
sugar_contract.tokens(10, 0, ADDRESS_ZERO, [])
))

assert tokens is not None
assert len(tokens) > 1

token0, token1, token2 = tokens[0: 3]

assert token0.token_address == first_lp.token0
assert token0.symbol is not None
assert token0.decimals > 0

assert token1.token_address == first_lp.token1
assert token2.token_address == second_lp.token0


def test_all(sugar_contract, LpStruct):
first_lp = LpStruct(*sugar_contract.byIndex(0))
second_lp = LpStruct(*sugar_contract.byIndex(1))
lps = list(map(
lambda _p: LpStruct(*_p),
sugar_contract.all(10, 0)
))

assert lps is not None
assert len(lps) > 1

lp1, lp2 = lps[0:2]

assert lp1.lp == first_lp.lp
assert lp1.gauge == first_lp.gauge

assert lp2.lp == second_lp.lp
assert lp2.gauge == second_lp.gauge


def test_all_pagination(sugar_contract, LpStruct):
max_lps = sugar_contract.MAX_LPS()

for i in range(0, max_lps, max_lps):
lps = sugar_contract.all(max_lps, 0)

assert lps is not None
assert len(lps) > max_lps - 1


def test_all_limit_offset(sugar_contract, LpStruct):
second_lp = LpStruct(*sugar_contract.byIndex(1))
lps = list(map(
lambda _p: LpStruct(*_p),
sugar_contract.all(1, 1)
))

assert lps is not None
assert len(lps) == 1

lp1 = lps[0]

assert lp1.lp == second_lp.lp
assert lp1.lp == second_lp.lp


def test_positionsByFactory(sugar_contract, PositionStruct):
limit = 100
offset = 0
account = os.getenv('TEST_ADDRESS_8453')
factory = os.getenv('TEST_FACTORY_ADDRESS_8453')

positions = list(map(
lambda _p: PositionStruct(*_p),
sugar_contract.positionsByFactory(limit, offset, account, factory)
))

assert positions is not None
assert len(positions) > 0

pos = positions[0]

assert pos.id is not None
assert pos.lp is not None


def test_positions_ALM(sugar_contract, PositionStruct):
account = os.getenv('TEST_ALM_ADDRESS_8453')

positions = list(map(
lambda _p: PositionStruct(*_p),
sugar_contract.positions(1000, 0, account)
))

assert positions is not None
assert len(positions) > 0

pos = positions[0]

assert pos.id is not None
assert pos.lp is not None
assert pos.alm is not None


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
Loading

0 comments on commit 2e26ccf

Please sign in to comment.