afp-sdk 0.5.4__py3-none-any.whl → 0.6.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.
Files changed (49) hide show
  1. afp/__init__.py +4 -1
  2. afp/afp.py +11 -0
  3. afp/api/admin.py +1 -1
  4. afp/api/base.py +11 -2
  5. afp/api/margin_account.py +12 -148
  6. afp/api/product.py +302 -148
  7. afp/api/trading.py +10 -19
  8. afp/auth.py +14 -0
  9. afp/bindings/__init__.py +30 -16
  10. afp/bindings/admin_facet.py +890 -0
  11. afp/bindings/clearing_facet.py +356 -773
  12. afp/bindings/facade.py +9 -6
  13. afp/bindings/final_settlement_facet.py +258 -99
  14. afp/bindings/margin_account.py +524 -839
  15. afp/bindings/margin_account_facet.py +722 -0
  16. afp/bindings/margin_account_registry.py +184 -310
  17. afp/bindings/mark_price_tracker_facet.py +74 -16
  18. afp/bindings/product_registry.py +1577 -541
  19. afp/bindings/product_registry_facet.py +1467 -0
  20. afp/bindings/system_viewer.py +592 -369
  21. afp/bindings/types.py +223 -0
  22. afp/config.py +4 -0
  23. afp/constants.py +49 -6
  24. afp/decorators.py +25 -3
  25. afp/dtos.py +142 -0
  26. afp/exceptions.py +10 -0
  27. afp/exchange.py +10 -8
  28. afp/hashing.py +7 -5
  29. afp/ipfs.py +245 -0
  30. afp/json-schemas/bafyreiaw34o6l3rmatabzbds2i2myazdw2yolevcpsoyd2i2g3ms7wa2eq.json +1 -0
  31. afp/json-schemas/bafyreibnfg6nq74dvpkre5rakkccij7iadp5rxpim7omsatjnrpmj3y7v4.json +1 -0
  32. afp/json-schemas/bafyreicgr6dfo5yduixjkcifghiulskfegwojvuwodtouvivl362zndhxe.json +1 -0
  33. afp/json-schemas/bafyreicheoypx6synljushh7mq2572iyhlolf4nake2p5dwobgnj3r5eua.json +1 -0
  34. afp/json-schemas/bafyreid35a67db4sqh4fs6boddyt2xvscbqy6nqvsp5jjur56qhkw4ixre.json +1 -0
  35. afp/json-schemas/bafyreidzs7okcpqiss6ztftltyptqwnw5e5opsy5yntospekjha4kpykaa.json +1 -0
  36. afp/json-schemas/bafyreifcec2km7hxwq6oqzjlspni2mgipetjb7pqtaewh2efislzoctboi.json +1 -0
  37. afp/json-schemas/bafyreihn3oiaxffe4e2w7pwtreadpw3obfd7gqlogbcxm56jc2hzfvco74.json +1 -0
  38. afp/json-schemas/bafyreihur3dzwhja6uxsbcw6eeoj3xmmc4e3zkmyzpot5v5dleevxe5zam.json +1 -0
  39. afp/schemas.py +236 -177
  40. afp/types.py +169 -0
  41. afp/validators.py +218 -8
  42. {afp_sdk-0.5.4.dist-info → afp_sdk-0.6.1.dist-info}/METADATA +76 -11
  43. afp_sdk-0.6.1.dist-info/RECORD +50 -0
  44. afp/bindings/auctioneer_facet.py +0 -752
  45. afp/bindings/bankruptcy_facet.py +0 -391
  46. afp/bindings/trading_protocol.py +0 -1158
  47. afp_sdk-0.5.4.dist-info/RECORD +0 -37
  48. {afp_sdk-0.5.4.dist-info → afp_sdk-0.6.1.dist-info}/WHEEL +0 -0
  49. {afp_sdk-0.5.4.dist-info → afp_sdk-0.6.1.dist-info}/licenses/LICENSE +0 -0
afp/bindings/facade.py CHANGED
@@ -5,14 +5,15 @@ from eth_typing.evm import ChecksumAddress
5
5
  from web3 import Web3
6
6
 
7
7
  from . import (
8
- auctioneer_facet,
9
- bankruptcy_facet,
8
+ admin_facet,
10
9
  clearing_facet,
11
10
  final_settlement_facet,
11
+ margin_account_facet,
12
12
  margin_account_registry,
13
13
  mark_price_tracker_facet,
14
14
  oracle_provider,
15
15
  product_registry,
16
+ product_registry_facet,
16
17
  system_viewer,
17
18
  )
18
19
  from ..constants import defaults
@@ -23,21 +24,23 @@ from ..constants import defaults
23
24
 
24
25
  CLEARING_DIAMOND_ABI = list(
25
26
  chain(
26
- auctioneer_facet.ABI,
27
- bankruptcy_facet.ABI,
27
+ admin_facet.ABI,
28
28
  clearing_facet.ABI,
29
29
  final_settlement_facet.ABI,
30
+ margin_account_facet.ABI,
30
31
  mark_price_tracker_facet.ABI,
32
+ product_registry_facet.ABI,
31
33
  )
32
34
  )
33
35
 
34
36
 
35
37
  class ClearingDiamond(
36
- auctioneer_facet.AuctioneerFacet,
37
- bankruptcy_facet.BankruptcyFacet,
38
+ admin_facet.AdminFacet,
38
39
  clearing_facet.ClearingFacet,
39
40
  final_settlement_facet.FinalSettlementFacet,
41
+ margin_account_facet.MarginAccountFacet,
40
42
  mark_price_tracker_facet.MarkPriceTrackerFacet,
43
+ product_registry_facet.ProductRegistryFacet,
41
44
  ):
42
45
  """ClearingDiamond contract binding.
43
46
 
@@ -7,6 +7,7 @@ import typing
7
7
  import eth_typing
8
8
  import hexbytes
9
9
  import web3
10
+ from web3 import types
10
11
  from web3.contract import contract
11
12
 
12
13
 
@@ -37,33 +38,44 @@ class FinalSettlementFacet:
37
38
  """Binding for `event FSPFinalized` on the FinalSettlementFacet contract."""
38
39
  return self._contract.events.FSPFinalized
39
40
 
41
+ @property
42
+ def FeeCollected(self) -> contract.ContractEvent:
43
+ """Binding for `event FeeCollected` on the FinalSettlementFacet contract."""
44
+ return self._contract.events.FeeCollected
45
+
46
+ @property
47
+ def FeeDispersed(self) -> contract.ContractEvent:
48
+ """Binding for `event FeeDispersed` on the FinalSettlementFacet contract."""
49
+ return self._contract.events.FeeDispersed
50
+
40
51
  @property
41
52
  def FinalSettlementCloseout(self) -> contract.ContractEvent:
42
53
  """Binding for `event FinalSettlementCloseout` on the FinalSettlementFacet contract."""
43
54
  return self._contract.events.FinalSettlementCloseout
44
55
 
45
- def closeout_fee_rate(
46
- self,
47
- ) -> int:
48
- """Binding for `CLOSEOUT_FEE_RATE` on the FinalSettlementFacet contract.
49
-
50
- Returns
51
- -------
52
- int
53
- """
54
- return_value = self._contract.functions.CLOSEOUT_FEE_RATE().call()
55
- return int(return_value)
56
+ @property
57
+ def PositionUpdated(self) -> contract.ContractEvent:
58
+ """Binding for `event PositionUpdated` on the FinalSettlementFacet contract."""
59
+ return self._contract.events.PositionUpdated
56
60
 
57
- def closeout_reward_rate(
61
+ def final_settlement_id(
58
62
  self,
63
+ block_identifier: types.BlockIdentifier = "latest",
59
64
  ) -> int:
60
- """Binding for `CLOSEOUT_REWARD_RATE` on the FinalSettlementFacet contract.
65
+ """Binding for `FINAL_SETTLEMENT_ID` on the FinalSettlementFacet contract.
66
+
67
+ Parameters
68
+ ----------
69
+ block_identifier : web3.types.BlockIdentifier
70
+ The block identifier, defaults to the latest block.
61
71
 
62
72
  Returns
63
73
  -------
64
74
  int
65
75
  """
66
- return_value = self._contract.functions.CLOSEOUT_REWARD_RATE().call()
76
+ return_value = self._contract.functions.FINAL_SETTLEMENT_ID().call(
77
+ block_identifier=block_identifier
78
+ )
67
79
  return int(return_value)
68
80
 
69
81
  def finalize_fsp(
@@ -88,12 +100,15 @@ class FinalSettlementFacet:
88
100
  def get_fsp(
89
101
  self,
90
102
  product_id: hexbytes.HexBytes,
103
+ block_identifier: types.BlockIdentifier = "latest",
91
104
  ) -> typing.Tuple[int, bool]:
92
105
  """Binding for `getFsp` on the FinalSettlementFacet contract.
93
106
 
94
107
  Parameters
95
108
  ----------
96
109
  product_id : hexbytes.HexBytes
110
+ block_identifier : web3.types.BlockIdentifier
111
+ The block identifier, defaults to the latest block.
97
112
 
98
113
  Returns
99
114
  -------
@@ -102,12 +117,34 @@ class FinalSettlementFacet:
102
117
  """
103
118
  return_value = self._contract.functions.getFsp(
104
119
  product_id,
105
- ).call()
120
+ ).call(block_identifier=block_identifier)
106
121
  return (
107
122
  int(return_value[0]),
108
123
  bool(return_value[1]),
109
124
  )
110
125
 
126
+ def get_fsp_finalization_time(
127
+ self,
128
+ product_id: hexbytes.HexBytes,
129
+ block_identifier: types.BlockIdentifier = "latest",
130
+ ) -> int:
131
+ """Binding for `getFspFinalizationTime` on the FinalSettlementFacet contract.
132
+
133
+ Parameters
134
+ ----------
135
+ product_id : hexbytes.HexBytes
136
+ block_identifier : web3.types.BlockIdentifier
137
+ The block identifier, defaults to the latest block.
138
+
139
+ Returns
140
+ -------
141
+ int
142
+ """
143
+ return_value = self._contract.functions.getFspFinalizationTime(
144
+ product_id,
145
+ ).call(block_identifier=block_identifier)
146
+ return int(return_value)
147
+
111
148
  def initiate_final_settlement(
112
149
  self,
113
150
  product_id: hexbytes.HexBytes,
@@ -133,12 +170,15 @@ class FinalSettlementFacet:
133
170
  def open_interest(
134
171
  self,
135
172
  product_id: hexbytes.HexBytes,
173
+ block_identifier: types.BlockIdentifier = "latest",
136
174
  ) -> int:
137
175
  """Binding for `openInterest` on the FinalSettlementFacet contract.
138
176
 
139
177
  Parameters
140
178
  ----------
141
179
  product_id : hexbytes.HexBytes
180
+ block_identifier : web3.types.BlockIdentifier
181
+ The block identifier, defaults to the latest block.
142
182
 
143
183
  Returns
144
184
  -------
@@ -146,7 +186,7 @@ class FinalSettlementFacet:
146
186
  """
147
187
  return_value = self._contract.functions.openInterest(
148
188
  product_id,
149
- ).call()
189
+ ).call(block_identifier=block_identifier)
150
190
  return int(return_value)
151
191
 
152
192
 
@@ -154,169 +194,288 @@ ABI = typing.cast(
154
194
  eth_typing.ABI,
155
195
  [
156
196
  {
157
- "inputs": [
158
- {"internalType": "bytes32", "name": "productId", "type": "bytes32"}
159
- ],
160
- "name": "FSPAlreadyFinalized",
161
- "type": "error",
197
+ "type": "function",
198
+ "name": "FINAL_SETTLEMENT_ID",
199
+ "inputs": [],
200
+ "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}],
201
+ "stateMutability": "view",
162
202
  },
163
203
  {
204
+ "type": "function",
205
+ "name": "finalizeFsp",
164
206
  "inputs": [
165
- {"internalType": "bytes32", "name": "productId", "type": "bytes32"}
207
+ {"name": "productID", "type": "bytes32", "internalType": "bytes32"}
166
208
  ],
167
- "name": "FSPNotFound",
168
- "type": "error",
209
+ "outputs": [{"name": "", "type": "int256", "internalType": "int256"}],
210
+ "stateMutability": "nonpayable",
169
211
  },
170
212
  {
213
+ "type": "function",
214
+ "name": "getFsp",
171
215
  "inputs": [
172
- {"internalType": "bytes32", "name": "productId", "type": "bytes32"},
173
- {"internalType": "uint256", "name": "currentTime", "type": "uint256"},
174
- {
175
- "internalType": "uint256",
176
- "name": "earliestFSPSubmissionTime",
177
- "type": "uint256",
178
- },
216
+ {"name": "productId", "type": "bytes32", "internalType": "bytes32"}
179
217
  ],
180
- "name": "FSPTimeNotReached",
181
- "type": "error",
218
+ "outputs": [
219
+ {"name": "fsp", "type": "int256", "internalType": "int256"},
220
+ {"name": "finalized", "type": "bool", "internalType": "bool"},
221
+ ],
222
+ "stateMutability": "view",
182
223
  },
183
224
  {
225
+ "type": "function",
226
+ "name": "getFspFinalizationTime",
184
227
  "inputs": [
185
- {"internalType": "address", "name": "fspAccount", "type": "address"}
228
+ {"name": "productId", "type": "bytes32", "internalType": "bytes32"}
186
229
  ],
187
- "name": "InvalidFSPAccount",
188
- "type": "error",
230
+ "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}],
231
+ "stateMutability": "view",
189
232
  },
190
233
  {
234
+ "type": "function",
235
+ "name": "initiateFinalSettlement",
191
236
  "inputs": [
192
- {"internalType": "address", "name": "oracleAddress", "type": "address"}
237
+ {"name": "productID", "type": "bytes32", "internalType": "bytes32"},
238
+ {"name": "accounts", "type": "address[]", "internalType": "address[]"},
193
239
  ],
194
- "name": "InvalidOracleAddress",
195
- "type": "error",
240
+ "outputs": [],
241
+ "stateMutability": "nonpayable",
196
242
  },
197
243
  {
244
+ "type": "function",
245
+ "name": "openInterest",
198
246
  "inputs": [
199
- {"internalType": "string", "name": "paramName", "type": "string"}
247
+ {"name": "productId", "type": "bytes32", "internalType": "bytes32"}
200
248
  ],
201
- "name": "InvalidParameter",
202
- "type": "error",
249
+ "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}],
250
+ "stateMutability": "view",
203
251
  },
204
252
  {
253
+ "type": "event",
254
+ "name": "FSPFinalized",
205
255
  "inputs": [
206
- {"internalType": "int256", "name": "checksum", "type": "int256"},
207
256
  {
208
- "internalType": "int256",
209
- "name": "expectedChecksum",
257
+ "name": "productID",
258
+ "type": "bytes32",
259
+ "indexed": True,
260
+ "internalType": "bytes32",
261
+ },
262
+ {
263
+ "name": "fsp",
210
264
  "type": "int256",
265
+ "indexed": False,
266
+ "internalType": "int256",
211
267
  },
212
268
  ],
213
- "name": "MismatchedFSPAccountQuantities",
214
- "type": "error",
269
+ "anonymous": False,
215
270
  },
216
271
  {
272
+ "type": "event",
273
+ "name": "FeeCollected",
217
274
  "inputs": [
218
- {"internalType": "bytes32", "name": "productId", "type": "bytes32"}
275
+ {
276
+ "name": "marginAccountId",
277
+ "type": "address",
278
+ "indexed": True,
279
+ "internalType": "address",
280
+ },
281
+ {
282
+ "name": "capitalAmount",
283
+ "type": "int256",
284
+ "indexed": False,
285
+ "internalType": "int256",
286
+ },
287
+ {
288
+ "name": "id",
289
+ "type": "uint256",
290
+ "indexed": False,
291
+ "internalType": "uint256",
292
+ },
219
293
  ],
220
- "name": "ProductNotInFinalSettlement",
221
- "type": "error",
294
+ "anonymous": False,
222
295
  },
223
296
  {
224
- "anonymous": False,
297
+ "type": "event",
298
+ "name": "FeeDispersed",
225
299
  "inputs": [
226
300
  {
301
+ "name": "recipient",
302
+ "type": "address",
227
303
  "indexed": True,
228
- "internalType": "bytes32",
229
- "name": "productID",
230
- "type": "bytes32",
304
+ "internalType": "address",
231
305
  },
232
306
  {
307
+ "name": "capitalAmount",
308
+ "type": "int256",
233
309
  "indexed": False,
234
- "internalType": "uint256",
235
- "name": "fsp",
310
+ "internalType": "int256",
311
+ },
312
+ {
313
+ "name": "id",
236
314
  "type": "uint256",
315
+ "indexed": False,
316
+ "internalType": "uint256",
237
317
  },
238
318
  ],
239
- "name": "FSPFinalized",
240
- "type": "event",
319
+ "anonymous": False,
241
320
  },
242
321
  {
243
- "anonymous": False,
322
+ "type": "event",
323
+ "name": "FinalSettlementCloseout",
244
324
  "inputs": [
245
325
  {
246
- "indexed": True,
247
- "internalType": "bytes32",
248
326
  "name": "productID",
249
327
  "type": "bytes32",
328
+ "indexed": True,
329
+ "internalType": "bytes32",
250
330
  },
251
331
  {
252
- "indexed": False,
253
- "internalType": "uint256",
254
332
  "name": "accountLength",
255
333
  "type": "uint256",
334
+ "indexed": False,
335
+ "internalType": "uint256",
256
336
  },
257
337
  {
258
- "indexed": False,
259
- "internalType": "address",
260
338
  "name": "closedBy",
261
339
  "type": "address",
340
+ "indexed": False,
341
+ "internalType": "address",
262
342
  },
263
343
  ],
264
- "name": "FinalSettlementCloseout",
344
+ "anonymous": False,
345
+ },
346
+ {
265
347
  "type": "event",
348
+ "name": "PositionUpdated",
349
+ "inputs": [
350
+ {
351
+ "name": "marginAccountId",
352
+ "type": "address",
353
+ "indexed": True,
354
+ "internalType": "address",
355
+ },
356
+ {
357
+ "name": "positionId",
358
+ "type": "bytes32",
359
+ "indexed": True,
360
+ "internalType": "bytes32",
361
+ },
362
+ {
363
+ "name": "costBasis",
364
+ "type": "int256",
365
+ "indexed": False,
366
+ "internalType": "int256",
367
+ },
368
+ {
369
+ "name": "price",
370
+ "type": "int256",
371
+ "indexed": False,
372
+ "internalType": "int256",
373
+ },
374
+ {
375
+ "name": "quantity",
376
+ "type": "int256",
377
+ "indexed": False,
378
+ "internalType": "int256",
379
+ },
380
+ {
381
+ "name": "id",
382
+ "type": "uint256",
383
+ "indexed": False,
384
+ "internalType": "uint256",
385
+ },
386
+ ],
387
+ "anonymous": False,
266
388
  },
267
389
  {
268
- "inputs": [],
269
- "name": "CLOSEOUT_FEE_RATE",
270
- "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
271
- "stateMutability": "pure",
272
- "type": "function",
390
+ "type": "error",
391
+ "name": "FSPAlreadyFinalized",
392
+ "inputs": [
393
+ {"name": "productId", "type": "bytes32", "internalType": "bytes32"}
394
+ ],
273
395
  },
274
396
  {
275
- "inputs": [],
276
- "name": "CLOSEOUT_REWARD_RATE",
277
- "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
278
- "stateMutability": "pure",
279
- "type": "function",
397
+ "type": "error",
398
+ "name": "FSPNotFound",
399
+ "inputs": [
400
+ {"name": "productId", "type": "bytes32", "internalType": "bytes32"}
401
+ ],
280
402
  },
281
403
  {
404
+ "type": "error",
405
+ "name": "FSPTimeNotReached",
282
406
  "inputs": [
283
- {"internalType": "bytes32", "name": "productID", "type": "bytes32"}
407
+ {"name": "productId", "type": "bytes32", "internalType": "bytes32"},
408
+ {"name": "currentTime", "type": "uint256", "internalType": "uint256"},
409
+ {
410
+ "name": "earliestFSPSubmissionTime",
411
+ "type": "uint256",
412
+ "internalType": "uint256",
413
+ },
284
414
  ],
285
- "name": "finalizeFsp",
286
- "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
287
- "stateMutability": "nonpayable",
288
- "type": "function",
289
415
  },
290
416
  {
417
+ "type": "error",
418
+ "name": "InvalidFieldAccess",
291
419
  "inputs": [
292
- {"internalType": "bytes32", "name": "productId", "type": "bytes32"}
420
+ {
421
+ "name": "productType",
422
+ "type": "uint8",
423
+ "internalType": "enum ProductType",
424
+ },
425
+ {"name": "field", "type": "string", "internalType": "string"},
293
426
  ],
294
- "name": "getFsp",
295
- "outputs": [
296
- {"internalType": "uint256", "name": "fsp", "type": "uint256"},
297
- {"internalType": "bool", "name": "finalized", "type": "bool"},
427
+ },
428
+ {
429
+ "type": "error",
430
+ "name": "InvalidOracleAddress",
431
+ "inputs": [
432
+ {"name": "oracleAddress", "type": "address", "internalType": "address"}
298
433
  ],
299
- "stateMutability": "view",
300
- "type": "function",
301
434
  },
302
435
  {
436
+ "type": "error",
437
+ "name": "InvalidParameter",
303
438
  "inputs": [
304
- {"internalType": "bytes32", "name": "productID", "type": "bytes32"},
305
- {"internalType": "address[]", "name": "accounts", "type": "address[]"},
439
+ {"name": "paramName", "type": "string", "internalType": "string"}
306
440
  ],
307
- "name": "initiateFinalSettlement",
308
- "outputs": [],
309
- "stateMutability": "nonpayable",
310
- "type": "function",
311
441
  },
312
442
  {
443
+ "type": "error",
444
+ "name": "MAECheckFailed",
313
445
  "inputs": [
314
- {"internalType": "bytes32", "name": "productId", "type": "bytes32"}
446
+ {"name": "marginAccount", "type": "address", "internalType": "address"}
315
447
  ],
316
- "name": "openInterest",
317
- "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
318
- "stateMutability": "view",
319
- "type": "function",
448
+ },
449
+ {
450
+ "type": "error",
451
+ "name": "MismatchedFSPAccountQuantities",
452
+ "inputs": [
453
+ {"name": "checksum", "type": "int256", "internalType": "int256"},
454
+ {
455
+ "name": "expectedChecksum",
456
+ "type": "int256",
457
+ "internalType": "int256",
458
+ },
459
+ ],
460
+ },
461
+ {
462
+ "type": "error",
463
+ "name": "NotFound",
464
+ "inputs": [
465
+ {"name": "parameter", "type": "string", "internalType": "string"}
466
+ ],
467
+ },
468
+ {
469
+ "type": "error",
470
+ "name": "ProductNotInFinalSettlement",
471
+ "inputs": [
472
+ {"name": "productId", "type": "bytes32", "internalType": "bytes32"}
473
+ ],
474
+ },
475
+ {
476
+ "type": "error",
477
+ "name": "SafeCastOverflowedUintToInt",
478
+ "inputs": [{"name": "value", "type": "uint256", "internalType": "uint256"}],
320
479
  },
321
480
  ],
322
481
  )