Typing fixes (#81)
This commit is contained in:
parent
4aed066b59
commit
a2f9bd6ca4
3
Pipfile
3
Pipfile
|
@ -27,9 +27,10 @@ sphinx = "*"
|
|||
sphinxemoji = "*"
|
||||
|
||||
[packages]
|
||||
solana = "*"
|
||||
solana = {version = ">=0.11.3"}
|
||||
construct = "*"
|
||||
flake8 = "*"
|
||||
construct-typing = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.7"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,5 @@
|
|||
|
||||
import sys
|
||||
|
||||
__import__("pkg_resources").declare_namespace("pyserum") # type: ignore
|
||||
|
||||
if sys.version_info < (3, 7):
|
||||
raise EnvironmentError("Python 3.7 or above is required.")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from construct import BitsInteger, BitsSwapped, BitStruct, Const, Flag # type: ignore
|
||||
from construct import BitsInteger, BitsSwapped, BitStruct, Const, Flag
|
||||
|
||||
# We will use a bitstruct with 64 bits instead of the widebits implementation in serum-js.
|
||||
ACCOUNT_FLAGS_LAYOUT = BitsSwapped( # Swap to little endian
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Layouts for dex instructions data."""
|
||||
from enum import IntEnum
|
||||
|
||||
from construct import Switch # type: ignore
|
||||
from construct import Switch
|
||||
from construct import Bytes, Const, Int8ul, Int16ul, Int32ul, Int64ul, Pass
|
||||
from construct import Struct as cStruct
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from construct import Bytes, Int8ul, Int64ul, Padding # type: ignore
|
||||
from construct import Struct as cStruct # type: ignore
|
||||
from construct import Bytes, Int8ul, Int64ul, Padding
|
||||
from construct import Struct as cStruct
|
||||
|
||||
from .account_flags import ACCOUNT_FLAGS_LAYOUT
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from construct import Bytes, Int64ul, Padding # type: ignore
|
||||
from construct import Struct as cStruct
|
||||
from construct import Bytes, Int64ul, Padding, Struct as cStruct
|
||||
|
||||
from .account_flags import ACCOUNT_FLAGS_LAYOUT
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from construct import BitStruct # type: ignore
|
||||
from construct import BitsInteger, BitsSwapped, Bytes, Const, Flag, Int8ul, Int32ul, Int64ul, Padding
|
||||
from construct import Struct as cStruct # type: ignore
|
||||
from construct import BitStruct, BitsInteger, BitsSwapped, Bytes, Const, Flag, Int8ul, Int32ul, Int64ul, Padding
|
||||
from construct import Struct as cStruct
|
||||
|
||||
from .account_flags import ACCOUNT_FLAGS_LAYOUT
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from enum import IntEnum
|
||||
|
||||
from construct import Switch # type: ignore
|
||||
from construct import Bytes, Int8ul, Int32ul, Int64ul, Padding
|
||||
from construct import Switch, Bytes, Int8ul, Int32ul, Int64ul, Padding
|
||||
from construct import Struct as cStruct
|
||||
|
||||
from .account_flags import ACCOUNT_FLAGS_LAYOUT
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
"""Serum Dex Instructions."""
|
||||
from typing import Any, Dict, List, NamedTuple, Optional
|
||||
from typing import Dict, List, NamedTuple, Optional
|
||||
|
||||
from solana.publickey import PublicKey
|
||||
from solana.sysvar import SYSVAR_RENT_PUBKEY
|
||||
from solana.transaction import AccountMeta, TransactionInstruction
|
||||
from solana.utils.validate import validate_instruction_keys, validate_instruction_type
|
||||
from spl.token.constants import TOKEN_PROGRAM_ID # type: ignore # TODO: Fix and remove ignore.
|
||||
from spl.token.constants import TOKEN_PROGRAM_ID
|
||||
from construct import Container
|
||||
|
||||
from ._layouts.instructions import INSTRUCTIONS_LAYOUT, InstructionType
|
||||
from .enums import OrderType, SelfTradeBehavior, Side
|
||||
|
@ -267,7 +268,9 @@ class CancelOrderByClientIDV2Params(NamedTuple):
|
|||
""""""
|
||||
|
||||
|
||||
def __parse_and_validate_instruction(instruction: TransactionInstruction, instruction_type: InstructionType) -> Any:
|
||||
def __parse_and_validate_instruction(
|
||||
instruction: TransactionInstruction, instruction_type: InstructionType
|
||||
) -> Container:
|
||||
instruction_type_to_length_map: Dict[InstructionType, int] = {
|
||||
InstructionType.INITIALIZE_MARKET: 9,
|
||||
InstructionType.NEW_ORDER: 9,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import math
|
||||
from enum import IntEnum
|
||||
from typing import List, Optional, Sequence, Tuple, Union, cast
|
||||
from typing import List, Optional, Tuple, Union, cast
|
||||
|
||||
from construct import Container # type: ignore
|
||||
from construct import Container
|
||||
from solana.publickey import PublicKey
|
||||
|
||||
from ..._layouts.queue import EVENT_LAYOUT, QUEUE_HEADER_LAYOUT, REQUEST_LAYOUT
|
||||
|
@ -15,7 +15,7 @@ class QueueType(IntEnum):
|
|||
|
||||
|
||||
def __from_bytes(
|
||||
buffer: Sequence[int], queue_type: QueueType, history: Optional[int]
|
||||
buffer: bytes, queue_type: QueueType, history: Optional[int]
|
||||
) -> Tuple[Container, List[Union[Event, Request]]]:
|
||||
header = QUEUE_HEADER_LAYOUT.parse(buffer)
|
||||
layout_size = EVENT_LAYOUT.sizeof() if queue_type == QueueType.EVENT else REQUEST_LAYOUT.sizeof()
|
||||
|
@ -34,7 +34,7 @@ def __from_bytes(
|
|||
return header, nodes
|
||||
|
||||
|
||||
def __parse_queue_item(buffer: Sequence[int], queue_type: QueueType) -> Union[Event, Request]:
|
||||
def __parse_queue_item(buffer: bytes, queue_type: QueueType) -> Union[Event, Request]:
|
||||
if queue_type == QueueType.EVENT: # pylint: disable=no-else-return
|
||||
parsed_item = EVENT_LAYOUT.parse(buffer)
|
||||
parsed_event_flags = parsed_item.event_flags
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Iterable, List, NamedTuple, Optional, Sequence
|
||||
from typing import Iterable, List, NamedTuple, Optional
|
||||
|
||||
from construct import Container # type: ignore
|
||||
from construct import ListContainer
|
||||
from solana.publickey import PublicKey
|
||||
|
||||
from ..._layouts.slab import SLAB_LAYOUT, NodeType
|
||||
|
@ -51,7 +51,7 @@ class Slab:
|
|||
self._nodes: List[SlabNode] = nodes
|
||||
|
||||
@staticmethod
|
||||
def __build(nodes: Container) -> List[SlabNode]:
|
||||
def __build(nodes: ListContainer) -> List[SlabNode]:
|
||||
res: List[SlabNode] = []
|
||||
for construct_node in nodes:
|
||||
node_type = construct_node.tag
|
||||
|
@ -90,7 +90,7 @@ class Slab:
|
|||
return res
|
||||
|
||||
@staticmethod
|
||||
def from_bytes(buffer: Sequence[int]) -> Slab:
|
||||
def from_bytes(buffer: bytes) -> Slab:
|
||||
parsed_slab = SLAB_LAYOUT.parse(buffer)
|
||||
header = parsed_slab.header
|
||||
nodes = parsed_slab.nodes
|
||||
|
|
|
@ -11,11 +11,11 @@ from solana.rpc.api import Client
|
|||
from solana.rpc.types import RPCResponse, TxOpts
|
||||
from solana.system_program import CreateAccountParams, create_account
|
||||
from solana.transaction import Transaction, TransactionInstruction
|
||||
from spl.token.constants import ACCOUNT_LEN, TOKEN_PROGRAM_ID, WRAPPED_SOL_MINT # type: ignore # TODO: Remove ignore.
|
||||
from spl.token.instructions import CloseAccountParams # type: ignore
|
||||
from spl.token.constants import ACCOUNT_LEN, TOKEN_PROGRAM_ID, WRAPPED_SOL_MINT
|
||||
from spl.token.instructions import CloseAccountParams
|
||||
from spl.token.instructions import InitializeAccountParams, close_account, initialize_account
|
||||
|
||||
import pyserum.instructions as instructions
|
||||
from pyserum import instructions
|
||||
import pyserum.market.types as t
|
||||
|
||||
from .._layouts.open_orders import OPEN_ORDERS_LAYOUT
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable, List, Sequence, Union
|
||||
from typing import Iterable, List, Union
|
||||
|
||||
import pyserum.market.types as t
|
||||
|
||||
|
@ -32,7 +32,7 @@ class OrderBook:
|
|||
return node.key >> 64
|
||||
|
||||
@staticmethod
|
||||
def from_bytes(market_state: MarketState, buffer: Sequence[int]) -> OrderBook:
|
||||
def from_bytes(market_state: MarketState, buffer: bytes) -> OrderBook:
|
||||
"""Decode the given buffer into an order book."""
|
||||
# This is a bit hacky at the moment. The first 5 bytes are padding, the
|
||||
# total length is 8 bytes which is 5 + 8 = 13 bytes.
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
from typing import Sequence
|
||||
|
||||
from construct import Container, Struct # type: ignore
|
||||
from construct import Container, Struct
|
||||
from solana.publickey import PublicKey
|
||||
from solana.rpc.api import Client
|
||||
|
||||
|
@ -42,7 +41,7 @@ class MarketState: # pylint: disable=too-many-public-methods
|
|||
|
||||
@staticmethod
|
||||
def from_bytes(
|
||||
program_id: PublicKey, base_mint_decimals: int, quote_mint_decimals: int, buffer: Sequence[int]
|
||||
program_id: PublicKey, base_mint_decimals: int, quote_mint_decimals: int, buffer: bytes
|
||||
) -> MarketState:
|
||||
parsed_market = MARKET_LAYOUT.parse(buffer)
|
||||
# TODO: add ownAddress check!
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import NamedTuple, Sequence
|
||||
from typing import NamedTuple
|
||||
|
||||
from solana.publickey import PublicKey
|
||||
|
||||
|
@ -25,7 +25,7 @@ class AccountFlags(NamedTuple):
|
|||
""""""
|
||||
|
||||
@staticmethod
|
||||
def from_bytes(buffer: Sequence[int]) -> AccountFlags:
|
||||
def from_bytes(buffer: bytes) -> AccountFlags:
|
||||
con = ACCOUNT_FLAGS_LAYOUT.parse(buffer)
|
||||
return AccountFlags(
|
||||
initialized=con.initialized,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
from typing import List, NamedTuple, Sequence
|
||||
from typing import List, NamedTuple
|
||||
|
||||
from solana.publickey import PublicKey
|
||||
from solana.rpc.api import Client
|
||||
|
@ -53,7 +53,7 @@ class OpenOrdersAccount:
|
|||
self.client_ids = client_ids
|
||||
|
||||
@staticmethod
|
||||
def from_bytes(address: PublicKey, buffer: Sequence[int]) -> OpenOrdersAccount:
|
||||
def from_bytes(address: PublicKey, buffer: bytes) -> OpenOrdersAccount:
|
||||
open_order_decoded = OPEN_ORDERS_LAYOUT.parse(buffer)
|
||||
if not open_order_decoded.account_flags.open_orders or not open_order_decoded.account_flags.initialized:
|
||||
raise Exception("Not an open order account or not initialized.")
|
||||
|
|
|
@ -2,7 +2,7 @@ import base64
|
|||
|
||||
from solana.publickey import PublicKey
|
||||
from solana.rpc.api import Client
|
||||
from spl.token.constants import WRAPPED_SOL_MINT # type: ignore # TODO: Remove ignore.
|
||||
from spl.token.constants import WRAPPED_SOL_MINT
|
||||
|
||||
from pyserum._layouts.market import MINT_LAYOUT
|
||||
|
||||
|
|
6
setup.py
6
setup.py
|
@ -4,13 +4,13 @@ from setuptools import find_packages, setup
|
|||
|
||||
setup(
|
||||
name="pyserum",
|
||||
version="0.3.4a1",
|
||||
version="0.3.5a1",
|
||||
author="serum-community",
|
||||
description="""Python client library for interacting with the Project Serum DEX.""",
|
||||
include_package_data=True,
|
||||
install_requires=[
|
||||
"construct>=2.10.56, <3.0.0",
|
||||
"solana>=0.3.0, <1.0.0",
|
||||
"construct-typing>=0.5.1, <1.0.0",
|
||||
"solana>=0.11.3, <1.0.0",
|
||||
],
|
||||
python_requires=">=3.7, <4",
|
||||
license="MIT",
|
||||
|
|
Loading…
Reference in New Issue