-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathremus.py
58 lines (51 loc) · 1.93 KB
/
remus.py
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
from starknet_py.contract import Contract
import asyncio
class RemusManager:
def __init__(self, account, env_config):
"""
Initialize the RemusManager with the given account and environment configuration.
This method should be called only once.
"""
self.account = account
self.env_config = env_config
self.remus_contract = None
self.all_remus_cfgs = None
async def init(self):
"""
Initialize the Remus connection and fetch market configurations.
This should be called only once when initializing RemusManager.
"""
if self.remus_contract is None:
self.remus_contract = await Contract.from_address(
address=self.env_config.remus_address, provider=self.account
)
await self.get_config()
async def get_config(self):
"""
Fetch all market configurations from Remus.
"""
self.all_remus_cfgs = await self.remus_contract.functions[
'get_all_market_configs'
].call()
async def get_base_contract(self, market_index=1):
"""
Get the base token contract for the specified market index.
"""
if not self.all_remus_cfgs:
await self.get_config()
market_cfg = self.all_remus_cfgs[market_index]
base_token_contract = await Contract.from_address(
address=market_cfg['base_token'], provider=self.account
)
return base_token_contract
async def get_quote_contract(self, market_index=1):
"""
Get the quote token contract for the specified market index.
"""
if not self.all_remus_cfgs:
await self.get_config()
market_cfg = self.all_remus_cfgs[market_index]
quote_token_contract = await Contract.from_address(
address=market_cfg['quote_token'], provider=self.account
)
return quote_token_contract