1
0

Improvements to PBC

This commit is contained in:
Jon Michael Aanes 2024-06-02 18:52:53 +02:00
parent 949244656a
commit d4a4d255fc
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -10,7 +10,7 @@ import fin_defs
import requests
from frozendict import frozendict
from . import DepoGroup, DepoSingle
from .data import DepoGroup, DepoSingle
logger = logging.getLogger(__name__)
@ -30,6 +30,7 @@ MPC_DECIMALS = 10000
def shard_id_for_address(address: str) -> str:
assert address is not None, 'missing address'
if address.endswith('a'):
return 'shards/Shard0/' # TODO
elif address.endswith('2'):
@ -127,19 +128,29 @@ class PbcClient:
return self.get_json(url, data=data)
BYOC_ASSETS = {
'ETH': fin_defs.WELL_KNOWN_SYMBOLS['ETH'],
'POLYGON_USDC': fin_defs.WELL_KNOWN_SYMBOLS['USDC'],
'BNB': fin_defs.WELL_KNOWN_SYMBOLS['BNB'],
'MATIC': fin_defs.WELL_KNOWN_SYMBOLS['MATIC'],
}
class PartisiaBlockchainAccountDepoFetcher:
def __init__(self, session, blockchain_address: str):
assert session is not None, 'missing session'
assert blockchain_address is not None, 'missing blockchain_address'
self.client = PbcClient(session)
self.blockchain_address = blockchain_address
def get_depo(self) -> DepoGroup:
balances = self.client.get_account_balances(self.blockchain_address)
depo_mpc = DepoSingle('MPC', balances.update_time, {fin_defs.MPC: balances.mpc})
depo_mpc = DepoSingle('Native', balances.update_time, {fin_defs.MPC: balances.mpc})
depo_byoc = DepoSingle(
'BYOC',
balances.update_time,
{fin_defs.WELL_KNOWN_SYMBOLS[k]: v for k, v in balances.byoc.items()},
{BYOC_ASSETS[k]: v for k, v in balances.byoc.items()},
)
return DepoGroup(