-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathmodels.py
More file actions
80 lines (66 loc) · 1.81 KB
/
models.py
File metadata and controls
80 lines (66 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from dataclasses import dataclass, field
from typing import List, Optional
@dataclass
class Asset:
"""Represents a registered asset on the SORA network."""
asset_id: str
symbol: str
name: str
precision: int = 18
is_mintable: bool = False
total_supply: str = "0"
@dataclass
class Pool:
"""Represents a liquidity pool on the Polkaswap DEX."""
base_asset: Asset
target_asset: Asset
base_reserves: str = "0"
target_reserves: str = "0"
total_liquidity: str = "0"
fee_percent: float = 0.3
@property
def pair(self) -> str:
return f"{self.base_asset.symbol}/{self.target_asset.symbol}"
@dataclass
class SwapQuote:
"""Result of a swap price quote from the DEX."""
input_asset: str
output_asset: str
amount_in: str
amount_out: str
price_impact: str = "0"
fee: str = "0"
route: List[str] = field(default_factory=list)
@dataclass
class SwapResult:
"""Result of an executed swap transaction."""
tx_hash: str
input_asset: str
output_asset: str
amount_in: str
amount_out: str
block_number: Optional[int] = None
status: str = "pending"
@dataclass
class AccountBalance:
"""Balance entry for a single asset in an account."""
asset: Asset
free: str = "0"
reserved: str = "0"
frozen: str = "0"
@property
def total(self) -> str:
try:
return str(int(self.free) + int(self.reserved))
except ValueError:
return self.free
@dataclass
class NetworkInfo:
"""Snapshot of SORA network state."""
chain: str = "SORA"
node_version: str = ""
spec_version: int = 0
block_height: int = 0
finalized_block: int = 0
peer_count: int = 0
total_issuance_xor: str = "0"