hashport-validator
hashport-validator copied to clipboard
Collecting validator's fees smart contract (Router) logic
High-level spec link
Example: LimeChain Merkle tree: github & github2
Example 2: Solidity link
Description:
- Method for getting the Merkle tree -new facet (+ link to the diamond) or update of an existing one.
- The method will receive:
- Merkle tree’s root.
- List of signatures from the majority of validators (Ex [5/9] ) - agreement of the Merkle tree’s root. To be validated.
- Related to the validator’s node nodes (so the Merkle tree can be built and verified in the Router) - based on the leaf’s index, we will be able to get the intermediate hashes
- The data/leaf to be verified ({validator_address}{network_id}{asset_address}{amount}):
- Validator’s address - to be checked if it is valid in the Router mapping.
- Asset’s address - to be checked if it is valid in the Router mapping.
- Network ID.
- Amount: the fee to be collected.
- The logic in the method will be:
- Check the validator’s, and the asset’s addresses in the Router mapping.
- Hash the Validator’s address + Network ID + Asset address + Amount (Fee).
- Use the related nodes to build a Merkle tree.
- Check the root of the built Merkle tree with the passed root.
- Check the passed signatures if they are valid.
- If all the checks passed proceed with paying the validator’s fee.
- The logic for paying the fee:
- Create a mapping validator’s address ⇒ paid fee. As init the fee will be 0.
- Once the fee is paid to the validator increase the amount.
- Ex: The first fee request of the validator Alice is for 1 MATIC. All checks passed. Alice requested 1 MATIC and in the Router, for her address, the already paid fee is 0, so 1-0 = 1 MATIC to be TX to her. Once the TX is successful the mapping in the Router will be added 1. The second request is for a fee of 11 MATIC. All checks passed. In the Router, there is 1 MATIC that was already paid to Alice. 11 - 1 = 10 MATIC will be TX to Alice. Once the TX is successful the mapping in the Router will be added 10. The total amount of the already paid fees in the Router will be 11.
- ‼️ To avoid duplication: In case the diff between the valid requested fee and the already paid fee in the smart contract is < 0 there will be no TX to the validator.
Subtasks:
- [ ] Smart contracts logic: receive the data, validation, execute the pay TX.
- [ ] tests.
- [ ] Smart contracts audit.