@quicknode/sdk 1.0.0 → 1.1.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.
- package/README.md +2 -0
- package/cjs/index.js +314 -1
- package/esm/package.json +2 -1
- package/esm/package.json.js +3 -0
- package/esm/src/api/api.js +85 -0
- package/esm/src/api/controllers/contracts.js +36 -0
- package/esm/src/api/controllers/events.js +121 -0
- package/esm/src/api/controllers/nfts.js +244 -0
- package/esm/src/api/controllers/tokens.js +98 -0
- package/esm/src/api/controllers/transactions.js +125 -0
- package/esm/src/api/controllers/utils.js +55 -0
- package/esm/src/api/graphql/customUrqlClient.js +23 -0
- package/esm/{index.js → src/api/graphql/generatedTypes.js} +1 -1099
- package/esm/src/api/graphql/schema.json.js +3 -0
- package/esm/src/api/index.d.ts +2687 -0
- package/esm/src/api/index.js +2 -0
- package/esm/src/api/types/chains.js +7 -0
- package/esm/src/api/types/contracts/getContractDetails.js +12 -0
- package/esm/src/api/types/events/getAll.js +7 -0
- package/esm/src/api/types/events/getByContract.js +12 -0
- package/esm/src/api/types/nfts/getByContractAddress.js +10 -0
- package/esm/src/api/types/nfts/getByWalletAddress.js +18 -0
- package/esm/src/api/types/nfts/getCollectionDetails.js +11 -0
- package/esm/src/api/types/nfts/getCollectionEvents.js +12 -0
- package/esm/src/api/types/nfts/getNFTDetails.js +9 -0
- package/esm/src/api/types/nfts/getNFTEvents.js +13 -0
- package/esm/src/api/types/nfts/getTrendingCollections.js +7 -0
- package/esm/src/api/types/nfts/verifyOwnershipByAddress.js +12 -0
- package/esm/src/api/types/tokens/getBalancesByWalletAddress.js +12 -0
- package/esm/src/api/types/transactions/getByHash.js +11 -0
- package/esm/src/api/types/transactions/getBySearch.js +7 -0
- package/esm/src/api/types/utils/gasPrices.js +12 -0
- package/esm/src/api/utils/constants.js +3 -0
- package/esm/src/api/utils/helpers.js +11 -0
- package/esm/src/api/utils/isValidENSAddress.js +21 -0
- package/esm/src/api/utils/postQueryFormatter.js +24 -0
- package/esm/src/api/utils/removeNodesAndEdges.js +51 -0
- package/esm/src/client/client.js +9 -0
- package/esm/src/client/index.js +2 -0
- package/esm/src/core/addOns/nftTokenV2/actions.js +107 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_fetchNFTCollectionDetails.js +10 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_fetchNFTs.js +13 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_fetchNFTsByCollection.js +13 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_getTokenMetadataByContractAddress.js +10 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_getTokenMetadataBySymbol.js +11 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_getTransactionsByAddress.js +18 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_getTransfersByNFT.js +12 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_getWalletTokenBalance.js +12 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_getWalletTokenTransactions.js +14 -0
- package/esm/src/core/addOns/nftTokenV2/types/qn_verifyNFTsOwner.js +11 -0
- package/esm/src/core/addOns/shared/helpers.js +10 -0
- package/esm/src/core/chains.js +60 -0
- package/esm/src/core/core.js +24 -0
- package/esm/src/core/index.d.ts +555 -0
- package/esm/src/core/index.js +2 -0
- package/esm/src/index.js +10 -0
- package/esm/src/lib/errors/QNChainNotSupported.js +7 -0
- package/esm/src/lib/errors/QNInputValidationError.js +10 -0
- package/esm/src/lib/errors/QNInvalidEnpointUrl.js +7 -0
- package/esm/src/lib/helpers/globalFetch.js +13 -0
- package/esm/src/lib/validation/ValidateInput.js +35 -0
- package/esm/src/lib/validation/codegenDerivedValidators.js +28 -0
- package/esm/src/lib/validation/validators.js +105 -0
- package/index.d.ts +560 -1
- package/package.json +25 -3
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { walletByAddressValidator } from '../types/nfts/getByWalletAddress.js';
|
|
3
|
+
import { nftDetailsValidator } from '../types/nfts/getNFTDetails.js';
|
|
4
|
+
import { nftCollectionDetailsValidator } from '../types/nfts/getCollectionDetails.js';
|
|
5
|
+
import { nftTrendingCollectionsValidator } from '../types/nfts/getTrendingCollections.js';
|
|
6
|
+
import { nftsByContractAddressValidator } from '../types/nfts/getByContractAddress.js';
|
|
7
|
+
import { verifyOwnershipValidator } from '../types/nfts/verifyOwnershipByAddress.js';
|
|
8
|
+
import { CodegenEthMainnetWalletNFTsByEnsDocument, CodegenPolygonMainnetWalletNFTsByEnsDocument, CodegenEthSepoliaWalletNFTsByEnsDocument, CodegenEthMainnetWalletNFTsByAddressDocument, CodegenPolygonMainnetWalletNFTsByAddressDocument, CodegenEthSepoliaWalletNFTsByAddressDocument, CodegenEthMainnetTrendingCollectionsDocument, CodegenPolygonMainnetTrendingCollectionsDocument, CodegenEthSepoliaTrendingCollectionsDocument, CodegenEthMainnetWalletNFTsByContractAddressDocument, CodegenPolygonMainnetNFTsByContractAddressDocument, CodegenEthSepoliaWalletNFTsByContractAddressDocument, CodegenEthMainnetNFTDetailsDocument, CodegenPolygonMainnetNFTDetailsDocument, CodegenEthSepoliaNFTDetailsDocument, CodegenEthMainnetNftCollectionDetailsDocument, CodegenPolygonMainnetNftCollectionDetailsDocument, CodegenEthSepoliaNftCollectionDetailsDocument, CodegenEthMainnetVerifyOwnershipByAddressDocument, CodegenPolygonMainnetVerifyOwnershipByAddressDocument, CodegenEthSepoliaVerifyOwnershipByAddressDocument, CodegenEthMainnetVerifyOwnershipByENSDocument, CodegenPolygonMainnetVerifyOwnershipByENSDocument, CodegenEthSepoliaVerifyOwnershipByENSDocument } from '../graphql/generatedTypes.js';
|
|
9
|
+
import { formatQueryResult } from '../utils/postQueryFormatter.js';
|
|
10
|
+
import { emptyPageInfo } from '../utils/helpers.js';
|
|
11
|
+
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
12
|
+
import { isValidENSAddress } from '../utils/isValidENSAddress.js';
|
|
13
|
+
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
14
|
+
|
|
15
|
+
class NftsController {
|
|
16
|
+
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
17
|
+
this.client = client;
|
|
18
|
+
this.defaultChain = defaultChain;
|
|
19
|
+
}
|
|
20
|
+
async getByWallet(variables) {
|
|
21
|
+
const { address, ...allVariables } = variables;
|
|
22
|
+
if (isValidENSAddress(address)) {
|
|
23
|
+
return this.getByWalletENS({
|
|
24
|
+
ensName: address,
|
|
25
|
+
...allVariables,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return this.getByWalletAddress({
|
|
29
|
+
address,
|
|
30
|
+
...allVariables,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async getByWalletENS(variables) {
|
|
34
|
+
const { chain, ...queryVariables } = variables;
|
|
35
|
+
const userChain = chain || this.defaultChain;
|
|
36
|
+
const query = {
|
|
37
|
+
ethereum: CodegenEthMainnetWalletNFTsByEnsDocument,
|
|
38
|
+
polygon: CodegenPolygonMainnetWalletNFTsByEnsDocument,
|
|
39
|
+
ethereumSepolia: CodegenEthSepoliaWalletNFTsByEnsDocument,
|
|
40
|
+
};
|
|
41
|
+
const { data: { [userChain]: { walletByENS }, }, } = await this.client.query({
|
|
42
|
+
query: query[userChain],
|
|
43
|
+
variables: queryVariables,
|
|
44
|
+
});
|
|
45
|
+
if (!walletByENS?.walletNFTs?.length) {
|
|
46
|
+
// Address can still be valid ENS name, but not have any NFTs
|
|
47
|
+
const address = walletByENS?.address || '';
|
|
48
|
+
const ensName = walletByENS?.ensName || '';
|
|
49
|
+
return {
|
|
50
|
+
address: address,
|
|
51
|
+
ensName: ensName,
|
|
52
|
+
results: [],
|
|
53
|
+
pageInfo: emptyPageInfo,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const formattedResult = formatQueryResult(walletByENS, 'walletNFTs', 'walletNFTsPageInfo', 'nft');
|
|
57
|
+
return formattedResult;
|
|
58
|
+
}
|
|
59
|
+
async getByWalletAddress(variables) {
|
|
60
|
+
const { chain, ...queryVariables } = variables;
|
|
61
|
+
const userChain = chain || this.defaultChain;
|
|
62
|
+
const query = {
|
|
63
|
+
ethereum: CodegenEthMainnetWalletNFTsByAddressDocument,
|
|
64
|
+
polygon: CodegenPolygonMainnetWalletNFTsByAddressDocument,
|
|
65
|
+
ethereumSepolia: CodegenEthSepoliaWalletNFTsByAddressDocument,
|
|
66
|
+
};
|
|
67
|
+
const { data: { [userChain]: { walletByAddress }, }, } = await this.client.query({
|
|
68
|
+
query: query[userChain],
|
|
69
|
+
variables: queryVariables,
|
|
70
|
+
});
|
|
71
|
+
if (!walletByAddress?.walletNFTs?.length) {
|
|
72
|
+
const address = walletByAddress?.address || '';
|
|
73
|
+
const ensName = walletByAddress?.ensName || '';
|
|
74
|
+
return {
|
|
75
|
+
address: address,
|
|
76
|
+
ensName: ensName,
|
|
77
|
+
results: [],
|
|
78
|
+
pageInfo: emptyPageInfo,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const formattedResult = formatQueryResult(walletByAddress, 'walletNFTs', 'walletNFTsPageInfo', 'nft');
|
|
82
|
+
return formattedResult;
|
|
83
|
+
}
|
|
84
|
+
async getTrendingCollections(variables) {
|
|
85
|
+
const { chain, ...queryVariables } = variables;
|
|
86
|
+
const userChain = chain || this.defaultChain;
|
|
87
|
+
const query = {
|
|
88
|
+
ethereum: CodegenEthMainnetTrendingCollectionsDocument,
|
|
89
|
+
polygon: CodegenPolygonMainnetTrendingCollectionsDocument,
|
|
90
|
+
ethereumSepolia: CodegenEthSepoliaTrendingCollectionsDocument,
|
|
91
|
+
};
|
|
92
|
+
const { data: { [userChain]: trendingCollections }, } = await this.client.query({
|
|
93
|
+
query: query[userChain],
|
|
94
|
+
variables: queryVariables,
|
|
95
|
+
});
|
|
96
|
+
const formattedResult = formatQueryResult(trendingCollections, 'trendingCollections', 'trendingCollectionsPageInfo', 'collection');
|
|
97
|
+
return formattedResult;
|
|
98
|
+
}
|
|
99
|
+
async getByContractAddress(variables) {
|
|
100
|
+
const { chain, ...queryVariables } = variables;
|
|
101
|
+
const userChain = chain || this.defaultChain;
|
|
102
|
+
const query = {
|
|
103
|
+
ethereum: CodegenEthMainnetWalletNFTsByContractAddressDocument,
|
|
104
|
+
polygon: CodegenPolygonMainnetNFTsByContractAddressDocument,
|
|
105
|
+
ethereumSepolia: CodegenEthSepoliaWalletNFTsByContractAddressDocument,
|
|
106
|
+
};
|
|
107
|
+
const { data: { [userChain]: { collection }, }, } = await this.client.query({
|
|
108
|
+
query: query[userChain],
|
|
109
|
+
variables: queryVariables,
|
|
110
|
+
});
|
|
111
|
+
if (!collection?.nfts?.length) {
|
|
112
|
+
return {
|
|
113
|
+
standard: null,
|
|
114
|
+
results: [],
|
|
115
|
+
pageInfo: emptyPageInfo,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const setErcStandard = (results) => {
|
|
119
|
+
const standardMap = {
|
|
120
|
+
ERC1155Collection: 'ERC1155',
|
|
121
|
+
ERC721Collection: 'ERC721',
|
|
122
|
+
};
|
|
123
|
+
// Remove address too since it was only used as a key field
|
|
124
|
+
const { __typename, address, ...newResults } = results;
|
|
125
|
+
return {
|
|
126
|
+
...newResults,
|
|
127
|
+
standard: standardMap[results['__typename']] || null,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const formattedResult = formatQueryResult(collection, 'nfts', 'nftsPageInfo', null, setErcStandard);
|
|
131
|
+
return formattedResult;
|
|
132
|
+
}
|
|
133
|
+
async getNFTDetails(variables) {
|
|
134
|
+
const { chain, ...queryVariables } = variables;
|
|
135
|
+
const userChain = chain || this.defaultChain;
|
|
136
|
+
const query = {
|
|
137
|
+
ethereum: CodegenEthMainnetNFTDetailsDocument,
|
|
138
|
+
polygon: CodegenPolygonMainnetNFTDetailsDocument,
|
|
139
|
+
ethereumSepolia: CodegenEthSepoliaNFTDetailsDocument,
|
|
140
|
+
};
|
|
141
|
+
const { data: { [userChain]: { nft }, }, } = await this.client.query({
|
|
142
|
+
query: query[userChain],
|
|
143
|
+
variables: queryVariables,
|
|
144
|
+
});
|
|
145
|
+
if (nft)
|
|
146
|
+
return { nft };
|
|
147
|
+
return { nft: null };
|
|
148
|
+
}
|
|
149
|
+
async getCollectionDetails(variables) {
|
|
150
|
+
const { chain, ...queryVariables } = variables;
|
|
151
|
+
const userChain = chain || this.defaultChain;
|
|
152
|
+
const query = {
|
|
153
|
+
ethereum: CodegenEthMainnetNftCollectionDetailsDocument,
|
|
154
|
+
polygon: CodegenPolygonMainnetNftCollectionDetailsDocument,
|
|
155
|
+
ethereumSepolia: CodegenEthSepoliaNftCollectionDetailsDocument,
|
|
156
|
+
};
|
|
157
|
+
const { data: { [userChain]: { collection }, }, } = await this.client.query({
|
|
158
|
+
query: query[userChain],
|
|
159
|
+
variables: queryVariables,
|
|
160
|
+
});
|
|
161
|
+
if (collection)
|
|
162
|
+
return { collection };
|
|
163
|
+
return { collection: null };
|
|
164
|
+
}
|
|
165
|
+
async verifyOwnership(variables) {
|
|
166
|
+
const { address, ...allVariables } = variables;
|
|
167
|
+
if (isValidENSAddress(address)) {
|
|
168
|
+
return this.verifyOwnershipByENS({
|
|
169
|
+
ensName: address,
|
|
170
|
+
...allVariables,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return this.verifyOwnershipByAddress({
|
|
174
|
+
address,
|
|
175
|
+
...allVariables,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async verifyOwnershipByAddress(variables) {
|
|
179
|
+
const { chain, address, nfts } = variables;
|
|
180
|
+
const userChain = chain || this.defaultChain;
|
|
181
|
+
const query = {
|
|
182
|
+
ethereum: CodegenEthMainnetVerifyOwnershipByAddressDocument,
|
|
183
|
+
polygon: CodegenPolygonMainnetVerifyOwnershipByAddressDocument,
|
|
184
|
+
ethereumSepolia: CodegenEthSepoliaVerifyOwnershipByAddressDocument,
|
|
185
|
+
};
|
|
186
|
+
const { data: { [userChain]: { walletByAddress }, }, } = await this.client.query({
|
|
187
|
+
query: query[userChain],
|
|
188
|
+
variables: { address, filter: { contractTokens: nfts } },
|
|
189
|
+
});
|
|
190
|
+
return !!walletByAddress?.walletNFTs?.length;
|
|
191
|
+
}
|
|
192
|
+
async verifyOwnershipByENS(variables) {
|
|
193
|
+
const { chain, ensName, nfts } = variables;
|
|
194
|
+
const userChain = chain || this.defaultChain;
|
|
195
|
+
const query = {
|
|
196
|
+
ethereum: CodegenEthMainnetVerifyOwnershipByENSDocument,
|
|
197
|
+
polygon: CodegenPolygonMainnetVerifyOwnershipByENSDocument,
|
|
198
|
+
ethereumSepolia: CodegenEthSepoliaVerifyOwnershipByENSDocument,
|
|
199
|
+
};
|
|
200
|
+
const { data: { [userChain]: { walletByENS }, }, } = await this.client.query({
|
|
201
|
+
query: query[userChain],
|
|
202
|
+
variables: { ensName, filter: { contractTokens: nfts } },
|
|
203
|
+
});
|
|
204
|
+
return !!walletByENS?.walletNFTs?.length;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
__decorate([
|
|
208
|
+
ValidateInput(walletByAddressValidator),
|
|
209
|
+
__metadata("design:type", Function),
|
|
210
|
+
__metadata("design:paramtypes", [Object]),
|
|
211
|
+
__metadata("design:returntype", Promise)
|
|
212
|
+
], NftsController.prototype, "getByWallet", null);
|
|
213
|
+
__decorate([
|
|
214
|
+
ValidateInput(nftTrendingCollectionsValidator),
|
|
215
|
+
__metadata("design:type", Function),
|
|
216
|
+
__metadata("design:paramtypes", [Object]),
|
|
217
|
+
__metadata("design:returntype", Promise)
|
|
218
|
+
], NftsController.prototype, "getTrendingCollections", null);
|
|
219
|
+
__decorate([
|
|
220
|
+
ValidateInput(nftsByContractAddressValidator),
|
|
221
|
+
__metadata("design:type", Function),
|
|
222
|
+
__metadata("design:paramtypes", [Object]),
|
|
223
|
+
__metadata("design:returntype", Promise)
|
|
224
|
+
], NftsController.prototype, "getByContractAddress", null);
|
|
225
|
+
__decorate([
|
|
226
|
+
ValidateInput(nftDetailsValidator),
|
|
227
|
+
__metadata("design:type", Function),
|
|
228
|
+
__metadata("design:paramtypes", [Object]),
|
|
229
|
+
__metadata("design:returntype", Promise)
|
|
230
|
+
], NftsController.prototype, "getNFTDetails", null);
|
|
231
|
+
__decorate([
|
|
232
|
+
ValidateInput(nftCollectionDetailsValidator),
|
|
233
|
+
__metadata("design:type", Function),
|
|
234
|
+
__metadata("design:paramtypes", [Object]),
|
|
235
|
+
__metadata("design:returntype", Promise)
|
|
236
|
+
], NftsController.prototype, "getCollectionDetails", null);
|
|
237
|
+
__decorate([
|
|
238
|
+
ValidateInput(verifyOwnershipValidator),
|
|
239
|
+
__metadata("design:type", Function),
|
|
240
|
+
__metadata("design:paramtypes", [Object]),
|
|
241
|
+
__metadata("design:returntype", Promise)
|
|
242
|
+
], NftsController.prototype, "verifyOwnership", null);
|
|
243
|
+
|
|
244
|
+
export { NftsController };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
3
|
+
import { balancesByWalletAddressValidator } from '../types/tokens/getBalancesByWalletAddress.js';
|
|
4
|
+
import { CodegenEthMainnetBalancesByWalletENSDocument, CodegenPolygonMainnetBalancesByWalletENSDocument, CodegenEthSepoliaBalancesByWalletENSDocument, CodegenEthMainnetBalancesByWalletAddressDocument, CodegenPolygonMainnetBalancesByWalletAddressDocument, CodegenEthSepoliaBalancesByWalletAddressDocument } from '../graphql/generatedTypes.js';
|
|
5
|
+
import { emptyPageInfo } from '../utils/helpers.js';
|
|
6
|
+
import { formatQueryResult } from '../utils/postQueryFormatter.js';
|
|
7
|
+
import { isValidENSAddress } from '../utils/isValidENSAddress.js';
|
|
8
|
+
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
9
|
+
|
|
10
|
+
class TokensController {
|
|
11
|
+
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
this.defaultChain = defaultChain;
|
|
14
|
+
}
|
|
15
|
+
async getBalancesByWallet(variables) {
|
|
16
|
+
const { address, ...allVariables } = variables;
|
|
17
|
+
if (isValidENSAddress(address)) {
|
|
18
|
+
return this.getBalancesByWalletENS({
|
|
19
|
+
ensName: address,
|
|
20
|
+
...allVariables,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return this.getBalancesByWalletAddress({
|
|
24
|
+
address,
|
|
25
|
+
...allVariables,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async getBalancesByWalletENS(variables) {
|
|
29
|
+
const { chain, ...queryVariables } = variables;
|
|
30
|
+
const userChain = chain || this.defaultChain;
|
|
31
|
+
const query = {
|
|
32
|
+
ethereum: CodegenEthMainnetBalancesByWalletENSDocument,
|
|
33
|
+
polygon: CodegenPolygonMainnetBalancesByWalletENSDocument,
|
|
34
|
+
ethereumSepolia: CodegenEthSepoliaBalancesByWalletENSDocument,
|
|
35
|
+
};
|
|
36
|
+
const { data: { [userChain]: { walletByENS }, }, } = await this.client.query({
|
|
37
|
+
variables: queryVariables,
|
|
38
|
+
query: query[userChain],
|
|
39
|
+
});
|
|
40
|
+
if (!walletByENS?.tokenBalances?.length) {
|
|
41
|
+
// Address can still be valid ENS name, but not have any balances
|
|
42
|
+
const address = walletByENS?.address || '';
|
|
43
|
+
const ensName = walletByENS?.ensName || '';
|
|
44
|
+
return {
|
|
45
|
+
address: address,
|
|
46
|
+
ensName: ensName,
|
|
47
|
+
results: [],
|
|
48
|
+
pageInfo: emptyPageInfo,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const formattedResult = formatQueryResult(walletByENS, 'tokenBalances', 'tokenBalancesPageInfo', null, this.flattenBalanceResponses // Remove the "contract" key and move info to balance result body
|
|
52
|
+
);
|
|
53
|
+
return formattedResult;
|
|
54
|
+
}
|
|
55
|
+
async getBalancesByWalletAddress(variables) {
|
|
56
|
+
const { chain, ...queryVariables } = variables;
|
|
57
|
+
const userChain = chain || this.defaultChain;
|
|
58
|
+
const query = {
|
|
59
|
+
ethereum: CodegenEthMainnetBalancesByWalletAddressDocument,
|
|
60
|
+
polygon: CodegenPolygonMainnetBalancesByWalletAddressDocument,
|
|
61
|
+
ethereumSepolia: CodegenEthSepoliaBalancesByWalletAddressDocument,
|
|
62
|
+
};
|
|
63
|
+
const { data: { [userChain]: { walletByAddress }, }, } = await this.client.query({
|
|
64
|
+
variables: queryVariables,
|
|
65
|
+
query: query[userChain],
|
|
66
|
+
});
|
|
67
|
+
if (!walletByAddress?.tokenBalances?.length) {
|
|
68
|
+
// Address can still be valid address, but not have any balances
|
|
69
|
+
const address = walletByAddress?.address || '';
|
|
70
|
+
const ensName = walletByAddress?.ensName || '';
|
|
71
|
+
return {
|
|
72
|
+
address: address,
|
|
73
|
+
ensName: ensName,
|
|
74
|
+
results: [],
|
|
75
|
+
pageInfo: emptyPageInfo,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const formattedResult = formatQueryResult(walletByAddress, 'tokenBalances', 'tokenBalancesPageInfo', null, this.flattenBalanceResponses // Remove the "contract" key and move info to balance result body
|
|
79
|
+
);
|
|
80
|
+
return formattedResult;
|
|
81
|
+
}
|
|
82
|
+
flattenBalanceResponses(response) {
|
|
83
|
+
const modifiedResults = response.results.map((result) => {
|
|
84
|
+
const { contract: { ...contractInfo }, ...balanceInfo } = result;
|
|
85
|
+
return { ...balanceInfo, ...contractInfo };
|
|
86
|
+
});
|
|
87
|
+
response.results = modifiedResults;
|
|
88
|
+
return response;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
__decorate([
|
|
92
|
+
ValidateInput(balancesByWalletAddressValidator),
|
|
93
|
+
__metadata("design:type", Function),
|
|
94
|
+
__metadata("design:paramtypes", [Object]),
|
|
95
|
+
__metadata("design:returntype", Promise)
|
|
96
|
+
], TokensController.prototype, "getBalancesByWallet", null);
|
|
97
|
+
|
|
98
|
+
export { TokensController };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
3
|
+
import { transactionsBySearchValidator } from '../types/transactions/getBySearch.js';
|
|
4
|
+
import { transactionsByHashValidator } from '../types/transactions/getByHash.js';
|
|
5
|
+
import { CodegenEthMainnetTransactionsByWalletAddressDocument, CodegenPolygonMainnetTransactionsByWalletAddressDocument, CodegenEthSepoliaTransactionsByWalletAddressDocument, CodegenEthMainnetTransactionsByWalletENSDocument, CodegenPolygonMainnetTransactionsByWalletENSDocument, CodegenEthSepoliaTransactionsByWalletENSDocument, CodegenEthMainnetTransactionsBySearchDocument, CodegenPolygonMainnetTransactionsBySearchDocument, CodegenEthSepoliaTransactionsBySearchDocument, CodegenEthMainnetTransactionsByHashDocument, CodegenPolygonMainnetTransactionsByHashDocument, CodegenEthSepoliaTransactionsByHashDocument } from '../graphql/generatedTypes.js';
|
|
6
|
+
import { emptyPageInfo } from '../utils/helpers.js';
|
|
7
|
+
import { formatQueryResult } from '../utils/postQueryFormatter.js';
|
|
8
|
+
import { isValidENSAddress } from '../utils/isValidENSAddress.js';
|
|
9
|
+
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
10
|
+
import { balancesByWalletAddressValidator } from '../types/tokens/getBalancesByWalletAddress.js';
|
|
11
|
+
|
|
12
|
+
class TransactionsController {
|
|
13
|
+
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.defaultChain = defaultChain;
|
|
16
|
+
}
|
|
17
|
+
async getByWallet(variables) {
|
|
18
|
+
const { address, ...allVariables } = variables;
|
|
19
|
+
let queryResult;
|
|
20
|
+
if (isValidENSAddress(address)) {
|
|
21
|
+
queryResult = await this.getByWalletENS({
|
|
22
|
+
ensName: address,
|
|
23
|
+
...allVariables,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
queryResult = await this.getByWalletAddress({
|
|
28
|
+
address,
|
|
29
|
+
...allVariables,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (!queryResult?.transactions?.length) {
|
|
33
|
+
// Address can still be valid address, but not have any transactions
|
|
34
|
+
const address = queryResult?.address || '';
|
|
35
|
+
const ensName = queryResult?.ensName || '';
|
|
36
|
+
return {
|
|
37
|
+
address: address,
|
|
38
|
+
ensName: ensName,
|
|
39
|
+
results: [],
|
|
40
|
+
pageInfo: emptyPageInfo,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const formattedResult = formatQueryResult(queryResult, 'transactions', 'transactionsPageInfo');
|
|
44
|
+
return formattedResult;
|
|
45
|
+
}
|
|
46
|
+
async getByWalletAddress(variables) {
|
|
47
|
+
const { chain, ...queryVariables } = variables;
|
|
48
|
+
const userChain = chain || this.defaultChain;
|
|
49
|
+
const query = {
|
|
50
|
+
ethereum: CodegenEthMainnetTransactionsByWalletAddressDocument,
|
|
51
|
+
polygon: CodegenPolygonMainnetTransactionsByWalletAddressDocument,
|
|
52
|
+
ethereumSepolia: CodegenEthSepoliaTransactionsByWalletAddressDocument,
|
|
53
|
+
};
|
|
54
|
+
const { data: { [userChain]: { walletByAddress }, }, } = await this.client.query({
|
|
55
|
+
variables: queryVariables,
|
|
56
|
+
query: query[userChain],
|
|
57
|
+
});
|
|
58
|
+
return walletByAddress;
|
|
59
|
+
}
|
|
60
|
+
async getByWalletENS(variables) {
|
|
61
|
+
const { chain, ...queryVariables } = variables;
|
|
62
|
+
const userChain = chain || this.defaultChain;
|
|
63
|
+
const query = {
|
|
64
|
+
ethereum: CodegenEthMainnetTransactionsByWalletENSDocument,
|
|
65
|
+
polygon: CodegenPolygonMainnetTransactionsByWalletENSDocument,
|
|
66
|
+
ethereumSepolia: CodegenEthSepoliaTransactionsByWalletENSDocument,
|
|
67
|
+
};
|
|
68
|
+
const { data: { [userChain]: { walletByENS }, }, } = await this.client.query({
|
|
69
|
+
variables: queryVariables,
|
|
70
|
+
query: query[userChain],
|
|
71
|
+
});
|
|
72
|
+
return walletByENS;
|
|
73
|
+
}
|
|
74
|
+
async getAll(variables) {
|
|
75
|
+
const { chain, ...queryVariables } = variables;
|
|
76
|
+
const userChain = chain || this.defaultChain;
|
|
77
|
+
const query = {
|
|
78
|
+
ethereum: CodegenEthMainnetTransactionsBySearchDocument,
|
|
79
|
+
polygon: CodegenPolygonMainnetTransactionsBySearchDocument,
|
|
80
|
+
ethereumSepolia: CodegenEthSepoliaTransactionsBySearchDocument,
|
|
81
|
+
};
|
|
82
|
+
const { data: { [userChain]: transactions }, } = await this.client.query({
|
|
83
|
+
variables: queryVariables,
|
|
84
|
+
query: query[userChain],
|
|
85
|
+
});
|
|
86
|
+
const formattedResult = formatQueryResult(transactions, 'transactions', 'transactionsPageInfo');
|
|
87
|
+
return formattedResult;
|
|
88
|
+
}
|
|
89
|
+
async getByHash(variables) {
|
|
90
|
+
const { chain, ...queryVariables } = variables;
|
|
91
|
+
const userChain = chain || this.defaultChain;
|
|
92
|
+
const query = {
|
|
93
|
+
ethereum: CodegenEthMainnetTransactionsByHashDocument,
|
|
94
|
+
polygon: CodegenPolygonMainnetTransactionsByHashDocument,
|
|
95
|
+
ethereumSepolia: CodegenEthSepoliaTransactionsByHashDocument,
|
|
96
|
+
};
|
|
97
|
+
const { data: { [userChain]: transaction }, } = await this.client.query({
|
|
98
|
+
variables: queryVariables,
|
|
99
|
+
query: query[userChain],
|
|
100
|
+
});
|
|
101
|
+
if (transaction?.transaction)
|
|
102
|
+
return transaction;
|
|
103
|
+
return { transaction: null };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
__decorate([
|
|
107
|
+
ValidateInput(balancesByWalletAddressValidator),
|
|
108
|
+
__metadata("design:type", Function),
|
|
109
|
+
__metadata("design:paramtypes", [Object]),
|
|
110
|
+
__metadata("design:returntype", Promise)
|
|
111
|
+
], TransactionsController.prototype, "getByWallet", null);
|
|
112
|
+
__decorate([
|
|
113
|
+
ValidateInput(transactionsBySearchValidator),
|
|
114
|
+
__metadata("design:type", Function),
|
|
115
|
+
__metadata("design:paramtypes", [Object]),
|
|
116
|
+
__metadata("design:returntype", Promise)
|
|
117
|
+
], TransactionsController.prototype, "getAll", null);
|
|
118
|
+
__decorate([
|
|
119
|
+
ValidateInput(transactionsByHashValidator),
|
|
120
|
+
__metadata("design:type", Function),
|
|
121
|
+
__metadata("design:paramtypes", [Object]),
|
|
122
|
+
__metadata("design:returntype", Promise)
|
|
123
|
+
], TransactionsController.prototype, "getByHash", null);
|
|
124
|
+
|
|
125
|
+
export { TransactionsController };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
3
|
+
import { gasPricesValidator } from '../types/utils/gasPrices.js';
|
|
4
|
+
import { CodegenEthMainnetGasPricesDocument, CodegenPolygonMainnetGasPricesDocument, CodegenEthSepoliaGasPricesDocument } from '../graphql/generatedTypes.js';
|
|
5
|
+
import { weiToGwei } from '../utils/helpers.js';
|
|
6
|
+
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
7
|
+
|
|
8
|
+
class UtilsController {
|
|
9
|
+
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
10
|
+
this.client = client;
|
|
11
|
+
this.defaultChain = defaultChain;
|
|
12
|
+
}
|
|
13
|
+
async getGasPrices(variables) {
|
|
14
|
+
const { chain, ...queryVariables } = variables;
|
|
15
|
+
const returnInGwei = variables.returnInGwei || false;
|
|
16
|
+
const userChain = chain || this.defaultChain;
|
|
17
|
+
const query = {
|
|
18
|
+
ethereum: CodegenEthMainnetGasPricesDocument,
|
|
19
|
+
polygon: CodegenPolygonMainnetGasPricesDocument,
|
|
20
|
+
ethereumSepolia: CodegenEthSepoliaGasPricesDocument,
|
|
21
|
+
};
|
|
22
|
+
const { data: { [userChain]: { gasPrices }, }, } = await this.client.query({
|
|
23
|
+
query: query[userChain],
|
|
24
|
+
variables: queryVariables,
|
|
25
|
+
});
|
|
26
|
+
if (Array.isArray(gasPrices) && gasPrices.length > 0) {
|
|
27
|
+
if (returnInGwei) {
|
|
28
|
+
const fieldsToTransform = [
|
|
29
|
+
'total',
|
|
30
|
+
'average',
|
|
31
|
+
'ceiling',
|
|
32
|
+
'floor',
|
|
33
|
+
'median',
|
|
34
|
+
];
|
|
35
|
+
const modifiedGasPrices = gasPrices.map((gasPrice) => {
|
|
36
|
+
fieldsToTransform.map((field) => {
|
|
37
|
+
gasPrice[field] = weiToGwei(gasPrice[field]);
|
|
38
|
+
});
|
|
39
|
+
return gasPrice;
|
|
40
|
+
});
|
|
41
|
+
return { gasPrices: modifiedGasPrices };
|
|
42
|
+
}
|
|
43
|
+
return { gasPrices };
|
|
44
|
+
}
|
|
45
|
+
return { gasPrices: [] };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
__decorate([
|
|
49
|
+
ValidateInput(gasPricesValidator),
|
|
50
|
+
__metadata("design:type", Function),
|
|
51
|
+
__metadata("design:paramtypes", [Object]),
|
|
52
|
+
__metadata("design:returntype", Promise)
|
|
53
|
+
], UtilsController.prototype, "getGasPrices", null);
|
|
54
|
+
|
|
55
|
+
export { UtilsController };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { removeNodesAndEdges } from '../utils/removeNodesAndEdges.js';
|
|
2
|
+
|
|
3
|
+
class CustomUrqlClient {
|
|
4
|
+
constructor(urqlClient) {
|
|
5
|
+
this.urqlClient = urqlClient;
|
|
6
|
+
}
|
|
7
|
+
async query(options) {
|
|
8
|
+
const { query, variables, ...additionalOptions } = options;
|
|
9
|
+
const result = await this.urqlClient.query(query, variables, additionalOptions);
|
|
10
|
+
const { error } = result;
|
|
11
|
+
if (error) {
|
|
12
|
+
console.error(error.stack);
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
...result,
|
|
17
|
+
data: result?.data &&
|
|
18
|
+
removeNodesAndEdges(result.data),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { CustomUrqlClient };
|