Skip to content

Commit

Permalink
feat: add multichain fetcher.PopulateAmounts()
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Feb 25, 2024
1 parent db00ad0 commit 766989c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
50 changes: 49 additions & 1 deletion pkg/data_fetcher/data_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,16 @@ func (f *DataFetcher) PopulateAmounts(chain *configTypes.Chain, amounts amountPk
for _, amount := range amounts {
denomInfo := chain.Denoms.Find(amount.BaseDenom)
if denomInfo == nil {
continue
if !amount.IsIbcToken() {
continue
}

// For IBC denoms, try fetching the multichain denom (as in, from local chains).
if externalDenom, found := f.MaybeFetchMultichainDenom(chain, amount.BaseDenom); found {
denomInfo = externalDenom
} else {
continue
}
}

amount.ConvertDenom(denomInfo.DisplayDenom, denomInfo.DenomCoefficient)
Expand Down Expand Up @@ -184,6 +193,45 @@ func (f *DataFetcher) PopulateAmounts(chain *configTypes.Chain, amounts amountPk
}
}

func (f *DataFetcher) MaybeFetchMultichainDenom(
chain *configTypes.Chain,
denom string,
) (*configTypes.DenomInfo, bool) {
// Fetching multichain denoms (as in, denoms from chains declared locally).

// 1. Fetching remote DenomTrace from chain this transaction/message belongs to.
trace, found := f.GetDenomTrace(chain, denom)
if !found {
return nil, false
}

// 2. Split port and channel. Multi-hop transfers are not supported.
pathParsed := strings.Split(trace.Path, "/")
if len(pathParsed) != 2 {
return nil, false
}

// 3. Getting the chain-id of the denom on the chain it was minted.
originalChainId, found := f.GetIbcRemoteChainID(chain, pathParsed[1], pathParsed[0])
if !found {
return nil, false
}

// 4. Trying to find this chain by chain-id in our local config.
remoteChain, found := f.FindChainById(originalChainId)
if !found {
return nil, false
}

// 5. Trying to find the denom in our local chain config.
remoteDenom := remoteChain.Denoms.Find(trace.BaseDenom)
if !found {
return nil, false
}

return remoteDenom, true
}

func (f *DataFetcher) GetValidator(chain *configTypes.Chain, address string) (*responses.Validator, bool) {
keyName := chain.Name + "_validator_" + address

Expand Down
8 changes: 5 additions & 3 deletions pkg/filterer/filterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func (f *Filterer) GetReportableForReporters(
Subscription: subscription,
ChainSubscription: chainSubscription,
}
f.MetricsManager.LogMatchedEvent(
chainSubscription.Chain,
reportableFiltered.Type(),
subscription.Name,
)
}
}
}
Expand All @@ -94,7 +99,6 @@ func (f *Filterer) FilterForChainAndSubscription(
return nil
}

f.MetricsManager.LogMatchedEvent(chainSubscription.Chain, reportable.Type(), subscription.Name)
return reportable
}

Expand All @@ -109,7 +113,6 @@ func (f *Filterer) FilterForChainAndSubscription(
return nil
}

f.MetricsManager.LogMatchedEvent(chainSubscription.Chain, reportable.Type(), subscription.Name)
return reportable
}

Expand Down Expand Up @@ -178,7 +181,6 @@ func (f *Filterer) FilterForChainAndSubscription(
}

tx.Messages = messages
f.MetricsManager.LogMatchedEvent(chainSubscription.Chain, reportable.Type(), subscription.Name)
return tx
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/messages/msg_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func (m MsgTransfer) Type() string {
func (m *MsgTransfer) GetAdditionalData(fetcher types.DataFetcher) {
m.FetchRemoteChainData(fetcher)

fetcher.PopulateAmount(m.Chain, m.Token)

if alias := fetcher.GetAliasManager().Get(m.Chain.Name, m.Sender.Value); alias != "" {
m.Sender.Title = alias
}
Expand Down

0 comments on commit 766989c

Please sign in to comment.