@longdotxyz/shared 0.0.101 → 0.0.103
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/dist/contracts/index.d.ts +81 -17
- package/dist/contracts/pathfinding.contract.d.ts +143 -33
- package/dist/contracts/pathfinding.contract.js +45 -21
- package/dist/contracts/pathfinding.contract.js.map +1 -1
- package/dist/graphql/generated.d.ts +313 -0
- package/dist/graphql/generated.js +92 -1
- package/dist/graphql/generated.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +185 -137
package/readme.md
CHANGED
|
@@ -24,11 +24,12 @@ The library includes auto-generated GraphQL types and a ready-to-use SDK client.
|
|
|
24
24
|
### Basic Setup
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
|
-
import { GraphQLClient } from
|
|
28
|
-
|
|
27
|
+
import { GraphQLClient } from "graphql-request";
|
|
28
|
+
|
|
29
|
+
import { getSdk } from "@longdotxyz/shared";
|
|
29
30
|
|
|
30
31
|
// Initialize GraphQL client
|
|
31
|
-
const client = new GraphQLClient(
|
|
32
|
+
const client = new GraphQLClient("https://graphql.long.xyz");
|
|
32
33
|
|
|
33
34
|
// Create SDK instance
|
|
34
35
|
const sdk = getSdk(client);
|
|
@@ -37,36 +38,30 @@ const sdk = getSdk(client);
|
|
|
37
38
|
### Example: Fetch Auction by Address
|
|
38
39
|
|
|
39
40
|
```typescript
|
|
40
|
-
import {
|
|
41
|
+
import { GetAuctionByAddressQuery, getSdk } from "@longdotxyz/shared";
|
|
41
42
|
|
|
42
43
|
// Query an auction
|
|
43
44
|
const { auction_pool } = await sdk.GetAuctionByAddress({
|
|
44
|
-
|
|
45
|
+
address: "0x123...",
|
|
45
46
|
});
|
|
46
47
|
|
|
47
48
|
// Type-safe access to auction data
|
|
48
49
|
if (auction_pool) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
console.log(auction_pool.auction_pool_address);
|
|
51
|
+
console.log(auction_pool.asset_address);
|
|
52
|
+
console.log(auction_pool.numeraire_address);
|
|
52
53
|
}
|
|
53
54
|
```
|
|
54
55
|
|
|
55
56
|
### Available GraphQL Types
|
|
56
57
|
|
|
57
58
|
```typescript
|
|
58
|
-
import type {
|
|
59
|
-
Asset,
|
|
60
|
-
AuctionPool,
|
|
61
|
-
GraduationPool,
|
|
62
|
-
Asset_Bool_Exp,
|
|
63
|
-
Asset_Order_By
|
|
64
|
-
} from '@longdotxyz/shared';
|
|
59
|
+
import type { Asset, Asset_Bool_Exp, Asset_Order_By, AuctionPool, GraduationPool } from "@longdotxyz/shared";
|
|
65
60
|
|
|
66
61
|
// Use types for type-safe queries
|
|
67
62
|
const assetFilter: Asset_Bool_Exp = {
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
chain_id: { _eq: 1 },
|
|
64
|
+
asset_address: { _ilike: "0x%" },
|
|
70
65
|
};
|
|
71
66
|
```
|
|
72
67
|
|
|
@@ -77,15 +72,16 @@ The library provides type-safe REST API contracts using [ts-rest](https://ts-res
|
|
|
77
72
|
### Initialize API Client
|
|
78
73
|
|
|
79
74
|
```typescript
|
|
80
|
-
import { initClient } from
|
|
81
|
-
|
|
75
|
+
import { initClient } from "@ts-rest/core";
|
|
76
|
+
|
|
77
|
+
import { rootContract } from "@longdotxyz/shared";
|
|
82
78
|
|
|
83
79
|
// Create typed API client
|
|
84
80
|
const apiClient = initClient(rootContract, {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
baseUrl: "https://api.long.xyz/v1",
|
|
82
|
+
baseHeaders: {
|
|
83
|
+
"Content-Type": "application/json",
|
|
84
|
+
},
|
|
89
85
|
});
|
|
90
86
|
```
|
|
91
87
|
|
|
@@ -94,37 +90,35 @@ const apiClient = initClient(rootContract, {
|
|
|
94
90
|
```typescript
|
|
95
91
|
// Get dynamic auction details
|
|
96
92
|
const auctionResponse = await apiClient.auctions.getDynamicAuction({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
params: {
|
|
94
|
+
address: "0x123...",
|
|
95
|
+
},
|
|
100
96
|
});
|
|
101
97
|
|
|
102
98
|
if (auctionResponse.status === 200) {
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
const { auction_pool_address, auction_base_token_symbol } = auctionResponse.body.result;
|
|
100
|
+
console.log(`Pool: ${auction_pool_address}, Symbol: ${auction_base_token_symbol}`);
|
|
105
101
|
}
|
|
106
102
|
|
|
107
103
|
// Create dynamic auction
|
|
108
104
|
const createResponse = await apiClient.auctions.createDynamicAuction({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
}
|
|
105
|
+
body: {
|
|
106
|
+
chain_id: 8453, // Base
|
|
107
|
+
template_id: "template_123",
|
|
108
|
+
metadata: {
|
|
109
|
+
token_name: "My Token",
|
|
110
|
+
token_symbol: "MTK",
|
|
111
|
+
token_uri: "ipfs://...",
|
|
112
|
+
migration_duration: 86400,
|
|
113
|
+
migration_beneficiaries: [{ address: "0xabc...", amount: 10000 }],
|
|
114
|
+
user_address: "0xdef...",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
123
117
|
});
|
|
124
118
|
|
|
125
119
|
if (createResponse.status === 200) {
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
const { governance_factory, pool_initializer, liquidity_migrator } = createResponse.body.result;
|
|
121
|
+
console.log("Auction created with factories:", { governance_factory, pool_initializer });
|
|
128
122
|
}
|
|
129
123
|
```
|
|
130
124
|
|
|
@@ -133,83 +127,83 @@ if (createResponse.status === 200) {
|
|
|
133
127
|
```typescript
|
|
134
128
|
// V4 Exact Input Quote
|
|
135
129
|
const v4InputQuote = await apiClient.quotes.v4ExactInputSingle({
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
130
|
+
body: {
|
|
131
|
+
chain_id: 8453,
|
|
132
|
+
pool_key: {
|
|
133
|
+
currency0: "0x0000000000000000000000000000000000000000", // ETH
|
|
134
|
+
currency1: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
|
|
135
|
+
fee: 500,
|
|
136
|
+
tick_spacing: 10,
|
|
137
|
+
hooks: "0x0000000000000000000000000000000000000000",
|
|
138
|
+
},
|
|
139
|
+
zero_for_one: true,
|
|
140
|
+
exact_amount: "1000000000000000000", // 1 ETH
|
|
141
|
+
hook_data: "0x", // Optional hook data
|
|
144
142
|
},
|
|
145
|
-
zero_for_one: true,
|
|
146
|
-
exact_amount: '1000000000000000000', // 1 ETH
|
|
147
|
-
hook_data: '0x' // Optional hook data
|
|
148
|
-
}
|
|
149
143
|
});
|
|
150
144
|
|
|
151
145
|
if (v4InputQuote.status === 200) {
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
console.log(`Output amount: ${v4InputQuote.body.result.amount_out}`);
|
|
147
|
+
console.log(`Gas estimate: ${v4InputQuote.body.result.gas_estimate}`);
|
|
154
148
|
}
|
|
155
149
|
|
|
156
150
|
// V4 Exact Output Quote
|
|
157
151
|
const v4OutputQuote = await apiClient.quotes.v4ExactOutputSingle({
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
152
|
+
body: {
|
|
153
|
+
chain_id: 8453,
|
|
154
|
+
pool_key: {
|
|
155
|
+
currency0: "0x0000000000000000000000000000000000000000", // ETH
|
|
156
|
+
currency1: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
|
|
157
|
+
fee: 500,
|
|
158
|
+
tick_spacing: 10,
|
|
159
|
+
hooks: "0x0000000000000000000000000000000000000000",
|
|
160
|
+
},
|
|
161
|
+
zero_for_one: true,
|
|
162
|
+
exact_amount: "1000000000", // 1000 USDC output
|
|
163
|
+
hook_data: "0x", // Optional hook data
|
|
166
164
|
},
|
|
167
|
-
zero_for_one: true,
|
|
168
|
-
exact_amount: '1000000000', // 1000 USDC output
|
|
169
|
-
hook_data: '0x' // Optional hook data
|
|
170
|
-
}
|
|
171
165
|
});
|
|
172
166
|
|
|
173
167
|
if (v4OutputQuote.status === 200) {
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
console.log(`Input required: ${v4OutputQuote.body.result.amount_in}`);
|
|
169
|
+
console.log(`Gas estimate: ${v4OutputQuote.body.result.gas_estimate}`);
|
|
176
170
|
}
|
|
177
171
|
|
|
178
172
|
// V3 Exact Input Quote
|
|
179
173
|
const v3InputQuote = await apiClient.quotes.v3ExactInputSingle({
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
174
|
+
body: {
|
|
175
|
+
chain_id: 1,
|
|
176
|
+
token_in: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
|
|
177
|
+
token_out: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
|
|
178
|
+
amount_in: "1000000000000000000", // 1 WETH
|
|
179
|
+
fee: 500, // 0.05%
|
|
180
|
+
sqrt_price_limit_x96: "0", // Optional price limit
|
|
181
|
+
},
|
|
188
182
|
});
|
|
189
183
|
|
|
190
184
|
if (v3InputQuote.status === 200) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
185
|
+
console.log(`Output amount: ${v3InputQuote.body.result.amount_out}`);
|
|
186
|
+
console.log(`Price after: ${v3InputQuote.body.result.sqrt_price_x96_after}`);
|
|
187
|
+
console.log(`Ticks crossed: ${v3InputQuote.body.result.initialized_ticks_crossed}`);
|
|
188
|
+
console.log(`Gas estimate: ${v3InputQuote.body.result.gas_estimate}`);
|
|
195
189
|
}
|
|
196
190
|
|
|
197
191
|
// V3 Exact Output Quote
|
|
198
192
|
const v3OutputQuote = await apiClient.quotes.v3ExactOutputSingle({
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
193
|
+
body: {
|
|
194
|
+
chain_id: 1,
|
|
195
|
+
token_in: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
|
|
196
|
+
token_out: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
|
|
197
|
+
amount_out: "1000000000", // 1000 USDC
|
|
198
|
+
fee: 500, // 0.05%
|
|
199
|
+
},
|
|
206
200
|
});
|
|
207
201
|
|
|
208
202
|
if (v3OutputQuote.status === 200) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
203
|
+
console.log(`Input required: ${v3OutputQuote.body.result.amount_in}`);
|
|
204
|
+
console.log(`Price after: ${v3OutputQuote.body.result.sqrt_price_x96_after}`);
|
|
205
|
+
console.log(`Ticks crossed: ${v3OutputQuote.body.result.initialized_ticks_crossed}`);
|
|
206
|
+
console.log(`Gas estimate: ${v3OutputQuote.body.result.gas_estimate}`);
|
|
213
207
|
}
|
|
214
208
|
```
|
|
215
209
|
|
|
@@ -220,15 +214,15 @@ if (v3OutputQuote.status === 200) {
|
|
|
220
214
|
const communities = await apiClient.communities.fetchCommunities();
|
|
221
215
|
|
|
222
216
|
if (communities.status === 200) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
217
|
+
communities.body.result.forEach((community) => {
|
|
218
|
+
console.log(`${community.label}: ${community.description}`);
|
|
219
|
+
console.log(`Funding: ${community.funding_amount}`);
|
|
220
|
+
});
|
|
227
221
|
}
|
|
228
222
|
|
|
229
223
|
// Get specific community
|
|
230
224
|
const community = await apiClient.communities.getCommunity({
|
|
231
|
-
|
|
225
|
+
params: { id: 1 },
|
|
232
226
|
});
|
|
233
227
|
```
|
|
234
228
|
|
|
@@ -237,90 +231,144 @@ const community = await apiClient.communities.getCommunity({
|
|
|
237
231
|
```typescript
|
|
238
232
|
// Upload an image to IPFS
|
|
239
233
|
const formData = new FormData();
|
|
240
|
-
formData.append(
|
|
234
|
+
formData.append("image", imageFile); // imageFile is a File object
|
|
241
235
|
|
|
242
236
|
const imageUpload = await apiClient.ipfs.uploadImage({
|
|
243
|
-
|
|
237
|
+
body: formData,
|
|
244
238
|
});
|
|
245
239
|
|
|
246
240
|
if (imageUpload.status === 200) {
|
|
247
|
-
|
|
248
|
-
|
|
241
|
+
const imageHash = imageUpload.body.result;
|
|
242
|
+
console.log(`Image IPFS hash: ${imageHash}`);
|
|
249
243
|
}
|
|
250
244
|
|
|
251
245
|
// Upload metadata to IPFS
|
|
252
246
|
const metadataUpload = await apiClient.ipfs.uploadMetadata({
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
247
|
+
body: {
|
|
248
|
+
name: "My Token",
|
|
249
|
+
description: "Token description",
|
|
250
|
+
image_hash: imageHash, // From previous upload
|
|
251
|
+
social_links: [
|
|
252
|
+
{ label: "Twitter", url: "https://twitter.com/mytoken" },
|
|
253
|
+
{ label: "Discord", url: "https://discord.gg/mytoken" },
|
|
254
|
+
],
|
|
255
|
+
vesting_recipients: [
|
|
256
|
+
{ address: "0xabc...", amount: 5000 },
|
|
257
|
+
{ address: "0xdef...", amount: 5000 },
|
|
258
|
+
],
|
|
259
|
+
fee_receiver: "0x123...",
|
|
260
|
+
},
|
|
267
261
|
});
|
|
268
262
|
|
|
269
263
|
if (metadataUpload.status === 200) {
|
|
270
|
-
|
|
271
|
-
|
|
264
|
+
const metadataHash = metadataUpload.body.result;
|
|
265
|
+
console.log(`Metadata IPFS hash: ${metadataHash}`);
|
|
272
266
|
}
|
|
273
267
|
```
|
|
274
268
|
|
|
269
|
+
### Pathfinding Endpoints
|
|
270
|
+
|
|
271
|
+
#### Get Swap Paths
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
import { apiClient } from "@longdotxyz/shared";
|
|
275
|
+
|
|
276
|
+
// Basic usage (Codex only)
|
|
277
|
+
const paths = await apiClient.pathfinding.fetchTokenPaths({
|
|
278
|
+
params: { tokenInAddress: "0xTokenAddress" },
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// With Kyber fallback (when amount provided)
|
|
282
|
+
const pathsWithFallback = await apiClient.pathfinding.fetchTokenPaths({
|
|
283
|
+
params: { tokenInAddress: "0xTokenAddress" },
|
|
284
|
+
query: {
|
|
285
|
+
amount: "1000000000000000000", // 1 token in wei
|
|
286
|
+
tokenOut: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", // Optional: USDC
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
if (pathsWithFallback.status === 200) {
|
|
291
|
+
const { paths, paths_count } = pathsWithFallback.body;
|
|
292
|
+
|
|
293
|
+
paths.forEach((path) => {
|
|
294
|
+
if (path.source === "kyber") {
|
|
295
|
+
// Kyber route includes executable calldata
|
|
296
|
+
console.log("Router:", path.router_address);
|
|
297
|
+
console.log("Calldata:", path.encoded_calldata);
|
|
298
|
+
console.log("Expected output:", path.amount_out);
|
|
299
|
+
} else {
|
|
300
|
+
// Codex route includes liquidity metrics
|
|
301
|
+
console.log("Liquidity:", path.total_liquidity_usd);
|
|
302
|
+
console.log("Volume:", path.total_volume_usd);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
**Query Parameters:**
|
|
309
|
+
|
|
310
|
+
- `amount` (optional): Swap amount in wei. When provided, enables Kyber fallback if Codex returns no paths.
|
|
311
|
+
- `tokenOut` (optional): Target token address. If omitted, queries all exit tokens (WETH, USDC, ETH on Base).
|
|
312
|
+
|
|
313
|
+
**Response Fields:**
|
|
314
|
+
|
|
315
|
+
- `source`: Either `"codex"` or `"kyber"` - indicates which service provided the route
|
|
316
|
+
- `encoded_calldata` (Kyber only): Ready-to-execute swap calldata
|
|
317
|
+
- `router_address` (Kyber only): Kyber router contract address
|
|
318
|
+
- `amount_in` (Kyber only): Input amount in wei
|
|
319
|
+
- `amount_out` (Kyber only): Expected output amount in wei
|
|
320
|
+
- `gas_estimate` (Kyber only): Estimated gas for the swap
|
|
321
|
+
|
|
275
322
|
## Type Utilities
|
|
276
323
|
|
|
277
324
|
### Pool Key Type (Uniswap V4)
|
|
278
325
|
|
|
279
326
|
```typescript
|
|
280
|
-
import { PoolKey } from
|
|
327
|
+
import { PoolKey } from "@longdotxyz/shared";
|
|
281
328
|
|
|
282
329
|
const poolKey: PoolKey = {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
330
|
+
currency0: "0x0000000000000000000000000000000000000000",
|
|
331
|
+
currency1: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
332
|
+
fee: 500,
|
|
333
|
+
tick_spacing: 10,
|
|
334
|
+
hooks: "0x0000000000000000000000000000000000000000",
|
|
288
335
|
};
|
|
289
336
|
```
|
|
290
337
|
|
|
291
338
|
### Hex Address Validation
|
|
292
339
|
|
|
293
340
|
```typescript
|
|
294
|
-
import {
|
|
295
|
-
|
|
341
|
+
import { z } from "zod";
|
|
342
|
+
|
|
343
|
+
import { hex } from "@longdotxyz/shared";
|
|
296
344
|
|
|
297
345
|
// Validate and normalize hex addresses
|
|
298
346
|
const addressSchema = z.string().pipe(hex);
|
|
299
|
-
const validAddress = addressSchema.parse(
|
|
347
|
+
const validAddress = addressSchema.parse("0xabc..."); // Returns lowercase hex
|
|
300
348
|
```
|
|
301
349
|
|
|
302
350
|
### BigInt Coercion
|
|
303
351
|
|
|
304
352
|
```typescript
|
|
305
|
-
import { coerceBigInt } from
|
|
353
|
+
import { coerceBigInt } from "@longdotxyz/shared";
|
|
306
354
|
|
|
307
|
-
const amount = coerceBigInt.parse(
|
|
355
|
+
const amount = coerceBigInt.parse("1000000000000000000"); // Returns bigint
|
|
308
356
|
const amount2 = coerceBigInt.parse(1000n); // Also accepts bigint
|
|
309
357
|
```
|
|
310
358
|
|
|
311
359
|
## Native Token Utilities
|
|
312
360
|
|
|
313
361
|
```typescript
|
|
314
|
-
import { isNativeToken, isNativeTokenAddress } from
|
|
362
|
+
import { isNativeToken, isNativeTokenAddress } from "@longdotxyz/shared";
|
|
315
363
|
|
|
316
364
|
// Check if address is native token (ETH)
|
|
317
|
-
isNativeTokenAddress(
|
|
318
|
-
isNativeTokenAddress(
|
|
365
|
+
isNativeTokenAddress("0x0000000000000000000000000000000000000000"); // true
|
|
366
|
+
isNativeTokenAddress("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"); // true
|
|
319
367
|
|
|
320
368
|
// Check token object
|
|
321
369
|
isNativeToken({
|
|
322
|
-
|
|
323
|
-
|
|
370
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
371
|
+
symbol: "ETH",
|
|
324
372
|
}); // true
|
|
325
373
|
```
|
|
326
374
|
|
|
@@ -362,4 +410,4 @@ All API contracts are defined using ts-rest and exported from `@longdotxyz/share
|
|
|
362
410
|
|
|
363
411
|
## License
|
|
364
412
|
|
|
365
|
-
UNLICENSED
|
|
413
|
+
UNLICENSED
|