Skip to content

Commit

Permalink
Added non-fungible position manager.
Browse files Browse the repository at this point in the history
Removed some attributes to free up resources.
  • Loading branch information
stas committed Feb 27, 2024
1 parent b6d97c8 commit 25c1178
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
25 changes: 7 additions & 18 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ struct TickInfo:

struct Position:
id: uint256 # NFT ID on v3, 0 on v2
manager: address # NFT Position Manager on v3, router on v2
liquidity: uint256 # Liquidity amount on v3, amount of LP tokens on v2
staked: uint256 # liq amount staked on v3, amount of staked LP tokens on v2
unstaked_earned0: uint256 # unstaked token0 fees earned on both v2 and v3
Expand Down Expand Up @@ -94,7 +93,6 @@ struct Lp:
decimals: uint8
total_supply: uint256

nft: address
type: int24 # tick spacing on v3, 0/-1 for stable/volatile on v2
tick: int24 # current tick on v3, 0 on v2
price: uint160 # current price on v3, 0 on v2
Expand Down Expand Up @@ -184,7 +182,6 @@ interface IPool:
def balanceOf(_account: address) -> uint256: view
def poolFees() -> address: view
def gauge() -> address: view # fetches gauge from v3 pool
def nft() -> address: view # fetches nft address from v3 pool
def tickSpacing() -> int24: view # v3 tick spacing
def slot0() -> Slot: view # v3 slot data
def gaugeFees() -> GaugeFees: view # v3 gauge fees amounts
Expand All @@ -198,7 +195,6 @@ interface IVoter:
def gaugeToFees(_gauge_addr: address) -> address: view
def isAlive(_gauge_addr: address) -> bool: view
def isWhitelistedToken(_token_addr: address) -> bool: view
def v1Factory() -> address: view

interface IGauge:
def fees0() -> uint256: view
Expand All @@ -218,7 +214,7 @@ interface ICLGauge:
def feesVotingReward() -> address: view
def stakedContains(_account: address, _position_id: uint256) -> bool: view

interface INFTPositionManager:
interface INFPositionManager:
def positions(_position_id: uint256) -> PositionData: view
def tokenOfOwnerByIndex(_account: address, _index: uint256) -> uint256: view

Expand All @@ -234,23 +230,21 @@ interface IReward:
registry: public(IFactoryRegistry)
voter: public(IVoter)
convertor: public(address)
router: public(address)
v1_factory: public(address)
nfpm: public(INFPositionManager)
alm_registry: public(address) # todo: add ALM interface when ALM contracts are ready

# Methods

@external
def __init__(_voter: address, _registry: address, _convertor: address, \
_router: address, _alm_registry: address):
_nfpm: address, _alm_registry: address):
"""
@dev Sets up our external contract addresses
"""
self.voter = IVoter(_voter)
self.registry = IFactoryRegistry(_registry)
self.nfpm = INFPositionManager(_nfpm)
self.convertor = _convertor
self.router = _router
self.v1_factory = self.voter.v1Factory()
self.alm_registry = _alm_registry

@internal
Expand All @@ -261,7 +255,7 @@ def _pools(_limit: uint256, _offset: uint256)\
@param _limit The max amount of pools to return
@param _offset The amount of pools to skip (for optimization)
@notice Returns a compiled list of pool and its factory and gauge
@return Array of four addresses (factory, pool, gauge, cl_factory)
@return Array of four addresses (factory, pool, gauge, type value: 0/2/3)
"""
factories: DynArray[address, MAX_FACTORIES] = self.registry.poolFactories()
# TODO: Remove
Expand Down Expand Up @@ -562,7 +556,6 @@ def _byData(_data: address[4], _token0: address, _token1: address, \
positions.append(
Position({
id: 0,
manager: self.router,
liquidity: acc_balance,
staked: acc_staked,
unstaked_earned0: claimable0,
Expand All @@ -580,7 +573,6 @@ def _byData(_data: address[4], _token0: address, _token1: address, \
decimals: decimals,
total_supply: pool_total_supply,

nft: empty(address),
type: type,
tick: 0,
price: 0,
Expand Down Expand Up @@ -626,7 +618,6 @@ def _byDataCL(_data: address[4], _token0: address, _token1: address, \
"""
pool: IPool = IPool(_data[1])
gauge: ICLGauge = ICLGauge(_data[2])
nft: INFTPositionManager = INFTPositionManager(pool.nft())

gauge_fees: GaugeFees = pool.gaugeFees()
gauge_alive: bool = self.voter.isAlive(gauge.address)
Expand All @@ -651,12 +642,12 @@ def _byDataCL(_data: address[4], _token0: address, _token1: address, \
empty(DynArray[Position, MAX_POSITIONS])

for index in range(0, MAX_POSITIONS):
position_id: uint256 = nft.tokenOfOwnerByIndex(_account, index)
position_id: uint256 = self.nfpm.tokenOfOwnerByIndex(_account, index)

if position_id == 0:
break

position_data: PositionData = nft.positions(position_id)
position_data: PositionData = self.nfpm.positions(position_id)

emissions_earned: uint256 = 0
staked: bool = False
Expand All @@ -668,7 +659,6 @@ def _byDataCL(_data: address[4], _token0: address, _token1: address, \
positions.append(
Position({
id: position_id,
manager: pool.nft(),
liquidity: convert(position_data.liquidity, uint256),
staked: convert(staked, uint256),
unstaked_earned0: convert(position_data.tokensOwed0, uint256),
Expand All @@ -686,7 +676,6 @@ def _byDataCL(_data: address[4], _token0: address, _token1: address, \
decimals: 0,
total_supply: 0,

nft: nft.address,
type: tick_spacing,
tick: slot.tick,
price: price,
Expand Down
2 changes: 1 addition & 1 deletion env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ REGISTRY_ADDRESS=0xF4c67CdEAaB8360370F41514d06e32CcD8aA1d7B
DIST_ADDRESS=0x9D4736EC60715e71aFe72973f7885DCBC21EA99b
CONVERTOR_ADDRESS=0x585Af0b397AC42dbeF7f18395426BF878634f18D
RELAY_REGISTRY_ADDRESSES=0xe9F00f2e61CB0c6fb00A2e457546aCbF0fC303C2,0x6b1253B116B5919932399295C75116d33F8EfF96
ROUTER_ADDRESS=0xa062aE8A9c5e11aaA026fc2670B0D65cCc8B2858
NFPM_ADDRESS=0xFB9155b36F90Fb105598251A0B1A8653911FF8A5
ALM_REGISTRY_ADDRESS=0x0000000000000000000000000000000000000000
GOVERNOR_ADDRESS=0x0000000000000000000000000000000000000000
LP_SUGAR_ADDRESS=0x7Aa598dec373d63B16060cFDB6cC6ff7a2e86fAd
Expand Down
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ The returned data/struct of type `Lp` values represent:
* `symbol` - pool symbol
* `decimals` - pool decimals
* `total_supply` - pool tokens supply
* `nft` - NFT position manager on v3 pools, empty address on v2 pools
* `type` - tick spacing on v3 pools, 0/-1 for stable/volatile on v2 pools
* `tick` - current tick on v3 pools, 0 on v2 pools
* `price` - pool price on v3 pools, 0 on v2 pools
Expand All @@ -70,7 +69,6 @@ The returned data/struct of type `Lp` values represent:
* `alm_reserve1` - ALM vault token1 reserves on v3, 0 on v2
* `positions` - a list of account pool position data, it is a struct of type `Position` with the following values:
* `id` - NFT ID on v3 pools, 0 on v2 pools
* `manager` - NFT position manager on v3 pools, router on v2 pools
* `liquidity` - liquidity amount on v3, deposited LP tokens on v2
* `staked` - staked/unstaked liquidity amount on v3, amount of staked tokens on v2
* `unstaked_earned0` - unstaked token0 fees earned
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main():
os.getenv('VOTER_ADDRESS'),
os.getenv('REGISTRY_ADDRESS'),
os.getenv('CONVERTOR_ADDRESS'),
os.getenv('ROUTER_ADDRESS'),
os.getenv('NFPM_ADDRESS'),
os.getenv('ALM_REGISTRY_ADDRESS'),
{'from': account}
)
Expand Down

0 comments on commit 25c1178

Please sign in to comment.