From 7622d39eb9288af31b27b4e092a0761c1e2f33a0 Mon Sep 17 00:00:00 2001 From: tolelom Date: Tue, 27 Aug 2024 16:49:22 +0900 Subject: [PATCH 1/5] feat: fraction entity added --- router/alpha-router.go | 27 +++- router/core/entities/baseCurrency.go | 29 +++++ router/core/entities/currency.go | 2 +- .../core/entities/fractions/currencyAmount.go | 7 ++ router/core/entities/fractions/fraction.go | 119 ++++++++++++++++++ .../core/entities/fractions/fraction_test.go | 39 ++++++ router/core/entities/gnot.go | 21 ++++ router/core/entities/nativeCurrency.go | 6 + router/core/entities/token.go | 10 +- router/core/entities/utils/math.go | 8 ++ router/core/entities/wgnot.go | 10 ++ router/providers/portion-provider.go | 15 +++ router/router.go | 10 ++ 13 files changed, 298 insertions(+), 5 deletions(-) create mode 100644 router/core/entities/baseCurrency.go create mode 100644 router/core/entities/fractions/fraction.go create mode 100644 router/core/entities/fractions/fraction_test.go create mode 100644 router/core/entities/gnot.go create mode 100644 router/core/entities/nativeCurrency.go create mode 100644 router/core/entities/utils/math.go create mode 100644 router/core/entities/wgnot.go create mode 100644 router/providers/portion-provider.go diff --git a/router/alpha-router.go b/router/alpha-router.go index a388b5c..c89e162 100644 --- a/router/alpha-router.go +++ b/router/alpha-router.go @@ -4,9 +4,11 @@ import ( "router/router/core" "router/router/core/entities" "router/router/core/entities/fractions" + "router/router/providers" ) type AlphaRouter struct { + portionProvider providers.IPortionProvider } func NewAlphaRouter(params AlphaRouterParams) *AlphaRouter { @@ -19,16 +21,35 @@ func (a AlphaRouter) route( amount fractions.CurrencyAmount, quoteCurrency entities.Currency, tradeType core.TradeType, + swapConfig SwapOptions, ) SwapRoute { originalAmount := amount currencyIn, currencyOut := a.determineCurrencyInOutFromTradeType(tradeType, amount, quoteCurrency) // currencyIn, currencyOut은 Currency 타입이고 - // Currency 타입은 NativeCurrency이거나 Token 타입이다. + // Currency 타입은 NativeCurrency(GNOT)이거나 Token 타입이다. // 아래에서 Token 타입이길 원하는 듯하다. - tokenIn := currencyIn - tokenOut := currencyOut + tokenIn := currencyIn.Wrapped() + tokenOut := currencyOut.Wrapped() + + // core 패키지를 TradeType 패키지로 변경하면 가독성이 더 좋아질 듯 하다. + if tradeType == core.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) + } + } swapRoute := SwapRoute{} return swapRoute diff --git a/router/core/entities/baseCurrency.go b/router/core/entities/baseCurrency.go new file mode 100644 index 0000000..a75e45f --- /dev/null +++ b/router/core/entities/baseCurrency.go @@ -0,0 +1,29 @@ +package entities + +type BaseCurrency struct { + isNative bool + isToken bool + + chainId int + decimals int + + symbol *string + name *string + address *string +} + +func NewBaseCurrency(chainId int, decimals int, symbol string, name string) *BaseCurrency { + return &BaseCurrency{ + // 아래 코드는 원문 + //invariant(Number.isSafeInteger(chainId), 'CHAIN_ID'); + //invariant( + // decimals >= 0 && decimals < 255 && Number.isInteger(decimals), + // 'DECIMALS', + //); + + chainId: chainId, + decimals: decimals, + symbol: &symbol, + name: &name, + } +} diff --git a/router/core/entities/currency.go b/router/core/entities/currency.go index 30a6b32..bebeb9a 100644 --- a/router/core/entities/currency.go +++ b/router/core/entities/currency.go @@ -4,5 +4,5 @@ package entities // Token과 NativeCurrency 모두 BaseCurrency를 상속받는다. // 하지만 여기서의 Currency는 NativeCurrency와 Token에 포함된다. type Currency interface { - wrapped() Token + Wrapped() Token } diff --git a/router/core/entities/fractions/currencyAmount.go b/router/core/entities/fractions/currencyAmount.go index 2fafe19..0089822 100644 --- a/router/core/entities/fractions/currencyAmount.go +++ b/router/core/entities/fractions/currencyAmount.go @@ -3,5 +3,12 @@ package fractions import "router/router/core/entities" type CurrencyAmount struct { + Fraction Currency entities.Currency } + +//func (c CurrencyAmount) add(other CurrencyAmount) CurrencyAmount { +// added := c.Fraction.add(other) +// +// return CurrencyAmount.fromFractionAmount() +//} diff --git a/router/core/entities/fractions/fraction.go b/router/core/entities/fractions/fraction.go new file mode 100644 index 0000000..4a72349 --- /dev/null +++ b/router/core/entities/fractions/fraction.go @@ -0,0 +1,119 @@ +package fractions + +import ( + "errors" + "math/big" +) + +type Fraction struct { + Numerator *big.Int + Denominator *big.Int +} + +func NewFraction(numerator int64, denominator int64) *Fraction { + return &Fraction{ + Numerator: big.NewInt(numerator), + Denominator: big.NewInt(denominator), + } +} + +func tryParseFraction(value interface{}) (Fraction, error) { + switch v := value.(type) { + case Fraction: + return v, nil + case *big.Int: + return Fraction{Numerator: v, Denominator: big.NewInt(1)}, nil + case big.Int: + return Fraction{Numerator: &v, Denominator: big.NewInt(1)}, nil + // TODO: int64 등 추가 바람 + default: + return Fraction{}, errors.New("not a fraction") + } +} + +// --------------------------- +// TODO: 형을 자유롭게 받은 다음 tryParseFraction으로 한 번 거르고 사용하도록 하기 +// 덧셈 +func (f Fraction) Add(other *Fraction) *Fraction { + numerator1 := new(big.Int).Mul(f.Numerator, other.Denominator) + numerator2 := new(big.Int).Mul(other.Numerator, f.Denominator) + denominator := new(big.Int).Mul(f.Denominator, other.Denominator) + resultNumerator := new(big.Int).Add(numerator1, numerator2) + + // TODO: 약분 + //g := utils.Gcd(resultNumerator, denominator) + + return &Fraction{ + Numerator: resultNumerator, + Denominator: denominator, + } +} + +// 뺄셈 +// TODO: 덧셈 활용해서 코드 단순화 할 수도 있을지도... +func (f Fraction) Sub(other *Fraction) *Fraction { + numerator1 := new(big.Int).Mul(f.Numerator, other.Denominator) + numerator2 := new(big.Int).Mul(other.Numerator, f.Denominator) + denominator := new(big.Int).Mul(f.Denominator, other.Denominator) + resultNumerator := new(big.Int).Sub(numerator1, numerator2) + + // TODO: 약분 + //g := utils.Gcd(resultNumerator, denominator) + + return &Fraction{ + Numerator: resultNumerator, + Denominator: denominator, + } +} + +func (f Fraction) LessThan(other *Fraction) bool { + leftValue := new(big.Int).Mul(f.Numerator, other.Denominator) + rightValue := new(big.Int).Mul(other.Numerator, f.Denominator) + return leftValue.Cmp(rightValue) < 0 +} + +func (f Fraction) GreaterThan(other *Fraction) bool { + leftValue := new(big.Int).Mul(f.Numerator, other.Denominator) + rightValue := new(big.Int).Mul(other.Numerator, f.Denominator) + return leftValue.Cmp(rightValue) > 0 +} + +// 약분이 완료되었다는 가정 +// WARN: 약분이 안되었다는 가정이라면 약분하는 로직 추가해야 함 +func (f Fraction) Equals(other *Fraction) bool { + return f.Numerator.Cmp(other.Numerator) == 0 && + f.Denominator.Cmp(other.Denominator) == 0 +} + +// 몫 +func (f Fraction) Quotient() *big.Int { + return new(big.Int).Quo(f.Numerator, f.Denominator) +} + +// NOTE: 단순 나머지가 아니라 분수 형태로 표시한다 +// 좋은 형태의 함수는 아니라 생각 +func (f Fraction) Remainder() Fraction { + return Fraction{ + Numerator: new(big.Int).Rem(f.Numerator, f.Denominator), + Denominator: f.Denominator, + } +} + +// 역 +func (f Fraction) Invert() Fraction { + return Fraction{ + Numerator: f.Denominator, + Denominator: f.Numerator, + } +} + +//func (f Fraction) GreaterThan(other interface{}) (bool, error) { +// otherParsed, err := tryParseFraction(other) +// if err != nil { +// return false, err +// } +//left := f.Numerator * otherParsed.Denominator +//right := otherParsed.Denominator * f.Numerator +// +// return left > right, nil +//} diff --git a/router/core/entities/fractions/fraction_test.go b/router/core/entities/fractions/fraction_test.go new file mode 100644 index 0000000..6a1ab85 --- /dev/null +++ b/router/core/entities/fractions/fraction_test.go @@ -0,0 +1,39 @@ +package fractions + +import ( + "testing" +) + +func TestFraction_Add(t *testing.T) { + fraction1 := NewFraction(1, 2) + fraction2 := NewFraction(1, 3) + + result := fraction1.Add(fraction2) + + expected := NewFraction(5, 6) + + if result.Numerator.Cmp(expected.Numerator) != 0 || result.Denominator.Cmp(expected.Denominator) != 0 { + t.Fatalf("Add: expected %v, got %v", expected, result) + } +} + +func TestFraction_Sub(t *testing.T) { + fraction1 := NewFraction(1, 2) + fraction2 := NewFraction(1, 3) + result := fraction1.Sub(fraction2) + expected := NewFraction(1, 6) + if result.Numerator.Cmp(expected.Numerator) != 0 || result.Denominator.Cmp(expected.Denominator) != 0 { + t.Fatalf("Sub: expected %v, got %v", expected, result) + } +} + +func TestFraction_LessThan(t *testing.T) { + fraction1 := NewFraction(1, 2) + fraction2 := NewFraction(1, 3) + result := fraction1.LessThan(fraction2) + expected := false + + if result != expected { + t.Fatalf("LessThan: expected %v, got %v", expected, result) + } +} diff --git a/router/core/entities/gnot.go b/router/core/entities/gnot.go new file mode 100644 index 0000000..2db7dbb --- /dev/null +++ b/router/core/entities/gnot.go @@ -0,0 +1,21 @@ +package entities + +type Gnot struct { + NativeCurrency +} + +func NewGnot(chainId int) *Gnot { + return &Gnot{ + NativeCurrency: NativeCurrency{ + BaseCurrency: BaseCurrency{ + chainId: chainId, + }, + }, + } +} + +func (g Gnot) Wrapped() Token { + wgnot := WGNOT[g.chainId] + // invariant(!!wgnot, 'WRAPPED') + return wgnot +} diff --git a/router/core/entities/nativeCurrency.go b/router/core/entities/nativeCurrency.go new file mode 100644 index 0000000..aa2862d --- /dev/null +++ b/router/core/entities/nativeCurrency.go @@ -0,0 +1,6 @@ +package entities + +// Gnot이 NativeCurrency를 상속한다. +type NativeCurrency struct { + BaseCurrency +} diff --git a/router/core/entities/token.go b/router/core/entities/token.go index cc76145..af61500 100644 --- a/router/core/entities/token.go +++ b/router/core/entities/token.go @@ -1,5 +1,13 @@ package entities type Token struct { - Currency + BaseCurrency +} + +func NewToken() *Token { + return &Token{} +} + +func (t Token) Wrapped() Token { + return t } diff --git a/router/core/entities/utils/math.go b/router/core/entities/utils/math.go new file mode 100644 index 0000000..0b6bd44 --- /dev/null +++ b/router/core/entities/utils/math.go @@ -0,0 +1,8 @@ +package utils + +import "math/big" + +func Gcd(a, b *big.Int) *big.Int { + + return a +} diff --git a/router/core/entities/wgnot.go b/router/core/entities/wgnot.go new file mode 100644 index 0000000..2740d5c --- /dev/null +++ b/router/core/entities/wgnot.go @@ -0,0 +1,10 @@ +package entities + +var WGNOT = map[int]Token{ + //1: NewToken(), + //2: NewToken(), + //3: NewToken(), + //4: NewToken(), + //5: NewToken(), + //99: NewToken(), +} diff --git a/router/providers/portion-provider.go b/router/providers/portion-provider.go new file mode 100644 index 0000000..22b82db --- /dev/null +++ b/router/providers/portion-provider.go @@ -0,0 +1,15 @@ +package providers + +import ( + "router/router" + "router/router/core" + "router/router/core/entities/fractions" +) + +// interface는 I 접두사를 붙이는 것이 관행인가? +type IPortionProvider interface { + GetPortionAmount(tokenOutAmount fractions.CurrencyAmount, tradeType core.TradeType, swapConfig router.SwapOptions) fractions.CurrencyAmount +} + +type PortionProvider struct { +} diff --git a/router/router.go b/router/router.go index 70026b2..4d4904e 100644 --- a/router/router.go +++ b/router/router.go @@ -2,3 +2,13 @@ package router type SwapRoute struct { } + +type IRouter interface { +} + +// TODO: 원문: type SwapOptions = SwapOptionsUniversalRouter | SwapOptionsSwapRouter02 +type SwapOptions struct { +} + +type SwapOptionsUniversalRouter struct { +} From 5a0545550128d92f28476be7d797d9efa519f6d0 Mon Sep 17 00:00:00 2001 From: tolelom Date: Tue, 27 Aug 2024 17:13:37 +0900 Subject: [PATCH 2/5] resolve dependency cycle change router/router -> router/core --- {router => core}/alpha-router-params.go | 2 +- {router => core}/alpha-router.go | 28 ++++++++----------- {router/core => core}/constants.go | 0 .../core => core}/entities/baseCurrency.go | 0 {router/core => core}/entities/currency.go | 0 .../entities/fractions/currencyAmount.go | 4 ++- .../entities/fractions/fraction.go | 0 .../entities/fractions/fraction_test.go | 0 {router/core => core}/entities/gnot.go | 0 .../core => core}/entities/nativeCurrency.go | 0 {router/core => core}/entities/token.go | 0 {router/core => core}/entities/utils/math.go | 0 {router/core => core}/entities/wgnot.go | 0 .../providers/portion-provider.go | 7 ++--- {router => core}/router.go | 2 +- 15 files changed, 20 insertions(+), 23 deletions(-) rename {router => core}/alpha-router-params.go (70%) rename {router => core}/alpha-router.go (77%) rename {router/core => core}/constants.go (100%) rename {router/core => core}/entities/baseCurrency.go (100%) rename {router/core => core}/entities/currency.go (100%) rename {router/core => core}/entities/fractions/currencyAmount.go (86%) rename {router/core => core}/entities/fractions/fraction.go (100%) rename {router/core => core}/entities/fractions/fraction_test.go (100%) rename {router/core => core}/entities/gnot.go (100%) rename {router/core => core}/entities/nativeCurrency.go (100%) rename {router/core => core}/entities/token.go (100%) rename {router/core => core}/entities/utils/math.go (100%) rename {router/core => core}/entities/wgnot.go (100%) rename {router => core}/providers/portion-provider.go (59%) rename {router => core}/router.go (93%) diff --git a/router/alpha-router-params.go b/core/alpha-router-params.go similarity index 70% rename from router/alpha-router-params.go rename to core/alpha-router-params.go index 6c258dd..e9c8e8d 100644 --- a/router/alpha-router-params.go +++ b/core/alpha-router-params.go @@ -1,4 +1,4 @@ -package router +package core type AlphaRouterParams struct { } diff --git a/router/alpha-router.go b/core/alpha-router.go similarity index 77% rename from router/alpha-router.go rename to core/alpha-router.go index c89e162..7d5351a 100644 --- a/router/alpha-router.go +++ b/core/alpha-router.go @@ -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 { @@ -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 @@ -34,7 +33,7 @@ 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, @@ -42,13 +41,10 @@ func (a AlphaRouter) route( 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{} @@ -56,11 +52,11 @@ func (a AlphaRouter) route( } 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 diff --git a/router/core/constants.go b/core/constants.go similarity index 100% rename from router/core/constants.go rename to core/constants.go diff --git a/router/core/entities/baseCurrency.go b/core/entities/baseCurrency.go similarity index 100% rename from router/core/entities/baseCurrency.go rename to core/entities/baseCurrency.go diff --git a/router/core/entities/currency.go b/core/entities/currency.go similarity index 100% rename from router/core/entities/currency.go rename to core/entities/currency.go diff --git a/router/core/entities/fractions/currencyAmount.go b/core/entities/fractions/currencyAmount.go similarity index 86% rename from router/core/entities/fractions/currencyAmount.go rename to core/entities/fractions/currencyAmount.go index 0089822..4fe107a 100644 --- a/router/core/entities/fractions/currencyAmount.go +++ b/core/entities/fractions/currencyAmount.go @@ -1,6 +1,8 @@ package fractions -import "router/router/core/entities" +import ( + "router/core/entities" +) type CurrencyAmount struct { Fraction diff --git a/router/core/entities/fractions/fraction.go b/core/entities/fractions/fraction.go similarity index 100% rename from router/core/entities/fractions/fraction.go rename to core/entities/fractions/fraction.go diff --git a/router/core/entities/fractions/fraction_test.go b/core/entities/fractions/fraction_test.go similarity index 100% rename from router/core/entities/fractions/fraction_test.go rename to core/entities/fractions/fraction_test.go diff --git a/router/core/entities/gnot.go b/core/entities/gnot.go similarity index 100% rename from router/core/entities/gnot.go rename to core/entities/gnot.go diff --git a/router/core/entities/nativeCurrency.go b/core/entities/nativeCurrency.go similarity index 100% rename from router/core/entities/nativeCurrency.go rename to core/entities/nativeCurrency.go diff --git a/router/core/entities/token.go b/core/entities/token.go similarity index 100% rename from router/core/entities/token.go rename to core/entities/token.go diff --git a/router/core/entities/utils/math.go b/core/entities/utils/math.go similarity index 100% rename from router/core/entities/utils/math.go rename to core/entities/utils/math.go diff --git a/router/core/entities/wgnot.go b/core/entities/wgnot.go similarity index 100% rename from router/core/entities/wgnot.go rename to core/entities/wgnot.go diff --git a/router/providers/portion-provider.go b/core/providers/portion-provider.go similarity index 59% rename from router/providers/portion-provider.go rename to core/providers/portion-provider.go index 22b82db..dc0f639 100644 --- a/router/providers/portion-provider.go +++ b/core/providers/portion-provider.go @@ -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 { diff --git a/router/router.go b/core/router.go similarity index 93% rename from router/router.go rename to core/router.go index 4d4904e..3ff9580 100644 --- a/router/router.go +++ b/core/router.go @@ -1,4 +1,4 @@ -package router +package core type SwapRoute struct { } From 3c12c8f7ea0b88ea59ea962bcc1433e99ac9f80d Mon Sep 17 00:00:00 2001 From: tolelom Date: Tue, 27 Aug 2024 17:19:42 +0900 Subject: [PATCH 3/5] fix --- core/alpha-router.go | 58 +++++++++---------- .../portion-provider.go => types.go} | 5 +- 2 files changed, 31 insertions(+), 32 deletions(-) rename core/{providers/portion-provider.go => types.go} (69%) diff --git a/core/alpha-router.go b/core/alpha-router.go index 7d5351a..89b25ec 100644 --- a/core/alpha-router.go +++ b/core/alpha-router.go @@ -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 { @@ -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( diff --git a/core/providers/portion-provider.go b/core/types.go similarity index 69% rename from core/providers/portion-provider.go rename to core/types.go index dc0f639..f80a40a 100644 --- a/core/providers/portion-provider.go +++ b/core/types.go @@ -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 { From 7ff5c4b8bf82a4633bf9018e090cf8a342301569 Mon Sep 17 00:00:00 2001 From: tolelom Date: Tue, 27 Aug 2024 17:27:06 +0900 Subject: [PATCH 4/5] delete router/main.go --- main.go | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 main.go diff --git a/main.go b/main.go deleted file mode 100644 index 725c460..0000000 --- a/main.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "fmt" -) - -func main() { - s := "gopher" - fmt.Println("Hello and welcome, %s!", s) - -} From a1b26b920debb68ac15ba3c057b1d6e9d5880737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=B1=EB=AF=BC?= <98kimsungmin@naver.com> Date: Tue, 27 Aug 2024 17:40:39 +0900 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Lee ByeongJun --- core/entities/baseCurrency.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/entities/baseCurrency.go b/core/entities/baseCurrency.go index a75e45f..ba333a4 100644 --- a/core/entities/baseCurrency.go +++ b/core/entities/baseCurrency.go @@ -7,9 +7,9 @@ type BaseCurrency struct { chainId int decimals int - symbol *string - name *string - address *string + symbol string + name string + address string } func NewBaseCurrency(chainId int, decimals int, symbol string, name string) *BaseCurrency { @@ -23,7 +23,7 @@ func NewBaseCurrency(chainId int, decimals int, symbol string, name string) *Bas chainId: chainId, decimals: decimals, - symbol: &symbol, - name: &name, + symbol: symbol, + name: name, } }