store.gno
1.16 Kb ยท 55 lines
1package router
2
3import (
4 "gno.land/p/gnoswap/store"
5 "gno.land/p/nt/ufmt"
6)
7
8type StoreKey string
9
10func (s StoreKey) String() string {
11 return string(s)
12}
13
14const (
15 StoreKeySwapFee StoreKey = "swapFee" // Swap fee in basis points
16)
17
18type routerStore struct {
19 kvStore store.KVStore
20}
21
22func (s *routerStore) HasSwapFeeKey() bool {
23 return s.kvStore.Has(StoreKeySwapFee.String())
24}
25
26// GetSwapFee retrieves the current swap fee.
27// If not set, returns the default swap fee.
28func (s *routerStore) GetSwapFee() uint64 {
29 result, err := s.kvStore.Get(StoreKeySwapFee.String())
30 if err != nil {
31 panic(err)
32 }
33
34 swapFee, ok := result.(uint64)
35 if !ok {
36 panic(ufmt.Sprintf("failed to cast result to uint64: %T", result))
37 }
38
39 return swapFee
40}
41
42// SetSwapFee stores the swap fee.
43func (s *routerStore) SetSwapFee(fee uint64) error {
44 return s.kvStore.Set(StoreKeySwapFee.String(), fee)
45}
46
47// NewRouterStore creates a new router store instance with the provided KV store.
48// This function is used by the upgrade system to create storage instances for each implementation.
49func NewRouterStore(kvStore store.KVStore) IRouterStore {
50 rs := &routerStore{
51 kvStore: kvStore,
52 }
53
54 return rs
55}