Skip to content

Commit

Permalink
Include allocations in CT's stake calculation (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandemeusy authored Sep 13, 2024
1 parent 31bcb19 commit 17c1a1e
Show file tree
Hide file tree
Showing 35 changed files with 641 additions and 310 deletions.
39 changes: 32 additions & 7 deletions ct-app/.configs/core_prod_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ flags:
connectedPeers: 300
registeredNodes: 300
topology: 300
allocations: 300
EOABalances: 300
NFTHolders: 300

applyEconomicModel: 120
Expand Down Expand Up @@ -47,6 +49,7 @@ economicModel:

legacy:
proportion: 1.0

apr: 12.5

coefficients:
Expand Down Expand Up @@ -110,15 +113,37 @@ channel:
#
# =============================================================================
subgraph:
type: auto # auto | default | backup
userID: 78696

mainnetAllocations:
queryID: FhU1GxUovoP1zphNbWFEQHwpabLGELQBdWWyFX1yjBkf
slug: hopr-allocations
inputs:
schedule_in:
- investor-node-remainder-2024-01
gnosisAllocations:
queryID: DXy4UwhNms3zm7abYeSYaD3hTkuaWYyNvozrXSXejMbS
slug: hopr-allocations---gnosis
inputs:
schedule_in:
- investor-node-remainder-2024-01
hoprOnMainet:
queryID: 4GZdwVtPcQp95RF77W27GK2ezgGLB1iintG6mYZQ1w33
slug: hopr---mainnet
hoprOnGnosis:
queryID: 2wMRp1AW1ghxoFiM6WeRD93djHNvNGhXsuQyadmwCyqE
slug: hopr-on-gnosis
rewards:
queryID: GoJ4KRuYEcELQk42hir2tjau6r1u4ibDFY6t1zH6zpKk
slug: hopr-channels
safesBalance:
queryID: GP2abJCarirMJCanuk4SBmnadiobEWH9ME2MNRAHbBTp
URLBackup: https://api.studio.thegraph.com/query/78696/hopr-nodes-dufour/version/latest

slug: hopr-nodes-dufour
staking:
queryID: F1NZayy7TXRi2szAVXvMFfJuC9uSdNYLUPAb6p6BYRmZ
URLBackup: https://api.studio.thegraph.com/query/78696/hopr-stake-all-seasons/version/latest

rewards:
queryID: GoJ4KRuYEcELQk42hir2tjau6r1u4ibDFY6t1zH6zpKk
URLBackup: https://api.studio.thegraph.com/query/78696/hopr-channels/version/latest
slug: hopr-stake-all-seasons
allBalances:
queryID: 2wMRp1AW1ghxoFiM6WeRD93djHNvNGhXsuQyadmwCyqE
slug: hopr-on-gnosis
...
57 changes: 41 additions & 16 deletions ct-app/.configs/core_staging_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
# =============================================================================
flags:
core:
rotateSubgraphs: 120
rotateSubgraphs: 300
peersRewards: 120
ticketParameters: 120

connectedPeers: 120
registeredNodes: 120
topology: 120
NFTHolders: 120
registeredNodes: 600
topology: 600
allocations: 600
EOABalances: 600
NFTHolders: 600

applyEconomicModel: 120

node:
healthcheck: 10
healthcheck: 60
retrievePeers: 120
retrieveIncomingChannels: 120
retrieveOutgoingChannels: 120
Expand All @@ -30,12 +32,12 @@ flags:

getTotalChannelFunds: 300

watchMessageQueue: On # should only be On / Off
relayedMessagesToDB: 120
watchMessageQueue: Off # should only be On / Off
relayedMessagesToDB: Off

peer:
messageRelayRequest: On # should only be On / Off
sentMessagesToDB: 30
messageRelayRequest: Off # should only be On / Off
sentMessagesToDB: Off

# =============================================================================
#
Expand Down Expand Up @@ -65,6 +67,7 @@ economicModel:

sigmoid:
proportion: 0

maxAPR: 0.0000001
networkCapacity: 100
totalTokenSupply: 200
Expand Down Expand Up @@ -111,15 +114,37 @@ channel:
#
# =============================================================================
subgraph:
type: auto # auto | default | backup
userID: 78696

mainnetAllocations:
queryID: FhU1GxUovoP1zphNbWFEQHwpabLGELQBdWWyFX1yjBkf
slug: hopr-allocations
inputs:
schedule_in:
- investor-node-remainder-2024-01
gnosisAllocations:
queryID: DXy4UwhNms3zm7abYeSYaD3hTkuaWYyNvozrXSXejMbS
slug: hopr-allocations---gnosis
inputs:
schedule_in:
- investor-node-remainder-2024-01
hoprOnMainet:
queryID: 4GZdwVtPcQp95RF77W27GK2ezgGLB1iintG6mYZQ1w33
slug: hopr---mainnet
hoprOnGnosis:
queryID: 2wMRp1AW1ghxoFiM6WeRD93djHNvNGhXsuQyadmwCyqE
slug: hopr-on-gnosis
rewards:
queryID: GoJ4KRuYEcELQk42hir2tjau6r1u4ibDFY6t1zH6zpKk
slug: hopr-channels
safesBalance:
queryID: GmbJTpa1o4baeStDT48TfQu4ditJmQwwXYPG1DvEiufB
URLBackup: https://api.studio.thegraph.com/query/78696/hopr-nodes-rotsee/version/latest

slug: hopr-nodes-rotsee
staking:
queryID: F1NZayy7TXRi2szAVXvMFfJuC9uSdNYLUPAb6p6BYRmZ
URLBackup: https://api.studio.thegraph.com/query/78696/hopr-stake-all-seasons/version/latest

rewards:
queryID: GoJ4KRuYEcELQk42hir2tjau6r1u4ibDFY6t1zH6zpKk
URLBackup: https://api.studio.thegraph.com/query/78696/hopr-channels/version/latest
slug: hopr-stake-all-seasons
allBalances:
queryID: 2wMRp1AW1ghxoFiM6WeRD93djHNvNGhXsuQyadmwCyqE
slug: hopr-on-gnosis
...
1 change: 0 additions & 1 deletion ct-app/.coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ exclude_also =
if __name__ == .__main__.:

def log_prefix


omit =
test/*
Expand Down
7 changes: 2 additions & 5 deletions ct-app/core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@

@click.command()
@click.option("--configfile", help="The .yaml configuration file to use")
def main(configfile: str = None):

def main(configfile: str):
with open(configfile, "r") as file:
config = yaml.safe_load(file)

# import envvars to params, such as self.params.subgraph.deployer_key
params = Parameters()
params.parse(config)
Base.logger.info(f"Loaded config file: {params}")
params.parse(config, entrypoint=True)
params.from_env("SUBGRAPH", "PG")
params.overrides("OVERRIDE")

Expand Down
6 changes: 0 additions & 6 deletions ct-app/core/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
from .baseclass import Base
from .channelstatus import ChannelStatus
from .environment_utils import EnvironmentUtils
from .graphql_providers import (
ProviderError,
RewardsProvider,
SafesProvider,
StakingProvider,
)
from .hoprd_api import HoprdAPI
from .lockedvar import LockedVar
from .messages import MessageFormat, MessageQueue
Expand Down
8 changes: 5 additions & 3 deletions ct-app/core/components/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ class Parameters(Base):
def __init__(self):
super().__init__()

def parse(self, data: dict):
def parse(self, data: dict, entrypoint=False):
for key, value in data.items():
subparams = type(self)()
key: str = key.replace("-", "_")
key = key.replace("-", "_")

setattr(self, key, subparams)
if isinstance(value, dict):
subparams.parse(value)
else:
setattr(self, key, value)

if entrypoint:
self.info(f"Loaded config: {self}")

def overrides(self, prefix: str):
for key, value in Utils.envvarWithPrefix(prefix).items():
path = key.replace(prefix, "").lower().split("_")

parent = self

for p in path:
Expand Down
6 changes: 0 additions & 6 deletions ct-app/core/components/subgraph_queries/rewards.graphql

This file was deleted.

18 changes: 0 additions & 18 deletions ct-app/core/components/subgraph_queries/safes_balance.graphql

This file was deleted.

8 changes: 0 additions & 8 deletions ct-app/core/components/subgraph_queries/staking.graphql

This file was deleted.

55 changes: 37 additions & 18 deletions ct-app/core/components/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from core.model import NodeSafeEntry
from core.model.subgraph import SafeEntry

from .baseclass import Base
from .channelstatus import ChannelStatus
Expand Down Expand Up @@ -26,28 +26,47 @@ async def mergeDataSources(
cls,
topology: list,
peers: list,
safes: list,
nodes: list,
allocations: list,
eoa_balances: dict,
):
for peer in peers:
address = peer.address.address
topo = next(filter(lambda t: t.node_address == address, topology), None)
safe = next(filter(lambda s: s.node_address == address, safes), None)

if safe is None:
safe = NodeSafeEntry(address, "0", "0x0", "0")

if topo is not None and safe is not None and peer is not None:
address = peer.node_address
topo = next(filter(lambda t: t.address == address, topology), None)
node = next(filter(lambda n: n.address == address, nodes), None)

peer.safe = getattr(node, "safe", SafeEntry.default())

for allocation in allocations:
if peer.safe.address in allocation.linked_safes:
peer.safe.additional_balance += (
allocation.unclaimed_amount / allocation.num_linked_safes
)
for eoa_balance in eoa_balances:
if peer.safe.address in eoa_balance.linked_safes:
peer.safe.additional_balance += (
eoa_balance.balance / eoa_balance.num_linked_safes
)

if topo is not None:
peer.channel_balance = topo.channels_balance
peer.safe_address = safe.safe_address
peer.safe_balance = (
safe.wxHoprBalance if safe.wxHoprBalance is not None else 0
)
peer.safe_allowance = float(safe.safe_allowance)
else:
await peer.yearly_message_count.set(None)

cls().info("Merged topology, peers, and safes data.")

@classmethod
def associateEntitiesToNodes(cls, entities, nodes):
entity_addresses = [e.address for e in entities]
for n in nodes:
for owner in n.safe.owners:
try:
index = entity_addresses.index(owner)
except ValueError:
continue

entities[index].linked_safes.add(n.safe.address)

@classmethod
def allowManyNodePerSafe(cls, peers: list):
"""
Expand All @@ -56,15 +75,15 @@ def allowManyNodePerSafe(cls, peers: list):
:param peer: list of peers
:returns: nothing.
"""
safe_counts = {peer.safe_address: 0 for peer in peers}
safe_counts = {peer.safe.address: 0 for peer in peers}

# Calculate the number of safe_addresses related to a node address
for peer in peers:
safe_counts[peer.safe_address] += 1
safe_counts[peer.safe.address] += 1

# Update the input_dict with the calculated splitted_stake
for peer in peers:
peer.safe_address_count = safe_counts[peer.safe_address]
peer.safe_address_count = safe_counts[peer.safe.address]

@classmethod
def exclude(cls, source_data: list, blacklist: list, text: str = "") -> list:
Expand Down
Loading

0 comments on commit 17c1a1e

Please sign in to comment.