@@ -2,6 +2,7 @@ package lanes
22
33import (
44 "fmt"
5+ "math/big"
56
67 "github.com/Masterminds/semver/v3"
78 chain_selectors "github.com/smartcontractkit/chain-selectors"
@@ -162,6 +163,10 @@ func populateAddresses(ds datastore.DataStore, chainDef *ChainDefinition, adapte
162163 if chainDef .GasPrice == nil {
163164 chainDef .GasPrice = adapter .GetDefaultGasPrice ()
164165 }
166+ if chainDef .TokenPrices == nil {
167+ populateTokenPrices (ds , chainDef , adapter )
168+ }
169+
165170 // handle v2 separately
166171 return populateAddressesV2 (ds , chainDef , adapter , version )
167172}
@@ -235,3 +240,29 @@ func populateAddressesV2(ds datastore.DataStore, chainDef *ChainDefinition, adap
235240 chainDef .DefaultOutboundCCVs = defaultOutboundCCVs
236241 return nil
237242}
243+
244+ func populateTokenPrices (ds datastore.DataStore , chainDef * ChainDefinition , adapter LaneAdapter ) {
245+ var tokenPrices map [datastore.ContractType ]* big.Int
246+ // Check if adapter implements TokenPriceProvider (optional interface)
247+ priceProvider , ok := adapter .(TokenPriceProvider )
248+ if ! ok {
249+ return
250+ }
251+
252+ // Get prices keyed by contract type
253+ tokenPrices = priceProvider .GetDefaultTokenPrices ()
254+
255+ // Resolve contract types to addresses
256+ addressPrices := make (map [string ]* big.Int )
257+ for contractType , price := range tokenPrices {
258+ refs := ds .Addresses ().Filter (
259+ datastore .AddressRefByType (contractType ),
260+ datastore .AddressRefByChainSelector (chainDef .Selector ),
261+ )
262+ for _ , ref := range refs {
263+ addressPrices [ref .Address ] = price
264+ }
265+ }
266+
267+ chainDef .TokenPrices = addressPrices
268+ }
0 commit comments