Skip to content

Index

data_types

Enums and Models used in the derive_client module

Classes

Currency

Bases: Enum

Depositable currencies

Environment

Bases: Enum

Environment.

BridgeTxDetails

Bases: BaseModel

Attributes
tx_hash property
tx_hash: str

Pre-computed transaction hash.

nonce property
nonce: int

Transaction nonce.

gas property
gas: int

Gas limit

ChecksumAddress

Bases: str

ChecksumAddress with validation.

PositionTransfer dataclass

PositionTransfer(instrument_name: str, amount: Decimal)

Position to transfer between subaccounts.

PreparedBridgeTx

Bases: BaseModel

Attributes
tx_hash property
tx_hash: str

Pre-computed transaction hash.

nonce property
nonce: int

Transaction nonce.

TxHash

Bases: str

Transaction hash with validation.

TypedFilterParams

Bases: BaseModel

Typed filter params for eth_getLogs that we actually use.

Unlike web3.types.FilterParams which has overly-broad unions, this reflects our actual runtime behavior: - We work with int block numbers internally - We convert to hex strings right before RPC calls - We use 'latest' as a special case for open-ended queries

Functions
to_rpc_params
to_rpc_params() -> FilterParams

Convert to RPC-compatible filter params with hex block numbers.

Source code in derive_client/data_types/models.py
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
def to_rpc_params(self) -> FilterParams:
    """Convert to RPC-compatible filter params with hex block numbers."""

    address: ETHChecksumAddress | list[ETHChecksumAddress]
    if isinstance(self.address, list):
        address = [cast(ETHChecksumAddress, addr) for addr in self.address]
    else:
        address = cast(ETHChecksumAddress, self.address)

    from_block = cast(HexStr, hex(self.fromBlock)) if self.fromBlock != "latest" else self.fromBlock
    to_block = cast(HexStr, hex(self.toBlock)) if self.toBlock != "latest" else self.toBlock

    params: FilterParams = {
        "address": address,
        "fromBlock": from_block,
        "toBlock": to_block,
    }

    if self.topics is not None:
        params["topics"] = [cast(HexStr, topic.to_0x_hex()) if topic is not None else None for topic in self.topics]
    if self.blockHash is not None:
        params["blockHash"] = self.blockHash

    return params

TypedLogReceipt

Bases: BaseModel

Typed log entry from transaction receipt.

Functions
to_w3
to_w3() -> LogReceipt

Convert to web3.py LogReceipt dict.

Source code in derive_client/data_types/models.py
250
251
252
253
254
255
256
257
258
259
260
261
262
263
def to_w3(self) -> LogReceipt:
    """Convert to web3.py LogReceipt dict."""

    return LogReceipt(
        address=cast(ETHChecksumAddress, self.address),
        blockHash=self.blockHash,
        blockNumber=cast(BlockNumber, self.blockNumber),
        data=self.data,
        logIndex=self.logIndex,
        removed=self.removed,
        topics=self.topics,
        transactionHash=self.transactionHash,
        transactionIndex=self.transactionIndex,
    )

TypedSignedTransaction

Bases: BaseModel

Properly typed signed transaction.

Immutable replacement for eth_account.datastructures.SignedTransaction.

Functions
to_w3
to_w3() -> SignedTransaction

Convert to eth_account SignedTransaction.

Source code in derive_client/data_types/models.py
338
339
340
341
342
343
344
345
346
347
def to_w3(self) -> SignedTransaction:
    """Convert to eth_account SignedTransaction."""

    return SignedTransaction(
        raw_transaction=self.raw_transaction,
        hash=self.hash,
        r=self.r,
        s=self.s,
        v=self.v,
    )

TypedTransaction

Bases: BaseModel

Fully typed transaction data retrieved from the blockchain.

Based on web3.types.TxData but with proper attribute access. This represents a transaction that has been retrieved from a node, which may or may not be mined yet.

TypedTxReceipt

Bases: BaseModel

Fully typed transaction receipt with attribute access.

Based on web3.types.TxReceipt but actually usable with type checkers. All fields from EIP-658 and common extensions included.

Functions
to_w3
to_w3() -> TxReceipt

Convert to web3.py TxReceipt dict.

Source code in derive_client/data_types/models.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
def to_w3(self) -> TxReceipt:
    """Convert to web3.py TxReceipt dict."""

    tx_receipt = {
        'blockHash': self.blockHash,
        'blockNumber': cast(BlockNumber, self.blockNumber),
        'contractAddress': cast(ETHChecksumAddress, self.contractAddress) if self.contractAddress else None,
        'cumulativeGasUsed': self.cumulativeGasUsed,
        'effectiveGasPrice': cast(ETHWei, self.effectiveGasPrice),
        'from': cast(ETHChecksumAddress, self.from_),
        'gasUsed': self.gasUsed,
        'logs': [log.to_w3() for log in self.logs],
        'logsBloom': self.logsBloom,
        'status': self.status,
        'to': cast(ETHChecksumAddress, self.to),
        'transactionHash': self.transactionHash,
        'transactionIndex': self.transactionIndex,
        'type': self.type,
    }
    if self.root is not None:
        tx_receipt["root"] = self.root

    # web3.py's definition is WRONG.
    # EIP-658 (Byzantium fork, 2017) replaced root with status
    # Pre-EIP-658 receipts: Have root, don't have status
    # Post-EIP-658 receipts: Have status, don't have root
    return cast(TxReceipt, tx_receipt)

Wei

Bases: int

Wei with validation.

Functions

D

D(value: int | float | str | Decimal) -> Decimal

Helper function to cast int, float, and str to Decimal.

Parameters:

Name Type Description Default
value int | float | str | Decimal

The value to convert to Decimal

required

Returns:

Type Description
Decimal

Decimal representation of the value

Examples:

>>> D(0.1)
Decimal('0.1')
>>> D("123.456")
Decimal('123.456')
>>> D(42)
Decimal('42')
Source code in derive_client/data_types/utils.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def D(value: int | float | str | Decimal) -> Decimal:
    """
    Helper function to cast int, float, and str to Decimal.

    Args:
        value: The value to convert to Decimal

    Returns:
        Decimal representation of the value

    Examples:
        >>> D(0.1)
        Decimal('0.1')
        >>> D("123.456")
        Decimal('123.456')
        >>> D(42)
        Decimal('42')
    """
    if isinstance(value, Decimal):
        return value
    return Decimal(str(value))