assert.gno
1.62 Kb · 58 lines
1package v1
2
3import (
4 ufmt "gno.land/p/nt/ufmt/v0"
5 pl "gno.land/r/gnoswap/pool"
6)
7
8func assertIsNotUserCall(_ int, rlm realm) {
9 previousRealm := rlm.Previous()
10 if previousRealm.IsUserCall() {
11 panic(newErrorWithDetail(
12 errNotAccessEOA,
13 ufmt.Sprintf("previousRealm(%s) is EOA", previousRealm.Address()),
14 ))
15 }
16}
17
18// assertIsNotEqualsTokens asserts that the token0Path and token1Path are not equal.
19func assertIsNotEqualsTokens(token0Path, token1Path string) {
20 if token0Path == token1Path {
21 panic(newErrorWithDetail(
22 errDuplicateTokenInPool,
23 ufmt.Sprintf("expected token0Path(%s) != token1Path(%s)", token0Path, token1Path),
24 ))
25 }
26}
27
28// assertIsSupportedFeeTier asserts that the fee is a supported fee tier.
29func assertIsSupportedFeeTier(fee uint32) {
30 if !isValidFeeTier(fee) {
31 panic(newErrorWithDetail(
32 errUnsupportedFeeTier,
33 ufmt.Sprintf("expected fee(%d) to be one of %d, %d, %d, %d", fee, FeeTier100, FeeTier500, FeeTier3000, FeeTier10000),
34 ))
35 }
36}
37
38// assertIsNotExistsPoolPath asserts that the pool path does not exist.
39func assertIsNotExistsPoolPath(instance *poolV1, token0Path, token1Path string, fee uint32) {
40 poolPath := pl.GetPoolPath(token0Path, token1Path, fee)
41
42 pools := instance.store.GetPools()
43 if pools.Has(poolPath) {
44 panic(newErrorWithDetail(
45 errPoolAlreadyExists,
46 ufmt.Sprintf("expected poolPath(%s:%s:%d) not to exist", token0Path, token1Path, fee),
47 ))
48 }
49}
50
51func assertIsValidTokenOrder(token0Path, token1Path string) {
52 if token0Path >= token1Path {
53 panic(newErrorWithDetail(
54 errInvalidInput,
55 ufmt.Sprintf("expected token0Path(%s) < token1Path(%s)", token0Path, token1Path),
56 ))
57 }
58}