-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'leon/OCT-1289/simulate-finalized-snapshot' into 'develop'
OCT-1289: simulate finalized snapshot See merge request golemfoundation/governance/octant!1096
- Loading branch information
Showing
28 changed files
with
552 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import List | ||
|
||
from multiproof import StandardMerkleTree | ||
|
||
from app.exceptions import MissingAddress | ||
from app.infrastructure import database | ||
from app.modules.dto import AccountFundsDTO | ||
|
||
LEAF_ENCODING: List[str] = ["address", "uint256"] | ||
|
||
|
||
def get_proof_by_address_and_epoch(address: str, epoch: int) -> List[str]: | ||
merkle_tree = get_merkle_tree_for_epoch(epoch) | ||
return get_proof(merkle_tree, address) | ||
|
||
|
||
def get_merkle_tree_for_epoch(epoch: int) -> StandardMerkleTree: | ||
leaves = [ | ||
AccountFundsDTO(r.address, int(r.amount)) | ||
for r in database.rewards.get_by_epoch(epoch) | ||
] | ||
return build_merkle_tree(leaves) | ||
|
||
|
||
def build_merkle_tree(leaves: List[AccountFundsDTO]) -> StandardMerkleTree: | ||
return StandardMerkleTree.of( | ||
[[leaf.address, leaf.amount] for leaf in leaves], LEAF_ENCODING | ||
) | ||
|
||
|
||
def get_proof(mt: StandardMerkleTree, address: str) -> List[str]: | ||
for i, leaf in enumerate(mt.values): | ||
if leaf.value[0] == address: | ||
return mt.get_proof(i) | ||
raise MissingAddress(address) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import List | ||
|
||
from app.engine.projects import ProjectSettings | ||
from app.engine.projects.rewards import ProjectRewardDTO, ProjectRewardsPayload | ||
from app.modules.dto import AllocationDTO | ||
|
||
|
||
def get_projects_rewards( | ||
project_settings: ProjectSettings, | ||
allocations: List[AllocationDTO], | ||
all_projects: List[str], | ||
matched_rewards: int, | ||
) -> (List[ProjectRewardDTO], int, int): | ||
return project_settings.rewards.calculate_project_rewards( | ||
ProjectRewardsPayload( | ||
allocations=allocations, | ||
matched_rewards=matched_rewards, | ||
projects=all_projects, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.