From c2116727696ce0d2fad9c43be1b225b1a932868f Mon Sep 17 00:00:00 2001 From: 0xNineteen <0x39015319@gmail.com> Date: Mon, 12 Dec 2022 11:31:13 -0500 Subject: [PATCH] fix if staking rpc --- src/driftpy/clearing_house.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/driftpy/clearing_house.py b/src/driftpy/clearing_house.py index d184bd22..9c30c42f 100644 --- a/src/driftpy/clearing_house.py +++ b/src/driftpy/clearing_house.py @@ -207,7 +207,7 @@ async def get_remaining_accounts( if isinstance(user_id, int): user_id = [user_id] - assert len(user_id) == len(authority) + assert len(user_id) == len(authority) or len(user_id) == 0 accounts = [] for pk, id in zip(authority, user_id): @@ -250,9 +250,6 @@ async def track_spot_market(spot_market_index, is_writable): market_index = position.market_index await track_market(market_index, is_writable=True) - if writable_market_index is not None: - await track_market(writable_market_index, is_writable=True) - if include_spot_markets: for spot_market_balance in user_account.spot_positions: if not is_spot_position_available(spot_market_balance): @@ -267,12 +264,15 @@ async def track_spot_market(spot_market_index, is_writable): for i in readable_spot_market_index: await track_spot_market(i, is_writable=False) - if writable_spot_market_index is not None: - if isinstance(writable_spot_market_index, int): - writable_spot_market_index = [writable_spot_market_index] + if writable_market_index is not None: + await track_market(writable_market_index, is_writable=True) + + if writable_spot_market_index is not None and include_spot_markets: + if isinstance(writable_spot_market_index, int): + writable_spot_market_index = [writable_spot_market_index] - for i in writable_spot_market_index: - await track_spot_market(i, is_writable=True) + for i in writable_spot_market_index: + await track_spot_market(i, is_writable=True) remaining_accounts = [ *oracle_map.values(), @@ -1271,7 +1271,8 @@ async def get_request_remove_insurance_fund_stake_ix( amount: int, ): ra = await self.get_remaining_accounts( - writable_spot_market_index=spot_market_index + writable_spot_market_index=spot_market_index, + user_id=[] # dont need the user account (might not exist) ) return self.program.instruction["request_remove_insurance_fund_stake"]( @@ -1304,7 +1305,8 @@ async def remove_insurance_fund_stake(self, spot_market_index: int): async def get_remove_insurance_fund_stake_ix(self, spot_market_index: int): ra = await self.get_remaining_accounts( - writable_spot_market_index=spot_market_index + writable_spot_market_index=spot_market_index, + user_id=[] # dont need the user account (might not exist) ) return self.program.instruction["remove_insurance_fund_stake"](