@fepvenancio/stela-sdk 0.5.3 → 0.6.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/dist/index.d.cts CHANGED
@@ -371,6 +371,17 @@ declare function parseEvent(raw: RawEvent): StelaEvent | null;
371
371
  /** Parse an array of raw events, skipping unrecognized ones. */
372
372
  declare function parseEvents(rawEvents: RawEvent[]): StelaEvent[];
373
373
 
374
+ interface BatchEntry {
375
+ orderHash: string;
376
+ bps: bigint;
377
+ }
378
+ /**
379
+ * Hash an array of BatchEntry using Poseidon -- matches Cairo's hash_batch_entries().
380
+ *
381
+ * Format: Poseidon(count, order_hash_1, u256_hash(bps_1), order_hash_2, u256_hash(bps_2), ...)
382
+ * where u256_hash(bps) = Poseidon(U256_TYPE_HASH, low, high)
383
+ */
384
+ declare function hashBatchEntries(entries: BatchEntry[]): string;
374
385
  /**
375
386
  * Hash an array of assets using Poseidon -- matches Cairo's hash_assets().
376
387
  *
@@ -414,6 +425,17 @@ declare function getLendOfferTypedData(params: {
414
425
  nonce: bigint;
415
426
  chainId: string;
416
427
  }): TypedData;
428
+ /**
429
+ * Build SNIP-12 TypedData for a lender's BatchLendOffer.
430
+ * The lender signs this off-chain to accept multiple orders atomically.
431
+ */
432
+ declare function getBatchLendOfferTypedData(params: {
433
+ batchHash: string;
434
+ count: number;
435
+ lender: string;
436
+ startNonce: bigint;
437
+ chainId: string;
438
+ }): TypedData;
417
439
 
418
440
  /**
419
441
  * Serialize a starknet.js signature (Signature type) for storage in D1.
@@ -479,6 +501,33 @@ declare class InscriptionClient {
479
501
  };
480
502
  lenderSig: string[];
481
503
  }): Call;
504
+ buildBatchSettle(params: {
505
+ orders: Array<{
506
+ borrower: string;
507
+ debtHash: string;
508
+ interestHash: string;
509
+ collateralHash: string;
510
+ debtCount: number;
511
+ interestCount: number;
512
+ collateralCount: number;
513
+ duration: bigint;
514
+ deadline: bigint;
515
+ multiLender: boolean;
516
+ nonce: bigint;
517
+ }>;
518
+ debtAssetsFlat: Asset[];
519
+ interestAssetsFlat: Asset[];
520
+ collateralAssetsFlat: Asset[];
521
+ borrowerSigs: string[][];
522
+ batchOffer: {
523
+ batchHash: string;
524
+ count: number;
525
+ lender: string;
526
+ startNonce: bigint;
527
+ };
528
+ lenderSig: string[];
529
+ bpsList: bigint[];
530
+ }): Call;
482
531
  buildFillSignedOrder(order: SignedOrder, signature: string[], fillBps: bigint): Call;
483
532
  buildCancelOrder(order: SignedOrder): Call;
484
533
  buildCancelOrdersByNonce(minNonce: string): Call;
@@ -656,4 +705,4 @@ declare class StelaSdk {
656
705
  constructor(opts: StelaSdkOptions);
657
706
  }
658
707
 
659
- export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, ApiClient, type ApiClientOptions, type ApiDetailResponse, ApiError, type ApiListResponse, type Asset, type AssetRow, type AssetType, CHAIN_ID, type Call, EXPLORER_TX_URL, type Inscription, type InscriptionCancelledEvent, InscriptionClient, type InscriptionClientOptions, type InscriptionCreatedEvent, type InscriptionEventRow, type InscriptionLiquidatedEvent, type InscriptionParams, type InscriptionRepaidEvent, type InscriptionRow, type InscriptionSignedEvent, type InscriptionStatus, type ListInscriptionsParams, type LockerCall, LockerClient, type LockerInfo, type LockerState, MAX_BPS, type Network, type OrderCancelledEvent, type OrderFilledEvent, type OrderSettledEvent, type OrdersBulkCancelledEvent, type RawEvent, SELECTORS, STATUS_LABELS, STELA_ADDRESS, type ShareBalance, ShareClient, type ShareClientOptions, type SharesRedeemedEvent, type SignedOrder, type StatusInput, type StelaEvent, StelaSdk, type StelaSdkOptions, type StoredInscription, type StoredSignature, TOKENS, type TokenInfo, type TransferSingleEvent, type TreasuryAsset, VALID_STATUSES, VIRTUAL_SHARE_OFFSET, addressesEqual, calculateFeeShares, computeStatus, convertToShares, deserializeSignature, findTokenByAddress, formatAddress, formatDuration, formatTimestamp, formatTokenValue, fromU256, getInscriptionOrderTypedData, getLendOfferTypedData, getTokensForNetwork, hashAssets, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
708
+ export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, ApiClient, type ApiClientOptions, type ApiDetailResponse, ApiError, type ApiListResponse, type Asset, type AssetRow, type AssetType, type BatchEntry, CHAIN_ID, type Call, EXPLORER_TX_URL, type Inscription, type InscriptionCancelledEvent, InscriptionClient, type InscriptionClientOptions, type InscriptionCreatedEvent, type InscriptionEventRow, type InscriptionLiquidatedEvent, type InscriptionParams, type InscriptionRepaidEvent, type InscriptionRow, type InscriptionSignedEvent, type InscriptionStatus, type ListInscriptionsParams, type LockerCall, LockerClient, type LockerInfo, type LockerState, MAX_BPS, type Network, type OrderCancelledEvent, type OrderFilledEvent, type OrderSettledEvent, type OrdersBulkCancelledEvent, type RawEvent, SELECTORS, STATUS_LABELS, STELA_ADDRESS, type ShareBalance, ShareClient, type ShareClientOptions, type SharesRedeemedEvent, type SignedOrder, type StatusInput, type StelaEvent, StelaSdk, type StelaSdkOptions, type StoredInscription, type StoredSignature, TOKENS, type TokenInfo, type TransferSingleEvent, type TreasuryAsset, VALID_STATUSES, VIRTUAL_SHARE_OFFSET, addressesEqual, calculateFeeShares, computeStatus, convertToShares, deserializeSignature, findTokenByAddress, formatAddress, formatDuration, formatTimestamp, formatTokenValue, fromU256, getBatchLendOfferTypedData, getInscriptionOrderTypedData, getLendOfferTypedData, getTokensForNetwork, hashAssets, hashBatchEntries, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
package/dist/index.d.ts CHANGED
@@ -371,6 +371,17 @@ declare function parseEvent(raw: RawEvent): StelaEvent | null;
371
371
  /** Parse an array of raw events, skipping unrecognized ones. */
372
372
  declare function parseEvents(rawEvents: RawEvent[]): StelaEvent[];
373
373
 
374
+ interface BatchEntry {
375
+ orderHash: string;
376
+ bps: bigint;
377
+ }
378
+ /**
379
+ * Hash an array of BatchEntry using Poseidon -- matches Cairo's hash_batch_entries().
380
+ *
381
+ * Format: Poseidon(count, order_hash_1, u256_hash(bps_1), order_hash_2, u256_hash(bps_2), ...)
382
+ * where u256_hash(bps) = Poseidon(U256_TYPE_HASH, low, high)
383
+ */
384
+ declare function hashBatchEntries(entries: BatchEntry[]): string;
374
385
  /**
375
386
  * Hash an array of assets using Poseidon -- matches Cairo's hash_assets().
376
387
  *
@@ -414,6 +425,17 @@ declare function getLendOfferTypedData(params: {
414
425
  nonce: bigint;
415
426
  chainId: string;
416
427
  }): TypedData;
428
+ /**
429
+ * Build SNIP-12 TypedData for a lender's BatchLendOffer.
430
+ * The lender signs this off-chain to accept multiple orders atomically.
431
+ */
432
+ declare function getBatchLendOfferTypedData(params: {
433
+ batchHash: string;
434
+ count: number;
435
+ lender: string;
436
+ startNonce: bigint;
437
+ chainId: string;
438
+ }): TypedData;
417
439
 
418
440
  /**
419
441
  * Serialize a starknet.js signature (Signature type) for storage in D1.
@@ -479,6 +501,33 @@ declare class InscriptionClient {
479
501
  };
480
502
  lenderSig: string[];
481
503
  }): Call;
504
+ buildBatchSettle(params: {
505
+ orders: Array<{
506
+ borrower: string;
507
+ debtHash: string;
508
+ interestHash: string;
509
+ collateralHash: string;
510
+ debtCount: number;
511
+ interestCount: number;
512
+ collateralCount: number;
513
+ duration: bigint;
514
+ deadline: bigint;
515
+ multiLender: boolean;
516
+ nonce: bigint;
517
+ }>;
518
+ debtAssetsFlat: Asset[];
519
+ interestAssetsFlat: Asset[];
520
+ collateralAssetsFlat: Asset[];
521
+ borrowerSigs: string[][];
522
+ batchOffer: {
523
+ batchHash: string;
524
+ count: number;
525
+ lender: string;
526
+ startNonce: bigint;
527
+ };
528
+ lenderSig: string[];
529
+ bpsList: bigint[];
530
+ }): Call;
482
531
  buildFillSignedOrder(order: SignedOrder, signature: string[], fillBps: bigint): Call;
483
532
  buildCancelOrder(order: SignedOrder): Call;
484
533
  buildCancelOrdersByNonce(minNonce: string): Call;
@@ -656,4 +705,4 @@ declare class StelaSdk {
656
705
  constructor(opts: StelaSdkOptions);
657
706
  }
658
707
 
659
- export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, ApiClient, type ApiClientOptions, type ApiDetailResponse, ApiError, type ApiListResponse, type Asset, type AssetRow, type AssetType, CHAIN_ID, type Call, EXPLORER_TX_URL, type Inscription, type InscriptionCancelledEvent, InscriptionClient, type InscriptionClientOptions, type InscriptionCreatedEvent, type InscriptionEventRow, type InscriptionLiquidatedEvent, type InscriptionParams, type InscriptionRepaidEvent, type InscriptionRow, type InscriptionSignedEvent, type InscriptionStatus, type ListInscriptionsParams, type LockerCall, LockerClient, type LockerInfo, type LockerState, MAX_BPS, type Network, type OrderCancelledEvent, type OrderFilledEvent, type OrderSettledEvent, type OrdersBulkCancelledEvent, type RawEvent, SELECTORS, STATUS_LABELS, STELA_ADDRESS, type ShareBalance, ShareClient, type ShareClientOptions, type SharesRedeemedEvent, type SignedOrder, type StatusInput, type StelaEvent, StelaSdk, type StelaSdkOptions, type StoredInscription, type StoredSignature, TOKENS, type TokenInfo, type TransferSingleEvent, type TreasuryAsset, VALID_STATUSES, VIRTUAL_SHARE_OFFSET, addressesEqual, calculateFeeShares, computeStatus, convertToShares, deserializeSignature, findTokenByAddress, formatAddress, formatDuration, formatTimestamp, formatTokenValue, fromU256, getInscriptionOrderTypedData, getLendOfferTypedData, getTokensForNetwork, hashAssets, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
708
+ export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, ApiClient, type ApiClientOptions, type ApiDetailResponse, ApiError, type ApiListResponse, type Asset, type AssetRow, type AssetType, type BatchEntry, CHAIN_ID, type Call, EXPLORER_TX_URL, type Inscription, type InscriptionCancelledEvent, InscriptionClient, type InscriptionClientOptions, type InscriptionCreatedEvent, type InscriptionEventRow, type InscriptionLiquidatedEvent, type InscriptionParams, type InscriptionRepaidEvent, type InscriptionRow, type InscriptionSignedEvent, type InscriptionStatus, type ListInscriptionsParams, type LockerCall, LockerClient, type LockerInfo, type LockerState, MAX_BPS, type Network, type OrderCancelledEvent, type OrderFilledEvent, type OrderSettledEvent, type OrdersBulkCancelledEvent, type RawEvent, SELECTORS, STATUS_LABELS, STELA_ADDRESS, type ShareBalance, ShareClient, type ShareClientOptions, type SharesRedeemedEvent, type SignedOrder, type StatusInput, type StelaEvent, StelaSdk, type StelaSdkOptions, type StoredInscription, type StoredSignature, TOKENS, type TokenInfo, type TransferSingleEvent, type TreasuryAsset, VALID_STATUSES, VIRTUAL_SHARE_OFFSET, addressesEqual, calculateFeeShares, computeStatus, convertToShares, deserializeSignature, findTokenByAddress, formatAddress, formatDuration, formatTimestamp, formatTokenValue, fromU256, getBatchLendOfferTypedData, getInscriptionOrderTypedData, getLendOfferTypedData, getTokensForNetwork, hashAssets, hashBatchEntries, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
package/dist/index.js CHANGED
@@ -426,6 +426,17 @@ function parseEvents(rawEvents) {
426
426
  }
427
427
  return results;
428
428
  }
429
+ var U256_TYPE_HASH = "0x3b143be38b811560b45593fb2a071ec4ddd0a020e10782be62ffe6f39e0e82c";
430
+ function hashBatchEntries(entries) {
431
+ const elements = [String(entries.length)];
432
+ for (const entry of entries) {
433
+ elements.push(entry.orderHash);
434
+ const [low, high] = toU256(entry.bps);
435
+ const bpsHash = hash.computePoseidonHashOnElements([U256_TYPE_HASH, low, high]);
436
+ elements.push(bpsHash);
437
+ }
438
+ return hash.computePoseidonHashOnElements(elements);
439
+ }
429
440
  function hashAssets(assets) {
430
441
  const elements = [String(assets.length)];
431
442
  for (const asset of assets) {
@@ -526,6 +537,35 @@ function getLendOfferTypedData(params) {
526
537
  }
527
538
  };
528
539
  }
540
+ function getBatchLendOfferTypedData(params) {
541
+ return {
542
+ types: {
543
+ StarknetDomain: [
544
+ { name: "name", type: "shortstring" },
545
+ { name: "version", type: "shortstring" },
546
+ { name: "chainId", type: "shortstring" },
547
+ { name: "revision", type: "shortstring" }
548
+ ],
549
+ BatchLendOffer: [
550
+ { name: "batch_hash", type: "felt" },
551
+ { name: "count", type: "u128" },
552
+ { name: "lender", type: "ContractAddress" },
553
+ { name: "start_nonce", type: "felt" }
554
+ ]
555
+ },
556
+ primaryType: "BatchLendOffer",
557
+ domain: {
558
+ ...STELA_DOMAIN,
559
+ chainId: params.chainId
560
+ },
561
+ message: {
562
+ batch_hash: params.batchHash,
563
+ count: params.count.toString(),
564
+ lender: params.lender,
565
+ start_nonce: params.startNonce.toString()
566
+ }
567
+ };
568
+ }
529
569
 
530
570
  // src/offchain/signature.ts
531
571
  function serializeSignature(sig) {
@@ -2449,6 +2489,44 @@ var InscriptionClient = class {
2449
2489
  ];
2450
2490
  return { contractAddress: this.address, entrypoint: "settle", calldata };
2451
2491
  }
2492
+ buildBatchSettle(params) {
2493
+ const calldata = [];
2494
+ calldata.push(String(params.orders.length));
2495
+ for (const order of params.orders) {
2496
+ calldata.push(
2497
+ order.borrower,
2498
+ order.debtHash,
2499
+ order.interestHash,
2500
+ order.collateralHash,
2501
+ String(order.debtCount),
2502
+ String(order.interestCount),
2503
+ String(order.collateralCount),
2504
+ order.duration.toString(),
2505
+ order.deadline.toString(),
2506
+ order.multiLender ? "1" : "0",
2507
+ order.nonce.toString()
2508
+ );
2509
+ }
2510
+ calldata.push(...serializeAssets(params.debtAssetsFlat));
2511
+ calldata.push(...serializeAssets(params.interestAssetsFlat));
2512
+ calldata.push(...serializeAssets(params.collateralAssetsFlat));
2513
+ calldata.push(String(params.borrowerSigs.length));
2514
+ for (const sig of params.borrowerSigs) {
2515
+ calldata.push(String(sig.length), ...sig);
2516
+ }
2517
+ calldata.push(
2518
+ params.batchOffer.batchHash,
2519
+ String(params.batchOffer.count),
2520
+ params.batchOffer.lender,
2521
+ params.batchOffer.startNonce.toString()
2522
+ );
2523
+ calldata.push(String(params.lenderSig.length), ...params.lenderSig);
2524
+ calldata.push(String(params.bpsList.length));
2525
+ for (const bps of params.bpsList) {
2526
+ calldata.push(...toU256(bps));
2527
+ }
2528
+ return { contractAddress: this.address, entrypoint: "batch_settle", calldata };
2529
+ }
2452
2530
  buildFillSignedOrder(order, signature, fillBps) {
2453
2531
  const calldata = [
2454
2532
  // SignedOrder struct fields
@@ -2896,6 +2974,6 @@ var StelaSdk = class {
2896
2974
  }
2897
2975
  };
2898
2976
 
2899
- export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, ApiClient, ApiError, CHAIN_ID, EXPLORER_TX_URL, InscriptionClient, LockerClient, MAX_BPS, SELECTORS, STATUS_LABELS, STELA_ADDRESS, ShareClient, StelaSdk, TOKENS, VALID_STATUSES, VIRTUAL_SHARE_OFFSET, addressesEqual, calculateFeeShares, computeStatus, convertToShares, deserializeSignature, findTokenByAddress, formatAddress, formatDuration, formatTimestamp, formatTokenValue, fromU256, getInscriptionOrderTypedData, getLendOfferTypedData, getTokensForNetwork, hashAssets, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
2977
+ export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, ApiClient, ApiError, CHAIN_ID, EXPLORER_TX_URL, InscriptionClient, LockerClient, MAX_BPS, SELECTORS, STATUS_LABELS, STELA_ADDRESS, ShareClient, StelaSdk, TOKENS, VALID_STATUSES, VIRTUAL_SHARE_OFFSET, addressesEqual, calculateFeeShares, computeStatus, convertToShares, deserializeSignature, findTokenByAddress, formatAddress, formatDuration, formatTimestamp, formatTokenValue, fromU256, getBatchLendOfferTypedData, getInscriptionOrderTypedData, getLendOfferTypedData, getTokensForNetwork, hashAssets, hashBatchEntries, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
2900
2978
  //# sourceMappingURL=index.js.map
2901
2979
  //# sourceMappingURL=index.js.map