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

init.gno

0.90 Kb · 43 lines
 1package router
 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	pendingProtocolFees := make(map[string]int64)
35	if routerStore.HasPendingProtocolFeesKey() {
36		pendingProtocolFees = routerStore.GetPendingProtocolFees()
37	}
38	if err := routerStore.SetPendingProtocolFees(0, rlm, pendingProtocolFees); err != nil {
39		return err
40	}
41
42	return nil
43}