Skip to content

Commit d03b7b5

Browse files
committed
chore!: use single alchemy api key for all chains
1 parent 78449f1 commit d03b7b5

File tree

6 files changed

+30
-85
lines changed

6 files changed

+30
-85
lines changed

api/backend_test.go

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import (
4343
"github.com/status-im/status-go/services/typeddata"
4444
"github.com/status-im/status-go/services/wallet"
4545
walletservice "github.com/status-im/status-go/services/wallet"
46-
"github.com/status-im/status-go/services/wallet/common"
4746
"github.com/status-im/status-go/signal"
4847
"github.com/status-im/status-go/t/helpers"
4948
"github.com/status-im/status-go/t/utils"
@@ -1258,14 +1257,7 @@ func TestWalletConfigOnLoginAccount(t *testing.T) {
12581257

12591258
poktToken := fakeToken()
12601259
infuraToken := fakeToken()
1261-
alchemyEthereumMainnetToken := fakeToken()
1262-
alchemyEthereumSepoliaToken := fakeToken()
1263-
alchemyArbitrumMainnetToken := fakeToken()
1264-
alchemyArbitrumSepoliaToken := fakeToken()
1265-
alchemyOptimismMainnetToken := fakeToken()
1266-
alchemyOptimismSepoliaToken := fakeToken()
1267-
alchemyBaseMainnetToken := fakeToken()
1268-
alchemyBaseSepoliaToken := fakeToken()
1260+
alchemyAPIKey := fakeToken()
12691261
raribleMainnetAPIKey := fakeToken()
12701262
raribleTestnetAPIKey := fakeToken()
12711263

@@ -1295,18 +1287,11 @@ func TestWalletConfigOnLoginAccount(t *testing.T) {
12951287
KeyUID: newAccount.KeyUID,
12961288
Password: testPassword,
12971289
WalletSecretsConfig: requests.WalletSecretsConfig{
1298-
PoktToken: poktToken,
1299-
InfuraToken: infuraToken,
1300-
AlchemyEthereumMainnetToken: alchemyEthereumMainnetToken,
1301-
AlchemyEthereumSepoliaToken: alchemyEthereumSepoliaToken,
1302-
AlchemyArbitrumMainnetToken: alchemyArbitrumMainnetToken,
1303-
AlchemyArbitrumSepoliaToken: alchemyArbitrumSepoliaToken,
1304-
AlchemyOptimismMainnetToken: alchemyOptimismMainnetToken,
1305-
AlchemyOptimismSepoliaToken: alchemyOptimismSepoliaToken,
1306-
AlchemyBaseMainnetToken: alchemyBaseMainnetToken,
1307-
AlchemyBaseSepoliaToken: alchemyBaseSepoliaToken,
1308-
RaribleMainnetAPIKey: raribleMainnetAPIKey,
1309-
RaribleTestnetAPIKey: raribleTestnetAPIKey,
1290+
PoktToken: poktToken,
1291+
InfuraToken: infuraToken,
1292+
AlchemyAPIKey: alchemyAPIKey,
1293+
RaribleMainnetAPIKey: raribleMainnetAPIKey,
1294+
RaribleTestnetAPIKey: raribleTestnetAPIKey,
13101295
},
13111296
}
13121297

@@ -1322,14 +1307,7 @@ func TestWalletConfigOnLoginAccount(t *testing.T) {
13221307

13231308
walletConfig := testContext.backend.config.WalletConfig
13241309
require.Equal(t, walletConfig.InfuraAPIKey, infuraToken)
1325-
require.Equal(t, walletConfig.AlchemyAPIKeys[common.EthereumMainnet], alchemyEthereumMainnetToken)
1326-
require.Equal(t, walletConfig.AlchemyAPIKeys[common.EthereumSepolia], alchemyEthereumSepoliaToken)
1327-
require.Equal(t, walletConfig.AlchemyAPIKeys[common.ArbitrumMainnet], alchemyArbitrumMainnetToken)
1328-
require.Equal(t, walletConfig.AlchemyAPIKeys[common.ArbitrumSepolia], alchemyArbitrumSepoliaToken)
1329-
require.Equal(t, walletConfig.AlchemyAPIKeys[common.OptimismMainnet], alchemyOptimismMainnetToken)
1330-
require.Equal(t, walletConfig.AlchemyAPIKeys[common.OptimismSepolia], alchemyOptimismSepoliaToken)
1331-
require.Equal(t, walletConfig.AlchemyAPIKeys[common.BaseMainnet], alchemyBaseMainnetToken)
1332-
require.Equal(t, walletConfig.AlchemyAPIKeys[common.BaseSepolia], alchemyBaseSepoliaToken)
1310+
require.Equal(t, walletConfig.AlchemyAPIKey, alchemyAPIKey)
13331311
require.Equal(t, walletConfig.RaribleMainnetAPIKey, raribleMainnetAPIKey)
13341312
require.Equal(t, walletConfig.RaribleTestnetAPIKey, raribleTestnetAPIKey)
13351313

api/defaults.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/status-im/status-go/messaging"
1515
"github.com/status-im/status-go/multiaccounts/settings"
1616
"github.com/status-im/status-go/params"
17-
"github.com/status-im/status-go/pkg/security"
1817
"github.com/status-im/status-go/protocol"
1918
"github.com/status-im/status-go/protocol/identity/alias"
2019
"github.com/status-im/status-go/protocol/protobuf"
@@ -153,7 +152,6 @@ func buildWalletConfig(walletRequest *requests.WalletConfig, request *requests.W
153152
walletConfig := params.WalletConfig{
154153
Enabled: true,
155154
EnableMercuryoProvider: true,
156-
AlchemyAPIKeys: make(map[uint64]security.SensitiveString),
157155

158156
TokensListsAutoRefreshCheckInterval: walletRequest.TokensListsAutoRefreshCheckInterval,
159157
TokensListsAutoRefreshInterval: walletRequest.TokensListsAutoRefreshInterval,
@@ -183,30 +181,10 @@ func buildWalletConfig(walletRequest *requests.WalletConfig, request *requests.W
183181
walletConfig.InfuraAPIKeySecret = request.InfuraSecret
184182
}
185183

186-
if !request.AlchemyEthereumMainnetToken.Empty() {
187-
walletConfig.AlchemyAPIKeys[walletcommon.EthereumMainnet] = request.AlchemyEthereumMainnetToken
188-
}
189-
if !request.AlchemyEthereumSepoliaToken.Empty() {
190-
walletConfig.AlchemyAPIKeys[walletcommon.EthereumSepolia] = request.AlchemyEthereumSepoliaToken
191-
}
192-
if !request.AlchemyArbitrumMainnetToken.Empty() {
193-
walletConfig.AlchemyAPIKeys[walletcommon.ArbitrumMainnet] = request.AlchemyArbitrumMainnetToken
194-
}
195-
if !request.AlchemyArbitrumSepoliaToken.Empty() {
196-
walletConfig.AlchemyAPIKeys[walletcommon.ArbitrumSepolia] = request.AlchemyArbitrumSepoliaToken
197-
}
198-
if !request.AlchemyOptimismMainnetToken.Empty() {
199-
walletConfig.AlchemyAPIKeys[walletcommon.OptimismMainnet] = request.AlchemyOptimismMainnetToken
200-
}
201-
if !request.AlchemyOptimismSepoliaToken.Empty() {
202-
walletConfig.AlchemyAPIKeys[walletcommon.OptimismSepolia] = request.AlchemyOptimismSepoliaToken
203-
}
204-
if !request.AlchemyBaseMainnetToken.Empty() {
205-
walletConfig.AlchemyAPIKeys[walletcommon.BaseMainnet] = request.AlchemyBaseMainnetToken
206-
}
207-
if !request.AlchemyBaseSepoliaToken.Empty() {
208-
walletConfig.AlchemyAPIKeys[walletcommon.BaseSepolia] = request.AlchemyBaseSepoliaToken
184+
if !request.AlchemyAPIKey.Empty() {
185+
walletConfig.AlchemyAPIKey = request.AlchemyAPIKey
209186
}
187+
210188
if !request.StatusProxyMarketUser.Empty() {
211189
walletConfig.StatusProxyMarketUser = request.StatusProxyMarketUser
212190
}

params/config.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ type NodeConfig struct {
215215
// WalletConfig extra configuration for wallet.Service.
216216
type WalletConfig struct {
217217
Enabled bool
218-
OpenseaAPIKey security.SensitiveString `json:"OpenseaAPIKey"`
219-
RaribleMainnetAPIKey security.SensitiveString `json:"RaribleMainnetAPIKey"`
220-
RaribleTestnetAPIKey security.SensitiveString `json:"RaribleTestnetAPIKey"`
221-
AlchemyAPIKeys map[uint64]security.SensitiveString `json:"AlchemyAPIKeys"`
222-
InfuraAPIKey security.SensitiveString `json:"InfuraAPIKey"`
223-
InfuraAPIKeySecret security.SensitiveString `json:"InfuraAPIKeySecret"`
224-
StatusProxyMarketUser security.SensitiveString `json:"StatusProxyMarketUser"`
225-
StatusProxyMarketPassword security.SensitiveString `json:"StatusProxyMarketPassword"`
226-
MarketDataProxyConfig MarketDataProxyConfig `json:"MarketDataProxyConfig"`
218+
OpenseaAPIKey security.SensitiveString `json:"OpenseaAPIKey"`
219+
RaribleMainnetAPIKey security.SensitiveString `json:"RaribleMainnetAPIKey"`
220+
RaribleTestnetAPIKey security.SensitiveString `json:"RaribleTestnetAPIKey"`
221+
AlchemyAPIKey security.SensitiveString `json:"AlchemyAPIKey"`
222+
InfuraAPIKey security.SensitiveString `json:"InfuraAPIKey"`
223+
InfuraAPIKeySecret security.SensitiveString `json:"InfuraAPIKeySecret"`
224+
StatusProxyMarketUser security.SensitiveString `json:"StatusProxyMarketUser"`
225+
StatusProxyMarketPassword security.SensitiveString `json:"StatusProxyMarketPassword"`
226+
MarketDataProxyConfig MarketDataProxyConfig `json:"MarketDataProxyConfig"`
227227
// FIXME: remove when EthRpcProxy* is integrated
228228
StatusProxyBlockchainUser security.SensitiveString `json:"StatusProxyBlockchainUser"`
229229
StatusProxyBlockchainPassword security.SensitiveString `json:"StatusProxyBlockchainPassword"`

protocol/requests/create_account.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,7 @@ type WalletSecretsConfig struct {
102102
OpenseaAPIKey security.SensitiveString `json:"openseaApiKey"`
103103
RaribleMainnetAPIKey security.SensitiveString `json:"raribleMainnetApiKey"`
104104
RaribleTestnetAPIKey security.SensitiveString `json:"raribleTestnetApiKey"`
105-
106-
AlchemyEthereumMainnetToken security.SensitiveString `json:"alchemyEthereumMainnetToken"`
107-
AlchemyEthereumSepoliaToken security.SensitiveString `json:"alchemyEthereumSepoliaToken"`
108-
AlchemyArbitrumMainnetToken security.SensitiveString `json:"alchemyArbitrumMainnetToken"`
109-
AlchemyArbitrumSepoliaToken security.SensitiveString `json:"alchemyArbitrumSepoliaToken"`
110-
AlchemyOptimismMainnetToken security.SensitiveString `json:"alchemyOptimismMainnetToken"`
111-
AlchemyOptimismSepoliaToken security.SensitiveString `json:"alchemyOptimismSepoliaToken"`
112-
AlchemyBaseMainnetToken security.SensitiveString `json:"alchemyBaseMainnetToken"`
113-
AlchemyBaseSepoliaToken security.SensitiveString `json:"alchemyBaseSepoliaToken"`
105+
AlchemyAPIKey security.SensitiveString `json:"alchemyApiKey"`
114106

115107
StatusProxyStageName string `json:"statusProxyStageName"`
116108
StatusProxyMarketUser security.SensitiveString `json:"statusProxyMarketUser"`

services/wallet/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func NewService(
142142
openseaHTTPClient := opensea.NewHTTPClient()
143143
openseaV2Client := opensea.NewClientV2(config.WalletConfig.OpenseaAPIKey, openseaHTTPClient)
144144
raribleClient := rarible.NewClient(config.WalletConfig.RaribleMainnetAPIKey, config.WalletConfig.RaribleTestnetAPIKey)
145-
alchemyClient := alchemy.NewClient(config.WalletConfig.AlchemyAPIKeys)
145+
alchemyClient := alchemy.NewClient(config.WalletConfig.AlchemyAPIKey)
146146

147147
// Collectible providers in priority order (i.e. provider N+1 will be tried only if provider N fails)
148148
contractOwnershipProviders := []thirdparty.CollectibleContractOwnershipProvider{

services/wallet/thirdparty/collectibles/alchemy/client.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,18 @@ func getNFTBaseURL(chainID walletCommon.ChainID, apiKey security.SensitiveString
8181
type Client struct {
8282
thirdparty.CollectibleContractOwnershipProvider
8383
client *http.Client
84-
apiKeys map[uint64]security.SensitiveString
84+
apiKey security.SensitiveString
8585
connectionStatus *connection.Status
8686
}
8787

88-
func NewClient(apiKeys map[uint64]security.SensitiveString) *Client {
89-
for _, chainID := range walletCommon.AllChainIDs() {
90-
key := apiKeys[uint64(chainID)]
91-
if key.Empty() {
92-
logutils.ZapLogger().Warn("Alchemy API key not available for", zap.Stringer("chainID", chainID))
93-
}
88+
func NewClient(apiKey security.SensitiveString) *Client {
89+
if apiKey.Empty() {
90+
logutils.ZapLogger().Warn("Alchemy API key not available")
9491
}
9592

9693
return &Client{
9794
client: &http.Client{Timeout: time.Minute},
98-
apiKeys: apiKeys,
95+
apiKey: apiKey,
9996
connectionStatus: connection.NewStatus(),
10097
}
10198
}
@@ -175,7 +172,7 @@ func (o *Client) FetchCollectibleOwnersByContractAddress(ctx context.Context, ch
175172
"withTokenBalances": {"true"},
176173
}
177174

178-
baseURL, err := getNFTBaseURL(chainID, o.apiKeys[uint64(chainID)])
175+
baseURL, err := getNFTBaseURL(chainID, o.apiKey)
179176

180177
if err != nil {
181178
return nil, err
@@ -246,7 +243,7 @@ func (o *Client) fetchOwnedAssets(ctx context.Context, chainID walletCommon.Chai
246243
}
247244
assets.Provider = o.ID()
248245

249-
baseURL, err := getNFTBaseURL(chainID, o.apiKeys[uint64(chainID)])
246+
baseURL, err := getNFTBaseURL(chainID, o.apiKey)
250247

251248
if err != nil {
252249
return nil, err
@@ -328,7 +325,7 @@ func getCollectibleUniqueIDBatches(ids []thirdparty.CollectibleUniqueID) []Batch
328325
}
329326

330327
func (o *Client) fetchAssetsByBatchTokenIDs(ctx context.Context, chainID walletCommon.ChainID, batchIDs BatchTokenIDs) ([]thirdparty.FullCollectibleData, error) {
331-
baseURL, err := getNFTBaseURL(chainID, o.apiKeys[uint64(chainID)])
328+
baseURL, err := getNFTBaseURL(chainID, o.apiKey)
332329
if err != nil {
333330
return nil, err
334331
}
@@ -419,7 +416,7 @@ func getContractAddressBatches(ids []thirdparty.ContractID) []BatchContractAddre
419416
}
420417

421418
func (o *Client) fetchCollectionsDataByBatchContractAddresses(ctx context.Context, chainID walletCommon.ChainID, batchAddresses BatchContractAddresses) ([]thirdparty.CollectionData, error) {
422-
baseURL, err := getNFTBaseURL(chainID, o.apiKeys[uint64(chainID)])
419+
baseURL, err := getNFTBaseURL(chainID, o.apiKey)
423420
if err != nil {
424421
return nil, err
425422
}

0 commit comments

Comments
 (0)