Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,14 @@ generate: ##@ Run generate for all given packages using go-generate-fast, fallb

generate-contracts:
go generate ./contracts

download-tokens:
go run -mod=mod ./services/wallet/token/token-lists/default-lists/downloader/main.go
echo "Downloading token lists..."; \
GOROOT=$$(go env GOROOT) GOFLAGS="-mod=mod" go run ./services/wallet/token/local-token-lists/default-lists/downloader/main.go; \
echo "token list downloaded successfully"; \

analyze-token-stores:
go run -mod=mod ./services/wallet/token/token-lists/analyzer/main.go
go run -mod=mod ./services/wallet/token/local-token-lists/analyzer/main.go

prepare-release: clean-release
mkdir -p $(RELEASE_DIR)
Expand Down
42 changes: 30 additions & 12 deletions api/protocol_adaptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/status-im/status-go/protocol/communities"
"github.com/status-im/status-go/rpc/network"
"github.com/status-im/status-go/services/wallet/token"
tokenTypes "github.com/status-im/status-go/services/wallet/token/types"
tokentypes "github.com/status-im/status-go/services/wallet/token/types"
"github.com/status-im/status-go/services/wallet/tokenbalances"
)

Expand Down Expand Up @@ -48,7 +48,7 @@ func NewCommunitiesTokenManager(tm *token.Manager) *CommunitiesTokenManager {
return &CommunitiesTokenManager{tokenManager: tm}
}

func (m *CommunitiesTokenManager) FindOrCreateTokenByAddress(ctx context.Context, chainID uint64, address gethcommon.Address) *tokenTypes.Token {
func (m *CommunitiesTokenManager) FindOrCreateTokenByAddress(ctx context.Context, chainID uint64, address gethcommon.Address) (*tokentypes.Token, error) {
return m.tokenManager.FindOrCreateTokenByAddress(ctx, chainID, address)
}

Expand All @@ -61,12 +61,18 @@ func NewCommunitiesTokenBalanceManager(f tokenbalances.FetcherIface, s tokenbala
return &CommunitiesTokenBalanceManager{tokenBalancesFetcher: f, tokenBalancesStorage: s}
}

func (m *CommunitiesTokenBalanceManager) GetBalancesByChain(ctx context.Context, accounts, tokenAddresses []gethcommon.Address, chainIDs []uint64) (communities.BalancesByChain, error) {
func (m *CommunitiesTokenBalanceManager) GetBalancesByChain(ctx context.Context, accounts []gethcommon.Address, tokens []*tokentypes.Token) (communities.BalancesByChain, error) {
if m.tokenBalancesFetcher == nil {
return nil, fmt.Errorf("tokenBalancesFetcher is nil")
}

tokenAddressesPerChain := make(map[uint64][]gethcommon.Address)
for _, token := range tokens {
tokenAddressesPerChain[token.ChainID] = append(tokenAddressesPerChain[token.ChainID], token.Address)
}

ret := make(communities.BalancesByChain)
for _, chainID := range chainIDs {
for chainID, tokenAddresses := range tokenAddressesPerChain {
ret[chainID] = make(map[gethcommon.Address]map[gethcommon.Address]*hexutil.Big)
balances, err := m.tokenBalancesFetcher.Fetch(ctx, chainID, tokenAddresses, accounts)
if err != nil {
Expand All @@ -77,19 +83,31 @@ func (m *CommunitiesTokenBalanceManager) GetBalancesByChain(ctx context.Context,
return ret, nil
}

func (m *CommunitiesTokenBalanceManager) GetCachedBalancesByChain(ctx context.Context, accounts, tokenAddresses []gethcommon.Address, chainIDs []uint64) (communities.BalancesByChain, error) {
func (m *CommunitiesTokenBalanceManager) GetCachedBalancesByChain(ctx context.Context, accounts []gethcommon.Address, tokens []*tokentypes.Token) (communities.BalancesByChain, error) {
if m.tokenBalancesStorage == nil {
return nil, fmt.Errorf("tokenBalancesStorage is nil")
}
ret := make(communities.BalancesByChain)
for _, chainID := range chainIDs {
balances, err := m.tokenBalancesStorage.GetBalances(ctx, chainID, tokenAddresses, accounts)
if err != nil {
return nil, err

balances, err := m.tokenBalancesStorage.GetBalances(ctx, tokens, accounts)
if err != nil {
return nil, err
}

return balancesPerChainToCommunitiesBalances(balances), nil
}

func balancesPerChainToCommunitiesBalances(balances map[uint64]map[gethcommon.Address]map[gethcommon.Address]*big.Int) map[uint64]map[gethcommon.Address]map[gethcommon.Address]*hexutil.Big {
ret := make(map[uint64]map[gethcommon.Address]map[gethcommon.Address]*hexutil.Big)
for chainID, tokenBalances := range balances {
ret[chainID] = make(map[gethcommon.Address]map[gethcommon.Address]*hexutil.Big)
for account, tokenBalances := range tokenBalances {
ret[chainID][account] = make(map[gethcommon.Address]*hexutil.Big)
for token, balance := range tokenBalances {
ret[chainID][account][token] = (*hexutil.Big)(balance)
}
}
ret[chainID] = balancesToCommunitiesBalances(balances)
}
return ret, nil
return ret
}

func balancesToCommunitiesBalances(balances map[gethcommon.Address]map[gethcommon.Address]*big.Int) map[gethcommon.Address]map[gethcommon.Address]*hexutil.Big {
Expand Down
Loading
Loading