Skip to content

Commit

Permalink
Feat: add TestShouldProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed Dec 20, 2023
1 parent 583da87 commit 23d2838
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions services/rfq/relayer/quoter/quoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func (m *Manager) isProfitableQuote(ctx context.Context, quote reldb.QuoteReques
return false, fmt.Errorf("error getting total fee: %w", err)
}
// NOTE: this logic assumes that the origin and destination tokens have the same price.
cost := new(big.Int).Sub(quote.Transaction.DestAmount, fee)
return quote.Transaction.OriginAmount.Cmp(cost) > 0, nil
cost := new(big.Int).Add(quote.Transaction.DestAmount, fee)
return quote.Transaction.OriginAmount.Cmp(cost) >= 0, nil
}

// SubmitAllQuotes submits all quotes to the RFQ API.
Expand Down
46 changes: 46 additions & 0 deletions services/rfq/relayer/quoter/quoter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/ethereum/go-ethereum/common"
rfqAPIClient "github.com/synapsecns/sanguine/services/rfq/api/client"
"github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge"
"github.com/synapsecns/sanguine/services/rfq/relayer/reldb"
)

func (s *QuoterSuite) TestGenerateQuotes() {
Expand All @@ -28,3 +30,47 @@ func (s *QuoterSuite) TestGenerateQuotes() {
}
s.Equal(quotes, expectedQuotes)
}

func (s *QuoterSuite) TestShouldProcess() {
// Set fee to breakeven; i.e. destAmount = originAmount - fee.
balance := big.NewInt(1000_000_000) // 1000 USDC
fee := big.NewInt(100_050_000) // 100.05 USDC
quote := reldb.QuoteRequest{
BlockNumber: 1,
OriginTokenDecimals: 6,
DestTokenDecimals: 6,
Transaction: fastbridge.IFastBridgeBridgeTransaction{
OriginChainId: s.origin,
DestChainId: s.destination,
OriginToken: common.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"),
DestToken: common.HexToAddress("0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85"),
OriginAmount: balance,
DestAmount: new(big.Int).Sub(balance, fee),
},
}
s.True(s.manager.ShouldProcess(s.GetTestContext(), quote))

// Set fee to greater than breakeven; i.e. destAmount > originAmount - fee.
quote.Transaction.DestAmount = new(big.Int).Sub(balance, new(big.Int).Mul(fee, big.NewInt(2)))
s.True(s.manager.ShouldProcess(s.GetTestContext(), quote))

// Set fee to less than breakeven; i.e. destAmount < originAmount - fee.
quote.Transaction.DestAmount = balance
s.False(s.manager.ShouldProcess(s.GetTestContext(), quote))

// Set different numbers of decimals for origin / dest tokens; should never process this.
quote = reldb.QuoteRequest{
BlockNumber: 1,
OriginTokenDecimals: 6,
DestTokenDecimals: 18,
Transaction: fastbridge.IFastBridgeBridgeTransaction{
OriginChainId: s.origin,
DestChainId: s.destination,
OriginToken: common.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"),
DestToken: common.HexToAddress("0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85"),
OriginAmount: balance,
DestAmount: new(big.Int).Sub(balance, fee),
},
}
s.False(s.manager.ShouldProcess(s.GetTestContext(), quote))
}

0 comments on commit 23d2838

Please sign in to comment.