Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

init.gno

2.10 Kb · 90 lines
 1package protocol_fee
 2
 3import (
 4	"gno.land/r/gnoswap/protocol_fee"
 5)
 6
 7func init(cur realm) {
 8	registerProtocolFeeV1(cur)
 9}
10
11func registerProtocolFeeV1(cur realm) {
12	protocol_fee.RegisterInitializer(cross(cur), func(_ int, rlm realm, protocolFeeStore protocol_fee.IProtocolFeeStore) protocol_fee.IProtocolFee {
13		// `rlm` here is the protocol_fee proxy realm threaded in by
14		// protocol_fee.RegisterInitializer. Per-version store bootstrap
15		// writes therefore pass the proxy's KV-store ACL.
16		err := initStoreData(0, rlm, protocolFeeStore)
17		if err != nil {
18			panic(err)
19		}
20
21		return NewProtocolFeeV1(protocolFeeStore)
22	})
23}
24
25func initStoreData(_ int, rlm realm, protocolFeeStore protocol_fee.IProtocolFeeStore) error {
26	if !protocolFeeStore.HasDevOpsPctStoreKey() {
27		err := protocolFeeStore.InitializeDevOpsPct(0, rlm)
28		if err != nil {
29			return err
30		}
31	}
32
33	if !protocolFeeStore.HasAccuToGovStakerStoreKey() {
34		err := protocolFeeStore.InitializeAccuToGovStaker(0, rlm)
35		if err != nil {
36			return err
37		}
38	}
39
40	if !protocolFeeStore.HasAccuToDevOpsStoreKey() {
41		err := protocolFeeStore.InitializeAccuToDevOps(0, rlm)
42		if err != nil {
43			return err
44		}
45	}
46
47	if !protocolFeeStore.HasDistributedToGovStakerHistoryStoreKey() {
48		err := protocolFeeStore.InitializeDistributedToGovStakerHistory(0, rlm)
49		if err != nil {
50			return err
51		}
52	}
53
54	if !protocolFeeStore.HasDistributedToDevOpsHistoryStoreKey() {
55		err := protocolFeeStore.InitializeDistributedToDevOpsHistory(0, rlm)
56		if err != nil {
57			return err
58		}
59	}
60
61	if !protocolFeeStore.HasReservedTokensStoreKey() {
62		err := protocolFeeStore.InitializeReservedTokens(0, rlm)
63		if err != nil {
64			return err
65		}
66	}
67
68	if !protocolFeeStore.HasAccrualEpochStoreKey() {
69		err := protocolFeeStore.InitializeAccrualEpoch(0, rlm)
70		if err != nil {
71			return err
72		}
73	}
74
75	if !protocolFeeStore.HasAccrualBucketsStoreKey() {
76		err := protocolFeeStore.InitializeAccrualBuckets(0, rlm)
77		if err != nil {
78			return err
79		}
80	}
81
82	if !protocolFeeStore.HasAccrualPendingTokensStoreKey() {
83		err := protocolFeeStore.InitializeAccrualPendingTokens(0, rlm)
84		if err != nil {
85			return err
86		}
87	}
88
89	return nil
90}