Added settle funds. (#45)
* Added settle funds. * Added tests. * Fixed bug. * Removed unnecessary tests. * Address comments Co-authored-by: michaelhly <michaelhly@gmail.com>
This commit is contained in:
parent
74355e01bf
commit
fb219b9207
|
@ -332,8 +332,37 @@ class Market:
|
|||
owner: Account,
|
||||
open_orders: OpenOrdersAccount,
|
||||
base_wallet: PublicKey,
|
||||
quote_wallet: PublicKey,
|
||||
referrer_quote_wallet: PublicKey,
|
||||
quote_wallet: PublicKey, # TODO: add referrer_quote_wallet.
|
||||
opts: TxOpts = TxOpts(),
|
||||
) -> str:
|
||||
raise NotImplementedError("settle_funds not implemented")
|
||||
) -> RPCResponse:
|
||||
# TODO: Handle wrapped sol accounts
|
||||
if open_orders.owner != owner.public_key():
|
||||
raise Exception("Invalid open orders account")
|
||||
vault_signer = PublicKey.create_program_address(
|
||||
[bytes(self.state.public_key()), self.state.vault_signer_nonce().to_bytes(8, byteorder="little")],
|
||||
self.state.program_id(),
|
||||
)
|
||||
transaction = Transaction()
|
||||
transaction.add(self.make_settle_funds_instruction(open_orders, base_wallet, quote_wallet, vault_signer))
|
||||
return self._conn.send_transaction(transaction, owner, opts=opts)
|
||||
|
||||
def make_settle_funds_instruction(
|
||||
self,
|
||||
open_orders_account: OpenOrdersAccount,
|
||||
base_wallet: PublicKey,
|
||||
quote_wallet: PublicKey,
|
||||
vault_signer: PublicKey,
|
||||
) -> TransactionInstruction:
|
||||
return instructions.settle_funds(
|
||||
instructions.SettleFundsParams(
|
||||
market=self.state.public_key(),
|
||||
open_orders=open_orders_account.address,
|
||||
owner=open_orders_account.owner,
|
||||
base_vault=self.state.base_vault(),
|
||||
quote_vault=self.state.quote_vault(),
|
||||
base_wallet=base_wallet,
|
||||
quote_wallet=quote_wallet,
|
||||
vault_signer=vault_signer,
|
||||
program_id=self.state.program_id(),
|
||||
)
|
||||
)
|
||||
|
|
|
@ -76,7 +76,7 @@ class MarketState: # pylint: disable=too-many-public-methods
|
|||
def request_queue(self) -> PublicKey:
|
||||
return PublicKey(self._decoded.request_queue)
|
||||
|
||||
def vault_signer_nonce(self) -> PublicKey:
|
||||
def vault_signer_nonce(self) -> int:
|
||||
return self._decoded.vault_signer_nonce
|
||||
|
||||
def base_mint(self) -> PublicKey:
|
||||
|
|
|
@ -79,6 +79,27 @@ def test_match_order(bootstrapped_market: Market, stubbed_payer: Account):
|
|||
assert sum(1 for _ in asks) == 0
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_settle_fund(
|
||||
bootstrapped_market: Market,
|
||||
stubbed_payer: Account,
|
||||
stubbed_quote_wallet: Account,
|
||||
stubbed_base_wallet: Account,
|
||||
):
|
||||
open_order_accounts = bootstrapped_market.find_open_orders_accounts_for_owner(stubbed_payer.public_key())
|
||||
|
||||
for open_order_account in open_order_accounts:
|
||||
assert "error" not in bootstrapped_market.settle_funds(
|
||||
stubbed_payer,
|
||||
open_order_account,
|
||||
stubbed_base_wallet.public_key(),
|
||||
stubbed_quote_wallet.public_key(),
|
||||
opts=TxOpts(skip_confirmation=False),
|
||||
)
|
||||
|
||||
# TODO: Check account states after settling funds
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_order_placement_cancellation_cycle(
|
||||
bootstrapped_market: Market,
|
||||
|
|
Loading…
Reference in New Issue