@fepvenancio/stela-sdk 0.9.0 → 0.11.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 +184 -31
- package/dist/index.cjs +432 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +404 -1
- package/dist/index.d.ts +404 -1
- package/dist/index.js +404 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -211,10 +211,19 @@ import {
|
|
|
211
211
|
| `getInscriptionOrderTypedData(params)` | Build SNIP-12 typed data for a borrower's InscriptionOrder |
|
|
212
212
|
| `getLendOfferTypedData(params)` | Build SNIP-12 typed data for a lender's LendOffer |
|
|
213
213
|
| `getBatchLendOfferTypedData(params)` | Build SNIP-12 typed data for a lender's BatchLendOffer (multi-order settlement) |
|
|
214
|
+
| `getCollectionLendOfferTypedData(params)` | Build SNIP-12 typed data for a collection-wide lending offer |
|
|
215
|
+
| `getCollectionBorrowAcceptanceTypedData(params)` | Build SNIP-12 typed data for accepting a collection offer |
|
|
216
|
+
| `getRenegotiationProposalTypedData(params)` | Build SNIP-12 typed data for a renegotiation proposal |
|
|
217
|
+
| `getCollateralSaleOfferTypedData(params)` | Build SNIP-12 typed data for a collateral sale offer |
|
|
218
|
+
| `getRefinanceOfferTypedData(params)` | Build SNIP-12 typed data for a refinance offer |
|
|
219
|
+
| `getRefinanceApprovalTypedData(params)` | Build SNIP-12 typed data for approving a refinance |
|
|
220
|
+
| `getTermsAcknowledgmentTypedData(params)` | Build SNIP-12 typed data for terms acknowledgment |
|
|
221
|
+
| `getCancelOrderTypedData(orderId, chainId)` | Build SNIP-12 typed data for off-chain order cancellation |
|
|
214
222
|
| `hashAssets(assets)` | Poseidon hash of an asset array (matches Cairo's `hash_assets()`) |
|
|
215
223
|
| `hashBatchEntries(entries)` | Poseidon hash of BatchEntry array for batch_settle() |
|
|
216
224
|
| `serializeSignature(sig)` | Convert `string[]` signature to `{ r, s }` for storage |
|
|
217
225
|
| `deserializeSignature(stored)` | Convert `{ r, s }` back to `string[]` |
|
|
226
|
+
| `getNonce(provider, stelaAddress, accountAddress)` | Read on-chain nonce via RPC (uses `latest` block) |
|
|
218
227
|
|
|
219
228
|
---
|
|
220
229
|
|
|
@@ -228,6 +237,11 @@ import {
|
|
|
228
237
|
scaleByPercentage,
|
|
229
238
|
sharesToPercentage,
|
|
230
239
|
calculateFeeShares,
|
|
240
|
+
divCeil,
|
|
241
|
+
proRataInterest,
|
|
242
|
+
computeInterestRate,
|
|
243
|
+
computePositionValue,
|
|
244
|
+
computeSafePositionFloor,
|
|
231
245
|
} from '@fepvenancio/stela-sdk'
|
|
232
246
|
```
|
|
233
247
|
|
|
@@ -237,6 +251,14 @@ import {
|
|
|
237
251
|
| `scaleByPercentage(value, percentage)` | Scale a value by basis points |
|
|
238
252
|
| `sharesToPercentage(shares, totalSupply, currentIssuedPercentage)` | Convert shares back to percentage |
|
|
239
253
|
| `calculateFeeShares(shares, feeBps)` | Calculate fee portion of shares |
|
|
254
|
+
| `divCeil(a, b)` | Ceiling division (rounds up) |
|
|
255
|
+
| `proRataInterest(amount, elapsed, duration)` | Pro-rata interest with ceiling rounding |
|
|
256
|
+
| `computeInterestRate(debtAssets, interestAssets)` | Interest/debt ratio (skips ERC721, returns `null` if zero debt) |
|
|
257
|
+
| `shareProportionBps(shares, totalSupply)` | Share proportion in basis points |
|
|
258
|
+
| `proportionalAssetValue(assetValue, shares, totalSupply)` | Asset value proportional to shares |
|
|
259
|
+
| `computePositionValue(params)` | Full position valuation (debt, interest, collateral) |
|
|
260
|
+
| `accruedInterestWithBuffer(amount, elapsed, duration, buffer?)` | Accrued interest + dust buffer |
|
|
261
|
+
| `computeSafePositionFloor(params)` | Safe minimum price for buying shares |
|
|
240
262
|
|
|
241
263
|
---
|
|
242
264
|
|
|
@@ -281,11 +303,16 @@ import {
|
|
|
281
303
|
toU256, fromU256, inscriptionIdToHex, toHex,
|
|
282
304
|
formatAddress, normalizeAddress, addressesEqual,
|
|
283
305
|
parseAmount, formatTokenValue,
|
|
284
|
-
formatDuration, formatTimestamp,
|
|
285
|
-
computeStatus,
|
|
306
|
+
formatDuration, formatTimestamp, formatDurationHuman,
|
|
307
|
+
computeStatus, enrichStatus,
|
|
308
|
+
normalizeOrderData, parseOrderRow,
|
|
309
|
+
formatSig, parseSigToArray,
|
|
310
|
+
serializeAssetCalldata, parseAssetArray, parseInscriptionCalldata,
|
|
286
311
|
} from '@fepvenancio/stela-sdk'
|
|
287
312
|
```
|
|
288
313
|
|
|
314
|
+
#### Address & Formatting
|
|
315
|
+
|
|
289
316
|
| Function | Description |
|
|
290
317
|
|----------|-------------|
|
|
291
318
|
| `toU256(value)` | Convert bigint to `[low, high]` string pair for Cairo u256 |
|
|
@@ -293,13 +320,49 @@ import {
|
|
|
293
320
|
| `inscriptionIdToHex(id)` | Format inscription ID as hex string |
|
|
294
321
|
| `toHex(value)` | Convert bigint/number to hex string |
|
|
295
322
|
| `formatAddress(address)` | Shorten an address for display (`0x1234...abcd`) |
|
|
296
|
-
| `normalizeAddress(address)` |
|
|
323
|
+
| `normalizeAddress(address)` | Pad and checksum an address |
|
|
297
324
|
| `addressesEqual(a, b)` | Case-insensitive address comparison |
|
|
298
325
|
| `parseAmount(value, decimals)` | Parse human-readable amount to bigint |
|
|
299
326
|
| `formatTokenValue(value, decimals)` | Format bigint token value for display |
|
|
300
|
-
| `formatDuration(seconds)` | Format seconds as
|
|
327
|
+
| `formatDuration(seconds)` | Format seconds as compact duration (`7d 0h`) |
|
|
301
328
|
| `formatTimestamp(timestamp)` | Format unix timestamp as date string |
|
|
329
|
+
| `formatDurationHuman(seconds)` | Format seconds as human-readable (`5 min`, `2 hours`, `7 days`) |
|
|
330
|
+
|
|
331
|
+
#### Status Computation
|
|
332
|
+
|
|
333
|
+
| Function | Description |
|
|
334
|
+
|----------|-------------|
|
|
302
335
|
| `computeStatus(input)` | Derive inscription status from on-chain fields |
|
|
336
|
+
| `enrichStatus(row)` | Compute display status — distinguishes `overdue`, `grace_period`, `auctioned` from base `expired` |
|
|
337
|
+
| `getStatusBadgeVariant(status)` | Map any status to a `StatusBadgeVariant` for UI |
|
|
338
|
+
| `getStatusLabel(status)` | Human-readable label for any status (base + extended) |
|
|
339
|
+
| `getOrderStatusBadgeVariant(status)` | Badge variant for off-chain order status |
|
|
340
|
+
| `getOrderStatusLabel(status)` | Human-readable label for order status |
|
|
341
|
+
| `inscriptionMatchesGroup(status, group)` | Check if inscription status belongs to filter group (`open`/`active`/`closed`/`all`) |
|
|
342
|
+
| `orderMatchesGroup(status, group)` | Check if order status belongs to filter group |
|
|
343
|
+
|
|
344
|
+
#### Order Data Parsing
|
|
345
|
+
|
|
346
|
+
| Function | Description |
|
|
347
|
+
|----------|-------------|
|
|
348
|
+
| `normalizeOrderData(raw)` | Normalize camelCase/snake_case variants in order_data JSON |
|
|
349
|
+
| `parseOrderRow(row)` | Parse D1 order row — sanitizes assets, strips signature for non-pending orders |
|
|
350
|
+
|
|
351
|
+
#### Signature Utilities
|
|
352
|
+
|
|
353
|
+
| Function | Description |
|
|
354
|
+
|----------|-------------|
|
|
355
|
+
| `formatSig(signature)` | Format wallet signature (array or `{r, s}`) to `string[]` — converts bigints to hex |
|
|
356
|
+
| `parseSigToArray(raw)` | Parse stored signature (JSON array, JSON object, CSV, or string array) to `string[]` |
|
|
357
|
+
|
|
358
|
+
#### Calldata Serialization
|
|
359
|
+
|
|
360
|
+
| Function | Description |
|
|
361
|
+
|----------|-------------|
|
|
362
|
+
| `serializeAssetCalldata(assets)` | Serialize asset array to Cairo calldata `[len, ...fields]` |
|
|
363
|
+
| `parseAssetArray(calldata, offset)` | Deserialize asset array from RPC calldata |
|
|
364
|
+
| `parseInscriptionCalldata(calldata)` | Extract `{debt, interest, collateral}` from `create_inscription`/`settle` tx calldata |
|
|
365
|
+
| `serializeSignatureCalldata(sig)` | Serialize signature string to calldata `[len, ...parts]` |
|
|
303
366
|
|
|
304
367
|
---
|
|
305
368
|
|
|
@@ -307,6 +370,8 @@ import {
|
|
|
307
370
|
|
|
308
371
|
All exported types from the SDK:
|
|
309
372
|
|
|
373
|
+
#### Core Protocol Types
|
|
374
|
+
|
|
310
375
|
| Type | Description |
|
|
311
376
|
|------|-------------|
|
|
312
377
|
| `Network` | `'sepolia' \| 'mainnet'` |
|
|
@@ -319,54 +384,142 @@ All exported types from the SDK:
|
|
|
319
384
|
| `Inscription` | Parsed inscription with computed status |
|
|
320
385
|
| `SignedOrder` | Signed order for the matching engine |
|
|
321
386
|
| `BatchEntry` | Entry in a batch settle (order hash + fill BPS) |
|
|
322
|
-
| `
|
|
323
|
-
| `
|
|
387
|
+
| `TokenInfo` | Token metadata (symbol, name, decimals, addresses) |
|
|
388
|
+
| `StoredSignature` | Serialized signature for storage (`r:s`) |
|
|
389
|
+
|
|
390
|
+
#### API / D1 Row Types
|
|
391
|
+
|
|
392
|
+
| Type | Description |
|
|
393
|
+
|------|-------------|
|
|
394
|
+
| `InscriptionRow` | Inscription row (includes `auction_started`, `auction_start_time`) |
|
|
395
|
+
| `InscriptionDetailResponse` | Detail response extending InscriptionRow |
|
|
396
|
+
| `AssetRow` | Asset row (`debt` / `interest` / `collateral`) |
|
|
324
397
|
| `ApiListResponse<T>` | Paginated list response envelope |
|
|
325
398
|
| `ApiDetailResponse<T>` | Single item response envelope |
|
|
326
399
|
| `TreasuryAsset` | Treasury asset balance |
|
|
327
400
|
| `ShareBalance` | Share balance for an account |
|
|
328
|
-
| `LockerInfo` | Locker information
|
|
329
|
-
| `
|
|
330
|
-
| `
|
|
401
|
+
| `LockerInfo` | Locker information |
|
|
402
|
+
| `OrderStatus` | `'pending' \| 'matched' \| 'settled' \| 'expired' \| 'cancelled'` |
|
|
403
|
+
| `OrderRow` | Off-chain order row from D1 |
|
|
404
|
+
| `OrderOfferRow` | Lender offer row from D1 |
|
|
405
|
+
| `CollectionOfferRow` | Collection-wide offer row from D1 |
|
|
406
|
+
| `RefinanceRow` | Refinance offer row from D1 |
|
|
407
|
+
| `RenegotiationRow` | Renegotiation proposal row from D1 |
|
|
408
|
+
| `CollateralSaleRow` | Collateral sale offer row from D1 |
|
|
409
|
+
| `ShareListingRow` | Secondary market share listing row |
|
|
410
|
+
|
|
411
|
+
#### Order Book Types
|
|
412
|
+
|
|
413
|
+
| Type | Description |
|
|
414
|
+
|------|-------------|
|
|
415
|
+
| `LendingLevel` | Price level in lending order book (APR, amount, orders) |
|
|
416
|
+
| `SwapLevel` | Price level in swap order book (rate, amount, orders) |
|
|
417
|
+
| `TokenDisplay` | Token display info (address, symbol, decimals, logoUrl) |
|
|
418
|
+
| `OrderBookResponse` | Full order book response (pair, lending, swaps, recentFills) |
|
|
419
|
+
| `DurationFilter` | `'all' \| '7d' \| '30d' \| '90d' \| '180d' \| '365d'` |
|
|
420
|
+
|
|
421
|
+
#### Status & UI Types
|
|
422
|
+
|
|
423
|
+
| Type | Description |
|
|
424
|
+
|------|-------------|
|
|
425
|
+
| `EnrichedStatus` | `InscriptionStatus \| 'overdue' \| 'grace_period' \| 'auctioned'` |
|
|
426
|
+
| `StatusBadgeVariant` | Union of all inscription + order status strings for badge rendering |
|
|
427
|
+
| `StatusInput` | Input for `computeStatus()` |
|
|
428
|
+
|
|
429
|
+
#### Order Parsing Types
|
|
430
|
+
|
|
431
|
+
| Type | Description |
|
|
432
|
+
|------|-------------|
|
|
433
|
+
| `SerializedAsset` | Asset in order_data JSON (string values) |
|
|
434
|
+
| `RawOrderData` | Flexible order_data with camelCase/snake_case variants |
|
|
435
|
+
| `ParsedOrderData` | Normalized order data output |
|
|
436
|
+
| `StoredAsset` | Asset shape for calldata serialization |
|
|
437
|
+
|
|
438
|
+
#### Preset Types
|
|
439
|
+
|
|
440
|
+
| Type | Description |
|
|
441
|
+
|------|-------------|
|
|
442
|
+
| `DeadlinePreset` | `{ label: string, seconds: number }` |
|
|
443
|
+
| `DurationPreset` | `{ label: string, seconds: number }` |
|
|
444
|
+
|
|
445
|
+
#### Event Types
|
|
446
|
+
|
|
447
|
+
| Type | Description |
|
|
448
|
+
|------|-------------|
|
|
331
449
|
| `RawEvent` | Raw StarkNet event (keys, data, tx_hash, block) |
|
|
332
450
|
| `StelaEvent` | Discriminated union of all protocol events |
|
|
333
|
-
| `InscriptionCreatedEvent` | InscriptionCreated event
|
|
334
|
-
| `InscriptionSignedEvent` | InscriptionSigned event
|
|
335
|
-
| `InscriptionCancelledEvent` | InscriptionCancelled event
|
|
336
|
-
| `InscriptionRepaidEvent` | InscriptionRepaid event
|
|
337
|
-
| `InscriptionLiquidatedEvent` | InscriptionLiquidated event
|
|
338
|
-
| `SharesRedeemedEvent` | SharesRedeemed event
|
|
339
|
-
| `TransferSingleEvent` | ERC1155 TransferSingle event
|
|
340
|
-
| `OrderSettledEvent` | OrderSettled event
|
|
341
|
-
| `OrderFilledEvent` | OrderFilled event
|
|
342
|
-
| `OrderCancelledEvent` | OrderCancelled event
|
|
343
|
-
| `OrdersBulkCancelledEvent` | OrdersBulkCancelled event
|
|
344
|
-
| `
|
|
345
|
-
| `
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
|
451
|
+
| `InscriptionCreatedEvent` | InscriptionCreated event |
|
|
452
|
+
| `InscriptionSignedEvent` | InscriptionSigned event |
|
|
453
|
+
| `InscriptionCancelledEvent` | InscriptionCancelled event |
|
|
454
|
+
| `InscriptionRepaidEvent` | InscriptionRepaid event |
|
|
455
|
+
| `InscriptionLiquidatedEvent` | InscriptionLiquidated event |
|
|
456
|
+
| `SharesRedeemedEvent` | SharesRedeemed event |
|
|
457
|
+
| `TransferSingleEvent` | ERC1155 TransferSingle event |
|
|
458
|
+
| `OrderSettledEvent` | OrderSettled event |
|
|
459
|
+
| `OrderFilledEvent` | OrderFilled event |
|
|
460
|
+
| `OrderCancelledEvent` | OrderCancelled event |
|
|
461
|
+
| `OrdersBulkCancelledEvent` | OrdersBulkCancelled event |
|
|
462
|
+
| `AuctionStartedEvent` | AuctionStarted event |
|
|
463
|
+
| `AuctionBidEvent` | AuctionBid event |
|
|
464
|
+
|
|
465
|
+
#### Client Types
|
|
466
|
+
|
|
467
|
+
| Type | Description |
|
|
468
|
+
|------|-------------|
|
|
469
|
+
| `LockerState` | Locker address + unlock status |
|
|
470
|
+
| `LockerCall` | Call to execute through a locker |
|
|
471
|
+
| `InscriptionClientOptions` | Options for InscriptionClient |
|
|
472
|
+
| `ShareClientOptions` | Options for ShareClient |
|
|
473
|
+
| `ApiClientOptions` | Options for ApiClient |
|
|
350
474
|
| `ListInscriptionsParams` | Parameters for `listInscriptions()` |
|
|
351
|
-
| `InscriptionEventRow` | API response row for
|
|
352
|
-
| `StelaSdkOptions` | Options for StelaSdk
|
|
475
|
+
| `InscriptionEventRow` | API response row for events |
|
|
476
|
+
| `StelaSdkOptions` | Options for StelaSdk |
|
|
477
|
+
| `AssetValue` | Asset with proportional value |
|
|
478
|
+
| `AccruedInterestEntry` | Interest with full + accrued amounts |
|
|
479
|
+
| `PositionValue` | Full position valuation result |
|
|
353
480
|
|
|
354
481
|
---
|
|
355
482
|
|
|
356
483
|
### Constants
|
|
357
484
|
|
|
485
|
+
#### Protocol
|
|
486
|
+
|
|
358
487
|
| Export | Description |
|
|
359
488
|
|--------|-------------|
|
|
360
489
|
| `STELA_ADDRESS` | Contract addresses per network (`{ sepolia, mainnet }`) |
|
|
361
490
|
| `resolveNetwork(raw?)` | Validate/default network string |
|
|
362
|
-
| `CHAIN_ID` | SNIP-12 chain ID shortstrings per network
|
|
363
|
-
| `EXPLORER_TX_URL` | Block explorer base URLs per network
|
|
491
|
+
| `CHAIN_ID` | SNIP-12 chain ID shortstrings per network |
|
|
492
|
+
| `EXPLORER_TX_URL` | Block explorer base URLs per network |
|
|
364
493
|
| `MAX_BPS` | `10_000n` (100% in basis points) |
|
|
365
494
|
| `VIRTUAL_SHARE_OFFSET` | `1e16n` (share calculation offset) |
|
|
366
495
|
| `ASSET_TYPE_ENUM` | AssetType to numeric enum mapping |
|
|
367
496
|
| `ASSET_TYPE_NAMES` | Numeric enum to AssetType mapping |
|
|
497
|
+
| `GRACE_PERIOD` | `86400n` — 24h grace before auction |
|
|
498
|
+
| `AUCTION_DURATION` | `86400n` — 24h Dutch auction |
|
|
499
|
+
| `AUCTION_PENALTY_BPS` | `500n` — 5% penalty at auction start |
|
|
500
|
+
| `AUCTION_RESERVE_BPS` | `1000n` — 10% auction floor |
|
|
501
|
+
| `DEFAULT_DUST_BUFFER_SECONDS` | `60n` — dust buffer for position floor |
|
|
502
|
+
|
|
503
|
+
#### Status
|
|
504
|
+
|
|
505
|
+
| Export | Description |
|
|
506
|
+
|--------|-------------|
|
|
368
507
|
| `VALID_STATUSES` | Array of all valid inscription statuses |
|
|
369
|
-
| `STATUS_LABELS` | Human-readable status labels |
|
|
508
|
+
| `STATUS_LABELS` | Human-readable inscription status labels |
|
|
509
|
+
| `ORDER_STATUS_LABELS` | Human-readable order status labels |
|
|
510
|
+
| `INSCRIPTION_STATUS_GROUPS` | Status → filter group mapping (`open`/`active`/`closed`) |
|
|
511
|
+
| `ORDER_STATUS_GROUPS` | Order status → filter group mapping |
|
|
512
|
+
| `STATUS_DESCRIPTIONS` | Detailed tooltip text for each status |
|
|
513
|
+
| `CONCEPT_DESCRIPTIONS` | Help text for protocol concepts (debt, interest, collateral, etc.) |
|
|
514
|
+
|
|
515
|
+
#### Trade Presets
|
|
516
|
+
|
|
517
|
+
| Export | Description |
|
|
518
|
+
|--------|-------------|
|
|
519
|
+
| `SWAP_DEADLINE_PRESETS` | `DeadlinePreset[]` — 5m to 30d |
|
|
520
|
+
| `LEND_DEADLINE_PRESETS` | `DeadlinePreset[]` — 7d to 90d |
|
|
521
|
+
| `DURATION_PRESETS` | `DurationPreset[]` — 1d to 1y |
|
|
522
|
+
| `DURATION_RANGES` | `Record<DurationFilter, [min, max] \| null>` — filter to seconds mapping |
|
|
370
523
|
|
|
371
524
|
### Classes
|
|
372
525
|
|