Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: router #431

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions router/comptue_routes.gno
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ type PoolWithMeta struct {
tokenPair string
liquidity *u256.Uint
}

func (pm PoolWithMeta) hasToken(token string) bool {
return pm.token0Path == token || pm.token1Path == token
}

type ByLiquidity []PoolWithMeta

func (p ByLiquidity) Len() int { return len(p) }
Expand Down Expand Up @@ -80,6 +85,7 @@ func _computeAllRoutes(
return routes
}

// TOOD: overcomplicated parameters
func computeRoutes(
inputTokenPath string,
outputTokenPath string,
Expand Down Expand Up @@ -163,10 +169,6 @@ func computeRoutes(
return routes
}

func (pool PoolWithMeta) hasToken(token string) bool {
return pool.token0Path == token || pool.token1Path == token
}

func findCandidatePools() []PoolWithMeta {
poolList := pl.PoolGetPoolList()

Expand Down
13 changes: 0 additions & 13 deletions router/gno.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
module gno.land/r/gnoswap/v1/router

require (
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/p/gnoswap/int256 v0.0.0-latest
gno.land/p/gnoswap/uint256 v0.0.0-latest
gno.land/r/demo/wugnot v0.0.0-latest
gno.land/r/gnoswap/v1/common v0.0.0-latest
gno.land/r/gnoswap/v1/consts v0.0.0-latest
gno.land/r/gnoswap/v1/emission v0.0.0-latest
gno.land/r/gnoswap/v1/pool v0.0.0-latest
gno.land/r/gnoswap/v1/staker v0.0.0-latest
)
11 changes: 0 additions & 11 deletions router/gno_helper.gno

This file was deleted.

20 changes: 13 additions & 7 deletions router/protocol_fee_swap.gno
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
u256 "gno.land/p/gnoswap/uint256"
)

// TODO: should be global?
var (
swapFee = uint64(15) // 0.15%
)
Expand Down Expand Up @@ -58,7 +59,9 @@ func SetSwapFeeByAdmin(fee uint64) {
panic(err)
}

setSwapFee(fee)
if err := setSwapFee(fee); err != nil {
panic(err)
}

prevAddr, prevRealm := getPrev()

Expand All @@ -79,7 +82,9 @@ func SetSwapFee(fee uint64) {
panic(err)
}

setSwapFee(fee)
if err := setSwapFee(fee); err != nil {
panic(err)
}

prevAddr, prevRealm := getPrev()

Expand All @@ -91,16 +96,17 @@ func SetSwapFee(fee uint64) {
)
}

func setSwapFee(fee uint64) {
func setSwapFee(fee uint64) error {
common.IsHalted()

// 10000 (bps) = 100%
if fee > 10000 {
panic(addDetailToError(
errInvalidSwapFee,
ufmt.Sprintf("protocol_fee_swap.gno__setSwapFee() || fee(%d) must be in range 0 ~ 10000", fee),
))
return ufmt.Errorf(
"%s: fee must be in range 0 to 10000. got %d",
errInvalidSwapFee.Error(), fee,
)
}

swapFee = fee
return nil
}
Loading
Loading