Search Apps Documentation Source Content File Folder Download Copy Actions Download

init.gno

0.79 Kb · 42 lines
 1package v1
 2
 3import (
 4	"gno.land/r/gnoswap/router"
 5)
 6
 7const (
 8	defaultSwapFeeBPS = uint64(15) // 0.15%
 9)
10
11func init(cur realm) {
12	registerRouterV1(cur)
13}
14
15func registerRouterV1(cur realm) {
16	router.RegisterInitializer(cross(cur), func(_ int, rlm realm, routerStore router.IRouterStore) router.IRouter {
17		err := initStoreData(0, rlm, routerStore)
18		if err != nil {
19			panic(err)
20		}
21
22		return NewRouterV1(routerStore)
23	})
24}
25
26func initStoreData(_ int, rlm realm, routerStore router.IRouterStore) error {
27	if !routerStore.HasSwapFeeKey() {
28		err := routerStore.SetSwapFee(0, rlm, defaultSwapFeeBPS)
29		if err != nil {
30			return err
31		}
32	}
33
34	if !routerStore.HasPendingProtocolFeesKey() {
35		err := routerStore.SetPendingProtocolFees(0, rlm, make(map[string]int64))
36		if err != nil {
37			return err
38		}
39	}
40
41	return nil
42}