Skip to content

Commit

Permalink
activeQuote depositAmount [SLT-464] (#3372)
Browse files Browse the repository at this point in the history
* add DepositAmount to QuoteInput, incorporate into getOriginAmount

* fix redundant declaration

* activequote tests. extended/revised comments

* lint

* relabel activeRFQ OriginAmount/DepositAmount to OriginAmountExact

* docs & json field label
  • Loading branch information
parodime authored Nov 12, 2024
1 parent 4019633 commit fd8ad75
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 140 deletions.
50 changes: 25 additions & 25 deletions services/rfq/api/db/api_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,39 +142,39 @@ var _ dbcommon.Enum = (*ActiveQuoteResponseStatus)(nil)

// ActiveQuoteRequest is the database model for an active quote request.
type ActiveQuoteRequest struct {
RequestID string `gorm:"column:request_id;primaryKey"`
IntegratorID string `gorm:"column:integrator_id"`
UserAddress string `gorm:"column:user_address"`
OriginChainID uint64 `gorm:"column:origin_chain_id"`
OriginTokenAddr string `gorm:"column:origin_token"`
DestChainID uint64 `gorm:"column:dest_chain_id"`
DestTokenAddr string `gorm:"column:dest_token"`
OriginAmount decimal.Decimal `gorm:"column:origin_amount"`
ExpirationWindow time.Duration `gorm:"column:expiration_window"`
CreatedAt time.Time `gorm:"column:created_at"`
Status ActiveQuoteRequestStatus `gorm:"column:status"`
ClosedAt *time.Time `gorm:"column:closed_at"`
ClosedQuoteID *string `gorm:"column:closed_quote_id"`
RequestID string `gorm:"column:request_id;primaryKey"`
IntegratorID string `gorm:"column:integrator_id"`
UserAddress string `gorm:"column:user_address"`
OriginChainID uint64 `gorm:"column:origin_chain_id"`
OriginTokenAddr string `gorm:"column:origin_token"`
DestChainID uint64 `gorm:"column:dest_chain_id"`
DestTokenAddr string `gorm:"column:dest_token"`
OriginAmountExact decimal.Decimal `gorm:"column:origin_amount_exact"`
ExpirationWindow time.Duration `gorm:"column:expiration_window"`
CreatedAt time.Time `gorm:"column:created_at"`
Status ActiveQuoteRequestStatus `gorm:"column:status"`
ClosedAt *time.Time `gorm:"column:closed_at"`
ClosedQuoteID *string `gorm:"column:closed_quote_id"`
}

// FromUserRequest converts a model.PutRFQRequest to an ActiveQuoteRequest.
func FromUserRequest(req *model.PutRFQRequest, requestID string) (*ActiveQuoteRequest, error) {
originAmount, err := decimal.NewFromString(req.Data.OriginAmount)
originAmountExact, err := decimal.NewFromString(req.Data.OriginAmountExact)
if err != nil {
return nil, fmt.Errorf("invalid origin amount: %w", err)
}
return &ActiveQuoteRequest{
RequestID: requestID,
IntegratorID: req.IntegratorID,
UserAddress: req.UserAddress,
OriginChainID: uint64(req.Data.OriginChainID),
OriginTokenAddr: req.Data.OriginTokenAddr,
DestChainID: uint64(req.Data.DestChainID),
DestTokenAddr: req.Data.DestTokenAddr,
OriginAmount: originAmount,
ExpirationWindow: time.Duration(req.Data.ExpirationWindow),
CreatedAt: time.Now(),
Status: Received,
RequestID: requestID,
IntegratorID: req.IntegratorID,
UserAddress: req.UserAddress,
OriginChainID: uint64(req.Data.OriginChainID),
OriginTokenAddr: req.Data.OriginTokenAddr,
DestChainID: uint64(req.Data.DestChainID),
DestTokenAddr: req.Data.DestTokenAddr,
OriginAmountExact: originAmountExact,
ExpirationWindow: time.Duration(req.Data.ExpirationWindow),
CreatedAt: time.Now(),
Status: Received,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions services/rfq/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const docTemplate = `{
"expiration_window": {
"type": "integer"
},
"origin_amount": {
"origin_amount_exact": {
"type": "string"
},
"origin_chain_id": {
Expand Down Expand Up @@ -511,7 +511,7 @@ const docTemplate = `{
"expiration_window": {
"type": "integer"
},
"origin_amount": {
"origin_amount_exact": {
"type": "string"
},
"origin_chain_id": {
Expand Down
18 changes: 9 additions & 9 deletions services/rfq/api/model/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ type QuoteRequest struct {

// QuoteData represents the data within a quote request.
type QuoteData struct {
OriginChainID int `json:"origin_chain_id"`
DestChainID int `json:"dest_chain_id"`
OriginTokenAddr string `json:"origin_token_addr"`
DestTokenAddr string `json:"dest_token_addr"`
OriginAmount string `json:"origin_amount"`
ExpirationWindow int64 `json:"expiration_window"`
DestAmount *string `json:"dest_amount"`
RelayerAddress *string `json:"relayer_address"`
QuoteID *string `json:"quote_id"`
OriginChainID int `json:"origin_chain_id"`
DestChainID int `json:"dest_chain_id"`
OriginTokenAddr string `json:"origin_token_addr"`
DestTokenAddr string `json:"dest_token_addr"`
OriginAmountExact string `json:"origin_amount_exact"`
ExpirationWindow int64 `json:"expiration_window"`
DestAmount *string `json:"dest_amount"`
RelayerAddress *string `json:"relayer_address"`
QuoteID *string `json:"quote_id"`
}

// WsRFQRequest represents a request for a quote to a relayer.
Expand Down
16 changes: 8 additions & 8 deletions services/rfq/api/model/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ type SubscriptionParams struct {

// GetOpenQuoteRequestsResponse represents a response to a GET /open_quote_requests request.
type GetOpenQuoteRequestsResponse struct {
UserAddress string `json:"user_address"`
OriginChainID uint64 `json:"origin_chain_id"`
OriginTokenAddr string `json:"origin_token"`
DestChainID uint64 `json:"dest_chain_id"`
DestTokenAddr string `json:"dest_token"`
OriginAmount string `json:"origin_amount"`
ExpirationWindow int `json:"expiration_window"`
CreatedAt time.Time `json:"created_at"`
UserAddress string `json:"user_address"`
OriginChainID uint64 `json:"origin_chain_id"`
OriginTokenAddr string `json:"origin_token"`
DestChainID uint64 `json:"dest_chain_id"`
DestTokenAddr string `json:"dest_token"`
OriginAmountExact string `json:"origin_amount_exact"`
ExpirationWindow int `json:"expiration_window"`
CreatedAt time.Time `json:"created_at"`
}
16 changes: 8 additions & 8 deletions services/rfq/api/rest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ func (h *Handler) GetOpenQuoteRequests(c *gin.Context) {

func dbActiveQuoteRequestToModel(dbQuote *db.ActiveQuoteRequest) *model.GetOpenQuoteRequestsResponse {
return &model.GetOpenQuoteRequestsResponse{
UserAddress: dbQuote.UserAddress,
OriginChainID: dbQuote.OriginChainID,
OriginTokenAddr: dbQuote.OriginTokenAddr,
DestChainID: dbQuote.DestChainID,
DestTokenAddr: dbQuote.DestTokenAddr,
OriginAmount: dbQuote.OriginAmount.String(),
ExpirationWindow: int(dbQuote.ExpirationWindow.Milliseconds()),
CreatedAt: dbQuote.CreatedAt,
UserAddress: dbQuote.UserAddress,
OriginChainID: dbQuote.OriginChainID,
OriginTokenAddr: dbQuote.OriginTokenAddr,
DestChainID: dbQuote.DestChainID,
DestTokenAddr: dbQuote.DestTokenAddr,
OriginAmountExact: dbQuote.OriginAmountExact.String(),
ExpirationWindow: int(dbQuote.ExpirationWindow.Milliseconds()),
CreatedAt: dbQuote.CreatedAt,
}
}

Expand Down
32 changes: 16 additions & 16 deletions services/rfq/api/rest/rfq.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ func (r *QuoterAPIServer) collectRelayerResponses(ctx context.Context, request *

func getRelayerQuoteData(request *model.PutRFQRequest, resp *model.WsRFQResponse) *model.QuoteData {
return &model.QuoteData{
OriginChainID: request.Data.OriginChainID,
DestChainID: request.Data.DestChainID,
OriginTokenAddr: request.Data.OriginTokenAddr,
DestTokenAddr: request.Data.DestTokenAddr,
OriginAmount: request.Data.OriginAmount,
DestAmount: &resp.DestAmount,
QuoteID: &resp.QuoteID,
OriginChainID: request.Data.OriginChainID,
DestChainID: request.Data.DestChainID,
OriginTokenAddr: request.Data.OriginTokenAddr,
DestTokenAddr: request.Data.DestTokenAddr,
OriginAmountExact: request.Data.OriginAmountExact,
DestAmount: &resp.DestAmount,
QuoteID: &resp.QuoteID,
}
}

Expand Down Expand Up @@ -226,9 +226,9 @@ func (r *QuoterAPIServer) handlePassiveRFQ(ctx context.Context, request *model.P
return nil, fmt.Errorf("failed to get quotes: %w", err)
}

originAmount, ok := new(big.Int).SetString(request.Data.OriginAmount, 10)
originAmount, ok := new(big.Int).SetString(request.Data.OriginAmountExact, 10)
if !ok {
return nil, errors.New("invalid origin amount")
return nil, errors.New("invalid origin amount exact")
}

var bestQuote *model.QuoteData
Expand Down Expand Up @@ -257,13 +257,13 @@ func (r *QuoterAPIServer) handlePassiveRFQ(ctx context.Context, request *model.P
destAmount := new(big.Int).Sub(rawDestAmountInt, quote.FixedFee.BigInt()).String()
//nolint:gosec
quoteData := &model.QuoteData{
OriginChainID: int(quote.OriginChainID),
DestChainID: int(quote.DestChainID),
OriginTokenAddr: quote.OriginTokenAddr,
DestTokenAddr: quote.DestTokenAddr,
OriginAmount: quote.MaxOriginAmount.String(),
DestAmount: &destAmount,
RelayerAddress: &quote.RelayerAddr,
OriginChainID: int(quote.OriginChainID),
DestChainID: int(quote.DestChainID),
OriginTokenAddr: quote.OriginTokenAddr,
DestTokenAddr: quote.DestTokenAddr,
OriginAmountExact: quote.MaxOriginAmount.String(),
DestAmount: &destAmount,
RelayerAddress: &quote.RelayerAddr,
}
bestQuote = getBestQuote(bestQuote, quoteData)
}
Expand Down
62 changes: 31 additions & 31 deletions services/rfq/api/rest/rfq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func verifyActiveQuoteRequest(c *ServerSuite, userReq *model.PutRFQRequest, acti
c.Assert().Equal(userReq.Data.OriginTokenAddr, activeQuoteRequest.OriginTokenAddr)
c.Assert().Equal(uint64(userReq.Data.DestChainID), activeQuoteRequest.DestChainID)
c.Assert().Equal(userReq.Data.DestTokenAddr, activeQuoteRequest.DestTokenAddr)
c.Assert().Equal(userReq.Data.OriginAmount, activeQuoteRequest.OriginAmount.String())
c.Assert().Equal(userReq.Data.OriginAmountExact, activeQuoteRequest.OriginAmountExact.String())
c.Assert().Equal(status, activeQuoteRequest.Status)
}

Expand All @@ -92,12 +92,12 @@ func (c *ServerSuite) TestActiveRFQSingleRelayer() {
userRequestAmount := big.NewInt(1_000_000)
userQuoteReq := &model.PutRFQRequest{
Data: model.QuoteData{
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmount: userRequestAmount.String(),
ExpirationWindow: 10_000,
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmountExact: userRequestAmount.String(),
ExpirationWindow: 10_000,
},
QuoteTypes: []string{"active"},
}
Expand Down Expand Up @@ -143,12 +143,12 @@ func (c *ServerSuite) TestActiveRFQExpiredRequest() {
userRequestAmount := big.NewInt(1_000_000)
userQuoteReq := &model.PutRFQRequest{
Data: model.QuoteData{
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmount: userRequestAmount.String(),
ExpirationWindow: 0,
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmountExact: userRequestAmount.String(),
ExpirationWindow: 0,
},
QuoteTypes: []string{"active"},
}
Expand Down Expand Up @@ -193,12 +193,12 @@ func (c *ServerSuite) TestActiveRFQMultipleRelayers() {
userRequestAmount := big.NewInt(1_000_000)
userQuoteReq := &model.PutRFQRequest{
Data: model.QuoteData{
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmount: userRequestAmount.String(),
ExpirationWindow: 10_000,
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmountExact: userRequestAmount.String(),
ExpirationWindow: 10_000,
},
QuoteTypes: []string{"active"},
}
Expand Down Expand Up @@ -276,12 +276,12 @@ func (c *ServerSuite) TestActiveRFQFallbackToPassive() {
// Prepare user quote request with 0 expiration window
userQuoteReq := &model.PutRFQRequest{
Data: model.QuoteData{
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmount: userRequestAmount.String(),
ExpirationWindow: 0,
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmountExact: userRequestAmount.String(),
ExpirationWindow: 0,
},
QuoteTypes: []string{"active", "passive"},
}
Expand Down Expand Up @@ -346,12 +346,12 @@ func (c *ServerSuite) TestActiveRFQPassiveBestQuote() {
// Prepare user quote request with 0 expiration window
userQuoteReq := &model.PutRFQRequest{
Data: model.QuoteData{
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmount: userRequestAmount.String(),
ExpirationWindow: 0,
OriginChainID: c.originChainID,
OriginTokenAddr: originTokenAddr,
DestChainID: c.destChainID,
DestTokenAddr: destTokenAddr,
OriginAmountExact: userRequestAmount.String(),
ExpirationWindow: 0,
},
QuoteTypes: []string{"active", "passive"},
}
Expand Down
36 changes: 18 additions & 18 deletions services/rfq/api/rest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,32 +209,32 @@ func (c *ServerSuite) TestGetOpenQuoteRequests() {
testRequests := []*model.PutRFQRequest{
{
Data: model.QuoteData{
OriginChainID: 1,
DestChainID: 42161,
OriginTokenAddr: "0xOriginTokenAddr",
DestTokenAddr: "0xDestTokenAddr",
OriginAmount: "100.0",
ExpirationWindow: 100,
OriginChainID: 1,
DestChainID: 42161,
OriginTokenAddr: "0xOriginTokenAddr",
DestTokenAddr: "0xDestTokenAddr",
OriginAmountExact: "100.0",
ExpirationWindow: 100,
},
},
{
Data: model.QuoteData{
OriginChainID: 1,
DestChainID: 42161,
OriginTokenAddr: "0xOriginTokenAddr",
DestTokenAddr: "0xDestTokenAddr",
OriginAmount: "100.0",
ExpirationWindow: 100,
OriginChainID: 1,
DestChainID: 42161,
OriginTokenAddr: "0xOriginTokenAddr",
DestTokenAddr: "0xDestTokenAddr",
OriginAmountExact: "100.0",
ExpirationWindow: 100,
},
},
{
Data: model.QuoteData{
OriginChainID: 1,
DestChainID: 42161,
OriginTokenAddr: "0xOriginTokenAddr",
DestTokenAddr: "0xDestTokenAddr",
OriginAmount: "100.0",
ExpirationWindow: 100,
OriginChainID: 1,
DestChainID: 42161,
OriginTokenAddr: "0xOriginTokenAddr",
DestTokenAddr: "0xDestTokenAddr",
OriginAmountExact: "100.0",
ExpirationWindow: 100,
},
},
}
Expand Down
Loading

0 comments on commit fd8ad75

Please sign in to comment.