@quicknode/sdk 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/cjs/index.js +443 -190
- 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 +34 -0
- package/esm/src/api/controllers/events.js +113 -0
- package/esm/src/api/controllers/nfts.js +227 -0
- package/esm/src/api/controllers/tokens.js +93 -0
- package/esm/src/api/controllers/transactions.js +120 -0
- package/esm/src/api/controllers/utils.js +53 -0
- package/esm/src/api/graphql/customUrqlClient.js +23 -0
- package/esm/src/api/graphql/generatedTypes.js +22 -0
- package/esm/src/api/graphql/modifyQueryForChain.js +27 -0
- package/esm/src/api/graphql/schema.json.js +3 -0
- package/esm/src/api/index.d.ts +2681 -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 +594 -41
- package/package.json +26 -4
- package/esm/index.js +0 -1160
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isEvmAddress, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
// Using zod for runtime validation
|
|
5
|
+
const contractDetailsValidator = z
|
|
6
|
+
.object({
|
|
7
|
+
contractAddress: isEvmAddress,
|
|
8
|
+
})
|
|
9
|
+
.merge(supportedChainInput)
|
|
10
|
+
.strict();
|
|
11
|
+
|
|
12
|
+
export { contractDetailsValidator };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isEvmAddress, baseEventsInput, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const contractEventsValidator = z
|
|
5
|
+
.object({
|
|
6
|
+
contractAddress: isEvmAddress,
|
|
7
|
+
})
|
|
8
|
+
.merge(baseEventsInput)
|
|
9
|
+
.merge(supportedChainInput)
|
|
10
|
+
.strict();
|
|
11
|
+
|
|
12
|
+
export { contractEventsValidator };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isEvmAddress, paginationParams, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const nftsByContractAddressValidator = z
|
|
5
|
+
.object({ contractAddress: isEvmAddress })
|
|
6
|
+
.merge(paginationParams)
|
|
7
|
+
.merge(supportedChainInput)
|
|
8
|
+
.strict();
|
|
9
|
+
|
|
10
|
+
export { nftsByContractAddressValidator };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isENSAddress, isEvmAddress, contractTokensFilter, paginationParams, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const walletByAddressValidator = z
|
|
5
|
+
.object({
|
|
6
|
+
address: z.union([isENSAddress, isEvmAddress]),
|
|
7
|
+
filter: z
|
|
8
|
+
.object({
|
|
9
|
+
contractTokens: contractTokensFilter,
|
|
10
|
+
})
|
|
11
|
+
.strict()
|
|
12
|
+
.optional(),
|
|
13
|
+
})
|
|
14
|
+
.merge(paginationParams)
|
|
15
|
+
.merge(supportedChainInput)
|
|
16
|
+
.strict();
|
|
17
|
+
|
|
18
|
+
export { walletByAddressValidator };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isEvmAddress, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const nftCollectionDetailsValidator = z
|
|
5
|
+
.object({
|
|
6
|
+
contractAddress: isEvmAddress,
|
|
7
|
+
})
|
|
8
|
+
.merge(supportedChainInput)
|
|
9
|
+
.strict();
|
|
10
|
+
|
|
11
|
+
export { nftCollectionDetailsValidator };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isEvmAddress, baseEventsInput, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const collectionEventsValidator = z
|
|
5
|
+
.object({
|
|
6
|
+
contractAddress: isEvmAddress,
|
|
7
|
+
})
|
|
8
|
+
.merge(baseEventsInput)
|
|
9
|
+
.merge(supportedChainInput)
|
|
10
|
+
.strict();
|
|
11
|
+
|
|
12
|
+
export { collectionEventsValidator };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isEvmAddress, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const nftDetailsValidator = z
|
|
5
|
+
.object({ contractAddress: isEvmAddress, tokenId: z.string() })
|
|
6
|
+
.merge(supportedChainInput)
|
|
7
|
+
.strict();
|
|
8
|
+
|
|
9
|
+
export { nftDetailsValidator };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isEvmAddress, baseEventsInput, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const nftEventsValidator = z
|
|
5
|
+
.object({
|
|
6
|
+
contractAddress: isEvmAddress,
|
|
7
|
+
tokenId: z.string(),
|
|
8
|
+
})
|
|
9
|
+
.merge(baseEventsInput)
|
|
10
|
+
.merge(supportedChainInput)
|
|
11
|
+
.strict();
|
|
12
|
+
|
|
13
|
+
export { nftEventsValidator };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isENSAddress, isEvmAddress, contractTokensFilter, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const verifyOwnershipValidator = z
|
|
5
|
+
.object({
|
|
6
|
+
address: z.union([isENSAddress, isEvmAddress]),
|
|
7
|
+
nfts: contractTokensFilter,
|
|
8
|
+
})
|
|
9
|
+
.merge(supportedChainInput)
|
|
10
|
+
.strict();
|
|
11
|
+
|
|
12
|
+
export { verifyOwnershipValidator };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isENSAddress, isEvmAddress, paginationParams, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const balancesByWalletAddressValidator = z
|
|
5
|
+
.object({
|
|
6
|
+
address: z.union([isENSAddress, isEvmAddress]),
|
|
7
|
+
})
|
|
8
|
+
.merge(paginationParams)
|
|
9
|
+
.merge(supportedChainInput)
|
|
10
|
+
.strict();
|
|
11
|
+
|
|
12
|
+
export { balancesByWalletAddressValidator };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isEvmTransactionHash, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const transactionsByHashValidator = z
|
|
5
|
+
.object({
|
|
6
|
+
hash: isEvmTransactionHash,
|
|
7
|
+
})
|
|
8
|
+
.merge(supportedChainInput)
|
|
9
|
+
.strict();
|
|
10
|
+
|
|
11
|
+
export { transactionsByHashValidator };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { gasPriceFilters, supportedChainInput } from '../../../lib/validation/validators.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const gasPricesValidator = z
|
|
5
|
+
.object({
|
|
6
|
+
returnInGwei: z.boolean().nullish(),
|
|
7
|
+
filter: gasPriceFilters.nullish(),
|
|
8
|
+
})
|
|
9
|
+
.merge(supportedChainInput)
|
|
10
|
+
.strict();
|
|
11
|
+
|
|
12
|
+
export { gasPricesValidator };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://eips.ethereum.org/EIPS/eip-137#name-syntax
|
|
3
|
+
*
|
|
4
|
+
* explanation of the regex pattern:
|
|
5
|
+
* ^ Matches the start of the string
|
|
6
|
+
* (?=.{3,255}$) Lookahead assertion for the length of the string (3 to 255 characters)
|
|
7
|
+
* [\p{L}\p{N}\p{Pd}\p{M}\p{S}\u{1F300}-\u{1F6FF}]+ Matches one or more Unicode letter, number, punctuation, symbol, or character in the specified emoji range
|
|
8
|
+
* (\.[\p{L}\p{N}\p{Pd}\p{M}\p{S}\u{1F300}-\u{1F6FF}]+)* Matches zero or more occurrences of a dot followed by one or more Unicode characters
|
|
9
|
+
* \.(?:eth|xyz|art) Matches a dot followed by either 'eth', 'xyz', or 'art'
|
|
10
|
+
* $ Matches the end of the string
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
function isValidENSAddress(ensAddress) {
|
|
14
|
+
const allowedTLDs = ['eth', 'xyz', 'art'];
|
|
15
|
+
const unicodeAndEmojis = '[\\p{L}\\p{N}\\p{Pd}\\p{M}\\p{S}\\u{1F300}-\\u{1F6FF}]';
|
|
16
|
+
const regexPattern = `^(?=.{3,255}$)${unicodeAndEmojis}+(\\.${unicodeAndEmojis}+)*\\.(?:${allowedTLDs.join('|')})$`;
|
|
17
|
+
const regex = new RegExp(regexPattern, 'mu');
|
|
18
|
+
return regex.test(ensAddress);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { isValidENSAddress };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Formats the query result with the edges and nodes removed into what we want to return to the user
|
|
2
|
+
function formatQueryResult(queryResult, resultsKey, // Key that the actual results are in
|
|
3
|
+
paginationKey, // Key that the pagination info is in
|
|
4
|
+
resultsKeyToRemove, // Key that the results are nested under to remove for each entry
|
|
5
|
+
additionalModification) {
|
|
6
|
+
const additionaProperties = Object.fromEntries(Object.entries(queryResult).filter(([key]) => key !== resultsKey && key !== paginationKey));
|
|
7
|
+
let trimmedResults = queryResult[resultsKey];
|
|
8
|
+
if (resultsKeyToRemove) {
|
|
9
|
+
trimmedResults = trimmedResults.map((result) => result[resultsKeyToRemove] || {});
|
|
10
|
+
}
|
|
11
|
+
const formattedResultBase = {
|
|
12
|
+
results: trimmedResults,
|
|
13
|
+
pageInfo: queryResult[paginationKey],
|
|
14
|
+
};
|
|
15
|
+
let result = {
|
|
16
|
+
...formattedResultBase,
|
|
17
|
+
...additionaProperties,
|
|
18
|
+
};
|
|
19
|
+
if (additionalModification)
|
|
20
|
+
result = additionalModification(result);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { formatQueryResult };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function isConnection(object) {
|
|
2
|
+
return (typeof object === 'object' &&
|
|
3
|
+
!!object &&
|
|
4
|
+
('edges' in object ||
|
|
5
|
+
'total' in object ||
|
|
6
|
+
'pageInfo' in object ||
|
|
7
|
+
'breadcrumbs' in object));
|
|
8
|
+
}
|
|
9
|
+
function removeNodesAndEdges(data) {
|
|
10
|
+
const keys = Object.keys(data);
|
|
11
|
+
const output = {};
|
|
12
|
+
keys.forEach((key) => {
|
|
13
|
+
const value = data[key];
|
|
14
|
+
if (typeof value === 'string' ||
|
|
15
|
+
typeof value === 'boolean' ||
|
|
16
|
+
typeof value === 'number' ||
|
|
17
|
+
value === null ||
|
|
18
|
+
value === undefined) {
|
|
19
|
+
return (output[key] = value);
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
// An array can just be an array of strings and not edges and nodes
|
|
23
|
+
if (value.every((val) => typeof val === 'string')) {
|
|
24
|
+
return (output[key] = value);
|
|
25
|
+
}
|
|
26
|
+
return (output[key] = value.map((item) => removeNodesAndEdges(item)));
|
|
27
|
+
}
|
|
28
|
+
if (isConnection(value)) {
|
|
29
|
+
if (value.breadcrumbs)
|
|
30
|
+
output[`${key}Breadcrumbs`] = value.breadcrumbs;
|
|
31
|
+
if (value.total)
|
|
32
|
+
output[`${key}Total`] = value.total;
|
|
33
|
+
if (value.viewport)
|
|
34
|
+
output[`${key}Viewport`] = value.viewport;
|
|
35
|
+
if (value.pageInfo) {
|
|
36
|
+
const { ...pageInfoRest } = value.pageInfo;
|
|
37
|
+
output[`${key}PageInfo`] = pageInfoRest;
|
|
38
|
+
}
|
|
39
|
+
return (output[key] = value.edges?.map((item) => {
|
|
40
|
+
if (item.node) {
|
|
41
|
+
return removeNodesAndEdges(item.node);
|
|
42
|
+
}
|
|
43
|
+
return item;
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
return (output[key] = removeNodesAndEdges(value));
|
|
47
|
+
});
|
|
48
|
+
return output;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { removeNodesAndEdges };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { formatErrors } from '../../../lib/validation/ValidateInput.js';
|
|
2
|
+
import { checkAddOnEnabled } from '../shared/helpers.js';
|
|
3
|
+
import { qnFetchNFTInputSchema } from './types/qn_fetchNFTs.js';
|
|
4
|
+
import { qnFetchNFTCollectionDetailsInputSchema } from './types/qn_fetchNFTCollectionDetails.js';
|
|
5
|
+
import { qnFetchNFTsByCollectionInputSchema } from './types/qn_fetchNFTsByCollection.js';
|
|
6
|
+
import { qnGetTransfersByNFTInputSchema } from './types/qn_getTransfersByNFT.js';
|
|
7
|
+
import { qnVerifyNFTsOwnerInputSchema } from './types/qn_verifyNFTsOwner.js';
|
|
8
|
+
import { qnGetTokenMetadataByCAInputSchema } from './types/qn_getTokenMetadataByContractAddress.js';
|
|
9
|
+
import { qnGetTokenMetadataBySymbolInputSchema } from './types/qn_getTokenMetadataBySymbol.js';
|
|
10
|
+
import { qnGetTransactionsByAddressInputSchema } from './types/qn_getTransactionsByAddress.js';
|
|
11
|
+
import { qnGetWalletTokenBalanceInputSchema } from './types/qn_getWalletTokenBalance.js';
|
|
12
|
+
import { qnGetWalletTokenTransactionsInputSchema } from './types/qn_getWalletTokenTransactions.js';
|
|
13
|
+
|
|
14
|
+
function nftAndTokenValidator(config, schema, args) {
|
|
15
|
+
checkAddOnEnabled(config.addOns?.nftTokenV2 ?? false, 'NFT And Token RPC API V2', 'nftTokenV2');
|
|
16
|
+
// Uses zod to validate schema at runtime
|
|
17
|
+
const validation = schema.safeParse(args);
|
|
18
|
+
if (!validation.success) {
|
|
19
|
+
const formattedErrors = formatErrors(validation.error);
|
|
20
|
+
if (formattedErrors)
|
|
21
|
+
throw formattedErrors;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const nftAndTokenActions = (client, config) => ({
|
|
25
|
+
async qn_fetchNFTCollectionDetails(args) {
|
|
26
|
+
nftAndTokenValidator(config, qnFetchNFTCollectionDetailsInputSchema, args);
|
|
27
|
+
const response = await client.request({
|
|
28
|
+
method: 'qn_fetchNFTCollectionDetails',
|
|
29
|
+
params: [args],
|
|
30
|
+
});
|
|
31
|
+
return response;
|
|
32
|
+
},
|
|
33
|
+
async qn_fetchNFTs(args) {
|
|
34
|
+
nftAndTokenValidator(config, qnFetchNFTInputSchema, args);
|
|
35
|
+
const response = await client.request({
|
|
36
|
+
method: 'qn_fetchNFTs',
|
|
37
|
+
params: [args],
|
|
38
|
+
});
|
|
39
|
+
return response;
|
|
40
|
+
},
|
|
41
|
+
async qn_fetchNFTsByCollection(args) {
|
|
42
|
+
nftAndTokenValidator(config, qnFetchNFTsByCollectionInputSchema, args);
|
|
43
|
+
const response = await client.request({
|
|
44
|
+
method: 'qn_fetchNFTsByCollection',
|
|
45
|
+
params: [args],
|
|
46
|
+
});
|
|
47
|
+
return response;
|
|
48
|
+
},
|
|
49
|
+
async qn_getTransfersByNFT(args) {
|
|
50
|
+
nftAndTokenValidator(config, qnGetTransfersByNFTInputSchema, args);
|
|
51
|
+
const response = await client.request({
|
|
52
|
+
method: 'qn_getTransfersByNFT',
|
|
53
|
+
params: [args],
|
|
54
|
+
});
|
|
55
|
+
return response;
|
|
56
|
+
},
|
|
57
|
+
async qn_verifyNFTsOwner(args) {
|
|
58
|
+
nftAndTokenValidator(config, qnVerifyNFTsOwnerInputSchema, args);
|
|
59
|
+
const response = await client.request({
|
|
60
|
+
method: 'qn_verifyNFTsOwner',
|
|
61
|
+
params: [args],
|
|
62
|
+
});
|
|
63
|
+
return response;
|
|
64
|
+
},
|
|
65
|
+
async qn_getTokenMetadataByContractAddress(args) {
|
|
66
|
+
nftAndTokenValidator(config, qnGetTokenMetadataByCAInputSchema, args);
|
|
67
|
+
const response = await client.request({
|
|
68
|
+
method: 'qn_getTokenMetadataByContractAddress',
|
|
69
|
+
params: [args],
|
|
70
|
+
});
|
|
71
|
+
return response;
|
|
72
|
+
},
|
|
73
|
+
async qn_getTokenMetadataBySymbol(args) {
|
|
74
|
+
nftAndTokenValidator(config, qnGetTokenMetadataBySymbolInputSchema, args);
|
|
75
|
+
const response = await client.request({
|
|
76
|
+
method: 'qn_getTokenMetadataBySymbol',
|
|
77
|
+
params: [args],
|
|
78
|
+
});
|
|
79
|
+
return response;
|
|
80
|
+
},
|
|
81
|
+
async qn_getTransactionsByAddress(args) {
|
|
82
|
+
nftAndTokenValidator(config, qnGetTransactionsByAddressInputSchema, args);
|
|
83
|
+
const response = await client.request({
|
|
84
|
+
method: 'qn_getTransactionsByAddress',
|
|
85
|
+
params: [args],
|
|
86
|
+
});
|
|
87
|
+
return response;
|
|
88
|
+
},
|
|
89
|
+
async qn_getWalletTokenBalance(args) {
|
|
90
|
+
nftAndTokenValidator(config, qnGetWalletTokenBalanceInputSchema, args);
|
|
91
|
+
const response = await client.request({
|
|
92
|
+
method: 'qn_getWalletTokenBalance',
|
|
93
|
+
params: [args],
|
|
94
|
+
});
|
|
95
|
+
return response;
|
|
96
|
+
},
|
|
97
|
+
async qn_getWalletTokenTransactions(args) {
|
|
98
|
+
nftAndTokenValidator(config, qnGetWalletTokenTransactionsInputSchema, args);
|
|
99
|
+
const response = await client.request({
|
|
100
|
+
method: 'qn_getWalletTokenTransactions',
|
|
101
|
+
params: [args],
|
|
102
|
+
});
|
|
103
|
+
return response;
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export { nftAndTokenActions };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEvmAddress } from '../../../../lib/validation/validators.js';
|
|
3
|
+
|
|
4
|
+
const qnFetchNFTCollectionDetailsInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
contracts: z.array(isEvmAddress),
|
|
7
|
+
})
|
|
8
|
+
.strict();
|
|
9
|
+
|
|
10
|
+
export { qnFetchNFTCollectionDetailsInputSchema };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEvmAddress, rpcPaginationParams } from '../../../../lib/validation/validators.js';
|
|
3
|
+
|
|
4
|
+
const qnFetchNFTInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
wallet: isEvmAddress,
|
|
7
|
+
contracts: z.array(isEvmAddress).nullish(),
|
|
8
|
+
omitFields: z.array(z.string()).nullish(),
|
|
9
|
+
})
|
|
10
|
+
.merge(rpcPaginationParams)
|
|
11
|
+
.strict();
|
|
12
|
+
|
|
13
|
+
export { qnFetchNFTInputSchema };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEvmAddress, rpcPaginationParams } from '../../../../lib/validation/validators.js';
|
|
3
|
+
|
|
4
|
+
const qnFetchNFTsByCollectionInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
collection: isEvmAddress,
|
|
7
|
+
tokens: z.array(z.string()).nullish(),
|
|
8
|
+
omitFields: z.array(z.string()).nullish(),
|
|
9
|
+
})
|
|
10
|
+
.merge(rpcPaginationParams)
|
|
11
|
+
.strict();
|
|
12
|
+
|
|
13
|
+
export { qnFetchNFTsByCollectionInputSchema };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { rpcPaginationParams } from '../../../../lib/validation/validators.js';
|
|
3
|
+
|
|
4
|
+
const qnGetTokenMetadataBySymbolInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
symbol: z.string(),
|
|
7
|
+
})
|
|
8
|
+
.merge(rpcPaginationParams)
|
|
9
|
+
.strict();
|
|
10
|
+
|
|
11
|
+
export { qnGetTokenMetadataBySymbolInputSchema };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEvmAddress, rpcPaginationParams } from '../../../../lib/validation/validators.js';
|
|
3
|
+
|
|
4
|
+
const qnGetTransactionsByAddressInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
address: isEvmAddress,
|
|
7
|
+
fromBlock: z.number().positive().nullish(),
|
|
8
|
+
toBlock: z.number().positive().nullish(),
|
|
9
|
+
})
|
|
10
|
+
.merge(rpcPaginationParams)
|
|
11
|
+
.strict()
|
|
12
|
+
.refine(({ fromBlock, toBlock }) => {
|
|
13
|
+
if (fromBlock && toBlock)
|
|
14
|
+
return fromBlock < toBlock;
|
|
15
|
+
return true;
|
|
16
|
+
}, { message: 'fromBlock must be less than toBlock' });
|
|
17
|
+
|
|
18
|
+
export { qnGetTransactionsByAddressInputSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEvmAddress, rpcPaginationParams } from '../../../../lib/validation/validators.js';
|
|
3
|
+
|
|
4
|
+
const qnGetTransfersByNFTInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
collection: isEvmAddress,
|
|
7
|
+
collectionTokenId: z.string(),
|
|
8
|
+
})
|
|
9
|
+
.merge(rpcPaginationParams)
|
|
10
|
+
.strict();
|
|
11
|
+
|
|
12
|
+
export { qnGetTransfersByNFTInputSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEvmAddress, rpcPaginationParams } from '../../../../lib/validation/validators.js';
|
|
3
|
+
|
|
4
|
+
const qnGetWalletTokenBalanceInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
wallet: isEvmAddress,
|
|
7
|
+
contracts: z.array(isEvmAddress).nullish(),
|
|
8
|
+
})
|
|
9
|
+
.merge(rpcPaginationParams)
|
|
10
|
+
.strict();
|
|
11
|
+
|
|
12
|
+
export { qnGetWalletTokenBalanceInputSchema };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEvmAddress, rpcPaginationParams } from '../../../../lib/validation/validators.js';
|
|
3
|
+
|
|
4
|
+
const qnGetWalletTokenTransactionsInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
address: isEvmAddress,
|
|
7
|
+
contract: isEvmAddress,
|
|
8
|
+
fromBlock: z.number().positive().nullish(),
|
|
9
|
+
toBlock: z.number().positive().nullish(),
|
|
10
|
+
})
|
|
11
|
+
.merge(rpcPaginationParams)
|
|
12
|
+
.strict();
|
|
13
|
+
|
|
14
|
+
export { qnGetWalletTokenTransactionsInputSchema };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isEvmAddress } from '../../../../lib/validation/validators.js';
|
|
3
|
+
|
|
4
|
+
const qnVerifyNFTsOwnerInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
wallet: isEvmAddress,
|
|
7
|
+
contracts: z.array(z.string()), // TODO: make this enforce the address:id format
|
|
8
|
+
})
|
|
9
|
+
.strict();
|
|
10
|
+
|
|
11
|
+
export { qnVerifyNFTsOwnerInputSchema };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// We can't dynamically extend the viem client based on which add-ons are specified, which would
|
|
2
|
+
// make the types fully align with the add-ons for the client, so instead we do run-time checks to
|
|
3
|
+
// prevent calling add-ons not explicitly added in the config
|
|
4
|
+
function checkAddOnEnabled(enabled, humanName, configName) {
|
|
5
|
+
if (!enabled) {
|
|
6
|
+
throw new Error(`${humanName} is not set as enabled. Please ensure the addon is enabled on your QuickNode endpoint and enable ${configName} in the Core configuration argument`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { checkAddOnEnabled };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { QNInvalidEndpointUrl } from '../lib/errors/QNInvalidEnpointUrl.js';
|
|
2
|
+
import { QNChainNotSupported } from '../lib/errors/QNChainNotSupported.js';
|
|
3
|
+
import { arbitrum, arbitrumGoerli, avalanche, avalancheFuji, baseGoerli, bsc, bscTestnet, celo, fantom, gnosis, goerli, harmonyOne, mainnet, optimism, optimismGoerli, polygon, polygonMumbai, polygonZkEvm, polygonZkEvmTestnet, sepolia } from 'viem/chains';
|
|
4
|
+
|
|
5
|
+
const ETH_MAINNET_NETWORK = 'ethereum-mainnet';
|
|
6
|
+
const qnChainToViemChain = {
|
|
7
|
+
'arbitrum-mainnet': arbitrum,
|
|
8
|
+
'arbitrum-goerli': arbitrumGoerli,
|
|
9
|
+
'avalanche-mainnet': avalanche,
|
|
10
|
+
'avalanche-testnet': avalancheFuji,
|
|
11
|
+
'base-goerli': baseGoerli,
|
|
12
|
+
['bsc']: bsc,
|
|
13
|
+
'bsc-testnet': bscTestnet,
|
|
14
|
+
'celo-mainnet': celo,
|
|
15
|
+
['fantom']: fantom,
|
|
16
|
+
['xdai']: gnosis,
|
|
17
|
+
['gnosis']: gnosis,
|
|
18
|
+
'ethereum-goerli': goerli,
|
|
19
|
+
'harmony-mainnet': harmonyOne,
|
|
20
|
+
[ETH_MAINNET_NETWORK]: mainnet,
|
|
21
|
+
['optimism']: optimism,
|
|
22
|
+
'optimism-goerli': optimismGoerli,
|
|
23
|
+
['matic']: polygon,
|
|
24
|
+
['polygon']: polygon,
|
|
25
|
+
'matic-testnet': polygonMumbai,
|
|
26
|
+
'zkevm-mainnet': polygonZkEvm,
|
|
27
|
+
'zkevm-testnet': polygonZkEvmTestnet,
|
|
28
|
+
'ethereum-sepolia': sepolia,
|
|
29
|
+
};
|
|
30
|
+
function chainNameFromEndpoint(endpointUrl) {
|
|
31
|
+
let hostnameParts;
|
|
32
|
+
try {
|
|
33
|
+
const parsedUrl = new URL(endpointUrl);
|
|
34
|
+
hostnameParts = parsedUrl.hostname.split('.');
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw new QNInvalidEndpointUrl();
|
|
38
|
+
}
|
|
39
|
+
const quiknode = hostnameParts.at(-2);
|
|
40
|
+
const chainOrDiscover = hostnameParts.at(-3);
|
|
41
|
+
if (quiknode !== 'quiknode' || !chainOrDiscover)
|
|
42
|
+
throw new QNInvalidEndpointUrl();
|
|
43
|
+
const indexOfName = chainOrDiscover === 'discover' ? -4 : -3;
|
|
44
|
+
const lengthOfEthereum = chainOrDiscover === 'discover' ? 4 : 3;
|
|
45
|
+
if (hostnameParts.length === lengthOfEthereum)
|
|
46
|
+
return ETH_MAINNET_NETWORK;
|
|
47
|
+
const potentialChainName = hostnameParts.at(indexOfName);
|
|
48
|
+
if (potentialChainName)
|
|
49
|
+
return potentialChainName;
|
|
50
|
+
throw new QNInvalidEndpointUrl();
|
|
51
|
+
}
|
|
52
|
+
function deriveChainFromUrl(endpointUrl) {
|
|
53
|
+
const chainName = chainNameFromEndpoint(endpointUrl);
|
|
54
|
+
const viemChain = qnChainToViemChain[chainName];
|
|
55
|
+
if (viemChain)
|
|
56
|
+
return viemChain;
|
|
57
|
+
throw new QNChainNotSupported(endpointUrl);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { deriveChainFromUrl };
|