Skip to content

Commit

Permalink
feat: trading/base pair
Browse files Browse the repository at this point in the history
  • Loading branch information
5lliot committed Dec 19, 2023
1 parent df70a6c commit 67bcb63
Showing 1 changed file with 77 additions and 8 deletions.
85 changes: 77 additions & 8 deletions core/trading.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package core

var TRADING_SYMBOLS = []string{
import (
"strings"

"github.com/Gearbox-protocol/sdk-go/log"
"github.com/Gearbox-protocol/sdk-go/utils"
)

var TRADING_SYMBOLS = []Symbol{
"MKR",
"UNI",
"LINK",
Expand All @@ -11,17 +18,79 @@ var TRADING_SYMBOLS = []string{
"CVX",
"FXS",
// "BLUR",
"WETH",
"WBTC",
"ETH",
"BTC",
//
"stETH",
}

var BASE_SYMBOL []string = []string{"DAI", "WETH", "WBTC"}
var BASE_SYMBOLS []Symbol = []Symbol{"DAI", "ETH", "BTC"}

var COMMON_TRADING_SYMBOLS []Symbol = []Symbol{"ETH", "BTC"}

func NotCommonBase() (ans []Symbol) {
set := map[Symbol]bool{}
for _, common := range COMMON_TRADING_SYMBOLS {
set[common] = true
}
for _, base := range BASE_SYMBOLS {
if !set[base] {
ans = append(ans, base)
}
}
return
}
func AllTradingSymbolForDBWithW() (ans []Symbol) {
set := map[Symbol]bool{}
for _, symbol := range TRADING_SYMBOLS {
set[symbol] = true
}
for _, symbol := range BASE_SYMBOLS {
set[symbol] = true
}
ans = make([]Symbol, 0, len(set))
for token := range set {
if utils.Contains([]string{"ETH", "BTC"}, string(token)) {
token = Symbol("W" + string(token))
}
ans = append(ans, token)
}
return
}

type TradingPair Symbol

func NewTradingPair[T ~string, X ~string](trading X, base T) TradingPair {
return TradingPair(string(trading) + string(base))
}

func (pair TradingPair) Tokens() (token, base Symbol) {
if strings.HasSuffix(string(pair), "USDC") {
return Symbol(pair[:len(pair)-len("USDC")]), Symbol("USDC")
}
for _, base := range BASE_SYMBOLS {
if strings.HasSuffix(string(pair), string(base)) {
return Symbol(pair[:len(pair)-len(base)]), base
}
}

func TradingSymNoW[T ~string](sym T) T {
if sym[0] == 'W' {
sym = sym[1:]
log.Fatalf("can't find the base token for pair %s", pair)
return "", ""
}

var notAllowedPairs = []TradingPair{
"ETHBTC",
"DAIBTC",
"DAIETH",
}

func PairIsAllowed(tradingSym, baseSym Symbol) bool {
if tradingSym == baseSym {
return false
}
pair := NewTradingPair(tradingSym, baseSym)
if utils.Contains(notAllowedPairs, pair) {
return false
}
return sym
return true
}

0 comments on commit 67bcb63

Please sign in to comment.