Skip to content

Commit

Permalink
feat(rfq-relayer): make QuoteWidthBps a token-level param [SLT-354] (#…
Browse files Browse the repository at this point in the history
…3305)

* Feat: make QuoteWidthBps token-level param

* [goreleaser]

* Fix: build

* [goreleaser]

* Fix: tests

* Cleanup: lint

* [goreleaser]

* [goreleaser]
  • Loading branch information
dwasse authored Oct 22, 2024
1 parent 18e6c61 commit a813e05
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 37 deletions.
2 changes: 1 addition & 1 deletion services/rfq/relayer/quoter/quoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ func (m *Manager) getDestAmount(parentCtx context.Context, originAmount *big.Int
if err != nil {
return nil, fmt.Errorf("error getting quote offset bps: %w", err)
}
quoteWidthBps, err := m.config.GetQuoteWidthBps(input.DestChainID)
quoteWidthBps, err := m.config.GetQuoteWidthBps(input.DestChainID, tokenName)
if err != nil {
return nil, fmt.Errorf("error getting quote width bps: %w", err)
}
Expand Down
9 changes: 4 additions & 5 deletions services/rfq/relayer/quoter/quoter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,12 @@ func (s *QuoterSuite) TestGetDestAmount() {
DestBalance: balance,
}
setQuoteParams := func(originQuoteOffsetBps, destQuoteOffsetBps, quoteWidthBps float64) {
s.config.BaseChainConfig.QuoteWidthBps = quoteWidthBps
tokenCfg := s.config.Chains[origin].Tokens["USDC"]
tokenCfg.QuoteOffsetBps = originQuoteOffsetBps
s.config.Chains[origin].Tokens["USDC"] = tokenCfg
tokenCfg = s.config.Chains[dest].Tokens["USDC"]
tokenCfg.QuoteOffsetBps = destQuoteOffsetBps
tokenCfg.QuoteWidthBps = quoteWidthBps
s.config.Chains[dest].Tokens["USDC"] = tokenCfg
s.manager.SetConfig(s.config)
}
Expand Down Expand Up @@ -398,12 +398,11 @@ func (s *QuoterSuite) TestGetDestAmount() {
expectedAmount = big.NewInt(960_000_000)
s.Equal(expectedAmount, destAmount)

// Set QuoteWidthBps to -100, should default to balance.
// Set QuoteWidthBps to -100, should error.
setQuoteParams(0, 0, -100)
destAmount, err = s.manager.GetDestAmount(s.GetTestContext(), balance, "USDC", input)
s.NoError(err)
expectedAmount = balance
s.Equal(expectedAmount, destAmount)
s.Error(err)
s.Nil(destAmount)

// Set origin offset to 100, should return 101% of balance.
setQuoteParams(100, 0, 0)
Expand Down
6 changes: 3 additions & 3 deletions services/rfq/relayer/relconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ type ChainConfig struct {
MinGasToken string `yaml:"min_gas_token"`
// QuotePct is the percent of balance to quote.
QuotePct *float64 `yaml:"quote_pct"`
// QuoteWidthBps is the number of basis points to deduct from the dest amount.
// Note that this parameter is applied on a chain level and must be positive.
QuoteWidthBps float64 `yaml:"quote_width_bps"`
// QuoteFixedFeeMultiplier is the multiplier for the fixed fee, applied when generating quotes.
QuoteFixedFeeMultiplier *float64 `yaml:"quote_fixed_fee_multiplier"`
// RelayFixedFeeMultiplier is the multiplier for the fixed fee, applied when relaying.
Expand Down Expand Up @@ -142,6 +139,9 @@ type TokenConfig struct {
// Note that this value can be positive or negative; if positive it effectively increases the quoted price
// of the given token, and vice versa.
QuoteOffsetBps float64 `yaml:"quote_offset_bps"`
// QuoteWidthBps is the number of basis points to deduct from the dest amount.
// Note that this parameter must be positive.
QuoteWidthBps float64 `yaml:"quote_width_bps"`
// MaxBalance is the maximum balance that should be accumulated for this token on this chain (human-readable units)
MaxBalance *string `yaml:"max_balance"`
}
Expand Down
18 changes: 0 additions & 18 deletions services/rfq/relayer/relconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestChainGetters(t *testing.T) {
L1FeeDestGasEstimate: 40000,
MinGasToken: "1000",
QuotePct: relconfig.NewFloatPtr(0),
QuoteWidthBps: 10,
QuoteFixedFeeMultiplier: relconfig.NewFloatPtr(1.1),
RebalanceConfigs: relconfig.RebalanceConfigs{
Synapse: &relconfig.SynapseCCTPRebalanceConfig{
Expand Down Expand Up @@ -60,7 +59,6 @@ func TestChainGetters(t *testing.T) {
L1FeeDestGasEstimate: 40001,
MinGasToken: "1001",
QuotePct: relconfig.NewFloatPtr(51),
QuoteWidthBps: 11,
QuoteFixedFeeMultiplier: relconfig.NewFloatPtr(1.2),
RebalanceConfigs: relconfig.RebalanceConfigs{
Synapse: &relconfig.SynapseCCTPRebalanceConfig{
Expand Down Expand Up @@ -91,7 +89,6 @@ func TestChainGetters(t *testing.T) {
L1FeeDestGasEstimate: 40000,
MinGasToken: "1000",
QuotePct: relconfig.NewFloatPtr(50),
QuoteWidthBps: 10,
QuoteFixedFeeMultiplier: relconfig.NewFloatPtr(1.1),
Tokens: map[string]relconfig.TokenConfig{
"USDC": {
Expand Down Expand Up @@ -257,20 +254,6 @@ func TestChainGetters(t *testing.T) {
assert.Equal(t, chainVal, 0.)
})

t.Run("GetQuoteWidthBps", func(t *testing.T) {
defaultVal, err := cfg.GetQuoteWidthBps(badChainID)
assert.NoError(t, err)
assert.Equal(t, defaultVal, relconfig.DefaultChainConfig.QuoteWidthBps)

baseVal, err := cfgWithBase.GetQuoteWidthBps(badChainID)
assert.NoError(t, err)
assert.Equal(t, baseVal, cfgWithBase.BaseChainConfig.QuoteWidthBps)

chainVal, err := cfgWithBase.GetQuoteWidthBps(chainID)
assert.NoError(t, err)
assert.Equal(t, chainVal, cfgWithBase.Chains[chainID].QuoteWidthBps)
})

t.Run("GetQuoteFixedFeeMultiplier", func(t *testing.T) {
defaultVal, err := cfg.GetQuoteFixedFeeMultiplier(badChainID)
assert.NoError(t, err)
Expand Down Expand Up @@ -311,7 +294,6 @@ func TestGetQuoteOffset(t *testing.T) {
L1FeeDestGasEstimate: 40000,
MinGasToken: "1000",
QuotePct: relconfig.NewFloatPtr(50),
QuoteWidthBps: 10,
QuoteFixedFeeMultiplier: relconfig.NewFloatPtr(1.1),
Tokens: map[string]relconfig.TokenConfig{
"USDC": {
Expand Down
22 changes: 12 additions & 10 deletions services/rfq/relayer/relconfig/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var DefaultChainConfig = ChainConfig{
DestGasEstimate: 100000,
MinGasToken: "100000000000000000", // 1 ETH
QuotePct: NewFloatPtr(100),
QuoteWidthBps: 0,
QuoteFixedFeeMultiplier: NewFloatPtr(1),
RelayFixedFeeMultiplier: NewFloatPtr(1),
}
Expand Down Expand Up @@ -440,20 +439,23 @@ func (c Config) GetMaxBalance(chainID int, addr common.Address) *big.Int {
}

// GetQuoteWidthBps returns the QuoteWidthBps for the given chainID.
func (c Config) GetQuoteWidthBps(chainID int) (value float64, err error) {
rawValue, err := c.getChainConfigValue(chainID, "QuoteWidthBps")
if err != nil {
return value, err
func (c Config) GetQuoteWidthBps(chainID int, tokenName string) (value float64, err error) {
chainCfg, ok := c.Chains[chainID]
if !ok {
return 0, fmt.Errorf("no chain config for chain %d", chainID)
}

value, ok := rawValue.(float64)
tokenCfg, ok := chainCfg.Tokens[tokenName]
if !ok {
return value, fmt.Errorf("failed to cast QuoteWidthBps to float")
return 0, fmt.Errorf("no token config for chain %d and token %s", chainID, tokenName)
}
if value <= 0 {
value = DefaultChainConfig.QuoteWidthBps

width := tokenCfg.QuoteWidthBps
if width < 0 {
return 0, fmt.Errorf("quote width bps must be positive: %f", width)
}
return value, nil

return width, nil
}

// GetQuoteFixedFeeMultiplier returns the QuoteFixedFeeMultiplier for the given chainID.
Expand Down

0 comments on commit a813e05

Please sign in to comment.