@longdotxyz/shared 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +336 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longdotxyz/shared",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Shared types and utilities for Long.xyz API",
5
5
  "files": [
6
6
  "dist"
package/readme.md CHANGED
@@ -1 +1,336 @@
1
- # Long.xyz Platform Shared Library
1
+ # @longdotxyz/shared
2
+
3
+ Shared TypeScript library for Long.xyz API containing GraphQL types, REST API contracts, and utilities.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @longdotxyz/shared
9
+ # or
10
+ pnpm add @longdotxyz/shared
11
+ ```
12
+
13
+ ## Features
14
+
15
+ - **GraphQL Types & SDK**: Auto-generated types and SDK client from GraphQL schema
16
+ - **REST API Contracts**: Type-safe API contracts built with [ts-rest](https://ts-rest.com)
17
+ - **Type Utilities**: Common types for blockchain addresses, pool keys, and more
18
+ - **Utilities**: Helper functions for native token handling
19
+
20
+ ## GraphQL Types and SDK
21
+
22
+ The library includes auto-generated GraphQL types and a ready-to-use SDK client.
23
+
24
+ ### Basic Setup
25
+
26
+ ```typescript
27
+ import { GraphQLClient } from 'graphql-request';
28
+ import { getSdk } from '@longdotxyz/shared';
29
+
30
+ // Initialize GraphQL client
31
+ const client = new GraphQLClient('https://graphql.long.xyz');
32
+
33
+ // Create SDK instance
34
+ const sdk = getSdk(client);
35
+ ```
36
+
37
+ ### Example: Fetch Auction by Address
38
+
39
+ ```typescript
40
+ import { getSdk, GetAuctionByAddressQuery } from '@longdotxyz/shared';
41
+
42
+ // Query an auction
43
+ const { auction_pool } = await sdk.GetAuctionByAddress({
44
+ address: '0x123...'
45
+ });
46
+
47
+ // Type-safe access to auction data
48
+ if (auction_pool) {
49
+ console.log(auction_pool.auction_pool_address);
50
+ console.log(auction_pool.asset_address);
51
+ console.log(auction_pool.numeraire_address);
52
+ }
53
+ ```
54
+
55
+ ### Available GraphQL Types
56
+
57
+ ```typescript
58
+ import type {
59
+ Asset,
60
+ AuctionPool,
61
+ GraduationPool,
62
+ Asset_Bool_Exp,
63
+ Asset_Order_By
64
+ } from '@longdotxyz/shared';
65
+
66
+ // Use types for type-safe queries
67
+ const assetFilter: Asset_Bool_Exp = {
68
+ chain_id: { _eq: 1 },
69
+ asset_address: { _ilike: '0x%' }
70
+ };
71
+ ```
72
+
73
+ ## REST API Client (ts-rest)
74
+
75
+ The library provides type-safe REST API contracts using [ts-rest](https://ts-rest.com/client/fetch).
76
+
77
+ ### Initialize API Client
78
+
79
+ ```typescript
80
+ import { initClient } from '@ts-rest/core';
81
+ import { rootContract } from '@longdotxyz/shared';
82
+
83
+ // Create typed API client
84
+ const apiClient = initClient(rootContract, {
85
+ baseUrl: 'https://api.long.xyz',
86
+ baseHeaders: {
87
+ 'Content-Type': 'application/json'
88
+ }
89
+ });
90
+ ```
91
+
92
+ ### Auction Endpoints
93
+
94
+ ```typescript
95
+ // Get dynamic auction details
96
+ const auctionResponse = await apiClient.auctions.getDynamicAuction({
97
+ params: {
98
+ address: '0x123...'
99
+ }
100
+ });
101
+
102
+ if (auctionResponse.status === 200) {
103
+ const { auction_pool_address, auction_base_token_symbol } = auctionResponse.body.result;
104
+ console.log(`Pool: ${auction_pool_address}, Symbol: ${auction_base_token_symbol}`);
105
+ }
106
+
107
+ // Create dynamic auction
108
+ const createResponse = await apiClient.auctions.createDynamicAuction({
109
+ body: {
110
+ chain_id: 8453, // Base
111
+ template_id: 'template_123',
112
+ metadata: {
113
+ token_name: 'My Token',
114
+ token_symbol: 'MTK',
115
+ token_uri: 'ipfs://...',
116
+ migration_duration: 86400,
117
+ migration_beneficiaries: [
118
+ { address: '0xabc...', percentage: 100 }
119
+ ],
120
+ user_address: '0xdef...'
121
+ }
122
+ }
123
+ });
124
+
125
+ if (createResponse.status === 200) {
126
+ const { governance_factory, pool_initializer, liquidity_migrator } = createResponse.body.result;
127
+ console.log('Auction created with factories:', { governance_factory, pool_initializer });
128
+ }
129
+ ```
130
+
131
+ ### Quote Endpoints (Uniswap V3/V4)
132
+
133
+ ```typescript
134
+ // V4 Exact Input Quote
135
+ const v4Quote = await apiClient.quotes.v4ExactInputSingle({
136
+ body: {
137
+ chainId: 8453,
138
+ poolKey: {
139
+ currency0: '0x0000000000000000000000000000000000000000', // ETH
140
+ currency1: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
141
+ fee: 500,
142
+ tickSpacing: 10,
143
+ hooks: '0x0000000000000000000000000000000000000000'
144
+ },
145
+ zeroForOne: true,
146
+ exactAmount: '1000000000000000000' // 1 ETH
147
+ }
148
+ });
149
+
150
+ if (v4Quote.status === 200) {
151
+ console.log(`Output amount: ${v4Quote.body.result.amountOut}`);
152
+ console.log(`Gas estimate: ${v4Quote.body.result.gasEstimate}`);
153
+ }
154
+
155
+ // V3 Exact Input Quote
156
+ const v3InputQuote = await apiClient.quotes.v3ExactInputSingle({
157
+ body: {
158
+ chainId: 1,
159
+ tokenIn: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
160
+ tokenOut: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
161
+ amountIn: '1000000000000000000', // 1 WETH
162
+ fee: 500 // 0.05%
163
+ }
164
+ });
165
+
166
+ if (v3InputQuote.status === 200) {
167
+ console.log(`Output amount: ${v3InputQuote.body.result.amountOut}`);
168
+ console.log(`Price after: ${v3InputQuote.body.result.sqrtPriceX96After}`);
169
+ }
170
+
171
+ // V3 Exact Output Quote
172
+ const v3OutputQuote = await apiClient.quotes.v3ExactOutputSingle({
173
+ body: {
174
+ chainId: 1,
175
+ tokenIn: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
176
+ tokenOut: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
177
+ amountOut: '1000000000', // 1000 USDC
178
+ fee: 500 // 0.05%
179
+ }
180
+ });
181
+
182
+ if (v3OutputQuote.status === 200) {
183
+ console.log(`Input required: ${v3OutputQuote.body.result.amountIn}`);
184
+ }
185
+ ```
186
+
187
+ ### Community Endpoints
188
+
189
+ ```typescript
190
+ // Fetch all communities
191
+ const communities = await apiClient.communities.fetchCommunities();
192
+
193
+ if (communities.status === 200) {
194
+ communities.body.result.forEach(community => {
195
+ console.log(`${community.label}: ${community.description}`);
196
+ console.log(`Funding: ${community.funding_amount}`);
197
+ });
198
+ }
199
+
200
+ // Get specific community
201
+ const community = await apiClient.communities.getCommunity({
202
+ params: { id: 1 }
203
+ });
204
+ ```
205
+
206
+ ### IPFS Endpoints
207
+
208
+ ```typescript
209
+ // Upload an image to IPFS
210
+ const formData = new FormData();
211
+ formData.append('image', imageFile); // imageFile is a File object
212
+
213
+ const imageUpload = await apiClient.ipfs.uploadImage({
214
+ body: formData
215
+ });
216
+
217
+ if (imageUpload.status === 200) {
218
+ const imageHash = imageUpload.body.result;
219
+ console.log(`Image IPFS hash: ${imageHash}`);
220
+ }
221
+
222
+ // Upload metadata to IPFS
223
+ const metadataUpload = await apiClient.ipfs.uploadMetadata({
224
+ body: {
225
+ name: 'My Token',
226
+ description: 'Token description',
227
+ image_hash: imageHash, // From previous upload
228
+ social_links: [
229
+ { label: 'Twitter', url: 'https://twitter.com/mytoken' },
230
+ { label: 'Discord', url: 'https://discord.gg/mytoken' }
231
+ ],
232
+ vesting_recipients: [
233
+ { address: '0xabc...', percentage: 50 },
234
+ { address: '0xdef...', percentage: 50 }
235
+ ],
236
+ fee_receiver: '0x123...'
237
+ }
238
+ });
239
+
240
+ if (metadataUpload.status === 200) {
241
+ const metadataHash = metadataUpload.body.result;
242
+ console.log(`Metadata IPFS hash: ${metadataHash}`);
243
+ }
244
+ ```
245
+
246
+ ## Type Utilities
247
+
248
+ ### Pool Key Type (Uniswap V4)
249
+
250
+ ```typescript
251
+ import { PoolKey } from '@longdotxyz/shared';
252
+
253
+ const poolKey: PoolKey = {
254
+ currency0: '0x0000000000000000000000000000000000000000',
255
+ currency1: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
256
+ fee: 500,
257
+ tickSpacing: 10,
258
+ hooks: '0x0000000000000000000000000000000000000000'
259
+ };
260
+ ```
261
+
262
+ ### Hex Address Validation
263
+
264
+ ```typescript
265
+ import { hex } from '@longdotxyz/shared';
266
+ import { z } from 'zod';
267
+
268
+ // Validate and normalize hex addresses
269
+ const addressSchema = z.string().pipe(hex);
270
+ const validAddress = addressSchema.parse('0xabc...'); // Returns lowercase hex
271
+ ```
272
+
273
+ ### BigInt Coercion
274
+
275
+ ```typescript
276
+ import { coerceBigInt } from '@longdotxyz/shared';
277
+
278
+ const amount = coerceBigInt.parse('1000000000000000000'); // Returns bigint
279
+ const amount2 = coerceBigInt.parse(1000n); // Also accepts bigint
280
+ ```
281
+
282
+ ## Native Token Utilities
283
+
284
+ ```typescript
285
+ import { isNativeToken, isNativeTokenAddress } from '@longdotxyz/shared';
286
+
287
+ // Check if address is native token (ETH)
288
+ isNativeTokenAddress('0x0000000000000000000000000000000000000000'); // true
289
+ isNativeTokenAddress('0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'); // true
290
+
291
+ // Check token object
292
+ isNativeToken({
293
+ address: '0x0000000000000000000000000000000000000000',
294
+ symbol: 'ETH'
295
+ }); // true
296
+ ```
297
+
298
+ ## Development
299
+
300
+ ### Building the Library
301
+
302
+ ```bash
303
+ # Generate GraphQL types
304
+ pnpm codegen
305
+
306
+ # Build TypeScript
307
+ pnpm build
308
+
309
+ # Run tests
310
+ pnpm test
311
+
312
+ # Format and lint
313
+ pnpm format
314
+ pnpm lint
315
+ ```
316
+
317
+ ### GraphQL Code Generation
318
+
319
+ The GraphQL types are generated from a schema using `@graphql-codegen`. Configuration is in `codegen.ts`.
320
+
321
+ ```bash
322
+ pnpm codegen
323
+ ```
324
+
325
+ ## API Contract Structure
326
+
327
+ All API contracts are defined using ts-rest and exported from `@longdotxyz/shared/contracts`:
328
+
329
+ - **Auctions**: `/auctions/*` - Dynamic auction creation and management
330
+ - **Quotes**: `/quotes/*` - Uniswap V3/V4 swap quotes
331
+ - **Communities**: `/communities/*` - Community data management
332
+ - **IPFS**: `/ipfs/*` - IPFS content creation
333
+
334
+ ## License
335
+
336
+ UNLICENSED