@evefrontier/dapp-kit 0.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 +53 -0
- package/config/dapp-kit.ts +20 -0
- package/config/index.ts +1 -0
- package/docs/api/.nojekyll +1 -0
- package/docs/api/assets/hierarchy.js +1 -0
- package/docs/api/assets/highlight.css +120 -0
- package/docs/api/assets/icons.js +18 -0
- package/docs/api/assets/icons.svg +1 -0
- package/docs/api/assets/main.js +60 -0
- package/docs/api/assets/navigation.js +1 -0
- package/docs/api/assets/search.js +1 -0
- package/docs/api/assets/style.css +1633 -0
- package/docs/api/classes/WalletNoAccountSelectedError.html +3 -0
- package/docs/api/classes/WalletNotConnectedError.html +3 -0
- package/docs/api/classes/WalletSponsoredTransactionNotSupportedError.html +5 -0
- package/docs/api/enums/ActionTypes.html +6 -0
- package/docs/api/enums/Assemblies.html +7 -0
- package/docs/api/enums/QueryParams.html +3 -0
- package/docs/api/enums/Severity.html +5 -0
- package/docs/api/enums/SponsoredTransactionActions.html +7 -0
- package/docs/api/enums/State.html +6 -0
- package/docs/api/enums/TYPEIDS.html +15 -0
- package/docs/api/functions/EveFrontierProvider.html +11 -0
- package/docs/api/functions/NotificationProvider.html +2 -0
- package/docs/api/functions/SmartObjectProvider.html +10 -0
- package/docs/api/functions/VaultProvider.html +1 -0
- package/docs/api/functions/abbreviateAddress.html +11 -0
- package/docs/api/functions/assertAssemblyType.html +9 -0
- package/docs/api/functions/clickToCopy.html +1 -0
- package/docs/api/functions/executeGraphQLQuery.html +12 -0
- package/docs/api/functions/findOwnerByAddress.html +5 -0
- package/docs/api/functions/formatDuration.html +8 -0
- package/docs/api/functions/formatM3.html +8 -0
- package/docs/api/functions/getAssemblyType.html +4 -0
- package/docs/api/functions/getAssemblyTypeApiString.html +2 -0
- package/docs/api/functions/getAssemblyWithOwner.html +18 -0
- package/docs/api/functions/getCharacterOwnerCapType.html +3 -0
- package/docs/api/functions/getCommonItems.html +1 -0
- package/docs/api/functions/getDappUrl.html +7 -0
- package/docs/api/functions/getDatahubGameInfo.html +13 -0
- package/docs/api/functions/getEnv.html +1 -0
- package/docs/api/functions/getEveWorldPackageId.html +4 -0
- package/docs/api/functions/getObjectByAddress.html +9 -0
- package/docs/api/functions/getObjectId.html +4 -0
- package/docs/api/functions/getObjectOwnerAndOwnedObjectsByType.html +10 -0
- package/docs/api/functions/getObjectRegistryType.html +3 -0
- package/docs/api/functions/getObjectWithDynamicFields.html +10 -0
- package/docs/api/functions/getObjectWithJson.html +9 -0
- package/docs/api/functions/getObjectsByType.html +12 -0
- package/docs/api/functions/getOwnedObjectsByPackage.html +10 -0
- package/docs/api/functions/getOwnedObjectsByType.html +10 -0
- package/docs/api/functions/getRegistryAddress.html +3 -0
- package/docs/api/functions/getSingletonObjectByType.html +9 -0
- package/docs/api/functions/getSponsoredTransactionFeature.html +11 -0
- package/docs/api/functions/getSuiGraphqlEndpoint.html +4 -0
- package/docs/api/functions/getTxUrl.html +8 -0
- package/docs/api/functions/getVolumeM3.html +5 -0
- package/docs/api/functions/hasSponsoredTransactionFeature.html +3 -0
- package/docs/api/functions/isOwner.html +10 -0
- package/docs/api/functions/parseErrorFromMessage.html +1 -0
- package/docs/api/functions/parseStatus.html +2 -0
- package/docs/api/functions/parseURL.html +1 -0
- package/docs/api/functions/removeTrailingZeros.html +1 -0
- package/docs/api/functions/transformToAssembly.html +5 -0
- package/docs/api/functions/transformToCharacter.html +2 -0
- package/docs/api/functions/useConnection.html +21 -0
- package/docs/api/functions/useNotification.html +28 -0
- package/docs/api/functions/useSmartObject.html +26 -0
- package/docs/api/functions/useSponsoredTransaction.html +50 -0
- package/docs/api/functions/walletSupportsSponsoredTransaction.html +13 -0
- package/docs/api/hierarchy.html +1 -0
- package/docs/api/index.html +26 -0
- package/docs/api/interfaces/AddressOwner.html +2 -0
- package/docs/api/interfaces/AddressOwnerWithJson.html +2 -0
- package/docs/api/interfaces/AssemblyProperties.html +14 -0
- package/docs/api/interfaces/CharacterInfo.html +8 -0
- package/docs/api/interfaces/DatahubGameInfo.html +30 -0
- package/docs/api/interfaces/DetailedAssemblyResponse.html +14 -0
- package/docs/api/interfaces/DetailedSmartCharacterResponse.html +7 -0
- package/docs/api/interfaces/DynamicFieldNode.html +3 -0
- package/docs/api/interfaces/EphemeralInventory.html +6 -0
- package/docs/api/interfaces/EveFrontierSponsoredTransactionFeature.html +7 -0
- package/docs/api/interfaces/GameTypeResponse.html +13 -0
- package/docs/api/interfaces/GateModule.html +5 -0
- package/docs/api/interfaces/GetObjectByAddressResponse.html +2 -0
- package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsResponse.html +2 -0
- package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsWithJsonResponse.html +2 -0
- package/docs/api/interfaces/GetObjectResponse.html +2 -0
- package/docs/api/interfaces/GetObjectWithJsonResponse.html +2 -0
- package/docs/api/interfaces/GetObjectsByTypeResponse.html +2 -0
- package/docs/api/interfaces/GetOwnedObjectsByPackageResponse.html +2 -0
- package/docs/api/interfaces/GetOwnedObjectsByTypeResponse.html +2 -0
- package/docs/api/interfaces/GetSingletonObjectByTypeResponse.html +2 -0
- package/docs/api/interfaces/GraphQLResponse.html +3 -0
- package/docs/api/interfaces/InventoryItem.html +8 -0
- package/docs/api/interfaces/ManufacturingModule.html +2 -0
- package/docs/api/interfaces/MoveObjectContents.html +4 -0
- package/docs/api/interfaces/MoveObjectData.html +3 -0
- package/docs/api/interfaces/NetworkNodeModule.html +7 -0
- package/docs/api/interfaces/NotificationContextType.html +4 -0
- package/docs/api/interfaces/NotificationState.html +6 -0
- package/docs/api/interfaces/Notify.html +6 -0
- package/docs/api/interfaces/ObjectWithContentsNode.html +4 -0
- package/docs/api/interfaces/OwnedObjectAddressNode.html +2 -0
- package/docs/api/interfaces/OwnedObjectFullNode.html +4 -0
- package/docs/api/interfaces/OwnedObjectNode.html +3 -0
- package/docs/api/interfaces/OwnedObjectNodeWithJson.html +4 -0
- package/docs/api/interfaces/OwnerCapData.html +5 -0
- package/docs/api/interfaces/PageInfo.html +3 -0
- package/docs/api/interfaces/RawCharacterData.html +8 -0
- package/docs/api/interfaces/RawSuiObjectData.html +17 -0
- package/docs/api/interfaces/RefineryModule.html +2 -0
- package/docs/api/interfaces/SmartAssemblyResponse.html +11 -0
- package/docs/api/interfaces/SmartObjectContextType.html +8 -0
- package/docs/api/interfaces/SponsoredTransactionInput.html +15 -0
- package/docs/api/interfaces/SponsoredTransactionOutput.html +8 -0
- package/docs/api/interfaces/StorageModule.html +4 -0
- package/docs/api/interfaces/SuiObjectResponse.html +5 -0
- package/docs/api/interfaces/TransformOptions.html +6 -0
- package/docs/api/interfaces/TurretModule.html +2 -0
- package/docs/api/interfaces/VaultContextType.html +7 -0
- package/docs/api/modules.html +1 -0
- package/docs/api/types/AssemblyType.html +1 -0
- package/docs/api/types/ErrorType.html +5 -0
- package/docs/api/types/SendSponsoredTransactionFn.html +1 -0
- package/docs/api/types/SponsoredTransactionArgs.html +2 -0
- package/docs/api/types/SponsoredTransactionAssemblyType.html +2 -0
- package/docs/api/types/SponsoredTransactionMethod.html +2 -0
- package/docs/api/types/UseSponsoredTransactionArgs.html +3 -0
- package/docs/api/types/UseSponsoredTransactionError.html +2 -0
- package/docs/api/types/UseSponsoredTransactionMutationOptions.html +2 -0
- package/docs/api/variables/ERRORS.html +1 -0
- package/docs/api/variables/ERROR_MESSAGES.html +1 -0
- package/docs/api/variables/EVEFRONTIER_SPONSORED_TRANSACTION.html +4 -0
- package/docs/api/variables/EXCLUDED_TYPEIDS.html +1 -0
- package/docs/api/variables/GET_OBJECTS_BY_TYPE.html +3 -0
- package/docs/api/variables/GET_OBJECT_BY_ADDRESS.html +3 -0
- package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE.html +4 -0
- package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON.html +3 -0
- package/docs/api/variables/GET_OBJECT_WITH_DYNAMIC_FIELDS.html +4 -0
- package/docs/api/variables/GET_OBJECT_WITH_JSON.html +3 -0
- package/docs/api/variables/GET_OWNED_OBJECTS_BY_PACKAGE.html +3 -0
- package/docs/api/variables/GET_OWNED_OBJECTS_BY_TYPE.html +3 -0
- package/docs/api/variables/GET_SINGLETON_OBJECT_BY_TYPE.html +3 -0
- package/docs/api/variables/NotificationContext.html +1 -0
- package/docs/api/variables/ONE_M3.html +2 -0
- package/docs/api/variables/POLLING_INTERVAL.html +2 -0
- package/docs/api/variables/STORAGE_KEYS.html +2 -0
- package/docs/api/variables/SmartObjectContext.html +1 -0
- package/docs/api/variables/VaultContext.html +1 -0
- package/docs/api/variables/dAppKit.html +2 -0
- package/graphql/client.ts +480 -0
- package/graphql/index.ts +73 -0
- package/graphql/queries.ts +371 -0
- package/graphql/types.ts +443 -0
- package/hooks/index.ts +14 -0
- package/hooks/useConnection.ts +58 -0
- package/hooks/useNotification.ts +80 -0
- package/hooks/useSmartObject.ts +78 -0
- package/hooks/useSponsoredTransaction.ts +323 -0
- package/index.ts +162 -0
- package/package.json +48 -0
- package/providers/EveFrontierProvider.tsx +41 -0
- package/providers/NotificationProvider.tsx +115 -0
- package/providers/SmartObjectProvider.tsx +282 -0
- package/providers/VaultProvider.tsx +114 -0
- package/providers/index.ts +17 -0
- package/tsconfig.json +22 -0
- package/typedoc.json +38 -0
- package/types/global.d.ts +7 -0
- package/types/index.ts +4 -0
- package/types/sponsoredTransaction.ts +26 -0
- package/types/types.ts +113 -0
- package/types/worldApiReturnTypes.ts +166 -0
- package/utils/__tests__/mapping.test.ts +441 -0
- package/utils/constants.ts +96 -0
- package/utils/datahub.ts +76 -0
- package/utils/errors.ts +171 -0
- package/utils/index.ts +38 -0
- package/utils/mapping.ts +115 -0
- package/utils/transforms.ts +258 -0
- package/utils/utils.ts +270 -0
- package/vite-env.d.ts +16 -0
- package/wallet/features.ts +165 -0
- package/wallet/index.ts +28 -0
- package/wallet/utils.ts +117 -0
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCharacterOwnerCapType,
|
|
3
|
+
getSuiGraphqlEndpoint,
|
|
4
|
+
} from "../utils/constants";
|
|
5
|
+
import type {
|
|
6
|
+
GraphQLResponse,
|
|
7
|
+
GetObjectByAddressResponse,
|
|
8
|
+
GetObjectOwnerAndOwnedObjectsResponse,
|
|
9
|
+
GetObjectOwnerAndOwnedObjectsWithJsonResponse,
|
|
10
|
+
GetOwnedObjectsByTypeResponse,
|
|
11
|
+
GetOwnedObjectsByPackageResponse,
|
|
12
|
+
GetSingletonObjectByTypeResponse,
|
|
13
|
+
GetObjectsByTypeResponse,
|
|
14
|
+
GetObjectResponse,
|
|
15
|
+
GetObjectWithJsonResponse,
|
|
16
|
+
RawCharacterData,
|
|
17
|
+
CharacterInfo,
|
|
18
|
+
GetObjectAndCharacterOwnerResponse,
|
|
19
|
+
DynamicFieldNode,
|
|
20
|
+
} from "./types";
|
|
21
|
+
import {
|
|
22
|
+
GET_OBJECT_BY_ADDRESS,
|
|
23
|
+
GET_OBJECT_WITH_DYNAMIC_FIELDS,
|
|
24
|
+
GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE,
|
|
25
|
+
GET_OBJECT_DYNAMICFIELD_CHARACTER_WITH_JSON,
|
|
26
|
+
GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON,
|
|
27
|
+
GET_OWNED_OBJECTS_BY_TYPE,
|
|
28
|
+
GET_OWNED_OBJECTS_BY_PACKAGE,
|
|
29
|
+
GET_SINGLETON_OBJECT_BY_TYPE,
|
|
30
|
+
GET_OBJECTS_BY_TYPE,
|
|
31
|
+
GET_OBJECT_WITH_JSON,
|
|
32
|
+
} from "./queries";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Execute a GraphQL query against the Sui blockchain endpoint.
|
|
36
|
+
*
|
|
37
|
+
* This is the low-level function used by all other GraphQL helper functions.
|
|
38
|
+
* Use this when you need to execute custom queries not covered by the helper functions.
|
|
39
|
+
*
|
|
40
|
+
* @category GraphQL
|
|
41
|
+
* @typeParam T - The expected response data type
|
|
42
|
+
* @param query - The GraphQL query string
|
|
43
|
+
* @param variables - Variables to pass to the query
|
|
44
|
+
* @returns Promise resolving to the GraphQL response
|
|
45
|
+
* @throws {Error} If the HTTP request fails
|
|
46
|
+
*
|
|
47
|
+
* @example Custom query
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const result = await executeGraphQLQuery<MyResponseType>(
|
|
50
|
+
* `query GetObject($address: SuiAddress!) {
|
|
51
|
+
* object(address: $address) {
|
|
52
|
+
* asMoveObject { contents { json } }
|
|
53
|
+
* }
|
|
54
|
+
* }`,
|
|
55
|
+
* { address: "0x123..." }
|
|
56
|
+
* );
|
|
57
|
+
* console.log(result.data?.object?.asMoveObject?.contents?.json);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export async function executeGraphQLQuery<T = unknown>(
|
|
61
|
+
query: string,
|
|
62
|
+
variables: Record<string, unknown>,
|
|
63
|
+
): Promise<GraphQLResponse<T>> {
|
|
64
|
+
const response = await fetch(getSuiGraphqlEndpoint(), {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify({
|
|
70
|
+
query,
|
|
71
|
+
variables,
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return response.json();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Helper Functions for Common Queries
|
|
84
|
+
// ============================================================================
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Fetch a Sui object by its address with BCS-encoded contents.
|
|
88
|
+
*
|
|
89
|
+
* Use this for low-level object access when you need raw BCS data.
|
|
90
|
+
* For JSON-decoded data, use {@link getObjectWithJson} instead.
|
|
91
|
+
*
|
|
92
|
+
* @category GraphQL
|
|
93
|
+
* @param address - The Sui object address (0x...)
|
|
94
|
+
* @returns Promise resolving to object with BCS contents
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const result = await getObjectByAddress("0x123...");
|
|
99
|
+
* const bcsData = result.data?.object?.asMoveObject?.contents?.bcs;
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export async function getObjectByAddress(address: string) {
|
|
103
|
+
return executeGraphQLQuery<GetObjectByAddressResponse>(
|
|
104
|
+
GET_OBJECT_BY_ADDRESS,
|
|
105
|
+
{ address },
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Fetch a Sui object with its dynamic fields in JSON format.
|
|
111
|
+
*
|
|
112
|
+
* Retrieves the object's contents and all associated dynamic fields,
|
|
113
|
+
* which is useful for assemblies that store data in dynamic fields
|
|
114
|
+
* (e.g., inventory items, configuration).
|
|
115
|
+
*
|
|
116
|
+
* @category GraphQL
|
|
117
|
+
* @param objectId - The Sui object ID
|
|
118
|
+
* @returns Promise resolving to object with dynamic fields
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const result = await getObjectWithDynamicFields("0x123...");
|
|
123
|
+
* const dynamicFields = result.data?.object?.asMoveObject?.dynamicFields?.nodes;
|
|
124
|
+
* dynamicFields?.forEach(field => {
|
|
125
|
+
* console.log(field.name.json, field.contents.json);
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export async function getObjectWithDynamicFields(objectId: string) {
|
|
130
|
+
return executeGraphQLQuery<GetObjectResponse>(
|
|
131
|
+
GET_OBJECT_WITH_DYNAMIC_FIELDS,
|
|
132
|
+
{ objectId },
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Fetch a Sui object with JSON-decoded contents.
|
|
138
|
+
*
|
|
139
|
+
* This is the most common way to fetch object data when you need
|
|
140
|
+
* to read the object's fields as JavaScript objects.
|
|
141
|
+
*
|
|
142
|
+
* @category GraphQL
|
|
143
|
+
* @param address - The Sui object address
|
|
144
|
+
* @returns Promise resolving to object with JSON contents
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const result = await getObjectWithJson("0x123...");
|
|
149
|
+
* const json = result.data?.object?.asMoveObject?.contents?.json;
|
|
150
|
+
* console.log(json); // { id: "...", name: "...", ... }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export async function getObjectWithJson(address: string) {
|
|
154
|
+
return executeGraphQLQuery<GetObjectWithJsonResponse>(GET_OBJECT_WITH_JSON, {
|
|
155
|
+
address,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Get an object's owner and their owned objects of a specific type.
|
|
161
|
+
*
|
|
162
|
+
* Useful for traversing ownership chains, e.g., finding all assemblies
|
|
163
|
+
* owned by a specific character.
|
|
164
|
+
*
|
|
165
|
+
* @category GraphQL
|
|
166
|
+
* @param objectAddress - The Sui object address to query owner of
|
|
167
|
+
* @param ownedObjectType - Optional type filter for owned objects
|
|
168
|
+
* @returns Promise resolving to owner info and owned objects (BCS format)
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const result = await getObjectOwnerAndOwnedObjectsByType(
|
|
173
|
+
* "0x123...",
|
|
174
|
+
* "0xpackage::module::MyType"
|
|
175
|
+
* );
|
|
176
|
+
* const ownerAddress = result.data?.object?.owner?.address?.address;
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export async function getObjectOwnerAndOwnedObjectsByType(
|
|
180
|
+
objectAddress: string,
|
|
181
|
+
ownedObjectType?: string,
|
|
182
|
+
) {
|
|
183
|
+
return executeGraphQLQuery<GetObjectOwnerAndOwnedObjectsResponse>(
|
|
184
|
+
GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE,
|
|
185
|
+
{
|
|
186
|
+
object: objectAddress,
|
|
187
|
+
owned_object_type: ownedObjectType,
|
|
188
|
+
},
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get an object's owner and their owned objects with JSON data.
|
|
194
|
+
*
|
|
195
|
+
* Similar to {@link getObjectOwnerAndOwnedObjectsByType} but returns
|
|
196
|
+
* JSON-decoded contents for easier consumption.
|
|
197
|
+
*
|
|
198
|
+
* @category GraphQL
|
|
199
|
+
* @param objectAddress - The Sui object address
|
|
200
|
+
* @param ownedObjectType - Optional type filter for owned objects
|
|
201
|
+
* @returns Promise resolving to owner info and owned objects (JSON format)
|
|
202
|
+
*/
|
|
203
|
+
export async function getObjectOwnerAndOwnedObjectsWithJson(
|
|
204
|
+
objectAddress: string,
|
|
205
|
+
ownedObjectType?: string,
|
|
206
|
+
) {
|
|
207
|
+
return executeGraphQLQuery<GetObjectOwnerAndOwnedObjectsWithJsonResponse>(
|
|
208
|
+
GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON,
|
|
209
|
+
{
|
|
210
|
+
object: objectAddress,
|
|
211
|
+
owned_object_type: ownedObjectType,
|
|
212
|
+
},
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Get an assembly object and resolve its owner character.
|
|
218
|
+
*
|
|
219
|
+
* This is a specialized query for EVE Frontier assemblies that
|
|
220
|
+
* follows the owner_cap_id to resolve the owning character.
|
|
221
|
+
*
|
|
222
|
+
* @category GraphQL
|
|
223
|
+
* @param objectAddress - The assembly object address
|
|
224
|
+
* @returns Promise resolving to assembly and character data
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
export async function getObjectAndCharacterOwner(objectAddress: string) {
|
|
228
|
+
return executeGraphQLQuery<GetObjectAndCharacterOwnerResponse>(
|
|
229
|
+
GET_OBJECT_DYNAMICFIELD_CHARACTER_WITH_JSON,
|
|
230
|
+
{
|
|
231
|
+
objectId: objectAddress,
|
|
232
|
+
characterOwnerType: getCharacterOwnerCapType(),
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Get all objects of a specific type owned by an address.
|
|
239
|
+
*
|
|
240
|
+
* Returns only object addresses (lightweight). Use this when you need
|
|
241
|
+
* to find objects and will fetch their details separately.
|
|
242
|
+
*
|
|
243
|
+
* @category GraphQL
|
|
244
|
+
* @param owner - The owner's Sui address
|
|
245
|
+
* @param objectType - Optional Move type filter (e.g., "0xpkg::module::Type")
|
|
246
|
+
* @returns Promise resolving to list of owned object addresses
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* const result = await getOwnedObjectsByType(
|
|
251
|
+
* "0xowner...",
|
|
252
|
+
* "0xworld::smart_storage_unit::SmartStorageUnit"
|
|
253
|
+
* );
|
|
254
|
+
* const addresses = result.data?.address?.objects?.nodes.map(n => n.address);
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
export async function getOwnedObjectsByType(
|
|
258
|
+
owner: string,
|
|
259
|
+
objectType?: string,
|
|
260
|
+
) {
|
|
261
|
+
return executeGraphQLQuery<GetOwnedObjectsByTypeResponse>(
|
|
262
|
+
GET_OWNED_OBJECTS_BY_TYPE,
|
|
263
|
+
{
|
|
264
|
+
owner,
|
|
265
|
+
object_type: objectType,
|
|
266
|
+
},
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Get all objects owned by an address filtered by package.
|
|
272
|
+
*
|
|
273
|
+
* Returns full object data with dynamic fields. Use this when you need
|
|
274
|
+
* all objects from a specific package (e.g., all EVE Frontier objects).
|
|
275
|
+
*
|
|
276
|
+
* @category GraphQL
|
|
277
|
+
* @param owner - The owner's Sui address
|
|
278
|
+
* @param packageId - The Move package ID to filter by
|
|
279
|
+
* @returns Promise resolving to full object data including dynamic fields
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const result = await getOwnedObjectsByPackage(
|
|
284
|
+
* "0xowner...",
|
|
285
|
+
* "0xworld_package_id..."
|
|
286
|
+
* );
|
|
287
|
+
* const objects = result.data?.objects?.nodes;
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
export async function getOwnedObjectsByPackage(
|
|
291
|
+
owner: string,
|
|
292
|
+
packageId: string,
|
|
293
|
+
) {
|
|
294
|
+
return executeGraphQLQuery<GetOwnedObjectsByPackageResponse>(
|
|
295
|
+
GET_OWNED_OBJECTS_BY_PACKAGE,
|
|
296
|
+
{
|
|
297
|
+
owner,
|
|
298
|
+
packageId,
|
|
299
|
+
},
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Get a singleton object by its Move type.
|
|
305
|
+
*
|
|
306
|
+
* Useful for global/singleton objects where there's only one instance
|
|
307
|
+
* of a particular type on-chain.
|
|
308
|
+
*
|
|
309
|
+
* @category GraphQL
|
|
310
|
+
* @param objectType - The full Move type string
|
|
311
|
+
* @returns Promise resolving to the singleton object address
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* const result = await getSingletonObjectByType("0xpkg::config::GlobalConfig");
|
|
316
|
+
* const address = result.data?.objects?.nodes[0]?.address;
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
export async function getSingletonObjectByType(objectType: string) {
|
|
320
|
+
return executeGraphQLQuery<GetSingletonObjectByTypeResponse>(
|
|
321
|
+
GET_SINGLETON_OBJECT_BY_TYPE,
|
|
322
|
+
{
|
|
323
|
+
object_type: objectType,
|
|
324
|
+
},
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Get all objects of a specific type with pagination.
|
|
330
|
+
*
|
|
331
|
+
* Use with caution as this may return many results. Supports cursor-based
|
|
332
|
+
* pagination for iterating through large result sets.
|
|
333
|
+
*
|
|
334
|
+
* @category GraphQL
|
|
335
|
+
* @param objectType - The full Move type string
|
|
336
|
+
* @param options - Pagination options
|
|
337
|
+
* @param options.first - Number of results per page (default: 50)
|
|
338
|
+
* @param options.after - Cursor for next page
|
|
339
|
+
* @returns Promise resolving to paginated object list
|
|
340
|
+
*
|
|
341
|
+
* @example Paginated fetch
|
|
342
|
+
* ```typescript
|
|
343
|
+
* let cursor: string | undefined;
|
|
344
|
+
* do {
|
|
345
|
+
* const result = await getObjectsByType("0xpkg::module::Type", {
|
|
346
|
+
* first: 50,
|
|
347
|
+
* after: cursor
|
|
348
|
+
* });
|
|
349
|
+
* const objects = result.data?.objects?.nodes;
|
|
350
|
+
* cursor = result.data?.objects?.pageInfo?.hasNextPage
|
|
351
|
+
* ? result.data?.objects?.pageInfo?.endCursor
|
|
352
|
+
* : undefined;
|
|
353
|
+
* } while (cursor);
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
export async function getObjectsByType(
|
|
357
|
+
objectType: string,
|
|
358
|
+
options?: { first?: number; after?: string },
|
|
359
|
+
) {
|
|
360
|
+
return executeGraphQLQuery<GetObjectsByTypeResponse>(GET_OBJECTS_BY_TYPE, {
|
|
361
|
+
object_type: objectType,
|
|
362
|
+
first: options?.first ?? 50,
|
|
363
|
+
after: options?.after,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Fetch an EVE Frontier assembly and its owner character in one call.
|
|
369
|
+
*
|
|
370
|
+
* This is the primary function for loading assembly data in dApps.
|
|
371
|
+
* It fetches the assembly's Move object data, dynamic fields, and
|
|
372
|
+
* resolves the owner character through the ownership chain.
|
|
373
|
+
*
|
|
374
|
+
* @category GraphQL
|
|
375
|
+
* @param assemblyId - The assembly's Sui object ID
|
|
376
|
+
* @returns Promise resolving to:
|
|
377
|
+
* - `moveObject` - The assembly's Move object data with JSON contents and dynamic fields
|
|
378
|
+
* - `character` - The owner character info (id, name, address, tribeId, characterId)
|
|
379
|
+
*
|
|
380
|
+
* @example Basic usage
|
|
381
|
+
* ```typescript
|
|
382
|
+
* const { moveObject, character } = await getAssemblyWithOwner("0x123...");
|
|
383
|
+
*
|
|
384
|
+
* if (moveObject) {
|
|
385
|
+
* console.log("Assembly data:", moveObject.contents.json);
|
|
386
|
+
* console.log("Dynamic fields:", moveObject.dynamicFields?.nodes);
|
|
387
|
+
* }
|
|
388
|
+
*
|
|
389
|
+
* if (character) {
|
|
390
|
+
* console.log("Owner:", character.name);
|
|
391
|
+
* }
|
|
392
|
+
* ```
|
|
393
|
+
*
|
|
394
|
+
* @example Transform to typed Assembly
|
|
395
|
+
* ```typescript
|
|
396
|
+
* import { transformToAssembly } from '@evefrontier/dapp-kit';
|
|
397
|
+
*
|
|
398
|
+
* const { moveObject, character } = await getAssemblyWithOwner(assemblyId);
|
|
399
|
+
* const assembly = await transformToAssembly(assemblyId, moveObject, { character });
|
|
400
|
+
* console.log(assembly.name, assembly.type, assembly.state);
|
|
401
|
+
* ```
|
|
402
|
+
*
|
|
403
|
+
* @see {@link transformToAssembly} for converting raw data to typed Assembly
|
|
404
|
+
*/
|
|
405
|
+
export async function getAssemblyWithOwner(assemblyId: string): Promise<{
|
|
406
|
+
moveObject: {
|
|
407
|
+
contents: {
|
|
408
|
+
json: Record<string, unknown>;
|
|
409
|
+
type?: { repr: string };
|
|
410
|
+
};
|
|
411
|
+
dynamicFields?: {
|
|
412
|
+
nodes: DynamicFieldNode[];
|
|
413
|
+
};
|
|
414
|
+
} | null;
|
|
415
|
+
character: CharacterInfo | null;
|
|
416
|
+
}> {
|
|
417
|
+
try {
|
|
418
|
+
const result = await getObjectAndCharacterOwner(assemblyId);
|
|
419
|
+
|
|
420
|
+
if (!result.data?.object?.asMoveObject) {
|
|
421
|
+
console.warn("[DappKit] getAssemblyWithOwner: Assembly not found");
|
|
422
|
+
return { moveObject: null, character: null };
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const moveObject = result.data.object.asMoveObject;
|
|
426
|
+
|
|
427
|
+
const dynamicFields = moveObject.dynamicFields;
|
|
428
|
+
|
|
429
|
+
// Extract character info from the owner chain
|
|
430
|
+
let characterInfo: CharacterInfo | null = null;
|
|
431
|
+
|
|
432
|
+
const characterMoveObject =
|
|
433
|
+
moveObject.contents.extract?.asAddress?.asObject?.asMoveObject?.owner
|
|
434
|
+
?.address?.objects?.nodes[0]?.contents?.authorizedObj?.asAddress
|
|
435
|
+
?.asObject?.asMoveObject;
|
|
436
|
+
|
|
437
|
+
if (!characterMoveObject?.contents?.json) {
|
|
438
|
+
console.warn("[DappKit] getAssemblyWithOwner: Character not found");
|
|
439
|
+
return { moveObject: result.data?.object?.asMoveObject, character: null };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const characterJson = characterMoveObject?.contents.json;
|
|
443
|
+
|
|
444
|
+
if (characterJson) {
|
|
445
|
+
const rawCharacter = characterJson as RawCharacterData;
|
|
446
|
+
characterInfo = {
|
|
447
|
+
id: rawCharacter.id || "",
|
|
448
|
+
address: characterJson.character_address || "",
|
|
449
|
+
name: rawCharacter.metadata.name || "",
|
|
450
|
+
tribeId:
|
|
451
|
+
typeof rawCharacter.tribe_id === "string"
|
|
452
|
+
? parseInt(rawCharacter.tribe_id, 10)
|
|
453
|
+
: (rawCharacter.tribe_id as number) || 0,
|
|
454
|
+
characterId:
|
|
455
|
+
typeof rawCharacter.key.item_id === "string"
|
|
456
|
+
? parseInt(rawCharacter.key.item_id, 10)
|
|
457
|
+
: (rawCharacter.key.item_id as number) || 0,
|
|
458
|
+
_raw: rawCharacter,
|
|
459
|
+
};
|
|
460
|
+
} else {
|
|
461
|
+
console.warn(
|
|
462
|
+
"[DappKit] getAssemblyWithOwner: Could not extract character JSON from owner chain",
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
moveObject: {
|
|
468
|
+
contents: {
|
|
469
|
+
json: moveObject.contents.json,
|
|
470
|
+
type: moveObject.contents.type,
|
|
471
|
+
},
|
|
472
|
+
dynamicFields: dynamicFields || undefined,
|
|
473
|
+
},
|
|
474
|
+
character: characterInfo,
|
|
475
|
+
};
|
|
476
|
+
} catch (error) {
|
|
477
|
+
console.error("[DappKit] getAssemblyWithOwner error:", error);
|
|
478
|
+
return { moveObject: null, character: null };
|
|
479
|
+
}
|
|
480
|
+
}
|
package/graphql/index.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Client & Query Execution
|
|
2
|
+
export {
|
|
3
|
+
executeGraphQLQuery,
|
|
4
|
+
getObjectByAddress,
|
|
5
|
+
getObjectWithDynamicFields,
|
|
6
|
+
getObjectWithJson,
|
|
7
|
+
getObjectOwnerAndOwnedObjectsByType,
|
|
8
|
+
getObjectOwnerAndOwnedObjectsWithJson,
|
|
9
|
+
getObjectAndCharacterOwner,
|
|
10
|
+
getOwnedObjectsByType,
|
|
11
|
+
getOwnedObjectsByPackage,
|
|
12
|
+
getSingletonObjectByType,
|
|
13
|
+
getObjectsByType,
|
|
14
|
+
// Character/owner resolution
|
|
15
|
+
getAssemblyWithOwner,
|
|
16
|
+
} from "./client";
|
|
17
|
+
|
|
18
|
+
// Query Strings
|
|
19
|
+
export {
|
|
20
|
+
// Core object queries
|
|
21
|
+
GET_OBJECT_BY_ADDRESS,
|
|
22
|
+
GET_OBJECT_WITH_DYNAMIC_FIELDS,
|
|
23
|
+
GET_OBJECT_WITH_JSON,
|
|
24
|
+
// Owner & ownership queries
|
|
25
|
+
GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE,
|
|
26
|
+
GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON,
|
|
27
|
+
GET_OWNED_OBJECTS_BY_TYPE,
|
|
28
|
+
GET_OWNED_OBJECTS_BY_PACKAGE,
|
|
29
|
+
// Singleton & type-based queries
|
|
30
|
+
GET_SINGLETON_OBJECT_BY_TYPE,
|
|
31
|
+
GET_OBJECTS_BY_TYPE,
|
|
32
|
+
} from "./queries";
|
|
33
|
+
|
|
34
|
+
// Types
|
|
35
|
+
export type {
|
|
36
|
+
// Base types
|
|
37
|
+
GraphQLResponse,
|
|
38
|
+
PageInfo,
|
|
39
|
+
// Move object types
|
|
40
|
+
MoveObjectContents,
|
|
41
|
+
DynamicFieldNode,
|
|
42
|
+
MoveObjectData,
|
|
43
|
+
// Object response types
|
|
44
|
+
SuiObjectResponse,
|
|
45
|
+
GetObjectResponse,
|
|
46
|
+
// GetObjectByAddress types
|
|
47
|
+
GetObjectByAddressResponse,
|
|
48
|
+
// GetObjectWithJson types
|
|
49
|
+
GetObjectWithJsonResponse,
|
|
50
|
+
// Owner & owned objects types
|
|
51
|
+
OwnedObjectNode,
|
|
52
|
+
AddressOwner,
|
|
53
|
+
GetObjectOwnerAndOwnedObjectsResponse,
|
|
54
|
+
// Owner & owned objects with JSON types
|
|
55
|
+
OwnedObjectNodeWithJson,
|
|
56
|
+
AddressOwnerWithJson,
|
|
57
|
+
GetObjectOwnerAndOwnedObjectsWithJsonResponse,
|
|
58
|
+
// GetOwnedObjectsByType types
|
|
59
|
+
OwnedObjectAddressNode,
|
|
60
|
+
GetOwnedObjectsByTypeResponse,
|
|
61
|
+
// GetOwnedObjectsByPackage types
|
|
62
|
+
OwnedObjectFullNode,
|
|
63
|
+
GetOwnedObjectsByPackageResponse,
|
|
64
|
+
// Singleton & type-based types
|
|
65
|
+
GetSingletonObjectByTypeResponse,
|
|
66
|
+
ObjectWithContentsNode,
|
|
67
|
+
GetObjectsByTypeResponse,
|
|
68
|
+
// EVE Frontier specific types
|
|
69
|
+
RawSuiObjectData,
|
|
70
|
+
OwnerCapData,
|
|
71
|
+
RawCharacterData,
|
|
72
|
+
CharacterInfo,
|
|
73
|
+
} from "./types";
|