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

refactor: router #431

wants to merge 23 commits into from

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Dec 10, 2024

Description

Refactor

  • Refactored route file mainly.

Remove

  • Removed unused compute_routes and gno_helper files
  • Removed underscore prefix from _swap functions and renamed them to swapInner
  • Remove DrySwapRoute function and related methods

Update

  • Modified to use enum values instead of hardcoded "EXACT_IN", "EXACT_OUT" strings. Additionally replace other hardcoded values with constants
  • Add _helper_test file for testing purpose

Functions that use Pool currently doesn't have tests yet. This is because there's no way to directly access and initialize the pool's state for now.

@notJoon notJoon added refactoring router router related works labels Dec 10, 2024
@notJoon notJoon self-assigned this Dec 10, 2024
router/router.gno Outdated Show resolved Hide resolved
@notJoon notJoon marked this pull request as ready for review December 11, 2024 13:22
@notJoon notJoon requested review from onlyhyde and r3v4s December 11, 2024 13:22
Copy link
Member

@dongwon8247 dongwon8247 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@notJoon Please add a unit test for swap_multi.gno, swap_single.gno and wrap_unwrap.gno.

Functions that use Pool currently doesn't have tests yet. This is because there's no way to directly access and initialize the pool's state for now.

Can you create mockup data in pool that you can use for testing purposes in router? This seems essential tests. Think about a way to complete tests for this please.

router/router.gno Outdated Show resolved Hide resolved
router/_helper_test.gno Outdated Show resolved Hide resolved

std.TestSetRealm(std.NewUserRealm(from))
std.TestSetOrigSend(std.Coins{{ugnotDenom, int64(amount)}}, nil)
banker := std.GetBanker(std.BankerTypeRealmSend)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gnolang/gno merged new pr relates to banker / coin issue

need to check

@@ -11,14 +11,17 @@ import (
u256 "gno.land/p/gnoswap/uint256"
)

const (
defaultSwapFee = uint64(15) // 0.15%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik, it should be value of bps
@onlyhyde need double check

)

func TestHandleSwapFee(t *testing.T) {
token0 := "token0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use proper token path

t.Run(tt.name, func(t *testing.T) {
defer func() {
r := recover()
if (r != nil) != tt.shouldPanic {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use uassert.PanicsWithMessage to check panic with panic messsage

tt.sqrtPriceLimitX96,
)

if !result.Eq(tt.expected) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uassert.Equal

ugnotTransfer(t, faucetAddress, to, amount)
}

func ugnotDeposit(t *testing.T, addr std.Address, amount uint64) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func wrap or func ugnotWrap seems more straightforward

@notJoon
Copy link
Member Author

notJoon commented Dec 20, 2024

@onlyhyde The SwapRouter split commit was going into the staker (#437) instead of the router now that I checked, I'll revert this tomorrow.😇😇😇

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring router router related works
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants