Skip to content

Commit

Permalink
Monitor improvements + sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
koirikivi committed May 15, 2024
1 parent 4a02802 commit 72eadce
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 5 deletions.
19 changes: 15 additions & 4 deletions bridge_node/bridge/api/monitor/templates/monitor/base.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@
</head>
<body>
<nav class="container-fluid mb-4">
<a href="deposits">deposits</a> |
<a href="runes">runes</a> |
<a href="users">users</a> |
<a href="multisig">multisig</a>
<a href="/api/v1/monitor/runesrsk/deposits">runes-rsk</a> |
<a href="/api/v1/monitor/runesrsk/deposits">runes-bob</a> |
</nav>
<nav class="container-fluid mb-4 clearfix">
<div style="float: left">
<a href="deposits">deposits</a> |
<a href="runes">runes</a> |
<a href="users">users</a> |
<a href="multisig">multisig</a> |
<a href="sanity-check">sanity check</a>
</div>
<div style="float: right">
<a href="/api/v1/monitor/runesrsk">runes-rsk</a> |
<a href="/api/v1/monitor/runesbob">runes-bob</a>
</div>
</nav>

<div class="container-fluid">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% extends "monitor/base.jinja2" %}
{% block content %}
<h2>Sanity check</h2>

<table class="table">
<thead>
<tr>
<th>Rune</th>
<th>Multisig Balance</th>
<th>Token Address</th>
<th>Token Supply</th>
<th>Difference</th>
</tr>
</thead>
<tbody>
{% for entry in entries %}
<tr>
<td>{{ entry["rune_name"] }}</td>
<td>{{ entry["multisig_rune_balance"] }}</td>
{% if entry["token"] %}
<td>{{ entry["token"]["address"] }}</td>
<td>{{ entry["token"]["supply"] }}</td>
<td>{{ entry["difference"] }}</td>
{% else %}
<td></td>
<td></td>
<td></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
59 changes: 59 additions & 0 deletions bridge_node/bridge/api/monitor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,64 @@ def format_raw_rune_amount(rune: str, amount_raw: int) -> Decimal:
"format_raw_rune_amount": format_raw_rune_amount,
}

@view_config(
route_name="monitor_sanity_check",
request_method="GET",
renderer="templates/monitor/sanitycheck.jinja2",
)
def sanity_check(self):
# TODO: some duplication in here
service = self._get_runebridge_service()
multisig = service.ord_multisig
utxos_with_ord_outputs = multisig.list_utxos_with_ord_outputs()
rune_balances = dict()
for _, ord_output in utxos_with_ord_outputs:
if not ord_output:
continue
for rune_name, amount in ord_output.rune_balances.items():
if rune_name not in rune_balances:
rune_balances[rune_name] = 0
rune_balances[rune_name] += amount

entries = []
for rune_name, balance_raw in rune_balances.keys():
rune = (
self.dbsession.query(
Rune,
)
.filter_by(
bridge_id=self.bridge_id,
name=rune_name,
)
.one()
)
balance_decimal = Decimal(balance_raw) / 10**rune.divisibility
token_contract = service.get_rune_token(rune.n)
if token_contract.address != "0x0000000000000000000000000000000000000000":
decimals = (token_contract.functions.decimals().call(),)
supply = (Decimal(token_contract.functions.totalSupply().call()) / 10**decimals,)
difference = supply - balance_decimal
token = {
"address": token_contract.address,
"name": token_contract.functions.name().call(),
"symbol": token_contract.functions.symbol().call(),
}
else:
token = None
difference = None
entries.append(
{
"rune": rune.spaced_name,
"multisig_rune_balance": balance_decimal,
"token": token,
"difference": difference,
}
)

return {
"entries": entries,
}

def _get_runebridge_service(self) -> RuneBridgeService:
if self.bridge_name == "runesrsk":
return self.runesrsk_service
Expand All @@ -187,3 +245,4 @@ def includeme(config: Configurator):
config.add_route("monitor_runes", "/:bridge/runes")
config.add_route("monitor_users", "/:bridge/users")
config.add_route("monitor_multisig", "/:bridge/multisig")
config.add_route("monitor_sanity_check", "/:bridge/sanity-check")
2 changes: 1 addition & 1 deletion bridge_node/bridge/bridges/runes/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ def _calculate_rune_to_evm_transfer_amounts(self, amount_raw: int, divisibility:
net_amount_raw=net_amount_raw,
)

def _get_rune_token(self, rune_number: int) -> Contract:
def get_rune_token(self, rune_number: int) -> Contract:
address = self.rune_bridge_contract.functions.getTokenByRune(rune_number).call()
return self.web3.eth.contract(
address=address,
Expand Down

0 comments on commit 72eadce

Please sign in to comment.