-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from gnoswap-labs/workflows
feat: Add Workflow
- Loading branch information
Showing
11 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
name: Go | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22.X' | ||
- name: Build | ||
run: go build -v ./... | ||
- name: Test | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
go.work.sum | ||
|
||
# env file | ||
.env | ||
|
||
.idea | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
s := "gopher" | ||
fmt.Println("Hello and welcome, %s!", s) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package router | ||
|
||
type AlphaRouterParams struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package router | ||
|
||
import ( | ||
"router/router/core" | ||
"router/router/core/entities" | ||
"router/router/core/entities/fractions" | ||
) | ||
|
||
type AlphaRouter struct { | ||
} | ||
|
||
func NewAlphaRouter(params AlphaRouterParams) *AlphaRouter { | ||
return &AlphaRouter{} | ||
} | ||
|
||
// TODO: 원본 코드에서는 async 함수 | ||
// 라우트 한 결과는 SwapRoute | ||
func (a AlphaRouter) route( | ||
amount fractions.CurrencyAmount, | ||
quoteCurrency entities.Currency, | ||
tradeType core.TradeType, | ||
) SwapRoute { | ||
originalAmount := amount | ||
|
||
currencyIn, currencyOut := a.determineCurrencyInOutFromTradeType(tradeType, amount, quoteCurrency) | ||
|
||
// currencyIn, currencyOut은 Currency 타입이고 | ||
// Currency 타입은 NativeCurrency이거나 Token 타입이다. | ||
// 아래에서 Token 타입이길 원하는 듯하다. | ||
tokenIn := currencyIn | ||
tokenOut := currencyOut | ||
|
||
swapRoute := SwapRoute{} | ||
return swapRoute | ||
} | ||
|
||
func (a AlphaRouter) determineCurrencyInOutFromTradeType( | ||
tradeType core.TradeType, | ||
amount fractions.CurrencyAmount, | ||
quoteCurrency entities.Currency, | ||
) (entities.Currency, entities.Currency) { | ||
if tradeType == core.EXACT_INPUT { | ||
return amount.Currency, quoteCurrency | ||
} else { | ||
return quoteCurrency, amount.Currency | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package core | ||
|
||
type TradeType int | ||
|
||
const ( | ||
EXACT_INPUT = iota | ||
EXACT_OUTPUT | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package entities | ||
|
||
// 원문에서는 Currency는 Token | NativeCurrency 이고 | ||
// Token과 NativeCurrency 모두 BaseCurrency를 상속받는다. | ||
// 하지만 여기서의 Currency는 NativeCurrency와 Token에 포함된다. | ||
type Currency interface { | ||
wrapped() Token | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fractions | ||
|
||
import "router/router/core/entities" | ||
|
||
type CurrencyAmount struct { | ||
Currency entities.Currency | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package entities | ||
|
||
type Token struct { | ||
Currency | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package router | ||
|
||
type SwapRoute struct { | ||
} |