PyPerp icon indicating copy to clipboard operation
PyPerp copied to clipboard

Add liquidity to a range using PyPerp

Open gabrielfior opened this issue 3 years ago • 2 comments

Is there a way to add liquidity to a range on the Perp Protocol (see screenshot) using the API?

add_liquidity_perp

gabrielfior avatar Jun 10 '22 14:06 gabrielfior

Hey Gabriel, that will be a good feature to be added to PyPerp!

Thank you for reaching out! I've not been maintaining this module for a long time. I'm currently in contact with Perpetual Protocol team to work out a deal to resume development of PyPerp.

Stay tuned!

Naveen V

On Fri, 10 Jun, 2022, 8:13 pm Gabriel Fior, @.***> wrote:

Is there a way to add liquidity to a range on the Perp Protocol (see screenshot) using the API?

[image: add_liquidity_perp] https://user-images.githubusercontent.com/4126235/173090359-f4a5519d-64a0-420c-be0f-2171feadce54.png

— Reply to this email directly, view it on GitHub https://github.com/DeveloperInProgress/PyPerp/issues/7, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJROTBVI6KNFQJY6YOEXEJLVONIBZANCNFSM5YN5LQFQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

guplersaxanoid avatar Jun 10 '22 20:06 guplersaxanoid

yeah, addliquidity already contained in clearHouse. But got some problem, I used like that

add_liquid_params = AddLiquidityParams(
      base_token= self._base_token,
      base = base,
      quote= quote,
      lower_tick=lower_tick,
      upper_tick=upper_tick,
      min_base= min_base,
      min_quote= min_quote,
      use_taker_balance=False,
      deadline=getDeadline(120)
    )

    receipt = self.clearing_house.add_liquidity(add_liquid_params,self.gas_params)

then got an exception like that

raise ValidationError(message)
web3.exceptions.ValidationError: 
Could not identify the intended function with name `addLiquidity`, positional argument(s) of type `(<class 'dict'>,)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `addLiquidity`: ['addLiquidity(tuple)']
Function invocation failed due to no matching argument types.

so I think it maybe need a tuple without a dict, so I modify the source code , add a to_tuple method:

def to_dict(self):
        return {
            'baseToken': self.base_token,
            'base': self.base,
            'quote': self.quote,
            'lowerTick': self.lower_tick,
            'upperTick': self.upper_tick,
            'minBase': self.min_base,
            'minQuote': self.min_quote,
            'useTakerBalance': self.use_taker_balance,
            'deadline': self.deadline
        }

    def to_tuple(self):
        rt_dict = self.to_dict
        return (rt_dict,)

and there is another exception like that :

Could not identify the intended function with name `addLiquidity`, positional argument(s) of type `(<class 'tuple'>,)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `addLiquidity`: ['addLiquidity(tuple)']
Function invocation failed due to no matching argument types.../abi/optimism/ClearingHouse.json

vvsuperman avatar Nov 04 '22 06:11 vvsuperman