Skip to content

Commit ae78769

Browse files
committed
chore: remove error message function prefix
1 parent 8206bed commit ae78769

File tree

5 files changed

+37
-39
lines changed

5 files changed

+37
-39
lines changed

router/protocol_fee_swap.gno

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ func SetSwapFee(fee uint64) {
8181

8282
setSwapFee(fee)
8383

84-
prevAddr, prevRealm := getPrev()
84+
prevAddr, prevPkgPath := getPrev()
8585

8686
std.Emit(
8787
"SetSwapFee",
8888
"prevAddr", prevAddr,
89-
"prevRealm", prevRealm,
89+
"prevRealm", prevPkgPath,
9090
"fee", ufmt.Sprintf("%d", fee),
9191
)
9292
}
@@ -98,7 +98,7 @@ func setSwapFee(fee uint64) {
9898
if fee > 10000 {
9999
panic(addDetailToError(
100100
errInvalidSwapFee,
101-
ufmt.Sprintf("protocol_fee_swap.gno__setSwapFee() || fee(%d) must be in range 0 ~ 10000", fee),
101+
ufmt.Sprintf("fee(%d) must be in range 0 ~ 10000", fee),
102102
))
103103
}
104104

router/router_dry.gno

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,49 @@ import (
1616
func DrySwapRoute(
1717
inputToken string,
1818
outputToken string,
19-
_amountSpecified string, // int256
19+
_amountSpecified string,
2020
swapType string,
21-
strRouteArr string, // []string
22-
quoteArr string, // []int
23-
) string { // uint256
24-
if swapType != "EXACT_IN" && swapType != "EXACT_OUT" {
25-
panic(addDetailToError(
26-
errInvalidSwapType,
27-
ufmt.Sprintf("router_dry.gno__DrySwapRoute() || unknown swapType(%s)", swapType),
28-
))
29-
}
21+
strRouteArr string,
22+
quoteArr string,
23+
) string {
24+
assertNotASwapType(swapType)
3025

3126
amountSpecified, err := i256.FromDecimal(_amountSpecified)
3227
if err != nil {
3328
panic(err.Error())
3429
}
3530

31+
// TODO (@notJoon): Faster using byte comparison rather than strings.Split() in a small size string.
3632
routes := strings.Split(strRouteArr, ",")
3733
quotes := strings.Split(quoteArr, ",")
3834

3935
validateInput(amountSpecified, swapType, routes, quotes)
4036

41-
if swapType == "EXACT_OUT" {
37+
if swapType == ExactOut {
4238
amountSpecified = i256.Zero().Neg(amountSpecified)
4339
}
4440

4541
resultAmountIn := u256.Zero()
4642
resultAmountOut := u256.Zero()
4743

4844
for i, route := range routes {
49-
numHops := strings.Count(route, "*POOL*") + 1
50-
quote, _ := strconv.Atoi(quotes[i])
51-
52-
if numHops < 1 || numHops > 3 {
45+
numHops := strings.Count(route, POOL_SEPARATOR) + 1
46+
quote, err := strconv.Atoi(quotes[i])
47+
if err != nil {
5348
panic(addDetailToError(
5449
errInvalidInput,
55-
ufmt.Sprintf("router_dry.gno__DrySwapRoute() || number of hops(%d) must be 1~3", numHops),
50+
ufmt.Sprintf("quote(%s) is not a valid integer", quotes[i]),
5651
))
5752
}
5853

54+
assertHopsInRange(numHops)
55+
5956
toSwap := i256.Zero().Mul(amountSpecified, i256.NewInt(int64(quote)))
6057
toSwap = toSwap.Div(toSwap, i256.NewInt(100))
6158

62-
if numHops == 1 { // SINGLE
59+
// TODO (@notJoon): use pattern matching and fall-through
60+
// TODO (@notJoon): Is it possible for an invalid SwapType to get this far?
61+
if numHops == 1 {
6362
amountIn, amountOut := handleSingleSwap(route, toSwap, true)
6463
resultAmountIn = new(u256.Uint).Add(resultAmountIn, amountIn)
6564
resultAmountOut = new(u256.Uint).Add(resultAmountOut, amountOut)
@@ -68,28 +67,27 @@ func DrySwapRoute(
6867
resultAmountIn = new(u256.Uint).Add(resultAmountIn, amountIn)
6968
resultAmountOut = new(u256.Uint).Add(resultAmountOut, amountOut)
7069
}
71-
7270
}
7371

7472
return processResult(swapType, resultAmountIn, resultAmountOut, amountSpecified)
7573
}
7674

7775
func processResult(swapType string, resultAmountIn, resultAmountOut *u256.Uint, amountSpecified *i256.Int) string {
7876
switch swapType {
79-
case "EXACT_IN":
77+
case ExactIn:
8078
if !i256.FromUint256(resultAmountIn).Eq(amountSpecified) {
8179
return "-1"
8280
}
8381
return resultAmountOut.ToString()
84-
case "EXACT_OUT":
82+
case ExactOut:
8583
if i256.FromUint256(resultAmountOut).Lt(amountSpecified) {
8684
return "-1"
8785
}
8886
return resultAmountIn.ToString()
8987
default:
90-
panic(addDetailToError(
91-
errInvalidSwapType,
92-
ufmt.Sprintf("router_dry.gno__processResult() || unknown swapType(%s)", swapType),
93-
))
88+
assertNotASwapType(swapType)
9489
}
90+
91+
// redundant return.
92+
return "-1"
9593
}

router/swap_inner.gno

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func getMinTick(fee uint32) int32 {
135135
default:
136136
panic(addDetailToError(
137137
errInvalidPoolFeeTier,
138-
ufmt.Sprintf("swap_inner.gno__getMinTick() || unknown fee(%d)", fee),
138+
ufmt.Sprintf("unknown fee(%d)", fee),
139139
))
140140
}
141141
}
@@ -153,7 +153,7 @@ func getMaxTick(fee uint32) int32 {
153153
default:
154154
panic(addDetailToError(
155155
errInvalidPoolFeeTier,
156-
ufmt.Sprintf("swap_inner.gno__getMaxTick() || unknown fee(%d)", fee),
156+
ufmt.Sprintf("unknown fee(%d)", fee),
157157
))
158158
}
159159
}

router/token_register.gno

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func RegisterGRC20Interface(pkgPath string, igrc20 GRC20Interface) {
4141
if !(prevAddr == consts.TOKEN_REGISTER || prevPath == consts.INIT_REGISTER_PATH || strings.HasPrefix(prevPath, "gno.land/r/g1er355fkjksqpdtwmhf5penwa82p0rhqxkkyhk5")) {
4242
panic(addDetailToError(
4343
errNoPermission,
44-
ufmt.Sprintf("token_register.gno__RegisterGRC20Interface() || only register(%s) can register token, called from %s", consts.TOKEN_REGISTER, prevAddr),
44+
ufmt.Sprintf("only register(%s) can register token, called from %s", consts.TOKEN_REGISTER, prevAddr),
4545
))
4646
}
4747

@@ -51,7 +51,7 @@ func RegisterGRC20Interface(pkgPath string, igrc20 GRC20Interface) {
5151
if found {
5252
panic(addDetailToError(
5353
errAlreadyRegistered,
54-
ufmt.Sprintf("token_register.gno__RegisterGRC20Interface() || token(%s) already registered", pkgPath),
54+
ufmt.Sprintf("token(%s) already registered", pkgPath),
5555
))
5656
}
5757

@@ -84,7 +84,7 @@ func transferByRegisterCall(pkgPath string, to std.Address, amount uint64) bool
8484
if !found {
8585
panic(addDetailToError(
8686
errNotRegistered,
87-
ufmt.Sprintf("token_register.gno__transferByRegisterCall() || token(%s) not registered", pkgPath),
87+
ufmt.Sprintf("token(%s) not registered", pkgPath),
8888
))
8989
}
9090

@@ -98,7 +98,7 @@ func transferByRegisterCall(pkgPath string, to std.Address, amount uint64) bool
9898
} else {
9999
panic(addDetailToError(
100100
errLocked,
101-
ufmt.Sprintf("token_register.gno__transferByRegisterCall() || expected locked(%t) to be false", locked),
101+
ufmt.Sprintf("expected locked(%t) to be false", locked),
102102
))
103103
}
104104

@@ -112,7 +112,7 @@ func transferFromByRegisterCall(pkgPath string, from, to std.Address, amount uin
112112
if !found {
113113
panic(addDetailToError(
114114
errNotRegistered,
115-
ufmt.Sprintf("token_register.gno__transferFromByRegisterCall() || token(%s) not registered", pkgPath),
115+
ufmt.Sprintf("token(%s) not registered", pkgPath),
116116
))
117117
}
118118

@@ -126,7 +126,7 @@ func transferFromByRegisterCall(pkgPath string, from, to std.Address, amount uin
126126
} else {
127127
panic(addDetailToError(
128128
errLocked,
129-
ufmt.Sprintf("token_register.gno__transferFromByRegisterCall() || expected locked(%t) to be false", locked),
129+
ufmt.Sprintf("expected locked(%t) to be false", locked),
130130
))
131131
}
132132
return true
@@ -139,7 +139,7 @@ func balanceOfByRegisterCall(pkgPath string, owner std.Address) uint64 {
139139
if !found {
140140
panic(addDetailToError(
141141
errNotRegistered,
142-
ufmt.Sprintf("token_register.gno__balanceOfByRegisterCall() || token(%s) not registered", pkgPath),
142+
ufmt.Sprintf("token(%s) not registered", pkgPath),
143143
))
144144
}
145145

@@ -154,7 +154,7 @@ func approveByRegisterCall(pkgPath string, spender std.Address, amount uint64) b
154154
if !found {
155155
panic(addDetailToError(
156156
errNotRegistered,
157-
ufmt.Sprintf("token_register.gno__approveByRegisterCall() || token(%s) not registered", pkgPath),
157+
ufmt.Sprintf("token(%s) not registered", pkgPath),
158158
))
159159
}
160160

router/wrap_unwrap.gno

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ func wrap(ugnotAmount uint64) {
1313
if ugnotAmount <= 0 {
1414
panic(addDetailToError(
1515
errWrapUnwrap,
16-
ufmt.Sprintf("wrap.gno__wrap() || cannot wrap 0 ugnot"),
16+
ufmt.Sprintf("cannot wrap 0 ugnot"),
1717
))
1818
}
1919

2020
if ugnotAmount < consts.UGNOT_MIN_DEPOSIT_TO_WRAP {
2121
panic(addDetailToError(
2222
errWugnotMinimum,
23-
ufmt.Sprintf("wrap.gno__wrap() || amount(%d) < minimum(%d)", ugnotAmount, consts.UGNOT_MIN_DEPOSIT_TO_WRAP),
23+
ufmt.Sprintf("amount(%d) < minimum(%d)", ugnotAmount, consts.UGNOT_MIN_DEPOSIT_TO_WRAP),
2424
))
2525
}
2626

0 commit comments

Comments
 (0)