Skip to content

Commit

Permalink
refactor: 🏷️ bebop: fix type & add logs
Browse files Browse the repository at this point in the history
Signed-off-by: thanhpp <[email protected]>
  • Loading branch information
thanhpp committed Oct 7, 2024
1 parent 1761162 commit 792f57c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
7 changes: 7 additions & 0 deletions pkg/liquidity-source/bebop/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"encoding/json"
"errors"

bebop "github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bebop"
Expand Down Expand Up @@ -60,7 +61,9 @@ func (c *HTTPClient) QuoteSingleOrderResult(ctx context.Context, params bebop.Qu
// token address case-sensitive
req := c.client.R().
SetContext(ctx).
// the SellTokens address must follow the HEX format
SetQueryParam(bebop.ParamsSellTokens, common.HexToAddress(params.SellTokens).Hex()).
// the BuyTokens address must follow the HEX format
SetQueryParam(bebop.ParamsBuyTokens, common.HexToAddress(params.BuyTokens).Hex()).
SetQueryParam(bebop.ParamsSellAmounts, params.SellAmounts).
SetQueryParam(bebop.ParamsTakerAddress, params.TakerAddress).
Expand All @@ -76,6 +79,10 @@ func (c *HTTPClient) QuoteSingleOrderResult(ctx context.Context, params bebop.Qu
return bebop.QuoteSingleOrderResult{}, err
}

respBytes := resp.Body()
_ = json.Unmarshal(respBytes, &result)
_ = json.Unmarshal(respBytes, &fail)

if !resp.IsSuccess() || fail.Failed() {
return bebop.QuoteSingleOrderResult{}, parseRFQError(fail.Error.ErrorCode, fail.Error.Message)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/liquidity-source/bebop/client/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func TestHTTPClient(t *testing.T) {
)

resp, err := c.QuoteSingleOrderResult(context.Background(), bebop.QuoteParams{
SellTokens: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
BuyTokens: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
SellTokens: "0xC02aaA39b223fe8D0A0e5C4F27eAD9083C756Cc2",
BuyTokens: "0xdac17F958D2ee523a2206206994597C13D831ec7",
SellAmounts: "100000000000000000",
TakerAddress: "0x5Bad996643a924De21b6b2875c85C33F3c5bBcB6",
ApprovalType: "Standard",
Expand Down
26 changes: 13 additions & 13 deletions pkg/liquidity-source/bebop/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ func (r QuoteFail) Failed() bool {
}

type QuoteSingleOrderResult struct {
Type string `json:"type"`
Status string `json:"status"`
QuoteID string `json:"quoteId"`
ChainID int `json:"chainId"`
ApprovalType string `json:"approvalType"`
NativeToken string `json:"nativeToken"`
Taker string `json:"taker"`
Receiver string `json:"receiver"`
Expiry int `json:"expiry"`
Slippage int `json:"slippage"`
Type string `json:"type"`
Status string `json:"status"`
QuoteID string `json:"quoteId"`
ChainID int `json:"chainId"`
ApprovalType string `json:"approvalType"`
NativeToken string `json:"nativeToken"`
Taker string `json:"taker"`
Receiver string `json:"receiver"`
Expiry int `json:"expiry"`
Slippage float64 `json:"slippage"`
GasFee struct {
Native string `json:"native"`
Usd int `json:"usd"`
Native string `json:"native"`
Usd float64 `json:"usd"`
} `json:"gasFee"`
BuyTokens map[string]TokenResult `json:"buyTokens"`
SellTokens map[string]TokenResult `json:"sellTokens"`
Expand All @@ -93,7 +93,7 @@ type QuoteSingleOrderResult struct {
Gas int `json:"gas"`
GasPrice int64 `json:"gasPrice"`
} `json:"tx"`
ToSign struct {
ToSign struct { // the toSign part uses camel_case
PartnerID int `json:"partner_id"`
Expiry int `json:"expiry"`
TakerAddress string `json:"taker_address"`
Expand Down

0 comments on commit 792f57c

Please sign in to comment.