Skip to content
Draft
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
15 changes: 15 additions & 0 deletions pkg/reader/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@
return components, nil
}

func (r *ccipChainReader) GetWrappedNativeTokenPriceUSD(

Check failure on line 444 in pkg/reader/ccip.go

View workflow job for this annotation

GitHub Actions / build-lint-test

cyclomatic complexity 14 of func `(*ccipChainReader).GetWrappedNativeTokenPriceUSD` is high (> 13) (gocyclo)
ctx context.Context,
selectors []cciptypes.ChainSelector,
) map[cciptypes.ChainSelector]cciptypes.BigInt {
Expand All @@ -455,6 +455,12 @@
var wg sync.WaitGroup
var mu sync.Mutex

// GetOfframpSourceChainConfigs() will filter out the dest chain if it's included in selectors
sourceChainConfigs, err := r.configPoller.GetOfframpSourceChainConfigs(ctx, r.destChain, selectors)
if err != nil {
lggr.Errorw("failed to get offramp source chain configs from config poller", "err", err)
}

for _, chainSelector := range selectors {
// Capture loop variable
chain := chainSelector
Expand All @@ -469,6 +475,15 @@
return
}

// Only fetch native token address if this is the destination chain OR if it is an enabled source chain
sourceChainConfig, ok := sourceChainConfigs[chain]
shouldFetchNativeTokenAddress := r.destChain == chain || (ok && sourceChainConfig.IsEnabled)
if !shouldFetchNativeTokenAddress {
lggr.Debugw("skipping native token price fetch for chain", "chain", chain,
"destChain", r.destChain, "isSourceChainEnabled", ok && sourceChainConfig.IsEnabled)
return
}

config, err := r.configPoller.GetChainConfig(ctx, chain)
if err != nil {
lggr.Warnw("failed to get chain config for native token address", "chain", chain, "err", err)
Expand Down
Loading