Distribution Functions
After the audit window is completed, a node is selected and tasked with the responsibility of generating and submitting a distribution list on-chain.
What is a Distribution List?
A distribution list is a JSON object that contains a key-value pair, where the key is the node's public key and the value is the number of KOII tokens to be awarded to the node.
Distribution list example:
const distributionList = {
"29SSj6EQARvATESSQbBcmSE3A1iaWwqXFunzAEDoV7Xj": 100,
"3KUfsjpjCSCjwCBm4TraM5cGx6YzEUo9rrq2hrSsJw3x": 200,
Avxvdc2efsPqysBZt4VKDSgiP4iuJ8GaAWhsNVUAi5CZ: 300,
};generateDistributionList()
As the name suggests, this function generates the distribution list.
For the example on the template:
An empty distribution list is initialized
The task's data is retrieved using the
getTaskStatehelper functionAll valid submissions are fetched from the task's data
The
submissions_audit_triggeris also retrieved from the task's data; this object contains information about the audited submissionsIf
submissionsis null, an empty distribution list is returned. Else, the keys and values of thesubmissionsare grouped separately and in a loop, it calculates the audits on each submission and how many votes on the audit, and based on that it makes a decision.
When writing this function for your task, you can use logic to determine how many KOII tokens to award to each node based on priority. You can award more KOII tokens to the node that worked the hardest to complete the task or to the node that staked the most KOII tokens.
submitDistributionList()
This function submits the distribution list generated by generateDistributionList() to K2.
For the example on the template:
The
generateDistributionList()is called to retrieve the distribution listThe distribution list is submitted on-chain
Click the link below to learn about auditing the distribution list.
Audit FunctionsLast updated