@opensea/sdk 10.5.0 → 11.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/lib/api/accounts.js +12 -8
- package/lib/api/accounts.js.map +1 -1
- package/lib/api/api.d.ts +27 -11
- package/lib/api/api.js +56 -18
- package/lib/api/api.js.map +1 -1
- package/lib/api/apiPaths.d.ts +2 -0
- package/lib/api/apiPaths.js +9 -1
- package/lib/api/apiPaths.js.map +1 -1
- package/lib/api/collections.js +7 -15
- package/lib/api/collections.js.map +1 -1
- package/lib/api/fetcher.d.ts +35 -5
- package/lib/api/listings.js +3 -3
- package/lib/api/listings.js.map +1 -1
- package/lib/api/nfts.d.ts +1 -1
- package/lib/api/nfts.js +2 -5
- package/lib/api/nfts.js.map +1 -1
- package/lib/api/offers.d.ts +11 -0
- package/lib/api/offers.js +14 -11
- package/lib/api/offers.js.map +1 -1
- package/lib/api/orders.d.ts +16 -1
- package/lib/api/orders.js +17 -3
- package/lib/api/orders.js.map +1 -1
- package/lib/api/tokens.d.ts +14 -3
- package/lib/api/tokens.js +16 -1
- package/lib/api/tokens.js.map +1 -1
- package/lib/api/types.d.ts +216 -356
- package/lib/api/types.js +2 -1
- package/lib/api/types.js.map +1 -1
- package/lib/orders/types.d.ts +2 -2
- package/lib/orders/utils.d.ts +53 -13
- package/lib/orders/utils.js +33 -50
- package/lib/orders/utils.js.map +1 -1
- package/lib/sdk/base.d.ts +11 -4
- package/lib/sdk/base.js +4 -4
- package/lib/sdk/base.js.map +1 -1
- package/lib/sdk/cancellation.d.ts +3 -1
- package/lib/sdk/cancellation.js +12 -6
- package/lib/sdk/cancellation.js.map +1 -1
- package/lib/sdk/fulfillment.js +7 -4
- package/lib/sdk/fulfillment.js.map +1 -1
- package/lib/sdk/orders.js +1 -1
- package/lib/sdk/orders.js.map +1 -1
- package/lib/types.d.ts +22 -122
- package/lib/types.js.map +1 -1
- package/lib/utils/case.d.ts +63 -0
- package/lib/utils/case.js +83 -0
- package/lib/utils/case.js.map +1 -0
- package/lib/utils/utils.d.ts +0 -1
- package/lib/utils/utils.js +0 -1
- package/lib/utils/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/api/accounts.ts +14 -8
- package/src/api/api.ts +88 -25
- package/src/api/apiPaths.ts +8 -0
- package/src/api/collections.ts +7 -21
- package/src/api/fetcher.ts +41 -6
- package/src/api/listings.ts +3 -3
- package/src/api/nfts.ts +3 -7
- package/src/api/offers.ts +17 -10
- package/src/api/orders.ts +29 -5
- package/src/api/tokens.ts +39 -2
- package/src/api/types.ts +290 -399
- package/src/orders/types.ts +2 -2
- package/src/orders/utils.ts +57 -79
- package/src/sdk/base.ts +4 -4
- package/src/sdk/cancellation.ts +16 -6
- package/src/sdk/fulfillment.ts +7 -6
- package/src/sdk/orders.ts +1 -1
- package/src/types.ts +33 -120
- package/src/utils/case.ts +150 -0
- package/src/utils/utils.ts +0 -1
- package/lib/utils/converters.d.ts +0 -37
- package/lib/utils/converters.js +0 -137
- package/lib/utils/converters.js.map +0 -1
- package/src/utils/converters.ts +0 -145
package/src/api/api.ts
CHANGED
|
@@ -11,6 +11,11 @@ import {
|
|
|
11
11
|
type OrderSide,
|
|
12
12
|
type RequestOptions,
|
|
13
13
|
} from "../types"
|
|
14
|
+
import {
|
|
15
|
+
type Camelize,
|
|
16
|
+
camelizeKeysDeep,
|
|
17
|
+
snakeizeKeysDeep,
|
|
18
|
+
} from "../utils/case"
|
|
14
19
|
import { executeWithRateLimit } from "../utils/rateLimit"
|
|
15
20
|
import { AccountsAPI } from "./accounts"
|
|
16
21
|
import { getInstantApiKeyPath } from "./apiPaths"
|
|
@@ -19,6 +24,7 @@ import { ChainsAPI } from "./chains"
|
|
|
19
24
|
import { CollectionsAPI } from "./collections"
|
|
20
25
|
import { DropsAPI } from "./drops"
|
|
21
26
|
import { EventsAPI } from "./events"
|
|
27
|
+
import type { PostOptions } from "./fetcher"
|
|
22
28
|
import { ListingsAPI } from "./listings"
|
|
23
29
|
import { NFTsAPI } from "./nfts"
|
|
24
30
|
import { OffersAPI } from "./offers"
|
|
@@ -110,6 +116,10 @@ import {
|
|
|
110
116
|
type SweepCollectionResponse,
|
|
111
117
|
type TokenActivityArgs,
|
|
112
118
|
type TokenBatchResponse,
|
|
119
|
+
type TokenHoldersArgs,
|
|
120
|
+
type TokenHoldersResponse,
|
|
121
|
+
type TokenLiquidityPoolsArgs,
|
|
122
|
+
type TokenLiquidityPoolsResponse,
|
|
113
123
|
type TokenSwapActivityPaginatedResponse,
|
|
114
124
|
type TokenTimeSeriesArgs,
|
|
115
125
|
type TraitFilter,
|
|
@@ -373,7 +383,7 @@ export class OpenSeaAPI {
|
|
|
373
383
|
unitsToFill?: string,
|
|
374
384
|
recipientAddress?: string,
|
|
375
385
|
includeOptionalCreatorFees: boolean = false,
|
|
376
|
-
): Promise<FulfillmentDataResponse
|
|
386
|
+
): Promise<Camelize<FulfillmentDataResponse>> {
|
|
377
387
|
return this.ordersAPI.generateFulfillmentData(
|
|
378
388
|
fulfillerAddress,
|
|
379
389
|
orderHash,
|
|
@@ -637,7 +647,7 @@ export class OpenSeaAPI {
|
|
|
637
647
|
address: string,
|
|
638
648
|
identifier: string,
|
|
639
649
|
chain: Chain = this.chain,
|
|
640
|
-
): Promise<
|
|
650
|
+
): Promise<Record<string, unknown>> {
|
|
641
651
|
return this.nftsAPI.refreshNFTMetadata(address, identifier, chain)
|
|
642
652
|
}
|
|
643
653
|
|
|
@@ -1050,13 +1060,13 @@ export class OpenSeaAPI {
|
|
|
1050
1060
|
* Fetch OHLCV candles for a token.
|
|
1051
1061
|
* @param chain Chain the token lives on.
|
|
1052
1062
|
* @param address Token contract address.
|
|
1053
|
-
* @param args Time-series window plus candle `
|
|
1063
|
+
* @param args Time-series window plus candle `bucketSize` (required).
|
|
1054
1064
|
* @returns The {@link OhlcvResponse} returned by the API.
|
|
1055
1065
|
*/
|
|
1056
1066
|
public async getTokenOhlcv(
|
|
1057
1067
|
chain: Chain,
|
|
1058
1068
|
address: string,
|
|
1059
|
-
args: TokenTimeSeriesArgs & {
|
|
1069
|
+
args: TokenTimeSeriesArgs & { bucketSize: string },
|
|
1060
1070
|
): Promise<OhlcvResponse> {
|
|
1061
1071
|
return this.tokensAPI.getTokenOhlcv(chain, address, args)
|
|
1062
1072
|
}
|
|
@@ -1072,6 +1082,30 @@ export class OpenSeaAPI {
|
|
|
1072
1082
|
return this.tokensAPI.getTokenActivity(chain, address, args)
|
|
1073
1083
|
}
|
|
1074
1084
|
|
|
1085
|
+
/**
|
|
1086
|
+
* Fetch paginated holders for a token, including quantity held, USD value,
|
|
1087
|
+
* and aggregate distribution health (STRONG | HEALTHY | CONCERNING | BAD).
|
|
1088
|
+
*/
|
|
1089
|
+
public async getTokenHolders(
|
|
1090
|
+
chain: Chain,
|
|
1091
|
+
address: string,
|
|
1092
|
+
args?: TokenHoldersArgs,
|
|
1093
|
+
): Promise<TokenHoldersResponse> {
|
|
1094
|
+
return this.tokensAPI.getTokenHolders(chain, address, args)
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Fetch liquidity pools for a token (pool type, USD reserves, and
|
|
1099
|
+
* bonding-curve progress / graduation flag where applicable).
|
|
1100
|
+
*/
|
|
1101
|
+
public async getTokenLiquidityPools(
|
|
1102
|
+
chain: Chain,
|
|
1103
|
+
address: string,
|
|
1104
|
+
args?: TokenLiquidityPoolsArgs,
|
|
1105
|
+
): Promise<TokenLiquidityPoolsResponse> {
|
|
1106
|
+
return this.tokensAPI.getTokenLiquidityPools(chain, address, args)
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1075
1109
|
/**
|
|
1076
1110
|
* Fetch multiple NFTs in a single request.
|
|
1077
1111
|
*/
|
|
@@ -1261,14 +1295,17 @@ export class OpenSeaAPI {
|
|
|
1261
1295
|
apiPath: string,
|
|
1262
1296
|
query: object = {},
|
|
1263
1297
|
options?: RequestOptions,
|
|
1264
|
-
): Promise<T
|
|
1298
|
+
): Promise<Camelize<T>> {
|
|
1265
1299
|
return executeWithRateLimit(
|
|
1266
1300
|
async () => {
|
|
1267
|
-
|
|
1301
|
+
// Snakeize query keys so consumers can pass camelCase args even
|
|
1302
|
+
// though the API expects snake_case URL params.
|
|
1303
|
+
const qs = this.objectToSearchParams(snakeizeKeysDeep(query))
|
|
1268
1304
|
const url = qs
|
|
1269
1305
|
? `${this.apiBaseUrl}${apiPath}?${qs}`
|
|
1270
1306
|
: `${this.apiBaseUrl}${apiPath}`
|
|
1271
|
-
|
|
1307
|
+
const raw = await this._fetch(url, undefined, undefined, options)
|
|
1308
|
+
return camelizeKeysDeep(raw) as Camelize<T>
|
|
1272
1309
|
},
|
|
1273
1310
|
{ logger: this.logger },
|
|
1274
1311
|
)
|
|
@@ -1279,19 +1316,30 @@ export class OpenSeaAPI {
|
|
|
1279
1316
|
* @param apiPath Path to URL endpoint under API
|
|
1280
1317
|
* @param body Data to send.
|
|
1281
1318
|
* @param headers Additional headers to send with the request.
|
|
1282
|
-
* @param options Request options
|
|
1319
|
+
* @param options Request options. Includes the {@link PostOptions.snakeizeBody}
|
|
1320
|
+
* opt-out (defaults to `true`) for callers that need to emit
|
|
1321
|
+
* the body in exact wire shape (e.g. Seaport-shaped POSTs
|
|
1322
|
+
* whose inner keys are camelCase on the wire).
|
|
1283
1323
|
* @returns @typeParam T The response from the API.
|
|
1284
1324
|
*/
|
|
1285
1325
|
public async post<T>(
|
|
1286
1326
|
apiPath: string,
|
|
1287
1327
|
body?: object,
|
|
1288
1328
|
headers?: object,
|
|
1289
|
-
options?:
|
|
1290
|
-
): Promise<T
|
|
1329
|
+
options?: PostOptions,
|
|
1330
|
+
): Promise<Camelize<T>> {
|
|
1291
1331
|
return executeWithRateLimit(
|
|
1292
1332
|
async () => {
|
|
1293
1333
|
const url = `${this.apiBaseUrl}${apiPath}`
|
|
1294
|
-
|
|
1334
|
+
// Snakeize the body so consumers can pass camelCase even though the
|
|
1335
|
+
// API expects snake_case JSON. Opt-out via `snakeizeBody: false` for
|
|
1336
|
+
// Seaport-shaped bodies whose inner keys must remain camelCase on the
|
|
1337
|
+
// wire (the OpenSea OpenAPI spec uses mixed casing for these).
|
|
1338
|
+
const shouldSnakeize = options?.snakeizeBody !== false
|
|
1339
|
+
const wireBody =
|
|
1340
|
+
body == null || !shouldSnakeize ? body : snakeizeKeysDeep(body)
|
|
1341
|
+
const raw = await this._fetch(url, headers, wireBody, options)
|
|
1342
|
+
return camelizeKeysDeep(raw) as Camelize<T>
|
|
1295
1343
|
},
|
|
1296
1344
|
{ logger: this.logger },
|
|
1297
1345
|
)
|
|
@@ -1387,15 +1435,26 @@ export class OpenSeaAPI {
|
|
|
1387
1435
|
if (response.status === 599 || response.status === 429) {
|
|
1388
1436
|
throw await this._createRateLimitError(response)
|
|
1389
1437
|
}
|
|
1390
|
-
const
|
|
1391
|
-
const
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1438
|
+
const rawBody = await response.json().catch(() => ({}))
|
|
1439
|
+
const responseBody = camelizeKeysDeep(rawBody) as {
|
|
1440
|
+
errors?: { length?: number } | unknown[]
|
|
1441
|
+
}
|
|
1442
|
+
const errors = responseBody?.errors as
|
|
1443
|
+
| { length?: number }
|
|
1444
|
+
| unknown[]
|
|
1445
|
+
| undefined
|
|
1446
|
+
if (errors?.length !== undefined && errors.length > 0) {
|
|
1447
|
+
// Handle both string entries (`["not found"]`) and structured ones
|
|
1448
|
+
// (`[{code: "invalid_param", message: "..."}]`) — String() on an
|
|
1449
|
+
// object yields "[object Object]", so JSON-stringify any non-string
|
|
1450
|
+
// element individually before joining.
|
|
1451
|
+
const errorMessage = Array.isArray(errors)
|
|
1452
|
+
? errors
|
|
1453
|
+
.map(e => (typeof e === "string" ? e : JSON.stringify(e)))
|
|
1454
|
+
.join(", ")
|
|
1455
|
+
: typeof errors === "string"
|
|
1456
|
+
? errors
|
|
1457
|
+
: JSON.stringify(errors)
|
|
1399
1458
|
throw new Error(`Server Error: ${errorMessage}`)
|
|
1400
1459
|
}
|
|
1401
1460
|
throw new Error(
|
|
@@ -1421,12 +1480,13 @@ export class OpenSeaAPI {
|
|
|
1421
1480
|
*
|
|
1422
1481
|
* @example
|
|
1423
1482
|
* ```ts
|
|
1424
|
-
* const {
|
|
1425
|
-
* const api = new OpenSeaAPI({ apiKey
|
|
1483
|
+
* const { apiKey } = await OpenSeaAPI.requestInstantApiKey()
|
|
1484
|
+
* const api = new OpenSeaAPI({ apiKey })
|
|
1426
1485
|
* ```
|
|
1427
1486
|
*
|
|
1428
1487
|
* @param apiBaseUrl Optional base URL override (defaults to mainnet).
|
|
1429
|
-
* @returns The {@link RequestInstantApiKeyResponse} containing the new key
|
|
1488
|
+
* @returns The {@link RequestInstantApiKeyResponse} containing the new key,
|
|
1489
|
+
* with response keys camelized to match SDK conventions.
|
|
1430
1490
|
*/
|
|
1431
1491
|
public static async requestInstantApiKey(
|
|
1432
1492
|
apiBaseUrl: string = API_BASE_MAINNET,
|
|
@@ -1444,7 +1504,8 @@ export class OpenSeaAPI {
|
|
|
1444
1504
|
`Server Error (${response.status}): ${response.statusText}`,
|
|
1445
1505
|
)
|
|
1446
1506
|
}
|
|
1447
|
-
|
|
1507
|
+
const raw = await response.json()
|
|
1508
|
+
return camelizeKeysDeep(raw) as RequestInstantApiKeyResponse
|
|
1448
1509
|
}
|
|
1449
1510
|
|
|
1450
1511
|
/**
|
|
@@ -1509,7 +1570,9 @@ export class OpenSeaAPI {
|
|
|
1509
1570
|
// Add status code and retry-after information to the error object
|
|
1510
1571
|
error.statusCode = response.status
|
|
1511
1572
|
error.retryAfter = retryAfter
|
|
1512
|
-
|
|
1573
|
+
const rawBody = await response.json().catch(() => undefined)
|
|
1574
|
+
error.responseBody =
|
|
1575
|
+
rawBody === undefined ? undefined : camelizeKeysDeep(rawBody)
|
|
1513
1576
|
return error
|
|
1514
1577
|
}
|
|
1515
1578
|
}
|
package/src/api/apiPaths.ts
CHANGED
|
@@ -321,6 +321,14 @@ export const getTokenActivityPath = (chain: Chain, address: string) => {
|
|
|
321
321
|
return `${API_V2_PREFIX}/chain/${chain}/token/${address}/activity`
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
export const getTokenHoldersPath = (chain: Chain, address: string) => {
|
|
325
|
+
return `${API_V2_PREFIX}/chain/${chain}/token/${address}/holders`
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export const getTokenLiquidityPoolsPath = (chain: Chain, address: string) => {
|
|
329
|
+
return `${API_V2_PREFIX}/chain/${chain}/token/${address}/liquidity-pools`
|
|
330
|
+
}
|
|
331
|
+
|
|
324
332
|
// ── NFT analytics ───────────────────────────────────────────────────
|
|
325
333
|
|
|
326
334
|
export const getNFTOwnersPath = (
|
package/src/api/collections.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Chain, OpenSeaCollection, OpenSeaCollectionStats } from "../types"
|
|
2
|
-
import { collectionFromJSON } from "../utils/converters"
|
|
3
2
|
import {
|
|
4
3
|
getBatchCollectionsPath,
|
|
5
4
|
getCollectionFloorPricesPath,
|
|
@@ -43,8 +42,7 @@ export class CollectionsAPI {
|
|
|
43
42
|
*/
|
|
44
43
|
async getCollection(slug: string): Promise<OpenSeaCollection> {
|
|
45
44
|
const path = getCollectionPath(slug)
|
|
46
|
-
|
|
47
|
-
return collectionFromJSON(response)
|
|
45
|
+
return this.fetcher.get<GetCollectionResponse>(path)
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
/**
|
|
@@ -60,18 +58,14 @@ export class CollectionsAPI {
|
|
|
60
58
|
): Promise<GetCollectionsResponse> {
|
|
61
59
|
const path = getCollectionsPath()
|
|
62
60
|
const args: GetCollectionsArgs = {
|
|
63
|
-
|
|
61
|
+
orderBy,
|
|
64
62
|
chain,
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
creatorUsername,
|
|
64
|
+
includeHidden,
|
|
67
65
|
limit,
|
|
68
66
|
next,
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
response.collections = response.collections.map(collection =>
|
|
72
|
-
collectionFromJSON(collection),
|
|
73
|
-
)
|
|
74
|
-
return response
|
|
68
|
+
return this.fetcher.get<GetCollectionsResponse>(path, args)
|
|
75
69
|
}
|
|
76
70
|
|
|
77
71
|
/**
|
|
@@ -98,17 +92,13 @@ export class CollectionsAPI {
|
|
|
98
92
|
async getTrendingCollections(
|
|
99
93
|
args?: GetTrendingCollectionsArgs,
|
|
100
94
|
): Promise<GetCollectionsPaginatedResponse> {
|
|
101
|
-
|
|
95
|
+
return this.fetcher.get<GetCollectionsPaginatedResponse>(
|
|
102
96
|
getTrendingCollectionsPath(),
|
|
103
97
|
{
|
|
104
98
|
...args,
|
|
105
99
|
chains: args?.chains?.join(","),
|
|
106
100
|
},
|
|
107
101
|
)
|
|
108
|
-
response.collections = response.collections.map(collection =>
|
|
109
|
-
collectionFromJSON(collection),
|
|
110
|
-
)
|
|
111
|
-
return response
|
|
112
102
|
}
|
|
113
103
|
|
|
114
104
|
/**
|
|
@@ -117,17 +107,13 @@ export class CollectionsAPI {
|
|
|
117
107
|
async getTopCollections(
|
|
118
108
|
args?: GetTopCollectionsArgs,
|
|
119
109
|
): Promise<GetCollectionsPaginatedResponse> {
|
|
120
|
-
|
|
110
|
+
return this.fetcher.get<GetCollectionsPaginatedResponse>(
|
|
121
111
|
getTopCollectionsPath(),
|
|
122
112
|
{
|
|
123
113
|
...args,
|
|
124
114
|
chains: args?.chains?.join(","),
|
|
125
115
|
},
|
|
126
116
|
)
|
|
127
|
-
response.collections = response.collections.map(collection =>
|
|
128
|
-
collectionFromJSON(collection),
|
|
129
|
-
)
|
|
130
|
-
return response
|
|
131
117
|
}
|
|
132
118
|
|
|
133
119
|
/**
|
package/src/api/fetcher.ts
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
import type { RequestOptions } from "../types"
|
|
2
|
+
import type { Camelize } from "../utils/case"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for the {@link Fetcher.post} method.
|
|
6
|
+
*
|
|
7
|
+
* Extends {@link RequestOptions} with a `snakeizeBody` opt-out so callers
|
|
8
|
+
* with mixed-casing wire bodies (e.g. Seaport order structs whose inner
|
|
9
|
+
* keys are camelCase on-wire) can disable the automatic camel→snake key
|
|
10
|
+
* rewrite and submit the body verbatim.
|
|
11
|
+
*
|
|
12
|
+
* @category API Models
|
|
13
|
+
*/
|
|
14
|
+
export interface PostOptions extends RequestOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Whether to recursively rewrite the body's keys from camelCase to
|
|
17
|
+
* snake_case before sending. Defaults to `true`.
|
|
18
|
+
*
|
|
19
|
+
* Set to `false` when the body contains Seaport-shaped structs or other
|
|
20
|
+
* mixed-casing payloads where some keys (`parameters.startTime`,
|
|
21
|
+
* `numericTraits`, `offererSignature`, …) must remain camelCase on the
|
|
22
|
+
* wire per the OpenSea OpenAPI spec. The caller is then responsible
|
|
23
|
+
* for emitting the body in exact wire shape.
|
|
24
|
+
*/
|
|
25
|
+
snakeizeBody?: boolean
|
|
26
|
+
}
|
|
2
27
|
|
|
3
28
|
/**
|
|
4
29
|
* Fetcher context interface for making HTTP requests to the OpenSea API.
|
|
5
30
|
* This interface abstracts the HTTP methods used by specialized API clients.
|
|
31
|
+
*
|
|
32
|
+
* Responses are camelized at this boundary — pass the API's snake_case shape
|
|
33
|
+
* (e.g. an api-types response type) as `T` and the return is the camelCase
|
|
34
|
+
* view. See `utils/case.ts`.
|
|
6
35
|
*/
|
|
7
36
|
export interface Fetcher {
|
|
8
37
|
/**
|
|
@@ -10,22 +39,28 @@ export interface Fetcher {
|
|
|
10
39
|
* @param apiPath Path to URL endpoint under API
|
|
11
40
|
* @param query URL query params. Will be used to create a URLSearchParams object.
|
|
12
41
|
* @param options Request options like timeout and abort signal.
|
|
13
|
-
* @returns The
|
|
42
|
+
* @returns The camelCase view of the API response.
|
|
14
43
|
*/
|
|
15
|
-
get<T>(
|
|
44
|
+
get<T>(
|
|
45
|
+
apiPath: string,
|
|
46
|
+
query?: object,
|
|
47
|
+
options?: RequestOptions,
|
|
48
|
+
): Promise<Camelize<T>>
|
|
16
49
|
|
|
17
50
|
/**
|
|
18
51
|
* Generic post method for POST requests with automatic rate limit retry
|
|
19
52
|
* @param apiPath Path to URL endpoint under API
|
|
20
53
|
* @param body Data to send.
|
|
21
54
|
* @param headers Additional headers to send with the request.
|
|
22
|
-
* @param options Request options
|
|
23
|
-
*
|
|
55
|
+
* @param options Request options. Includes the {@link PostOptions.snakeizeBody}
|
|
56
|
+
* opt-out for callers that need to emit the body in exact wire
|
|
57
|
+
* shape (e.g. Seaport-shaped POSTs).
|
|
58
|
+
* @returns The camelCase view of the API response.
|
|
24
59
|
*/
|
|
25
60
|
post<T>(
|
|
26
61
|
apiPath: string,
|
|
27
62
|
body?: object,
|
|
28
63
|
headers?: object,
|
|
29
|
-
options?:
|
|
30
|
-
): Promise<T
|
|
64
|
+
options?: PostOptions,
|
|
65
|
+
): Promise<Camelize<T>>
|
|
31
66
|
}
|
package/src/api/listings.ts
CHANGED
|
@@ -45,7 +45,7 @@ export class ListingsAPI {
|
|
|
45
45
|
limit,
|
|
46
46
|
next,
|
|
47
47
|
...(includePrivateListings !== undefined && {
|
|
48
|
-
|
|
48
|
+
includePrivateListings,
|
|
49
49
|
}),
|
|
50
50
|
},
|
|
51
51
|
)
|
|
@@ -66,7 +66,7 @@ export class ListingsAPI {
|
|
|
66
66
|
const response = await this.fetcher.get<GetBestListingResponse>(
|
|
67
67
|
getBestListingAPIPath(collectionSlug, tokenId),
|
|
68
68
|
includePrivateListings !== undefined
|
|
69
|
-
? {
|
|
69
|
+
? { includePrivateListings }
|
|
70
70
|
: undefined,
|
|
71
71
|
)
|
|
72
72
|
return response
|
|
@@ -89,7 +89,7 @@ export class ListingsAPI {
|
|
|
89
89
|
limit,
|
|
90
90
|
next,
|
|
91
91
|
...(includePrivateListings !== undefined && {
|
|
92
|
-
|
|
92
|
+
includePrivateListings,
|
|
93
93
|
}),
|
|
94
94
|
traits: encodeTraitsParam(traits),
|
|
95
95
|
},
|
package/src/api/nfts.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Chain, OpenSeaCollection } from "../types"
|
|
2
|
-
import { collectionFromJSON } from "../utils/converters"
|
|
3
2
|
import {
|
|
4
3
|
getBatchNFTsPath,
|
|
5
4
|
getContractPath,
|
|
@@ -117,13 +116,11 @@ export class NFTsAPI {
|
|
|
117
116
|
address: string,
|
|
118
117
|
identifier: string,
|
|
119
118
|
chain: Chain = this.chain,
|
|
120
|
-
): Promise<
|
|
121
|
-
|
|
119
|
+
): Promise<Record<string, unknown>> {
|
|
120
|
+
return this.fetcher.post<Record<string, unknown>>(
|
|
122
121
|
getRefreshMetadataPath(chain, address, identifier),
|
|
123
122
|
{},
|
|
124
123
|
)
|
|
125
|
-
|
|
126
|
-
return response
|
|
127
124
|
}
|
|
128
125
|
|
|
129
126
|
/**
|
|
@@ -166,10 +163,9 @@ export class NFTsAPI {
|
|
|
166
163
|
identifier: string,
|
|
167
164
|
chain: Chain = this.chain,
|
|
168
165
|
): Promise<OpenSeaCollection> {
|
|
169
|
-
|
|
166
|
+
return this.fetcher.get<GetCollectionResponse>(
|
|
170
167
|
getNFTCollectionPath(chain, address, identifier),
|
|
171
168
|
)
|
|
172
|
-
return collectionFromJSON(response)
|
|
173
169
|
}
|
|
174
170
|
|
|
175
171
|
/**
|
package/src/api/offers.ts
CHANGED
|
@@ -114,18 +114,10 @@ export class OffersAPI {
|
|
|
114
114
|
floatValue?: number,
|
|
115
115
|
intValue?: number,
|
|
116
116
|
): Promise<GetOffersResponse> {
|
|
117
|
-
|
|
117
|
+
return this.fetcher.get<GetOffersResponse>(
|
|
118
118
|
getTraitOffersPath(collectionSlug),
|
|
119
|
-
{
|
|
120
|
-
type,
|
|
121
|
-
value,
|
|
122
|
-
limit,
|
|
123
|
-
next,
|
|
124
|
-
float_value: floatValue,
|
|
125
|
-
int_value: intValue,
|
|
126
|
-
},
|
|
119
|
+
{ type, value, limit, next, floatValue, intValue },
|
|
127
120
|
)
|
|
128
|
-
return response
|
|
129
121
|
}
|
|
130
122
|
|
|
131
123
|
/**
|
|
@@ -143,6 +135,12 @@ export class OffersAPI {
|
|
|
143
135
|
|
|
144
136
|
/**
|
|
145
137
|
* Build a OpenSea collection offer.
|
|
138
|
+
*
|
|
139
|
+
* The body uses mixed casing per the OpenSea OpenAPI spec: the outer
|
|
140
|
+
* envelope (`protocol_address`, `offer_protection_enabled`) is snake_case,
|
|
141
|
+
* but `criteria.numericTraits` keeps its camelCase key on the wire per
|
|
142
|
+
* the {@link CriteriaObject} schema. Opt out of automatic snakeize and
|
|
143
|
+
* emit the body in exact wire shape.
|
|
146
144
|
*/
|
|
147
145
|
async buildOffer(
|
|
148
146
|
offererAddress: string,
|
|
@@ -169,6 +167,8 @@ export class OffersAPI {
|
|
|
169
167
|
const response = await this.fetcher.post<BuildOfferResponse>(
|
|
170
168
|
getBuildOfferPath(),
|
|
171
169
|
payload,
|
|
170
|
+
undefined,
|
|
171
|
+
{ snakeizeBody: false },
|
|
172
172
|
)
|
|
173
173
|
return response
|
|
174
174
|
}
|
|
@@ -192,6 +192,11 @@ export class OffersAPI {
|
|
|
192
192
|
|
|
193
193
|
/**
|
|
194
194
|
* Post a collection offer to OpenSea.
|
|
195
|
+
*
|
|
196
|
+
* Mixed-casing body: outer `protocol_address`, `protocol_data` are
|
|
197
|
+
* snake_case, but `protocol_data.parameters` (Seaport struct) and
|
|
198
|
+
* `criteria.numericTraits` keep their camelCase keys on the wire. Opt out
|
|
199
|
+
* of automatic snakeize and emit the body in exact wire shape.
|
|
195
200
|
*/
|
|
196
201
|
async postCollectionOffer(
|
|
197
202
|
order: ProtocolData,
|
|
@@ -214,6 +219,8 @@ export class OffersAPI {
|
|
|
214
219
|
return await this.fetcher.post<CollectionOffer>(
|
|
215
220
|
getPostCollectionOfferPath(),
|
|
216
221
|
payload,
|
|
222
|
+
undefined,
|
|
223
|
+
{ snakeizeBody: false },
|
|
217
224
|
)
|
|
218
225
|
}
|
|
219
226
|
|
package/src/api/orders.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getFulfillOfferPayload,
|
|
6
6
|
} from "../orders/utils"
|
|
7
7
|
import { type Chain, OrderSide } from "../types"
|
|
8
|
+
import type { Camelize } from "../utils/case"
|
|
8
9
|
import {
|
|
9
10
|
getCancelOrderPath,
|
|
10
11
|
getOrderByHashPath,
|
|
@@ -56,7 +57,7 @@ export class OrdersAPI {
|
|
|
56
57
|
unitsToFill?: string,
|
|
57
58
|
recipientAddress?: string,
|
|
58
59
|
includeOptionalCreatorFees: boolean = false,
|
|
59
|
-
): Promise<FulfillmentDataResponse
|
|
60
|
+
): Promise<Camelize<FulfillmentDataResponse>> {
|
|
60
61
|
const payload =
|
|
61
62
|
side === OrderSide.LISTING
|
|
62
63
|
? getFulfillListingPayload(
|
|
@@ -88,6 +89,12 @@ export class OrdersAPI {
|
|
|
88
89
|
|
|
89
90
|
/**
|
|
90
91
|
* Post a listing to OpenSea.
|
|
92
|
+
*
|
|
93
|
+
* The body uses mixed casing per the OpenSea OpenAPI spec: the outer
|
|
94
|
+
* envelope (`protocol_address`) is snake_case, but the inner Seaport
|
|
95
|
+
* struct (`parameters.startTime`, `parameters.orderType`, `offer[].itemType`,
|
|
96
|
+
* etc.) mirrors the on-chain struct names and must stay camelCase on the
|
|
97
|
+
* wire. We pass `snakeizeBody: false` and emit the body in exact wire shape.
|
|
91
98
|
*/
|
|
92
99
|
async postListing(
|
|
93
100
|
order: ProtocolData,
|
|
@@ -106,11 +113,18 @@ export class OrdersAPI {
|
|
|
106
113
|
...order,
|
|
107
114
|
protocol_address: protocolAddress,
|
|
108
115
|
},
|
|
116
|
+
undefined,
|
|
117
|
+
{ snakeizeBody: false },
|
|
109
118
|
)
|
|
110
119
|
}
|
|
111
120
|
|
|
112
121
|
/**
|
|
113
122
|
* Post an offer to OpenSea.
|
|
123
|
+
*
|
|
124
|
+
* Same mixed-casing wire shape as {@link postListing}: outer
|
|
125
|
+
* `protocol_address` is snake_case but the inner Seaport struct stays
|
|
126
|
+
* camelCase. We opt out of automatic snakeize so `parameters` is sent
|
|
127
|
+
* verbatim.
|
|
114
128
|
*/
|
|
115
129
|
async postOffer(
|
|
116
130
|
order: ProtocolData,
|
|
@@ -123,14 +137,22 @@ export class OrdersAPI {
|
|
|
123
137
|
throw new Error("Invalid protocol address format")
|
|
124
138
|
}
|
|
125
139
|
|
|
126
|
-
return this.fetcher.post<Offer>(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
140
|
+
return this.fetcher.post<Offer>(
|
|
141
|
+
getPostOfferPath(this.chain, "seaport"),
|
|
142
|
+
{
|
|
143
|
+
...order,
|
|
144
|
+
protocol_address: protocolAddress,
|
|
145
|
+
},
|
|
146
|
+
undefined,
|
|
147
|
+
{ snakeizeBody: false },
|
|
148
|
+
)
|
|
130
149
|
}
|
|
131
150
|
|
|
132
151
|
/**
|
|
133
152
|
* Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
|
|
153
|
+
*
|
|
154
|
+
* The OpenSea OpenAPI `CancelRequest` schema uses camelCase
|
|
155
|
+
* `offererSignature`, so we opt out of automatic snakeize.
|
|
134
156
|
*/
|
|
135
157
|
async offchainCancelOrder(
|
|
136
158
|
protocolAddress: string,
|
|
@@ -141,6 +163,8 @@ export class OrdersAPI {
|
|
|
141
163
|
return this.fetcher.post<CancelOrderResponse>(
|
|
142
164
|
getCancelOrderPath(chain, protocolAddress, orderHash),
|
|
143
165
|
{ offererSignature },
|
|
166
|
+
undefined,
|
|
167
|
+
{ snakeizeBody: false },
|
|
144
168
|
)
|
|
145
169
|
}
|
|
146
170
|
}
|
package/src/api/tokens.ts
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
getTokenActivityPath,
|
|
7
7
|
getTokenGroupPath,
|
|
8
8
|
getTokenGroupsPath,
|
|
9
|
+
getTokenHoldersPath,
|
|
10
|
+
getTokenLiquidityPoolsPath,
|
|
9
11
|
getTokenOhlcvPath,
|
|
10
12
|
getTokenPath,
|
|
11
13
|
getTokenPriceHistoryPath,
|
|
@@ -30,6 +32,10 @@ import type {
|
|
|
30
32
|
SwapExecuteResponse,
|
|
31
33
|
TokenActivityArgs,
|
|
32
34
|
TokenBatchResponse,
|
|
35
|
+
TokenHoldersArgs,
|
|
36
|
+
TokenHoldersResponse,
|
|
37
|
+
TokenLiquidityPoolsArgs,
|
|
38
|
+
TokenLiquidityPoolsResponse,
|
|
33
39
|
TokenSwapActivityPaginatedResponse,
|
|
34
40
|
TokenTimeSeriesArgs,
|
|
35
41
|
} from "./types"
|
|
@@ -135,12 +141,12 @@ export class TokensAPI {
|
|
|
135
141
|
|
|
136
142
|
/**
|
|
137
143
|
* Fetch OHLCV (open / high / low / close / volume) candles for a token.
|
|
138
|
-
* `
|
|
144
|
+
* `startTime` and `bucketSize` are required.
|
|
139
145
|
*/
|
|
140
146
|
async getTokenOhlcv(
|
|
141
147
|
chain: Chain,
|
|
142
148
|
address: string,
|
|
143
|
-
args: TokenTimeSeriesArgs & {
|
|
149
|
+
args: TokenTimeSeriesArgs & { bucketSize: string },
|
|
144
150
|
): Promise<OhlcvResponse> {
|
|
145
151
|
return this.fetcher.get<OhlcvResponse>(
|
|
146
152
|
getTokenOhlcvPath(chain, address),
|
|
@@ -161,4 +167,35 @@ export class TokensAPI {
|
|
|
161
167
|
args,
|
|
162
168
|
)
|
|
163
169
|
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Fetch paginated holders for a token, including quantity held, USD value,
|
|
173
|
+
* and an aggregate distribution health label (STRONG | HEALTHY |
|
|
174
|
+
* CONCERNING | BAD).
|
|
175
|
+
*/
|
|
176
|
+
async getTokenHolders(
|
|
177
|
+
chain: Chain,
|
|
178
|
+
address: string,
|
|
179
|
+
args?: TokenHoldersArgs,
|
|
180
|
+
): Promise<TokenHoldersResponse> {
|
|
181
|
+
return this.fetcher.get<TokenHoldersResponse>(
|
|
182
|
+
getTokenHoldersPath(chain, address),
|
|
183
|
+
args,
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Fetch liquidity pools for a token (pool type, reserves in USD, and
|
|
189
|
+
* bonding-curve progress / graduation flag where applicable).
|
|
190
|
+
*/
|
|
191
|
+
async getTokenLiquidityPools(
|
|
192
|
+
chain: Chain,
|
|
193
|
+
address: string,
|
|
194
|
+
args?: TokenLiquidityPoolsArgs,
|
|
195
|
+
): Promise<TokenLiquidityPoolsResponse> {
|
|
196
|
+
return this.fetcher.get<TokenLiquidityPoolsResponse>(
|
|
197
|
+
getTokenLiquidityPoolsPath(chain, address),
|
|
198
|
+
args,
|
|
199
|
+
)
|
|
200
|
+
}
|
|
164
201
|
}
|