nado-protocol 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. nado_protocol-0.1.0/PKG-INFO +157 -0
  2. nado_protocol-0.1.0/README.md +133 -0
  3. nado_protocol-0.1.0/nado_protocol/__init__.py +0 -0
  4. nado_protocol-0.1.0/nado_protocol/client/__init__.py +200 -0
  5. nado_protocol-0.1.0/nado_protocol/client/apis/__init__.py +26 -0
  6. nado_protocol-0.1.0/nado_protocol/client/apis/base.py +42 -0
  7. nado_protocol-0.1.0/nado_protocol/client/apis/market/__init__.py +23 -0
  8. nado_protocol-0.1.0/nado_protocol/client/apis/market/execute.py +192 -0
  9. nado_protocol-0.1.0/nado_protocol/client/apis/market/query.py +310 -0
  10. nado_protocol-0.1.0/nado_protocol/client/apis/perp/__init__.py +18 -0
  11. nado_protocol-0.1.0/nado_protocol/client/apis/perp/query.py +30 -0
  12. nado_protocol-0.1.0/nado_protocol/client/apis/rewards/__init__.py +6 -0
  13. nado_protocol-0.1.0/nado_protocol/client/apis/rewards/execute.py +131 -0
  14. nado_protocol-0.1.0/nado_protocol/client/apis/rewards/query.py +12 -0
  15. nado_protocol-0.1.0/nado_protocol/client/apis/spot/__init__.py +23 -0
  16. nado_protocol-0.1.0/nado_protocol/client/apis/spot/base.py +32 -0
  17. nado_protocol-0.1.0/nado_protocol/client/apis/spot/execute.py +117 -0
  18. nado_protocol-0.1.0/nado_protocol/client/apis/spot/query.py +79 -0
  19. nado_protocol-0.1.0/nado_protocol/client/apis/subaccount/__init__.py +24 -0
  20. nado_protocol-0.1.0/nado_protocol/client/apis/subaccount/execute.py +54 -0
  21. nado_protocol-0.1.0/nado_protocol/client/apis/subaccount/query.py +145 -0
  22. nado_protocol-0.1.0/nado_protocol/client/context.py +90 -0
  23. nado_protocol-0.1.0/nado_protocol/contracts/__init__.py +377 -0
  24. nado_protocol-0.1.0/nado_protocol/contracts/abis/Endpoint.json +636 -0
  25. nado_protocol-0.1.0/nado_protocol/contracts/abis/FQuerier.json +1909 -0
  26. nado_protocol-0.1.0/nado_protocol/contracts/abis/IClearinghouse.json +876 -0
  27. nado_protocol-0.1.0/nado_protocol/contracts/abis/IERC20.json +185 -0
  28. nado_protocol-0.1.0/nado_protocol/contracts/abis/IEndpoint.json +250 -0
  29. nado_protocol-0.1.0/nado_protocol/contracts/abis/IFoundationRewardsAirdrop.json +76 -0
  30. nado_protocol-0.1.0/nado_protocol/contracts/abis/IOffchainBook.json +536 -0
  31. nado_protocol-0.1.0/nado_protocol/contracts/abis/IPerpEngine.json +931 -0
  32. nado_protocol-0.1.0/nado_protocol/contracts/abis/IProductEngine.json +352 -0
  33. nado_protocol-0.1.0/nado_protocol/contracts/abis/ISpotEngine.json +813 -0
  34. nado_protocol-0.1.0/nado_protocol/contracts/abis/IStaking.json +288 -0
  35. nado_protocol-0.1.0/nado_protocol/contracts/abis/IVrtxAirdrop.json +138 -0
  36. nado_protocol-0.1.0/nado_protocol/contracts/abis/MockERC20.json +311 -0
  37. nado_protocol-0.1.0/nado_protocol/contracts/deployments/deployment.test.json +18 -0
  38. nado_protocol-0.1.0/nado_protocol/contracts/eip712/__init__.py +16 -0
  39. nado_protocol-0.1.0/nado_protocol/contracts/eip712/domain.py +36 -0
  40. nado_protocol-0.1.0/nado_protocol/contracts/eip712/sign.py +79 -0
  41. nado_protocol-0.1.0/nado_protocol/contracts/eip712/types.py +154 -0
  42. nado_protocol-0.1.0/nado_protocol/contracts/loader.py +55 -0
  43. nado_protocol-0.1.0/nado_protocol/contracts/types.py +141 -0
  44. nado_protocol-0.1.0/nado_protocol/engine_client/__init__.py +35 -0
  45. nado_protocol-0.1.0/nado_protocol/engine_client/execute.py +416 -0
  46. nado_protocol-0.1.0/nado_protocol/engine_client/query.py +481 -0
  47. nado_protocol-0.1.0/nado_protocol/engine_client/types/__init__.py +113 -0
  48. nado_protocol-0.1.0/nado_protocol/engine_client/types/execute.py +680 -0
  49. nado_protocol-0.1.0/nado_protocol/engine_client/types/models.py +247 -0
  50. nado_protocol-0.1.0/nado_protocol/engine_client/types/query.py +516 -0
  51. nado_protocol-0.1.0/nado_protocol/engine_client/types/stream.py +6 -0
  52. nado_protocol-0.1.0/nado_protocol/indexer_client/__init__.py +28 -0
  53. nado_protocol-0.1.0/nado_protocol/indexer_client/query.py +466 -0
  54. nado_protocol-0.1.0/nado_protocol/indexer_client/types/__init__.py +122 -0
  55. nado_protocol-0.1.0/nado_protocol/indexer_client/types/models.py +364 -0
  56. nado_protocol-0.1.0/nado_protocol/indexer_client/types/query.py +819 -0
  57. nado_protocol-0.1.0/nado_protocol/trigger_client/__init__.py +17 -0
  58. nado_protocol-0.1.0/nado_protocol/trigger_client/execute.py +118 -0
  59. nado_protocol-0.1.0/nado_protocol/trigger_client/query.py +61 -0
  60. nado_protocol-0.1.0/nado_protocol/trigger_client/types/__init__.py +7 -0
  61. nado_protocol-0.1.0/nado_protocol/trigger_client/types/execute.py +89 -0
  62. nado_protocol-0.1.0/nado_protocol/trigger_client/types/models.py +44 -0
  63. nado_protocol-0.1.0/nado_protocol/trigger_client/types/query.py +77 -0
  64. nado_protocol-0.1.0/nado_protocol/utils/__init__.py +37 -0
  65. nado_protocol-0.1.0/nado_protocol/utils/backend.py +111 -0
  66. nado_protocol-0.1.0/nado_protocol/utils/bytes32.py +159 -0
  67. nado_protocol-0.1.0/nado_protocol/utils/enum.py +6 -0
  68. nado_protocol-0.1.0/nado_protocol/utils/exceptions.py +58 -0
  69. nado_protocol-0.1.0/nado_protocol/utils/execute.py +403 -0
  70. nado_protocol-0.1.0/nado_protocol/utils/expiration.py +45 -0
  71. nado_protocol-0.1.0/nado_protocol/utils/interest.py +66 -0
  72. nado_protocol-0.1.0/nado_protocol/utils/math.py +67 -0
  73. nado_protocol-0.1.0/nado_protocol/utils/model.py +79 -0
  74. nado_protocol-0.1.0/nado_protocol/utils/nonce.py +33 -0
  75. nado_protocol-0.1.0/nado_protocol/utils/subaccount.py +18 -0
  76. nado_protocol-0.1.0/nado_protocol/utils/time.py +21 -0
  77. nado_protocol-0.1.0/pyproject.toml +77 -0
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.3
2
+ Name: nado-protocol
3
+ Version: 0.1.0
4
+ Summary: Nado Protocol SDK
5
+ Keywords: nado protocol,nado sdk,nado protocol api
6
+ Author: Jeury Mejia
7
+ Author-email: jeury@inkfnd.com
8
+ Maintainer: Frank Jia
9
+ Maintainer-email: frank@inkfnd.com
10
+ Requires-Python: >=3.9,<4.0
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Dist: eth-account (>=0.8.0,<0.9.0)
18
+ Requires-Dist: pydantic (>=1.10.7,<2.0.0)
19
+ Requires-Dist: web3 (>=6.4.0,<7.0.0)
20
+ Project-URL: Documentation, https://nadohq.github.io/nado-python-sdk/
21
+ Project-URL: Homepage, https://nado.xyz
22
+ Description-Content-Type: text/markdown
23
+
24
+ # Nado Protocol Python SDK
25
+
26
+ This is the Python SDK for the [Nado Protocol API](TODO).
27
+
28
+ See [SDK docs](https://nadohq.github.io/nado-python-sdk/index.html) to get started.
29
+
30
+ ## Requirements
31
+
32
+ - Python 3.9 or above
33
+
34
+ ## Installation
35
+
36
+ You can install the SDK via pip:
37
+
38
+ ```bash
39
+ pip install nado-protocol
40
+ ```
41
+
42
+ ## Basic usage
43
+
44
+ ### Import the necessary utilities:
45
+
46
+ ```python
47
+ from nado_protocol.client import create_nado_client, NadoClientMode
48
+ from nado_protocol.contracts.types import DepositCollateralParams
49
+ from nado_protocol.engine_client.types.execute import (
50
+ OrderParams,
51
+ PlaceOrderParams,
52
+ SubaccountParams
53
+ )
54
+ from nado_protocol.utils.expiration import OrderType, get_expiration_timestamp
55
+ from nado_protocol.utils.math import to_pow_10, to_x18
56
+ from nado_protocol.utils.nonce import gen_order_nonce
57
+ ```
58
+
59
+ ### Create the NadoClient providing your private key:
60
+
61
+ ```python
62
+ print("setting up nado client...")
63
+ private_key = "xxx"
64
+ client = create_nado_client(NadoClientMode.DEVNET, private_key)
65
+ ```
66
+
67
+ ### Perform basic operations:
68
+
69
+ ```python
70
+ # Depositing collaterals
71
+ print("approving allowance...")
72
+ approve_allowance_tx_hash = client.spot.approve_allowance(0, to_pow_10(100000, 6))
73
+ print("approve allowance tx hash:", approve_allowance_tx_hash)
74
+
75
+ print("querying my allowance...")
76
+ token_allowance = client.spot.get_token_allowance(0, client.context.signer.address)
77
+ print("token allowance:", token_allowance)
78
+
79
+ print("depositing collateral...")
80
+ deposit_tx_hash = client.spot.deposit(
81
+ DepositCollateralParams(
82
+ subaccount_name="default", product_id=0, amount=to_pow_10(100000, 6)
83
+ )
84
+ )
85
+ print("deposit collateral tx hash:", deposit_tx_hash)
86
+
87
+ # Placing orders
88
+ print("placing order...")
89
+ owner = client.context.engine_client.signer.address
90
+ product_id = 1
91
+ order = OrderParams(
92
+ sender=SubaccountParams(
93
+ subaccount_owner=owner,
94
+ subaccount_name="default",
95
+ ),
96
+ priceX18=to_x18(20000),
97
+ amount=to_pow_10(1, 17),
98
+ expiration=get_expiration_timestamp(OrderType.POST_ONLY, int(time.time()) + 40),
99
+ nonce=gen_order_nonce(),
100
+ )
101
+ res = client.market.place_order({"product_id": product_id, "order": order})
102
+ print("order result:", res.json(indent=2))
103
+ ```
104
+
105
+ See [Getting Started](https://nadohq.github.io/nado-python-sdk/getting-started.html) for more.
106
+
107
+ ## Running locally
108
+
109
+ 1. Clone [github repo](https://github.com/nadohq/nado-python-sdk)
110
+
111
+ 2. Install poetry
112
+
113
+ ```
114
+
115
+ $ curl -sSL https://install.python-poetry.org | python3 -
116
+
117
+ ```
118
+
119
+ 3. Setup a virtual environment and activate it
120
+
121
+ ```
122
+
123
+ $ python3 -m venv venv
124
+ $ source ./venv/bin/activate
125
+
126
+ ```
127
+
128
+ 4. Install dependencies via `poetry install`
129
+ 5. Setup an `.env` file and set the following envvars
130
+
131
+ ```shell
132
+ CLIENT_MODE='devnet'
133
+ SIGNER_PRIVATE_KEY="0x..."
134
+ LINKED_SIGNER_PRIVATE_KEY="0x..." # not required
135
+ ```
136
+
137
+ ### Run tests
138
+
139
+ ```
140
+ $ poetry run test
141
+ ```
142
+
143
+ ### Run sanity checks
144
+
145
+ - `poetry run client-sanity`: runs sanity checks for the top-level client.
146
+ - `poetry run engine-sanity`: runs sanity checks for the `engine-client`.
147
+ - `poetry run indexer-sanity`: runs sanity checks for the `indexer-client`.
148
+ - `poetry run contracts-sanity`: runs sanity checks for the contracts module.
149
+
150
+ ### Build Docs
151
+
152
+ To build the docs locally run:
153
+
154
+ ```
155
+ $ poetry run sphinx-build docs/source docs/build
156
+ ```
157
+
@@ -0,0 +1,133 @@
1
+ # Nado Protocol Python SDK
2
+
3
+ This is the Python SDK for the [Nado Protocol API](TODO).
4
+
5
+ See [SDK docs](https://nadohq.github.io/nado-python-sdk/index.html) to get started.
6
+
7
+ ## Requirements
8
+
9
+ - Python 3.9 or above
10
+
11
+ ## Installation
12
+
13
+ You can install the SDK via pip:
14
+
15
+ ```bash
16
+ pip install nado-protocol
17
+ ```
18
+
19
+ ## Basic usage
20
+
21
+ ### Import the necessary utilities:
22
+
23
+ ```python
24
+ from nado_protocol.client import create_nado_client, NadoClientMode
25
+ from nado_protocol.contracts.types import DepositCollateralParams
26
+ from nado_protocol.engine_client.types.execute import (
27
+ OrderParams,
28
+ PlaceOrderParams,
29
+ SubaccountParams
30
+ )
31
+ from nado_protocol.utils.expiration import OrderType, get_expiration_timestamp
32
+ from nado_protocol.utils.math import to_pow_10, to_x18
33
+ from nado_protocol.utils.nonce import gen_order_nonce
34
+ ```
35
+
36
+ ### Create the NadoClient providing your private key:
37
+
38
+ ```python
39
+ print("setting up nado client...")
40
+ private_key = "xxx"
41
+ client = create_nado_client(NadoClientMode.DEVNET, private_key)
42
+ ```
43
+
44
+ ### Perform basic operations:
45
+
46
+ ```python
47
+ # Depositing collaterals
48
+ print("approving allowance...")
49
+ approve_allowance_tx_hash = client.spot.approve_allowance(0, to_pow_10(100000, 6))
50
+ print("approve allowance tx hash:", approve_allowance_tx_hash)
51
+
52
+ print("querying my allowance...")
53
+ token_allowance = client.spot.get_token_allowance(0, client.context.signer.address)
54
+ print("token allowance:", token_allowance)
55
+
56
+ print("depositing collateral...")
57
+ deposit_tx_hash = client.spot.deposit(
58
+ DepositCollateralParams(
59
+ subaccount_name="default", product_id=0, amount=to_pow_10(100000, 6)
60
+ )
61
+ )
62
+ print("deposit collateral tx hash:", deposit_tx_hash)
63
+
64
+ # Placing orders
65
+ print("placing order...")
66
+ owner = client.context.engine_client.signer.address
67
+ product_id = 1
68
+ order = OrderParams(
69
+ sender=SubaccountParams(
70
+ subaccount_owner=owner,
71
+ subaccount_name="default",
72
+ ),
73
+ priceX18=to_x18(20000),
74
+ amount=to_pow_10(1, 17),
75
+ expiration=get_expiration_timestamp(OrderType.POST_ONLY, int(time.time()) + 40),
76
+ nonce=gen_order_nonce(),
77
+ )
78
+ res = client.market.place_order({"product_id": product_id, "order": order})
79
+ print("order result:", res.json(indent=2))
80
+ ```
81
+
82
+ See [Getting Started](https://nadohq.github.io/nado-python-sdk/getting-started.html) for more.
83
+
84
+ ## Running locally
85
+
86
+ 1. Clone [github repo](https://github.com/nadohq/nado-python-sdk)
87
+
88
+ 2. Install poetry
89
+
90
+ ```
91
+
92
+ $ curl -sSL https://install.python-poetry.org | python3 -
93
+
94
+ ```
95
+
96
+ 3. Setup a virtual environment and activate it
97
+
98
+ ```
99
+
100
+ $ python3 -m venv venv
101
+ $ source ./venv/bin/activate
102
+
103
+ ```
104
+
105
+ 4. Install dependencies via `poetry install`
106
+ 5. Setup an `.env` file and set the following envvars
107
+
108
+ ```shell
109
+ CLIENT_MODE='devnet'
110
+ SIGNER_PRIVATE_KEY="0x..."
111
+ LINKED_SIGNER_PRIVATE_KEY="0x..." # not required
112
+ ```
113
+
114
+ ### Run tests
115
+
116
+ ```
117
+ $ poetry run test
118
+ ```
119
+
120
+ ### Run sanity checks
121
+
122
+ - `poetry run client-sanity`: runs sanity checks for the top-level client.
123
+ - `poetry run engine-sanity`: runs sanity checks for the `engine-client`.
124
+ - `poetry run indexer-sanity`: runs sanity checks for the `indexer-client`.
125
+ - `poetry run contracts-sanity`: runs sanity checks for the contracts module.
126
+
127
+ ### Build Docs
128
+
129
+ To build the docs locally run:
130
+
131
+ ```
132
+ $ poetry run sphinx-build docs/source docs/build
133
+ ```
File without changes
@@ -0,0 +1,200 @@
1
+ import logging
2
+ from nado_protocol.client.apis.market import MarketAPI
3
+ from nado_protocol.client.apis.perp import PerpAPI
4
+ from nado_protocol.client.apis.spot import SpotAPI
5
+ from nado_protocol.client.apis.subaccount import SubaccountAPI
6
+ from nado_protocol.client.apis.rewards import RewardsAPI
7
+ from nado_protocol.client.context import (
8
+ NadoClientContext,
9
+ NadoClientContextOpts,
10
+ create_nado_client_context,
11
+ )
12
+ from nado_protocol.contracts import NadoContractsContext
13
+ from nado_protocol.contracts.loader import load_deployment
14
+ from nado_protocol.contracts.types import NadoNetwork
15
+ from nado_protocol.utils.backend import NadoBackendURL, Signer
16
+ from nado_protocol.utils.enum import StrEnum
17
+ from nado_protocol.client.context import *
18
+
19
+ from pydantic import parse_obj_as
20
+
21
+
22
+ class NadoClientMode(StrEnum):
23
+ """
24
+ NadoClientMode is an enumeration representing the operational modes of the NadoClient.
25
+
26
+ Attributes:
27
+ DEVNET: For local development.
28
+
29
+ TESTING: For running tests.
30
+ """
31
+
32
+ # dev
33
+ DEVNET = "devnet"
34
+ TESTING = "testing"
35
+
36
+
37
+ class NadoClient:
38
+ """
39
+ The primary client interface for interacting with Nado Protocol.
40
+
41
+ This client consolidates the functionality of various aspects of Nado such as spot, market,
42
+ subaccount, and perpetual (perp) operations.
43
+
44
+ To initialize an instance of this client, use the `create_nado_client` utility.
45
+
46
+ Attributes:
47
+ - context (NadoClientContext): The client context containing configuration for interacting with Nado.
48
+ - market (MarketAPI): Sub-client for executing and querying market operations.
49
+ - subaccount (SubaccountAPI): Sub-client for executing and querying subaccount operations.
50
+ - spot (SpotAPI): Sub-client for executing and querying spot operations.
51
+ - perp (PerpAPI): Sub-client for executing and querying perpetual operations.
52
+ - rewards (RewardsAPI): Sub-client for executing and querying rewards operations (e.g: staking, claiming, etc).
53
+ """
54
+
55
+ context: NadoClientContext
56
+ market: MarketAPI
57
+ subaccount: SubaccountAPI
58
+ spot: SpotAPI
59
+ perp: PerpAPI
60
+ rewards: RewardsAPI
61
+
62
+ def __init__(self, context: NadoClientContext):
63
+ """
64
+ Initialize a new instance of the NadoClient.
65
+
66
+ This constructor should not be called directly. Instead, use the `create_nado_client` utility to
67
+ create a new NadoClient. This is because the `create_nado_client` utility includes important
68
+ additional setup steps that aren't included in this constructor.
69
+
70
+ Args:
71
+ context (NadoClientContext): The client context.
72
+
73
+ Note:
74
+ Use `create_nado_client` for creating instances.
75
+ """
76
+ self.context = context
77
+ self.market = MarketAPI(context)
78
+ self.subaccount = SubaccountAPI(context)
79
+ self.spot = SpotAPI(context)
80
+ self.perp = PerpAPI(context)
81
+ self.rewards = RewardsAPI(context)
82
+
83
+
84
+ def create_nado_client(
85
+ mode: NadoClientMode,
86
+ signer: Optional[Signer] = None,
87
+ context_opts: Optional[NadoClientContextOpts] = None,
88
+ ) -> NadoClient:
89
+ """
90
+ Create a new NadoClient based on the given mode and signer.
91
+
92
+ This function will create a new NadoClientContext based on the provided mode, and then
93
+ initialize a new NadoClient with that context.
94
+
95
+ If `context_opts` are provided, they will be used to create the client context. Otherwise,
96
+ default context options for the given mode will be used.
97
+
98
+ Args:
99
+ mode (NadoClientMode): The mode in which to operate the client. Can be one of the following:
100
+ NadoClientMode.DEVNET: For local development.
101
+
102
+ signer (Signer, optional): An instance of LocalAccount or a private key string for signing transactions.
103
+
104
+ context_opts (NadoClientContextOpts, optional): Options for creating the client context.
105
+ If not provided, default options for the given mode will be used.
106
+
107
+ Returns:
108
+ NadoClient: The created NadoClient instance.
109
+ """
110
+ logging.info(f"Initializing default {mode} context")
111
+ (
112
+ engine_endpoint_url,
113
+ indexer_endpoint_url,
114
+ trigger_endpoint_url,
115
+ network_name,
116
+ ) = client_mode_to_setup(mode)
117
+ try:
118
+ network = NadoNetwork(network_name)
119
+ deployment = load_deployment(network)
120
+ rpc_node_url = deployment.node_url
121
+ contracts_context = NadoContractsContext(
122
+ network=network,
123
+ endpoint_addr=deployment.endpoint_addr,
124
+ querier_addr=deployment.querier_addr,
125
+ perp_engine_addr=deployment.perp_engine_addr,
126
+ spot_engine_addr=deployment.spot_engine_addr,
127
+ clearinghouse_addr=deployment.clearinghouse_addr,
128
+ vrtx_airdrop_addr=deployment.vrtx_airdrop_addr,
129
+ vrtx_staking_addr=deployment.vrtx_staking_addr,
130
+ foundation_rewards_airdrop_addr=deployment.foundation_rewards_airdrop_addr,
131
+ )
132
+ except Exception as e:
133
+ logging.warning(
134
+ f"Failed to load contracts for mode {mode} with error: {e}, using provided defaults."
135
+ )
136
+ assert context_opts is not None and context_opts.rpc_node_url is not None
137
+ assert context_opts is not None and context_opts.contracts_context is not None
138
+
139
+ rpc_node_url = context_opts.rpc_node_url
140
+ contracts_context = context_opts.contracts_context
141
+
142
+ if context_opts:
143
+ parsed_context_opts: NadoClientContextOpts = NadoClientContextOpts.parse_obj(
144
+ context_opts
145
+ )
146
+ engine_endpoint_url = (
147
+ parsed_context_opts.engine_endpoint_url or engine_endpoint_url
148
+ )
149
+ indexer_endpoint_url = (
150
+ parsed_context_opts.indexer_endpoint_url or indexer_endpoint_url
151
+ )
152
+ trigger_endpoint_url = (
153
+ parsed_context_opts.trigger_endpoint_url or trigger_endpoint_url
154
+ )
155
+ rpc_node_url = parsed_context_opts.rpc_node_url or rpc_node_url
156
+ contracts_context = parsed_context_opts.contracts_context or contracts_context
157
+
158
+ context = create_nado_client_context(
159
+ NadoClientContextOpts(
160
+ rpc_node_url=rpc_node_url,
161
+ engine_endpoint_url=parse_obj_as(AnyUrl, engine_endpoint_url),
162
+ indexer_endpoint_url=parse_obj_as(AnyUrl, indexer_endpoint_url),
163
+ trigger_endpoint_url=parse_obj_as(AnyUrl, trigger_endpoint_url),
164
+ contracts_context=contracts_context,
165
+ ),
166
+ signer,
167
+ )
168
+ return NadoClient(context)
169
+
170
+
171
+ def client_mode_to_setup(
172
+ client_mode: NadoClientMode,
173
+ ) -> tuple[str, str, str, str]:
174
+ try:
175
+ return {
176
+ NadoClientMode.DEVNET: (
177
+ NadoBackendURL.DEVNET_GATEWAY.value,
178
+ NadoBackendURL.DEVNET_INDEXER.value,
179
+ NadoBackendURL.DEVNET_TRIGGER.value,
180
+ NadoNetwork.HARDHAT.value,
181
+ ),
182
+ NadoClientMode.TESTING: (
183
+ NadoBackendURL.DEVNET_GATEWAY.value,
184
+ NadoBackendURL.DEVNET_INDEXER.value,
185
+ NadoBackendURL.DEVNET_TRIGGER.value,
186
+ NadoNetwork.TESTING.value,
187
+ ),
188
+ }[client_mode]
189
+ except KeyError:
190
+ raise Exception(f"Mode provided `{client_mode}` not supported!")
191
+
192
+
193
+ __all__ = [
194
+ "NadoClient",
195
+ "NadoClientMode",
196
+ "create_nado_client",
197
+ "NadoClientContext",
198
+ "NadoClientContextOpts",
199
+ "create_nado_client_context",
200
+ ]
@@ -0,0 +1,26 @@
1
+ from nado_protocol.client.apis.base import *
2
+ from nado_protocol.client.apis.market import *
3
+ from nado_protocol.client.apis.perp import *
4
+ from nado_protocol.client.apis.spot import *
5
+ from nado_protocol.client.apis.spot.base import *
6
+ from nado_protocol.client.apis.subaccount import *
7
+ from nado_protocol.client.apis.rewards import *
8
+
9
+ __all__ = [
10
+ "NadoBaseAPI",
11
+ "MarketAPI",
12
+ "MarketExecuteAPI",
13
+ "MarketQueryAPI",
14
+ "SpotAPI",
15
+ "BaseSpotAPI",
16
+ "SpotExecuteAPI",
17
+ "SpotQueryAPI",
18
+ "SubaccountAPI",
19
+ "SubaccountExecuteAPI",
20
+ "SubaccountQueryAPI",
21
+ "PerpAPI",
22
+ "PerpQueryAPI",
23
+ "RewardsAPI",
24
+ "RewardsExecuteAPI",
25
+ "RewardsQueryAPI",
26
+ ]
@@ -0,0 +1,42 @@
1
+ from typing import Optional
2
+ from nado_protocol.client.context import NadoClientContext
3
+ from nado_protocol.utils.exceptions import MissingSignerException
4
+ from eth_account.signers.local import LocalAccount
5
+
6
+
7
+ class NadoBaseAPI:
8
+ """
9
+ The base class for all Nado API classes, providing the foundation for API-specific classes in the Nado client.
10
+
11
+ NadoBaseAPI serves as a foundation for the hierarchical structure of the Nado API classes. This structure allows for better
12
+ organization and separation of concerns, with each API-specific subclass handling a different aspect of the Nado client's functionality.
13
+
14
+ Attributes:
15
+ context (NadoClientContext): The context in which the API operates, providing access to the client's state and services.
16
+
17
+ Note:
18
+ This class is not meant to be used directly. It provides base functionality for other API classes in the Nado client.
19
+ """
20
+
21
+ context: NadoClientContext
22
+
23
+ def __init__(self, context: NadoClientContext):
24
+ """
25
+ Initialize an instance of NadoBaseAPI.
26
+
27
+ NadoBaseAPI requires a context during instantiation, which should be an instance of NadoClientContext. This context
28
+ provides access to the state and services of the Nado client and allows the API to interact with these.
29
+
30
+ Args:
31
+ context (NadoClientContext): The context in which this API operates. Provides access to the state and services
32
+ of the Nado client.
33
+ """
34
+ self.context = context
35
+
36
+ def _get_signer(self, signer: Optional[LocalAccount]) -> LocalAccount:
37
+ signer = signer if signer else self.context.signer
38
+ if not signer:
39
+ raise MissingSignerException(
40
+ "A signer must be provided or set via the context."
41
+ )
42
+ return signer
@@ -0,0 +1,23 @@
1
+ from nado_protocol.client.apis.market.execute import MarketExecuteAPI
2
+ from nado_protocol.client.apis.market.query import MarketQueryAPI
3
+
4
+
5
+ class MarketAPI(MarketExecuteAPI, MarketQueryAPI):
6
+ """
7
+ A unified interface for market operations in the Nado Protocol.
8
+
9
+ This class combines functionalities from both MarketExecuteAPI and MarketQueryAPI
10
+ into a single interface, providing a simpler and more consistent way to perform market operations.
11
+ It allows for both query (data retrieval) and execution (transaction) operations for market.
12
+
13
+ Inheritance:
14
+ MarketExecuteAPI: This provides functionalities to execute various operations related to market.
15
+ These include actions like placing an order, canceling an order, minting and burning LP tokens.
16
+
17
+ MarketQueryAPI: This provides functionalities to retrieve various kinds of information related to market.
18
+ These include operations like retrieving order books, historical orders, market matches, and others.
19
+
20
+ Attributes and Methods: Inherited from MarketExecuteAPI and MarketQueryAPI.
21
+ """
22
+
23
+ pass