@@ -27,17 +27,29 @@ export function handleNewSponsorship(event: NewSponsorship): void {
27
27
sponsorship . operatorCount = 0
28
28
sponsorship . isRunning = false
29
29
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).
30
35
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).
31
41
sponsorship . minimumStakingPeriodSeconds = event . params . policyParams [ 1 ]
32
42
sponsorship . creator = creator
33
43
sponsorship . cumulativeSponsoring = BigInt . zero ( )
34
44
35
45
// TODO: once it's possible to add minOperatorCount to NewSponsorship event, get rid of this smart contract call
36
46
sponsorship . minOperators = SponsorshipContract . bind ( sponsorshipContractAddress ) . minOperatorCount ( ) . toI32 ( )
37
47
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).
41
53
if ( event . params . policies . length == 4 ) {
42
54
sponsorship . maxOperators = event . params . policyParams [ 3 ] . toI32 ( )
43
55
}
0 commit comments