Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tolelom committed Aug 27, 2024
1 parent 5a05455 commit 3c12c8f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
58 changes: 29 additions & 29 deletions core/alpha-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package core
import (
"router/core/entities"
"router/core/entities/fractions"
"router/core/providers"
)

type AlphaRouter struct {
portionProvider providers.IPortionProvider
portionProvider IPortionProvider
}

func NewAlphaRouter(params AlphaRouterParams) *AlphaRouter {
Expand All @@ -22,33 +21,34 @@ func (a AlphaRouter) route(
tradeType TradeType,
swapConfig SwapOptions,
) SwapRoute {
originalAmount := amount

currencyIn, currencyOut := a.determineCurrencyInOutFromTradeType(tradeType, amount, quoteCurrency)

// currencyIn, currencyOut은 Currency 타입이고
// Currency 타입은 NativeCurrency(GNOT)이거나 Token 타입이다.
// 아래에서 Token 타입이길 원하는 듯하다.
tokenIn := currencyIn.Wrapped()
tokenOut := currencyOut.Wrapped()

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

//result := portionAmount.GreaterThan(0)
//if result {
// amount = amount.add(portionAmount)
//}
}

swapRoute := SwapRoute{}
return swapRoute
//originalAmount := amount
//
//currencyIn, currencyOut := a.determineCurrencyInOutFromTradeType(tradeType, amount, quoteCurrency)
//
//// currencyIn, currencyOut은 Currency 타입이고
//// Currency 타입은 NativeCurrency(GNOT)이거나 Token 타입이다.
//// 아래에서 Token 타입이길 원하는 듯하다.
//tokenIn := currencyIn.Wrapped()
//tokenOut := currencyOut.Wrapped()
//
//// core 패키지를 TradeType 패키지로 변경하면 가독성이 더 좋아질 듯 하다.
//if tradeType == EXACT_OUTPUT {
// // TODO: GetPortionAmount에서 반환 값인 CurrencyAmount을 반환하지 못할 경우가 있을 수도 있다.(높은 확률로)
// portionAmount := a.portionProvider.GetPortionAmount(
// amount,
// tradeType,
// swapConfig,
// )
//
// //result := portionAmount.GreaterThan(0)
// //if result {
// // amount = amount.add(portionAmount)
// //}
//}
//
//swapRoute := SwapRoute{}
//return swapRoute
return SwapRoute{}
}

func (a AlphaRouter) determineCurrencyInOutFromTradeType(
Expand Down
5 changes: 2 additions & 3 deletions core/providers/portion-provider.go → core/types.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package providers
package core

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

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

type PortionProvider struct {
Expand Down

0 comments on commit 3c12c8f

Please sign in to comment.