@web3dotorg/evm-slc-core
v0.3.1
Published
EVM SLC Core contracts and SDK
Maintainers
Readme
evm-slc-core
graph TD
subgraph SLC Creation Flow
b0[User wants to create an SLC] --> b00;
b00{Is a default governance address<br/>set in the Q Parameters Registry?};
b00 -- No --> b01;
b00 -- Yes --> b10;
b10{Use a custom<br/>governance address?};
b10 -- Yes --> b01;
b10 -- No --> b000;
b01[Call 'deploySLCWithGovernance', providing a<br/>legal document link and a user defined governance address.] --> b_end;
b000[Call 'deploySLC' with a legal document link<br/>to use the default governance address.] --> b_end;
subgraph Deployment Outcome
b_end(( )) --> b001["SLC Core is deployed to a deterministic address.<br/><br/><i>Address derived from:</i><br/>- Creator's address<br/>- Nonce<br/>- Source code hash<br/><br/>The specified governance address is assigned."];
end
end
graph TD
subgraph Service Request and Execution
direction TB
U[User wants to request a service] --> A1;
A1[Call 'requestService', providing a<br/>service fee, the desired number of neutrals, and additional document link];
A1 --> A2{Choose Payment Method};
A2 -- ERC20 Token --> B1;
A2 -- Native Q Token --> B1;
subgraph GovernanceProcess[Internal SLC Governance processing]
B1[Check validity of service fee and neutral count] --> B2;
B2["Select the requested number of neutrals<br/>pseudo-randomly from the Neutrals Registry"];
B3[Distribute rewards to participating<br/>neutrals and executors];
B4["Start neutral decision-making process"];
B2 --> B3 --> B4;
end
B4 --> C1;
subgraph Decision & Execution
C1[Selected neutrals propose operations] --> C2{Has a neutral consensus<br/>threshold been reached?};
C2 -- No --> C1;
C2 -- Yes --> C3[Executors approve the decision];
C3 -- On Rejection --> C1;
C3 -- On Approval --> D1;
D1["SLC Governance call the SLC Core contract to executor approved operation bundle."];
D2["Execution of the approved operation bundle<br/>is processed in the SLC Core contract"];
D1 --> D2
end
endgraph TD
A1["Service Request(Selected Neutrals)"]
subgraph RewardCalculation[Reward Distribution Process]
U0(Service fee provided for the service request = serviceFee)
B1["Calculate Nuetrals Registry Reward"]
B2["Calculate Executors Registry Reward"]
B3["Calculate Treasury Registry Reward"]
Z1["Send treasury rewards to the treasury"]
subgraph NeutralsRewardDistribution[Distribute Neutrals' Part between Selected Neutrals]
direction TB
C0["Each neutral's total reward amount = (Neutrals Registry Part) / (Count of Selected Neutrals)"]
C1[For every neutral in selectedNeutral]
C2[Calculate delegators part of reward from delegationShare parameter of the neutral]
C3[Calculate the neutral rewards as Total Neutral Reward Amount - DepegatorRewards]
C4[Add neutral's reward to his reward balance]
C5[Distribute delegators' rewards between delegators of the neutral based on their delegated stake]
C0 --> C1 --> C2 --> C3 --> C4 --> C5
end
subgraph ExecutorsRewardDistrinbution[Distribute Executors' Part evenly between current Active Executors]
end
subgraph ClaimingRewards[Reward Claim Process]
E0[The Neutral calls claimNeutralReward function on NeutralsRegistry contract]
F0[The Delegator calls claimDelegatorReward on the Neutrals Registry, specifying the address of the Neutral to whom they delegated.]
G0[The Executor calls claimRewards function on ExecutorsRegistry contract]
E1[The Neutral's reward tokens are transferred from the Neutrals Registry.]
F1[The Delegator's reward tokens are transferred from the Neutrals Registry]
G1[Reward tokens are transferred from the Executors Registry to the Executor.]
end
U0 --> B1
U0 --> B2
U0 --> B3
B1 --> NeutralsRewardDistribution
B2 --> ExecutorsRewardDistrinbution --> G0 --> G1
B3 --> Z1
NeutralsRewardDistribution --> E0 --> E1
NeutralsRewardDistribution --> F0 --> F1
end
A1 --> RewardCalculation
sequenceDiagram
actor Initiator as "Initial SLC Creator"
participant SlcFactory as "SLC Factory"
participant Executors as "Executors Registry"
participant Neutrals as "Neutrals Registry"
participant IQParamerRegistry as "IQ Parameter Registry"
participant Governance
participant SlcCoreContract as "SLC Core Contract"
actor User
actor Neutral
actor Executor
alt Specify Custom Governance
Initiator->>SlcFactory: deploySlcWithGovernance(governance, externalLink)
else Use Default Governance
Initiator->>SlcFactory: deploySlc(externalLink)
end
SlcFactory->>SlcCoreContract: Deploys and initializes the SLC Core Contract
User->>SlcCoreContract: requestService(serviceRequestData)
SlcCoreContract->>Governance: processServiceRequest(serviceRequestData)
Governance->>IQParamerRegistry: getMinServiceFee()
IQParamerRegistry-->>Governance: Returns minServiceFee
opt Service fee is too low
Governance-->>User: revert ServiceFeeTooLow()
end
Governance->>Neutrals: getNeutralSlice(numRequested)
alt Enough active Neutrals are available
Neutrals-->>Governance: Returns addresses of selected Neutrals
else Not enough active Neutrals
Neutrals-->>User: revert NotEnoughNeutralsAvailable()
end
note over Governance: Distributes rewards to active Executors and selected Neutrals.
note over Governance: Begins a Neutral decision-making phase for the service request.
note over Neutral: Evaluate serviceRequestData and externalLink and make a decision
Neutral->>Governance: proposeOperations(proposalId, operationBundle)
note over Governance: 1. Verifies it's the correct proposal phase.<br/>2. Verifies sender is a selected Neutral for this proposal.
alt Sender or phase is invalid
Governance-->>Neutral: revert InvalidVotingPhase() or NeutralNotSelected()
else Proposal is valid
note over Governance: Removes previous proposed operation of this Neutral (if any).<br/>Adds the new proposed operation.
end
Note over Executor: Threshold of neutral operations (>50% of neutrals proposed the same operation) was met.
Executor->>Governance: castVote(proposalId, decision)
note over Governance: Verifies sender is an active Executor.
Governance->>Executors: isExecutor(msg.sender)
Executors-->>Governance: Response: true / false
alt Sender is not an active Executor
Governance-->>Executor: revert AccountNotExecutor()
else Sender is an active Executor
note over Governance: Verifies that the Executor has not already voted.
alt Executor has already voted
Governance-->>Executor: revert AlreadyVoted()
else Executor has not voted
alt Executor votes YES
note over Governance: decision.positiveVotes += 1
else Executor votes NO
note over Governance: decision.positiveVotes -= 1
end
alt Vote count exceeds threshold
note over Governance: Proposal is approved. Executing operations...
loop For each operation in the bundle
Governance->>SlcCoreContract: executeArbitrary(operation_i)
Note over SlcCoreContract: depending on the proposed operation, the operation is executed on the SLC core contract,<br> or the SLC Core contract calls an external contract as specified
end
end
end
end