Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ignore] thinner rfq diff for api #1689

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions services/rfq/api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ package client

import (
"fmt"
"strconv"
"time"

"github.com/brianvoe/gofakeit/v6"
"github.com/synapsecns/sanguine/core/ginhelper"
"github.com/synapsecns/sanguine/core/metrics"
"strconv"
"time"

"github.com/dubonzi/otelresty"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -179,8 +180,8 @@ type APIQuotePutRequest struct {
DestChainID string `json:"dest_chain_id"`
DestTokenAddr string `json:"dest_token_addr"`
DestAmount string `json:"dest_amount"`
Price string `json:"price"`
MaxOriginAmount string `json:"max_origin_amount"`
FixedFee string `json:"fixed_fee"`
}

// APIQuoteSpecificGetRequest is the struct for the quote API.
Expand Down
11 changes: 6 additions & 5 deletions services/rfq/api/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package client_test

import (
"fmt"
"strconv"

"github.com/shopspring/decimal"
"github.com/synapsecns/sanguine/services/rfq/api/db"
"strconv"

"github.com/synapsecns/sanguine/services/rfq/api/client"
)
Expand All @@ -18,8 +19,8 @@ func (c *ClientSuite) TestPutAndGetQuote() {
DestChainID: "42161",
DestTokenAddr: "0xDestTokenAddr",
DestAmount: "100.0",
Price: "50.0",
MaxOriginAmount: "200.0",
FixedFee: "10.0",
}

err := c.client.PutQuote(&putData)
Expand All @@ -37,8 +38,8 @@ func (c *ClientSuite) assertEqual(q1 client.APIQuotePutRequest, quote *db.Quote)
c.Assert().Equal(q1.DestChainID, strconv.Itoa(int(quote.DestChainID)))
c.Assert().Equal(q1.DestTokenAddr, quote.DestTokenAddr)
c.assertStringFloatEqual(q1.DestAmount, quote.DestAmount)
c.assertStringFloatEqual(q1.Price, quote.Price)
c.assertStringFloatEqual(q1.MaxOriginAmount, quote.MaxOriginAmount)
c.assertStringFloatEqual(q1.FixedFee, quote.FixedFee)
}

func (c *ClientSuite) assertStringFloatEqual(s1 string, f2 decimal.Decimal) {
Expand All @@ -58,8 +59,8 @@ func (c *ClientSuite) TestGetSpecificQuote() {
DestChainID: "42161",
DestTokenAddr: "0xDestTokenAddr",
DestAmount: "100.0",
Price: "50.0",
MaxOriginAmount: "200.0",
FixedFee: "10.0",
}

err := c.client.PutQuote(&putData)
Expand All @@ -83,8 +84,8 @@ func (c *ClientSuite) TestGetQuoteByRelayerAddress() {
DestChainID: "42161",
DestTokenAddr: "0xDestTokenAddr",
DestAmount: "100.0",
Price: "50.0",
MaxOriginAmount: "200.0",
FixedFee: "10.0",
}

err := c.client.PutQuote(&putData)
Expand Down
6 changes: 3 additions & 3 deletions services/rfq/api/db/api_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ type Quote struct {
DestTokenAddr string `gorm:"column:dest_token;index;primaryKey"`
// DestAmount is the max amount of liquidity which exists for a given destination token, provided in the destination token decimals
DestAmount decimal.Decimal `gorm:"column:dest_amount"`
// Price is the price per origin token provided for which a relayer is indicating willingness to relay
Price decimal.Decimal `gorm:"column:price"`
// MaxOriginAmount is the maximum amount of origin tokens bridgeable, calculated by dividing the DestAmount by the Price
// MaxOriginAmount is the maximum amount of origin tokens bridgeable
MaxOriginAmount decimal.Decimal `gorm:"column:max_origin_amount"`
// FixedFee is the fixed fee for the quote, provided in the destination token terms
FixedFee decimal.Decimal `gorm:"column:fixed_fee"`
// Address of the relayer providing the quote
RelayerAddr string `gorm:"column:relayer_address;primaryKey"`
// UpdatedAt is the time that the quote was last upserted
Expand Down
8 changes: 4 additions & 4 deletions services/rfq/api/db/api_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func (d *DBSuite) TestGetQuotesByDestChainAndToken() {
DestChainID: 42161,
DestTokenAddr: "0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE",
DestAmount: decimal.NewFromInt(1000),
Price: decimal.NewFromFloat(0.01),
MaxOriginAmount: decimal.NewFromInt(1000).Div(decimal.NewFromFloat(0.01)),
FixedFee: decimal.NewFromFloat(1),
}
err := testDB.UpsertQuote(d.GetTestContext(), expectedQuote)
d.Require().NoError(err)
Expand Down Expand Up @@ -50,8 +50,8 @@ func (d *DBSuite) TestUpsertQuote() {
DestChainID: 42161,
DestTokenAddr: "0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE",
DestAmount: decimal.NewFromInt(1000),
Price: decimal.NewFromFloat(0.01),
MaxOriginAmount: decimal.NewFromInt(1000).Div(decimal.NewFromFloat(0.01)),
FixedFee: decimal.NewFromFloat(1),
}

// Act & Assert: Insert new quote
Expand All @@ -65,15 +65,15 @@ func (d *DBSuite) TestUpsertQuote() {
// Assert other fields if necessary

// Act & Assert: Update the existing quote
quote.Price = decimal.NewFromFloat(0.02)
quote.FixedFee = decimal.NewFromFloat(2)
err = testDB.UpsertQuote(d.GetTestContext(), quote)
d.Require().NoError(err)

// Retrieve to verify update
updatedQuotes, err := testDB.GetQuotesByDestChainAndToken(d.GetTestContext(), quote.DestChainID, quote.DestTokenAddr)
d.Require().NoError(err)
d.Len(updatedQuotes, 1)
d.Equal(quote.Price, updatedQuotes[0].Price)
d.Equal(quote.FixedFee, updatedQuotes[0].FixedFee)
// Assert other fields if necessary
})
}
6 changes: 3 additions & 3 deletions services/rfq/api/rest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func (h *Handler) ModifyQuote(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid DestAmount"})
return
}
price, err := decimal.NewFromString(putRequest.Price)
fixedFee, err := decimal.NewFromString(putRequest.FixedFee)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Price"})
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid FixedFee"})
return
}
// nolint: forcetypeassert
Expand All @@ -75,8 +75,8 @@ func (h *Handler) ModifyQuote(c *gin.Context) {
DestChainID: destChainID,
DestTokenAddr: putRequest.DestTokenAddr,
DestAmount: destAmount,
Price: price,
MaxOriginAmount: maxOriginAmount,
FixedFee: fixedFee,
//nolint: forcetypeassert
RelayerAddr: relayerAddr.(string),
}
Expand Down
7 changes: 4 additions & 3 deletions services/rfq/api/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ package rest
import (
"context"
"fmt"
"github.com/ipfs/go-log"
"github.com/synapsecns/sanguine/core/ginhelper"
"net/http"
"strconv"
"time"

"github.com/ipfs/go-log"
"github.com/synapsecns/sanguine/core/ginhelper"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -118,8 +119,8 @@ type PutRequest struct {
DestChainID string `json:"dest_chain_id"`
DestTokenAddr string `json:"dest_token_addr"`
DestAmount string `json:"dest_amount"`
Price string `json:"price"`
MaxOriginAmount string `json:"max_origin_amount"`
FixedFee string `json:"fixed_fee"`
}

// AuthMiddleware is the Gin authentication middleware that authenticates requests using EIP191.
Expand Down
11 changes: 6 additions & 5 deletions services/rfq/api/rest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/synapsecns/sanguine/ethergo/signer/wallet"
"github.com/synapsecns/sanguine/services/rfq/api/db"
"github.com/synapsecns/sanguine/services/rfq/api/rest"
)

Expand Down Expand Up @@ -146,14 +147,14 @@ func (c *ServerSuite) TestPutAndGetQuote() {
}()
c.Assert().Equal(http.StatusOK, getResp.StatusCode)

var quotes []rest.PutRequest
var quotes []*db.Quote
err = json.NewDecoder(getResp.Body).Decode(&quotes)
c.Require().NoError(err)

// Check if the newly added quote is present
found := false
for _, q := range quotes {
if q.Price == "50" {
if q.FixedFee.String() == "10" {
found = true
break
}
Expand Down Expand Up @@ -188,14 +189,14 @@ func (c *ServerSuite) TestPutAndGetQuoteByRelayer() {
}()
c.Assert().Equal(http.StatusOK, getResp.StatusCode)

var quotes []rest.PutRequest
var quotes []*db.Quote
err = json.NewDecoder(getResp.Body).Decode(&quotes)
c.Require().NoError(err)

// Check if the newly added quote is present
found := false
for _, q := range quotes {
if q.Price == "50" {
if q.FixedFee.String() == "10" {
found = true
break
}
Expand Down Expand Up @@ -242,8 +243,8 @@ func (c *ServerSuite) sendPutRequest(header string) (*http.Response, error) {
DestChainID: "42161",
DestTokenAddr: "0xDestTokenAddr",
DestAmount: "100.0",
Price: "50.0",
MaxOriginAmount: "200.0",
FixedFee: "10.0",
}
jsonData, err := json.Marshal(putData)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions services/rfq/relayer/quoter/quoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ package quoter
import (
"context"
"fmt"
"math/big"
"strings"

"github.com/ipfs/go-log"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/services/rfq/relayer/reldb"
"golang.org/x/exp/slices"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/synapsecns/sanguine/ethergo/signer/signer"
Expand Down Expand Up @@ -143,7 +144,6 @@ func (m *Manager) GenerateQuotes(chainID int, address common.Address, balance *b
DestChainID: fmt.Sprint(chainID),
DestTokenAddr: address.Hex(),
DestAmount: balance.String(),
Price: "1",
MaxOriginAmount: balance.String(),
}
quotes = append(quotes, quote)
Expand Down
Loading