Skip to content

Commit

Permalink
fix: forSwaps pool stable type (#44)
Browse files Browse the repository at this point in the history
* fix: forSwaps pool stable type

* getPool wrapper documentation, specify Brownie version

* correct is_stable calls

* Use try catch to determine if factory is CL factory

* Deployment address, move method_id inline
  • Loading branch information
ethzoomer authored Feb 7, 2024
1 parent d406ade commit 7233c2d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
50 changes: 27 additions & 23 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:

pools_count: uint256 = factory.allPoolsLength()

is_cl_factory: bool = self._is_cl_factory(factories[index])

for pindex in range(_offset, _offset + MAX_POOLS):
if len(pools) >= _limit or pindex >= pools_count:
break
Expand All @@ -309,22 +311,16 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:
reserve0: uint256 = 0
pool_fee: uint256 = 0

is_cl_pool: bool = False
is_stable: bool = factory.getPool(token0, token1, 0) == pool_addr

if not is_stable and factory.getPool(token0, token1, 1) != pool_addr:
is_cl_pool = True

if is_cl_pool:
if is_cl_factory:
type = pool.tickSpacing()
reserve0 = IERC20(token0).balanceOf(pool_addr)
pool_fee = convert(pool.fee(), uint256)

else:
if is_stable:
if factory.getPool(token0, token1, 1) == pool_addr:
type = 0
reserve0 = pool.reserve0()
pool_fee = factory.getFee(pool_addr, is_stable)
pool_fee = factory.getFee(pool_addr, (type == 0))

if reserve0 > 0:
pools.append(SwapLp({
Expand Down Expand Up @@ -422,14 +418,9 @@ def all(_limit: uint256, _offset: uint256, _account: address) \
factory: IPoolFactory = IPoolFactory(pools[index][0])
token0: address = pool.token0()
token1: address = pool.token1()
is_cl_factory: bool = self._is_cl_factory(pools[index][0])

is_cl_pool: bool = False
is_stable: bool = factory.getPool(token0, token1, 0) == pool.address

if not is_stable and factory.getPool(token0, token1, 1) != pool.address:
is_cl_pool = True

if is_cl_pool:
if is_cl_factory:
col.append(self._byDataCL(pools[index], token0, token1, _account))
else:
col.append(self._byData(pools[index], token0, token1, _account))
Expand All @@ -451,14 +442,9 @@ def byIndex(_index: uint256, _account: address) -> Lp:
factory: IPoolFactory = IPoolFactory(pools[_index][0])
token0: address = pool.token0()
token1: address = pool.token1()
is_cl_factory: bool = self._is_cl_factory(pools[_index][0])

is_cl_pool: bool = False
is_stable: bool = factory.getPool(token0, token1, 0) == pool.address

if not is_stable and factory.getPool(token0, token1, 1) != pool.address:
is_cl_pool = True

if is_cl_pool:
if is_cl_factory:
return self._byDataCL(pools[_index], token0, token1, _account)
return self._byData(pools[_index], token0, token1, _account)

Expand Down Expand Up @@ -968,3 +954,21 @@ def _poolRewards(_venft_id: uint256, _pool: address, _gauge: address) \
)

return col

@internal
@view
def _is_cl_factory(_factory: address) -> (bool):
"""
@notice Returns true if address is a CL factory
@param _factory The factory address
"""
response: Bytes[32] = raw_call(
_factory,
method_id("nft()"),
max_outsize=32,
is_delegate_call=False,
is_static_call=True,
revert_on_failure=False
)[1]

return len(response) > 0
2 changes: 1 addition & 1 deletion env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ VOTER_ADDRESS=0x41C914ee0c7E1A5edCD0295623e6dC557B5aBf3C
REGISTRY_ADDRESS=0xF4c67CdEAaB8360370F41514d06e32CcD8aA1d7B
DIST_ADDRESS=0x9D4736EC60715e71aFe72973f7885DCBC21EA99b
CONVERTOR_ADDRESS=0x585Af0b397AC42dbeF7f18395426BF878634f18D
LP_SUGAR_ADDRESS=0xE180829A166d1e0bec705C1eB25758F645C9E317
LP_SUGAR_ADDRESS=0x4F6C0ae189fB11937E092D71F5D5F4B343d06a8C
VE_SUGAR_ADDRESS=0x37403dBd6f1b583ea244F7956fF9e37EF45c63eB
RELAY_SUGAR_ADDRESS=0x062185EEF2726EFc11880856CD356FA2Ac2B38Ff
RELAY_REGISTRY_ADDRESS=0xe9F00f2e61CB0c6fb00A2e457546aCbF0fC303C2
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Below is the list of datasets we support.

### Liquidity Pools Data

`LpSugar.vy` is deployed at `0xE180829A166d1e0bec705C1eB25758F645C9E317`
`LpSugar.vy` is deployed at `0x90b18D906aa461a45229877469eD4c6A41c31Da6`

It allows fetching on-chain pools data.
The returned data/struct of type `Lp` values represent:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eth-brownie
eth-brownie==1.19.3
vyper
flake8
titanoboa

0 comments on commit 7233c2d

Please sign in to comment.