compass_api_sdk 0.0.1__py3-none-any.whl

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.

Potentially problematic release.


This version of compass_api_sdk might be problematic. Click here for more details.

Files changed (137) hide show
  1. compass_api_sdk/__init__.py +17 -0
  2. compass_api_sdk/_hooks/__init__.py +5 -0
  3. compass_api_sdk/_hooks/registration.py +13 -0
  4. compass_api_sdk/_hooks/sdkhooks.py +76 -0
  5. compass_api_sdk/_hooks/types.py +106 -0
  6. compass_api_sdk/_version.py +15 -0
  7. compass_api_sdk/aave_v3.py +1903 -0
  8. compass_api_sdk/aerodrome_slipstream.py +1875 -0
  9. compass_api_sdk/basesdk.py +362 -0
  10. compass_api_sdk/errors/__init__.py +7 -0
  11. compass_api_sdk/errors/apierror.py +22 -0
  12. compass_api_sdk/errors/httpvalidationerror.py +21 -0
  13. compass_api_sdk/httpclient.py +136 -0
  14. compass_api_sdk/models/__init__.py +777 -0
  15. compass_api_sdk/models/aave_liquidity_changeop.py +108 -0
  16. compass_api_sdk/models/aave_token_priceop.py +98 -0
  17. compass_api_sdk/models/aave_user_position_per_tokenop.py +104 -0
  18. compass_api_sdk/models/aave_user_position_summaryop.py +35 -0
  19. compass_api_sdk/models/aaveborrowrequest.py +105 -0
  20. compass_api_sdk/models/aaveliquiditychangeresponse.py +26 -0
  21. compass_api_sdk/models/aaverepayrequest.py +105 -0
  22. compass_api_sdk/models/aavesupplyrequest.py +93 -0
  23. compass_api_sdk/models/aavetokenpriceresponse.py +15 -0
  24. compass_api_sdk/models/aaveuserpositionpertokenresponse.py +73 -0
  25. compass_api_sdk/models/aaveuserpositionsummaryresponse.py +50 -0
  26. compass_api_sdk/models/aavewithdrawrequest.py +58 -0
  27. compass_api_sdk/models/aerodrome_slipstream_liquidity_provision_positionsop.py +35 -0
  28. compass_api_sdk/models/aerodrome_slipstream_pool_priceop.py +173 -0
  29. compass_api_sdk/models/aerodromelppositionsresponse.py +21 -0
  30. compass_api_sdk/models/aerodromeposition.py +70 -0
  31. compass_api_sdk/models/aerodromeslipstreambuyexactlyrequest.py +92 -0
  32. compass_api_sdk/models/aerodromeslipstreamincreaseliquidityprovisionrequest.py +109 -0
  33. compass_api_sdk/models/aerodromeslipstreammintliquidityprovisionrequest.py +186 -0
  34. compass_api_sdk/models/aerodromeslipstreampoolpriceresponse.py +57 -0
  35. compass_api_sdk/models/aerodromeslipstreamsellexactlyrequest.py +96 -0
  36. compass_api_sdk/models/aerodromeslipstreamwithdrawliquidityprovisionrequest.py +50 -0
  37. compass_api_sdk/models/allowanceinforesponse.py +48 -0
  38. compass_api_sdk/models/balanceinforesponse.py +43 -0
  39. compass_api_sdk/models/chain.py +12 -0
  40. compass_api_sdk/models/chaininfo.py +53 -0
  41. compass_api_sdk/models/compass_api_backend_models_morpho_read_response_get_markets_asset.py +22 -0
  42. compass_api_sdk/models/compass_api_backend_models_morpho_read_response_get_vaults_asset.py +23 -0
  43. compass_api_sdk/models/ensnameinforesponse.py +24 -0
  44. compass_api_sdk/models/feeenum.py +16 -0
  45. compass_api_sdk/models/generic_allowanceop.py +121 -0
  46. compass_api_sdk/models/generic_balanceop.py +104 -0
  47. compass_api_sdk/models/generic_ensop.py +35 -0
  48. compass_api_sdk/models/generic_portfolioop.py +35 -0
  49. compass_api_sdk/models/generic_price_usdop.py +98 -0
  50. compass_api_sdk/models/generic_supported_tokensop.py +29 -0
  51. compass_api_sdk/models/generic_visualize_portfolioop.py +35 -0
  52. compass_api_sdk/models/image.py +15 -0
  53. compass_api_sdk/models/increaseallowancerequest.py +77 -0
  54. compass_api_sdk/models/interestratemode.py +14 -0
  55. compass_api_sdk/models/marketstate.py +35 -0
  56. compass_api_sdk/models/morpho_market_positionop.py +39 -0
  57. compass_api_sdk/models/morpho_marketsop.py +78 -0
  58. compass_api_sdk/models/morpho_vault_positionop.py +39 -0
  59. compass_api_sdk/models/morpho_vaultsop.py +72 -0
  60. compass_api_sdk/models/morphoborrowrequest.py +91 -0
  61. compass_api_sdk/models/morphocheckmarketpositionresponse.py +23 -0
  62. compass_api_sdk/models/morphocheckvaultpositionresponse.py +20 -0
  63. compass_api_sdk/models/morphodepositrequest.py +86 -0
  64. compass_api_sdk/models/morphogetmarketsresponse.py +17 -0
  65. compass_api_sdk/models/morphogetvaultsresponse.py +17 -0
  66. compass_api_sdk/models/morphomarket.py +80 -0
  67. compass_api_sdk/models/morphorepayrequest.py +79 -0
  68. compass_api_sdk/models/morphosetvaultallowancerequest.py +44 -0
  69. compass_api_sdk/models/morphosupplycollateralrequest.py +91 -0
  70. compass_api_sdk/models/morphovault.py +47 -0
  71. compass_api_sdk/models/morphowithdrawcollateralrequest.py +91 -0
  72. compass_api_sdk/models/morphowithdrawrequest.py +74 -0
  73. compass_api_sdk/models/portfolio.py +22 -0
  74. compass_api_sdk/models/priceresponse.py +15 -0
  75. compass_api_sdk/models/security.py +24 -0
  76. compass_api_sdk/models/token_addressop.py +98 -0
  77. compass_api_sdk/models/token_balanceop.py +49 -0
  78. compass_api_sdk/models/token_enum.py +57 -0
  79. compass_api_sdk/models/token_priceop.py +97 -0
  80. compass_api_sdk/models/tokenaddressresponse.py +15 -0
  81. compass_api_sdk/models/tokenbalance.py +49 -0
  82. compass_api_sdk/models/tokenbalanceresponse.py +44 -0
  83. compass_api_sdk/models/tokeninfo.py +17 -0
  84. compass_api_sdk/models/tokenpriceresponse.py +15 -0
  85. compass_api_sdk/models/tokentransferrequest.py +66 -0
  86. compass_api_sdk/models/transfererc20request.py +62 -0
  87. compass_api_sdk/models/transferethrequest.py +46 -0
  88. compass_api_sdk/models/uniswap_liquidity_provision_in_rangeop.py +34 -0
  89. compass_api_sdk/models/uniswap_liquidity_provision_positionsop.py +35 -0
  90. compass_api_sdk/models/uniswap_pool_priceop.py +193 -0
  91. compass_api_sdk/models/uniswap_quote_buy_exactlyop.py +209 -0
  92. compass_api_sdk/models/uniswap_quote_sell_exactlyop.py +209 -0
  93. compass_api_sdk/models/uniswapbuyexactlyrequest.py +104 -0
  94. compass_api_sdk/models/uniswapbuyquoteinforesponse.py +20 -0
  95. compass_api_sdk/models/uniswapcheckinrangeresponse.py +15 -0
  96. compass_api_sdk/models/uniswapincreaseliquidityprovisionrequest.py +99 -0
  97. compass_api_sdk/models/uniswaplppositionsinforesponse.py +24 -0
  98. compass_api_sdk/models/uniswapmintliquidityprovisionrequest.py +185 -0
  99. compass_api_sdk/models/uniswappoolpriceresponse.py +47 -0
  100. compass_api_sdk/models/uniswappositionssolidityresponse.py +46 -0
  101. compass_api_sdk/models/uniswapsellexactlyrequest.py +104 -0
  102. compass_api_sdk/models/uniswapsellquoteinforesponse.py +20 -0
  103. compass_api_sdk/models/uniswapwithdrawliquidityprovisionrequest.py +51 -0
  104. compass_api_sdk/models/unsignedtransaction.py +58 -0
  105. compass_api_sdk/models/unwrapwethrequest.py +41 -0
  106. compass_api_sdk/models/validationerror.py +26 -0
  107. compass_api_sdk/models/vaultstate.py +32 -0
  108. compass_api_sdk/models/weeklyapys.py +23 -0
  109. compass_api_sdk/models/wrapethrequest.py +41 -0
  110. compass_api_sdk/morpho.py +2577 -0
  111. compass_api_sdk/py.typed +1 -0
  112. compass_api_sdk/sdk.py +155 -0
  113. compass_api_sdk/sdkconfiguration.py +56 -0
  114. compass_api_sdk/token_sdk.py +861 -0
  115. compass_api_sdk/types/__init__.py +21 -0
  116. compass_api_sdk/types/basemodel.py +39 -0
  117. compass_api_sdk/uniswap_v3.py +2551 -0
  118. compass_api_sdk/universal.py +2625 -0
  119. compass_api_sdk/utils/__init__.py +100 -0
  120. compass_api_sdk/utils/annotations.py +55 -0
  121. compass_api_sdk/utils/datetimes.py +23 -0
  122. compass_api_sdk/utils/enums.py +74 -0
  123. compass_api_sdk/utils/eventstreaming.py +238 -0
  124. compass_api_sdk/utils/forms.py +202 -0
  125. compass_api_sdk/utils/headers.py +136 -0
  126. compass_api_sdk/utils/logger.py +22 -0
  127. compass_api_sdk/utils/metadata.py +118 -0
  128. compass_api_sdk/utils/queryparams.py +205 -0
  129. compass_api_sdk/utils/requestbodies.py +66 -0
  130. compass_api_sdk/utils/retries.py +217 -0
  131. compass_api_sdk/utils/security.py +174 -0
  132. compass_api_sdk/utils/serializers.py +248 -0
  133. compass_api_sdk/utils/url.py +155 -0
  134. compass_api_sdk/utils/values.py +137 -0
  135. compass_api_sdk-0.0.1.dist-info/METADATA +534 -0
  136. compass_api_sdk-0.0.1.dist-info/RECORD +137 -0
  137. compass_api_sdk-0.0.1.dist-info/WHEEL +4 -0
@@ -0,0 +1,2577 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from compass_api_sdk import errors, models, utils
5
+ from compass_api_sdk._hooks import HookContext
6
+ from compass_api_sdk.types import OptionalNullable, UNSET
7
+ from typing import Any, Mapping, Optional, Union
8
+
9
+
10
+ class Morpho(BaseSDK):
11
+ def vaults(
12
+ self,
13
+ *,
14
+ chain: Optional[
15
+ models.MorphoVaultsChain
16
+ ] = models.MorphoVaultsChain.ETHEREUM_MAINNET,
17
+ deposit_token: OptionalNullable[str] = UNSET,
18
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
19
+ server_url: Optional[str] = None,
20
+ timeout_ms: Optional[int] = None,
21
+ http_headers: Optional[Mapping[str, str]] = None,
22
+ ) -> models.MorphoGetVaultsResponse:
23
+ r"""Get Vaults
24
+
25
+ Query a list of vaults you can deposit into.
26
+
27
+ Each vault has one unique token that can be deposited. In exchange for depositing
28
+ tokens into a vault you receive shares. You earn yield on these shares by their
29
+ exchange value increasing over time.
30
+
31
+ :param chain: The chain to use.
32
+ :param deposit_token:
33
+ :param retries: Override the default retry configuration for this method
34
+ :param server_url: Override the default server URL for this method
35
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
36
+ :param http_headers: Additional headers to set or replace on requests.
37
+ """
38
+ base_url = None
39
+ url_variables = None
40
+ if timeout_ms is None:
41
+ timeout_ms = self.sdk_configuration.timeout_ms
42
+
43
+ if server_url is not None:
44
+ base_url = server_url
45
+ else:
46
+ base_url = self._get_url(base_url, url_variables)
47
+
48
+ request = models.MorphoVaultsRequest(
49
+ chain=chain,
50
+ deposit_token=deposit_token,
51
+ )
52
+
53
+ req = self._build_request(
54
+ method="GET",
55
+ path="/v0/morpho/vaults",
56
+ base_url=base_url,
57
+ url_variables=url_variables,
58
+ request=request,
59
+ request_body_required=False,
60
+ request_has_path_params=False,
61
+ request_has_query_params=True,
62
+ user_agent_header="user-agent",
63
+ accept_header_value="application/json",
64
+ http_headers=http_headers,
65
+ security=self.sdk_configuration.security,
66
+ timeout_ms=timeout_ms,
67
+ )
68
+
69
+ if retries == UNSET:
70
+ if self.sdk_configuration.retry_config is not UNSET:
71
+ retries = self.sdk_configuration.retry_config
72
+
73
+ retry_config = None
74
+ if isinstance(retries, utils.RetryConfig):
75
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
76
+
77
+ http_res = self.do_request(
78
+ hook_ctx=HookContext(
79
+ base_url=base_url or "",
80
+ operation_id="morpho_vaults",
81
+ oauth2_scopes=[],
82
+ security_source=self.sdk_configuration.security,
83
+ ),
84
+ request=req,
85
+ error_status_codes=["422", "4XX", "5XX"],
86
+ retry_config=retry_config,
87
+ )
88
+
89
+ response_data: Any = None
90
+ if utils.match_response(http_res, "200", "application/json"):
91
+ return utils.unmarshal_json(http_res.text, models.MorphoGetVaultsResponse)
92
+ if utils.match_response(http_res, "422", "application/json"):
93
+ response_data = utils.unmarshal_json(
94
+ http_res.text, errors.HTTPValidationErrorData
95
+ )
96
+ raise errors.HTTPValidationError(data=response_data)
97
+ if utils.match_response(http_res, "4XX", "*"):
98
+ http_res_text = utils.stream_to_text(http_res)
99
+ raise errors.APIError(
100
+ "API error occurred", http_res.status_code, http_res_text, http_res
101
+ )
102
+ if utils.match_response(http_res, "5XX", "*"):
103
+ http_res_text = utils.stream_to_text(http_res)
104
+ raise errors.APIError(
105
+ "API error occurred", http_res.status_code, http_res_text, http_res
106
+ )
107
+
108
+ content_type = http_res.headers.get("Content-Type")
109
+ http_res_text = utils.stream_to_text(http_res)
110
+ raise errors.APIError(
111
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
112
+ http_res.status_code,
113
+ http_res_text,
114
+ http_res,
115
+ )
116
+
117
+ async def vaults_async(
118
+ self,
119
+ *,
120
+ chain: Optional[
121
+ models.MorphoVaultsChain
122
+ ] = models.MorphoVaultsChain.ETHEREUM_MAINNET,
123
+ deposit_token: OptionalNullable[str] = UNSET,
124
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
125
+ server_url: Optional[str] = None,
126
+ timeout_ms: Optional[int] = None,
127
+ http_headers: Optional[Mapping[str, str]] = None,
128
+ ) -> models.MorphoGetVaultsResponse:
129
+ r"""Get Vaults
130
+
131
+ Query a list of vaults you can deposit into.
132
+
133
+ Each vault has one unique token that can be deposited. In exchange for depositing
134
+ tokens into a vault you receive shares. You earn yield on these shares by their
135
+ exchange value increasing over time.
136
+
137
+ :param chain: The chain to use.
138
+ :param deposit_token:
139
+ :param retries: Override the default retry configuration for this method
140
+ :param server_url: Override the default server URL for this method
141
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
142
+ :param http_headers: Additional headers to set or replace on requests.
143
+ """
144
+ base_url = None
145
+ url_variables = None
146
+ if timeout_ms is None:
147
+ timeout_ms = self.sdk_configuration.timeout_ms
148
+
149
+ if server_url is not None:
150
+ base_url = server_url
151
+ else:
152
+ base_url = self._get_url(base_url, url_variables)
153
+
154
+ request = models.MorphoVaultsRequest(
155
+ chain=chain,
156
+ deposit_token=deposit_token,
157
+ )
158
+
159
+ req = self._build_request_async(
160
+ method="GET",
161
+ path="/v0/morpho/vaults",
162
+ base_url=base_url,
163
+ url_variables=url_variables,
164
+ request=request,
165
+ request_body_required=False,
166
+ request_has_path_params=False,
167
+ request_has_query_params=True,
168
+ user_agent_header="user-agent",
169
+ accept_header_value="application/json",
170
+ http_headers=http_headers,
171
+ security=self.sdk_configuration.security,
172
+ timeout_ms=timeout_ms,
173
+ )
174
+
175
+ if retries == UNSET:
176
+ if self.sdk_configuration.retry_config is not UNSET:
177
+ retries = self.sdk_configuration.retry_config
178
+
179
+ retry_config = None
180
+ if isinstance(retries, utils.RetryConfig):
181
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
182
+
183
+ http_res = await self.do_request_async(
184
+ hook_ctx=HookContext(
185
+ base_url=base_url or "",
186
+ operation_id="morpho_vaults",
187
+ oauth2_scopes=[],
188
+ security_source=self.sdk_configuration.security,
189
+ ),
190
+ request=req,
191
+ error_status_codes=["422", "4XX", "5XX"],
192
+ retry_config=retry_config,
193
+ )
194
+
195
+ response_data: Any = None
196
+ if utils.match_response(http_res, "200", "application/json"):
197
+ return utils.unmarshal_json(http_res.text, models.MorphoGetVaultsResponse)
198
+ if utils.match_response(http_res, "422", "application/json"):
199
+ response_data = utils.unmarshal_json(
200
+ http_res.text, errors.HTTPValidationErrorData
201
+ )
202
+ raise errors.HTTPValidationError(data=response_data)
203
+ if utils.match_response(http_res, "4XX", "*"):
204
+ http_res_text = await utils.stream_to_text_async(http_res)
205
+ raise errors.APIError(
206
+ "API error occurred", http_res.status_code, http_res_text, http_res
207
+ )
208
+ if utils.match_response(http_res, "5XX", "*"):
209
+ http_res_text = await utils.stream_to_text_async(http_res)
210
+ raise errors.APIError(
211
+ "API error occurred", http_res.status_code, http_res_text, http_res
212
+ )
213
+
214
+ content_type = http_res.headers.get("Content-Type")
215
+ http_res_text = await utils.stream_to_text_async(http_res)
216
+ raise errors.APIError(
217
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
218
+ http_res.status_code,
219
+ http_res_text,
220
+ http_res,
221
+ )
222
+
223
+ def vault_position(
224
+ self,
225
+ *,
226
+ user_address: str = "0xa829B388A3DF7f581cE957a95edbe419dd146d1B",
227
+ vault_address: str = "0xbEef047a543E45807105E51A8BBEFCc5950fcfBa",
228
+ chain: Optional[
229
+ models.MorphoVaultPositionChain
230
+ ] = models.MorphoVaultPositionChain.ETHEREUM_MAINNET,
231
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
232
+ server_url: Optional[str] = None,
233
+ timeout_ms: Optional[int] = None,
234
+ http_headers: Optional[Mapping[str, str]] = None,
235
+ ) -> models.MorphoCheckVaultPositionResponse:
236
+ r"""Check Vault Position
237
+
238
+ Check how many shares you own and the equivalent token amount of a given
239
+ vault.
240
+
241
+ :param user_address:
242
+ :param vault_address:
243
+ :param chain: The chain to use.
244
+ :param retries: Override the default retry configuration for this method
245
+ :param server_url: Override the default server URL for this method
246
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
247
+ :param http_headers: Additional headers to set or replace on requests.
248
+ """
249
+ base_url = None
250
+ url_variables = None
251
+ if timeout_ms is None:
252
+ timeout_ms = self.sdk_configuration.timeout_ms
253
+
254
+ if server_url is not None:
255
+ base_url = server_url
256
+ else:
257
+ base_url = self._get_url(base_url, url_variables)
258
+
259
+ request = models.MorphoVaultPositionRequest(
260
+ chain=chain,
261
+ user_address=user_address,
262
+ vault_address=vault_address,
263
+ )
264
+
265
+ req = self._build_request(
266
+ method="GET",
267
+ path="/v0/morpho/vault_position",
268
+ base_url=base_url,
269
+ url_variables=url_variables,
270
+ request=request,
271
+ request_body_required=False,
272
+ request_has_path_params=False,
273
+ request_has_query_params=True,
274
+ user_agent_header="user-agent",
275
+ accept_header_value="application/json",
276
+ http_headers=http_headers,
277
+ security=self.sdk_configuration.security,
278
+ timeout_ms=timeout_ms,
279
+ )
280
+
281
+ if retries == UNSET:
282
+ if self.sdk_configuration.retry_config is not UNSET:
283
+ retries = self.sdk_configuration.retry_config
284
+
285
+ retry_config = None
286
+ if isinstance(retries, utils.RetryConfig):
287
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
288
+
289
+ http_res = self.do_request(
290
+ hook_ctx=HookContext(
291
+ base_url=base_url or "",
292
+ operation_id="morpho_vault_position",
293
+ oauth2_scopes=[],
294
+ security_source=self.sdk_configuration.security,
295
+ ),
296
+ request=req,
297
+ error_status_codes=["422", "4XX", "5XX"],
298
+ retry_config=retry_config,
299
+ )
300
+
301
+ response_data: Any = None
302
+ if utils.match_response(http_res, "200", "application/json"):
303
+ return utils.unmarshal_json(
304
+ http_res.text, models.MorphoCheckVaultPositionResponse
305
+ )
306
+ if utils.match_response(http_res, "422", "application/json"):
307
+ response_data = utils.unmarshal_json(
308
+ http_res.text, errors.HTTPValidationErrorData
309
+ )
310
+ raise errors.HTTPValidationError(data=response_data)
311
+ if utils.match_response(http_res, "4XX", "*"):
312
+ http_res_text = utils.stream_to_text(http_res)
313
+ raise errors.APIError(
314
+ "API error occurred", http_res.status_code, http_res_text, http_res
315
+ )
316
+ if utils.match_response(http_res, "5XX", "*"):
317
+ http_res_text = utils.stream_to_text(http_res)
318
+ raise errors.APIError(
319
+ "API error occurred", http_res.status_code, http_res_text, http_res
320
+ )
321
+
322
+ content_type = http_res.headers.get("Content-Type")
323
+ http_res_text = utils.stream_to_text(http_res)
324
+ raise errors.APIError(
325
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
326
+ http_res.status_code,
327
+ http_res_text,
328
+ http_res,
329
+ )
330
+
331
+ async def vault_position_async(
332
+ self,
333
+ *,
334
+ user_address: str = "0xa829B388A3DF7f581cE957a95edbe419dd146d1B",
335
+ vault_address: str = "0xbEef047a543E45807105E51A8BBEFCc5950fcfBa",
336
+ chain: Optional[
337
+ models.MorphoVaultPositionChain
338
+ ] = models.MorphoVaultPositionChain.ETHEREUM_MAINNET,
339
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
340
+ server_url: Optional[str] = None,
341
+ timeout_ms: Optional[int] = None,
342
+ http_headers: Optional[Mapping[str, str]] = None,
343
+ ) -> models.MorphoCheckVaultPositionResponse:
344
+ r"""Check Vault Position
345
+
346
+ Check how many shares you own and the equivalent token amount of a given
347
+ vault.
348
+
349
+ :param user_address:
350
+ :param vault_address:
351
+ :param chain: The chain to use.
352
+ :param retries: Override the default retry configuration for this method
353
+ :param server_url: Override the default server URL for this method
354
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
355
+ :param http_headers: Additional headers to set or replace on requests.
356
+ """
357
+ base_url = None
358
+ url_variables = None
359
+ if timeout_ms is None:
360
+ timeout_ms = self.sdk_configuration.timeout_ms
361
+
362
+ if server_url is not None:
363
+ base_url = server_url
364
+ else:
365
+ base_url = self._get_url(base_url, url_variables)
366
+
367
+ request = models.MorphoVaultPositionRequest(
368
+ chain=chain,
369
+ user_address=user_address,
370
+ vault_address=vault_address,
371
+ )
372
+
373
+ req = self._build_request_async(
374
+ method="GET",
375
+ path="/v0/morpho/vault_position",
376
+ base_url=base_url,
377
+ url_variables=url_variables,
378
+ request=request,
379
+ request_body_required=False,
380
+ request_has_path_params=False,
381
+ request_has_query_params=True,
382
+ user_agent_header="user-agent",
383
+ accept_header_value="application/json",
384
+ http_headers=http_headers,
385
+ security=self.sdk_configuration.security,
386
+ timeout_ms=timeout_ms,
387
+ )
388
+
389
+ if retries == UNSET:
390
+ if self.sdk_configuration.retry_config is not UNSET:
391
+ retries = self.sdk_configuration.retry_config
392
+
393
+ retry_config = None
394
+ if isinstance(retries, utils.RetryConfig):
395
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
396
+
397
+ http_res = await self.do_request_async(
398
+ hook_ctx=HookContext(
399
+ base_url=base_url or "",
400
+ operation_id="morpho_vault_position",
401
+ oauth2_scopes=[],
402
+ security_source=self.sdk_configuration.security,
403
+ ),
404
+ request=req,
405
+ error_status_codes=["422", "4XX", "5XX"],
406
+ retry_config=retry_config,
407
+ )
408
+
409
+ response_data: Any = None
410
+ if utils.match_response(http_res, "200", "application/json"):
411
+ return utils.unmarshal_json(
412
+ http_res.text, models.MorphoCheckVaultPositionResponse
413
+ )
414
+ if utils.match_response(http_res, "422", "application/json"):
415
+ response_data = utils.unmarshal_json(
416
+ http_res.text, errors.HTTPValidationErrorData
417
+ )
418
+ raise errors.HTTPValidationError(data=response_data)
419
+ if utils.match_response(http_res, "4XX", "*"):
420
+ http_res_text = await utils.stream_to_text_async(http_res)
421
+ raise errors.APIError(
422
+ "API error occurred", http_res.status_code, http_res_text, http_res
423
+ )
424
+ if utils.match_response(http_res, "5XX", "*"):
425
+ http_res_text = await utils.stream_to_text_async(http_res)
426
+ raise errors.APIError(
427
+ "API error occurred", http_res.status_code, http_res_text, http_res
428
+ )
429
+
430
+ content_type = http_res.headers.get("Content-Type")
431
+ http_res_text = await utils.stream_to_text_async(http_res)
432
+ raise errors.APIError(
433
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
434
+ http_res.status_code,
435
+ http_res_text,
436
+ http_res,
437
+ )
438
+
439
+ def markets(
440
+ self,
441
+ *,
442
+ chain: Optional[
443
+ models.MorphoMarketsChain
444
+ ] = models.MorphoMarketsChain.ETHEREUM_MAINNET,
445
+ collateral_token: OptionalNullable[str] = UNSET,
446
+ loan_token: OptionalNullable[str] = UNSET,
447
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
448
+ server_url: Optional[str] = None,
449
+ timeout_ms: Optional[int] = None,
450
+ http_headers: Optional[Mapping[str, str]] = None,
451
+ ) -> models.MorphoGetMarketsResponse:
452
+ r"""Get Markets
453
+
454
+ Query a list of markets you can borrow from.
455
+
456
+ Each market has one unique token that can be borrowed against one unique token that
457
+ can be used as collateral.
458
+
459
+ :param chain: The chain to use.
460
+ :param collateral_token:
461
+ :param loan_token:
462
+ :param retries: Override the default retry configuration for this method
463
+ :param server_url: Override the default server URL for this method
464
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
465
+ :param http_headers: Additional headers to set or replace on requests.
466
+ """
467
+ base_url = None
468
+ url_variables = None
469
+ if timeout_ms is None:
470
+ timeout_ms = self.sdk_configuration.timeout_ms
471
+
472
+ if server_url is not None:
473
+ base_url = server_url
474
+ else:
475
+ base_url = self._get_url(base_url, url_variables)
476
+
477
+ request = models.MorphoMarketsRequest(
478
+ chain=chain,
479
+ collateral_token=collateral_token,
480
+ loan_token=loan_token,
481
+ )
482
+
483
+ req = self._build_request(
484
+ method="GET",
485
+ path="/v0/morpho/markets",
486
+ base_url=base_url,
487
+ url_variables=url_variables,
488
+ request=request,
489
+ request_body_required=False,
490
+ request_has_path_params=False,
491
+ request_has_query_params=True,
492
+ user_agent_header="user-agent",
493
+ accept_header_value="application/json",
494
+ http_headers=http_headers,
495
+ security=self.sdk_configuration.security,
496
+ timeout_ms=timeout_ms,
497
+ )
498
+
499
+ if retries == UNSET:
500
+ if self.sdk_configuration.retry_config is not UNSET:
501
+ retries = self.sdk_configuration.retry_config
502
+
503
+ retry_config = None
504
+ if isinstance(retries, utils.RetryConfig):
505
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
506
+
507
+ http_res = self.do_request(
508
+ hook_ctx=HookContext(
509
+ base_url=base_url or "",
510
+ operation_id="morpho_markets",
511
+ oauth2_scopes=[],
512
+ security_source=self.sdk_configuration.security,
513
+ ),
514
+ request=req,
515
+ error_status_codes=["422", "4XX", "5XX"],
516
+ retry_config=retry_config,
517
+ )
518
+
519
+ response_data: Any = None
520
+ if utils.match_response(http_res, "200", "application/json"):
521
+ return utils.unmarshal_json(http_res.text, models.MorphoGetMarketsResponse)
522
+ if utils.match_response(http_res, "422", "application/json"):
523
+ response_data = utils.unmarshal_json(
524
+ http_res.text, errors.HTTPValidationErrorData
525
+ )
526
+ raise errors.HTTPValidationError(data=response_data)
527
+ if utils.match_response(http_res, "4XX", "*"):
528
+ http_res_text = utils.stream_to_text(http_res)
529
+ raise errors.APIError(
530
+ "API error occurred", http_res.status_code, http_res_text, http_res
531
+ )
532
+ if utils.match_response(http_res, "5XX", "*"):
533
+ http_res_text = utils.stream_to_text(http_res)
534
+ raise errors.APIError(
535
+ "API error occurred", http_res.status_code, http_res_text, http_res
536
+ )
537
+
538
+ content_type = http_res.headers.get("Content-Type")
539
+ http_res_text = utils.stream_to_text(http_res)
540
+ raise errors.APIError(
541
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
542
+ http_res.status_code,
543
+ http_res_text,
544
+ http_res,
545
+ )
546
+
547
+ async def markets_async(
548
+ self,
549
+ *,
550
+ chain: Optional[
551
+ models.MorphoMarketsChain
552
+ ] = models.MorphoMarketsChain.ETHEREUM_MAINNET,
553
+ collateral_token: OptionalNullable[str] = UNSET,
554
+ loan_token: OptionalNullable[str] = UNSET,
555
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
556
+ server_url: Optional[str] = None,
557
+ timeout_ms: Optional[int] = None,
558
+ http_headers: Optional[Mapping[str, str]] = None,
559
+ ) -> models.MorphoGetMarketsResponse:
560
+ r"""Get Markets
561
+
562
+ Query a list of markets you can borrow from.
563
+
564
+ Each market has one unique token that can be borrowed against one unique token that
565
+ can be used as collateral.
566
+
567
+ :param chain: The chain to use.
568
+ :param collateral_token:
569
+ :param loan_token:
570
+ :param retries: Override the default retry configuration for this method
571
+ :param server_url: Override the default server URL for this method
572
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
573
+ :param http_headers: Additional headers to set or replace on requests.
574
+ """
575
+ base_url = None
576
+ url_variables = None
577
+ if timeout_ms is None:
578
+ timeout_ms = self.sdk_configuration.timeout_ms
579
+
580
+ if server_url is not None:
581
+ base_url = server_url
582
+ else:
583
+ base_url = self._get_url(base_url, url_variables)
584
+
585
+ request = models.MorphoMarketsRequest(
586
+ chain=chain,
587
+ collateral_token=collateral_token,
588
+ loan_token=loan_token,
589
+ )
590
+
591
+ req = self._build_request_async(
592
+ method="GET",
593
+ path="/v0/morpho/markets",
594
+ base_url=base_url,
595
+ url_variables=url_variables,
596
+ request=request,
597
+ request_body_required=False,
598
+ request_has_path_params=False,
599
+ request_has_query_params=True,
600
+ user_agent_header="user-agent",
601
+ accept_header_value="application/json",
602
+ http_headers=http_headers,
603
+ security=self.sdk_configuration.security,
604
+ timeout_ms=timeout_ms,
605
+ )
606
+
607
+ if retries == UNSET:
608
+ if self.sdk_configuration.retry_config is not UNSET:
609
+ retries = self.sdk_configuration.retry_config
610
+
611
+ retry_config = None
612
+ if isinstance(retries, utils.RetryConfig):
613
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
614
+
615
+ http_res = await self.do_request_async(
616
+ hook_ctx=HookContext(
617
+ base_url=base_url or "",
618
+ operation_id="morpho_markets",
619
+ oauth2_scopes=[],
620
+ security_source=self.sdk_configuration.security,
621
+ ),
622
+ request=req,
623
+ error_status_codes=["422", "4XX", "5XX"],
624
+ retry_config=retry_config,
625
+ )
626
+
627
+ response_data: Any = None
628
+ if utils.match_response(http_res, "200", "application/json"):
629
+ return utils.unmarshal_json(http_res.text, models.MorphoGetMarketsResponse)
630
+ if utils.match_response(http_res, "422", "application/json"):
631
+ response_data = utils.unmarshal_json(
632
+ http_res.text, errors.HTTPValidationErrorData
633
+ )
634
+ raise errors.HTTPValidationError(data=response_data)
635
+ if utils.match_response(http_res, "4XX", "*"):
636
+ http_res_text = await utils.stream_to_text_async(http_res)
637
+ raise errors.APIError(
638
+ "API error occurred", http_res.status_code, http_res_text, http_res
639
+ )
640
+ if utils.match_response(http_res, "5XX", "*"):
641
+ http_res_text = await utils.stream_to_text_async(http_res)
642
+ raise errors.APIError(
643
+ "API error occurred", http_res.status_code, http_res_text, http_res
644
+ )
645
+
646
+ content_type = http_res.headers.get("Content-Type")
647
+ http_res_text = await utils.stream_to_text_async(http_res)
648
+ raise errors.APIError(
649
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
650
+ http_res.status_code,
651
+ http_res_text,
652
+ http_res,
653
+ )
654
+
655
+ def market_position(
656
+ self,
657
+ *,
658
+ user_address: str = "0xa829B388A3DF7f581cE957a95edbe419dd146d1B",
659
+ unique_market_key: str = "0xe7399fdebc318d76dfec7356caafcf8cd4b91287e139a3ec423f09aeeb656fc4",
660
+ chain: Optional[
661
+ models.MorphoMarketPositionChain
662
+ ] = models.MorphoMarketPositionChain.ETHEREUM_MAINNET,
663
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
664
+ server_url: Optional[str] = None,
665
+ timeout_ms: Optional[int] = None,
666
+ http_headers: Optional[Mapping[str, str]] = None,
667
+ ) -> models.MorphoCheckMarketPositionResponse:
668
+ r"""Check Market Position
669
+
670
+ Check how many shares you've borrowed and the equivalent token amount of a given
671
+ market.
672
+
673
+ :param user_address:
674
+ :param unique_market_key:
675
+ :param chain: The chain to use.
676
+ :param retries: Override the default retry configuration for this method
677
+ :param server_url: Override the default server URL for this method
678
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
679
+ :param http_headers: Additional headers to set or replace on requests.
680
+ """
681
+ base_url = None
682
+ url_variables = None
683
+ if timeout_ms is None:
684
+ timeout_ms = self.sdk_configuration.timeout_ms
685
+
686
+ if server_url is not None:
687
+ base_url = server_url
688
+ else:
689
+ base_url = self._get_url(base_url, url_variables)
690
+
691
+ request = models.MorphoMarketPositionRequest(
692
+ chain=chain,
693
+ user_address=user_address,
694
+ unique_market_key=unique_market_key,
695
+ )
696
+
697
+ req = self._build_request(
698
+ method="GET",
699
+ path="/v0/morpho/market_position",
700
+ base_url=base_url,
701
+ url_variables=url_variables,
702
+ request=request,
703
+ request_body_required=False,
704
+ request_has_path_params=False,
705
+ request_has_query_params=True,
706
+ user_agent_header="user-agent",
707
+ accept_header_value="application/json",
708
+ http_headers=http_headers,
709
+ security=self.sdk_configuration.security,
710
+ timeout_ms=timeout_ms,
711
+ )
712
+
713
+ if retries == UNSET:
714
+ if self.sdk_configuration.retry_config is not UNSET:
715
+ retries = self.sdk_configuration.retry_config
716
+
717
+ retry_config = None
718
+ if isinstance(retries, utils.RetryConfig):
719
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
720
+
721
+ http_res = self.do_request(
722
+ hook_ctx=HookContext(
723
+ base_url=base_url or "",
724
+ operation_id="morpho_market_position",
725
+ oauth2_scopes=[],
726
+ security_source=self.sdk_configuration.security,
727
+ ),
728
+ request=req,
729
+ error_status_codes=["422", "4XX", "5XX"],
730
+ retry_config=retry_config,
731
+ )
732
+
733
+ response_data: Any = None
734
+ if utils.match_response(http_res, "200", "application/json"):
735
+ return utils.unmarshal_json(
736
+ http_res.text, models.MorphoCheckMarketPositionResponse
737
+ )
738
+ if utils.match_response(http_res, "422", "application/json"):
739
+ response_data = utils.unmarshal_json(
740
+ http_res.text, errors.HTTPValidationErrorData
741
+ )
742
+ raise errors.HTTPValidationError(data=response_data)
743
+ if utils.match_response(http_res, "4XX", "*"):
744
+ http_res_text = utils.stream_to_text(http_res)
745
+ raise errors.APIError(
746
+ "API error occurred", http_res.status_code, http_res_text, http_res
747
+ )
748
+ if utils.match_response(http_res, "5XX", "*"):
749
+ http_res_text = utils.stream_to_text(http_res)
750
+ raise errors.APIError(
751
+ "API error occurred", http_res.status_code, http_res_text, http_res
752
+ )
753
+
754
+ content_type = http_res.headers.get("Content-Type")
755
+ http_res_text = utils.stream_to_text(http_res)
756
+ raise errors.APIError(
757
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
758
+ http_res.status_code,
759
+ http_res_text,
760
+ http_res,
761
+ )
762
+
763
+ async def market_position_async(
764
+ self,
765
+ *,
766
+ user_address: str = "0xa829B388A3DF7f581cE957a95edbe419dd146d1B",
767
+ unique_market_key: str = "0xe7399fdebc318d76dfec7356caafcf8cd4b91287e139a3ec423f09aeeb656fc4",
768
+ chain: Optional[
769
+ models.MorphoMarketPositionChain
770
+ ] = models.MorphoMarketPositionChain.ETHEREUM_MAINNET,
771
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
772
+ server_url: Optional[str] = None,
773
+ timeout_ms: Optional[int] = None,
774
+ http_headers: Optional[Mapping[str, str]] = None,
775
+ ) -> models.MorphoCheckMarketPositionResponse:
776
+ r"""Check Market Position
777
+
778
+ Check how many shares you've borrowed and the equivalent token amount of a given
779
+ market.
780
+
781
+ :param user_address:
782
+ :param unique_market_key:
783
+ :param chain: The chain to use.
784
+ :param retries: Override the default retry configuration for this method
785
+ :param server_url: Override the default server URL for this method
786
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
787
+ :param http_headers: Additional headers to set or replace on requests.
788
+ """
789
+ base_url = None
790
+ url_variables = None
791
+ if timeout_ms is None:
792
+ timeout_ms = self.sdk_configuration.timeout_ms
793
+
794
+ if server_url is not None:
795
+ base_url = server_url
796
+ else:
797
+ base_url = self._get_url(base_url, url_variables)
798
+
799
+ request = models.MorphoMarketPositionRequest(
800
+ chain=chain,
801
+ user_address=user_address,
802
+ unique_market_key=unique_market_key,
803
+ )
804
+
805
+ req = self._build_request_async(
806
+ method="GET",
807
+ path="/v0/morpho/market_position",
808
+ base_url=base_url,
809
+ url_variables=url_variables,
810
+ request=request,
811
+ request_body_required=False,
812
+ request_has_path_params=False,
813
+ request_has_query_params=True,
814
+ user_agent_header="user-agent",
815
+ accept_header_value="application/json",
816
+ http_headers=http_headers,
817
+ security=self.sdk_configuration.security,
818
+ timeout_ms=timeout_ms,
819
+ )
820
+
821
+ if retries == UNSET:
822
+ if self.sdk_configuration.retry_config is not UNSET:
823
+ retries = self.sdk_configuration.retry_config
824
+
825
+ retry_config = None
826
+ if isinstance(retries, utils.RetryConfig):
827
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
828
+
829
+ http_res = await self.do_request_async(
830
+ hook_ctx=HookContext(
831
+ base_url=base_url or "",
832
+ operation_id="morpho_market_position",
833
+ oauth2_scopes=[],
834
+ security_source=self.sdk_configuration.security,
835
+ ),
836
+ request=req,
837
+ error_status_codes=["422", "4XX", "5XX"],
838
+ retry_config=retry_config,
839
+ )
840
+
841
+ response_data: Any = None
842
+ if utils.match_response(http_res, "200", "application/json"):
843
+ return utils.unmarshal_json(
844
+ http_res.text, models.MorphoCheckMarketPositionResponse
845
+ )
846
+ if utils.match_response(http_res, "422", "application/json"):
847
+ response_data = utils.unmarshal_json(
848
+ http_res.text, errors.HTTPValidationErrorData
849
+ )
850
+ raise errors.HTTPValidationError(data=response_data)
851
+ if utils.match_response(http_res, "4XX", "*"):
852
+ http_res_text = await utils.stream_to_text_async(http_res)
853
+ raise errors.APIError(
854
+ "API error occurred", http_res.status_code, http_res_text, http_res
855
+ )
856
+ if utils.match_response(http_res, "5XX", "*"):
857
+ http_res_text = await utils.stream_to_text_async(http_res)
858
+ raise errors.APIError(
859
+ "API error occurred", http_res.status_code, http_res_text, http_res
860
+ )
861
+
862
+ content_type = http_res.headers.get("Content-Type")
863
+ http_res_text = await utils.stream_to_text_async(http_res)
864
+ raise errors.APIError(
865
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
866
+ http_res.status_code,
867
+ http_res_text,
868
+ http_res,
869
+ )
870
+
871
+ def allowance(
872
+ self,
873
+ *,
874
+ vault_address: str,
875
+ amount: Union[
876
+ models.MorphoSetVaultAllowanceRequestAmount,
877
+ models.MorphoSetVaultAllowanceRequestAmountTypedDict,
878
+ ],
879
+ chain: models.Chain,
880
+ sender: str,
881
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
882
+ server_url: Optional[str] = None,
883
+ timeout_ms: Optional[int] = None,
884
+ http_headers: Optional[Mapping[str, str]] = None,
885
+ ) -> models.UnsignedTransaction:
886
+ r"""Set Allowance for Vault
887
+
888
+ Set an allowance for a Morpho vault. You must set this for at least the amount you wish to deposit - before depositing.
889
+
890
+ Each vault has only one associated token that can be deposited.
891
+
892
+ Use the 'Get Vaults' endpoint to query a list of vaults you can deposit into.
893
+
894
+ :param vault_address: The vault address you are increasing the allowance for.
895
+ :param amount: The amount of tokens to increase the allowance by.
896
+ :param chain: The chain to use.
897
+ :param sender: The address of the transaction sender.
898
+ :param retries: Override the default retry configuration for this method
899
+ :param server_url: Override the default server URL for this method
900
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
901
+ :param http_headers: Additional headers to set or replace on requests.
902
+ """
903
+ base_url = None
904
+ url_variables = None
905
+ if timeout_ms is None:
906
+ timeout_ms = self.sdk_configuration.timeout_ms
907
+
908
+ if server_url is not None:
909
+ base_url = server_url
910
+ else:
911
+ base_url = self._get_url(base_url, url_variables)
912
+
913
+ request = models.MorphoSetVaultAllowanceRequest(
914
+ vault_address=vault_address,
915
+ amount=amount,
916
+ chain=chain,
917
+ sender=sender,
918
+ )
919
+
920
+ req = self._build_request(
921
+ method="POST",
922
+ path="/v0/morpho/allowance",
923
+ base_url=base_url,
924
+ url_variables=url_variables,
925
+ request=request,
926
+ request_body_required=True,
927
+ request_has_path_params=False,
928
+ request_has_query_params=True,
929
+ user_agent_header="user-agent",
930
+ accept_header_value="application/json",
931
+ http_headers=http_headers,
932
+ security=self.sdk_configuration.security,
933
+ get_serialized_body=lambda: utils.serialize_request_body(
934
+ request, False, False, "json", models.MorphoSetVaultAllowanceRequest
935
+ ),
936
+ timeout_ms=timeout_ms,
937
+ )
938
+
939
+ if retries == UNSET:
940
+ if self.sdk_configuration.retry_config is not UNSET:
941
+ retries = self.sdk_configuration.retry_config
942
+
943
+ retry_config = None
944
+ if isinstance(retries, utils.RetryConfig):
945
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
946
+
947
+ http_res = self.do_request(
948
+ hook_ctx=HookContext(
949
+ base_url=base_url or "",
950
+ operation_id="morpho_allowance",
951
+ oauth2_scopes=[],
952
+ security_source=self.sdk_configuration.security,
953
+ ),
954
+ request=req,
955
+ error_status_codes=["422", "4XX", "5XX"],
956
+ retry_config=retry_config,
957
+ )
958
+
959
+ response_data: Any = None
960
+ if utils.match_response(http_res, "200", "application/json"):
961
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
962
+ if utils.match_response(http_res, "422", "application/json"):
963
+ response_data = utils.unmarshal_json(
964
+ http_res.text, errors.HTTPValidationErrorData
965
+ )
966
+ raise errors.HTTPValidationError(data=response_data)
967
+ if utils.match_response(http_res, "4XX", "*"):
968
+ http_res_text = utils.stream_to_text(http_res)
969
+ raise errors.APIError(
970
+ "API error occurred", http_res.status_code, http_res_text, http_res
971
+ )
972
+ if utils.match_response(http_res, "5XX", "*"):
973
+ http_res_text = utils.stream_to_text(http_res)
974
+ raise errors.APIError(
975
+ "API error occurred", http_res.status_code, http_res_text, http_res
976
+ )
977
+
978
+ content_type = http_res.headers.get("Content-Type")
979
+ http_res_text = utils.stream_to_text(http_res)
980
+ raise errors.APIError(
981
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
982
+ http_res.status_code,
983
+ http_res_text,
984
+ http_res,
985
+ )
986
+
987
+ async def allowance_async(
988
+ self,
989
+ *,
990
+ vault_address: str,
991
+ amount: Union[
992
+ models.MorphoSetVaultAllowanceRequestAmount,
993
+ models.MorphoSetVaultAllowanceRequestAmountTypedDict,
994
+ ],
995
+ chain: models.Chain,
996
+ sender: str,
997
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
998
+ server_url: Optional[str] = None,
999
+ timeout_ms: Optional[int] = None,
1000
+ http_headers: Optional[Mapping[str, str]] = None,
1001
+ ) -> models.UnsignedTransaction:
1002
+ r"""Set Allowance for Vault
1003
+
1004
+ Set an allowance for a Morpho vault. You must set this for at least the amount you wish to deposit - before depositing.
1005
+
1006
+ Each vault has only one associated token that can be deposited.
1007
+
1008
+ Use the 'Get Vaults' endpoint to query a list of vaults you can deposit into.
1009
+
1010
+ :param vault_address: The vault address you are increasing the allowance for.
1011
+ :param amount: The amount of tokens to increase the allowance by.
1012
+ :param chain: The chain to use.
1013
+ :param sender: The address of the transaction sender.
1014
+ :param retries: Override the default retry configuration for this method
1015
+ :param server_url: Override the default server URL for this method
1016
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1017
+ :param http_headers: Additional headers to set or replace on requests.
1018
+ """
1019
+ base_url = None
1020
+ url_variables = None
1021
+ if timeout_ms is None:
1022
+ timeout_ms = self.sdk_configuration.timeout_ms
1023
+
1024
+ if server_url is not None:
1025
+ base_url = server_url
1026
+ else:
1027
+ base_url = self._get_url(base_url, url_variables)
1028
+
1029
+ request = models.MorphoSetVaultAllowanceRequest(
1030
+ vault_address=vault_address,
1031
+ amount=amount,
1032
+ chain=chain,
1033
+ sender=sender,
1034
+ )
1035
+
1036
+ req = self._build_request_async(
1037
+ method="POST",
1038
+ path="/v0/morpho/allowance",
1039
+ base_url=base_url,
1040
+ url_variables=url_variables,
1041
+ request=request,
1042
+ request_body_required=True,
1043
+ request_has_path_params=False,
1044
+ request_has_query_params=True,
1045
+ user_agent_header="user-agent",
1046
+ accept_header_value="application/json",
1047
+ http_headers=http_headers,
1048
+ security=self.sdk_configuration.security,
1049
+ get_serialized_body=lambda: utils.serialize_request_body(
1050
+ request, False, False, "json", models.MorphoSetVaultAllowanceRequest
1051
+ ),
1052
+ timeout_ms=timeout_ms,
1053
+ )
1054
+
1055
+ if retries == UNSET:
1056
+ if self.sdk_configuration.retry_config is not UNSET:
1057
+ retries = self.sdk_configuration.retry_config
1058
+
1059
+ retry_config = None
1060
+ if isinstance(retries, utils.RetryConfig):
1061
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1062
+
1063
+ http_res = await self.do_request_async(
1064
+ hook_ctx=HookContext(
1065
+ base_url=base_url or "",
1066
+ operation_id="morpho_allowance",
1067
+ oauth2_scopes=[],
1068
+ security_source=self.sdk_configuration.security,
1069
+ ),
1070
+ request=req,
1071
+ error_status_codes=["422", "4XX", "5XX"],
1072
+ retry_config=retry_config,
1073
+ )
1074
+
1075
+ response_data: Any = None
1076
+ if utils.match_response(http_res, "200", "application/json"):
1077
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
1078
+ if utils.match_response(http_res, "422", "application/json"):
1079
+ response_data = utils.unmarshal_json(
1080
+ http_res.text, errors.HTTPValidationErrorData
1081
+ )
1082
+ raise errors.HTTPValidationError(data=response_data)
1083
+ if utils.match_response(http_res, "4XX", "*"):
1084
+ http_res_text = await utils.stream_to_text_async(http_res)
1085
+ raise errors.APIError(
1086
+ "API error occurred", http_res.status_code, http_res_text, http_res
1087
+ )
1088
+ if utils.match_response(http_res, "5XX", "*"):
1089
+ http_res_text = await utils.stream_to_text_async(http_res)
1090
+ raise errors.APIError(
1091
+ "API error occurred", http_res.status_code, http_res_text, http_res
1092
+ )
1093
+
1094
+ content_type = http_res.headers.get("Content-Type")
1095
+ http_res_text = await utils.stream_to_text_async(http_res)
1096
+ raise errors.APIError(
1097
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1098
+ http_res.status_code,
1099
+ http_res_text,
1100
+ http_res,
1101
+ )
1102
+
1103
+ def deposit(
1104
+ self,
1105
+ *,
1106
+ vault_address: str,
1107
+ amount: Union[
1108
+ models.MorphoDepositRequestAmount,
1109
+ models.MorphoDepositRequestAmountTypedDict,
1110
+ ],
1111
+ chain: models.Chain,
1112
+ sender: str,
1113
+ receiver: OptionalNullable[str] = UNSET,
1114
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1115
+ server_url: Optional[str] = None,
1116
+ timeout_ms: Optional[int] = None,
1117
+ http_headers: Optional[Mapping[str, str]] = None,
1118
+ ) -> models.UnsignedTransaction:
1119
+ r"""Deposit to Vault
1120
+
1121
+ Deposit tokens into a Morpho Vault to earn passive yield from interest paid by
1122
+ borrowers.
1123
+
1124
+ Each vault accepts one unique token that can be deposited.
1125
+
1126
+ A Morpho Vault has one loan asset and can allocate deposits to multiple Morpho
1127
+ markets. Users can deposit into a vault to start earning passive yield from interest
1128
+ paid by borrowers. Vaults feature automated risk management, actively curating risk
1129
+ exposure for all deposited assets so users don't need to make these decisions
1130
+ themselves. Users maintain full control over their assets, can monitor the vault's
1131
+ state at any time, and withdraw their liquidity at their discretion.
1132
+
1133
+ :param vault_address: The vault address you are depositing to.
1134
+ :param amount: The amount of tokens to deposit into the vault.
1135
+ :param chain: The chain to use.
1136
+ :param sender: The address of the transaction sender.
1137
+ :param receiver: The address which will receive the shares from the vault representing their proportional ownership of the vault's assets. Defaults to the sender.
1138
+ :param retries: Override the default retry configuration for this method
1139
+ :param server_url: Override the default server URL for this method
1140
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1141
+ :param http_headers: Additional headers to set or replace on requests.
1142
+ """
1143
+ base_url = None
1144
+ url_variables = None
1145
+ if timeout_ms is None:
1146
+ timeout_ms = self.sdk_configuration.timeout_ms
1147
+
1148
+ if server_url is not None:
1149
+ base_url = server_url
1150
+ else:
1151
+ base_url = self._get_url(base_url, url_variables)
1152
+
1153
+ request = models.MorphoDepositRequest(
1154
+ vault_address=vault_address,
1155
+ amount=amount,
1156
+ receiver=receiver,
1157
+ chain=chain,
1158
+ sender=sender,
1159
+ )
1160
+
1161
+ req = self._build_request(
1162
+ method="POST",
1163
+ path="/v0/morpho/deposit",
1164
+ base_url=base_url,
1165
+ url_variables=url_variables,
1166
+ request=request,
1167
+ request_body_required=True,
1168
+ request_has_path_params=False,
1169
+ request_has_query_params=True,
1170
+ user_agent_header="user-agent",
1171
+ accept_header_value="application/json",
1172
+ http_headers=http_headers,
1173
+ security=self.sdk_configuration.security,
1174
+ get_serialized_body=lambda: utils.serialize_request_body(
1175
+ request, False, False, "json", models.MorphoDepositRequest
1176
+ ),
1177
+ timeout_ms=timeout_ms,
1178
+ )
1179
+
1180
+ if retries == UNSET:
1181
+ if self.sdk_configuration.retry_config is not UNSET:
1182
+ retries = self.sdk_configuration.retry_config
1183
+
1184
+ retry_config = None
1185
+ if isinstance(retries, utils.RetryConfig):
1186
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1187
+
1188
+ http_res = self.do_request(
1189
+ hook_ctx=HookContext(
1190
+ base_url=base_url or "",
1191
+ operation_id="morpho_deposit",
1192
+ oauth2_scopes=[],
1193
+ security_source=self.sdk_configuration.security,
1194
+ ),
1195
+ request=req,
1196
+ error_status_codes=["422", "4XX", "5XX"],
1197
+ retry_config=retry_config,
1198
+ )
1199
+
1200
+ response_data: Any = None
1201
+ if utils.match_response(http_res, "200", "application/json"):
1202
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
1203
+ if utils.match_response(http_res, "422", "application/json"):
1204
+ response_data = utils.unmarshal_json(
1205
+ http_res.text, errors.HTTPValidationErrorData
1206
+ )
1207
+ raise errors.HTTPValidationError(data=response_data)
1208
+ if utils.match_response(http_res, "4XX", "*"):
1209
+ http_res_text = utils.stream_to_text(http_res)
1210
+ raise errors.APIError(
1211
+ "API error occurred", http_res.status_code, http_res_text, http_res
1212
+ )
1213
+ if utils.match_response(http_res, "5XX", "*"):
1214
+ http_res_text = utils.stream_to_text(http_res)
1215
+ raise errors.APIError(
1216
+ "API error occurred", http_res.status_code, http_res_text, http_res
1217
+ )
1218
+
1219
+ content_type = http_res.headers.get("Content-Type")
1220
+ http_res_text = utils.stream_to_text(http_res)
1221
+ raise errors.APIError(
1222
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1223
+ http_res.status_code,
1224
+ http_res_text,
1225
+ http_res,
1226
+ )
1227
+
1228
+ async def deposit_async(
1229
+ self,
1230
+ *,
1231
+ vault_address: str,
1232
+ amount: Union[
1233
+ models.MorphoDepositRequestAmount,
1234
+ models.MorphoDepositRequestAmountTypedDict,
1235
+ ],
1236
+ chain: models.Chain,
1237
+ sender: str,
1238
+ receiver: OptionalNullable[str] = UNSET,
1239
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1240
+ server_url: Optional[str] = None,
1241
+ timeout_ms: Optional[int] = None,
1242
+ http_headers: Optional[Mapping[str, str]] = None,
1243
+ ) -> models.UnsignedTransaction:
1244
+ r"""Deposit to Vault
1245
+
1246
+ Deposit tokens into a Morpho Vault to earn passive yield from interest paid by
1247
+ borrowers.
1248
+
1249
+ Each vault accepts one unique token that can be deposited.
1250
+
1251
+ A Morpho Vault has one loan asset and can allocate deposits to multiple Morpho
1252
+ markets. Users can deposit into a vault to start earning passive yield from interest
1253
+ paid by borrowers. Vaults feature automated risk management, actively curating risk
1254
+ exposure for all deposited assets so users don't need to make these decisions
1255
+ themselves. Users maintain full control over their assets, can monitor the vault's
1256
+ state at any time, and withdraw their liquidity at their discretion.
1257
+
1258
+ :param vault_address: The vault address you are depositing to.
1259
+ :param amount: The amount of tokens to deposit into the vault.
1260
+ :param chain: The chain to use.
1261
+ :param sender: The address of the transaction sender.
1262
+ :param receiver: The address which will receive the shares from the vault representing their proportional ownership of the vault's assets. Defaults to the sender.
1263
+ :param retries: Override the default retry configuration for this method
1264
+ :param server_url: Override the default server URL for this method
1265
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1266
+ :param http_headers: Additional headers to set or replace on requests.
1267
+ """
1268
+ base_url = None
1269
+ url_variables = None
1270
+ if timeout_ms is None:
1271
+ timeout_ms = self.sdk_configuration.timeout_ms
1272
+
1273
+ if server_url is not None:
1274
+ base_url = server_url
1275
+ else:
1276
+ base_url = self._get_url(base_url, url_variables)
1277
+
1278
+ request = models.MorphoDepositRequest(
1279
+ vault_address=vault_address,
1280
+ amount=amount,
1281
+ receiver=receiver,
1282
+ chain=chain,
1283
+ sender=sender,
1284
+ )
1285
+
1286
+ req = self._build_request_async(
1287
+ method="POST",
1288
+ path="/v0/morpho/deposit",
1289
+ base_url=base_url,
1290
+ url_variables=url_variables,
1291
+ request=request,
1292
+ request_body_required=True,
1293
+ request_has_path_params=False,
1294
+ request_has_query_params=True,
1295
+ user_agent_header="user-agent",
1296
+ accept_header_value="application/json",
1297
+ http_headers=http_headers,
1298
+ security=self.sdk_configuration.security,
1299
+ get_serialized_body=lambda: utils.serialize_request_body(
1300
+ request, False, False, "json", models.MorphoDepositRequest
1301
+ ),
1302
+ timeout_ms=timeout_ms,
1303
+ )
1304
+
1305
+ if retries == UNSET:
1306
+ if self.sdk_configuration.retry_config is not UNSET:
1307
+ retries = self.sdk_configuration.retry_config
1308
+
1309
+ retry_config = None
1310
+ if isinstance(retries, utils.RetryConfig):
1311
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1312
+
1313
+ http_res = await self.do_request_async(
1314
+ hook_ctx=HookContext(
1315
+ base_url=base_url or "",
1316
+ operation_id="morpho_deposit",
1317
+ oauth2_scopes=[],
1318
+ security_source=self.sdk_configuration.security,
1319
+ ),
1320
+ request=req,
1321
+ error_status_codes=["422", "4XX", "5XX"],
1322
+ retry_config=retry_config,
1323
+ )
1324
+
1325
+ response_data: Any = None
1326
+ if utils.match_response(http_res, "200", "application/json"):
1327
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
1328
+ if utils.match_response(http_res, "422", "application/json"):
1329
+ response_data = utils.unmarshal_json(
1330
+ http_res.text, errors.HTTPValidationErrorData
1331
+ )
1332
+ raise errors.HTTPValidationError(data=response_data)
1333
+ if utils.match_response(http_res, "4XX", "*"):
1334
+ http_res_text = await utils.stream_to_text_async(http_res)
1335
+ raise errors.APIError(
1336
+ "API error occurred", http_res.status_code, http_res_text, http_res
1337
+ )
1338
+ if utils.match_response(http_res, "5XX", "*"):
1339
+ http_res_text = await utils.stream_to_text_async(http_res)
1340
+ raise errors.APIError(
1341
+ "API error occurred", http_res.status_code, http_res_text, http_res
1342
+ )
1343
+
1344
+ content_type = http_res.headers.get("Content-Type")
1345
+ http_res_text = await utils.stream_to_text_async(http_res)
1346
+ raise errors.APIError(
1347
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1348
+ http_res.status_code,
1349
+ http_res_text,
1350
+ http_res,
1351
+ )
1352
+
1353
+ def withdraw(
1354
+ self,
1355
+ *,
1356
+ vault_address: str,
1357
+ amount: Any,
1358
+ chain: models.Chain,
1359
+ sender: str,
1360
+ receiver: OptionalNullable[str] = UNSET,
1361
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1362
+ server_url: Optional[str] = None,
1363
+ timeout_ms: Optional[int] = None,
1364
+ http_headers: Optional[Mapping[str, str]] = None,
1365
+ ) -> models.UnsignedTransaction:
1366
+ r"""Withdraw from Vault
1367
+
1368
+ Withdraw deposited tokens from a Morpho Vault.
1369
+
1370
+ The passive yield earned on token deposits is represented by the increased value of
1371
+ the shares received upon depositing tokens.
1372
+
1373
+ A Morpho Vault has one loan asset and can allocate deposits to multiple Morpho
1374
+ markets. Users can deposit into a vault to start earning passive yield from interest
1375
+ paid by borrowers. Vaults feature automated risk management, actively curating risk
1376
+ exposure for all deposited assets so users don't need to make these decisions
1377
+ themselves. Users maintain full control over their assets, can monitor the vault's
1378
+ state at any time, and withdraw their liquidity at their discretion.
1379
+
1380
+ :param vault_address: The vault address you are withdrawing from.
1381
+ :param amount: The amount of tokens to withdraw from the vault. If set to 'ALL', your total deposited token amount will be withdrawn.
1382
+ :param chain: The chain to use.
1383
+ :param sender: The address of the transaction sender.
1384
+ :param receiver: The address which will receive the tokens withdrawn. Defaults to the sender.
1385
+ :param retries: Override the default retry configuration for this method
1386
+ :param server_url: Override the default server URL for this method
1387
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1388
+ :param http_headers: Additional headers to set or replace on requests.
1389
+ """
1390
+ base_url = None
1391
+ url_variables = None
1392
+ if timeout_ms is None:
1393
+ timeout_ms = self.sdk_configuration.timeout_ms
1394
+
1395
+ if server_url is not None:
1396
+ base_url = server_url
1397
+ else:
1398
+ base_url = self._get_url(base_url, url_variables)
1399
+
1400
+ request = models.MorphoWithdrawRequest(
1401
+ vault_address=vault_address,
1402
+ amount=amount,
1403
+ receiver=receiver,
1404
+ chain=chain,
1405
+ sender=sender,
1406
+ )
1407
+
1408
+ req = self._build_request(
1409
+ method="POST",
1410
+ path="/v0/morpho/withdraw",
1411
+ base_url=base_url,
1412
+ url_variables=url_variables,
1413
+ request=request,
1414
+ request_body_required=True,
1415
+ request_has_path_params=False,
1416
+ request_has_query_params=True,
1417
+ user_agent_header="user-agent",
1418
+ accept_header_value="application/json",
1419
+ http_headers=http_headers,
1420
+ security=self.sdk_configuration.security,
1421
+ get_serialized_body=lambda: utils.serialize_request_body(
1422
+ request, False, False, "json", models.MorphoWithdrawRequest
1423
+ ),
1424
+ timeout_ms=timeout_ms,
1425
+ )
1426
+
1427
+ if retries == UNSET:
1428
+ if self.sdk_configuration.retry_config is not UNSET:
1429
+ retries = self.sdk_configuration.retry_config
1430
+
1431
+ retry_config = None
1432
+ if isinstance(retries, utils.RetryConfig):
1433
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1434
+
1435
+ http_res = self.do_request(
1436
+ hook_ctx=HookContext(
1437
+ base_url=base_url or "",
1438
+ operation_id="morpho_withdraw",
1439
+ oauth2_scopes=[],
1440
+ security_source=self.sdk_configuration.security,
1441
+ ),
1442
+ request=req,
1443
+ error_status_codes=["422", "4XX", "5XX"],
1444
+ retry_config=retry_config,
1445
+ )
1446
+
1447
+ response_data: Any = None
1448
+ if utils.match_response(http_res, "200", "application/json"):
1449
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
1450
+ if utils.match_response(http_res, "422", "application/json"):
1451
+ response_data = utils.unmarshal_json(
1452
+ http_res.text, errors.HTTPValidationErrorData
1453
+ )
1454
+ raise errors.HTTPValidationError(data=response_data)
1455
+ if utils.match_response(http_res, "4XX", "*"):
1456
+ http_res_text = utils.stream_to_text(http_res)
1457
+ raise errors.APIError(
1458
+ "API error occurred", http_res.status_code, http_res_text, http_res
1459
+ )
1460
+ if utils.match_response(http_res, "5XX", "*"):
1461
+ http_res_text = utils.stream_to_text(http_res)
1462
+ raise errors.APIError(
1463
+ "API error occurred", http_res.status_code, http_res_text, http_res
1464
+ )
1465
+
1466
+ content_type = http_res.headers.get("Content-Type")
1467
+ http_res_text = utils.stream_to_text(http_res)
1468
+ raise errors.APIError(
1469
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1470
+ http_res.status_code,
1471
+ http_res_text,
1472
+ http_res,
1473
+ )
1474
+
1475
+ async def withdraw_async(
1476
+ self,
1477
+ *,
1478
+ vault_address: str,
1479
+ amount: Any,
1480
+ chain: models.Chain,
1481
+ sender: str,
1482
+ receiver: OptionalNullable[str] = UNSET,
1483
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1484
+ server_url: Optional[str] = None,
1485
+ timeout_ms: Optional[int] = None,
1486
+ http_headers: Optional[Mapping[str, str]] = None,
1487
+ ) -> models.UnsignedTransaction:
1488
+ r"""Withdraw from Vault
1489
+
1490
+ Withdraw deposited tokens from a Morpho Vault.
1491
+
1492
+ The passive yield earned on token deposits is represented by the increased value of
1493
+ the shares received upon depositing tokens.
1494
+
1495
+ A Morpho Vault has one loan asset and can allocate deposits to multiple Morpho
1496
+ markets. Users can deposit into a vault to start earning passive yield from interest
1497
+ paid by borrowers. Vaults feature automated risk management, actively curating risk
1498
+ exposure for all deposited assets so users don't need to make these decisions
1499
+ themselves. Users maintain full control over their assets, can monitor the vault's
1500
+ state at any time, and withdraw their liquidity at their discretion.
1501
+
1502
+ :param vault_address: The vault address you are withdrawing from.
1503
+ :param amount: The amount of tokens to withdraw from the vault. If set to 'ALL', your total deposited token amount will be withdrawn.
1504
+ :param chain: The chain to use.
1505
+ :param sender: The address of the transaction sender.
1506
+ :param receiver: The address which will receive the tokens withdrawn. Defaults to the sender.
1507
+ :param retries: Override the default retry configuration for this method
1508
+ :param server_url: Override the default server URL for this method
1509
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1510
+ :param http_headers: Additional headers to set or replace on requests.
1511
+ """
1512
+ base_url = None
1513
+ url_variables = None
1514
+ if timeout_ms is None:
1515
+ timeout_ms = self.sdk_configuration.timeout_ms
1516
+
1517
+ if server_url is not None:
1518
+ base_url = server_url
1519
+ else:
1520
+ base_url = self._get_url(base_url, url_variables)
1521
+
1522
+ request = models.MorphoWithdrawRequest(
1523
+ vault_address=vault_address,
1524
+ amount=amount,
1525
+ receiver=receiver,
1526
+ chain=chain,
1527
+ sender=sender,
1528
+ )
1529
+
1530
+ req = self._build_request_async(
1531
+ method="POST",
1532
+ path="/v0/morpho/withdraw",
1533
+ base_url=base_url,
1534
+ url_variables=url_variables,
1535
+ request=request,
1536
+ request_body_required=True,
1537
+ request_has_path_params=False,
1538
+ request_has_query_params=True,
1539
+ user_agent_header="user-agent",
1540
+ accept_header_value="application/json",
1541
+ http_headers=http_headers,
1542
+ security=self.sdk_configuration.security,
1543
+ get_serialized_body=lambda: utils.serialize_request_body(
1544
+ request, False, False, "json", models.MorphoWithdrawRequest
1545
+ ),
1546
+ timeout_ms=timeout_ms,
1547
+ )
1548
+
1549
+ if retries == UNSET:
1550
+ if self.sdk_configuration.retry_config is not UNSET:
1551
+ retries = self.sdk_configuration.retry_config
1552
+
1553
+ retry_config = None
1554
+ if isinstance(retries, utils.RetryConfig):
1555
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1556
+
1557
+ http_res = await self.do_request_async(
1558
+ hook_ctx=HookContext(
1559
+ base_url=base_url or "",
1560
+ operation_id="morpho_withdraw",
1561
+ oauth2_scopes=[],
1562
+ security_source=self.sdk_configuration.security,
1563
+ ),
1564
+ request=req,
1565
+ error_status_codes=["422", "4XX", "5XX"],
1566
+ retry_config=retry_config,
1567
+ )
1568
+
1569
+ response_data: Any = None
1570
+ if utils.match_response(http_res, "200", "application/json"):
1571
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
1572
+ if utils.match_response(http_res, "422", "application/json"):
1573
+ response_data = utils.unmarshal_json(
1574
+ http_res.text, errors.HTTPValidationErrorData
1575
+ )
1576
+ raise errors.HTTPValidationError(data=response_data)
1577
+ if utils.match_response(http_res, "4XX", "*"):
1578
+ http_res_text = await utils.stream_to_text_async(http_res)
1579
+ raise errors.APIError(
1580
+ "API error occurred", http_res.status_code, http_res_text, http_res
1581
+ )
1582
+ if utils.match_response(http_res, "5XX", "*"):
1583
+ http_res_text = await utils.stream_to_text_async(http_res)
1584
+ raise errors.APIError(
1585
+ "API error occurred", http_res.status_code, http_res_text, http_res
1586
+ )
1587
+
1588
+ content_type = http_res.headers.get("Content-Type")
1589
+ http_res_text = await utils.stream_to_text_async(http_res)
1590
+ raise errors.APIError(
1591
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1592
+ http_res.status_code,
1593
+ http_res_text,
1594
+ http_res,
1595
+ )
1596
+
1597
+ def supply_collateral(
1598
+ self,
1599
+ *,
1600
+ amount: Union[
1601
+ models.MorphoSupplyCollateralRequestAmount,
1602
+ models.MorphoSupplyCollateralRequestAmountTypedDict,
1603
+ ],
1604
+ unique_market_key: str,
1605
+ chain: models.Chain,
1606
+ sender: str,
1607
+ on_behalf_of: OptionalNullable[str] = UNSET,
1608
+ callback_data: OptionalNullable[bytes] = UNSET,
1609
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1610
+ server_url: Optional[str] = None,
1611
+ timeout_ms: Optional[int] = None,
1612
+ http_headers: Optional[Mapping[str, str]] = None,
1613
+ ) -> models.UnsignedTransaction:
1614
+ r"""Supply Collateral to Market
1615
+
1616
+ Supply collateral to a Morpho Market in order to borrow against it.
1617
+
1618
+ A Morpho Market is a primitive lending pool that pairs one collateral asset with one
1619
+ loan asset. Each market is isolated (meaning risks are contained within each
1620
+ individual market), immutable (cannot be changed after deployment), and will persist
1621
+ as long as the blockchain it is deployed on is live.
1622
+
1623
+ :param amount: Amount of the token to supply to the market as collateral.
1624
+ :param unique_market_key: The key that uniquely identifies the market. This can be found using the 'Get Markets' endpoint.
1625
+ :param chain: The chain to use.
1626
+ :param sender: The address of the transaction sender.
1627
+ :param on_behalf_of: The address on behalf of whom the supplied collateral is made. Defaults to sender.
1628
+ :param callback_data: An optional field for callback byte data that will be triggered upon successful supplying of collateral.
1629
+ :param retries: Override the default retry configuration for this method
1630
+ :param server_url: Override the default server URL for this method
1631
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1632
+ :param http_headers: Additional headers to set or replace on requests.
1633
+ """
1634
+ base_url = None
1635
+ url_variables = None
1636
+ if timeout_ms is None:
1637
+ timeout_ms = self.sdk_configuration.timeout_ms
1638
+
1639
+ if server_url is not None:
1640
+ base_url = server_url
1641
+ else:
1642
+ base_url = self._get_url(base_url, url_variables)
1643
+
1644
+ request = models.MorphoSupplyCollateralRequest(
1645
+ amount=amount,
1646
+ unique_market_key=unique_market_key,
1647
+ on_behalf_of=on_behalf_of,
1648
+ callback_data=callback_data,
1649
+ chain=chain,
1650
+ sender=sender,
1651
+ )
1652
+
1653
+ req = self._build_request(
1654
+ method="POST",
1655
+ path="/v0/morpho/supply_collateral",
1656
+ base_url=base_url,
1657
+ url_variables=url_variables,
1658
+ request=request,
1659
+ request_body_required=True,
1660
+ request_has_path_params=False,
1661
+ request_has_query_params=True,
1662
+ user_agent_header="user-agent",
1663
+ accept_header_value="application/json",
1664
+ http_headers=http_headers,
1665
+ security=self.sdk_configuration.security,
1666
+ get_serialized_body=lambda: utils.serialize_request_body(
1667
+ request, False, False, "json", models.MorphoSupplyCollateralRequest
1668
+ ),
1669
+ timeout_ms=timeout_ms,
1670
+ )
1671
+
1672
+ if retries == UNSET:
1673
+ if self.sdk_configuration.retry_config is not UNSET:
1674
+ retries = self.sdk_configuration.retry_config
1675
+
1676
+ retry_config = None
1677
+ if isinstance(retries, utils.RetryConfig):
1678
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1679
+
1680
+ http_res = self.do_request(
1681
+ hook_ctx=HookContext(
1682
+ base_url=base_url or "",
1683
+ operation_id="morpho_supply_collateral",
1684
+ oauth2_scopes=[],
1685
+ security_source=self.sdk_configuration.security,
1686
+ ),
1687
+ request=req,
1688
+ error_status_codes=["422", "4XX", "5XX"],
1689
+ retry_config=retry_config,
1690
+ )
1691
+
1692
+ response_data: Any = None
1693
+ if utils.match_response(http_res, "200", "application/json"):
1694
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
1695
+ if utils.match_response(http_res, "422", "application/json"):
1696
+ response_data = utils.unmarshal_json(
1697
+ http_res.text, errors.HTTPValidationErrorData
1698
+ )
1699
+ raise errors.HTTPValidationError(data=response_data)
1700
+ if utils.match_response(http_res, "4XX", "*"):
1701
+ http_res_text = utils.stream_to_text(http_res)
1702
+ raise errors.APIError(
1703
+ "API error occurred", http_res.status_code, http_res_text, http_res
1704
+ )
1705
+ if utils.match_response(http_res, "5XX", "*"):
1706
+ http_res_text = utils.stream_to_text(http_res)
1707
+ raise errors.APIError(
1708
+ "API error occurred", http_res.status_code, http_res_text, http_res
1709
+ )
1710
+
1711
+ content_type = http_res.headers.get("Content-Type")
1712
+ http_res_text = utils.stream_to_text(http_res)
1713
+ raise errors.APIError(
1714
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1715
+ http_res.status_code,
1716
+ http_res_text,
1717
+ http_res,
1718
+ )
1719
+
1720
+ async def supply_collateral_async(
1721
+ self,
1722
+ *,
1723
+ amount: Union[
1724
+ models.MorphoSupplyCollateralRequestAmount,
1725
+ models.MorphoSupplyCollateralRequestAmountTypedDict,
1726
+ ],
1727
+ unique_market_key: str,
1728
+ chain: models.Chain,
1729
+ sender: str,
1730
+ on_behalf_of: OptionalNullable[str] = UNSET,
1731
+ callback_data: OptionalNullable[bytes] = UNSET,
1732
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1733
+ server_url: Optional[str] = None,
1734
+ timeout_ms: Optional[int] = None,
1735
+ http_headers: Optional[Mapping[str, str]] = None,
1736
+ ) -> models.UnsignedTransaction:
1737
+ r"""Supply Collateral to Market
1738
+
1739
+ Supply collateral to a Morpho Market in order to borrow against it.
1740
+
1741
+ A Morpho Market is a primitive lending pool that pairs one collateral asset with one
1742
+ loan asset. Each market is isolated (meaning risks are contained within each
1743
+ individual market), immutable (cannot be changed after deployment), and will persist
1744
+ as long as the blockchain it is deployed on is live.
1745
+
1746
+ :param amount: Amount of the token to supply to the market as collateral.
1747
+ :param unique_market_key: The key that uniquely identifies the market. This can be found using the 'Get Markets' endpoint.
1748
+ :param chain: The chain to use.
1749
+ :param sender: The address of the transaction sender.
1750
+ :param on_behalf_of: The address on behalf of whom the supplied collateral is made. Defaults to sender.
1751
+ :param callback_data: An optional field for callback byte data that will be triggered upon successful supplying of collateral.
1752
+ :param retries: Override the default retry configuration for this method
1753
+ :param server_url: Override the default server URL for this method
1754
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1755
+ :param http_headers: Additional headers to set or replace on requests.
1756
+ """
1757
+ base_url = None
1758
+ url_variables = None
1759
+ if timeout_ms is None:
1760
+ timeout_ms = self.sdk_configuration.timeout_ms
1761
+
1762
+ if server_url is not None:
1763
+ base_url = server_url
1764
+ else:
1765
+ base_url = self._get_url(base_url, url_variables)
1766
+
1767
+ request = models.MorphoSupplyCollateralRequest(
1768
+ amount=amount,
1769
+ unique_market_key=unique_market_key,
1770
+ on_behalf_of=on_behalf_of,
1771
+ callback_data=callback_data,
1772
+ chain=chain,
1773
+ sender=sender,
1774
+ )
1775
+
1776
+ req = self._build_request_async(
1777
+ method="POST",
1778
+ path="/v0/morpho/supply_collateral",
1779
+ base_url=base_url,
1780
+ url_variables=url_variables,
1781
+ request=request,
1782
+ request_body_required=True,
1783
+ request_has_path_params=False,
1784
+ request_has_query_params=True,
1785
+ user_agent_header="user-agent",
1786
+ accept_header_value="application/json",
1787
+ http_headers=http_headers,
1788
+ security=self.sdk_configuration.security,
1789
+ get_serialized_body=lambda: utils.serialize_request_body(
1790
+ request, False, False, "json", models.MorphoSupplyCollateralRequest
1791
+ ),
1792
+ timeout_ms=timeout_ms,
1793
+ )
1794
+
1795
+ if retries == UNSET:
1796
+ if self.sdk_configuration.retry_config is not UNSET:
1797
+ retries = self.sdk_configuration.retry_config
1798
+
1799
+ retry_config = None
1800
+ if isinstance(retries, utils.RetryConfig):
1801
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1802
+
1803
+ http_res = await self.do_request_async(
1804
+ hook_ctx=HookContext(
1805
+ base_url=base_url or "",
1806
+ operation_id="morpho_supply_collateral",
1807
+ oauth2_scopes=[],
1808
+ security_source=self.sdk_configuration.security,
1809
+ ),
1810
+ request=req,
1811
+ error_status_codes=["422", "4XX", "5XX"],
1812
+ retry_config=retry_config,
1813
+ )
1814
+
1815
+ response_data: Any = None
1816
+ if utils.match_response(http_res, "200", "application/json"):
1817
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
1818
+ if utils.match_response(http_res, "422", "application/json"):
1819
+ response_data = utils.unmarshal_json(
1820
+ http_res.text, errors.HTTPValidationErrorData
1821
+ )
1822
+ raise errors.HTTPValidationError(data=response_data)
1823
+ if utils.match_response(http_res, "4XX", "*"):
1824
+ http_res_text = await utils.stream_to_text_async(http_res)
1825
+ raise errors.APIError(
1826
+ "API error occurred", http_res.status_code, http_res_text, http_res
1827
+ )
1828
+ if utils.match_response(http_res, "5XX", "*"):
1829
+ http_res_text = await utils.stream_to_text_async(http_res)
1830
+ raise errors.APIError(
1831
+ "API error occurred", http_res.status_code, http_res_text, http_res
1832
+ )
1833
+
1834
+ content_type = http_res.headers.get("Content-Type")
1835
+ http_res_text = await utils.stream_to_text_async(http_res)
1836
+ raise errors.APIError(
1837
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1838
+ http_res.status_code,
1839
+ http_res_text,
1840
+ http_res,
1841
+ )
1842
+
1843
+ def withdraw_collateral(
1844
+ self,
1845
+ *,
1846
+ amount: Union[
1847
+ models.MorphoWithdrawCollateralRequestAmount,
1848
+ models.MorphoWithdrawCollateralRequestAmountTypedDict,
1849
+ ],
1850
+ unique_market_key: str,
1851
+ chain: models.Chain,
1852
+ sender: str,
1853
+ on_behalf_of: OptionalNullable[str] = UNSET,
1854
+ receiver: OptionalNullable[str] = UNSET,
1855
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1856
+ server_url: Optional[str] = None,
1857
+ timeout_ms: Optional[int] = None,
1858
+ http_headers: Optional[Mapping[str, str]] = None,
1859
+ ) -> models.UnsignedTransaction:
1860
+ r"""Withdraw Collateral from Market
1861
+
1862
+ Withdraw collateral that has been supplied to a Morpho Market.
1863
+
1864
+ A Morpho Market is a primitive lending pool that pairs one collateral asset with one
1865
+ loan asset. Each market is isolated (meaning risks are contained within each
1866
+ individual market), immutable (cannot be changed after deployment), and will persist
1867
+ as long as the blockchain it is deployed on is live.
1868
+
1869
+ :param amount: Amount of the token to supply to the market as collateral.
1870
+ :param unique_market_key: The key that uniquely identifies the market. This can be found using the 'Get Markets' endpoint.
1871
+ :param chain: The chain to use.
1872
+ :param sender: The address of the transaction sender.
1873
+ :param on_behalf_of: The address on behalf of whom the withdraw is made. Defaults to sender.
1874
+ :param receiver: The address where the withdrawn collateral will be received. Defaults to sender.
1875
+ :param retries: Override the default retry configuration for this method
1876
+ :param server_url: Override the default server URL for this method
1877
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1878
+ :param http_headers: Additional headers to set or replace on requests.
1879
+ """
1880
+ base_url = None
1881
+ url_variables = None
1882
+ if timeout_ms is None:
1883
+ timeout_ms = self.sdk_configuration.timeout_ms
1884
+
1885
+ if server_url is not None:
1886
+ base_url = server_url
1887
+ else:
1888
+ base_url = self._get_url(base_url, url_variables)
1889
+
1890
+ request = models.MorphoWithdrawCollateralRequest(
1891
+ amount=amount,
1892
+ unique_market_key=unique_market_key,
1893
+ on_behalf_of=on_behalf_of,
1894
+ receiver=receiver,
1895
+ chain=chain,
1896
+ sender=sender,
1897
+ )
1898
+
1899
+ req = self._build_request(
1900
+ method="POST",
1901
+ path="/v0/morpho/withdraw_collateral",
1902
+ base_url=base_url,
1903
+ url_variables=url_variables,
1904
+ request=request,
1905
+ request_body_required=True,
1906
+ request_has_path_params=False,
1907
+ request_has_query_params=True,
1908
+ user_agent_header="user-agent",
1909
+ accept_header_value="application/json",
1910
+ http_headers=http_headers,
1911
+ security=self.sdk_configuration.security,
1912
+ get_serialized_body=lambda: utils.serialize_request_body(
1913
+ request, False, False, "json", models.MorphoWithdrawCollateralRequest
1914
+ ),
1915
+ timeout_ms=timeout_ms,
1916
+ )
1917
+
1918
+ if retries == UNSET:
1919
+ if self.sdk_configuration.retry_config is not UNSET:
1920
+ retries = self.sdk_configuration.retry_config
1921
+
1922
+ retry_config = None
1923
+ if isinstance(retries, utils.RetryConfig):
1924
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1925
+
1926
+ http_res = self.do_request(
1927
+ hook_ctx=HookContext(
1928
+ base_url=base_url or "",
1929
+ operation_id="morpho_withdraw_collateral",
1930
+ oauth2_scopes=[],
1931
+ security_source=self.sdk_configuration.security,
1932
+ ),
1933
+ request=req,
1934
+ error_status_codes=["422", "4XX", "5XX"],
1935
+ retry_config=retry_config,
1936
+ )
1937
+
1938
+ response_data: Any = None
1939
+ if utils.match_response(http_res, "200", "application/json"):
1940
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
1941
+ if utils.match_response(http_res, "422", "application/json"):
1942
+ response_data = utils.unmarshal_json(
1943
+ http_res.text, errors.HTTPValidationErrorData
1944
+ )
1945
+ raise errors.HTTPValidationError(data=response_data)
1946
+ if utils.match_response(http_res, "4XX", "*"):
1947
+ http_res_text = utils.stream_to_text(http_res)
1948
+ raise errors.APIError(
1949
+ "API error occurred", http_res.status_code, http_res_text, http_res
1950
+ )
1951
+ if utils.match_response(http_res, "5XX", "*"):
1952
+ http_res_text = utils.stream_to_text(http_res)
1953
+ raise errors.APIError(
1954
+ "API error occurred", http_res.status_code, http_res_text, http_res
1955
+ )
1956
+
1957
+ content_type = http_res.headers.get("Content-Type")
1958
+ http_res_text = utils.stream_to_text(http_res)
1959
+ raise errors.APIError(
1960
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1961
+ http_res.status_code,
1962
+ http_res_text,
1963
+ http_res,
1964
+ )
1965
+
1966
+ async def withdraw_collateral_async(
1967
+ self,
1968
+ *,
1969
+ amount: Union[
1970
+ models.MorphoWithdrawCollateralRequestAmount,
1971
+ models.MorphoWithdrawCollateralRequestAmountTypedDict,
1972
+ ],
1973
+ unique_market_key: str,
1974
+ chain: models.Chain,
1975
+ sender: str,
1976
+ on_behalf_of: OptionalNullable[str] = UNSET,
1977
+ receiver: OptionalNullable[str] = UNSET,
1978
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1979
+ server_url: Optional[str] = None,
1980
+ timeout_ms: Optional[int] = None,
1981
+ http_headers: Optional[Mapping[str, str]] = None,
1982
+ ) -> models.UnsignedTransaction:
1983
+ r"""Withdraw Collateral from Market
1984
+
1985
+ Withdraw collateral that has been supplied to a Morpho Market.
1986
+
1987
+ A Morpho Market is a primitive lending pool that pairs one collateral asset with one
1988
+ loan asset. Each market is isolated (meaning risks are contained within each
1989
+ individual market), immutable (cannot be changed after deployment), and will persist
1990
+ as long as the blockchain it is deployed on is live.
1991
+
1992
+ :param amount: Amount of the token to supply to the market as collateral.
1993
+ :param unique_market_key: The key that uniquely identifies the market. This can be found using the 'Get Markets' endpoint.
1994
+ :param chain: The chain to use.
1995
+ :param sender: The address of the transaction sender.
1996
+ :param on_behalf_of: The address on behalf of whom the withdraw is made. Defaults to sender.
1997
+ :param receiver: The address where the withdrawn collateral will be received. Defaults to sender.
1998
+ :param retries: Override the default retry configuration for this method
1999
+ :param server_url: Override the default server URL for this method
2000
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2001
+ :param http_headers: Additional headers to set or replace on requests.
2002
+ """
2003
+ base_url = None
2004
+ url_variables = None
2005
+ if timeout_ms is None:
2006
+ timeout_ms = self.sdk_configuration.timeout_ms
2007
+
2008
+ if server_url is not None:
2009
+ base_url = server_url
2010
+ else:
2011
+ base_url = self._get_url(base_url, url_variables)
2012
+
2013
+ request = models.MorphoWithdrawCollateralRequest(
2014
+ amount=amount,
2015
+ unique_market_key=unique_market_key,
2016
+ on_behalf_of=on_behalf_of,
2017
+ receiver=receiver,
2018
+ chain=chain,
2019
+ sender=sender,
2020
+ )
2021
+
2022
+ req = self._build_request_async(
2023
+ method="POST",
2024
+ path="/v0/morpho/withdraw_collateral",
2025
+ base_url=base_url,
2026
+ url_variables=url_variables,
2027
+ request=request,
2028
+ request_body_required=True,
2029
+ request_has_path_params=False,
2030
+ request_has_query_params=True,
2031
+ user_agent_header="user-agent",
2032
+ accept_header_value="application/json",
2033
+ http_headers=http_headers,
2034
+ security=self.sdk_configuration.security,
2035
+ get_serialized_body=lambda: utils.serialize_request_body(
2036
+ request, False, False, "json", models.MorphoWithdrawCollateralRequest
2037
+ ),
2038
+ timeout_ms=timeout_ms,
2039
+ )
2040
+
2041
+ if retries == UNSET:
2042
+ if self.sdk_configuration.retry_config is not UNSET:
2043
+ retries = self.sdk_configuration.retry_config
2044
+
2045
+ retry_config = None
2046
+ if isinstance(retries, utils.RetryConfig):
2047
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2048
+
2049
+ http_res = await self.do_request_async(
2050
+ hook_ctx=HookContext(
2051
+ base_url=base_url or "",
2052
+ operation_id="morpho_withdraw_collateral",
2053
+ oauth2_scopes=[],
2054
+ security_source=self.sdk_configuration.security,
2055
+ ),
2056
+ request=req,
2057
+ error_status_codes=["422", "4XX", "5XX"],
2058
+ retry_config=retry_config,
2059
+ )
2060
+
2061
+ response_data: Any = None
2062
+ if utils.match_response(http_res, "200", "application/json"):
2063
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
2064
+ if utils.match_response(http_res, "422", "application/json"):
2065
+ response_data = utils.unmarshal_json(
2066
+ http_res.text, errors.HTTPValidationErrorData
2067
+ )
2068
+ raise errors.HTTPValidationError(data=response_data)
2069
+ if utils.match_response(http_res, "4XX", "*"):
2070
+ http_res_text = await utils.stream_to_text_async(http_res)
2071
+ raise errors.APIError(
2072
+ "API error occurred", http_res.status_code, http_res_text, http_res
2073
+ )
2074
+ if utils.match_response(http_res, "5XX", "*"):
2075
+ http_res_text = await utils.stream_to_text_async(http_res)
2076
+ raise errors.APIError(
2077
+ "API error occurred", http_res.status_code, http_res_text, http_res
2078
+ )
2079
+
2080
+ content_type = http_res.headers.get("Content-Type")
2081
+ http_res_text = await utils.stream_to_text_async(http_res)
2082
+ raise errors.APIError(
2083
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2084
+ http_res.status_code,
2085
+ http_res_text,
2086
+ http_res,
2087
+ )
2088
+
2089
+ def borrow(
2090
+ self,
2091
+ *,
2092
+ amount: Union[
2093
+ models.MorphoBorrowRequestAmount, models.MorphoBorrowRequestAmountTypedDict
2094
+ ],
2095
+ unique_market_key: str,
2096
+ chain: models.Chain,
2097
+ sender: str,
2098
+ on_behalf_of: OptionalNullable[str] = UNSET,
2099
+ receiver: OptionalNullable[str] = UNSET,
2100
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2101
+ server_url: Optional[str] = None,
2102
+ timeout_ms: Optional[int] = None,
2103
+ http_headers: Optional[Mapping[str, str]] = None,
2104
+ ) -> models.UnsignedTransaction:
2105
+ r"""Borrow from Market
2106
+
2107
+ Borrow tokens from a Morpho Market against supplied collateral.
2108
+
2109
+ The position could be liquidated when a borrower's Loan-To-Value (LTV) exceeds the
2110
+ Liquidation Loan-To-Value (LLTV) threshold of the market.
2111
+
2112
+ A Morpho Market is a primitive lending pool that pairs one collateral asset with one
2113
+ loan asset. Each market is isolated (meaning risks are contained within each
2114
+ individual market), immutable (cannot be changed after deployment), and will persist
2115
+ as long as the blockchain it is deployed on is live.
2116
+
2117
+ :param amount: Amount of the token to borrow from the market.
2118
+ :param unique_market_key: The key that uniquely identifies the market. This can be found using the 'Get Markets' endpoint.
2119
+ :param chain: The chain to use.
2120
+ :param sender: The address of the transaction sender.
2121
+ :param on_behalf_of: The address where the collateral is borrowed against. Defaults to sender.
2122
+ :param receiver: The address of the receiver of the tokens borrowed. Defaults to the transaction sender.
2123
+ :param retries: Override the default retry configuration for this method
2124
+ :param server_url: Override the default server URL for this method
2125
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2126
+ :param http_headers: Additional headers to set or replace on requests.
2127
+ """
2128
+ base_url = None
2129
+ url_variables = None
2130
+ if timeout_ms is None:
2131
+ timeout_ms = self.sdk_configuration.timeout_ms
2132
+
2133
+ if server_url is not None:
2134
+ base_url = server_url
2135
+ else:
2136
+ base_url = self._get_url(base_url, url_variables)
2137
+
2138
+ request = models.MorphoBorrowRequest(
2139
+ amount=amount,
2140
+ unique_market_key=unique_market_key,
2141
+ on_behalf_of=on_behalf_of,
2142
+ receiver=receiver,
2143
+ chain=chain,
2144
+ sender=sender,
2145
+ )
2146
+
2147
+ req = self._build_request(
2148
+ method="POST",
2149
+ path="/v0/morpho/borrow",
2150
+ base_url=base_url,
2151
+ url_variables=url_variables,
2152
+ request=request,
2153
+ request_body_required=True,
2154
+ request_has_path_params=False,
2155
+ request_has_query_params=True,
2156
+ user_agent_header="user-agent",
2157
+ accept_header_value="application/json",
2158
+ http_headers=http_headers,
2159
+ security=self.sdk_configuration.security,
2160
+ get_serialized_body=lambda: utils.serialize_request_body(
2161
+ request, False, False, "json", models.MorphoBorrowRequest
2162
+ ),
2163
+ timeout_ms=timeout_ms,
2164
+ )
2165
+
2166
+ if retries == UNSET:
2167
+ if self.sdk_configuration.retry_config is not UNSET:
2168
+ retries = self.sdk_configuration.retry_config
2169
+
2170
+ retry_config = None
2171
+ if isinstance(retries, utils.RetryConfig):
2172
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2173
+
2174
+ http_res = self.do_request(
2175
+ hook_ctx=HookContext(
2176
+ base_url=base_url or "",
2177
+ operation_id="morpho_borrow",
2178
+ oauth2_scopes=[],
2179
+ security_source=self.sdk_configuration.security,
2180
+ ),
2181
+ request=req,
2182
+ error_status_codes=["422", "4XX", "5XX"],
2183
+ retry_config=retry_config,
2184
+ )
2185
+
2186
+ response_data: Any = None
2187
+ if utils.match_response(http_res, "200", "application/json"):
2188
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
2189
+ if utils.match_response(http_res, "422", "application/json"):
2190
+ response_data = utils.unmarshal_json(
2191
+ http_res.text, errors.HTTPValidationErrorData
2192
+ )
2193
+ raise errors.HTTPValidationError(data=response_data)
2194
+ if utils.match_response(http_res, "4XX", "*"):
2195
+ http_res_text = utils.stream_to_text(http_res)
2196
+ raise errors.APIError(
2197
+ "API error occurred", http_res.status_code, http_res_text, http_res
2198
+ )
2199
+ if utils.match_response(http_res, "5XX", "*"):
2200
+ http_res_text = utils.stream_to_text(http_res)
2201
+ raise errors.APIError(
2202
+ "API error occurred", http_res.status_code, http_res_text, http_res
2203
+ )
2204
+
2205
+ content_type = http_res.headers.get("Content-Type")
2206
+ http_res_text = utils.stream_to_text(http_res)
2207
+ raise errors.APIError(
2208
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2209
+ http_res.status_code,
2210
+ http_res_text,
2211
+ http_res,
2212
+ )
2213
+
2214
+ async def borrow_async(
2215
+ self,
2216
+ *,
2217
+ amount: Union[
2218
+ models.MorphoBorrowRequestAmount, models.MorphoBorrowRequestAmountTypedDict
2219
+ ],
2220
+ unique_market_key: str,
2221
+ chain: models.Chain,
2222
+ sender: str,
2223
+ on_behalf_of: OptionalNullable[str] = UNSET,
2224
+ receiver: OptionalNullable[str] = UNSET,
2225
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2226
+ server_url: Optional[str] = None,
2227
+ timeout_ms: Optional[int] = None,
2228
+ http_headers: Optional[Mapping[str, str]] = None,
2229
+ ) -> models.UnsignedTransaction:
2230
+ r"""Borrow from Market
2231
+
2232
+ Borrow tokens from a Morpho Market against supplied collateral.
2233
+
2234
+ The position could be liquidated when a borrower's Loan-To-Value (LTV) exceeds the
2235
+ Liquidation Loan-To-Value (LLTV) threshold of the market.
2236
+
2237
+ A Morpho Market is a primitive lending pool that pairs one collateral asset with one
2238
+ loan asset. Each market is isolated (meaning risks are contained within each
2239
+ individual market), immutable (cannot be changed after deployment), and will persist
2240
+ as long as the blockchain it is deployed on is live.
2241
+
2242
+ :param amount: Amount of the token to borrow from the market.
2243
+ :param unique_market_key: The key that uniquely identifies the market. This can be found using the 'Get Markets' endpoint.
2244
+ :param chain: The chain to use.
2245
+ :param sender: The address of the transaction sender.
2246
+ :param on_behalf_of: The address where the collateral is borrowed against. Defaults to sender.
2247
+ :param receiver: The address of the receiver of the tokens borrowed. Defaults to the transaction sender.
2248
+ :param retries: Override the default retry configuration for this method
2249
+ :param server_url: Override the default server URL for this method
2250
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2251
+ :param http_headers: Additional headers to set or replace on requests.
2252
+ """
2253
+ base_url = None
2254
+ url_variables = None
2255
+ if timeout_ms is None:
2256
+ timeout_ms = self.sdk_configuration.timeout_ms
2257
+
2258
+ if server_url is not None:
2259
+ base_url = server_url
2260
+ else:
2261
+ base_url = self._get_url(base_url, url_variables)
2262
+
2263
+ request = models.MorphoBorrowRequest(
2264
+ amount=amount,
2265
+ unique_market_key=unique_market_key,
2266
+ on_behalf_of=on_behalf_of,
2267
+ receiver=receiver,
2268
+ chain=chain,
2269
+ sender=sender,
2270
+ )
2271
+
2272
+ req = self._build_request_async(
2273
+ method="POST",
2274
+ path="/v0/morpho/borrow",
2275
+ base_url=base_url,
2276
+ url_variables=url_variables,
2277
+ request=request,
2278
+ request_body_required=True,
2279
+ request_has_path_params=False,
2280
+ request_has_query_params=True,
2281
+ user_agent_header="user-agent",
2282
+ accept_header_value="application/json",
2283
+ http_headers=http_headers,
2284
+ security=self.sdk_configuration.security,
2285
+ get_serialized_body=lambda: utils.serialize_request_body(
2286
+ request, False, False, "json", models.MorphoBorrowRequest
2287
+ ),
2288
+ timeout_ms=timeout_ms,
2289
+ )
2290
+
2291
+ if retries == UNSET:
2292
+ if self.sdk_configuration.retry_config is not UNSET:
2293
+ retries = self.sdk_configuration.retry_config
2294
+
2295
+ retry_config = None
2296
+ if isinstance(retries, utils.RetryConfig):
2297
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2298
+
2299
+ http_res = await self.do_request_async(
2300
+ hook_ctx=HookContext(
2301
+ base_url=base_url or "",
2302
+ operation_id="morpho_borrow",
2303
+ oauth2_scopes=[],
2304
+ security_source=self.sdk_configuration.security,
2305
+ ),
2306
+ request=req,
2307
+ error_status_codes=["422", "4XX", "5XX"],
2308
+ retry_config=retry_config,
2309
+ )
2310
+
2311
+ response_data: Any = None
2312
+ if utils.match_response(http_res, "200", "application/json"):
2313
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
2314
+ if utils.match_response(http_res, "422", "application/json"):
2315
+ response_data = utils.unmarshal_json(
2316
+ http_res.text, errors.HTTPValidationErrorData
2317
+ )
2318
+ raise errors.HTTPValidationError(data=response_data)
2319
+ if utils.match_response(http_res, "4XX", "*"):
2320
+ http_res_text = await utils.stream_to_text_async(http_res)
2321
+ raise errors.APIError(
2322
+ "API error occurred", http_res.status_code, http_res_text, http_res
2323
+ )
2324
+ if utils.match_response(http_res, "5XX", "*"):
2325
+ http_res_text = await utils.stream_to_text_async(http_res)
2326
+ raise errors.APIError(
2327
+ "API error occurred", http_res.status_code, http_res_text, http_res
2328
+ )
2329
+
2330
+ content_type = http_res.headers.get("Content-Type")
2331
+ http_res_text = await utils.stream_to_text_async(http_res)
2332
+ raise errors.APIError(
2333
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2334
+ http_res.status_code,
2335
+ http_res_text,
2336
+ http_res,
2337
+ )
2338
+
2339
+ def repay(
2340
+ self,
2341
+ *,
2342
+ amount: Any,
2343
+ unique_market_key: str,
2344
+ chain: models.Chain,
2345
+ sender: str,
2346
+ on_behalf_of: OptionalNullable[str] = UNSET,
2347
+ callback_data: OptionalNullable[bytes] = UNSET,
2348
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2349
+ server_url: Optional[str] = None,
2350
+ timeout_ms: Optional[int] = None,
2351
+ http_headers: Optional[Mapping[str, str]] = None,
2352
+ ) -> models.UnsignedTransaction:
2353
+ r"""Repay to Market
2354
+
2355
+ Repay borrowed tokens to a market in order to reduce or eliminate debt.
2356
+
2357
+ A Morpho Market is a primitive lending pool that pairs one collateral asset with one
2358
+ loan asset. Each market is isolated (meaning risks are contained within each
2359
+ individual market), immutable (cannot be changed after deployment), and will persist
2360
+ as long as the blockchain it is deployed on is live.
2361
+
2362
+ :param amount: Amount of the token to repay to the market. If set to 'ALL', all debt plus interest will be paid back if the user has a sufficient token balance in their wallet.
2363
+ :param unique_market_key: The key that uniquely identifies the market. This can be found using the 'Get Markets' endpoint.
2364
+ :param chain: The chain to use.
2365
+ :param sender: The address of the transaction sender.
2366
+ :param on_behalf_of: The address on behalf of whom the repayment is made. Defaults to sender.
2367
+ :param callback_data: An optional field for callback byte data that will be triggered upon successful repaying of debt.
2368
+ :param retries: Override the default retry configuration for this method
2369
+ :param server_url: Override the default server URL for this method
2370
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2371
+ :param http_headers: Additional headers to set or replace on requests.
2372
+ """
2373
+ base_url = None
2374
+ url_variables = None
2375
+ if timeout_ms is None:
2376
+ timeout_ms = self.sdk_configuration.timeout_ms
2377
+
2378
+ if server_url is not None:
2379
+ base_url = server_url
2380
+ else:
2381
+ base_url = self._get_url(base_url, url_variables)
2382
+
2383
+ request = models.MorphoRepayRequest(
2384
+ amount=amount,
2385
+ unique_market_key=unique_market_key,
2386
+ on_behalf_of=on_behalf_of,
2387
+ callback_data=callback_data,
2388
+ chain=chain,
2389
+ sender=sender,
2390
+ )
2391
+
2392
+ req = self._build_request(
2393
+ method="POST",
2394
+ path="/v0/morpho/repay",
2395
+ base_url=base_url,
2396
+ url_variables=url_variables,
2397
+ request=request,
2398
+ request_body_required=True,
2399
+ request_has_path_params=False,
2400
+ request_has_query_params=True,
2401
+ user_agent_header="user-agent",
2402
+ accept_header_value="application/json",
2403
+ http_headers=http_headers,
2404
+ security=self.sdk_configuration.security,
2405
+ get_serialized_body=lambda: utils.serialize_request_body(
2406
+ request, False, False, "json", models.MorphoRepayRequest
2407
+ ),
2408
+ timeout_ms=timeout_ms,
2409
+ )
2410
+
2411
+ if retries == UNSET:
2412
+ if self.sdk_configuration.retry_config is not UNSET:
2413
+ retries = self.sdk_configuration.retry_config
2414
+
2415
+ retry_config = None
2416
+ if isinstance(retries, utils.RetryConfig):
2417
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2418
+
2419
+ http_res = self.do_request(
2420
+ hook_ctx=HookContext(
2421
+ base_url=base_url or "",
2422
+ operation_id="morpho_repay",
2423
+ oauth2_scopes=[],
2424
+ security_source=self.sdk_configuration.security,
2425
+ ),
2426
+ request=req,
2427
+ error_status_codes=["422", "4XX", "5XX"],
2428
+ retry_config=retry_config,
2429
+ )
2430
+
2431
+ response_data: Any = None
2432
+ if utils.match_response(http_res, "200", "application/json"):
2433
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
2434
+ if utils.match_response(http_res, "422", "application/json"):
2435
+ response_data = utils.unmarshal_json(
2436
+ http_res.text, errors.HTTPValidationErrorData
2437
+ )
2438
+ raise errors.HTTPValidationError(data=response_data)
2439
+ if utils.match_response(http_res, "4XX", "*"):
2440
+ http_res_text = utils.stream_to_text(http_res)
2441
+ raise errors.APIError(
2442
+ "API error occurred", http_res.status_code, http_res_text, http_res
2443
+ )
2444
+ if utils.match_response(http_res, "5XX", "*"):
2445
+ http_res_text = utils.stream_to_text(http_res)
2446
+ raise errors.APIError(
2447
+ "API error occurred", http_res.status_code, http_res_text, http_res
2448
+ )
2449
+
2450
+ content_type = http_res.headers.get("Content-Type")
2451
+ http_res_text = utils.stream_to_text(http_res)
2452
+ raise errors.APIError(
2453
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2454
+ http_res.status_code,
2455
+ http_res_text,
2456
+ http_res,
2457
+ )
2458
+
2459
+ async def repay_async(
2460
+ self,
2461
+ *,
2462
+ amount: Any,
2463
+ unique_market_key: str,
2464
+ chain: models.Chain,
2465
+ sender: str,
2466
+ on_behalf_of: OptionalNullable[str] = UNSET,
2467
+ callback_data: OptionalNullable[bytes] = UNSET,
2468
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2469
+ server_url: Optional[str] = None,
2470
+ timeout_ms: Optional[int] = None,
2471
+ http_headers: Optional[Mapping[str, str]] = None,
2472
+ ) -> models.UnsignedTransaction:
2473
+ r"""Repay to Market
2474
+
2475
+ Repay borrowed tokens to a market in order to reduce or eliminate debt.
2476
+
2477
+ A Morpho Market is a primitive lending pool that pairs one collateral asset with one
2478
+ loan asset. Each market is isolated (meaning risks are contained within each
2479
+ individual market), immutable (cannot be changed after deployment), and will persist
2480
+ as long as the blockchain it is deployed on is live.
2481
+
2482
+ :param amount: Amount of the token to repay to the market. If set to 'ALL', all debt plus interest will be paid back if the user has a sufficient token balance in their wallet.
2483
+ :param unique_market_key: The key that uniquely identifies the market. This can be found using the 'Get Markets' endpoint.
2484
+ :param chain: The chain to use.
2485
+ :param sender: The address of the transaction sender.
2486
+ :param on_behalf_of: The address on behalf of whom the repayment is made. Defaults to sender.
2487
+ :param callback_data: An optional field for callback byte data that will be triggered upon successful repaying of debt.
2488
+ :param retries: Override the default retry configuration for this method
2489
+ :param server_url: Override the default server URL for this method
2490
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2491
+ :param http_headers: Additional headers to set or replace on requests.
2492
+ """
2493
+ base_url = None
2494
+ url_variables = None
2495
+ if timeout_ms is None:
2496
+ timeout_ms = self.sdk_configuration.timeout_ms
2497
+
2498
+ if server_url is not None:
2499
+ base_url = server_url
2500
+ else:
2501
+ base_url = self._get_url(base_url, url_variables)
2502
+
2503
+ request = models.MorphoRepayRequest(
2504
+ amount=amount,
2505
+ unique_market_key=unique_market_key,
2506
+ on_behalf_of=on_behalf_of,
2507
+ callback_data=callback_data,
2508
+ chain=chain,
2509
+ sender=sender,
2510
+ )
2511
+
2512
+ req = self._build_request_async(
2513
+ method="POST",
2514
+ path="/v0/morpho/repay",
2515
+ base_url=base_url,
2516
+ url_variables=url_variables,
2517
+ request=request,
2518
+ request_body_required=True,
2519
+ request_has_path_params=False,
2520
+ request_has_query_params=True,
2521
+ user_agent_header="user-agent",
2522
+ accept_header_value="application/json",
2523
+ http_headers=http_headers,
2524
+ security=self.sdk_configuration.security,
2525
+ get_serialized_body=lambda: utils.serialize_request_body(
2526
+ request, False, False, "json", models.MorphoRepayRequest
2527
+ ),
2528
+ timeout_ms=timeout_ms,
2529
+ )
2530
+
2531
+ if retries == UNSET:
2532
+ if self.sdk_configuration.retry_config is not UNSET:
2533
+ retries = self.sdk_configuration.retry_config
2534
+
2535
+ retry_config = None
2536
+ if isinstance(retries, utils.RetryConfig):
2537
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2538
+
2539
+ http_res = await self.do_request_async(
2540
+ hook_ctx=HookContext(
2541
+ base_url=base_url or "",
2542
+ operation_id="morpho_repay",
2543
+ oauth2_scopes=[],
2544
+ security_source=self.sdk_configuration.security,
2545
+ ),
2546
+ request=req,
2547
+ error_status_codes=["422", "4XX", "5XX"],
2548
+ retry_config=retry_config,
2549
+ )
2550
+
2551
+ response_data: Any = None
2552
+ if utils.match_response(http_res, "200", "application/json"):
2553
+ return utils.unmarshal_json(http_res.text, models.UnsignedTransaction)
2554
+ if utils.match_response(http_res, "422", "application/json"):
2555
+ response_data = utils.unmarshal_json(
2556
+ http_res.text, errors.HTTPValidationErrorData
2557
+ )
2558
+ raise errors.HTTPValidationError(data=response_data)
2559
+ if utils.match_response(http_res, "4XX", "*"):
2560
+ http_res_text = await utils.stream_to_text_async(http_res)
2561
+ raise errors.APIError(
2562
+ "API error occurred", http_res.status_code, http_res_text, http_res
2563
+ )
2564
+ if utils.match_response(http_res, "5XX", "*"):
2565
+ http_res_text = await utils.stream_to_text_async(http_res)
2566
+ raise errors.APIError(
2567
+ "API error occurred", http_res.status_code, http_res_text, http_res
2568
+ )
2569
+
2570
+ content_type = http_res.headers.get("Content-Type")
2571
+ http_res_text = await utils.stream_to_text_async(http_res)
2572
+ raise errors.APIError(
2573
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2574
+ http_res.status_code,
2575
+ http_res_text,
2576
+ http_res,
2577
+ )