Skip to content

Commit

Permalink
resolve dependency cycle
Browse files Browse the repository at this point in the history
change router/router -> router/core
  • Loading branch information
tolelom committed Aug 27, 2024
1 parent 7622d39 commit 5a05455
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package router
package core

type AlphaRouterParams struct {
}
28 changes: 12 additions & 16 deletions router/alpha-router.go → core/alpha-router.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package router
package core

import (
"router/router/core"
"router/router/core/entities"
"router/router/core/entities/fractions"
"router/router/providers"
"router/core/entities"
"router/core/entities/fractions"
"router/core/providers"
)

type AlphaRouter struct {
Expand All @@ -20,7 +19,7 @@ func NewAlphaRouter(params AlphaRouterParams) *AlphaRouter {
func (a AlphaRouter) route(
amount fractions.CurrencyAmount,
quoteCurrency entities.Currency,
tradeType core.TradeType,
tradeType TradeType,
swapConfig SwapOptions,
) SwapRoute {
originalAmount := amount
Expand All @@ -34,33 +33,30 @@ func (a AlphaRouter) route(
tokenOut := currencyOut.Wrapped()

// core 패키지를 TradeType 패키지로 변경하면 가독성이 더 좋아질 듯 하다.
if tradeType == core.EXACT_OUTPUT {
if tradeType == EXACT_OUTPUT {
// TODO: GetPortionAmount에서 반환 값인 CurrencyAmount을 반환하지 못할 경우가 있을 수도 있다.(높은 확률로)
portionAmount := a.portionProvider.GetPortionAmount(
amount,
tradeType,
swapConfig,
)

result, err := portionAmount.GreaterThan(0)
if err != nil {
// 오류
}
if result {
amount = amount.add(portionAmount)
}
//result := portionAmount.GreaterThan(0)
//if result {
// amount = amount.add(portionAmount)
//}
}

swapRoute := SwapRoute{}
return swapRoute
}

func (a AlphaRouter) determineCurrencyInOutFromTradeType(
tradeType core.TradeType,
tradeType TradeType,
amount fractions.CurrencyAmount,
quoteCurrency entities.Currency,
) (entities.Currency, entities.Currency) {
if tradeType == core.EXACT_INPUT {
if tradeType == EXACT_INPUT {
return amount.Currency, quoteCurrency
} else {
return quoteCurrency, amount.Currency
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fractions

import "router/router/core/entities"
import (
"router/core/entities"
)

type CurrencyAmount struct {
Fraction
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package providers

import (
"router/router"
"router/router/core"
"router/router/core/entities/fractions"
"router/core"
"router/core/entities/fractions"
)

// interface는 I 접두사를 붙이는 것이 관행인가?
type IPortionProvider interface {
GetPortionAmount(tokenOutAmount fractions.CurrencyAmount, tradeType core.TradeType, swapConfig router.SwapOptions) fractions.CurrencyAmount
GetPortionAmount(tokenOutAmount fractions.CurrencyAmount, tradeType core.TradeType, swapConfig core.SwapOptions) fractions.CurrencyAmount
}

type PortionProvider struct {
Expand Down
2 changes: 1 addition & 1 deletion router/router.go → core/router.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package router
package core

type SwapRoute struct {
}
Expand Down

0 comments on commit 5a05455

Please sign in to comment.