init.gno
2.56 Kb ยท 113 lines
1package v1
2
3import (
4 "gno.land/p/nt/avl"
5 "gno.land/r/gnoswap/pool"
6)
7
8const (
9 // slot0FeeProtocol represents the protocol fee percentage (0-10).
10 // This parameter can be modified through governance.
11 defaultSlot0FeeProtocol = uint8(0)
12
13 // poolCreationFee is the fee that is charged when a user creates a pool.
14 // The fee is denominated in GNS tokens.
15 // This parameter can be modified through governance.
16 defaultPoolCreationFee = int64(100_000_000) // 100_GNS
17
18 // withdrawalFeeBPS is the fee that is charged when a user withdraws their collected fees
19 // The fee is denominated in BPS (Basis Points)
20 // Example: 100 BPS = 1%
21 // This parameter can be modified through governance.
22 defaultWithdrawalFeeBPS = uint64(100)
23)
24
25var defaultFeeAmountTickSpacing = map[uint32]int32{
26 100: 1,
27 500: 10,
28 3000: 60,
29 10000: 200,
30}
31
32func init() {
33 registerPoolV1()
34}
35
36func registerPoolV1() {
37 pool.RegisterInitializer(cross, func(poolStore pool.IPoolStore) pool.IPool {
38 err := initStoreData(poolStore)
39 if err != nil {
40 panic(err)
41 }
42
43 return NewPoolV1(poolStore)
44 })
45}
46
47func initStoreData(poolStore pool.IPoolStore) error {
48 if !poolStore.HasPools() {
49 err := poolStore.SetPools(avl.NewTree())
50 if err != nil {
51 return err
52 }
53 }
54
55 if !poolStore.HasFeeAmountTickSpacing() {
56 err := poolStore.SetFeeAmountTickSpacing(defaultFeeAmountTickSpacing)
57 if err != nil {
58 return err
59 }
60 }
61
62 if !poolStore.HasPoolCreationFee() {
63 err := poolStore.SetPoolCreationFee(defaultPoolCreationFee)
64 if err != nil {
65 return err
66 }
67 }
68
69 if !poolStore.HasSlot0FeeProtocol() {
70 err := poolStore.SetSlot0FeeProtocol(defaultSlot0FeeProtocol)
71 if err != nil {
72 return err
73 }
74 }
75
76 if !poolStore.HasWithdrawalFeeBPS() {
77 err := poolStore.SetWithdrawalFeeBPS(defaultWithdrawalFeeBPS)
78 if err != nil {
79 return err
80 }
81 }
82
83 // Initialize swap start hook with no-op function
84 if !poolStore.HasSwapStartHook() {
85 noopSwapStart := func(cur realm, poolPath string, timestamp int64) {}
86 err := poolStore.SetSwapStartHook(noopSwapStart)
87 if err != nil {
88 return err
89 }
90 }
91
92 // Initialize swap end hook with no-op function
93 if !poolStore.HasSwapEndHook() {
94 noopSwapEnd := func(cur realm, poolPath string) error {
95 return nil
96 }
97 err := poolStore.SetSwapEndHook(noopSwapEnd)
98 if err != nil {
99 return err
100 }
101 }
102
103 // Initialize tick cross hook with no-op function
104 if !poolStore.HasTickCrossHook() {
105 noopTickCross := func(cur realm, poolPath string, tickId int32, zeroForOne bool, timestamp int64) {}
106 err := poolStore.SetTickCrossHook(noopTickCross)
107 if err != nil {
108 return err
109 }
110 }
111
112 return nil
113}