fix: missing pool token registry bootstrapper

This commit is contained in:
2024-04-18 13:20:04 +08:00
parent 9b31b8c3e5
commit ec5dfc784a
2 changed files with 33 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/grassrootseconomics/celo-tracker/internal/chain"
"github.com/grassrootseconomics/celoutils/v2"
"github.com/grassrootseconomics/w3-celo"
"github.com/grassrootseconomics/w3-celo/module/eth"
)
type (
@@ -26,6 +27,10 @@ type (
}
)
var (
tokenRegistryFunc = w3.MustNewFunc("tokenRegistry()", "address")
)
func New(o CacheOpts) (Cache, error) {
var (
cache Cache
@@ -68,9 +73,28 @@ func New(o CacheOpts) (Cache, error) {
for _, pool := range pools {
cache.Add(pool.Hex())
var (
poolTokenRegistry common.Address
)
err := o.Chain.Provider.Client.CallCtx(
ctx,
eth.CallFunc(pool, tokenRegistryFunc).Returns(&poolTokenRegistry),
)
if err != nil {
return nil, err
}
poolTokens, err := o.Chain.GetAllTokensFromTokenIndex(ctx, poolTokenRegistry)
if err != nil {
return nil, err
}
for _, token := range poolTokens {
cache.Add(token.Hex())
}
}
}
}
o.Logg.Debug("cache bootstrap complete", "cached_addresses", cache.Size())