@covalenthq/client-sdk 1.0.1 → 2.0.0

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.
Files changed (147) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +223 -282
  3. package/package.json +25 -12
  4. package/dist/cjs/index.d.ts +0 -20
  5. package/dist/cjs/index.js +0 -8190
  6. package/dist/cjs/index.js.map +0 -1
  7. package/dist/cjs/services/BalanceService.d.ts +0 -638
  8. package/dist/cjs/services/BaseService.d.ts +0 -571
  9. package/dist/cjs/services/CovalentClient.d.ts +0 -57
  10. package/dist/cjs/services/NftService.d.ts +0 -686
  11. package/dist/cjs/services/PricingService.d.ts +0 -103
  12. package/dist/cjs/services/SecurityService.d.ts +0 -162
  13. package/dist/cjs/services/TransactionService.d.ts +0 -711
  14. package/dist/cjs/services/XykService.d.ts +0 -1018
  15. package/dist/cjs/util/ApiHelpers.d.ts +0 -6
  16. package/dist/cjs/util/ApiKeyValidator.d.ts +0 -8
  17. package/dist/cjs/util/CalculatePrettyBalance.d.ts +0 -1
  18. package/dist/cjs/util/Chains.d.ts +0 -223
  19. package/dist/cjs/util/backoff.d.ts +0 -12
  20. package/dist/cjs/util/prettifyCurrency.d.ts +0 -2
  21. package/dist/cjs/util/types/BalanceServiceTypes.d.ts +0 -378
  22. package/dist/cjs/util/types/BaseServiceTypes.d.ts +0 -276
  23. package/dist/cjs/util/types/GenericTypes.d.ts +0 -116
  24. package/dist/cjs/util/types/NftServiceTypes.d.ts +0 -303
  25. package/dist/cjs/util/types/PricingServiceTypes.d.ts +0 -33
  26. package/dist/cjs/util/types/SecurityServiceTypes.d.ts +0 -121
  27. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +0 -388
  28. package/dist/cjs/util/types/XykServiceTypes.d.ts +0 -687
  29. package/dist/es/index.d.ts +0 -20
  30. package/dist/es/index.js +0 -8176
  31. package/dist/es/index.js.map +0 -1
  32. package/dist/es/services/BalanceService.d.ts +0 -638
  33. package/dist/es/services/BaseService.d.ts +0 -571
  34. package/dist/es/services/CovalentClient.d.ts +0 -57
  35. package/dist/es/services/NftService.d.ts +0 -686
  36. package/dist/es/services/PricingService.d.ts +0 -103
  37. package/dist/es/services/SecurityService.d.ts +0 -162
  38. package/dist/es/services/TransactionService.d.ts +0 -711
  39. package/dist/es/services/XykService.d.ts +0 -1018
  40. package/dist/es/util/ApiHelpers.d.ts +0 -6
  41. package/dist/es/util/ApiKeyValidator.d.ts +0 -8
  42. package/dist/es/util/CalculatePrettyBalance.d.ts +0 -1
  43. package/dist/es/util/Chains.d.ts +0 -223
  44. package/dist/es/util/backoff.d.ts +0 -12
  45. package/dist/es/util/prettifyCurrency.d.ts +0 -2
  46. package/dist/es/util/types/BalanceServiceTypes.d.ts +0 -378
  47. package/dist/es/util/types/BaseServiceTypes.d.ts +0 -276
  48. package/dist/es/util/types/GenericTypes.d.ts +0 -116
  49. package/dist/es/util/types/NftServiceTypes.d.ts +0 -303
  50. package/dist/es/util/types/PricingServiceTypes.d.ts +0 -33
  51. package/dist/es/util/types/SecurityServiceTypes.d.ts +0 -121
  52. package/dist/es/util/types/TransactionServiceTypes.d.ts +0 -388
  53. package/dist/es/util/types/XykServiceTypes.d.ts +0 -687
  54. package/dist/esm/index.d.ts +0 -20
  55. package/dist/esm/index.js +0 -8176
  56. package/dist/esm/index.js.map +0 -1
  57. package/dist/esm/services/BalanceService.d.ts +0 -638
  58. package/dist/esm/services/BaseService.d.ts +0 -571
  59. package/dist/esm/services/CovalentClient.d.ts +0 -57
  60. package/dist/esm/services/NftService.d.ts +0 -686
  61. package/dist/esm/services/PricingService.d.ts +0 -103
  62. package/dist/esm/services/SecurityService.d.ts +0 -162
  63. package/dist/esm/services/TransactionService.d.ts +0 -711
  64. package/dist/esm/services/XykService.d.ts +0 -1018
  65. package/dist/esm/util/ApiHelpers.d.ts +0 -6
  66. package/dist/esm/util/ApiKeyValidator.d.ts +0 -8
  67. package/dist/esm/util/CalculatePrettyBalance.d.ts +0 -1
  68. package/dist/esm/util/Chains.d.ts +0 -223
  69. package/dist/esm/util/backoff.d.ts +0 -12
  70. package/dist/esm/util/prettifyCurrency.d.ts +0 -2
  71. package/dist/esm/util/types/BalanceServiceTypes.d.ts +0 -378
  72. package/dist/esm/util/types/BaseServiceTypes.d.ts +0 -276
  73. package/dist/esm/util/types/GenericTypes.d.ts +0 -116
  74. package/dist/esm/util/types/NftServiceTypes.d.ts +0 -303
  75. package/dist/esm/util/types/PricingServiceTypes.d.ts +0 -33
  76. package/dist/esm/util/types/SecurityServiceTypes.d.ts +0 -121
  77. package/dist/esm/util/types/TransactionServiceTypes.d.ts +0 -388
  78. package/dist/esm/util/types/XykServiceTypes.d.ts +0 -687
  79. package/dist/index.d.ts +0 -20
  80. package/dist/index.js +0 -21
  81. package/dist/index.js.map +0 -1
  82. package/dist/services/BalanceService.d.ts +0 -638
  83. package/dist/services/BalanceService.js +0 -959
  84. package/dist/services/BalanceService.js.map +0 -1
  85. package/dist/services/BaseService.d.ts +0 -571
  86. package/dist/services/BaseService.js +0 -1202
  87. package/dist/services/BaseService.js.map +0 -1
  88. package/dist/services/CovalentClient.d.ts +0 -57
  89. package/dist/services/CovalentClient.js +0 -49
  90. package/dist/services/CovalentClient.js.map +0 -1
  91. package/dist/services/NftService.d.ts +0 -686
  92. package/dist/services/NftService.js +0 -1490
  93. package/dist/services/NftService.js.map +0 -1
  94. package/dist/services/PricingService.d.ts +0 -103
  95. package/dist/services/PricingService.js +0 -155
  96. package/dist/services/PricingService.js.map +0 -1
  97. package/dist/services/SecurityService.d.ts +0 -162
  98. package/dist/services/SecurityService.js +0 -249
  99. package/dist/services/SecurityService.js.map +0 -1
  100. package/dist/services/TransactionService.d.ts +0 -711
  101. package/dist/services/TransactionService.js +0 -1687
  102. package/dist/services/TransactionService.js.map +0 -1
  103. package/dist/services/XykService.d.ts +0 -1018
  104. package/dist/services/XykService.js +0 -1827
  105. package/dist/services/XykService.js.map +0 -1
  106. package/dist/util/ApiHelpers.d.ts +0 -6
  107. package/dist/util/ApiHelpers.js +0 -87
  108. package/dist/util/ApiHelpers.js.map +0 -1
  109. package/dist/util/ApiKeyValidator.d.ts +0 -8
  110. package/dist/util/ApiKeyValidator.js +0 -13
  111. package/dist/util/ApiKeyValidator.js.map +0 -1
  112. package/dist/util/CalculatePrettyBalance.d.ts +0 -1
  113. package/dist/util/CalculatePrettyBalance.js +0 -32
  114. package/dist/util/CalculatePrettyBalance.js.map +0 -1
  115. package/dist/util/Chains.d.ts +0 -223
  116. package/dist/util/Chains.js +0 -225
  117. package/dist/util/Chains.js.map +0 -1
  118. package/dist/util/backoff.d.ts +0 -12
  119. package/dist/util/backoff.js +0 -47
  120. package/dist/util/backoff.js.map +0 -1
  121. package/dist/util/prettifyCurrency.d.ts +0 -2
  122. package/dist/util/prettifyCurrency.js +0 -69
  123. package/dist/util/prettifyCurrency.js.map +0 -1
  124. package/dist/util/types/BalanceServiceTypes.d.ts +0 -378
  125. package/dist/util/types/BalanceServiceTypes.js +0 -2
  126. package/dist/util/types/BalanceServiceTypes.js.map +0 -1
  127. package/dist/util/types/BaseServiceTypes.d.ts +0 -276
  128. package/dist/util/types/BaseServiceTypes.js +0 -2
  129. package/dist/util/types/BaseServiceTypes.js.map +0 -1
  130. package/dist/util/types/GenericTypes.d.ts +0 -116
  131. package/dist/util/types/GenericTypes.js +0 -2
  132. package/dist/util/types/GenericTypes.js.map +0 -1
  133. package/dist/util/types/NftServiceTypes.d.ts +0 -303
  134. package/dist/util/types/NftServiceTypes.js +0 -2
  135. package/dist/util/types/NftServiceTypes.js.map +0 -1
  136. package/dist/util/types/PricingServiceTypes.d.ts +0 -33
  137. package/dist/util/types/PricingServiceTypes.js +0 -2
  138. package/dist/util/types/PricingServiceTypes.js.map +0 -1
  139. package/dist/util/types/SecurityServiceTypes.d.ts +0 -121
  140. package/dist/util/types/SecurityServiceTypes.js +0 -2
  141. package/dist/util/types/SecurityServiceTypes.js.map +0 -1
  142. package/dist/util/types/TransactionServiceTypes.d.ts +0 -388
  143. package/dist/util/types/TransactionServiceTypes.js +0 -2
  144. package/dist/util/types/TransactionServiceTypes.js.map +0 -1
  145. package/dist/util/types/XykServiceTypes.d.ts +0 -687
  146. package/dist/util/types/XykServiceTypes.js +0 -2
  147. package/dist/util/types/XykServiceTypes.js.map +0 -1
@@ -1,1827 +0,0 @@
1
- import { userAgent } from "./CovalentClient";
2
- import { debugOutput } 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 PoolResponse {
8
- constructor(data) {
9
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
10
- this.chain_id = data.chain_id;
11
- this.chain_name = data.chain_name;
12
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new Pool(itemData)) : null;
13
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
14
- }
15
- }
16
- class Pool {
17
- constructor(data) {
18
- this.exchange = data.exchange;
19
- this.swap_count_24h = data.swap_count_24h;
20
- this.total_liquidity_quote = data.total_liquidity_quote;
21
- this.volume_24h_quote = data.volume_24h_quote;
22
- this.fee_24h_quote = data.fee_24h_quote;
23
- this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
24
- this.quote_rate = data.quote_rate;
25
- this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
26
- this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
27
- this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
28
- this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
29
- this.chain_name = data.chain_name;
30
- this.chain_id = data.chain_id;
31
- this.dex_name = data.dex_name;
32
- this.volume_7d_quote = data.volume_7d_quote;
33
- this.annualized_fee = data.annualized_fee;
34
- this.token_0 = data.token_0 && data.token_0 !== null ? new Token(data.token_0) : null;
35
- this.token_1 = data.token_1 && data.token_1 !== null ? new Token(data.token_1) : null;
36
- }
37
- }
38
- class Pagination {
39
- constructor(data) {
40
- this.has_more = data.has_more;
41
- this.page_number = data.page_number;
42
- this.page_size = data.page_size;
43
- this.total_count = data.total_count;
44
- }
45
- }
46
- class Explorer {
47
- constructor(data) {
48
- this.label = data.label;
49
- this.url = data.url;
50
- }
51
- }
52
- class Token {
53
- constructor(data) {
54
- this.contract_address = data.contract_address;
55
- this.contract_name = data.contract_name;
56
- this.volume_in_24h = data.volume_in_24h;
57
- this.volume_out_24h = data.volume_out_24h;
58
- this.quote_rate = data.quote_rate;
59
- this.reserve = data.reserve;
60
- this.logo_url = data.logo_url;
61
- this.contract_ticker_symbol = data.contract_ticker_symbol;
62
- this.contract_decimals = data.contract_decimals;
63
- this.volume_in_7d = data.volume_in_7d;
64
- this.volume_out_7d = data.volume_out_7d;
65
- }
66
- }
67
- class PoolToDexResponse {
68
- constructor(data) {
69
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
70
- this.address = data.address;
71
- this.chain_id = data.chain_id;
72
- this.chain_name = data.chain_name;
73
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new PoolToDexItem(itemData)) : null;
74
- }
75
- }
76
- class SupportedDex {
77
- constructor(data) {
78
- this.chain_id = data.chain_id;
79
- this.chain_name = data.chain_name;
80
- this.dex_name = data.dex_name;
81
- this.display_name = data.display_name;
82
- this.logo_url = data.logo_url;
83
- this.factory_contract_address = data.factory_contract_address;
84
- this.router_contract_addresses = data.router_contract_addresses;
85
- this.swap_fee = data.swap_fee;
86
- }
87
- }
88
- class PoolToDexItem extends SupportedDex {
89
- constructor(data) {
90
- super(data);
91
- this.logo_url = data.logo_url;
92
- }
93
- }
94
- class PoolByAddressResponse {
95
- constructor(data) {
96
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
97
- this.chain_id = data.chain_id;
98
- this.chain_name = data.chain_name;
99
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new PoolWithTimeseries(itemData)) : null;
100
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
101
- }
102
- }
103
- class PoolWithTimeseries {
104
- constructor(data) {
105
- this.exchange = data.exchange;
106
- this.swap_count_24h = data.swap_count_24h;
107
- this.total_liquidity_quote = data.total_liquidity_quote;
108
- this.volume_24h_quote = data.volume_24h_quote;
109
- this.fee_24h_quote = data.fee_24h_quote;
110
- this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
111
- this.quote_rate = data.quote_rate;
112
- this.chain_id = data.chain_id;
113
- this.dex_name = data.dex_name;
114
- this.volume_7d_quote = data.volume_7d_quote;
115
- this.annualized_fee = data.annualized_fee;
116
- this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
117
- this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
118
- this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
119
- this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
120
- this.token_0_reserve_quote = data.token_0_reserve_quote;
121
- this.token_1_reserve_quote = data.token_1_reserve_quote;
122
- this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
123
- this.token_0 = data.token_0 && data.token_0 !== null ? new Token(data.token_0) : null;
124
- this.token_1 = data.token_1 && data.token_1 !== null ? new Token(data.token_1) : null;
125
- this.volume_timeseries_7d = data.volume_timeseries_7d && data.volume_timeseries_7d !== null ? data.volume_timeseries_7d.map((itemData) => new VolumeTimeseries(itemData)) : null;
126
- this.volume_timeseries_30d = data.volume_timeseries_30d && data.volume_timeseries_30d !== null ? data.volume_timeseries_30d.map((itemData) => new VolumeTimeseries(itemData)) : null;
127
- this.liquidity_timeseries_7d = data.liquidity_timeseries_7d && data.liquidity_timeseries_7d !== null ? data.liquidity_timeseries_7d.map((itemData) => new LiquidityTimeseries(itemData)) : null;
128
- this.liquidity_timeseries_30d = data.liquidity_timeseries_30d && data.liquidity_timeseries_30d !== null ? data.liquidity_timeseries_30d.map((itemData) => new LiquidityTimeseries(itemData)) : null;
129
- this.price_timeseries_7d = data.price_timeseries_7d && data.price_timeseries_7d !== null ? data.price_timeseries_7d.map((itemData) => new PriceTimeseries(itemData)) : null;
130
- this.price_timeseries_30d = data.price_timeseries_30d && data.price_timeseries_30d !== null ? data.price_timeseries_30d.map((itemData) => new PriceTimeseries(itemData)) : null;
131
- }
132
- }
133
- class VolumeTimeseries {
134
- constructor(data) {
135
- this.dex_name = data.dex_name;
136
- this.chain_id = data.chain_id;
137
- this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
138
- this.exchange = data.exchange;
139
- this.sum_amount0in = data.sum_amount0in;
140
- this.sum_amount0out = data.sum_amount0out;
141
- this.sum_amount1in = data.sum_amount1in;
142
- this.sum_amount1out = data.sum_amount1out;
143
- this.volume_quote = data.volume_quote;
144
- this.pretty_volume_quote = data.pretty_volume_quote;
145
- this.token_0_quote_rate = data.token_0_quote_rate;
146
- this.token_1_quote_rate = data.token_1_quote_rate;
147
- this.swap_count_24 = data.swap_count_24;
148
- }
149
- }
150
- class LiquidityTimeseries {
151
- constructor(data) {
152
- this.dex_name = data.dex_name;
153
- this.chain_id = data.chain_id;
154
- this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
155
- this.exchange = data.exchange;
156
- this.r0_c = data.r0_c;
157
- this.r1_c = data.r1_c;
158
- this.liquidity_quote = data.liquidity_quote;
159
- this.pretty_liquidity_quote = data.pretty_liquidity_quote;
160
- this.token_0_quote_rate = data.token_0_quote_rate;
161
- this.token_1_quote_rate = data.token_1_quote_rate;
162
- }
163
- }
164
- class PriceTimeseries {
165
- constructor(data) {
166
- this.dex_name = data.dex_name;
167
- this.chain_id = data.chain_id;
168
- this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
169
- this.exchange = data.exchange;
170
- this.price_of_token0_in_token1 = data.price_of_token0_in_token1;
171
- this.pretty_price_of_token0_in_token1 = data.pretty_price_of_token0_in_token1;
172
- this.price_of_token0_in_token1_description = data.price_of_token0_in_token1_description;
173
- this.price_of_token1_in_token0 = data.price_of_token1_in_token0;
174
- this.pretty_price_of_token1_in_token0 = data.pretty_price_of_token1_in_token0;
175
- this.price_of_token1_in_token0_description = data.price_of_token1_in_token0_description;
176
- this.quote_currency = data.quote_currency;
177
- this.price_of_token0_in_quote_currency = data.price_of_token0_in_quote_currency;
178
- this.price_of_token1_in_quote_currency = data.price_of_token1_in_quote_currency;
179
- }
180
- }
181
- class PoolsDexDataResponse {
182
- constructor(data) {
183
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
184
- this.address = data.address;
185
- this.chain_id = data.chain_id;
186
- this.chain_name = data.chain_name;
187
- this.quote_currency = data.quote_currency;
188
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new PoolsDexDataItem(itemData)) : null;
189
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
190
- }
191
- }
192
- class PoolsDexDataItem {
193
- constructor(data) {
194
- this.dex_name = data.dex_name;
195
- this.exchange = data.exchange;
196
- this.exchange_ticker_symbol = data.exchange_ticker_symbol;
197
- this.exchange_logo_url = data.exchange_logo_url;
198
- this.total_liquidity_quote = data.total_liquidity_quote;
199
- this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
200
- this.volume_24h_quote = data.volume_24h_quote;
201
- this.volume_7d_quote = data.volume_7d_quote;
202
- this.fee_24h_quote = data.fee_24h_quote;
203
- this.quote_rate = data.quote_rate;
204
- this.pretty_quote_rate = data.pretty_quote_rate;
205
- this.annualized_fee = data.annualized_fee;
206
- this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
207
- this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
208
- this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
209
- this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
210
- this.token_0 = data.token_0 && data.token_0 !== null ? new PoolsDexToken(data.token_0) : null;
211
- this.token_1 = data.token_1 && data.token_1 !== null ? new PoolsDexToken(data.token_1) : null;
212
- }
213
- }
214
- class PoolsDexToken {
215
- constructor(data) {
216
- this.reserve = data.reserve;
217
- this.contract_name = data.contract_name;
218
- this.contract_decimals = data.contract_decimals;
219
- this.contract_ticker_symbol = data.contract_ticker_symbol;
220
- this.contract_address = data.contract_address;
221
- this.logo_url = data.logo_url;
222
- this.quote_rate = data.quote_rate;
223
- }
224
- }
225
- class AddressExchangeBalancesResponse {
226
- constructor(data) {
227
- this.address = data.address;
228
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
229
- this.chain_id = data.chain_id;
230
- this.chain_name = data.chain_name;
231
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new UniswapLikeBalanceItem(itemData)) : null;
232
- }
233
- }
234
- class UniswapLikeBalanceItem {
235
- constructor(data) {
236
- this.token_0 = data.token_0 && data.token_0 !== null ? new UniswapLikeToken(data.token_0) : null;
237
- this.token_1 = data.token_1 && data.token_1 !== null ? new UniswapLikeToken(data.token_1) : null;
238
- this.pool_token = data.pool_token && data.pool_token !== null ? new UniswapLikeTokenWithSupply(data.pool_token) : null;
239
- }
240
- }
241
- class UniswapLikeToken {
242
- constructor(data) {
243
- this.contract_decimals = data.contract_decimals;
244
- this.contract_ticker_symbol = data.contract_ticker_symbol;
245
- this.contract_address = data.contract_address;
246
- this.logo_url = data.logo_url;
247
- this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
248
- this.quote = data.quote;
249
- this.pretty_quote = data.pretty_quote;
250
- this.quote_rate = data.quote_rate;
251
- }
252
- }
253
- class UniswapLikeTokenWithSupply {
254
- constructor(data) {
255
- this.contract_decimals = data.contract_decimals;
256
- this.contract_ticker_symbol = data.contract_ticker_symbol;
257
- this.contract_address = data.contract_address;
258
- this.logo_url = data.logo_url;
259
- this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
260
- this.quote = data.quote;
261
- this.pretty_quote = data.pretty_quote;
262
- this.quote_rate = data.quote_rate;
263
- this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
264
- }
265
- }
266
- class NetworkExchangeTokensResponse {
267
- constructor(data) {
268
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
269
- this.chain_id = data.chain_id;
270
- this.chain_name = data.chain_name;
271
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2Volume(itemData)) : null;
272
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
273
- }
274
- }
275
- class TokenV2Volume {
276
- constructor(data) {
277
- this.chain_name = data.chain_name;
278
- this.chain_id = data.chain_id;
279
- this.dex_name = data.dex_name;
280
- this.contract_address = data.contract_address;
281
- this.contract_name = data.contract_name;
282
- this.total_liquidity = data.total_liquidity;
283
- this.total_volume_24h = data.total_volume_24h;
284
- this.logo_url = data.logo_url;
285
- this.contract_ticker_symbol = data.contract_ticker_symbol;
286
- this.contract_decimals = data.contract_decimals;
287
- this.swap_count_24h = data.swap_count_24h;
288
- this.quote_rate = data.quote_rate;
289
- this.quote_rate_24h = data.quote_rate_24h;
290
- this.pretty_quote_rate = data.pretty_quote_rate;
291
- this.pretty_quote_rate_24h = data.pretty_quote_rate_24h;
292
- this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
293
- this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
294
- this.total_liquidity_quote = data.total_liquidity_quote;
295
- this.total_volume_24h_quote = data.total_volume_24h_quote;
296
- this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
297
- }
298
- }
299
- class NetworkExchangeTokenViewResponse {
300
- constructor(data) {
301
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
302
- this.chain_id = data.chain_id;
303
- this.chain_name = data.chain_name;
304
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2VolumeWithChartData(itemData)) : null;
305
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
306
- }
307
- }
308
- class TokenV2VolumeWithChartData {
309
- constructor(data) {
310
- this.chain_name = data.chain_name;
311
- this.chain_id = data.chain_id;
312
- this.dex_name = data.dex_name;
313
- this.contract_address = data.contract_address;
314
- this.contract_name = data.contract_name;
315
- this.total_liquidity = data.total_liquidity;
316
- this.total_volume_24h = data.total_volume_24h;
317
- this.logo_url = data.logo_url;
318
- this.contract_ticker_symbol = data.contract_ticker_symbol;
319
- this.contract_decimals = data.contract_decimals;
320
- this.swap_count_24h = data.swap_count_24h;
321
- this.quote_rate = data.quote_rate;
322
- this.quote_rate_24h = data.quote_rate_24h;
323
- this.pretty_quote_rate = data.pretty_quote_rate;
324
- this.pretty_quote_rate_24h = data.pretty_quote_rate_24h;
325
- this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
326
- this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
327
- this.total_liquidity_quote = data.total_liquidity_quote;
328
- this.total_volume_24h_quote = data.total_volume_24h_quote;
329
- this.transactions_24h = data.transactions_24h;
330
- this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
331
- this.volume_timeseries_7d = data.volume_timeseries_7d && data.volume_timeseries_7d !== null ? data.volume_timeseries_7d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
332
- this.volume_timeseries_30d = data.volume_timeseries_30d && data.volume_timeseries_30d !== null ? data.volume_timeseries_30d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
333
- this.liquidity_timeseries_7d = data.liquidity_timeseries_7d && data.liquidity_timeseries_7d !== null ? data.liquidity_timeseries_7d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
334
- this.liquidity_timeseries_30d = data.liquidity_timeseries_30d && data.liquidity_timeseries_30d !== null ? data.liquidity_timeseries_30d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
335
- this.price_timeseries_7d = data.price_timeseries_7d && data.price_timeseries_7d !== null ? data.price_timeseries_7d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
336
- this.price_timeseries_30d = data.price_timeseries_30d && data.price_timeseries_30d !== null ? data.price_timeseries_30d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
337
- }
338
- }
339
- class VolumeTokenTimeseries {
340
- constructor(data) {
341
- this.dex_name = data.dex_name;
342
- this.chain_id = data.chain_id;
343
- this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
344
- this.total_volume = data.total_volume;
345
- this.volume_quote = data.volume_quote;
346
- this.pretty_volume_quote = data.pretty_volume_quote;
347
- }
348
- }
349
- class LiquidityTokenTimeseries {
350
- constructor(data) {
351
- this.dex_name = data.dex_name;
352
- this.chain_id = data.chain_id;
353
- this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
354
- this.total_liquidity = data.total_liquidity;
355
- this.liquidity_quote = data.liquidity_quote;
356
- this.pretty_liquidity_quote = data.pretty_liquidity_quote;
357
- }
358
- }
359
- class PriceTokenTimeseries {
360
- constructor(data) {
361
- this.dex_name = data.dex_name;
362
- this.chain_id = data.chain_id;
363
- this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
364
- this.quote_currency = data.quote_currency;
365
- this.quote_rate = data.quote_rate;
366
- this.pretty_quote_rate = data.pretty_quote_rate;
367
- }
368
- }
369
- class SupportedDexesResponse {
370
- constructor(data) {
371
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
372
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new SupportedDex(itemData)) : null;
373
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
374
- }
375
- }
376
- class SingleNetworkExchangeTokenResponse {
377
- constructor(data) {
378
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
379
- this.chain_id = data.chain_id;
380
- this.chain_name = data.chain_name;
381
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new PoolWithTimeseries(itemData)) : null;
382
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
383
- }
384
- }
385
- class TransactionsForAccountAddressResponse {
386
- constructor(data) {
387
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
388
- this.chain_id = data.chain_id;
389
- this.chain_name = data.chain_name;
390
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
391
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
392
- }
393
- }
394
- class ExchangeTransaction {
395
- constructor(data) {
396
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
397
- this.tx_hash = data.tx_hash;
398
- this.act = data.act;
399
- this.address = data.address;
400
- this.amount_0 = data.amount_0;
401
- this.amount_1 = data.amount_1;
402
- this.amount_0_in = data.amount_0_in;
403
- this.amount_0_out = data.amount_0_out;
404
- this.amount_1_in = data.amount_1_in;
405
- this.amount_1_out = data.amount_1_out;
406
- this.to_address = data.to_address;
407
- this.from_address = data.from_address;
408
- this.sender_address = data.sender_address;
409
- this.total_quote = data.total_quote;
410
- this.pretty_total_quote = data.pretty_total_quote;
411
- this.value = data.value && data.value !== null ? BigInt(data.value) : null;
412
- this.value_quote = data.value_quote;
413
- this.pretty_value_quote = data.pretty_value_quote;
414
- this.gas_offered = data.gas_offered;
415
- this.gas_spent = data.gas_spent;
416
- this.gas_price = data.gas_price;
417
- this.fees_paid = data.fees_paid && data.fees_paid !== null ? BigInt(data.fees_paid) : null;
418
- this.gas_quote = data.gas_quote;
419
- this.pretty_gas_quote = data.pretty_gas_quote;
420
- this.gas_quote_rate = data.gas_quote_rate;
421
- this.quote_currency = data.quote_currency;
422
- this.token_0_quote_rate = data.token_0_quote_rate;
423
- this.token_1_quote_rate = data.token_1_quote_rate;
424
- this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
425
- this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
426
- this.token_0 = data.token_0 && data.token_0 !== null ? new PoolToken(data.token_0) : null;
427
- this.token_1 = data.token_1 && data.token_1 !== null ? new PoolToken(data.token_1) : null;
428
- }
429
- }
430
- class ContractMetadata {
431
- constructor(data) {
432
- this.contract_decimals = data.contract_decimals;
433
- this.contract_name = data.contract_name;
434
- this.contract_ticker_symbol = data.contract_ticker_symbol;
435
- this.contract_address = data.contract_address;
436
- this.supports_erc = data.supports_erc;
437
- this.logo_url = data.logo_url;
438
- }
439
- }
440
- class PoolToken {
441
- constructor(data) {
442
- this.contract_decimals = data.contract_decimals;
443
- this.contract_name = data.contract_name;
444
- this.contract_ticker_symbol = data.contract_ticker_symbol;
445
- this.contract_address = data.contract_address;
446
- this.supports_erc = data.supports_erc;
447
- this.logo_url = data.logo_url;
448
- }
449
- }
450
- class TransactionsForTokenAddressResponse {
451
- constructor(data) {
452
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
453
- this.chain_id = data.chain_id;
454
- this.chain_name = data.chain_name;
455
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
456
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
457
- }
458
- }
459
- class TransactionsForExchangeResponse {
460
- constructor(data) {
461
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
462
- this.chain_id = data.chain_id;
463
- this.chain_name = data.chain_name;
464
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
465
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
466
- }
467
- }
468
- class NetworkTransactionsResponse {
469
- constructor(data) {
470
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
471
- this.chain_id = data.chain_id;
472
- this.chain_name = data.chain_name;
473
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
474
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
475
- }
476
- }
477
- class EcosystemChartDataResponse {
478
- constructor(data) {
479
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
480
- this.chain_id = data.chain_id;
481
- this.chain_name = data.chain_name;
482
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new UniswapLikeEcosystemCharts(itemData)) : null;
483
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
484
- }
485
- }
486
- class UniswapLikeEcosystemCharts {
487
- constructor(data) {
488
- this.dex_name = data.dex_name;
489
- this.chain_id = data.chain_id;
490
- this.quote_currency = data.quote_currency;
491
- this.gas_token_price_quote = data.gas_token_price_quote;
492
- this.total_swaps_24h = data.total_swaps_24h;
493
- this.total_active_pairs_7d = data.total_active_pairs_7d;
494
- this.total_fees_24h = data.total_fees_24h;
495
- this.pretty_gas_token_price_quote = data.pretty_gas_token_price_quote;
496
- this.pretty_total_fees_24h = data.pretty_total_fees_24h;
497
- this.volume_chart_7d = data.volume_chart_7d && data.volume_chart_7d !== null ? data.volume_chart_7d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
498
- this.volume_chart_30d = data.volume_chart_30d && data.volume_chart_30d !== null ? data.volume_chart_30d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
499
- this.liquidity_chart_7d = data.liquidity_chart_7d && data.liquidity_chart_7d !== null ? data.liquidity_chart_7d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
500
- this.liquidity_chart_30d = data.liquidity_chart_30d && data.liquidity_chart_30d !== null ? data.liquidity_chart_30d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
501
- }
502
- }
503
- class VolumeEcosystemChart {
504
- constructor(data) {
505
- this.dex_name = data.dex_name;
506
- this.chain_id = data.chain_id;
507
- this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
508
- this.quote_currency = data.quote_currency;
509
- this.volume_quote = data.volume_quote;
510
- this.pretty_volume_quote = data.pretty_volume_quote;
511
- this.swap_count_24 = data.swap_count_24;
512
- }
513
- }
514
- class LiquidityEcosystemChart {
515
- constructor(data) {
516
- this.dex_name = data.dex_name;
517
- this.chain_id = data.chain_id;
518
- this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
519
- this.quote_currency = data.quote_currency;
520
- this.liquidity_quote = data.liquidity_quote;
521
- this.pretty_liquidity_quote = data.pretty_liquidity_quote;
522
- }
523
- }
524
- class HealthDataResponse {
525
- constructor(data) {
526
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
527
- this.chain_id = data.chain_id;
528
- this.chain_name = data.chain_name;
529
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new HealthData(itemData)) : null;
530
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
531
- }
532
- }
533
- class HealthData {
534
- constructor(data) {
535
- this.synced_block_height = data.synced_block_height;
536
- this.synced_block_signed_at = data.synced_block_signed_at && data.synced_block_signed_at !== null ? parseISO(data.synced_block_signed_at.toString()) : null;
537
- this.latest_block_height = data.latest_block_height;
538
- this.latest_block_signed_at = data.latest_block_signed_at && data.latest_block_signed_at !== null ? parseISO(data.latest_block_signed_at.toString()) : null;
539
- }
540
- }
541
- /**
542
- * XYK APIs
543
- *
544
- */
545
- export class XykService {
546
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
547
- this.apiKey = apiKey;
548
- this.debug = debug;
549
- this.threadCount = threadCount;
550
- this.is_key_valid = is_key_valid;
551
- this.enableRetry = enableRetry;
552
- this.source = source;
553
- this.LIMIT = pLimit(this.threadCount);
554
- }
555
- /**
556
- *
557
- * Commonly used to get all the pools of a particular DEX. Supports most common DEXs (Uniswap, SushiSwap, etc), and returns detailed trading data (volume, liquidity, swap counts, fees, LP token prices).
558
- *
559
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
560
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
561
- * @param {GetPoolsQueryParamOpts} queryParamOpts
562
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
563
- * - `pageNumber`: 0-indexed page number to begin pagination.
564
- *
565
- */
566
- async getPools(chainName, dexName, queryParamOpts) {
567
- let success = false;
568
- let data;
569
- let response;
570
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
571
- while (!success) {
572
- try {
573
- const urlParams = new URLSearchParams();
574
- if (queryParamOpts?.date !== undefined) {
575
- urlParams.append("date", queryParamOpts?.date.toString());
576
- }
577
- if (queryParamOpts?.pageSize !== undefined) {
578
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
579
- }
580
- if (queryParamOpts?.pageNumber !== undefined) {
581
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
582
- }
583
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`;
584
- if (!this.is_key_valid) {
585
- return {
586
- data: null,
587
- error: true,
588
- error_code: 401,
589
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
590
- };
591
- }
592
- let startTime;
593
- if (this.debug) {
594
- startTime = new Date();
595
- }
596
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`, {
597
- headers: {
598
- "Authorization": `Bearer ${this.apiKey}`,
599
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
600
- }
601
- }));
602
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
603
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
604
- try {
605
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
606
- }
607
- catch (error) {
608
- success = true;
609
- return {
610
- data: null,
611
- error: true,
612
- error_code: response.status ?? 429,
613
- error_message: error.message
614
- };
615
- }
616
- }
617
- else {
618
- data = await response.json();
619
- }
620
- const dataClass = new PoolResponse(data.data);
621
- success = true;
622
- return {
623
- data: dataClass,
624
- error: data ? data.error : true,
625
- error_code: data ? data.error_code : response.status,
626
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
627
- };
628
- }
629
- catch (error) {
630
- success = true;
631
- return {
632
- data: null,
633
- error: true,
634
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
635
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
636
- };
637
- }
638
- }
639
- }
640
- /**
641
- *
642
- * Commonly used to get the corresponding supported DEX given a pool address, along with the swap fees, DEX's logo url, and factory addresses. Useful to identifying the specific DEX to which a pair address is associated.
643
- *
644
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
645
- * @param {string} poolAddress - The requested pool address.
646
- *
647
- */
648
- async getDexForPoolAddress(chainName, poolAddress) {
649
- let success = false;
650
- let data;
651
- let response;
652
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
653
- while (!success) {
654
- try {
655
- const urlParams = new URLSearchParams();
656
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`;
657
- if (!this.is_key_valid) {
658
- return {
659
- data: null,
660
- error: true,
661
- error_code: 401,
662
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
663
- };
664
- }
665
- let startTime;
666
- if (this.debug) {
667
- startTime = new Date();
668
- }
669
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`, {
670
- headers: {
671
- "Authorization": `Bearer ${this.apiKey}`,
672
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
673
- }
674
- }));
675
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
676
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
677
- try {
678
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
679
- }
680
- catch (error) {
681
- success = true;
682
- return {
683
- data: null,
684
- error: true,
685
- error_code: response.status ?? 429,
686
- error_message: error.message
687
- };
688
- }
689
- }
690
- else {
691
- data = await response.json();
692
- }
693
- const dataClass = new PoolToDexResponse(data.data);
694
- success = true;
695
- return {
696
- data: dataClass,
697
- error: data ? data.error : true,
698
- error_code: data ? data.error_code : response.status,
699
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
700
- };
701
- }
702
- catch (error) {
703
- success = true;
704
- return {
705
- data: null,
706
- error: true,
707
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
708
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
709
- };
710
- }
711
- }
712
- }
713
- /**
714
- *
715
- * Commonly used to get the 7 day and 30 day time-series data (volume, liquidity, price) of a particular liquidity pool in a DEX. Useful for building time-series charts on DEX trading activity.
716
- *
717
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
718
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
719
- * @param {string} poolAddress - The pool contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
720
- *
721
- */
722
- async getPoolByAddress(chainName, dexName, poolAddress) {
723
- let success = false;
724
- let data;
725
- let response;
726
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
727
- while (!success) {
728
- try {
729
- const urlParams = new URLSearchParams();
730
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`;
731
- if (!this.is_key_valid) {
732
- return {
733
- data: null,
734
- error: true,
735
- error_code: 401,
736
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
737
- };
738
- }
739
- let startTime;
740
- if (this.debug) {
741
- startTime = new Date();
742
- }
743
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`, {
744
- headers: {
745
- "Authorization": `Bearer ${this.apiKey}`,
746
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
747
- }
748
- }));
749
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
750
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
751
- try {
752
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
753
- }
754
- catch (error) {
755
- success = true;
756
- return {
757
- data: null,
758
- error: true,
759
- error_code: response.status ?? 429,
760
- error_message: error.message
761
- };
762
- }
763
- }
764
- else {
765
- data = await response.json();
766
- }
767
- const dataClass = new PoolByAddressResponse(data.data);
768
- success = true;
769
- return {
770
- data: dataClass,
771
- error: data ? data.error : true,
772
- error_code: data ? data.error_code : response.status,
773
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
774
- };
775
- }
776
- catch (error) {
777
- success = true;
778
- return {
779
- data: null,
780
- error: true,
781
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
782
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
783
- };
784
- }
785
- }
786
- }
787
- /**
788
- *
789
- * Commonly used to get all pools and the supported DEX for a token. Useful for building a table of top pairs across all supported DEXes that the token is trading on.
790
- *
791
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
792
- * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
793
- * @param {number} page - The requested 0-indexed page number.
794
- * @param {GetPoolsForTokenAddressQueryParamOpts} queryParamOpts
795
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
796
- * - `dexName`: The DEX name eg: `uniswap_v2`.
797
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
798
- *
799
- */
800
- async getPoolsForTokenAddress(chainName, tokenAddress, page, queryParamOpts) {
801
- let success = false;
802
- let data;
803
- let response;
804
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
805
- while (!success) {
806
- try {
807
- const urlParams = new URLSearchParams();
808
- if (!this.is_key_valid) {
809
- return {
810
- data: null,
811
- error: true,
812
- error_code: 401,
813
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
814
- };
815
- }
816
- if (queryParamOpts?.quoteCurrency !== undefined) {
817
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
818
- }
819
- if (queryParamOpts?.dexName !== undefined) {
820
- urlParams.append("dex-name", queryParamOpts?.dexName.toString());
821
- }
822
- if (queryParamOpts?.pageSize !== undefined) {
823
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
824
- }
825
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`;
826
- let startTime;
827
- if (this.debug) {
828
- startTime = new Date();
829
- }
830
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`, {
831
- headers: {
832
- "Authorization": `Bearer ${this.apiKey}`,
833
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
834
- }
835
- }));
836
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
837
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
838
- try {
839
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
840
- }
841
- catch (error) {
842
- success = true;
843
- return {
844
- data: null,
845
- error: true,
846
- error_code: response.status ?? 429,
847
- error_message: error.message
848
- };
849
- }
850
- }
851
- else {
852
- data = await response.json();
853
- }
854
- const dataClass = new PoolsDexDataResponse(data.data);
855
- success = true;
856
- return {
857
- data: dataClass,
858
- error: data ? data.error : true,
859
- error_code: data ? data.error_code : response.status,
860
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
861
- };
862
- }
863
- catch (error) {
864
- success = true;
865
- return {
866
- data: null,
867
- error: true,
868
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
869
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
870
- };
871
- }
872
- }
873
- }
874
- /**
875
- *
876
- * Commonly used to return balance of a wallet/contract address on a specific DEX.
877
- *
878
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
879
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
880
- * @param {string} accountAddress - The account address.
881
- *
882
- */
883
- async getAddressExchangeBalances(chainName, dexName, accountAddress) {
884
- let success = false;
885
- let data;
886
- let response;
887
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
888
- while (!success) {
889
- try {
890
- const urlParams = new URLSearchParams();
891
- if (!this.is_key_valid) {
892
- return {
893
- data: null,
894
- error: true,
895
- error_code: 401,
896
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
897
- };
898
- }
899
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`;
900
- let startTime;
901
- if (this.debug) {
902
- startTime = new Date();
903
- }
904
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
905
- headers: {
906
- "Authorization": `Bearer ${this.apiKey}`,
907
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
908
- }
909
- }));
910
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
911
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
912
- try {
913
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
914
- }
915
- catch (error) {
916
- success = true;
917
- return {
918
- data: null,
919
- error: true,
920
- error_code: response.status ?? 429,
921
- error_message: error.message
922
- };
923
- }
924
- }
925
- else {
926
- data = await response.json();
927
- }
928
- const dataClass = new AddressExchangeBalancesResponse(data.data);
929
- success = true;
930
- return {
931
- data: dataClass,
932
- error: data ? data.error : true,
933
- error_code: data ? data.error_code : response.status,
934
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
935
- };
936
- }
937
- catch (error) {
938
- success = true;
939
- return {
940
- data: null,
941
- error: true,
942
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
943
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
944
- };
945
- }
946
- }
947
- }
948
- /**
949
- *
950
- * Commonly used to get all pools and supported DEX for a wallet. Useful for building a personal DEX UI showcasing pairs and supported DEXes associated to the wallet.
951
- *
952
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
953
- * @param {string} walletAddress - The account address.
954
- * @param {number} page - The requested 0-indexed page number.
955
- * @param {GetPoolsForWalletAddressQueryParamOpts} queryParamOpts
956
- * - `tokenAddress`: The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
957
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
958
- * - `dexName`: The DEX name eg: `uniswap_v2`.
959
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
960
- *
961
- */
962
- async getPoolsForWalletAddress(chainName, walletAddress, page, queryParamOpts) {
963
- let success = false;
964
- let data;
965
- let response;
966
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
967
- while (!success) {
968
- try {
969
- const urlParams = new URLSearchParams();
970
- if (!this.is_key_valid) {
971
- return {
972
- data: null,
973
- error: true,
974
- error_code: 401,
975
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
976
- };
977
- }
978
- if (queryParamOpts?.tokenAddress !== undefined) {
979
- urlParams.append("token-address", queryParamOpts?.tokenAddress.toString());
980
- }
981
- if (queryParamOpts?.quoteCurrency !== undefined) {
982
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
983
- }
984
- if (queryParamOpts?.dexName !== undefined) {
985
- urlParams.append("dex-name", queryParamOpts?.dexName.toString());
986
- }
987
- if (queryParamOpts?.pageSize !== undefined) {
988
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
989
- }
990
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`;
991
- let startTime;
992
- if (this.debug) {
993
- startTime = new Date();
994
- }
995
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`, {
996
- headers: {
997
- "Authorization": `Bearer ${this.apiKey}`,
998
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
999
- }
1000
- }));
1001
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1002
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1003
- try {
1004
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1005
- }
1006
- catch (error) {
1007
- success = true;
1008
- return {
1009
- data: null,
1010
- error: true,
1011
- error_code: response.status ?? 429,
1012
- error_message: error.message
1013
- };
1014
- }
1015
- }
1016
- else {
1017
- data = await response.json();
1018
- }
1019
- const dataClass = new PoolsDexDataResponse(data.data);
1020
- success = true;
1021
- return {
1022
- data: dataClass,
1023
- error: data ? data.error : true,
1024
- error_code: data ? data.error_code : response.status,
1025
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1026
- };
1027
- }
1028
- catch (error) {
1029
- success = true;
1030
- return {
1031
- data: null,
1032
- error: true,
1033
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1034
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1035
- };
1036
- }
1037
- }
1038
- }
1039
- /**
1040
- *
1041
- * Commonly used to retrieve all network exchange tokens for a specific DEX. Useful for building a top tokens table by total liquidity within a particular DEX.
1042
- *
1043
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1044
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1045
- * @param {GetNetworkExchangeTokensQueryParamOpts} queryParamOpts
1046
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1047
- * - `pageNumber`: 0-indexed page number to begin pagination.
1048
- *
1049
- */
1050
- async getNetworkExchangeTokens(chainName, dexName, queryParamOpts) {
1051
- let success = false;
1052
- let data;
1053
- let response;
1054
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1055
- while (!success) {
1056
- try {
1057
- const urlParams = new URLSearchParams();
1058
- if (queryParamOpts?.pageSize !== undefined) {
1059
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1060
- }
1061
- if (queryParamOpts?.pageNumber !== undefined) {
1062
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1063
- }
1064
- if (!this.is_key_valid) {
1065
- return {
1066
- data: null,
1067
- error: true,
1068
- error_code: 401,
1069
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1070
- };
1071
- }
1072
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`;
1073
- let startTime;
1074
- if (this.debug) {
1075
- startTime = new Date();
1076
- }
1077
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
1078
- headers: {
1079
- "Authorization": `Bearer ${this.apiKey}`,
1080
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1081
- }
1082
- }));
1083
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1084
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1085
- try {
1086
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1087
- }
1088
- catch (error) {
1089
- success = true;
1090
- return {
1091
- data: null,
1092
- error: true,
1093
- error_code: response.status ?? 429,
1094
- error_message: error.message
1095
- };
1096
- }
1097
- }
1098
- else {
1099
- data = await response.json();
1100
- }
1101
- const dataClass = new NetworkExchangeTokensResponse(data.data);
1102
- success = true;
1103
- return {
1104
- data: dataClass,
1105
- error: data ? data.error : true,
1106
- error_code: data ? data.error_code : response.status,
1107
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1108
- };
1109
- }
1110
- catch (error) {
1111
- success = true;
1112
- return {
1113
- data: null,
1114
- error: true,
1115
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1116
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1117
- };
1118
- }
1119
- }
1120
- }
1121
- /**
1122
- *
1123
- * Commonly used to get a detailed view for a single liquidity pool token. Includes time series data.
1124
- *
1125
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1126
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1127
- * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1128
- * @param {GetLpTokenViewQueryParamOpts} queryParamOpts
1129
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1130
- *
1131
- */
1132
- async getLpTokenView(chainName, dexName, tokenAddress, queryParamOpts) {
1133
- let success = false;
1134
- let data;
1135
- let response;
1136
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1137
- while (!success) {
1138
- try {
1139
- const urlParams = new URLSearchParams();
1140
- if (!this.is_key_valid) {
1141
- return {
1142
- data: null,
1143
- error: true,
1144
- error_code: 401,
1145
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1146
- };
1147
- }
1148
- if (queryParamOpts?.quoteCurrency !== undefined) {
1149
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1150
- }
1151
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`;
1152
- let startTime;
1153
- if (this.debug) {
1154
- startTime = new Date();
1155
- }
1156
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`, {
1157
- headers: {
1158
- "Authorization": `Bearer ${this.apiKey}`,
1159
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1160
- }
1161
- }));
1162
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1163
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1164
- try {
1165
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1166
- }
1167
- catch (error) {
1168
- success = true;
1169
- return {
1170
- data: null,
1171
- error: true,
1172
- error_code: response.status ?? 429,
1173
- error_message: error.message
1174
- };
1175
- }
1176
- }
1177
- else {
1178
- data = await response.json();
1179
- }
1180
- const dataClass = new NetworkExchangeTokenViewResponse(data.data);
1181
- success = true;
1182
- return {
1183
- data: dataClass,
1184
- error: data ? data.error : true,
1185
- error_code: data ? data.error_code : response.status,
1186
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1187
- };
1188
- }
1189
- catch (error) {
1190
- success = true;
1191
- return {
1192
- data: null,
1193
- error: true,
1194
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1195
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1196
- };
1197
- }
1198
- }
1199
- }
1200
- /**
1201
- *
1202
- * Commonly used to get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
1203
- *
1204
- *
1205
- */
1206
- async getSupportedDEXes() {
1207
- let success = false;
1208
- let data;
1209
- let response;
1210
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1211
- while (!success) {
1212
- try {
1213
- const urlParams = new URLSearchParams();
1214
- if (!this.is_key_valid) {
1215
- return {
1216
- data: null,
1217
- error: true,
1218
- error_code: 401,
1219
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1220
- };
1221
- }
1222
- const url = `https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`;
1223
- let startTime;
1224
- if (this.debug) {
1225
- startTime = new Date();
1226
- }
1227
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
1228
- headers: {
1229
- "Authorization": `Bearer ${this.apiKey}`,
1230
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1231
- }
1232
- }));
1233
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1234
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1235
- try {
1236
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1237
- }
1238
- catch (error) {
1239
- success = true;
1240
- return {
1241
- data: null,
1242
- error: true,
1243
- error_code: response.status ?? 429,
1244
- error_message: error.message
1245
- };
1246
- }
1247
- }
1248
- else {
1249
- data = await response.json();
1250
- }
1251
- const dataClass = new SupportedDexesResponse(data.data);
1252
- success = true;
1253
- return {
1254
- data: dataClass,
1255
- error: data ? data.error : true,
1256
- error_code: data ? data.error_code : response.status,
1257
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1258
- };
1259
- }
1260
- catch (error) {
1261
- success = true;
1262
- return {
1263
- data: null,
1264
- error: true,
1265
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1266
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1267
- };
1268
- }
1269
- }
1270
- }
1271
- /**
1272
- *
1273
- * Commonly used to get historical daily swap count for a single network exchange token.
1274
- *
1275
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1276
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1277
- * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1278
- * @param {GetSingleNetworkExchangeTokenQueryParamOpts} queryParamOpts
1279
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1280
- * - `pageNumber`: 0-indexed page number to begin pagination.
1281
- *
1282
- */
1283
- async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress, queryParamOpts) {
1284
- let success = false;
1285
- let data;
1286
- let response;
1287
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1288
- while (!success) {
1289
- try {
1290
- const urlParams = new URLSearchParams();
1291
- if (queryParamOpts?.pageSize !== undefined) {
1292
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1293
- }
1294
- if (queryParamOpts?.pageNumber !== undefined) {
1295
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1296
- }
1297
- if (!this.is_key_valid) {
1298
- return {
1299
- data: null,
1300
- error: true,
1301
- error_code: 401,
1302
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1303
- };
1304
- }
1305
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`;
1306
- let startTime;
1307
- if (this.debug) {
1308
- startTime = new Date();
1309
- }
1310
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
1311
- headers: {
1312
- "Authorization": `Bearer ${this.apiKey}`,
1313
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1314
- }
1315
- }));
1316
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1317
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1318
- try {
1319
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1320
- }
1321
- catch (error) {
1322
- success = true;
1323
- return {
1324
- data: null,
1325
- error: true,
1326
- error_code: response.status ?? 429,
1327
- error_message: error.message
1328
- };
1329
- }
1330
- }
1331
- else {
1332
- data = await response.json();
1333
- }
1334
- const dataClass = new SingleNetworkExchangeTokenResponse(data.data);
1335
- success = true;
1336
- return {
1337
- data: dataClass,
1338
- error: data ? data.error : true,
1339
- error_code: data ? data.error_code : response.status,
1340
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1341
- };
1342
- }
1343
- catch (error) {
1344
- success = true;
1345
- return {
1346
- data: null,
1347
- error: true,
1348
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1349
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1350
- };
1351
- }
1352
- }
1353
- }
1354
- /**
1355
- *
1356
- * Commonly used to get all the DEX transactions of a wallet. Useful for building tables of DEX activity segmented by wallet.
1357
- *
1358
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1359
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1360
- * @param {string} accountAddress - The account address. Passing in an `ENS` or `RNS` resolves automatically.
1361
- *
1362
- */
1363
- async getTransactionsForAccountAddress(chainName, dexName, accountAddress) {
1364
- let success = false;
1365
- let data;
1366
- let response;
1367
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1368
- while (!success) {
1369
- try {
1370
- const urlParams = new URLSearchParams();
1371
- if (!this.is_key_valid) {
1372
- return {
1373
- data: null,
1374
- error: true,
1375
- error_code: 401,
1376
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1377
- };
1378
- }
1379
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`;
1380
- let startTime;
1381
- if (this.debug) {
1382
- startTime = new Date();
1383
- }
1384
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
1385
- headers: {
1386
- "Authorization": `Bearer ${this.apiKey}`,
1387
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1388
- }
1389
- }));
1390
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1391
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1392
- try {
1393
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1394
- }
1395
- catch (error) {
1396
- success = true;
1397
- return {
1398
- data: null,
1399
- error: true,
1400
- error_code: response.status ?? 429,
1401
- error_message: error.message
1402
- };
1403
- }
1404
- }
1405
- else {
1406
- data = await response.json();
1407
- }
1408
- const dataClass = new TransactionsForAccountAddressResponse(data.data);
1409
- success = true;
1410
- return {
1411
- data: dataClass,
1412
- error: data ? data.error : true,
1413
- error_code: data ? data.error_code : response.status,
1414
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1415
- };
1416
- }
1417
- catch (error) {
1418
- success = true;
1419
- return {
1420
- data: null,
1421
- error: true,
1422
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1423
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1424
- };
1425
- }
1426
- }
1427
- }
1428
- /**
1429
- *
1430
- * Commonly used to get all the transactions of a token within a particular DEX. Useful for getting a per-token view of DEX activity.
1431
- *
1432
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1433
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1434
- * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1435
- * @param {GetTransactionsForTokenAddressQueryParamOpts} queryParamOpts
1436
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1437
- * - `pageNumber`: 0-indexed page number to begin pagination.
1438
- *
1439
- */
1440
- async getTransactionsForTokenAddress(chainName, dexName, tokenAddress, queryParamOpts) {
1441
- let success = false;
1442
- let data;
1443
- let response;
1444
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1445
- while (!success) {
1446
- try {
1447
- const urlParams = new URLSearchParams();
1448
- if (!this.is_key_valid) {
1449
- return {
1450
- data: null,
1451
- error: true,
1452
- error_code: 401,
1453
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1454
- };
1455
- }
1456
- if (queryParamOpts?.pageSize !== undefined) {
1457
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1458
- }
1459
- if (queryParamOpts?.pageNumber !== undefined) {
1460
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1461
- }
1462
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`;
1463
- let startTime;
1464
- if (this.debug) {
1465
- startTime = new Date();
1466
- }
1467
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
1468
- headers: {
1469
- "Authorization": `Bearer ${this.apiKey}`,
1470
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1471
- }
1472
- }));
1473
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1474
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1475
- try {
1476
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1477
- }
1478
- catch (error) {
1479
- success = true;
1480
- return {
1481
- data: null,
1482
- error: true,
1483
- error_code: response.status ?? 429,
1484
- error_message: error.message
1485
- };
1486
- }
1487
- }
1488
- else {
1489
- data = await response.json();
1490
- }
1491
- const dataClass = new TransactionsForTokenAddressResponse(data.data);
1492
- success = true;
1493
- return {
1494
- data: dataClass,
1495
- error: data ? data.error : true,
1496
- error_code: data ? data.error_code : response.status,
1497
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1498
- };
1499
- }
1500
- catch (error) {
1501
- success = true;
1502
- return {
1503
- data: null,
1504
- error: true,
1505
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1506
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1507
- };
1508
- }
1509
- }
1510
- }
1511
- /**
1512
- *
1513
- * Commonly used for getting all the transactions of a particular DEX liquidity pool. Useful for building a transactions history table for an individual pool.
1514
- *
1515
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1516
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1517
- * @param {string} poolAddress - The pool contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1518
- * @param {GetTransactionsForExchangeQueryParamOpts} queryParamOpts
1519
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1520
- * - `pageNumber`: 0-indexed page number to begin pagination.
1521
- *
1522
- */
1523
- async getTransactionsForExchange(chainName, dexName, poolAddress, queryParamOpts) {
1524
- let success = false;
1525
- let data;
1526
- let response;
1527
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1528
- while (!success) {
1529
- try {
1530
- const urlParams = new URLSearchParams();
1531
- if (!this.is_key_valid) {
1532
- return {
1533
- data: null,
1534
- error: true,
1535
- error_code: 401,
1536
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1537
- };
1538
- }
1539
- if (queryParamOpts?.pageSize !== undefined) {
1540
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1541
- }
1542
- if (queryParamOpts?.pageNumber !== undefined) {
1543
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1544
- }
1545
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`;
1546
- let startTime;
1547
- if (this.debug) {
1548
- startTime = new Date();
1549
- }
1550
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
1551
- headers: {
1552
- "Authorization": `Bearer ${this.apiKey}`,
1553
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1554
- }
1555
- }));
1556
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1557
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1558
- try {
1559
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1560
- }
1561
- catch (error) {
1562
- success = true;
1563
- return {
1564
- data: null,
1565
- error: true,
1566
- error_code: response.status ?? 429,
1567
- error_message: error.message
1568
- };
1569
- }
1570
- }
1571
- else {
1572
- data = await response.json();
1573
- }
1574
- const dataClass = new TransactionsForExchangeResponse(data.data);
1575
- success = true;
1576
- return {
1577
- data: dataClass,
1578
- error: data ? data.error : true,
1579
- error_code: data ? data.error_code : response.status,
1580
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1581
- };
1582
- }
1583
- catch (error) {
1584
- success = true;
1585
- return {
1586
- data: null,
1587
- error: true,
1588
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1589
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1590
- };
1591
- }
1592
- }
1593
- }
1594
- /**
1595
- *
1596
- * Commonly used to get all the the transactions for a given DEX. Useful for building DEX activity views.
1597
- *
1598
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1599
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1600
- * @param {GetTransactionsForDexQueryParamOpts} queryParamOpts
1601
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1602
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1603
- * - `pageNumber`: 0-indexed page number to begin pagination.
1604
- *
1605
- */
1606
- async getTransactionsForDex(chainName, dexName, queryParamOpts) {
1607
- let success = false;
1608
- let data;
1609
- let response;
1610
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1611
- while (!success) {
1612
- try {
1613
- const urlParams = new URLSearchParams();
1614
- if (!this.is_key_valid) {
1615
- return {
1616
- data: null,
1617
- error: true,
1618
- error_code: 401,
1619
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1620
- };
1621
- }
1622
- if (queryParamOpts?.quoteCurrency !== undefined) {
1623
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1624
- }
1625
- if (queryParamOpts?.pageSize !== undefined) {
1626
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1627
- }
1628
- if (queryParamOpts?.pageNumber !== undefined) {
1629
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1630
- }
1631
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`;
1632
- let startTime;
1633
- if (this.debug) {
1634
- startTime = new Date();
1635
- }
1636
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`, {
1637
- headers: {
1638
- "Authorization": `Bearer ${this.apiKey}`,
1639
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1640
- }
1641
- }));
1642
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1643
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1644
- try {
1645
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1646
- }
1647
- catch (error) {
1648
- success = true;
1649
- return {
1650
- data: null,
1651
- error: true,
1652
- error_code: response.status ?? 429,
1653
- error_message: error.message
1654
- };
1655
- }
1656
- }
1657
- else {
1658
- data = await response.json();
1659
- }
1660
- const dataClass = new NetworkTransactionsResponse(data.data);
1661
- success = true;
1662
- return {
1663
- data: dataClass,
1664
- error: data.error,
1665
- error_code: data ? data.error_code : response.status,
1666
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1667
- };
1668
- }
1669
- catch (error) {
1670
- success = true;
1671
- return {
1672
- data: null,
1673
- error: true,
1674
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1675
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1676
- };
1677
- }
1678
- }
1679
- }
1680
- /**
1681
- *
1682
- * Commonly used to get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
1683
- *
1684
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1685
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1686
- *
1687
- */
1688
- async getEcosystemChartData(chainName, dexName) {
1689
- let success = false;
1690
- let data;
1691
- let response;
1692
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1693
- while (!success) {
1694
- try {
1695
- const urlParams = new URLSearchParams();
1696
- if (!this.is_key_valid) {
1697
- return {
1698
- data: null,
1699
- error: true,
1700
- error_code: 401,
1701
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1702
- };
1703
- }
1704
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`;
1705
- let startTime;
1706
- if (this.debug) {
1707
- startTime = new Date();
1708
- }
1709
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
1710
- headers: {
1711
- "Authorization": `Bearer ${this.apiKey}`,
1712
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1713
- }
1714
- }));
1715
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1716
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1717
- try {
1718
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1719
- }
1720
- catch (error) {
1721
- success = true;
1722
- return {
1723
- data: null,
1724
- error: true,
1725
- error_code: response.status ?? 429,
1726
- error_message: error.message
1727
- };
1728
- }
1729
- }
1730
- else {
1731
- data = await response.json();
1732
- }
1733
- const dataClass = new EcosystemChartDataResponse(data.data);
1734
- success = true;
1735
- return {
1736
- data: dataClass,
1737
- error: data ? data.error : true,
1738
- error_code: data ? data.error_code : response.status,
1739
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1740
- };
1741
- }
1742
- catch (error) {
1743
- success = true;
1744
- return {
1745
- data: null,
1746
- error: true,
1747
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1748
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1749
- };
1750
- }
1751
- }
1752
- }
1753
- /**
1754
- *
1755
- * Commonly used to ping the health of xy=k endpoints to get the synced block height per chain.
1756
- *
1757
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1758
- * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1759
- *
1760
- */
1761
- async getHealthData(chainName, dexName) {
1762
- let success = false;
1763
- let data;
1764
- let response;
1765
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1766
- while (!success) {
1767
- try {
1768
- const urlParams = new URLSearchParams();
1769
- if (!this.is_key_valid) {
1770
- return {
1771
- data: null,
1772
- error: true,
1773
- error_code: 401,
1774
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1775
- };
1776
- }
1777
- const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`;
1778
- let startTime;
1779
- if (this.debug) {
1780
- startTime = new Date();
1781
- }
1782
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
1783
- headers: {
1784
- "Authorization": `Bearer ${this.apiKey}`,
1785
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1786
- }
1787
- }));
1788
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1789
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1790
- try {
1791
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1792
- }
1793
- catch (error) {
1794
- success = true;
1795
- return {
1796
- data: null,
1797
- error: true,
1798
- error_code: response.status ?? 429,
1799
- error_message: error.message
1800
- };
1801
- }
1802
- }
1803
- else {
1804
- data = await response.json();
1805
- }
1806
- const dataClass = new HealthDataResponse(data.data);
1807
- success = true;
1808
- return {
1809
- data: dataClass,
1810
- error: data ? data.error : true,
1811
- error_code: data ? data.error_code : response.status,
1812
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1813
- };
1814
- }
1815
- catch (error) {
1816
- success = true;
1817
- return {
1818
- data: null,
1819
- error: true,
1820
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1821
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1822
- };
1823
- }
1824
- }
1825
- }
1826
- }
1827
- //# sourceMappingURL=XykService.js.map