@covalenthq/client-sdk 1.0.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +223 -282
- package/dist/cjs/index.d.ts +17 -20
- package/dist/cjs/index.js +2331 -7659
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/src/GoldRushClient.d.ts +20 -0
- package/dist/cjs/src/services/BalanceService.d.ts +125 -0
- package/dist/cjs/src/services/BaseService.d.ts +161 -0
- package/dist/cjs/src/services/NftService.d.ts +157 -0
- package/dist/cjs/src/services/PricingService.d.ts +25 -0
- package/dist/cjs/src/services/SecurityService.d.ts +28 -0
- package/dist/cjs/src/services/TransactionService.d.ts +128 -0
- package/dist/cjs/src/utils/functions/bigIntParser.d.ts +1 -0
- package/dist/cjs/{util/CalculatePrettyBalance.d.ts → src/utils/functions/calculatePrettyBalance.d.ts} +0 -0
- package/dist/cjs/src/utils/functions/debugOutput.d.ts +2 -0
- package/dist/cjs/src/utils/functions/endpointGenerator.d.ts +4 -0
- package/dist/cjs/src/utils/functions/execution.d.ts +11 -0
- package/dist/cjs/src/utils/functions/isValidApiKey.d.ts +1 -0
- package/dist/cjs/src/utils/functions/paginateEndpoint.d.ts +7 -0
- package/dist/cjs/src/utils/functions/prettifyCurrency.d.ts +2 -0
- package/dist/{esm/util/types/BalanceServiceTypes.d.ts → cjs/src/utils/types/BalanceService.types.d.ts} +91 -27
- package/dist/{es/util/types/BaseServiceTypes.d.ts → cjs/src/utils/types/BaseService.types.d.ts} +68 -18
- package/dist/cjs/src/utils/types/Generic.types.d.ts +477 -0
- package/dist/{esm/util/types/NftServiceTypes.d.ts → cjs/src/utils/types/NftService.types.d.ts} +53 -83
- package/dist/cjs/{util/types/PricingServiceTypes.d.ts → src/utils/types/PricingService.types.d.ts} +9 -3
- package/dist/{esm/util/types/SecurityServiceTypes.d.ts → cjs/src/utils/types/SecurityService.types.d.ts} +8 -7
- package/dist/{esm/util/types/TransactionServiceTypes.d.ts → cjs/src/utils/types/TransactionService.types.d.ts} +110 -24
- package/dist/es/index.d.ts +17 -20
- package/dist/es/index.js +2327 -7649
- package/dist/es/index.js.map +1 -1
- package/dist/es/src/GoldRushClient.d.ts +20 -0
- package/dist/es/src/services/BalanceService.d.ts +125 -0
- package/dist/es/src/services/BaseService.d.ts +161 -0
- package/dist/es/src/services/NftService.d.ts +157 -0
- package/dist/es/src/services/PricingService.d.ts +25 -0
- package/dist/es/src/services/SecurityService.d.ts +28 -0
- package/dist/es/src/services/TransactionService.d.ts +128 -0
- package/dist/es/src/utils/functions/bigIntParser.d.ts +1 -0
- package/dist/es/{util/CalculatePrettyBalance.d.ts → src/utils/functions/calculatePrettyBalance.d.ts} +0 -0
- package/dist/es/src/utils/functions/debugOutput.d.ts +2 -0
- package/dist/es/src/utils/functions/endpointGenerator.d.ts +4 -0
- package/dist/es/src/utils/functions/execution.d.ts +11 -0
- package/dist/es/src/utils/functions/isValidApiKey.d.ts +1 -0
- package/dist/es/src/utils/functions/paginateEndpoint.d.ts +7 -0
- package/dist/es/src/utils/functions/prettifyCurrency.d.ts +2 -0
- package/dist/{cjs/util/types/BalanceServiceTypes.d.ts → es/src/utils/types/BalanceService.types.d.ts} +91 -27
- package/dist/{esm/util/types/BaseServiceTypes.d.ts → es/src/utils/types/BaseService.types.d.ts} +68 -18
- package/dist/es/src/utils/types/Generic.types.d.ts +477 -0
- package/dist/{cjs/util/types/NftServiceTypes.d.ts → es/src/utils/types/NftService.types.d.ts} +53 -83
- package/dist/es/{util/types/PricingServiceTypes.d.ts → src/utils/types/PricingService.types.d.ts} +9 -3
- package/dist/{util/types/SecurityServiceTypes.d.ts → es/src/utils/types/SecurityService.types.d.ts} +8 -7
- package/dist/{cjs/util/types/TransactionServiceTypes.d.ts → es/src/utils/types/TransactionService.types.d.ts} +110 -24
- package/dist/esm/index.d.ts +17 -20
- package/dist/esm/index.js +2327 -7649
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/src/GoldRushClient.d.ts +20 -0
- package/dist/esm/src/services/BalanceService.d.ts +125 -0
- package/dist/esm/src/services/BaseService.d.ts +161 -0
- package/dist/esm/src/services/NftService.d.ts +157 -0
- package/dist/esm/src/services/PricingService.d.ts +25 -0
- package/dist/esm/src/services/SecurityService.d.ts +28 -0
- package/dist/esm/src/services/TransactionService.d.ts +128 -0
- package/dist/esm/src/utils/functions/bigIntParser.d.ts +1 -0
- package/dist/esm/{util/CalculatePrettyBalance.d.ts → src/utils/functions/calculatePrettyBalance.d.ts} +0 -0
- package/dist/esm/src/utils/functions/debugOutput.d.ts +2 -0
- package/dist/esm/src/utils/functions/endpointGenerator.d.ts +4 -0
- package/dist/esm/src/utils/functions/execution.d.ts +11 -0
- package/dist/esm/src/utils/functions/isValidApiKey.d.ts +1 -0
- package/dist/esm/src/utils/functions/paginateEndpoint.d.ts +7 -0
- package/dist/esm/src/utils/functions/prettifyCurrency.d.ts +2 -0
- package/dist/{util/types/BalanceServiceTypes.d.ts → esm/src/utils/types/BalanceService.types.d.ts} +91 -27
- package/dist/{cjs/util/types/BaseServiceTypes.d.ts → esm/src/utils/types/BaseService.types.d.ts} +68 -18
- package/dist/esm/src/utils/types/Generic.types.d.ts +477 -0
- package/dist/{util/types/NftServiceTypes.d.ts → esm/src/utils/types/NftService.types.d.ts} +53 -83
- package/dist/esm/{util/types/PricingServiceTypes.d.ts → src/utils/types/PricingService.types.d.ts} +9 -3
- package/dist/{es/util/types/SecurityServiceTypes.d.ts → esm/src/utils/types/SecurityService.types.d.ts} +8 -7
- package/dist/{util/types/TransactionServiceTypes.d.ts → esm/src/utils/types/TransactionService.types.d.ts} +110 -24
- package/package.json +25 -12
- package/dist/cjs/services/BalanceService.d.ts +0 -638
- package/dist/cjs/services/BaseService.d.ts +0 -571
- package/dist/cjs/services/CovalentClient.d.ts +0 -57
- package/dist/cjs/services/NftService.d.ts +0 -686
- package/dist/cjs/services/PricingService.d.ts +0 -103
- package/dist/cjs/services/SecurityService.d.ts +0 -162
- package/dist/cjs/services/TransactionService.d.ts +0 -711
- package/dist/cjs/services/XykService.d.ts +0 -1018
- package/dist/cjs/util/ApiHelpers.d.ts +0 -6
- package/dist/cjs/util/ApiKeyValidator.d.ts +0 -8
- package/dist/cjs/util/Chains.d.ts +0 -223
- package/dist/cjs/util/backoff.d.ts +0 -12
- package/dist/cjs/util/prettifyCurrency.d.ts +0 -2
- package/dist/cjs/util/types/GenericTypes.d.ts +0 -116
- package/dist/cjs/util/types/SecurityServiceTypes.d.ts +0 -121
- package/dist/cjs/util/types/XykServiceTypes.d.ts +0 -687
- package/dist/es/services/BalanceService.d.ts +0 -638
- package/dist/es/services/BaseService.d.ts +0 -571
- package/dist/es/services/CovalentClient.d.ts +0 -57
- package/dist/es/services/NftService.d.ts +0 -686
- package/dist/es/services/PricingService.d.ts +0 -103
- package/dist/es/services/SecurityService.d.ts +0 -162
- package/dist/es/services/TransactionService.d.ts +0 -711
- package/dist/es/services/XykService.d.ts +0 -1018
- package/dist/es/util/ApiHelpers.d.ts +0 -6
- package/dist/es/util/ApiKeyValidator.d.ts +0 -8
- package/dist/es/util/Chains.d.ts +0 -223
- package/dist/es/util/backoff.d.ts +0 -12
- package/dist/es/util/prettifyCurrency.d.ts +0 -2
- package/dist/es/util/types/BalanceServiceTypes.d.ts +0 -378
- package/dist/es/util/types/GenericTypes.d.ts +0 -116
- package/dist/es/util/types/NftServiceTypes.d.ts +0 -303
- package/dist/es/util/types/TransactionServiceTypes.d.ts +0 -388
- package/dist/es/util/types/XykServiceTypes.d.ts +0 -687
- package/dist/esm/services/BalanceService.d.ts +0 -638
- package/dist/esm/services/BaseService.d.ts +0 -571
- package/dist/esm/services/CovalentClient.d.ts +0 -57
- package/dist/esm/services/NftService.d.ts +0 -686
- package/dist/esm/services/PricingService.d.ts +0 -103
- package/dist/esm/services/SecurityService.d.ts +0 -162
- package/dist/esm/services/TransactionService.d.ts +0 -711
- package/dist/esm/services/XykService.d.ts +0 -1018
- package/dist/esm/util/ApiHelpers.d.ts +0 -6
- package/dist/esm/util/ApiKeyValidator.d.ts +0 -8
- package/dist/esm/util/Chains.d.ts +0 -223
- package/dist/esm/util/backoff.d.ts +0 -12
- package/dist/esm/util/prettifyCurrency.d.ts +0 -2
- package/dist/esm/util/types/GenericTypes.d.ts +0 -116
- package/dist/esm/util/types/XykServiceTypes.d.ts +0 -687
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -21
- package/dist/index.js.map +0 -1
- package/dist/services/BalanceService.d.ts +0 -638
- package/dist/services/BalanceService.js +0 -959
- package/dist/services/BalanceService.js.map +0 -1
- package/dist/services/BaseService.d.ts +0 -571
- package/dist/services/BaseService.js +0 -1202
- package/dist/services/BaseService.js.map +0 -1
- package/dist/services/CovalentClient.d.ts +0 -57
- package/dist/services/CovalentClient.js +0 -49
- package/dist/services/CovalentClient.js.map +0 -1
- package/dist/services/NftService.d.ts +0 -686
- package/dist/services/NftService.js +0 -1490
- package/dist/services/NftService.js.map +0 -1
- package/dist/services/PricingService.d.ts +0 -103
- package/dist/services/PricingService.js +0 -155
- package/dist/services/PricingService.js.map +0 -1
- package/dist/services/SecurityService.d.ts +0 -162
- package/dist/services/SecurityService.js +0 -249
- package/dist/services/SecurityService.js.map +0 -1
- package/dist/services/TransactionService.d.ts +0 -711
- package/dist/services/TransactionService.js +0 -1687
- package/dist/services/TransactionService.js.map +0 -1
- package/dist/services/XykService.d.ts +0 -1018
- package/dist/services/XykService.js +0 -1827
- package/dist/services/XykService.js.map +0 -1
- package/dist/util/ApiHelpers.d.ts +0 -6
- package/dist/util/ApiHelpers.js +0 -87
- package/dist/util/ApiHelpers.js.map +0 -1
- package/dist/util/ApiKeyValidator.d.ts +0 -8
- package/dist/util/ApiKeyValidator.js +0 -13
- package/dist/util/ApiKeyValidator.js.map +0 -1
- package/dist/util/CalculatePrettyBalance.d.ts +0 -1
- package/dist/util/CalculatePrettyBalance.js +0 -32
- package/dist/util/CalculatePrettyBalance.js.map +0 -1
- package/dist/util/Chains.d.ts +0 -223
- package/dist/util/Chains.js +0 -225
- package/dist/util/Chains.js.map +0 -1
- package/dist/util/backoff.d.ts +0 -12
- package/dist/util/backoff.js +0 -47
- package/dist/util/backoff.js.map +0 -1
- package/dist/util/prettifyCurrency.d.ts +0 -2
- package/dist/util/prettifyCurrency.js +0 -69
- package/dist/util/prettifyCurrency.js.map +0 -1
- package/dist/util/types/BalanceServiceTypes.js +0 -2
- package/dist/util/types/BalanceServiceTypes.js.map +0 -1
- package/dist/util/types/BaseServiceTypes.d.ts +0 -276
- package/dist/util/types/BaseServiceTypes.js +0 -2
- package/dist/util/types/BaseServiceTypes.js.map +0 -1
- package/dist/util/types/GenericTypes.d.ts +0 -116
- package/dist/util/types/GenericTypes.js +0 -2
- package/dist/util/types/GenericTypes.js.map +0 -1
- package/dist/util/types/NftServiceTypes.js +0 -2
- package/dist/util/types/NftServiceTypes.js.map +0 -1
- package/dist/util/types/PricingServiceTypes.d.ts +0 -33
- package/dist/util/types/PricingServiceTypes.js +0 -2
- package/dist/util/types/PricingServiceTypes.js.map +0 -1
- package/dist/util/types/SecurityServiceTypes.js +0 -2
- package/dist/util/types/SecurityServiceTypes.js.map +0 -1
- package/dist/util/types/TransactionServiceTypes.js +0 -2
- package/dist/util/types/TransactionServiceTypes.js.map +0 -1
- package/dist/util/types/XykServiceTypes.d.ts +0 -687
- package/dist/util/types/XykServiceTypes.js +0 -2
- package/dist/util/types/XykServiceTypes.js.map +0 -1
|
@@ -1,959 +0,0 @@
|
|
|
1
|
-
import { userAgent } from "./CovalentClient";
|
|
2
|
-
import { debugOutput, paginateEndpoint } from "../util/ApiHelpers";
|
|
3
|
-
import { parseISO } from "date-fns";
|
|
4
|
-
import { ExponentialBackoff } from "../util/backoff";
|
|
5
|
-
import pLimit from "p-limit";
|
|
6
|
-
import { ApiKeyValidator } from "../util/ApiKeyValidator";
|
|
7
|
-
class BalancesResponse {
|
|
8
|
-
constructor(data) {
|
|
9
|
-
this.address = data.address;
|
|
10
|
-
this.chain_id = data.chain_id;
|
|
11
|
-
this.chain_name = data.chain_name;
|
|
12
|
-
this.quote_currency = data.quote_currency;
|
|
13
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
14
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new BalanceItem(itemData)) : null;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
class BalanceItem {
|
|
18
|
-
constructor(data) {
|
|
19
|
-
this.contract_decimals = data.contract_decimals;
|
|
20
|
-
this.contract_name = data.contract_name;
|
|
21
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
22
|
-
this.contract_address = data.contract_address;
|
|
23
|
-
this.contract_display_name = data.contract_display_name;
|
|
24
|
-
this.supports_erc = data.supports_erc;
|
|
25
|
-
this.logo_url = data.logo_url;
|
|
26
|
-
this.last_transferred_at = data.last_transferred_at && data.last_transferred_at !== null ? parseISO(data.last_transferred_at.toString()) : null;
|
|
27
|
-
this.native_token = data.native_token;
|
|
28
|
-
this.type = data.type;
|
|
29
|
-
this.is_spam = data.is_spam;
|
|
30
|
-
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
31
|
-
this.balance_24h = data.balance_24h && data.balance_24h !== null ? BigInt(data.balance_24h) : null;
|
|
32
|
-
this.quote_rate = data.quote_rate;
|
|
33
|
-
this.quote_rate_24h = data.quote_rate_24h;
|
|
34
|
-
this.quote = data.quote;
|
|
35
|
-
this.quote_24h = data.quote_24h;
|
|
36
|
-
this.pretty_quote = data.pretty_quote;
|
|
37
|
-
this.pretty_quote_24h = data.pretty_quote_24h;
|
|
38
|
-
this.logo_urls = data.logo_urls && data.logo_urls !== null ? new LogoUrls(data.logo_urls) : null;
|
|
39
|
-
this.protocol_metadata = data.protocol_metadata && data.protocol_metadata !== null ? new ProtocolMetadata(data.protocol_metadata) : null;
|
|
40
|
-
this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new BalanceNftData(itemData)) : null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
class LogoUrls {
|
|
44
|
-
constructor(data) {
|
|
45
|
-
this.token_logo_url = data.token_logo_url;
|
|
46
|
-
this.protocol_logo_url = data.protocol_logo_url;
|
|
47
|
-
this.chain_logo_url = data.chain_logo_url;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
class ProtocolMetadata {
|
|
51
|
-
constructor(data) {
|
|
52
|
-
this.protocol_name = data.protocol_name;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
class BalanceNftData {
|
|
56
|
-
constructor(data) {
|
|
57
|
-
this.token_id = data.token_id && data.token_id !== null ? BigInt(data.token_id) : null;
|
|
58
|
-
this.token_balance = data.token_balance && data.token_balance !== null ? BigInt(data.token_balance) : null;
|
|
59
|
-
this.token_url = data.token_url;
|
|
60
|
-
this.supports_erc = data.supports_erc;
|
|
61
|
-
this.token_price_wei = data.token_price_wei && data.token_price_wei !== null ? BigInt(data.token_price_wei) : null;
|
|
62
|
-
this.token_quote_rate_eth = data.token_quote_rate_eth;
|
|
63
|
-
this.original_owner = data.original_owner;
|
|
64
|
-
this.owner = data.owner;
|
|
65
|
-
this.owner_address = data.owner_address;
|
|
66
|
-
this.burned = data.burned;
|
|
67
|
-
this.external_data = data.external_data && data.external_data !== null ? new NftExternalDataV1(data.external_data) : null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
class NftExternalDataV1 {
|
|
71
|
-
constructor(data) {
|
|
72
|
-
this.name = data.name;
|
|
73
|
-
this.description = data.description;
|
|
74
|
-
this.image = data.image;
|
|
75
|
-
this.image_256 = data.image_256;
|
|
76
|
-
this.image_512 = data.image_512;
|
|
77
|
-
this.image_1024 = data.image_1024;
|
|
78
|
-
this.animation_url = data.animation_url;
|
|
79
|
-
this.external_url = data.external_url;
|
|
80
|
-
this.owner = data.owner;
|
|
81
|
-
this.attributes = data.attributes && data.attributes !== null ? data.attributes.map((itemData) => new NftCollectionAttribute(itemData)) : null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
class NftCollectionAttribute {
|
|
85
|
-
constructor(data) {
|
|
86
|
-
this.trait_type = data.trait_type;
|
|
87
|
-
this.value = data.value;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
class PortfolioResponse {
|
|
91
|
-
constructor(data) {
|
|
92
|
-
this.address = data.address;
|
|
93
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
94
|
-
this.quote_currency = data.quote_currency;
|
|
95
|
-
this.chain_id = data.chain_id;
|
|
96
|
-
this.chain_name = data.chain_name;
|
|
97
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new PortfolioItem(itemData)) : null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
class PortfolioItem {
|
|
101
|
-
constructor(data) {
|
|
102
|
-
this.contract_address = data.contract_address;
|
|
103
|
-
this.contract_decimals = data.contract_decimals;
|
|
104
|
-
this.contract_name = data.contract_name;
|
|
105
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
106
|
-
this.logo_url = data.logo_url;
|
|
107
|
-
this.holdings = data.holdings && data.holdings !== null ? data.holdings.map((itemData) => new HoldingItem(itemData)) : null;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
class HoldingItem {
|
|
111
|
-
constructor(data) {
|
|
112
|
-
this.quote_rate = data.quote_rate;
|
|
113
|
-
this.timestamp = data.timestamp && data.timestamp !== null ? parseISO(data.timestamp.toString()) : null;
|
|
114
|
-
this.close = data.close && data.close !== null ? new OhlcItem(data.close) : null;
|
|
115
|
-
this.high = data.high && data.high !== null ? new OhlcItem(data.high) : null;
|
|
116
|
-
this.low = data.low && data.low !== null ? new OhlcItem(data.low) : null;
|
|
117
|
-
this.open = data.open && data.open !== null ? new OhlcItem(data.open) : null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
class OhlcItem {
|
|
121
|
-
constructor(data) {
|
|
122
|
-
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
123
|
-
this.quote = data.quote;
|
|
124
|
-
this.pretty_quote = data.pretty_quote;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
class Erc20TransfersResponse {
|
|
128
|
-
constructor(data) {
|
|
129
|
-
this.address = data.address;
|
|
130
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
131
|
-
this.quote_currency = data.quote_currency;
|
|
132
|
-
this.chain_id = data.chain_id;
|
|
133
|
-
this.chain_name = data.chain_name;
|
|
134
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new BlockTransactionWithContractTransfers(itemData)) : null;
|
|
135
|
-
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
class BlockTransactionWithContractTransfers {
|
|
139
|
-
constructor(data) {
|
|
140
|
-
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
|
|
141
|
-
this.block_height = data.block_height;
|
|
142
|
-
this.block_hash = data.block_hash;
|
|
143
|
-
this.tx_hash = data.tx_hash;
|
|
144
|
-
this.tx_offset = data.tx_offset;
|
|
145
|
-
this.successful = data.successful;
|
|
146
|
-
this.miner_address = data.miner_address;
|
|
147
|
-
this.from_address = data.from_address;
|
|
148
|
-
this.from_address_label = data.from_address_label;
|
|
149
|
-
this.to_address = data.to_address;
|
|
150
|
-
this.to_address_label = data.to_address_label;
|
|
151
|
-
this.value = data.value && data.value !== null ? BigInt(data.value) : null;
|
|
152
|
-
this.value_quote = data.value_quote;
|
|
153
|
-
this.pretty_value_quote = data.pretty_value_quote;
|
|
154
|
-
this.gas_offered = data.gas_offered;
|
|
155
|
-
this.gas_spent = data.gas_spent;
|
|
156
|
-
this.gas_price = data.gas_price;
|
|
157
|
-
this.fees_paid = data.fees_paid && data.fees_paid !== null ? BigInt(data.fees_paid) : null;
|
|
158
|
-
this.gas_quote = data.gas_quote;
|
|
159
|
-
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
160
|
-
this.gas_quote_rate = data.gas_quote_rate;
|
|
161
|
-
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
|
|
162
|
-
this.transfers = data.transfers && data.transfers !== null ? data.transfers.map((itemData) => new TokenTransferItem(itemData)) : null;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
class Pagination {
|
|
166
|
-
constructor(data) {
|
|
167
|
-
this.has_more = data.has_more;
|
|
168
|
-
this.page_number = data.page_number;
|
|
169
|
-
this.page_size = data.page_size;
|
|
170
|
-
this.total_count = data.total_count;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
class ContractMetadata {
|
|
174
|
-
constructor(data) {
|
|
175
|
-
this.contract_decimals = data.contract_decimals;
|
|
176
|
-
this.contract_name = data.contract_name;
|
|
177
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
178
|
-
this.contract_address = data.contract_address;
|
|
179
|
-
this.supports_erc = data.supports_erc;
|
|
180
|
-
this.logo_url = data.logo_url;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
class Explorer {
|
|
184
|
-
constructor(data) {
|
|
185
|
-
this.label = data.label;
|
|
186
|
-
this.url = data.url;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
class TokenTransferItem {
|
|
190
|
-
constructor(data) {
|
|
191
|
-
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
|
|
192
|
-
this.tx_hash = data.tx_hash;
|
|
193
|
-
this.from_address = data.from_address;
|
|
194
|
-
this.from_address_label = data.from_address_label;
|
|
195
|
-
this.to_address = data.to_address;
|
|
196
|
-
this.to_address_label = data.to_address_label;
|
|
197
|
-
this.contract_decimals = data.contract_decimals;
|
|
198
|
-
this.contract_name = data.contract_name;
|
|
199
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
200
|
-
this.contract_address = data.contract_address;
|
|
201
|
-
this.logo_url = data.logo_url;
|
|
202
|
-
this.transfer_type = data.transfer_type;
|
|
203
|
-
this.delta = data.delta && data.delta !== null ? BigInt(data.delta) : null;
|
|
204
|
-
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
205
|
-
this.quote_rate = data.quote_rate;
|
|
206
|
-
this.delta_quote = data.delta_quote;
|
|
207
|
-
this.pretty_delta_quote = data.pretty_delta_quote;
|
|
208
|
-
this.balance_quote = data.balance_quote;
|
|
209
|
-
this.method_calls = data.method_calls && data.method_calls !== null ? data.method_calls.map((itemData) => new MethodCallsForTransfers(itemData)) : null;
|
|
210
|
-
this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
class MethodCallsForTransfers {
|
|
214
|
-
constructor(data) {
|
|
215
|
-
this.sender_address = data.sender_address;
|
|
216
|
-
this.method = data.method;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
class TokenHoldersResponse {
|
|
220
|
-
constructor(data) {
|
|
221
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
222
|
-
this.chain_id = data.chain_id;
|
|
223
|
-
this.chain_name = data.chain_name;
|
|
224
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenHolder(itemData)) : null;
|
|
225
|
-
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
class TokenHolder {
|
|
229
|
-
constructor(data) {
|
|
230
|
-
this.contract_decimals = data.contract_decimals;
|
|
231
|
-
this.contract_name = data.contract_name;
|
|
232
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
233
|
-
this.contract_address = data.contract_address;
|
|
234
|
-
this.supports_erc = data.supports_erc;
|
|
235
|
-
this.logo_url = data.logo_url;
|
|
236
|
-
this.address = data.address;
|
|
237
|
-
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
238
|
-
this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
|
|
239
|
-
this.block_height = data.block_height;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
class HistoricalBalancesResponse {
|
|
243
|
-
constructor(data) {
|
|
244
|
-
this.address = data.address;
|
|
245
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
246
|
-
this.quote_currency = data.quote_currency;
|
|
247
|
-
this.chain_id = data.chain_id;
|
|
248
|
-
this.chain_name = data.chain_name;
|
|
249
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new HistoricalBalanceItem(itemData)) : null;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
class HistoricalBalanceItem {
|
|
253
|
-
constructor(data) {
|
|
254
|
-
this.contract_decimals = data.contract_decimals;
|
|
255
|
-
this.contract_name = data.contract_name;
|
|
256
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
257
|
-
this.contract_address = data.contract_address;
|
|
258
|
-
this.supports_erc = data.supports_erc;
|
|
259
|
-
this.logo_url = data.logo_url;
|
|
260
|
-
this.block_height = data.block_height;
|
|
261
|
-
this.last_transferred_block_height = data.last_transferred_block_height;
|
|
262
|
-
this.contract_display_name = data.contract_display_name;
|
|
263
|
-
this.last_transferred_at = data.last_transferred_at && data.last_transferred_at !== null ? parseISO(data.last_transferred_at.toString()) : null;
|
|
264
|
-
this.native_token = data.native_token;
|
|
265
|
-
this.type = data.type;
|
|
266
|
-
this.is_spam = data.is_spam;
|
|
267
|
-
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
268
|
-
this.quote_rate = data.quote_rate;
|
|
269
|
-
this.quote = data.quote;
|
|
270
|
-
this.pretty_quote = data.pretty_quote;
|
|
271
|
-
this.protocol_metadata = data.protocol_metadata && data.protocol_metadata !== null ? new ProtocolMetadata(data.protocol_metadata) : null;
|
|
272
|
-
this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new BalanceNftData(itemData)) : null;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
class TokenBalanceNativeResponse {
|
|
276
|
-
constructor(data) {
|
|
277
|
-
this.address = data.address;
|
|
278
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
279
|
-
this.quote_currency = data.quote_currency;
|
|
280
|
-
this.chain_id = data.chain_id;
|
|
281
|
-
this.chain_name = data.chain_name;
|
|
282
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NativeBalanceItem(itemData)) : null;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
class NativeBalanceItem {
|
|
286
|
-
constructor(data) {
|
|
287
|
-
this.contract_decimals = data.contract_decimals;
|
|
288
|
-
this.contract_name = data.contract_name;
|
|
289
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
290
|
-
this.contract_address = data.contract_address;
|
|
291
|
-
this.supports_erc = data.supports_erc;
|
|
292
|
-
this.logo_url = data.logo_url;
|
|
293
|
-
this.block_height = data.block_height;
|
|
294
|
-
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
295
|
-
this.quote_rate = data.quote_rate;
|
|
296
|
-
this.quote = data.quote;
|
|
297
|
-
this.pretty_quote = data.pretty_quote;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Balances APIs
|
|
302
|
-
*
|
|
303
|
-
*/
|
|
304
|
-
export class BalanceService {
|
|
305
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
306
|
-
this.apiKey = apiKey;
|
|
307
|
-
this.debug = debug;
|
|
308
|
-
this.threadCount = threadCount;
|
|
309
|
-
this.is_key_valid = is_key_valid;
|
|
310
|
-
this.enableRetry = enableRetry;
|
|
311
|
-
this.source = source;
|
|
312
|
-
this.LIMIT = pLimit(this.threadCount);
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
*
|
|
316
|
-
* Commonly used to fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
|
|
317
|
-
*
|
|
318
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
319
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
320
|
-
* @param {GetTokenBalancesForWalletAddressQueryParamOpts} queryParamOpts
|
|
321
|
-
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
322
|
-
* - `nft`: If `true`, NFTs will be included in the response.
|
|
323
|
-
* - `noNftFetch`: If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times.
|
|
324
|
-
* - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
325
|
-
* - `noNftAssetMetadata`: If `true`, the response shape is limited to a list of collections and token ids, omitting metadata and asset information. Helpful for faster response times and wallets holding a large number of NFTs.
|
|
326
|
-
*
|
|
327
|
-
*/
|
|
328
|
-
async getTokenBalancesForWalletAddress(chainName, walletAddress, queryParamOpts) {
|
|
329
|
-
let success = false;
|
|
330
|
-
let data;
|
|
331
|
-
let response;
|
|
332
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
333
|
-
while (!success) {
|
|
334
|
-
try {
|
|
335
|
-
const urlParams = new URLSearchParams();
|
|
336
|
-
if (!this.is_key_valid) {
|
|
337
|
-
return {
|
|
338
|
-
data: null,
|
|
339
|
-
error: true,
|
|
340
|
-
error_code: 401,
|
|
341
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
345
|
-
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
346
|
-
}
|
|
347
|
-
if (queryParamOpts?.nft !== undefined) {
|
|
348
|
-
urlParams.append("nft", queryParamOpts?.nft.toString());
|
|
349
|
-
}
|
|
350
|
-
if (queryParamOpts?.noNftFetch !== undefined) {
|
|
351
|
-
urlParams.append("no-nft-fetch", queryParamOpts?.noNftFetch.toString());
|
|
352
|
-
}
|
|
353
|
-
if (queryParamOpts?.noSpam !== undefined) {
|
|
354
|
-
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
355
|
-
}
|
|
356
|
-
if (queryParamOpts?.noNftAssetMetadata !== undefined) {
|
|
357
|
-
urlParams.append("no-nft-asset-metadata", queryParamOpts?.noNftAssetMetadata.toString());
|
|
358
|
-
}
|
|
359
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`;
|
|
360
|
-
let startTime;
|
|
361
|
-
if (this.debug) {
|
|
362
|
-
startTime = new Date();
|
|
363
|
-
}
|
|
364
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`, {
|
|
365
|
-
headers: {
|
|
366
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
367
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
368
|
-
}
|
|
369
|
-
}));
|
|
370
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
371
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
372
|
-
try {
|
|
373
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
374
|
-
}
|
|
375
|
-
catch (error) {
|
|
376
|
-
success = true;
|
|
377
|
-
return {
|
|
378
|
-
data: null,
|
|
379
|
-
error: true,
|
|
380
|
-
error_code: response.status ?? 429,
|
|
381
|
-
error_message: error.message
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
data = await response.json();
|
|
387
|
-
}
|
|
388
|
-
const dataClass = new BalancesResponse(data.data);
|
|
389
|
-
success = true;
|
|
390
|
-
return {
|
|
391
|
-
data: dataClass,
|
|
392
|
-
error: data ? data.error : true,
|
|
393
|
-
error_code: data ? data.error_code : response.status,
|
|
394
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
catch (error) {
|
|
398
|
-
success = true;
|
|
399
|
-
return {
|
|
400
|
-
data: null,
|
|
401
|
-
error: true,
|
|
402
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
403
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
*
|
|
410
|
-
* Commonly used to render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.
|
|
411
|
-
*
|
|
412
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
413
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
414
|
-
* @param {GetHistoricalPortfolioForWalletAddressQueryParamOpts} queryParamOpts
|
|
415
|
-
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
416
|
-
* - `days`: The number of days to return data for. Defaults to 30 days.
|
|
417
|
-
*
|
|
418
|
-
*/
|
|
419
|
-
async getHistoricalPortfolioForWalletAddress(chainName, walletAddress, queryParamOpts) {
|
|
420
|
-
let success = false;
|
|
421
|
-
let data;
|
|
422
|
-
let response;
|
|
423
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
424
|
-
while (!success) {
|
|
425
|
-
try {
|
|
426
|
-
const urlParams = new URLSearchParams();
|
|
427
|
-
if (!this.is_key_valid) {
|
|
428
|
-
return {
|
|
429
|
-
data: null,
|
|
430
|
-
error: true,
|
|
431
|
-
error_code: 401,
|
|
432
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
436
|
-
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
437
|
-
}
|
|
438
|
-
if (queryParamOpts?.days !== undefined) {
|
|
439
|
-
urlParams.append("days", queryParamOpts?.days.toString());
|
|
440
|
-
}
|
|
441
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`;
|
|
442
|
-
let startTime;
|
|
443
|
-
if (this.debug) {
|
|
444
|
-
startTime = new Date();
|
|
445
|
-
}
|
|
446
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`, {
|
|
447
|
-
headers: {
|
|
448
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
449
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
450
|
-
}
|
|
451
|
-
}));
|
|
452
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
453
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
454
|
-
try {
|
|
455
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
456
|
-
}
|
|
457
|
-
catch (error) {
|
|
458
|
-
success = true;
|
|
459
|
-
return {
|
|
460
|
-
data: null,
|
|
461
|
-
error: true,
|
|
462
|
-
error_code: response.status ?? 429,
|
|
463
|
-
error_message: error.message
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
else {
|
|
468
|
-
data = await response.json();
|
|
469
|
-
}
|
|
470
|
-
const dataClass = new PortfolioResponse(data.data);
|
|
471
|
-
success = true;
|
|
472
|
-
return {
|
|
473
|
-
data: dataClass,
|
|
474
|
-
error: data ? data.error : true,
|
|
475
|
-
error_code: data ? data.error_code : response.status,
|
|
476
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
catch (error) {
|
|
480
|
-
success = true;
|
|
481
|
-
return {
|
|
482
|
-
data: null,
|
|
483
|
-
error: true,
|
|
484
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
485
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
*
|
|
492
|
-
* Commonly used to render the transfer-in and transfer-out of a token along with historical prices from an address.
|
|
493
|
-
*
|
|
494
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
495
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
496
|
-
* @param {GetErc20TransfersForWalletAddressQueryParamOpts} queryParamOpts
|
|
497
|
-
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
498
|
-
* - `contractAddress`: The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
499
|
-
* - `startingBlock`: The block height to start from, defaults to `0`.
|
|
500
|
-
* - `endingBlock`: The block height to end at, defaults to current block height.
|
|
501
|
-
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
502
|
-
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
503
|
-
*
|
|
504
|
-
*/
|
|
505
|
-
async *getErc20TransfersForWalletAddress(chainName, walletAddress, queryParamOpts) {
|
|
506
|
-
let success = false;
|
|
507
|
-
let res;
|
|
508
|
-
while (!success) {
|
|
509
|
-
try {
|
|
510
|
-
const urlParams = new URLSearchParams();
|
|
511
|
-
if (!this.is_key_valid) {
|
|
512
|
-
throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
|
|
513
|
-
}
|
|
514
|
-
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
515
|
-
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
516
|
-
}
|
|
517
|
-
if (queryParamOpts?.contractAddress !== undefined) {
|
|
518
|
-
urlParams.append("contract-address", queryParamOpts?.contractAddress.toString());
|
|
519
|
-
}
|
|
520
|
-
if (queryParamOpts?.startingBlock !== undefined) {
|
|
521
|
-
urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
|
|
522
|
-
}
|
|
523
|
-
if (queryParamOpts?.endingBlock !== undefined) {
|
|
524
|
-
urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
|
|
525
|
-
}
|
|
526
|
-
if (queryParamOpts?.pageSize !== undefined) {
|
|
527
|
-
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
528
|
-
}
|
|
529
|
-
if (queryParamOpts?.pageNumber !== undefined) {
|
|
530
|
-
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
531
|
-
}
|
|
532
|
-
for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
533
|
-
yield res;
|
|
534
|
-
}
|
|
535
|
-
success = true;
|
|
536
|
-
}
|
|
537
|
-
catch (error) {
|
|
538
|
-
success = true;
|
|
539
|
-
throw new Error(error.message);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
*
|
|
545
|
-
* Commonly used to render the transfer-in and transfer-out of a token along with historical prices from an address.
|
|
546
|
-
*
|
|
547
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
548
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
549
|
-
* @param {GetErc20TransfersForWalletAddressQueryParamOpts} queryParamOpts
|
|
550
|
-
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
551
|
-
* - `contractAddress`: The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
552
|
-
* - `startingBlock`: The block height to start from, defaults to `0`.
|
|
553
|
-
* - `endingBlock`: The block height to end at, defaults to current block height.
|
|
554
|
-
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
555
|
-
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
556
|
-
*
|
|
557
|
-
*/
|
|
558
|
-
async getErc20TransfersForWalletAddressByPage(chainName, walletAddress, queryParamOpts) {
|
|
559
|
-
let success = false;
|
|
560
|
-
let data;
|
|
561
|
-
let response;
|
|
562
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
563
|
-
while (!success) {
|
|
564
|
-
try {
|
|
565
|
-
const urlParams = new URLSearchParams();
|
|
566
|
-
if (!this.is_key_valid) {
|
|
567
|
-
return {
|
|
568
|
-
data: null,
|
|
569
|
-
error: true,
|
|
570
|
-
error_code: 401,
|
|
571
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
575
|
-
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
576
|
-
}
|
|
577
|
-
if (queryParamOpts?.contractAddress !== undefined) {
|
|
578
|
-
urlParams.append("contract-address", queryParamOpts?.contractAddress.toString());
|
|
579
|
-
}
|
|
580
|
-
if (queryParamOpts?.startingBlock !== undefined) {
|
|
581
|
-
urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
|
|
582
|
-
}
|
|
583
|
-
if (queryParamOpts?.endingBlock !== undefined) {
|
|
584
|
-
urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
|
|
585
|
-
}
|
|
586
|
-
if (queryParamOpts?.pageSize !== undefined) {
|
|
587
|
-
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
588
|
-
}
|
|
589
|
-
if (queryParamOpts?.pageNumber !== undefined) {
|
|
590
|
-
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
591
|
-
}
|
|
592
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`;
|
|
593
|
-
let startTime;
|
|
594
|
-
if (this.debug) {
|
|
595
|
-
startTime = new Date();
|
|
596
|
-
}
|
|
597
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`, {
|
|
598
|
-
headers: {
|
|
599
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
600
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
601
|
-
}
|
|
602
|
-
}));
|
|
603
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
604
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
605
|
-
try {
|
|
606
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
607
|
-
}
|
|
608
|
-
catch (error) {
|
|
609
|
-
success = true;
|
|
610
|
-
return {
|
|
611
|
-
data: null,
|
|
612
|
-
error: true,
|
|
613
|
-
error_code: response.status ?? 429,
|
|
614
|
-
error_message: error.message
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
else {
|
|
619
|
-
data = await response.json();
|
|
620
|
-
}
|
|
621
|
-
const dataClass = new Erc20TransfersResponse(data.data);
|
|
622
|
-
success = true;
|
|
623
|
-
return {
|
|
624
|
-
data: dataClass,
|
|
625
|
-
error: data ? data.error : true,
|
|
626
|
-
error_code: data ? data.error_code : response.status,
|
|
627
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
catch (error) {
|
|
631
|
-
success = true;
|
|
632
|
-
return {
|
|
633
|
-
data: null,
|
|
634
|
-
error: true,
|
|
635
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
636
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
*
|
|
643
|
-
* Commonly used to get a list of all the token holders for a specified ERC20 or ERC721 token. Returns historic token holders when block-height is set (defaults to `latest`). Useful for building pie charts of token holders.
|
|
644
|
-
*
|
|
645
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
646
|
-
* @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
647
|
-
* @param {GetTokenHoldersV2ForTokenAddressQueryParamOpts} queryParamOpts
|
|
648
|
-
* - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
649
|
-
* - `pageSize`: Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100.
|
|
650
|
-
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
651
|
-
* - `date`: Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date.
|
|
652
|
-
*
|
|
653
|
-
*/
|
|
654
|
-
async *getTokenHoldersV2ForTokenAddress(chainName, tokenAddress, queryParamOpts) {
|
|
655
|
-
let success = false;
|
|
656
|
-
let res;
|
|
657
|
-
while (!success) {
|
|
658
|
-
try {
|
|
659
|
-
const urlParams = new URLSearchParams();
|
|
660
|
-
if (!this.is_key_valid) {
|
|
661
|
-
throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
|
|
662
|
-
}
|
|
663
|
-
if (queryParamOpts?.blockHeight !== undefined) {
|
|
664
|
-
urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
|
|
665
|
-
}
|
|
666
|
-
if (queryParamOpts?.pageSize !== undefined) {
|
|
667
|
-
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
668
|
-
}
|
|
669
|
-
if (queryParamOpts?.pageNumber !== undefined) {
|
|
670
|
-
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
671
|
-
}
|
|
672
|
-
if (queryParamOpts?.date !== undefined) {
|
|
673
|
-
urlParams.append("date", queryParamOpts?.date.toString());
|
|
674
|
-
}
|
|
675
|
-
for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
676
|
-
yield res;
|
|
677
|
-
}
|
|
678
|
-
success = true;
|
|
679
|
-
}
|
|
680
|
-
catch (error) {
|
|
681
|
-
success = true;
|
|
682
|
-
throw new Error(error.message);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
*
|
|
688
|
-
* Commonly used to get a list of all the token holders for a specified ERC20 or ERC721 token. Returns historic token holders when block-height is set (defaults to `latest`). Useful for building pie charts of token holders.
|
|
689
|
-
*
|
|
690
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
691
|
-
* @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
692
|
-
* @param {GetTokenHoldersV2ForTokenAddressQueryParamOpts} queryParamOpts
|
|
693
|
-
* - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
694
|
-
* - `pageSize`: Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100.
|
|
695
|
-
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
696
|
-
* - `date`: Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date.
|
|
697
|
-
*
|
|
698
|
-
*/
|
|
699
|
-
async getTokenHoldersV2ForTokenAddressByPage(chainName, tokenAddress, queryParamOpts) {
|
|
700
|
-
let success = false;
|
|
701
|
-
let data;
|
|
702
|
-
let response;
|
|
703
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
704
|
-
while (!success) {
|
|
705
|
-
try {
|
|
706
|
-
const urlParams = new URLSearchParams();
|
|
707
|
-
if (!this.is_key_valid) {
|
|
708
|
-
return {
|
|
709
|
-
data: null,
|
|
710
|
-
error: true,
|
|
711
|
-
error_code: 401,
|
|
712
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
if (queryParamOpts?.blockHeight !== undefined) {
|
|
716
|
-
urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
|
|
717
|
-
}
|
|
718
|
-
if (queryParamOpts?.pageSize !== undefined) {
|
|
719
|
-
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
720
|
-
}
|
|
721
|
-
if (queryParamOpts?.pageNumber !== undefined) {
|
|
722
|
-
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
723
|
-
}
|
|
724
|
-
if (queryParamOpts?.date !== undefined) {
|
|
725
|
-
urlParams.append("date", queryParamOpts?.date.toString());
|
|
726
|
-
}
|
|
727
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`;
|
|
728
|
-
let startTime;
|
|
729
|
-
if (this.debug) {
|
|
730
|
-
startTime = new Date();
|
|
731
|
-
}
|
|
732
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`, {
|
|
733
|
-
headers: {
|
|
734
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
735
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
736
|
-
}
|
|
737
|
-
}));
|
|
738
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
739
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
740
|
-
try {
|
|
741
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
742
|
-
}
|
|
743
|
-
catch (error) {
|
|
744
|
-
success = true;
|
|
745
|
-
return {
|
|
746
|
-
data: null,
|
|
747
|
-
error: true,
|
|
748
|
-
error_code: response.status ?? 429,
|
|
749
|
-
error_message: error.message
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
else {
|
|
754
|
-
data = await response.json();
|
|
755
|
-
}
|
|
756
|
-
const dataClass = new TokenHoldersResponse(data.data);
|
|
757
|
-
success = true;
|
|
758
|
-
return {
|
|
759
|
-
data: dataClass,
|
|
760
|
-
error: data ? data.error : true,
|
|
761
|
-
error_code: data ? data.error_code : response.status,
|
|
762
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
catch (error) {
|
|
766
|
-
success = true;
|
|
767
|
-
return {
|
|
768
|
-
data: null,
|
|
769
|
-
error: true,
|
|
770
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
771
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
/**
|
|
777
|
-
*
|
|
778
|
-
* Commonly used to fetch the historical native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address at a given block height or date. Response includes daily prices and other metadata.
|
|
779
|
-
*
|
|
780
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
781
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
782
|
-
* @param {GetHistoricalTokenBalancesForWalletAddressQueryParamOpts} queryParamOpts
|
|
783
|
-
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
784
|
-
* - `nft`: If `true`, NFTs will be included in the response.
|
|
785
|
-
* - `noNftFetch`: If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times.
|
|
786
|
-
* - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
787
|
-
* - `noNftAssetMetadata`: If `true`, the response shape is limited to a list of collections and token ids, omitting metadata and asset information. Helpful for faster response times and wallets holding a large number of NFTs.
|
|
788
|
-
* - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
789
|
-
* - `date`: Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date.
|
|
790
|
-
*
|
|
791
|
-
*/
|
|
792
|
-
async getHistoricalTokenBalancesForWalletAddress(chainName, walletAddress, queryParamOpts) {
|
|
793
|
-
let success = false;
|
|
794
|
-
let data;
|
|
795
|
-
let response;
|
|
796
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
797
|
-
while (!success) {
|
|
798
|
-
try {
|
|
799
|
-
const urlParams = new URLSearchParams();
|
|
800
|
-
if (!this.is_key_valid) {
|
|
801
|
-
return {
|
|
802
|
-
data: null,
|
|
803
|
-
error: true,
|
|
804
|
-
error_code: 401,
|
|
805
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
806
|
-
};
|
|
807
|
-
}
|
|
808
|
-
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
809
|
-
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
810
|
-
}
|
|
811
|
-
if (queryParamOpts?.nft !== undefined) {
|
|
812
|
-
urlParams.append("nft", queryParamOpts?.nft.toString());
|
|
813
|
-
}
|
|
814
|
-
if (queryParamOpts?.noNftFetch !== undefined) {
|
|
815
|
-
urlParams.append("no-nft-fetch", queryParamOpts?.noNftFetch.toString());
|
|
816
|
-
}
|
|
817
|
-
if (queryParamOpts?.noSpam !== undefined) {
|
|
818
|
-
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
819
|
-
}
|
|
820
|
-
if (queryParamOpts?.noNftAssetMetadata !== undefined) {
|
|
821
|
-
urlParams.append("no-nft-asset-metadata", queryParamOpts?.noNftAssetMetadata.toString());
|
|
822
|
-
}
|
|
823
|
-
if (queryParamOpts?.blockHeight !== undefined) {
|
|
824
|
-
urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
|
|
825
|
-
}
|
|
826
|
-
if (queryParamOpts?.date !== undefined) {
|
|
827
|
-
urlParams.append("date", queryParamOpts?.date.toString());
|
|
828
|
-
}
|
|
829
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`;
|
|
830
|
-
let startTime;
|
|
831
|
-
if (this.debug) {
|
|
832
|
-
startTime = new Date();
|
|
833
|
-
}
|
|
834
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`, {
|
|
835
|
-
headers: {
|
|
836
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
837
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
838
|
-
}
|
|
839
|
-
}));
|
|
840
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
841
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
842
|
-
try {
|
|
843
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
844
|
-
}
|
|
845
|
-
catch (error) {
|
|
846
|
-
success = true;
|
|
847
|
-
return {
|
|
848
|
-
data: null,
|
|
849
|
-
error: true,
|
|
850
|
-
error_code: response.status ?? 429,
|
|
851
|
-
error_message: error.message
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
else {
|
|
856
|
-
data = await response.json();
|
|
857
|
-
}
|
|
858
|
-
const dataClass = new HistoricalBalancesResponse(data.data);
|
|
859
|
-
success = true;
|
|
860
|
-
return {
|
|
861
|
-
data: dataClass,
|
|
862
|
-
error: data ? data.error : true,
|
|
863
|
-
error_code: data ? data.error_code : response.status,
|
|
864
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
865
|
-
};
|
|
866
|
-
}
|
|
867
|
-
catch (error) {
|
|
868
|
-
success = true;
|
|
869
|
-
return {
|
|
870
|
-
data: null,
|
|
871
|
-
error: true,
|
|
872
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
873
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
874
|
-
};
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
/**
|
|
879
|
-
*
|
|
880
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
881
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
882
|
-
* @param {GetNativeTokenBalanceQueryParamOpts} queryParamOpts
|
|
883
|
-
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
884
|
-
* - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
885
|
-
*
|
|
886
|
-
*/
|
|
887
|
-
async getNativeTokenBalance(chainName, walletAddress, queryParamOpts) {
|
|
888
|
-
let success = false;
|
|
889
|
-
let data;
|
|
890
|
-
let response;
|
|
891
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
892
|
-
while (!success) {
|
|
893
|
-
try {
|
|
894
|
-
const urlParams = new URLSearchParams();
|
|
895
|
-
if (!this.is_key_valid) {
|
|
896
|
-
return {
|
|
897
|
-
data: null,
|
|
898
|
-
error: true,
|
|
899
|
-
error_code: 401,
|
|
900
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
901
|
-
};
|
|
902
|
-
}
|
|
903
|
-
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
904
|
-
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
905
|
-
}
|
|
906
|
-
if (queryParamOpts?.blockHeight !== undefined) {
|
|
907
|
-
urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
|
|
908
|
-
}
|
|
909
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`;
|
|
910
|
-
let startTime;
|
|
911
|
-
if (this.debug) {
|
|
912
|
-
startTime = new Date();
|
|
913
|
-
}
|
|
914
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`, {
|
|
915
|
-
headers: {
|
|
916
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
917
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
918
|
-
}
|
|
919
|
-
}));
|
|
920
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
921
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
922
|
-
try {
|
|
923
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
924
|
-
}
|
|
925
|
-
catch (error) {
|
|
926
|
-
success = true;
|
|
927
|
-
return {
|
|
928
|
-
data: null,
|
|
929
|
-
error: true,
|
|
930
|
-
error_code: response.status ?? 429,
|
|
931
|
-
error_message: error.message
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
else {
|
|
936
|
-
data = await response.json();
|
|
937
|
-
}
|
|
938
|
-
const dataClass = new TokenBalanceNativeResponse(data.data);
|
|
939
|
-
success = true;
|
|
940
|
-
return {
|
|
941
|
-
data: dataClass,
|
|
942
|
-
error: data ? data.error : true,
|
|
943
|
-
error_code: data ? data.error_code : response.status,
|
|
944
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
945
|
-
};
|
|
946
|
-
}
|
|
947
|
-
catch (error) {
|
|
948
|
-
success = true;
|
|
949
|
-
return {
|
|
950
|
-
data: null,
|
|
951
|
-
error: true,
|
|
952
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
953
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
//# sourceMappingURL=BalanceService.js.map
|