Skip to content

Commit

Permalink
Update OKX utility logging and handle empty symbols in quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
perrornet committed Jul 10, 2024
1 parent 48228b7 commit ff5bd92
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion utils/provider/bridge/okx/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (o *OKX) GetBestTokenInChain(ctx context.Context, args provider.SwapParams)
FromTokenAddress: common.HexToAddress(tokenIn.ContractAddress),
})
if err != nil {
logrus.Debugf("get quote error: %s", err)
currentLog.Debugf("get quote error: %s", err)
return err
}
if len(quote.RouterList) == 0 {
Expand Down
17 changes: 17 additions & 0 deletions utils/provider/bridge/routernitro/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ func (r Routernitro) BuildTx(ctx context.Context, quote Quote, sender, receiver
quoteData["receiverAddress"] = sender.Hex()
}
quoteData["senderAddress"] = sender.Hex()
if quote.BridgeFee.Symbol == "" {
delete(quoteData, "bridgeFee")
quoteData["bridgeFee"] = map[string]string{}
}

if quote.Source.StableReserveAsset.Symbol == "" {
data := quoteData["source"].(map[string]interface{})
delete(data, "stableReserveAsset")
quoteData["source"] = data
}

if quote.Destination.StableReserveAsset.Symbol == "" {
data := quoteData["destination"].(map[string]interface{})
delete(data, "stableReserveAsset")
quoteData["destination"] = data
}

var body = bytes.NewBuffer(nil)
_ = json.NewEncoder(body).Encode(quoteData)
var result Txn
Expand Down
16 changes: 3 additions & 13 deletions utils/provider/bridge/routernitro/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ type Quote struct {
DataTx []string `json:"dataTx"`
} `json:"source"`
Destination struct {
ChainId string `json:"chainId"`
ChainType string `json:"chainType"`
Asset struct {
ChainId string `json:"chainId"`
Asset struct {
Decimals int `json:"decimals"`
Symbol string `json:"symbol"`
Name string `json:"name"`
Expand Down Expand Up @@ -108,13 +107,7 @@ type Quote struct {
IsWrappedAsset bool `json:"isWrappedAsset"`
IsReserveAsset bool `json:"isReserveAsset"`
} `json:"stableReserveAsset"`
TokenAmount decimal.Decimal `json:"tokenAmount"`
StableReserveAmount decimal.Decimal `json:"stableReserveAmount"`
PriceImpact string `json:"priceImpact"`
TokenPath string `json:"tokenPath"`
DataTx []string `json:"dataTx"`
Path []string `json:"path"`
Flags []string `json:"flags"`
TokenAmount decimal.Decimal `json:"tokenAmount"`
} `json:"destination"`
PartnerId interface{} `json:"partnerId"`
SlippageTolerance interface{} `json:"slippageTolerance"`
Expand Down Expand Up @@ -146,9 +139,6 @@ func (q Quote) Error() error {
if q.FlowType == "" {
return errors.New("flowType is empty")
}
if q.BridgeFee.Symbol == "" {
return errors.New("bridgeFee.symbol is empty")
}
if q.Destination.Asset.Symbol == "" {
return errors.New("destination.asset.symbol is empty")
}
Expand Down

0 comments on commit ff5bd92

Please sign in to comment.