init.gno
1.64 Kb · 69 lines
1package v1
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 return nil
69}