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

Cleanups #89

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 13 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ name: CI
on: [push, pull_request]

jobs:
ci:
chains_matrix:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
chain: [optimism, base]
experimental: [false]
include:
- chain: mode
experimental: true
- chain: bob
experimental: true

steps:
- uses: actions/checkout@master

- name: Builds the Docker image
run: docker build ./ -t velodrome/sugar

- 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 --network=mode-main'
- name: Runs code QA and tests
run: docker run --rm --env-file=env.${{ matrix.chain }} -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test --network=${{ matrix.chain }}-main'
1 change: 1 addition & 0 deletions brownie-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ networks:
fork: https://optimism-mainnet.wallet.coinbase.com
evm_version: shanghai
compiler:
evm_version: cancun
vyper:
version: 0.4.0
33 changes: 16 additions & 17 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, lp_shared.MA
break

factory: lp_shared.IPoolFactory = lp_shared.IPoolFactory(factories[index])
if lp_shared._is_root_factory(factory.address):
if lp_shared._is_root_placeholder_factory(factory.address):
continue

nfpm: address = lp_shared._fetch_nfpm(factory.address)
Expand Down Expand Up @@ -570,8 +570,7 @@ def _positions(

factory: lp_shared.IPoolFactory = lp_shared.IPoolFactory(_factories[index])

# Skip root placeholder pools...
if lp_shared._is_root_factory(factory.address):
if lp_shared._is_root_placeholder_factory(factory.address):
continue

pools_count: uint256 = staticcall factory.allPoolsLength()
Expand Down Expand Up @@ -766,7 +765,7 @@ def positionsUnstakedConcentrated(
if nfpm.address == empty(address):
continue

if lp_shared._is_root_factory(factory.address):
if lp_shared._is_root_placeholder_factory(factory.address):
continue

# Handled in `positions()`
Expand Down Expand Up @@ -1038,7 +1037,7 @@ def _safe_balance_of(_token: address, _address: address) -> uint256:
"""
response: Bytes[32] = raw_call(
_token,
concat(method_id("balanceOf(address)"), convert(_address, bytes32)),
abi_encode(_address, method_id=method_id("balanceOf(address)")),
max_outsize=32,
gas=100000,
is_delegate_call=False,
Expand All @@ -1047,7 +1046,7 @@ def _safe_balance_of(_token: address, _address: address) -> uint256:
)[1]

if len(response) > 0:
return (convert(response, uint256))
return (abi_decode(response, uint256))

return 0

Expand All @@ -1059,20 +1058,20 @@ def _safe_decimals(_token: address) -> uint8:
@param _token The token to call
@param _address The address to get the balanceOf
"""
success: bool = False
response: Bytes[32] = b""
success, response = raw_call(
response = raw_call(
_token,
method_id("decimals()"),
max_outsize=32,
gas=50000,
is_delegate_call=False,
is_static_call=True,
revert_on_failure=False
)
)[1]

if success:
return (convert(response, uint8))
# Check response as revert_on_failure is set to False
if len(response) > 0:
return (abi_decode(response, uint8))

return 18

Expand All @@ -1083,21 +1082,21 @@ def _safe_symbol(_token: address) -> String[100]:
@notice Returns the `ERC20.symbol()` result safely
@param _token The token to call
"""
success: bool = False
# >=192 input size is required by Vyper's _abi_decode()
response: Bytes[192] = b""
success, response = raw_call(
response = raw_call(
_token,
method_id("symbol()"),
max_outsize=192,
gas=50000,
is_delegate_call=False,
is_static_call=True,
revert_on_failure=False
)
)[1]

if success:
return _abi_decode(response, String[100])
# Check response as revert_on_failure is set to False
if len(response) > 0:
return abi_decode(response, String[100])

return "-NA-"

Expand All @@ -1114,7 +1113,7 @@ def _has_userPositions(_nfpm: address) -> bool:
_nfpm,
abi_encode(
# We just need valid addresses, please ignore the values
_nfpm, _nfpm, method_id("userPositions(address,address)"),
_nfpm, _nfpm, method_id=method_id("userPositions(address,address)"),
),
max_outsize=32,
is_delegate_call=False,
Expand Down
15 changes: 8 additions & 7 deletions contracts/modules/lp_shared.vy
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _pools(_limit: uint256, _offset: uint256)\
break

factory: IPoolFactory = IPoolFactory(factories[index])
if self._is_root_factory(factory.address):
if self._is_root_placeholder_factory(factory.address):
continue

pools_count: uint256 = staticcall factory.allPoolsLength()
Expand Down Expand Up @@ -99,21 +99,22 @@ def _pools(_limit: uint256, _offset: uint256)\

@internal
@view
def _is_root_factory(_factory: address) -> bool:
def _is_root_placeholder_factory(_factory: address) -> bool:
"""
@notice Returns true if the factory is a root pool factory and false if it is a leaf pool factory.
@notice Checks if the factory is for root placeholder pools
@param _factory The factory address
@return bool
"""
success: bool = raw_call(
response: Bytes[32] = raw_call(
_factory,
method_id("bridge()"),
max_outsize=32,
is_delegate_call=False,
is_static_call=True,
revert_on_failure=False
)[0]
)[1]

return success
return len(response) > 0

@internal
@view
Expand All @@ -135,6 +136,6 @@ def _fetch_nfpm(_factory: address) -> address:
)[1]

if len(response) > 0:
return convert(response, address)
return abi_decode(response, address)

return empty(address)
20 changes: 20 additions & 0 deletions env.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CHAIN_ID=8453
CONTRACT='lp'

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

TEST_FACTORY_ADDRESS_8453=0x5e7BB104d84c7CB9B682AaC2F3d509f5F406809A
TEST_ADDRESS_8453=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac
TEST_ALM_ADDRESS_8453=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac

LP_SUGAR_ADDRESS_8453=0xC9611f3191073EE063a6AFDc6b58b660e8C90afE
REWARDS_SUGAR_ADDRESS_8453=0xEbfD2d983340e0bA6109a387928ADAe9FEE47D4b
VE_SUGAR_ADDRESS_8453=0x4c5d3925fe65DFeB5A079485136e4De09cb664A5
RELAY_SUGAR_ADDRESS_8453=0x8932B5FE23C07Df06533F8f09E43e7cca6a24143
17 changes: 17 additions & 0 deletions env.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CHAIN_ID=60808
CONTRACT='lp'

VOTER_60808=0x0000000000000000000000000000000000000000
REGISTRY_60808=0x0000000000000000000000000000000000000000
CONVERTOR_60808=0x1111111111111111111111111111111111111111
SLIPSTREAM_HELPER_60808=0x0000000000000000000000000000000000000000
ALM_FACTORY_60808=0x0000000000000000000000000000000000000000
FACTORIES_60808=
DIST_60808=0x0000000000000000000000000000000000000000
RELAY_REGISTRY_ADDRESSES_60808=
GOVERNOR_60808=0x1111111111111111111111111111111111111111

LP_SUGAR_ADDRESS_60808=
REWARDS_SUGAR_ADDRESS_60808=
VE_SUGAR_ADDRESS_60808=
RELAY_SUGAR_ADDRESS_60808=
72 changes: 0 additions & 72 deletions env.example

This file was deleted.

17 changes: 17 additions & 0 deletions env.mode
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CHAIN_ID=34443
CONTRACT='lp'

VOTER_34443=0x0000000000000000000000000000000000000000
REGISTRY_34443=0x6B290762F9F9155637F0Bb6B7A5B1cEb394cceD8
CONVERTOR_34443=0x1111111111111111111111111111111111111111
SLIPSTREAM_HELPER_34443=0x0000000000000000000000000000000000000000
ALM_FACTORY_34443=0x0000000000000000000000000000000000000000
FACTORIES_34443=
DIST_34443=0x0000000000000000000000000000000000000000
RELAY_REGISTRY_ADDRESSES_34443=
GOVERNOR_34443=0x1111111111111111111111111111111111111111

LP_SUGAR_ADDRESS_34443=
REWARDS_SUGAR_ADDRESS_34443=
VE_SUGAR_ADDRESS_34443=
RELAY_SUGAR_ADDRESS_34443=
20 changes: 20 additions & 0 deletions env.optimism
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CHAIN_ID=10
CONTRACT='lp'

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

TEST_FACTORY_ADDRESS_10=0xCc0bDDB707055e04e497aB22a59c2aF4391cd12F
TEST_ADDRESS_10=0x892ff98a46e5bd141e2d12618f4b2fe6284debac
TEST_ALM_ADDRESS_10=0x892ff98a46e5bd141e2d12618f4b2fe6284debac

LP_SUGAR_ADDRESS_10=0x5b29e481f663ec2857487567E1383CBdE83fa2f1
REWARDS_SUGAR_ADDRESS_10=0xc4e64A0B93713a9be19B1ccdA408F76923202B73
VE_SUGAR_ADDRESS_10=0x94f913362b232e31daB49a1aFB775cfd25DaA6a1
RELAY_SUGAR_ADDRESS_10=0xb8307e5842B9aeE75C704183F0355076aa74b4e2
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ docker build ./ -t velodrome/sugar

Next start the container with existing environment variables:
```sh
docker run --env-file=env.example --rm -v $(pwd):/app -w /app -it velodrome/sugar sh
docker run --env-file=env.{{chain}} --rm -v $(pwd):/app -w /app -it velodrome/sugar sh
```
The environment has Brownie and Vyper already installed.

To run the tests inside the container, use:
```sh
brownie test --network=optimism-test
brownie test --network={{chain}}-test
```

## Why the contracts are not verified?
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
eth-brownie @ git+https://github.com/velodrome-finance/[email protected]
vyper==0.4.0
flake8
titanoboa
4 changes: 3 additions & 1 deletion scripts/deploy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# SPDX-License-Identifier: BUSL-1.1
import os

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


def main():
Expand Down
Loading
Loading