LighterSDKSession

Documentation for eth_defi.lighter.session.LighterSDKSession Python class.

class LighterSDKSession

Bases: object

Exponential backoff for all HTTP traffic of the official Lighter SDK.

The SDK sends everything through ApiClient.rest_client.request() using aiohttp, so LighterSession cannot see it. This class replaces rest_client by composition, which keeps the optional SDK out of eth-defi’s imports. It does not change the SDK’s error handling: the final response is returned unchanged and the SDK raises its usual ApiException.

Retrying here rather than around a signer method matters. The SDK does not roll its nonce back when a 429 escapes, so a retry above this layer would sign again with a later nonce. Here the same signed body is resent, so the nonce and the transaction hash do not change.

Which requests are retried:

The SDK holds its per-key nonce lock during a wait. That keeps transactions in nonce order, and clients are built per operation, so nothing else is blocked.

Authenticated Lighter requests can carry a token in the query string, and bodies hold signed transactions, so logs only name the method and URL path.

The native Go signer has its own HTTP client, which this class cannot wrap. It is used when an SDK transaction method receives api_key_index without a nonce, and by SignerClient.check_client(). Do not call them that way: omit api_key_index and the Python nonce manager fetches the nonce through this class.

See Lighter’s rate limits and the SDK’s REST client.

Attributes summary

rest_client

The SDK's RESTClientObject.

policy

Delays and deadlines.

clock

Monotonic clock, injectable for deterministic tests.

sleep

Async sleep, injectable for deterministic tests.

Methods summary

__init__(rest_client[, policy, clock, sleep])

close()

Close the wrapped SDK client.

request(method, url[, headers, body, ...])

Send one SDK request, matching RESTClientObject.request().

rest_client: Any

The SDK’s RESTClientObject.

policy: eth_defi.lighter.session.LighterSDKRetryPolicy

Delays and deadlines.

clock: collections.abc.Callable[[], float]

Monotonic clock, injectable for deterministic tests.

sleep: collections.abc.Callable[[float], collections.abc.Awaitable[None]]

Async sleep, injectable for deterministic tests.

async close()

Close the wrapped SDK client.

Return type

None

async request(method, url, headers=None, body=None, post_params=None, _request_timeout=None)

Send one SDK request, matching RESTClientObject.request().

The body is read here because the SDK reads it only after this returns, which would leave a truncated read outside the retries. RESTResponse caches it, so the SDK’s later read returns the same bytes.

Parameters
  • method (str) – HTTP method.

  • url (str) – Full URL. May contain a token, so it is never logged whole.

  • headers (Optional[dict[str, str]]) – Request headers.

  • body (Any) – JSON body.

  • post_params (Any) – Form parameters.

  • _request_timeout (Optional[Union[float, tuple[float, float]]]) – Timeout of one attempt. Defaults to the policy’s.

Returns

SDK RESTResponse with its body read.

Return type

Any

__init__(rest_client, policy=LighterSDKRetryPolicy(initial_delay=1.0, max_delay=64.0, read_deadline=130.0, transaction_deadline=30.0, request_timeout=30.0), clock=<built-in function monotonic>, sleep=<function sleep>)
Parameters
Return type

None