synapsecns / sanguine

Synapse Monorepo
MIT License
43 stars 31 forks source link

[RFQ] Config Overhaul #1751

Open trajan0x opened 10 months ago

trajan0x commented 10 months ago

Couple of issues here we should be solving:

  1. address is currently case sensitive. You can see this in quoter.go:

    originIDPair := quote.GetOriginIDPair(): "42161-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"

    vs

    m.config.QuotableTokens[originIDPair]: ["42161-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"

    In order to get #1650 out, we're working around this by just lowercasing everything in in the config but we should make sure these are consistent. There's a chance this is a non-issue because of 2

  2. See this comment Think config needs a complete overhaul basically. I'd use getter sin more places (this could also solve 1) and deduplicate a lot of the quotable token stuff.

greptile-apps[bot] commented 5 months ago

To address the issues mentioned:

  1. Case Sensitivity: Ensure that all token addresses are consistently formatted. Modify the SanitizeTokenID function in relconfig/config.go to handle this. Use this function wherever token IDs are processed.

    // relconfig/config.go
    func SanitizeTokenID(id string) (sanitized string, err error) {
        split := strings.Split(id, tokenIDDelimiter)
        if len(split) != 2 {
            return sanitized, fmt.Errorf("invalid token ID: %s", id)
        }
        chainID, err := strconv.Atoi(split[0])
        if err != nil {
            return sanitized, fmt.Errorf("invalid chain ID: %s", split[0])
        }
        addr := common.HexToAddress(strings.ToLower(split[1]))
        sanitized = fmt.Sprintf("%d%s%s", chainID, tokenIDDelimiter, addr.Hex())
        return sanitized, nil
    }

    Use SanitizeTokenID in quoter.go:

    // quoter.go
    originIDPair, err := relconfig.SanitizeTokenID(quote.GetOriginIDPair())
    if err != nil {
        return false, fmt.Errorf("error sanitizing origin ID pair: %w", err)
    }
    destPairs := m.quotableTokens[originIDPair]
  2. Config Overhaul: Use getters in more places to deduplicate and ensure consistency. Replace direct config map accesses with getter functions in relconfig/getters.go.

    // quoter.go
    originIDPair, err := m.config.GetTokenID(quote.Transaction.OriginChainId, quote.Transaction.OriginToken.String())
    if err != nil {
        return false, fmt.Errorf("error getting origin token ID: %w", err)
    }
    destPairs, err := m.config.GetQuotableTokens(originIDPair)
    if err != nil {
        return false, fmt.Errorf("error getting quotable tokens: %w", err)
    }

    Ensure all token-related operations use these getters to maintain consistency and reduce duplication.

References

/services/rfq/relayer/quoter/quoter.go /services/rfq/relayer/relconfig/getters.go /services/rfq/relayer/relconfig/config.go

Ask Greptile