Skip to content

Commit

Permalink
have settle lp naming match ts
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Nov 27, 2023
1 parent b9b596a commit 8a70fab
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/driftpy/drift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,39 +1172,38 @@ def get_remove_liquidity_ix(

async def settle_lp(
self,
settlee_authority: Pubkey,
settlee_user_account_public_key: Pubkey,
market_index: int,
sub_account_id: int = 0,
):
return await self.send_ixs(
[
await self.get_settle_lp_ix(
settlee_authority, market_index, sub_account_id
settlee_user_account_public_key, market_index
)
],
signers=[],
)

async def get_settle_lp_ix(
self, settlee_authority: Pubkey, market_index: int, sub_account_id: int = 0
self,
settlee_user_account_public_key: Pubkey,
market_index: int,
):
user_account_pubkey = get_user_account_public_key(
self.program_id, settlee_authority, sub_account_id
settlee_user_account = await self.program.account["User"].fetch(
settlee_user_account_public_key
)
user_account = await self.program.account["User"].fetch(user_account_pubkey)

remaining_accounts = self.get_remaining_accounts(
writable_perp_market_indexes=[market_index], user_accounts=[user_account]
writable_perp_market_indexes=[market_index],
user_accounts=[settlee_user_account],
)

return self.program.instruction["settle_lp"](
market_index,
ctx=Context(
accounts={
"state": self.get_state_public_key(),
"user": get_user_account_public_key(
self.program_id, settlee_authority, sub_account_id
),
"user": settlee_user_account_public_key,
},
remaining_accounts=remaining_accounts,
),
Expand Down Expand Up @@ -1446,24 +1445,26 @@ async def get_liquidate_perp_pnl_for_deposit_ix(

async def settle_pnl(
self,
user_public_key: Pubkey,
user_account: UserAccount,
settlee_user_account_public_key: Pubkey,
settlee_user_account: UserAccount,
market_index: int,
):
return await self.send_ixs(
self.get_settle_pnl_ix(user_public_key, user_account, market_index)
self.get_settle_pnl_ix(
settlee_user_account_public_key, settlee_user_account, market_index
)
)

def get_settle_pnl_ix(
self,
user_public_key: Pubkey,
user_account: UserAccount,
settlee_user_public_key: Pubkey,
settlee_user_account: UserAccount,
market_index: int,
):
remaining_accounts = self.get_remaining_accounts(
writable_perp_market_indexes=[market_index],
writable_spot_market_indexes=[QUOTE_SPOT_MARKET_INDEX],
user_accounts=[user_account],
user_accounts=[settlee_user_account],
)

instruction = self.program.instruction["settle_pnl"](
Expand All @@ -1472,7 +1473,7 @@ def get_settle_pnl_ix(
accounts={
"state": self.get_state_public_key(),
"authority": self.authority,
"user": user_public_key,
"user": settlee_user_public_key,
"spot_market_vault": get_spot_market_vault_public_key(
self.program_id, QUOTE_SPOT_MARKET_INDEX
),
Expand Down

0 comments on commit 8a70fab

Please sign in to comment.