@quicknode/sdk 1.1.0 → 1.1.2
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/cjs/index.js +129 -192
- package/esm/package.json.js +1 -1
- package/esm/src/api/api.js +0 -2
- package/esm/src/api/controllers/contracts.js +6 -8
- package/esm/src/api/controllers/events.js +23 -31
- package/esm/src/api/controllers/nfts.js +44 -61
- package/esm/src/api/controllers/tokens.js +10 -15
- package/esm/src/api/controllers/transactions.js +26 -31
- package/esm/src/api/controllers/utils.js +6 -8
- package/esm/src/api/graphql/generatedTypes.js +1 -41
- package/esm/src/api/graphql/modifyQueryForChain.js +27 -0
- package/esm/src/api/index.d.ts +44 -41
- package/index.d.ts +56 -41
- package/package.json +3 -4
- package/esm/src/api/graphql/schema.json.js +0 -3
package/esm/package.json.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var name="@quicknode/sdk";var repository={type:"git",url:"https://github.com/quiknode-labs/qn-oss.git",directory:"packages/libs/sdk"};var license="MIT";var version="1.1.
|
|
1
|
+
var name="@quicknode/sdk";var repository={type:"git",url:"https://github.com/quiknode-labs/qn-oss.git",directory:"packages/libs/sdk"};var license="MIT";var version="1.1.2";var main="./cjs/index.js";var module="./esm/src/index.js";var types="./index.d.ts";var sideEffects=false;var dependencies={"@urql/core":"^4.0.7","@urql/exchange-graphcache":"^6.0.4","cross-fetch":"^3.1.6",graphql:"^16.6.0",tslib:"^2.5.3",viem:"^1.2.0",zod:"^3.21.4"};var devDependencies={"@graphql-codegen/cli":"4.0.1","@graphql-codegen/fragment-matcher":"^3.3.1","@graphql-codegen/typed-document-node":"^4.0.1","@graphql-codegen/typescript":"2.8.0","@graphql-codegen/typescript-operations":"^2.5.5","@pollyjs/adapter-node-http":"^6.0.5","@pollyjs/core":"^6.0.5","@pollyjs/persister-fs":"^6.0.5","@types/jest":"^29.5.1","@types/mocha":"^10.0.1","@types/node":"^18.13.0","@types/supertest":"^2.0.12",dotenv:"^16.0.3","eslint-plugin-no-only-tests":"^3.1.0",supertest:"^6.3.3"};var scripts={codegen:"npx graphql-codegen --require dotenv/config"};var exports={".":{"import":"./esm/src/index.js",require:"./cjs/index.js"},"./api":{"import":"./esm/src/api/index.js","default":"./cjs/src/api/index.js",types:"./esm/src/api/index.d.ts"},"./core":{"import":"./esm/src/core/index.js","default":"./cjs/src/core/index.js",types:"./esm/src/core/index.d.ts"}};var typesVersions={"*":{api:["./esm/src/api/index.d.ts"],core:["./esm/src/core/index.d.ts"]}};var packageJson = {name:name,repository:repository,license:license,version:version,main:main,module:module,types:types,sideEffects:sideEffects,dependencies:dependencies,devDependencies:devDependencies,scripts:scripts,exports:exports,typesVersions:typesVersions};
|
|
2
2
|
|
|
3
3
|
export { packageJson as default, dependencies, devDependencies, exports, license, main, module, name, repository, scripts, sideEffects, types, typesVersions, version };
|
package/esm/src/api/api.js
CHANGED
|
@@ -8,7 +8,6 @@ import { UtilsController } from './controllers/utils.js';
|
|
|
8
8
|
import { ContractsController } from './controllers/contracts.js';
|
|
9
9
|
import { EventsController } from './controllers/events.js';
|
|
10
10
|
import { DEFAULT_CHAIN } from './utils/constants.js';
|
|
11
|
-
import schema from './graphql/schema.json.js';
|
|
12
11
|
import { TransactionsController } from './controllers/transactions.js';
|
|
13
12
|
import packageJson from '../../package.json.js';
|
|
14
13
|
|
|
@@ -41,7 +40,6 @@ class API {
|
|
|
41
40
|
const useAddressAsKey = (data) => `${data['address']}`;
|
|
42
41
|
const useTransactionHashAndIndex = (data) => `${data['transactionHash']}:${data['transferIndex']}`;
|
|
43
42
|
const urqlCache = cacheExchange({
|
|
44
|
-
schema,
|
|
45
43
|
keys: {
|
|
46
44
|
EVMSchemaType: () => null,
|
|
47
45
|
Collection: useAddressAsKey,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
3
3
|
import { contractDetailsValidator } from '../types/contracts/getContractDetails.js';
|
|
4
|
-
import { CodegenEthMainnetContractDetailsDocument
|
|
4
|
+
import { CodegenEthMainnetContractDetailsDocument } from '../graphql/generatedTypes.js';
|
|
5
5
|
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
6
|
+
import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
|
|
6
7
|
|
|
7
8
|
class ContractsController {
|
|
8
9
|
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
@@ -12,15 +13,12 @@ class ContractsController {
|
|
|
12
13
|
async getDetails(variables) {
|
|
13
14
|
const { chain, ...queryVariables } = variables;
|
|
14
15
|
const userChain = chain || this.defaultChain;
|
|
15
|
-
const query =
|
|
16
|
-
|
|
17
|
-
polygon: CodegenPolygonMainnetContractDetailsDocument,
|
|
18
|
-
ethereumSepolia: CodegenEthSepoliaContractDetailsDocument,
|
|
19
|
-
};
|
|
20
|
-
const { data: { [userChain]: { contract }, }, } = await this.client.query({
|
|
16
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetContractDetailsDocument);
|
|
17
|
+
const result = await this.client.query({
|
|
21
18
|
variables: queryVariables,
|
|
22
|
-
query: query
|
|
19
|
+
query: query,
|
|
23
20
|
});
|
|
21
|
+
const contract = result?.data?.[userChain]?.contract;
|
|
24
22
|
if (contract)
|
|
25
23
|
return { contract };
|
|
26
24
|
return { contract: null };
|
|
@@ -3,11 +3,12 @@ import { contractEventsValidator } from '../types/events/getByContract.js';
|
|
|
3
3
|
import { collectionEventsValidator } from '../types/nfts/getCollectionEvents.js';
|
|
4
4
|
import { nftEventsValidator } from '../types/nfts/getNFTEvents.js';
|
|
5
5
|
import { allEventsValidator } from '../types/events/getAll.js';
|
|
6
|
-
import { CodegenEthereumMainnetEventsByContractDocument,
|
|
6
|
+
import { CodegenEthereumMainnetEventsByContractDocument, CodegenEthMainnetEventsByCollectionDocument, CodegenEthereumMainnetEventsByNftDocument, CodegenEthereumMainnetEventsGetAllDocument } from '../graphql/generatedTypes.js';
|
|
7
7
|
import { formatQueryResult } from '../utils/postQueryFormatter.js';
|
|
8
8
|
import { emptyPageInfo } from '../utils/helpers.js';
|
|
9
9
|
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
10
10
|
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
11
|
+
import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
|
|
11
12
|
|
|
12
13
|
class EventsController {
|
|
13
14
|
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
@@ -17,15 +18,12 @@ class EventsController {
|
|
|
17
18
|
async getByContract(variables) {
|
|
18
19
|
const { chain, ...queryVariables } = variables;
|
|
19
20
|
const userChain = chain || this.defaultChain;
|
|
20
|
-
const query =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
ethereumSepolia: CodegenEthereumSepoliaEventsByContractDocument,
|
|
24
|
-
};
|
|
25
|
-
const { data: { [userChain]: { contract }, }, } = await this.client.query({
|
|
26
|
-
query: query[userChain],
|
|
21
|
+
const query = modifyQueryForChain(userChain, CodegenEthereumMainnetEventsByContractDocument);
|
|
22
|
+
const result = await this.client.query({
|
|
23
|
+
query: query,
|
|
27
24
|
variables: queryVariables,
|
|
28
25
|
});
|
|
26
|
+
const contract = result?.data?.[userChain]?.contract;
|
|
29
27
|
if (!contract?.tokenEvents?.length) {
|
|
30
28
|
return {
|
|
31
29
|
results: [],
|
|
@@ -38,15 +36,12 @@ class EventsController {
|
|
|
38
36
|
async getByNFTCollection(variables) {
|
|
39
37
|
const { chain, ...queryVariables } = variables;
|
|
40
38
|
const userChain = chain || this.defaultChain;
|
|
41
|
-
const query =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
ethereumSepolia: CodegenEthSepoliaEventsByCollectionDocument,
|
|
45
|
-
};
|
|
46
|
-
const { data: { [userChain]: { collection }, }, } = await this.client.query({
|
|
47
|
-
query: query[userChain],
|
|
39
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetEventsByCollectionDocument);
|
|
40
|
+
const result = await this.client.query({
|
|
41
|
+
query: query,
|
|
48
42
|
variables: queryVariables,
|
|
49
43
|
});
|
|
44
|
+
const collection = result?.data?.[userChain]?.collection;
|
|
50
45
|
if (!collection?.tokenEvents?.length)
|
|
51
46
|
return { results: [], pageInfo: emptyPageInfo };
|
|
52
47
|
function removeKeyFields(results) {
|
|
@@ -59,15 +54,12 @@ class EventsController {
|
|
|
59
54
|
async getByNFT(variables) {
|
|
60
55
|
const { chain, ...queryVariables } = variables;
|
|
61
56
|
const userChain = chain || this.defaultChain;
|
|
62
|
-
const query =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
ethereumSepolia: CodegenEthSepoliaEventsByNftDocument,
|
|
66
|
-
};
|
|
67
|
-
const { data: { [userChain]: { nft }, }, } = await this.client.query({
|
|
68
|
-
query: query[userChain],
|
|
57
|
+
const query = modifyQueryForChain(userChain, CodegenEthereumMainnetEventsByNftDocument);
|
|
58
|
+
const result = await this.client.query({
|
|
59
|
+
query: query,
|
|
69
60
|
variables: queryVariables,
|
|
70
61
|
});
|
|
62
|
+
const nft = result?.data?.[userChain]?.nft;
|
|
71
63
|
if (!nft?.tokenEvents?.length)
|
|
72
64
|
return { results: [], pageInfo: emptyPageInfo };
|
|
73
65
|
function removeKeyFields(results) {
|
|
@@ -80,17 +72,17 @@ class EventsController {
|
|
|
80
72
|
async getAll(variables) {
|
|
81
73
|
const { chain, ...queryVariables } = variables;
|
|
82
74
|
const userChain = chain || this.defaultChain;
|
|
83
|
-
const query =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
ethereumSepolia: CodegenEthereumSepoliaEventsGetAllDocument,
|
|
87
|
-
};
|
|
88
|
-
const { data: { [userChain]: tokenEvents }, } = await this.client.query({
|
|
89
|
-
query: query[userChain],
|
|
75
|
+
const query = modifyQueryForChain(userChain, CodegenEthereumMainnetEventsGetAllDocument);
|
|
76
|
+
const result = await this.client.query({
|
|
77
|
+
query: query,
|
|
90
78
|
variables: queryVariables,
|
|
91
79
|
});
|
|
92
|
-
const
|
|
93
|
-
|
|
80
|
+
const events = result?.data?.[userChain];
|
|
81
|
+
if (events?.tokenEvents?.length) {
|
|
82
|
+
const formattedResult = formatQueryResult(events, 'tokenEvents', 'tokenEventsPageInfo');
|
|
83
|
+
return formattedResult;
|
|
84
|
+
}
|
|
85
|
+
return { results: [], pageInfo: emptyPageInfo };
|
|
94
86
|
}
|
|
95
87
|
}
|
|
96
88
|
__decorate([
|
|
@@ -5,12 +5,13 @@ import { nftCollectionDetailsValidator } from '../types/nfts/getCollectionDetail
|
|
|
5
5
|
import { nftTrendingCollectionsValidator } from '../types/nfts/getTrendingCollections.js';
|
|
6
6
|
import { nftsByContractAddressValidator } from '../types/nfts/getByContractAddress.js';
|
|
7
7
|
import { verifyOwnershipValidator } from '../types/nfts/verifyOwnershipByAddress.js';
|
|
8
|
-
import { CodegenEthMainnetWalletNFTsByEnsDocument,
|
|
8
|
+
import { CodegenEthMainnetWalletNFTsByEnsDocument, CodegenEthMainnetWalletNFTsByAddressDocument, CodegenEthMainnetTrendingCollectionsDocument, CodegenEthMainnetWalletNFTsByContractAddressDocument, CodegenEthMainnetNFTDetailsDocument, CodegenEthMainnetNftCollectionDetailsDocument, CodegenEthMainnetVerifyOwnershipByAddressDocument, CodegenEthMainnetVerifyOwnershipByENSDocument } from '../graphql/generatedTypes.js';
|
|
9
9
|
import { formatQueryResult } from '../utils/postQueryFormatter.js';
|
|
10
10
|
import { emptyPageInfo } from '../utils/helpers.js';
|
|
11
11
|
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
12
12
|
import { isValidENSAddress } from '../utils/isValidENSAddress.js';
|
|
13
13
|
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
14
|
+
import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
|
|
14
15
|
|
|
15
16
|
class NftsController {
|
|
16
17
|
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
@@ -33,15 +34,12 @@ class NftsController {
|
|
|
33
34
|
async getByWalletENS(variables) {
|
|
34
35
|
const { chain, ...queryVariables } = variables;
|
|
35
36
|
const userChain = chain || this.defaultChain;
|
|
36
|
-
const query =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
ethereumSepolia: CodegenEthSepoliaWalletNFTsByEnsDocument,
|
|
40
|
-
};
|
|
41
|
-
const { data: { [userChain]: { walletByENS }, }, } = await this.client.query({
|
|
42
|
-
query: query[userChain],
|
|
37
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetWalletNFTsByEnsDocument);
|
|
38
|
+
const result = await this.client.query({
|
|
39
|
+
query: query,
|
|
43
40
|
variables: queryVariables,
|
|
44
41
|
});
|
|
42
|
+
const walletByENS = result?.data?.[userChain]?.walletByENS;
|
|
45
43
|
if (!walletByENS?.walletNFTs?.length) {
|
|
46
44
|
// Address can still be valid ENS name, but not have any NFTs
|
|
47
45
|
const address = walletByENS?.address || '';
|
|
@@ -59,15 +57,12 @@ class NftsController {
|
|
|
59
57
|
async getByWalletAddress(variables) {
|
|
60
58
|
const { chain, ...queryVariables } = variables;
|
|
61
59
|
const userChain = chain || this.defaultChain;
|
|
62
|
-
const query =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
ethereumSepolia: CodegenEthSepoliaWalletNFTsByAddressDocument,
|
|
66
|
-
};
|
|
67
|
-
const { data: { [userChain]: { walletByAddress }, }, } = await this.client.query({
|
|
68
|
-
query: query[userChain],
|
|
60
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetWalletNFTsByAddressDocument);
|
|
61
|
+
const result = await this.client.query({
|
|
62
|
+
query: query,
|
|
69
63
|
variables: queryVariables,
|
|
70
64
|
});
|
|
65
|
+
const walletByAddress = result?.data?.[userChain]?.walletByAddress;
|
|
71
66
|
if (!walletByAddress?.walletNFTs?.length) {
|
|
72
67
|
const address = walletByAddress?.address || '';
|
|
73
68
|
const ensName = walletByAddress?.ensName || '';
|
|
@@ -84,30 +79,30 @@ class NftsController {
|
|
|
84
79
|
async getTrendingCollections(variables) {
|
|
85
80
|
const { chain, ...queryVariables } = variables;
|
|
86
81
|
const userChain = chain || this.defaultChain;
|
|
87
|
-
const query =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
ethereumSepolia: CodegenEthSepoliaTrendingCollectionsDocument,
|
|
91
|
-
};
|
|
92
|
-
const { data: { [userChain]: trendingCollections }, } = await this.client.query({
|
|
93
|
-
query: query[userChain],
|
|
82
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetTrendingCollectionsDocument);
|
|
83
|
+
const result = await this.client.query({
|
|
84
|
+
query: query,
|
|
94
85
|
variables: queryVariables,
|
|
95
86
|
});
|
|
96
|
-
const
|
|
97
|
-
|
|
87
|
+
const chainResult = result?.data?.[userChain];
|
|
88
|
+
if (chainResult?.trendingCollections?.length) {
|
|
89
|
+
const formattedResult = formatQueryResult(chainResult, 'trendingCollections', 'trendingCollectionsPageInfo', 'collection');
|
|
90
|
+
return formattedResult;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
results: [],
|
|
94
|
+
pageInfo: emptyPageInfo,
|
|
95
|
+
};
|
|
98
96
|
}
|
|
99
97
|
async getByContractAddress(variables) {
|
|
100
98
|
const { chain, ...queryVariables } = variables;
|
|
101
99
|
const userChain = chain || this.defaultChain;
|
|
102
|
-
const query =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
ethereumSepolia: CodegenEthSepoliaWalletNFTsByContractAddressDocument,
|
|
106
|
-
};
|
|
107
|
-
const { data: { [userChain]: { collection }, }, } = await this.client.query({
|
|
108
|
-
query: query[userChain],
|
|
100
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetWalletNFTsByContractAddressDocument);
|
|
101
|
+
const result = await this.client.query({
|
|
102
|
+
query: query,
|
|
109
103
|
variables: queryVariables,
|
|
110
104
|
});
|
|
105
|
+
const collection = result?.data?.[userChain]?.collection;
|
|
111
106
|
if (!collection?.nfts?.length) {
|
|
112
107
|
return {
|
|
113
108
|
standard: null,
|
|
@@ -133,15 +128,12 @@ class NftsController {
|
|
|
133
128
|
async getNFTDetails(variables) {
|
|
134
129
|
const { chain, ...queryVariables } = variables;
|
|
135
130
|
const userChain = chain || this.defaultChain;
|
|
136
|
-
const query =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ethereumSepolia: CodegenEthSepoliaNFTDetailsDocument,
|
|
140
|
-
};
|
|
141
|
-
const { data: { [userChain]: { nft }, }, } = await this.client.query({
|
|
142
|
-
query: query[userChain],
|
|
131
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetNFTDetailsDocument);
|
|
132
|
+
const result = await this.client.query({
|
|
133
|
+
query,
|
|
143
134
|
variables: queryVariables,
|
|
144
135
|
});
|
|
136
|
+
const nft = result?.data?.[userChain]?.nft;
|
|
145
137
|
if (nft)
|
|
146
138
|
return { nft };
|
|
147
139
|
return { nft: null };
|
|
@@ -149,15 +141,12 @@ class NftsController {
|
|
|
149
141
|
async getCollectionDetails(variables) {
|
|
150
142
|
const { chain, ...queryVariables } = variables;
|
|
151
143
|
const userChain = chain || this.defaultChain;
|
|
152
|
-
const query =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
ethereumSepolia: CodegenEthSepoliaNftCollectionDetailsDocument,
|
|
156
|
-
};
|
|
157
|
-
const { data: { [userChain]: { collection }, }, } = await this.client.query({
|
|
158
|
-
query: query[userChain],
|
|
144
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetNftCollectionDetailsDocument);
|
|
145
|
+
const result = await this.client.query({
|
|
146
|
+
query: query,
|
|
159
147
|
variables: queryVariables,
|
|
160
148
|
});
|
|
149
|
+
const collection = result?.data?.[userChain]?.collection;
|
|
161
150
|
if (collection)
|
|
162
151
|
return { collection };
|
|
163
152
|
return { collection: null };
|
|
@@ -178,30 +167,24 @@ class NftsController {
|
|
|
178
167
|
async verifyOwnershipByAddress(variables) {
|
|
179
168
|
const { chain, address, nfts } = variables;
|
|
180
169
|
const userChain = chain || this.defaultChain;
|
|
181
|
-
const query =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
ethereumSepolia: CodegenEthSepoliaVerifyOwnershipByAddressDocument,
|
|
185
|
-
};
|
|
186
|
-
const { data: { [userChain]: { walletByAddress }, }, } = await this.client.query({
|
|
187
|
-
query: query[userChain],
|
|
170
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetVerifyOwnershipByAddressDocument);
|
|
171
|
+
const result = await this.client.query({
|
|
172
|
+
query: query,
|
|
188
173
|
variables: { address, filter: { contractTokens: nfts } },
|
|
189
174
|
});
|
|
190
|
-
|
|
175
|
+
const walletNFTs = result?.data?.[userChain]?.walletByAddress?.walletNFTs;
|
|
176
|
+
return !!walletNFTs?.length;
|
|
191
177
|
}
|
|
192
178
|
async verifyOwnershipByENS(variables) {
|
|
193
179
|
const { chain, ensName, nfts } = variables;
|
|
194
180
|
const userChain = chain || this.defaultChain;
|
|
195
|
-
const query =
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
ethereumSepolia: CodegenEthSepoliaVerifyOwnershipByENSDocument,
|
|
199
|
-
};
|
|
200
|
-
const { data: { [userChain]: { walletByENS }, }, } = await this.client.query({
|
|
201
|
-
query: query[userChain],
|
|
181
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetVerifyOwnershipByENSDocument);
|
|
182
|
+
const result = await this.client.query({
|
|
183
|
+
query: query,
|
|
202
184
|
variables: { ensName, filter: { contractTokens: nfts } },
|
|
203
185
|
});
|
|
204
|
-
|
|
186
|
+
const walletByENS = result?.data?.[userChain]?.walletByENS?.walletNFTs;
|
|
187
|
+
return !!walletByENS?.length;
|
|
205
188
|
}
|
|
206
189
|
}
|
|
207
190
|
__decorate([
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
3
3
|
import { balancesByWalletAddressValidator } from '../types/tokens/getBalancesByWalletAddress.js';
|
|
4
|
-
import { CodegenEthMainnetBalancesByWalletENSDocument,
|
|
4
|
+
import { CodegenEthMainnetBalancesByWalletENSDocument, CodegenEthMainnetBalancesByWalletAddressDocument } from '../graphql/generatedTypes.js';
|
|
5
5
|
import { emptyPageInfo } from '../utils/helpers.js';
|
|
6
6
|
import { formatQueryResult } from '../utils/postQueryFormatter.js';
|
|
7
7
|
import { isValidENSAddress } from '../utils/isValidENSAddress.js';
|
|
8
8
|
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
9
|
+
import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
|
|
9
10
|
|
|
10
11
|
class TokensController {
|
|
11
12
|
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
@@ -28,15 +29,12 @@ class TokensController {
|
|
|
28
29
|
async getBalancesByWalletENS(variables) {
|
|
29
30
|
const { chain, ...queryVariables } = variables;
|
|
30
31
|
const userChain = chain || this.defaultChain;
|
|
31
|
-
const query =
|
|
32
|
-
|
|
33
|
-
polygon: CodegenPolygonMainnetBalancesByWalletENSDocument,
|
|
34
|
-
ethereumSepolia: CodegenEthSepoliaBalancesByWalletENSDocument,
|
|
35
|
-
};
|
|
36
|
-
const { data: { [userChain]: { walletByENS }, }, } = await this.client.query({
|
|
32
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetBalancesByWalletENSDocument);
|
|
33
|
+
const result = await this.client.query({
|
|
37
34
|
variables: queryVariables,
|
|
38
|
-
query: query
|
|
35
|
+
query: query,
|
|
39
36
|
});
|
|
37
|
+
const walletByENS = result?.data?.[userChain]?.walletByENS;
|
|
40
38
|
if (!walletByENS?.tokenBalances?.length) {
|
|
41
39
|
// Address can still be valid ENS name, but not have any balances
|
|
42
40
|
const address = walletByENS?.address || '';
|
|
@@ -55,15 +53,12 @@ class TokensController {
|
|
|
55
53
|
async getBalancesByWalletAddress(variables) {
|
|
56
54
|
const { chain, ...queryVariables } = variables;
|
|
57
55
|
const userChain = chain || this.defaultChain;
|
|
58
|
-
const query =
|
|
59
|
-
|
|
60
|
-
polygon: CodegenPolygonMainnetBalancesByWalletAddressDocument,
|
|
61
|
-
ethereumSepolia: CodegenEthSepoliaBalancesByWalletAddressDocument,
|
|
62
|
-
};
|
|
63
|
-
const { data: { [userChain]: { walletByAddress }, }, } = await this.client.query({
|
|
56
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetBalancesByWalletAddressDocument);
|
|
57
|
+
const result = await this.client.query({
|
|
64
58
|
variables: queryVariables,
|
|
65
|
-
query: query
|
|
59
|
+
query: query,
|
|
66
60
|
});
|
|
61
|
+
const walletByAddress = result?.data?.[userChain]?.walletByAddress;
|
|
67
62
|
if (!walletByAddress?.tokenBalances?.length) {
|
|
68
63
|
// Address can still be valid address, but not have any balances
|
|
69
64
|
const address = walletByAddress?.address || '';
|
|
@@ -2,12 +2,13 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
3
3
|
import { transactionsBySearchValidator } from '../types/transactions/getBySearch.js';
|
|
4
4
|
import { transactionsByHashValidator } from '../types/transactions/getByHash.js';
|
|
5
|
-
import { CodegenEthMainnetTransactionsByWalletAddressDocument,
|
|
5
|
+
import { CodegenEthMainnetTransactionsByWalletAddressDocument, CodegenEthMainnetTransactionsByWalletENSDocument, CodegenEthMainnetTransactionsBySearchDocument, CodegenEthMainnetTransactionsByHashDocument } from '../graphql/generatedTypes.js';
|
|
6
6
|
import { emptyPageInfo } from '../utils/helpers.js';
|
|
7
7
|
import { formatQueryResult } from '../utils/postQueryFormatter.js';
|
|
8
8
|
import { isValidENSAddress } from '../utils/isValidENSAddress.js';
|
|
9
9
|
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
10
10
|
import { balancesByWalletAddressValidator } from '../types/tokens/getBalancesByWalletAddress.js';
|
|
11
|
+
import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
|
|
11
12
|
|
|
12
13
|
class TransactionsController {
|
|
13
14
|
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
@@ -46,58 +47,52 @@ class TransactionsController {
|
|
|
46
47
|
async getByWalletAddress(variables) {
|
|
47
48
|
const { chain, ...queryVariables } = variables;
|
|
48
49
|
const userChain = chain || this.defaultChain;
|
|
49
|
-
const query =
|
|
50
|
-
|
|
51
|
-
polygon: CodegenPolygonMainnetTransactionsByWalletAddressDocument,
|
|
52
|
-
ethereumSepolia: CodegenEthSepoliaTransactionsByWalletAddressDocument,
|
|
53
|
-
};
|
|
54
|
-
const { data: { [userChain]: { walletByAddress }, }, } = await this.client.query({
|
|
50
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetTransactionsByWalletAddressDocument);
|
|
51
|
+
const result = await this.client.query({
|
|
55
52
|
variables: queryVariables,
|
|
56
|
-
query: query
|
|
53
|
+
query: query,
|
|
57
54
|
});
|
|
55
|
+
const walletByAddress = result?.data?.[userChain]?.walletByAddress;
|
|
58
56
|
return walletByAddress;
|
|
59
57
|
}
|
|
60
58
|
async getByWalletENS(variables) {
|
|
61
59
|
const { chain, ...queryVariables } = variables;
|
|
62
60
|
const userChain = chain || this.defaultChain;
|
|
63
|
-
const query =
|
|
64
|
-
|
|
65
|
-
polygon: CodegenPolygonMainnetTransactionsByWalletENSDocument,
|
|
66
|
-
ethereumSepolia: CodegenEthSepoliaTransactionsByWalletENSDocument,
|
|
67
|
-
};
|
|
68
|
-
const { data: { [userChain]: { walletByENS }, }, } = await this.client.query({
|
|
61
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetTransactionsByWalletENSDocument);
|
|
62
|
+
const result = await this.client.query({
|
|
69
63
|
variables: queryVariables,
|
|
70
|
-
query: query
|
|
64
|
+
query: query,
|
|
71
65
|
});
|
|
66
|
+
const walletByENS = result?.data?.[userChain]?.walletByENS;
|
|
72
67
|
return walletByENS;
|
|
73
68
|
}
|
|
74
69
|
async getAll(variables) {
|
|
75
70
|
const { chain, ...queryVariables } = variables;
|
|
76
71
|
const userChain = chain || this.defaultChain;
|
|
77
|
-
const query =
|
|
78
|
-
|
|
79
|
-
polygon: CodegenPolygonMainnetTransactionsBySearchDocument,
|
|
80
|
-
ethereumSepolia: CodegenEthSepoliaTransactionsBySearchDocument,
|
|
81
|
-
};
|
|
82
|
-
const { data: { [userChain]: transactions }, } = await this.client.query({
|
|
72
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetTransactionsBySearchDocument);
|
|
73
|
+
const result = await this.client.query({
|
|
83
74
|
variables: queryVariables,
|
|
84
|
-
query: query
|
|
75
|
+
query: query,
|
|
85
76
|
});
|
|
86
|
-
const
|
|
87
|
-
|
|
77
|
+
const transactions = result?.data?.[userChain];
|
|
78
|
+
if (transactions && transactions?.transactions?.length > 0) {
|
|
79
|
+
const formattedResult = formatQueryResult(transactions, 'transactions', 'transactionsPageInfo');
|
|
80
|
+
return formattedResult;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
results: [],
|
|
84
|
+
pageInfo: emptyPageInfo,
|
|
85
|
+
};
|
|
88
86
|
}
|
|
89
87
|
async getByHash(variables) {
|
|
90
88
|
const { chain, ...queryVariables } = variables;
|
|
91
89
|
const userChain = chain || this.defaultChain;
|
|
92
|
-
const query =
|
|
93
|
-
|
|
94
|
-
polygon: CodegenPolygonMainnetTransactionsByHashDocument,
|
|
95
|
-
ethereumSepolia: CodegenEthSepoliaTransactionsByHashDocument,
|
|
96
|
-
};
|
|
97
|
-
const { data: { [userChain]: transaction }, } = await this.client.query({
|
|
90
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetTransactionsByHashDocument);
|
|
91
|
+
const result = await this.client.query({
|
|
98
92
|
variables: queryVariables,
|
|
99
|
-
query: query
|
|
93
|
+
query: query,
|
|
100
94
|
});
|
|
95
|
+
const transaction = result?.data?.[userChain];
|
|
101
96
|
if (transaction?.transaction)
|
|
102
97
|
return transaction;
|
|
103
98
|
return { transaction: null };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { DEFAULT_CHAIN } from '../utils/constants.js';
|
|
3
3
|
import { gasPricesValidator } from '../types/utils/gasPrices.js';
|
|
4
|
-
import { CodegenEthMainnetGasPricesDocument
|
|
4
|
+
import { CodegenEthMainnetGasPricesDocument } from '../graphql/generatedTypes.js';
|
|
5
5
|
import { weiToGwei } from '../utils/helpers.js';
|
|
6
6
|
import { ValidateInput } from '../../lib/validation/ValidateInput.js';
|
|
7
|
+
import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
|
|
7
8
|
|
|
8
9
|
class UtilsController {
|
|
9
10
|
constructor(client, defaultChain = DEFAULT_CHAIN) {
|
|
@@ -14,15 +15,12 @@ class UtilsController {
|
|
|
14
15
|
const { chain, ...queryVariables } = variables;
|
|
15
16
|
const returnInGwei = variables.returnInGwei || false;
|
|
16
17
|
const userChain = chain || this.defaultChain;
|
|
17
|
-
const query =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
ethereumSepolia: CodegenEthSepoliaGasPricesDocument,
|
|
21
|
-
};
|
|
22
|
-
const { data: { [userChain]: { gasPrices }, }, } = await this.client.query({
|
|
23
|
-
query: query[userChain],
|
|
18
|
+
const query = modifyQueryForChain(userChain, CodegenEthMainnetGasPricesDocument);
|
|
19
|
+
const result = await this.client.query({
|
|
20
|
+
query: query,
|
|
24
21
|
variables: queryVariables,
|
|
25
22
|
});
|
|
23
|
+
const gasPrices = result?.data?.[userChain]?.gasPrices;
|
|
26
24
|
if (Array.isArray(gasPrices) && gasPrices.length > 0) {
|
|
27
25
|
if (returnInGwei) {
|
|
28
26
|
const fieldsToTransform = [
|