-
Notifications
You must be signed in to change notification settings - Fork 3
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 #109 from unification-com/tweaks
go-ooo - ensure token symbols are not empty
- Loading branch information
Showing
1 changed file
with
31 additions
and
10 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 |
---|---|---|
@@ -1,24 +1,45 @@ | ||
package dex | ||
|
||
import ( | ||
"go-ooo/logger" | ||
"go-ooo/ooo_api/dex/types" | ||
"go-ooo/utils" | ||
"strings" | ||
) | ||
|
||
func pairIsClean(pair types.DexPair) bool { | ||
// check if Token symbols are empty/only whitespace | ||
if strings.TrimSpace(pair.Token0.Symbol) == "" || pair.Token0.Symbol == " " { | ||
return false | ||
} | ||
if strings.TrimSpace(pair.Token1.Symbol) == "" || pair.Token1.Symbol == " " { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
func (dm *Manager) updatePairsInDb(pairs []types.DexPair, dex, chain string) { | ||
for _, pair := range pairs { | ||
// pair.Token0.Id is the token's contract address | ||
t0Db, _ := dm.db.FindOrInsertNewTokenContract(pair.Token0.Symbol, pair.Token0.Id, chain) | ||
t1Db, _ := dm.db.FindOrInsertNewTokenContract(pair.Token1.Symbol, pair.Token1.Id, chain) | ||
if pairIsClean(pair) { | ||
// pair.Token0.Id is the token's contract address | ||
t0Db, _ := dm.db.FindOrInsertNewTokenContract(pair.Token0.Symbol, pair.Token0.Id, chain) | ||
t1Db, _ := dm.db.FindOrInsertNewTokenContract(pair.Token1.Symbol, pair.Token1.Id, chain) | ||
|
||
t0DtDb, _ := dm.db.FindOrInsertNewDexToken(pair.Token0.Symbol, t0Db.ID, dex, chain) | ||
t1DtDb, _ := dm.db.FindOrInsertNewDexToken(pair.Token1.Symbol, t1Db.ID, dex, chain) | ||
t0DtDb, _ := dm.db.FindOrInsertNewDexToken(pair.Token0.Symbol, t0Db.ID, dex, chain) | ||
t1DtDb, _ := dm.db.FindOrInsertNewDexToken(pair.Token1.Symbol, t1Db.ID, dex, chain) | ||
|
||
// store liquidity | ||
reserve, _ := utils.ParseBigFloat(pair.ReserveUSD) | ||
reserveUsd, _ := reserve.Float64() | ||
// store liquidity | ||
reserve, _ := utils.ParseBigFloat(pair.ReserveUSD) | ||
reserveUsd, _ := reserve.Float64() | ||
|
||
// todo - update latest liquidity | ||
_, _ = dm.db.FindOrInsertNewDexPair(pair.Token0.Symbol, pair.Token1.Symbol, pair.Id, dex, t0DtDb.ID, t1DtDb.ID, reserveUsd) | ||
// todo - update latest liquidity | ||
_, _ = dm.db.FindOrInsertNewDexPair(pair.Token0.Symbol, pair.Token1.Symbol, pair.Id, dex, t0DtDb.ID, t1DtDb.ID, reserveUsd) | ||
} else { | ||
logger.Debug("dex", "updatePairsInDb", "", "pair not clean", logger.Fields{ | ||
"Token0.Symbol": pair.Token0.Symbol, | ||
"Token1.Symbol": pair.Token1.Symbol, | ||
}) | ||
} | ||
} | ||
} |