afp-sdk 0.1.0__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.
@@ -0,0 +1,1355 @@
1
+ """MarginAccount contract binding and data structures."""
2
+
3
+ # This module has been generated using pyabigen v0.2.16
4
+
5
+ import typing
6
+ from dataclasses import dataclass
7
+
8
+ import eth_typing
9
+ import hexbytes
10
+ import web3
11
+ from web3.contract import contract
12
+
13
+
14
+ @dataclass
15
+ class Settlement:
16
+ """Port of `struct Settlement` on the IMarginAccount contract."""
17
+
18
+ position_id: hexbytes.HexBytes
19
+ quantity: int
20
+ price: int
21
+
22
+
23
+ @dataclass
24
+ class PositionData:
25
+ """Port of `struct PositionData` on the IMarginAccount contract."""
26
+
27
+ position_id: hexbytes.HexBytes
28
+ quantity: int
29
+ cost_basis: int
30
+ maintenance_margin: int
31
+ pnl: int
32
+
33
+
34
+ class MarginAccount:
35
+ """MarginAccount contract binding.
36
+
37
+ Parameters
38
+ ----------
39
+ w3 : web3.Web3
40
+ address : eth_typing.ChecksumAddress
41
+ The address of a deployed MarginAccount contract.
42
+ """
43
+
44
+ _contract: contract.Contract
45
+
46
+ def __init__(
47
+ self,
48
+ w3: web3.Web3,
49
+ address: eth_typing.ChecksumAddress,
50
+ ):
51
+ self._contract = w3.eth.contract(
52
+ address=address,
53
+ abi=ABI,
54
+ )
55
+
56
+ @property
57
+ def FeeCollected(self) -> contract.ContractEvent:
58
+ """Binding for `event FeeCollected` on the MarginAccount contract."""
59
+ return self._contract.events.FeeCollected
60
+
61
+ @property
62
+ def FeeDispersed(self) -> contract.ContractEvent:
63
+ """Binding for `event FeeDispersed` on the MarginAccount contract."""
64
+ return self._contract.events.FeeDispersed
65
+
66
+ @property
67
+ def Initialized(self) -> contract.ContractEvent:
68
+ """Binding for `event Initialized` on the MarginAccount contract."""
69
+ return self._contract.events.Initialized
70
+
71
+ @property
72
+ def PositionUpdated(self) -> contract.ContractEvent:
73
+ """Binding for `event PositionUpdated` on the MarginAccount contract."""
74
+ return self._contract.events.PositionUpdated
75
+
76
+ def authorize(
77
+ self,
78
+ intent_account: eth_typing.ChecksumAddress,
79
+ ) -> contract.ContractFunction:
80
+ """Binding for `authorize` on the MarginAccount contract.
81
+
82
+ Parameters
83
+ ----------
84
+ intent_account : eth_typing.ChecksumAddress
85
+
86
+ Returns
87
+ -------
88
+ web3.contract.contract.ContractFunction
89
+ A contract function instance to be sent in a transaction.
90
+ """
91
+ return self._contract.functions.authorize(
92
+ intent_account,
93
+ )
94
+
95
+ def authorized(
96
+ self,
97
+ margin_account: eth_typing.ChecksumAddress,
98
+ intent_account: eth_typing.ChecksumAddress,
99
+ ) -> bool:
100
+ """Binding for `authorized` on the MarginAccount contract.
101
+
102
+ Parameters
103
+ ----------
104
+ margin_account : eth_typing.ChecksumAddress
105
+ intent_account : eth_typing.ChecksumAddress
106
+
107
+ Returns
108
+ -------
109
+ bool
110
+ """
111
+ return_value = self._contract.functions.authorized(
112
+ margin_account,
113
+ intent_account,
114
+ ).call()
115
+ return bool(return_value)
116
+
117
+ def batch_mae_check(
118
+ self,
119
+ margin_account: eth_typing.ChecksumAddress,
120
+ settlements: typing.List[Settlement],
121
+ mark_price_if_settled: typing.List[int],
122
+ ) -> typing.Tuple[bool, int, int]:
123
+ """Binding for `batchMaeCheck` on the MarginAccount contract.
124
+
125
+ Parameters
126
+ ----------
127
+ margin_account : eth_typing.ChecksumAddress
128
+ settlements : typing.List[Settlement]
129
+ mark_price_if_settled : typing.List[int]
130
+
131
+ Returns
132
+ -------
133
+ bool
134
+ int
135
+ int
136
+ """
137
+ return_value = self._contract.functions.batchMaeCheck(
138
+ margin_account,
139
+ [(item.position_id, item.quantity, item.price) for item in settlements],
140
+ mark_price_if_settled,
141
+ ).call()
142
+ return (
143
+ bool(return_value[0]),
144
+ int(return_value[1]),
145
+ int(return_value[2]),
146
+ )
147
+
148
+ def batch_settle(
149
+ self,
150
+ margin_account_id: eth_typing.ChecksumAddress,
151
+ settlements: typing.List[Settlement],
152
+ ) -> contract.ContractFunction:
153
+ """Binding for `batchSettle` on the MarginAccount contract.
154
+
155
+ Parameters
156
+ ----------
157
+ margin_account_id : eth_typing.ChecksumAddress
158
+ settlements : typing.List[Settlement]
159
+
160
+ Returns
161
+ -------
162
+ web3.contract.contract.ContractFunction
163
+ A contract function instance to be sent in a transaction.
164
+ """
165
+ return self._contract.functions.batchSettle(
166
+ margin_account_id,
167
+ [(item.position_id, item.quantity, item.price) for item in settlements],
168
+ )
169
+
170
+ def capital(
171
+ self,
172
+ margin_account: eth_typing.ChecksumAddress,
173
+ ) -> int:
174
+ """Binding for `capital` on the MarginAccount contract.
175
+
176
+ Parameters
177
+ ----------
178
+ margin_account : eth_typing.ChecksumAddress
179
+
180
+ Returns
181
+ -------
182
+ int
183
+ """
184
+ return_value = self._contract.functions.capital(
185
+ margin_account,
186
+ ).call()
187
+ return int(return_value)
188
+
189
+ def clearing(
190
+ self,
191
+ ) -> eth_typing.ChecksumAddress:
192
+ """Binding for `clearing` on the MarginAccount contract.
193
+
194
+ Returns
195
+ -------
196
+ eth_typing.ChecksumAddress
197
+ """
198
+ return_value = self._contract.functions.clearing().call()
199
+ return eth_typing.ChecksumAddress(return_value)
200
+
201
+ def collateral_asset(
202
+ self,
203
+ ) -> eth_typing.ChecksumAddress:
204
+ """Binding for `collateralAsset` on the MarginAccount contract.
205
+
206
+ Returns
207
+ -------
208
+ eth_typing.ChecksumAddress
209
+ """
210
+ return_value = self._contract.functions.collateralAsset().call()
211
+ return eth_typing.ChecksumAddress(return_value)
212
+
213
+ def collateral_token(
214
+ self,
215
+ ) -> eth_typing.ChecksumAddress:
216
+ """Binding for `collateralToken` on the MarginAccount contract.
217
+
218
+ Returns
219
+ -------
220
+ eth_typing.ChecksumAddress
221
+ """
222
+ return_value = self._contract.functions.collateralToken().call()
223
+ return eth_typing.ChecksumAddress(return_value)
224
+
225
+ def collect_fee(
226
+ self,
227
+ margin_account: eth_typing.ChecksumAddress,
228
+ capital_amount: int,
229
+ ) -> contract.ContractFunction:
230
+ """Binding for `collectFee` on the MarginAccount contract.
231
+
232
+ Parameters
233
+ ----------
234
+ margin_account : eth_typing.ChecksumAddress
235
+ capital_amount : int
236
+
237
+ Returns
238
+ -------
239
+ web3.contract.contract.ContractFunction
240
+ A contract function instance to be sent in a transaction.
241
+ """
242
+ return self._contract.functions.collectFee(
243
+ margin_account,
244
+ capital_amount,
245
+ )
246
+
247
+ def deposit(
248
+ self,
249
+ amount: int,
250
+ ) -> contract.ContractFunction:
251
+ """Binding for `deposit` on the MarginAccount contract.
252
+
253
+ Parameters
254
+ ----------
255
+ amount : int
256
+
257
+ Returns
258
+ -------
259
+ web3.contract.contract.ContractFunction
260
+ A contract function instance to be sent in a transaction.
261
+ """
262
+ return self._contract.functions.deposit(
263
+ amount,
264
+ )
265
+
266
+ def disperse_fees(
267
+ self,
268
+ recipients: typing.List[eth_typing.ChecksumAddress],
269
+ capital_amounts: typing.List[int],
270
+ ) -> contract.ContractFunction:
271
+ """Binding for `disperseFees` on the MarginAccount contract.
272
+
273
+ Parameters
274
+ ----------
275
+ recipients : typing.List[eth_typing.ChecksumAddress]
276
+ capital_amounts : typing.List[int]
277
+
278
+ Returns
279
+ -------
280
+ web3.contract.contract.ContractFunction
281
+ A contract function instance to be sent in a transaction.
282
+ """
283
+ return self._contract.functions.disperseFees(
284
+ recipients,
285
+ capital_amounts,
286
+ )
287
+
288
+ def estimate_liquidation_price(
289
+ self,
290
+ margin_account_id: eth_typing.ChecksumAddress,
291
+ product_id: hexbytes.HexBytes,
292
+ price: int,
293
+ quantity: int,
294
+ ) -> int:
295
+ """Binding for `estimateLiquidationPrice` on the MarginAccount contract.
296
+
297
+ Parameters
298
+ ----------
299
+ margin_account_id : eth_typing.ChecksumAddress
300
+ product_id : hexbytes.HexBytes
301
+ price : int
302
+ quantity : int
303
+
304
+ Returns
305
+ -------
306
+ int
307
+ """
308
+ return_value = self._contract.functions.estimateLiquidationPrice(
309
+ margin_account_id,
310
+ product_id,
311
+ price,
312
+ quantity,
313
+ ).call()
314
+ return int(return_value)
315
+
316
+ def estimate_liquidation_price_for_position(
317
+ self,
318
+ margin_account_id: eth_typing.ChecksumAddress,
319
+ position_id: hexbytes.HexBytes,
320
+ ) -> int:
321
+ """Binding for `estimateLiquidationPriceForPosition` on the MarginAccount contract.
322
+
323
+ Parameters
324
+ ----------
325
+ margin_account_id : eth_typing.ChecksumAddress
326
+ position_id : hexbytes.HexBytes
327
+
328
+ Returns
329
+ -------
330
+ int
331
+ """
332
+ return_value = self._contract.functions.estimateLiquidationPriceForPosition(
333
+ margin_account_id,
334
+ position_id,
335
+ ).call()
336
+ return int(return_value)
337
+
338
+ def initialize(
339
+ self,
340
+ _collateral_token: eth_typing.ChecksumAddress,
341
+ _valuation: eth_typing.ChecksumAddress,
342
+ _product_registry: eth_typing.ChecksumAddress,
343
+ _clearing: eth_typing.ChecksumAddress,
344
+ ) -> contract.ContractFunction:
345
+ """Binding for `initialize` on the MarginAccount contract.
346
+
347
+ Parameters
348
+ ----------
349
+ _collateral_token : eth_typing.ChecksumAddress
350
+ _valuation : eth_typing.ChecksumAddress
351
+ _product_registry : eth_typing.ChecksumAddress
352
+ _clearing : eth_typing.ChecksumAddress
353
+
354
+ Returns
355
+ -------
356
+ web3.contract.contract.ContractFunction
357
+ A contract function instance to be sent in a transaction.
358
+ """
359
+ return self._contract.functions.initialize(
360
+ _collateral_token,
361
+ _valuation,
362
+ _product_registry,
363
+ _clearing,
364
+ )
365
+
366
+ def mae(
367
+ self,
368
+ margin_account: eth_typing.ChecksumAddress,
369
+ ) -> int:
370
+ """Binding for `mae` on the MarginAccount contract.
371
+
372
+ Parameters
373
+ ----------
374
+ margin_account : eth_typing.ChecksumAddress
375
+
376
+ Returns
377
+ -------
378
+ int
379
+ """
380
+ return_value = self._contract.functions.mae(
381
+ margin_account,
382
+ ).call()
383
+ return int(return_value)
384
+
385
+ def mae_and_mmu_after_batch_trade(
386
+ self,
387
+ margin_account: eth_typing.ChecksumAddress,
388
+ settlements: typing.List[Settlement],
389
+ mark_price_if_settled: typing.List[int],
390
+ ) -> typing.Tuple[int, int]:
391
+ """Binding for `maeAndMmuAfterBatchTrade` on the MarginAccount contract.
392
+
393
+ Parameters
394
+ ----------
395
+ margin_account : eth_typing.ChecksumAddress
396
+ settlements : typing.List[Settlement]
397
+ mark_price_if_settled : typing.List[int]
398
+
399
+ Returns
400
+ -------
401
+ int
402
+ int
403
+ """
404
+ return_value = self._contract.functions.maeAndMmuAfterBatchTrade(
405
+ margin_account,
406
+ [(item.position_id, item.quantity, item.price) for item in settlements],
407
+ mark_price_if_settled,
408
+ ).call()
409
+ return (
410
+ int(return_value[0]),
411
+ int(return_value[1]),
412
+ )
413
+
414
+ def mae_check(
415
+ self,
416
+ margin_account: eth_typing.ChecksumAddress,
417
+ settlement: Settlement,
418
+ mark_price_if_settled: int,
419
+ ) -> typing.Tuple[bool, int, int]:
420
+ """Binding for `maeCheck` on the MarginAccount contract.
421
+
422
+ Parameters
423
+ ----------
424
+ margin_account : eth_typing.ChecksumAddress
425
+ settlement : Settlement
426
+ mark_price_if_settled : int
427
+
428
+ Returns
429
+ -------
430
+ bool
431
+ int
432
+ int
433
+ """
434
+ return_value = self._contract.functions.maeCheck(
435
+ margin_account,
436
+ (settlement.position_id, settlement.quantity, settlement.price),
437
+ mark_price_if_settled,
438
+ ).call()
439
+ return (
440
+ bool(return_value[0]),
441
+ int(return_value[1]),
442
+ int(return_value[2]),
443
+ )
444
+
445
+ def mma(
446
+ self,
447
+ margin_account: eth_typing.ChecksumAddress,
448
+ ) -> int:
449
+ """Binding for `mma` on the MarginAccount contract.
450
+
451
+ Parameters
452
+ ----------
453
+ margin_account : eth_typing.ChecksumAddress
454
+
455
+ Returns
456
+ -------
457
+ int
458
+ """
459
+ return_value = self._contract.functions.mma(
460
+ margin_account,
461
+ ).call()
462
+ return int(return_value)
463
+
464
+ def mmu(
465
+ self,
466
+ margin_account: eth_typing.ChecksumAddress,
467
+ ) -> int:
468
+ """Binding for `mmu` on the MarginAccount contract.
469
+
470
+ Parameters
471
+ ----------
472
+ margin_account : eth_typing.ChecksumAddress
473
+
474
+ Returns
475
+ -------
476
+ int
477
+ """
478
+ return_value = self._contract.functions.mmu(
479
+ margin_account,
480
+ ).call()
481
+ return int(return_value)
482
+
483
+ def pnl(
484
+ self,
485
+ margin_account: eth_typing.ChecksumAddress,
486
+ ) -> int:
487
+ """Binding for `pnl` on the MarginAccount contract.
488
+
489
+ Parameters
490
+ ----------
491
+ margin_account : eth_typing.ChecksumAddress
492
+
493
+ Returns
494
+ -------
495
+ int
496
+ """
497
+ return_value = self._contract.functions.pnl(
498
+ margin_account,
499
+ ).call()
500
+ return int(return_value)
501
+
502
+ def position_age(
503
+ self,
504
+ margin_account_id: eth_typing.ChecksumAddress,
505
+ position_id: hexbytes.HexBytes,
506
+ ) -> int:
507
+ """Binding for `positionAge` on the MarginAccount contract.
508
+
509
+ Parameters
510
+ ----------
511
+ margin_account_id : eth_typing.ChecksumAddress
512
+ position_id : hexbytes.HexBytes
513
+
514
+ Returns
515
+ -------
516
+ int
517
+ """
518
+ return_value = self._contract.functions.positionAge(
519
+ margin_account_id,
520
+ position_id,
521
+ ).call()
522
+ return int(return_value)
523
+
524
+ def position_count(
525
+ self,
526
+ margin_account: eth_typing.ChecksumAddress,
527
+ ) -> int:
528
+ """Binding for `positionCount` on the MarginAccount contract.
529
+
530
+ Parameters
531
+ ----------
532
+ margin_account : eth_typing.ChecksumAddress
533
+
534
+ Returns
535
+ -------
536
+ int
537
+ """
538
+ return_value = self._contract.functions.positionCount(
539
+ margin_account,
540
+ ).call()
541
+ return int(return_value)
542
+
543
+ def position_data(
544
+ self,
545
+ margin_account: eth_typing.ChecksumAddress,
546
+ position_id: hexbytes.HexBytes,
547
+ ) -> PositionData:
548
+ """Binding for `positionData` on the MarginAccount contract.
549
+
550
+ Parameters
551
+ ----------
552
+ margin_account : eth_typing.ChecksumAddress
553
+ position_id : hexbytes.HexBytes
554
+
555
+ Returns
556
+ -------
557
+ PositionData
558
+ """
559
+ return_value = self._contract.functions.positionData(
560
+ margin_account,
561
+ position_id,
562
+ ).call()
563
+ return PositionData(
564
+ hexbytes.HexBytes(return_value[0]),
565
+ int(return_value[1]),
566
+ int(return_value[2]),
567
+ int(return_value[3]),
568
+ int(return_value[4]),
569
+ )
570
+
571
+ def position_pn_l(
572
+ self,
573
+ margin_account: eth_typing.ChecksumAddress,
574
+ position_id: hexbytes.HexBytes,
575
+ ) -> int:
576
+ """Binding for `positionPnL` on the MarginAccount contract.
577
+
578
+ Parameters
579
+ ----------
580
+ margin_account : eth_typing.ChecksumAddress
581
+ position_id : hexbytes.HexBytes
582
+
583
+ Returns
584
+ -------
585
+ int
586
+ """
587
+ return_value = self._contract.functions.positionPnL(
588
+ margin_account,
589
+ position_id,
590
+ ).call()
591
+ return int(return_value)
592
+
593
+ def position_quantity(
594
+ self,
595
+ margin_account: eth_typing.ChecksumAddress,
596
+ position_id: hexbytes.HexBytes,
597
+ ) -> int:
598
+ """Binding for `positionQuantity` on the MarginAccount contract.
599
+
600
+ Parameters
601
+ ----------
602
+ margin_account : eth_typing.ChecksumAddress
603
+ position_id : hexbytes.HexBytes
604
+
605
+ Returns
606
+ -------
607
+ int
608
+ """
609
+ return_value = self._contract.functions.positionQuantity(
610
+ margin_account,
611
+ position_id,
612
+ ).call()
613
+ return int(return_value)
614
+
615
+ def positions(
616
+ self,
617
+ margin_account: eth_typing.ChecksumAddress,
618
+ ) -> typing.List[hexbytes.HexBytes]:
619
+ """Binding for `positions` on the MarginAccount contract.
620
+
621
+ Parameters
622
+ ----------
623
+ margin_account : eth_typing.ChecksumAddress
624
+
625
+ Returns
626
+ -------
627
+ typing.List[hexbytes.HexBytes]
628
+ """
629
+ return_value = self._contract.functions.positions(
630
+ margin_account,
631
+ ).call()
632
+ return [
633
+ hexbytes.HexBytes(return_value_elem) for return_value_elem in return_value
634
+ ]
635
+
636
+ def product_registry(
637
+ self,
638
+ ) -> eth_typing.ChecksumAddress:
639
+ """Binding for `productRegistry` on the MarginAccount contract.
640
+
641
+ Returns
642
+ -------
643
+ eth_typing.ChecksumAddress
644
+ """
645
+ return_value = self._contract.functions.productRegistry().call()
646
+ return eth_typing.ChecksumAddress(return_value)
647
+
648
+ def revoke_authorization(
649
+ self,
650
+ intent_account: eth_typing.ChecksumAddress,
651
+ ) -> contract.ContractFunction:
652
+ """Binding for `revokeAuthorization` on the MarginAccount contract.
653
+
654
+ Parameters
655
+ ----------
656
+ intent_account : eth_typing.ChecksumAddress
657
+
658
+ Returns
659
+ -------
660
+ web3.contract.contract.ContractFunction
661
+ A contract function instance to be sent in a transaction.
662
+ """
663
+ return self._contract.functions.revokeAuthorization(
664
+ intent_account,
665
+ )
666
+
667
+ def settle(
668
+ self,
669
+ margin_account: eth_typing.ChecksumAddress,
670
+ intent_account: eth_typing.ChecksumAddress,
671
+ settlement: Settlement,
672
+ ) -> contract.ContractFunction:
673
+ """Binding for `settle` on the MarginAccount contract.
674
+
675
+ Parameters
676
+ ----------
677
+ margin_account : eth_typing.ChecksumAddress
678
+ intent_account : eth_typing.ChecksumAddress
679
+ settlement : Settlement
680
+
681
+ Returns
682
+ -------
683
+ web3.contract.contract.ContractFunction
684
+ A contract function instance to be sent in a transaction.
685
+ """
686
+ return self._contract.functions.settle(
687
+ margin_account,
688
+ intent_account,
689
+ (settlement.position_id, settlement.quantity, settlement.price),
690
+ )
691
+
692
+ def valuation(
693
+ self,
694
+ ) -> eth_typing.ChecksumAddress:
695
+ """Binding for `valuation` on the MarginAccount contract.
696
+
697
+ Returns
698
+ -------
699
+ eth_typing.ChecksumAddress
700
+ """
701
+ return_value = self._contract.functions.valuation().call()
702
+ return eth_typing.ChecksumAddress(return_value)
703
+
704
+ def withdraw(
705
+ self,
706
+ amount: int,
707
+ ) -> contract.ContractFunction:
708
+ """Binding for `withdraw` on the MarginAccount contract.
709
+
710
+ Parameters
711
+ ----------
712
+ amount : int
713
+
714
+ Returns
715
+ -------
716
+ web3.contract.contract.ContractFunction
717
+ A contract function instance to be sent in a transaction.
718
+ """
719
+ return self._contract.functions.withdraw(
720
+ amount,
721
+ )
722
+
723
+ def withdrawable(
724
+ self,
725
+ margin_account: eth_typing.ChecksumAddress,
726
+ ) -> int:
727
+ """Binding for `withdrawable` on the MarginAccount contract.
728
+
729
+ Parameters
730
+ ----------
731
+ margin_account : eth_typing.ChecksumAddress
732
+
733
+ Returns
734
+ -------
735
+ int
736
+ """
737
+ return_value = self._contract.functions.withdrawable(
738
+ margin_account,
739
+ ).call()
740
+ return int(return_value)
741
+
742
+
743
+ ABI = typing.cast(
744
+ eth_typing.ABI,
745
+ [
746
+ {
747
+ "inputs": [
748
+ {"internalType": "uint256", "name": "dispersed", "type": "uint256"},
749
+ {"internalType": "int256", "name": "collected", "type": "int256"},
750
+ ],
751
+ "name": "FeeInvariantViolated",
752
+ "type": "error",
753
+ },
754
+ {
755
+ "inputs": [
756
+ {"internalType": "address", "name": "account", "type": "address"},
757
+ {"internalType": "uint256", "name": "balance", "type": "uint256"},
758
+ {"internalType": "uint256", "name": "required", "type": "uint256"},
759
+ ],
760
+ "name": "InsufficientBalance",
761
+ "type": "error",
762
+ },
763
+ {"inputs": [], "name": "InvalidInitialization", "type": "error"},
764
+ {
765
+ "inputs": [
766
+ {"internalType": "string", "name": "paramName", "type": "string"}
767
+ ],
768
+ "name": "InvalidParameter",
769
+ "type": "error",
770
+ },
771
+ {"inputs": [], "name": "NotInitializing", "type": "error"},
772
+ {
773
+ "inputs": [
774
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
775
+ {"internalType": "bytes32", "name": "productId", "type": "bytes32"},
776
+ ],
777
+ "name": "PositionNotFound",
778
+ "type": "error",
779
+ },
780
+ {
781
+ "inputs": [{"internalType": "address", "name": "token", "type": "address"}],
782
+ "name": "SafeERC20FailedOperation",
783
+ "type": "error",
784
+ },
785
+ {
786
+ "inputs": [
787
+ {"internalType": "address", "name": "account", "type": "address"}
788
+ ],
789
+ "name": "Unauthorized",
790
+ "type": "error",
791
+ },
792
+ {
793
+ "anonymous": False,
794
+ "inputs": [
795
+ {
796
+ "indexed": True,
797
+ "internalType": "address",
798
+ "name": "marginAccountID",
799
+ "type": "address",
800
+ },
801
+ {
802
+ "indexed": False,
803
+ "internalType": "int256",
804
+ "name": "capitalAmount",
805
+ "type": "int256",
806
+ },
807
+ ],
808
+ "name": "FeeCollected",
809
+ "type": "event",
810
+ },
811
+ {
812
+ "anonymous": False,
813
+ "inputs": [
814
+ {
815
+ "indexed": True,
816
+ "internalType": "address",
817
+ "name": "recipient",
818
+ "type": "address",
819
+ },
820
+ {
821
+ "indexed": False,
822
+ "internalType": "uint256",
823
+ "name": "capitalAmount",
824
+ "type": "uint256",
825
+ },
826
+ ],
827
+ "name": "FeeDispersed",
828
+ "type": "event",
829
+ },
830
+ {
831
+ "anonymous": False,
832
+ "inputs": [
833
+ {
834
+ "indexed": False,
835
+ "internalType": "uint64",
836
+ "name": "version",
837
+ "type": "uint64",
838
+ }
839
+ ],
840
+ "name": "Initialized",
841
+ "type": "event",
842
+ },
843
+ {
844
+ "anonymous": False,
845
+ "inputs": [
846
+ {
847
+ "indexed": True,
848
+ "internalType": "address",
849
+ "name": "marginAccountID",
850
+ "type": "address",
851
+ },
852
+ {
853
+ "indexed": True,
854
+ "internalType": "bytes32",
855
+ "name": "positionId",
856
+ "type": "bytes32",
857
+ },
858
+ {
859
+ "indexed": False,
860
+ "internalType": "int256",
861
+ "name": "totalQuantity",
862
+ "type": "int256",
863
+ },
864
+ {
865
+ "indexed": False,
866
+ "internalType": "int256",
867
+ "name": "costBasis",
868
+ "type": "int256",
869
+ },
870
+ ],
871
+ "name": "PositionUpdated",
872
+ "type": "event",
873
+ },
874
+ {
875
+ "inputs": [
876
+ {"internalType": "address", "name": "intentAccount", "type": "address"}
877
+ ],
878
+ "name": "authorize",
879
+ "outputs": [],
880
+ "stateMutability": "nonpayable",
881
+ "type": "function",
882
+ },
883
+ {
884
+ "inputs": [
885
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
886
+ {"internalType": "address", "name": "intentAccount", "type": "address"},
887
+ ],
888
+ "name": "authorized",
889
+ "outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
890
+ "stateMutability": "view",
891
+ "type": "function",
892
+ },
893
+ {
894
+ "inputs": [
895
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
896
+ {
897
+ "components": [
898
+ {
899
+ "internalType": "bytes32",
900
+ "name": "positionId",
901
+ "type": "bytes32",
902
+ },
903
+ {
904
+ "internalType": "int256",
905
+ "name": "quantity",
906
+ "type": "int256",
907
+ },
908
+ {"internalType": "uint256", "name": "price", "type": "uint256"},
909
+ ],
910
+ "internalType": "struct IMarginAccount.Settlement[]",
911
+ "name": "settlements",
912
+ "type": "tuple[]",
913
+ },
914
+ {
915
+ "internalType": "uint256[]",
916
+ "name": "markPriceIfSettled",
917
+ "type": "uint256[]",
918
+ },
919
+ ],
920
+ "name": "batchMaeCheck",
921
+ "outputs": [
922
+ {"internalType": "bool", "name": "checkPassed", "type": "bool"},
923
+ {"internalType": "int256", "name": "maeAfter", "type": "int256"},
924
+ {"internalType": "uint256", "name": "mmuAfter", "type": "uint256"},
925
+ ],
926
+ "stateMutability": "view",
927
+ "type": "function",
928
+ },
929
+ {
930
+ "inputs": [
931
+ {
932
+ "internalType": "address",
933
+ "name": "marginAccountID",
934
+ "type": "address",
935
+ },
936
+ {
937
+ "components": [
938
+ {
939
+ "internalType": "bytes32",
940
+ "name": "positionId",
941
+ "type": "bytes32",
942
+ },
943
+ {
944
+ "internalType": "int256",
945
+ "name": "quantity",
946
+ "type": "int256",
947
+ },
948
+ {"internalType": "uint256", "name": "price", "type": "uint256"},
949
+ ],
950
+ "internalType": "struct IMarginAccount.Settlement[]",
951
+ "name": "settlements",
952
+ "type": "tuple[]",
953
+ },
954
+ ],
955
+ "name": "batchSettle",
956
+ "outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
957
+ "stateMutability": "nonpayable",
958
+ "type": "function",
959
+ },
960
+ {
961
+ "inputs": [
962
+ {"internalType": "address", "name": "marginAccount", "type": "address"}
963
+ ],
964
+ "name": "capital",
965
+ "outputs": [{"internalType": "int256", "name": "", "type": "int256"}],
966
+ "stateMutability": "view",
967
+ "type": "function",
968
+ },
969
+ {
970
+ "inputs": [],
971
+ "name": "clearing",
972
+ "outputs": [{"internalType": "address", "name": "", "type": "address"}],
973
+ "stateMutability": "view",
974
+ "type": "function",
975
+ },
976
+ {
977
+ "inputs": [],
978
+ "name": "collateralAsset",
979
+ "outputs": [{"internalType": "address", "name": "", "type": "address"}],
980
+ "stateMutability": "view",
981
+ "type": "function",
982
+ },
983
+ {
984
+ "inputs": [],
985
+ "name": "collateralToken",
986
+ "outputs": [
987
+ {"internalType": "contract IERC20", "name": "", "type": "address"}
988
+ ],
989
+ "stateMutability": "view",
990
+ "type": "function",
991
+ },
992
+ {
993
+ "inputs": [
994
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
995
+ {"internalType": "int256", "name": "capitalAmount", "type": "int256"},
996
+ ],
997
+ "name": "collectFee",
998
+ "outputs": [],
999
+ "stateMutability": "nonpayable",
1000
+ "type": "function",
1001
+ },
1002
+ {
1003
+ "inputs": [
1004
+ {"internalType": "uint256", "name": "amount", "type": "uint256"}
1005
+ ],
1006
+ "name": "deposit",
1007
+ "outputs": [],
1008
+ "stateMutability": "nonpayable",
1009
+ "type": "function",
1010
+ },
1011
+ {
1012
+ "inputs": [
1013
+ {
1014
+ "internalType": "address[]",
1015
+ "name": "recipients",
1016
+ "type": "address[]",
1017
+ },
1018
+ {
1019
+ "internalType": "uint256[]",
1020
+ "name": "capitalAmounts",
1021
+ "type": "uint256[]",
1022
+ },
1023
+ ],
1024
+ "name": "disperseFees",
1025
+ "outputs": [],
1026
+ "stateMutability": "nonpayable",
1027
+ "type": "function",
1028
+ },
1029
+ {
1030
+ "inputs": [
1031
+ {
1032
+ "internalType": "address",
1033
+ "name": "marginAccountId",
1034
+ "type": "address",
1035
+ },
1036
+ {"internalType": "bytes32", "name": "productId", "type": "bytes32"},
1037
+ {"internalType": "uint256", "name": "price", "type": "uint256"},
1038
+ {"internalType": "int256", "name": "quantity", "type": "int256"},
1039
+ ],
1040
+ "name": "estimateLiquidationPrice",
1041
+ "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
1042
+ "stateMutability": "view",
1043
+ "type": "function",
1044
+ },
1045
+ {
1046
+ "inputs": [
1047
+ {
1048
+ "internalType": "address",
1049
+ "name": "marginAccountId",
1050
+ "type": "address",
1051
+ },
1052
+ {"internalType": "bytes32", "name": "positionId", "type": "bytes32"},
1053
+ ],
1054
+ "name": "estimateLiquidationPriceForPosition",
1055
+ "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
1056
+ "stateMutability": "view",
1057
+ "type": "function",
1058
+ },
1059
+ {
1060
+ "inputs": [
1061
+ {
1062
+ "internalType": "address",
1063
+ "name": "_collateralToken",
1064
+ "type": "address",
1065
+ },
1066
+ {"internalType": "address", "name": "_valuation", "type": "address"},
1067
+ {
1068
+ "internalType": "address",
1069
+ "name": "_productRegistry",
1070
+ "type": "address",
1071
+ },
1072
+ {"internalType": "address", "name": "_clearing", "type": "address"},
1073
+ ],
1074
+ "name": "initialize",
1075
+ "outputs": [],
1076
+ "stateMutability": "nonpayable",
1077
+ "type": "function",
1078
+ },
1079
+ {
1080
+ "inputs": [
1081
+ {"internalType": "address", "name": "marginAccount", "type": "address"}
1082
+ ],
1083
+ "name": "mae",
1084
+ "outputs": [{"internalType": "int256", "name": "", "type": "int256"}],
1085
+ "stateMutability": "view",
1086
+ "type": "function",
1087
+ },
1088
+ {
1089
+ "inputs": [
1090
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
1091
+ {
1092
+ "components": [
1093
+ {
1094
+ "internalType": "bytes32",
1095
+ "name": "positionId",
1096
+ "type": "bytes32",
1097
+ },
1098
+ {
1099
+ "internalType": "int256",
1100
+ "name": "quantity",
1101
+ "type": "int256",
1102
+ },
1103
+ {"internalType": "uint256", "name": "price", "type": "uint256"},
1104
+ ],
1105
+ "internalType": "struct IMarginAccount.Settlement[]",
1106
+ "name": "settlements",
1107
+ "type": "tuple[]",
1108
+ },
1109
+ {
1110
+ "internalType": "uint256[]",
1111
+ "name": "markPriceIfSettled",
1112
+ "type": "uint256[]",
1113
+ },
1114
+ ],
1115
+ "name": "maeAndMmuAfterBatchTrade",
1116
+ "outputs": [
1117
+ {"internalType": "int256", "name": "maeAfter", "type": "int256"},
1118
+ {"internalType": "uint256", "name": "mmuAfter", "type": "uint256"},
1119
+ ],
1120
+ "stateMutability": "view",
1121
+ "type": "function",
1122
+ },
1123
+ {
1124
+ "inputs": [
1125
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
1126
+ {
1127
+ "components": [
1128
+ {
1129
+ "internalType": "bytes32",
1130
+ "name": "positionId",
1131
+ "type": "bytes32",
1132
+ },
1133
+ {
1134
+ "internalType": "int256",
1135
+ "name": "quantity",
1136
+ "type": "int256",
1137
+ },
1138
+ {"internalType": "uint256", "name": "price", "type": "uint256"},
1139
+ ],
1140
+ "internalType": "struct IMarginAccount.Settlement",
1141
+ "name": "settlement",
1142
+ "type": "tuple",
1143
+ },
1144
+ {
1145
+ "internalType": "uint256",
1146
+ "name": "markPriceIfSettled",
1147
+ "type": "uint256",
1148
+ },
1149
+ ],
1150
+ "name": "maeCheck",
1151
+ "outputs": [
1152
+ {"internalType": "bool", "name": "checkPassed", "type": "bool"},
1153
+ {"internalType": "int256", "name": "maeAfter", "type": "int256"},
1154
+ {"internalType": "uint256", "name": "mmuAfter", "type": "uint256"},
1155
+ ],
1156
+ "stateMutability": "view",
1157
+ "type": "function",
1158
+ },
1159
+ {
1160
+ "inputs": [
1161
+ {"internalType": "address", "name": "marginAccount", "type": "address"}
1162
+ ],
1163
+ "name": "mma",
1164
+ "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
1165
+ "stateMutability": "view",
1166
+ "type": "function",
1167
+ },
1168
+ {
1169
+ "inputs": [
1170
+ {"internalType": "address", "name": "marginAccount", "type": "address"}
1171
+ ],
1172
+ "name": "mmu",
1173
+ "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
1174
+ "stateMutability": "view",
1175
+ "type": "function",
1176
+ },
1177
+ {
1178
+ "inputs": [
1179
+ {"internalType": "address", "name": "marginAccount", "type": "address"}
1180
+ ],
1181
+ "name": "pnl",
1182
+ "outputs": [{"internalType": "int256", "name": "", "type": "int256"}],
1183
+ "stateMutability": "view",
1184
+ "type": "function",
1185
+ },
1186
+ {
1187
+ "inputs": [
1188
+ {
1189
+ "internalType": "address",
1190
+ "name": "marginAccountId",
1191
+ "type": "address",
1192
+ },
1193
+ {"internalType": "bytes32", "name": "positionId", "type": "bytes32"},
1194
+ ],
1195
+ "name": "positionAge",
1196
+ "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
1197
+ "stateMutability": "view",
1198
+ "type": "function",
1199
+ },
1200
+ {
1201
+ "inputs": [
1202
+ {"internalType": "address", "name": "marginAccount", "type": "address"}
1203
+ ],
1204
+ "name": "positionCount",
1205
+ "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
1206
+ "stateMutability": "view",
1207
+ "type": "function",
1208
+ },
1209
+ {
1210
+ "inputs": [
1211
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
1212
+ {"internalType": "bytes32", "name": "positionId", "type": "bytes32"},
1213
+ ],
1214
+ "name": "positionData",
1215
+ "outputs": [
1216
+ {
1217
+ "components": [
1218
+ {
1219
+ "internalType": "bytes32",
1220
+ "name": "positionId",
1221
+ "type": "bytes32",
1222
+ },
1223
+ {
1224
+ "internalType": "int256",
1225
+ "name": "quantity",
1226
+ "type": "int256",
1227
+ },
1228
+ {
1229
+ "internalType": "int256",
1230
+ "name": "costBasis",
1231
+ "type": "int256",
1232
+ },
1233
+ {
1234
+ "internalType": "uint256",
1235
+ "name": "maintenanceMargin",
1236
+ "type": "uint256",
1237
+ },
1238
+ {"internalType": "int256", "name": "pnl", "type": "int256"},
1239
+ ],
1240
+ "internalType": "struct IMarginAccount.PositionData",
1241
+ "name": "",
1242
+ "type": "tuple",
1243
+ }
1244
+ ],
1245
+ "stateMutability": "view",
1246
+ "type": "function",
1247
+ },
1248
+ {
1249
+ "inputs": [
1250
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
1251
+ {"internalType": "bytes32", "name": "positionId", "type": "bytes32"},
1252
+ ],
1253
+ "name": "positionPnL",
1254
+ "outputs": [{"internalType": "int256", "name": "", "type": "int256"}],
1255
+ "stateMutability": "view",
1256
+ "type": "function",
1257
+ },
1258
+ {
1259
+ "inputs": [
1260
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
1261
+ {"internalType": "bytes32", "name": "positionId", "type": "bytes32"},
1262
+ ],
1263
+ "name": "positionQuantity",
1264
+ "outputs": [{"internalType": "int256", "name": "", "type": "int256"}],
1265
+ "stateMutability": "view",
1266
+ "type": "function",
1267
+ },
1268
+ {
1269
+ "inputs": [
1270
+ {"internalType": "address", "name": "marginAccount", "type": "address"}
1271
+ ],
1272
+ "name": "positions",
1273
+ "outputs": [{"internalType": "bytes32[]", "name": "", "type": "bytes32[]"}],
1274
+ "stateMutability": "view",
1275
+ "type": "function",
1276
+ },
1277
+ {
1278
+ "inputs": [],
1279
+ "name": "productRegistry",
1280
+ "outputs": [
1281
+ {
1282
+ "internalType": "contract IProductRegistry",
1283
+ "name": "",
1284
+ "type": "address",
1285
+ }
1286
+ ],
1287
+ "stateMutability": "view",
1288
+ "type": "function",
1289
+ },
1290
+ {
1291
+ "inputs": [
1292
+ {"internalType": "address", "name": "intentAccount", "type": "address"}
1293
+ ],
1294
+ "name": "revokeAuthorization",
1295
+ "outputs": [],
1296
+ "stateMutability": "nonpayable",
1297
+ "type": "function",
1298
+ },
1299
+ {
1300
+ "inputs": [
1301
+ {"internalType": "address", "name": "marginAccount", "type": "address"},
1302
+ {"internalType": "address", "name": "intentAccount", "type": "address"},
1303
+ {
1304
+ "components": [
1305
+ {
1306
+ "internalType": "bytes32",
1307
+ "name": "positionId",
1308
+ "type": "bytes32",
1309
+ },
1310
+ {
1311
+ "internalType": "int256",
1312
+ "name": "quantity",
1313
+ "type": "int256",
1314
+ },
1315
+ {"internalType": "uint256", "name": "price", "type": "uint256"},
1316
+ ],
1317
+ "internalType": "struct IMarginAccount.Settlement",
1318
+ "name": "settlement",
1319
+ "type": "tuple",
1320
+ },
1321
+ ],
1322
+ "name": "settle",
1323
+ "outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
1324
+ "stateMutability": "nonpayable",
1325
+ "type": "function",
1326
+ },
1327
+ {
1328
+ "inputs": [],
1329
+ "name": "valuation",
1330
+ "outputs": [
1331
+ {"internalType": "contract IValuation", "name": "", "type": "address"}
1332
+ ],
1333
+ "stateMutability": "view",
1334
+ "type": "function",
1335
+ },
1336
+ {
1337
+ "inputs": [
1338
+ {"internalType": "uint256", "name": "amount", "type": "uint256"}
1339
+ ],
1340
+ "name": "withdraw",
1341
+ "outputs": [],
1342
+ "stateMutability": "nonpayable",
1343
+ "type": "function",
1344
+ },
1345
+ {
1346
+ "inputs": [
1347
+ {"internalType": "address", "name": "marginAccount", "type": "address"}
1348
+ ],
1349
+ "name": "withdrawable",
1350
+ "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
1351
+ "stateMutability": "view",
1352
+ "type": "function",
1353
+ },
1354
+ ],
1355
+ )