Skip to content

Commit f71de02

Browse files
authored
docs: Improve comments about join policies (#1003)
1 parent b2897b5 commit f71de02

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

packages/network-contracts/contracts/OperatorTokenomics/SponsorshipFactory.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@ contract SponsorshipFactory is Initializable, AccessControlUpgradeable, UUPSUpgr
108108
}
109109

110110
/**
111-
* Policies array is interpreted as follows:
111+
* @param policies smart contract addresses found in the trustedPolicies. It is interpreted as follows:
112112
* 0: allocation policy (mandatory!)
113113
* 1: leave policy (address(0) for none)
114114
* 2: kick policy (address(0) for none)
115115
* 3+: join policies (leave out if none)
116-
* @param policies smart contract addresses found in the trustedPolicies
117116
*/
118117
function deploySponsorship(
119118
uint minOperatorCount,

packages/network-subgraphs/src/sponsorshipFactory.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,29 @@ export function handleNewSponsorship(event: NewSponsorship): void {
2727
sponsorship.operatorCount = 0
2828
sponsorship.isRunning = false
2929
sponsorship.metadata = event.params.metadata
30+
// The first item in the array must be a trusted allocation policy (see SponsorshipFactory#deploySponsorship()).
31+
// Currently, StakeWeightedAllocationPolicy is the only trusted allocation policy.
32+
// Therefore, we assume the first policy parameter corresponds to StakeWeightedAllocationPolicy#incomePerSecond.
33+
// If more trusted allocation policies are added in the future, we must add a check here (i.e. verify that event.params.policies[0]
34+
// matches the address of StakeWeightedAllocationPolicy).
3035
sponsorship.totalPayoutWeiPerSec = event.params.policyParams[0]
36+
// The second item in the array must be a trusted leave policy (see SponsorshipFactory#deploySponsorship()).
37+
// Currently, DefaultLeavePolicy is the only trusted leave policy.
38+
// Therefore, we assume the second policy parameter corresponds to DefaultLeavePolicy#penaltyPeriodSeconds.
39+
// If more trusted allocation policies are added in the future, we must add a check here (i.e. verify that event.params.policies[1]
40+
// matches the address of DefaultLeavePolicy).
3141
sponsorship.minimumStakingPeriodSeconds = event.params.policyParams[1]
3242
sponsorship.creator = creator
3343
sponsorship.cumulativeSponsoring = BigInt.zero()
3444

3545
// TODO: once it's possible to add minOperatorCount to NewSponsorship event, get rid of this smart contract call
3646
sponsorship.minOperators = SponsorshipContract.bind(sponsorshipContractAddress).minOperatorCount().toI32()
3747

38-
// The standard ordering is: allocation, leave, kick, join policies
39-
// "Operator-only join policy" is always set, so we check if we have 5 policies,
40-
// and in that case we assume the 4th policy is the "max-operators join policy"
48+
// If there is a 4th item in the array, it is a trusted join policy. All policies beyond the third are join policies,
49+
// and all join policies are trusted (see SponsorshipFactory#deploySponsorship()). Technically, it could be any join policy,
50+
// but in practice, it is currently always MaxOperatorsJoinPolicy, as that is the only trusted join policy available.
51+
// If more trusted join policies are added in the future, we must add a check here (i.e. verify that event.params.policies[3]
52+
// matches the address of MaxOperatorsJoinPolicy).
4153
if (event.params.policies.length == 4) {
4254
sponsorship.maxOperators = event.params.policyParams[3].toI32()
4355
}

0 commit comments

Comments
 (0)