@fepvenancio/stela-sdk 0.8.1 → 0.9.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
@@ -360,6 +360,8 @@ interface TokenInfo {
360
360
  decimals: number;
361
361
  addresses: Partial<Record<Network, string>>;
362
362
  logoUrl?: string;
363
+ /** Asset type — defaults to ERC20 if omitted */
364
+ assetType?: 'ERC20' | 'ERC721' | 'ERC1155' | 'ERC4626';
363
365
  }
364
366
 
365
367
  /**
@@ -367,6 +369,8 @@ interface TokenInfo {
367
369
  * Addresses sourced from official deployments.
368
370
  */
369
371
  declare const TOKENS: TokenInfo[];
372
+ /** Get NFT collections (ERC721) available on a specific network */
373
+ declare function getNFTCollections(network: string): TokenInfo[];
370
374
  /** Get tokens available on a specific network */
371
375
  declare function getTokensForNetwork(network: string): TokenInfo[];
372
376
  /** Find a token by its address (any network) */
@@ -380,6 +384,128 @@ declare function scaleByPercentage(value: bigint, percentage: bigint): bigint;
380
384
  declare function sharesToPercentage(shares: bigint, totalSupply: bigint, currentIssuedPercentage: bigint): bigint;
381
385
  /** Calculate the fee portion of shares given a fee in basis points */
382
386
  declare function calculateFeeShares(shares: bigint, feeBps: bigint): bigint;
387
+ /** Ceiling integer division: ceil(a / b). Matches Cairo div_ceil. */
388
+ declare function divCeil(a: bigint, b: bigint): bigint;
389
+ /**
390
+ * Pro-rata interest for early repayment. Matches Cairo pro_rata_interest().
391
+ * Rounds UP (ceiling) to protect lenders — borrower never underpays.
392
+ *
393
+ * @param amount - Full interest amount
394
+ * @param elapsed - Seconds elapsed since loan signed
395
+ * @param duration - Total loan duration in seconds
396
+ * @returns ceil(amount * elapsed / duration), capped at amount
397
+ */
398
+ declare function proRataInterest(amount: bigint, elapsed: bigint, duration: bigint): bigint;
399
+
400
+ /** Default dust buffer: 60 seconds of extra interest accrual to account for tx confirmation delay */
401
+ declare const DEFAULT_DUST_BUFFER_SECONDS = 60n;
402
+ /** Value breakdown for a single asset in a position */
403
+ interface AssetValue {
404
+ /** The asset definition */
405
+ asset: Asset;
406
+ /** The share-proportional amount of this asset */
407
+ proportionalValue: bigint;
408
+ }
409
+ /** Accrued interest for a single asset in a position */
410
+ interface AccruedInterestEntry {
411
+ /** The interest asset definition */
412
+ asset: Asset;
413
+ /** Full interest amount (before pro-rata) scaled to share proportion */
414
+ fullInterest: bigint;
415
+ /** Pro-rata accrued interest at the given elapsed time */
416
+ accruedInterest: bigint;
417
+ }
418
+ /** Complete position valuation at a point in time */
419
+ interface PositionValue {
420
+ /** Inscription ID */
421
+ inscriptionId: string;
422
+ /** Shares held */
423
+ shares: bigint;
424
+ /** Total supply of shares for this inscription */
425
+ totalSupply: bigint;
426
+ /** Share proportion as a fraction of MAX_BPS (10000) */
427
+ shareBps: bigint;
428
+ /** Debt asset values (proportional to shares held) */
429
+ debt: AssetValue[];
430
+ /** Interest asset values (full and accrued) */
431
+ interest: AccruedInterestEntry[];
432
+ /** Collateral asset values (proportional to shares held) */
433
+ collateral: AssetValue[];
434
+ /** Suggested floor price: sum of proportional debt + accrued interest (per asset) */
435
+ accrued: AccruedInterestEntry[];
436
+ /** Elapsed seconds since loan signed */
437
+ elapsed: bigint;
438
+ /** Total loan duration */
439
+ duration: bigint;
440
+ }
441
+ /**
442
+ * Compute the share proportion in BPS for a given share amount.
443
+ * Returns how many basis points (out of 10000) the shares represent.
444
+ */
445
+ declare function shareProportionBps(shares: bigint, totalSupply: bigint): bigint;
446
+ /**
447
+ * Compute the proportional value of an asset for a given share amount.
448
+ * This is the amount the share holder would receive on redemption.
449
+ *
450
+ * Matches the contract: `tracked_balance * shares / total_supply`
451
+ */
452
+ declare function proportionalAssetValue(assetValue: bigint, shares: bigint, totalSupply: bigint): bigint;
453
+ /**
454
+ * Compute the full position valuation at a point in time.
455
+ *
456
+ * @param params.inscriptionId - The inscription ID
457
+ * @param params.shares - Shares held by the position owner
458
+ * @param params.totalSupply - Total shares for this inscription
459
+ * @param params.debtAssets - Debt asset definitions with values
460
+ * @param params.interestAssets - Interest asset definitions with values
461
+ * @param params.collateralAssets - Collateral asset definitions with values
462
+ * @param params.elapsed - Seconds elapsed since signed_at
463
+ * @param params.duration - Total loan duration in seconds
464
+ */
465
+ declare function computePositionValue(params: {
466
+ inscriptionId: string;
467
+ shares: bigint;
468
+ totalSupply: bigint;
469
+ debtAssets: Asset[];
470
+ interestAssets: Asset[];
471
+ collateralAssets: Asset[];
472
+ elapsed: bigint;
473
+ duration: bigint;
474
+ }): PositionValue;
475
+ /**
476
+ * Compute accrued interest with a dust buffer to account for transaction confirmation delay.
477
+ *
478
+ * Between computing the price and the transaction landing on-chain, interest continues
479
+ * to accrue. This adds a configurable buffer (default 60s) of extra interest so the
480
+ * buyer's approval doesn't fail due to a tiny increase.
481
+ *
482
+ * @param amount - Full interest amount for the position
483
+ * @param elapsed - Current elapsed seconds since signed_at
484
+ * @param duration - Total loan duration in seconds
485
+ * @param bufferSeconds - Extra seconds to add (default: 60)
486
+ * @returns Accrued interest at (elapsed + buffer), capped at full amount
487
+ */
488
+ declare function accruedInterestWithBuffer(amount: bigint, elapsed: bigint, duration: bigint, bufferSeconds?: bigint): bigint;
489
+ /**
490
+ * Compute a safe minimum price for buying a lending position.
491
+ * Includes proportional debt + accrued interest + dust buffer for each interest asset.
492
+ *
493
+ * Use this when the buyer needs to know how much to approve for payment tokens.
494
+ *
495
+ * @returns Array of { asset, safeAmount } for debt assets and interest assets respectively
496
+ */
497
+ declare function computeSafePositionFloor(params: {
498
+ shares: bigint;
499
+ totalSupply: bigint;
500
+ debtAssets: Asset[];
501
+ interestAssets: Asset[];
502
+ elapsed: bigint;
503
+ duration: bigint;
504
+ bufferSeconds?: bigint;
505
+ }): {
506
+ debtFloor: AssetValue[];
507
+ interestFloor: AssetValue[];
508
+ };
383
509
 
384
510
  /** Event selectors for all Stela protocol events */
385
511
  declare const SELECTORS: {
@@ -795,13 +921,19 @@ declare class InscriptionClient {
795
921
  interface ShareClientOptions {
796
922
  stelaAddress: string;
797
923
  provider: RpcProvider;
924
+ account?: Account;
798
925
  }
799
926
  /**
800
- * Client for reading ERC1155 share balances on the Stela contract.
927
+ * Client for ERC1155 share operations on the Stela contract.
801
928
  * Inscription IDs are token IDs — each lender receives shares as ERC1155 tokens.
929
+ *
930
+ * Shares are freely transferable via standard ERC1155 safeTransferFrom.
931
+ * Any address holding shares can call redeem() after repayment/liquidation.
802
932
  */
803
933
  declare class ShareClient {
804
934
  private contract;
935
+ private address;
936
+ private account?;
805
937
  constructor(opts: ShareClientOptions);
806
938
  /** Get share balance for an account on a specific inscription */
807
939
  balanceOf(account: string, inscriptionId: bigint): Promise<bigint>;
@@ -809,6 +941,33 @@ declare class ShareClient {
809
941
  balanceOfBatch(accounts: string[], inscriptionIds: bigint[]): Promise<bigint[]>;
810
942
  /** Check if an operator is approved for all tokens of an owner */
811
943
  isApprovedForAll(owner: string, operator: string): Promise<boolean>;
944
+ /**
945
+ * Build a call to transfer shares (ERC1155 safeTransferFrom).
946
+ * This enables secondary market trading of lending positions.
947
+ *
948
+ * @param from - Current share holder
949
+ * @param to - Recipient address
950
+ * @param inscriptionId - The inscription (token ID)
951
+ * @param amount - Number of shares to transfer
952
+ * @param data - Optional calldata (empty array by default)
953
+ */
954
+ buildTransferShares(from: string, to: string, inscriptionId: bigint, amount: bigint, data?: string[]): Call;
955
+ /**
956
+ * Build a call to approve an operator for all ERC1155 tokens.
957
+ * Required before a marketplace contract can transfer shares on your behalf.
958
+ *
959
+ * @param operator - The address to approve (e.g., marketplace contract)
960
+ * @param approved - Whether to approve or revoke
961
+ */
962
+ buildSetApprovalForAll(operator: string, approved: boolean): Call;
963
+ /** Transfer shares to another address */
964
+ transferShares(from: string, to: string, inscriptionId: bigint, amount: bigint, data?: string[]): Promise<{
965
+ transaction_hash: string;
966
+ }>;
967
+ /** Approve or revoke an operator for all ERC1155 tokens */
968
+ setApprovalForAll(operator: string, approved: boolean): Promise<{
969
+ transaction_hash: string;
970
+ }>;
812
971
  }
813
972
 
814
973
  declare class LockerClient {
@@ -930,4 +1089,4 @@ declare class StelaSdk {
930
1089
  constructor(opts: StelaSdkOptions);
931
1090
  }
932
1091
 
933
- export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, AUCTION_DURATION, AUCTION_PENALTY_BPS, AUCTION_RESERVE_BPS, ApiClient, type ApiClientOptions, type ApiDetailResponse, ApiError, type ApiListResponse, type Asset, type AssetRow, type AssetType, type AuctionBidEvent, type AuctionStartedEvent, type BatchEntry, CHAIN_ID, type Call, EXPLORER_TX_URL, GRACE_PERIOD, 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, getCollateralSaleOfferTypedData, getCollectionBorrowAcceptanceTypedData, getCollectionLendOfferTypedData, getInscriptionOrderTypedData, getLendOfferTypedData, getRefinanceApprovalTypedData, getRefinanceOfferTypedData, getRenegotiationProposalTypedData, getTokensForNetwork, hashAssets, hashBatchEntries, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
1092
+ export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, AUCTION_DURATION, AUCTION_PENALTY_BPS, AUCTION_RESERVE_BPS, type AccruedInterestEntry, ApiClient, type ApiClientOptions, type ApiDetailResponse, ApiError, type ApiListResponse, type Asset, type AssetRow, type AssetType, type AssetValue, type AuctionBidEvent, type AuctionStartedEvent, type BatchEntry, CHAIN_ID, type Call, DEFAULT_DUST_BUFFER_SECONDS, EXPLORER_TX_URL, GRACE_PERIOD, 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 PositionValue, 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, accruedInterestWithBuffer, addressesEqual, calculateFeeShares, computePositionValue, computeSafePositionFloor, computeStatus, convertToShares, deserializeSignature, divCeil, findTokenByAddress, formatAddress, formatDuration, formatTimestamp, formatTokenValue, fromU256, getBatchLendOfferTypedData, getCollateralSaleOfferTypedData, getCollectionBorrowAcceptanceTypedData, getCollectionLendOfferTypedData, getInscriptionOrderTypedData, getLendOfferTypedData, getNFTCollections, getRefinanceApprovalTypedData, getRefinanceOfferTypedData, getRenegotiationProposalTypedData, getTokensForNetwork, hashAssets, hashBatchEntries, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, proRataInterest, proportionalAssetValue, resolveNetwork, scaleByPercentage, serializeSignature, shareProportionBps, sharesToPercentage, toHex, toU256 };
package/dist/index.d.ts CHANGED
@@ -360,6 +360,8 @@ interface TokenInfo {
360
360
  decimals: number;
361
361
  addresses: Partial<Record<Network, string>>;
362
362
  logoUrl?: string;
363
+ /** Asset type — defaults to ERC20 if omitted */
364
+ assetType?: 'ERC20' | 'ERC721' | 'ERC1155' | 'ERC4626';
363
365
  }
364
366
 
365
367
  /**
@@ -367,6 +369,8 @@ interface TokenInfo {
367
369
  * Addresses sourced from official deployments.
368
370
  */
369
371
  declare const TOKENS: TokenInfo[];
372
+ /** Get NFT collections (ERC721) available on a specific network */
373
+ declare function getNFTCollections(network: string): TokenInfo[];
370
374
  /** Get tokens available on a specific network */
371
375
  declare function getTokensForNetwork(network: string): TokenInfo[];
372
376
  /** Find a token by its address (any network) */
@@ -380,6 +384,128 @@ declare function scaleByPercentage(value: bigint, percentage: bigint): bigint;
380
384
  declare function sharesToPercentage(shares: bigint, totalSupply: bigint, currentIssuedPercentage: bigint): bigint;
381
385
  /** Calculate the fee portion of shares given a fee in basis points */
382
386
  declare function calculateFeeShares(shares: bigint, feeBps: bigint): bigint;
387
+ /** Ceiling integer division: ceil(a / b). Matches Cairo div_ceil. */
388
+ declare function divCeil(a: bigint, b: bigint): bigint;
389
+ /**
390
+ * Pro-rata interest for early repayment. Matches Cairo pro_rata_interest().
391
+ * Rounds UP (ceiling) to protect lenders — borrower never underpays.
392
+ *
393
+ * @param amount - Full interest amount
394
+ * @param elapsed - Seconds elapsed since loan signed
395
+ * @param duration - Total loan duration in seconds
396
+ * @returns ceil(amount * elapsed / duration), capped at amount
397
+ */
398
+ declare function proRataInterest(amount: bigint, elapsed: bigint, duration: bigint): bigint;
399
+
400
+ /** Default dust buffer: 60 seconds of extra interest accrual to account for tx confirmation delay */
401
+ declare const DEFAULT_DUST_BUFFER_SECONDS = 60n;
402
+ /** Value breakdown for a single asset in a position */
403
+ interface AssetValue {
404
+ /** The asset definition */
405
+ asset: Asset;
406
+ /** The share-proportional amount of this asset */
407
+ proportionalValue: bigint;
408
+ }
409
+ /** Accrued interest for a single asset in a position */
410
+ interface AccruedInterestEntry {
411
+ /** The interest asset definition */
412
+ asset: Asset;
413
+ /** Full interest amount (before pro-rata) scaled to share proportion */
414
+ fullInterest: bigint;
415
+ /** Pro-rata accrued interest at the given elapsed time */
416
+ accruedInterest: bigint;
417
+ }
418
+ /** Complete position valuation at a point in time */
419
+ interface PositionValue {
420
+ /** Inscription ID */
421
+ inscriptionId: string;
422
+ /** Shares held */
423
+ shares: bigint;
424
+ /** Total supply of shares for this inscription */
425
+ totalSupply: bigint;
426
+ /** Share proportion as a fraction of MAX_BPS (10000) */
427
+ shareBps: bigint;
428
+ /** Debt asset values (proportional to shares held) */
429
+ debt: AssetValue[];
430
+ /** Interest asset values (full and accrued) */
431
+ interest: AccruedInterestEntry[];
432
+ /** Collateral asset values (proportional to shares held) */
433
+ collateral: AssetValue[];
434
+ /** Suggested floor price: sum of proportional debt + accrued interest (per asset) */
435
+ accrued: AccruedInterestEntry[];
436
+ /** Elapsed seconds since loan signed */
437
+ elapsed: bigint;
438
+ /** Total loan duration */
439
+ duration: bigint;
440
+ }
441
+ /**
442
+ * Compute the share proportion in BPS for a given share amount.
443
+ * Returns how many basis points (out of 10000) the shares represent.
444
+ */
445
+ declare function shareProportionBps(shares: bigint, totalSupply: bigint): bigint;
446
+ /**
447
+ * Compute the proportional value of an asset for a given share amount.
448
+ * This is the amount the share holder would receive on redemption.
449
+ *
450
+ * Matches the contract: `tracked_balance * shares / total_supply`
451
+ */
452
+ declare function proportionalAssetValue(assetValue: bigint, shares: bigint, totalSupply: bigint): bigint;
453
+ /**
454
+ * Compute the full position valuation at a point in time.
455
+ *
456
+ * @param params.inscriptionId - The inscription ID
457
+ * @param params.shares - Shares held by the position owner
458
+ * @param params.totalSupply - Total shares for this inscription
459
+ * @param params.debtAssets - Debt asset definitions with values
460
+ * @param params.interestAssets - Interest asset definitions with values
461
+ * @param params.collateralAssets - Collateral asset definitions with values
462
+ * @param params.elapsed - Seconds elapsed since signed_at
463
+ * @param params.duration - Total loan duration in seconds
464
+ */
465
+ declare function computePositionValue(params: {
466
+ inscriptionId: string;
467
+ shares: bigint;
468
+ totalSupply: bigint;
469
+ debtAssets: Asset[];
470
+ interestAssets: Asset[];
471
+ collateralAssets: Asset[];
472
+ elapsed: bigint;
473
+ duration: bigint;
474
+ }): PositionValue;
475
+ /**
476
+ * Compute accrued interest with a dust buffer to account for transaction confirmation delay.
477
+ *
478
+ * Between computing the price and the transaction landing on-chain, interest continues
479
+ * to accrue. This adds a configurable buffer (default 60s) of extra interest so the
480
+ * buyer's approval doesn't fail due to a tiny increase.
481
+ *
482
+ * @param amount - Full interest amount for the position
483
+ * @param elapsed - Current elapsed seconds since signed_at
484
+ * @param duration - Total loan duration in seconds
485
+ * @param bufferSeconds - Extra seconds to add (default: 60)
486
+ * @returns Accrued interest at (elapsed + buffer), capped at full amount
487
+ */
488
+ declare function accruedInterestWithBuffer(amount: bigint, elapsed: bigint, duration: bigint, bufferSeconds?: bigint): bigint;
489
+ /**
490
+ * Compute a safe minimum price for buying a lending position.
491
+ * Includes proportional debt + accrued interest + dust buffer for each interest asset.
492
+ *
493
+ * Use this when the buyer needs to know how much to approve for payment tokens.
494
+ *
495
+ * @returns Array of { asset, safeAmount } for debt assets and interest assets respectively
496
+ */
497
+ declare function computeSafePositionFloor(params: {
498
+ shares: bigint;
499
+ totalSupply: bigint;
500
+ debtAssets: Asset[];
501
+ interestAssets: Asset[];
502
+ elapsed: bigint;
503
+ duration: bigint;
504
+ bufferSeconds?: bigint;
505
+ }): {
506
+ debtFloor: AssetValue[];
507
+ interestFloor: AssetValue[];
508
+ };
383
509
 
384
510
  /** Event selectors for all Stela protocol events */
385
511
  declare const SELECTORS: {
@@ -795,13 +921,19 @@ declare class InscriptionClient {
795
921
  interface ShareClientOptions {
796
922
  stelaAddress: string;
797
923
  provider: RpcProvider;
924
+ account?: Account;
798
925
  }
799
926
  /**
800
- * Client for reading ERC1155 share balances on the Stela contract.
927
+ * Client for ERC1155 share operations on the Stela contract.
801
928
  * Inscription IDs are token IDs — each lender receives shares as ERC1155 tokens.
929
+ *
930
+ * Shares are freely transferable via standard ERC1155 safeTransferFrom.
931
+ * Any address holding shares can call redeem() after repayment/liquidation.
802
932
  */
803
933
  declare class ShareClient {
804
934
  private contract;
935
+ private address;
936
+ private account?;
805
937
  constructor(opts: ShareClientOptions);
806
938
  /** Get share balance for an account on a specific inscription */
807
939
  balanceOf(account: string, inscriptionId: bigint): Promise<bigint>;
@@ -809,6 +941,33 @@ declare class ShareClient {
809
941
  balanceOfBatch(accounts: string[], inscriptionIds: bigint[]): Promise<bigint[]>;
810
942
  /** Check if an operator is approved for all tokens of an owner */
811
943
  isApprovedForAll(owner: string, operator: string): Promise<boolean>;
944
+ /**
945
+ * Build a call to transfer shares (ERC1155 safeTransferFrom).
946
+ * This enables secondary market trading of lending positions.
947
+ *
948
+ * @param from - Current share holder
949
+ * @param to - Recipient address
950
+ * @param inscriptionId - The inscription (token ID)
951
+ * @param amount - Number of shares to transfer
952
+ * @param data - Optional calldata (empty array by default)
953
+ */
954
+ buildTransferShares(from: string, to: string, inscriptionId: bigint, amount: bigint, data?: string[]): Call;
955
+ /**
956
+ * Build a call to approve an operator for all ERC1155 tokens.
957
+ * Required before a marketplace contract can transfer shares on your behalf.
958
+ *
959
+ * @param operator - The address to approve (e.g., marketplace contract)
960
+ * @param approved - Whether to approve or revoke
961
+ */
962
+ buildSetApprovalForAll(operator: string, approved: boolean): Call;
963
+ /** Transfer shares to another address */
964
+ transferShares(from: string, to: string, inscriptionId: bigint, amount: bigint, data?: string[]): Promise<{
965
+ transaction_hash: string;
966
+ }>;
967
+ /** Approve or revoke an operator for all ERC1155 tokens */
968
+ setApprovalForAll(operator: string, approved: boolean): Promise<{
969
+ transaction_hash: string;
970
+ }>;
812
971
  }
813
972
 
814
973
  declare class LockerClient {
@@ -930,4 +1089,4 @@ declare class StelaSdk {
930
1089
  constructor(opts: StelaSdkOptions);
931
1090
  }
932
1091
 
933
- export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, AUCTION_DURATION, AUCTION_PENALTY_BPS, AUCTION_RESERVE_BPS, ApiClient, type ApiClientOptions, type ApiDetailResponse, ApiError, type ApiListResponse, type Asset, type AssetRow, type AssetType, type AuctionBidEvent, type AuctionStartedEvent, type BatchEntry, CHAIN_ID, type Call, EXPLORER_TX_URL, GRACE_PERIOD, 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, getCollateralSaleOfferTypedData, getCollectionBorrowAcceptanceTypedData, getCollectionLendOfferTypedData, getInscriptionOrderTypedData, getLendOfferTypedData, getRefinanceApprovalTypedData, getRefinanceOfferTypedData, getRenegotiationProposalTypedData, getTokensForNetwork, hashAssets, hashBatchEntries, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
1092
+ export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, AUCTION_DURATION, AUCTION_PENALTY_BPS, AUCTION_RESERVE_BPS, type AccruedInterestEntry, ApiClient, type ApiClientOptions, type ApiDetailResponse, ApiError, type ApiListResponse, type Asset, type AssetRow, type AssetType, type AssetValue, type AuctionBidEvent, type AuctionStartedEvent, type BatchEntry, CHAIN_ID, type Call, DEFAULT_DUST_BUFFER_SECONDS, EXPLORER_TX_URL, GRACE_PERIOD, 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 PositionValue, 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, accruedInterestWithBuffer, addressesEqual, calculateFeeShares, computePositionValue, computeSafePositionFloor, computeStatus, convertToShares, deserializeSignature, divCeil, findTokenByAddress, formatAddress, formatDuration, formatTimestamp, formatTokenValue, fromU256, getBatchLendOfferTypedData, getCollateralSaleOfferTypedData, getCollectionBorrowAcceptanceTypedData, getCollectionLendOfferTypedData, getInscriptionOrderTypedData, getLendOfferTypedData, getNFTCollections, getRefinanceApprovalTypedData, getRefinanceOfferTypedData, getRenegotiationProposalTypedData, getTokensForNetwork, hashAssets, hashBatchEntries, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, proRataInterest, proportionalAssetValue, resolveNetwork, scaleByPercentage, serializeSignature, shareProportionBps, sharesToPercentage, toHex, toU256 };
package/dist/index.js CHANGED
@@ -256,11 +256,35 @@ var TOKENS = [
256
256
  addresses: {
257
257
  sepolia: "0x04f2345306bf8ef1c8c1445661354ef08421aa092459445a5d6b46641237e943"
258
258
  }
259
+ },
260
+ // NFT Collections (ERC721)
261
+ {
262
+ symbol: "GENESIS",
263
+ name: "Stela Genesis",
264
+ decimals: 0,
265
+ assetType: "ERC721",
266
+ addresses: {
267
+ sepolia: "0x0265ea52ffbf1b7e1a029b94fe1a2023899dd0bc02eb1f11c9b04ea90e957d28"
268
+ }
269
+ },
270
+ {
271
+ symbol: "MockNFT",
272
+ name: "Mock ERC721",
273
+ decimals: 0,
274
+ assetType: "ERC721",
275
+ addresses: {
276
+ sepolia: "0x032bfd52134ad92beae1bc5018a3748e1d1240efd627220e314c07e4c63433d5"
277
+ }
259
278
  }
260
279
  ];
261
280
  function normalizeHex(addr) {
262
281
  return "0x" + addr.replace(/^0x0*/i, "").toLowerCase();
263
282
  }
283
+ function getNFTCollections(network) {
284
+ return TOKENS.filter(
285
+ (t) => t.assetType === "ERC721" && t.addresses[network] !== void 0
286
+ );
287
+ }
264
288
  function getTokensForNetwork(network) {
265
289
  return TOKENS.filter((t) => t.addresses[network] !== void 0);
266
290
  }
@@ -286,6 +310,74 @@ function sharesToPercentage(shares, totalSupply, currentIssuedPercentage) {
286
310
  function calculateFeeShares(shares, feeBps) {
287
311
  return shares * feeBps / MAX_BPS;
288
312
  }
313
+ function divCeil(a, b) {
314
+ if (a === 0n) return 0n;
315
+ return (a + b - 1n) / b;
316
+ }
317
+ function proRataInterest(amount, elapsed, duration) {
318
+ if (amount === 0n || elapsed === 0n) return 0n;
319
+ if (elapsed >= duration) return amount;
320
+ return divCeil(amount * elapsed, duration);
321
+ }
322
+
323
+ // src/math/position.ts
324
+ var DEFAULT_DUST_BUFFER_SECONDS = 60n;
325
+ function shareProportionBps(shares, totalSupply) {
326
+ if (totalSupply === 0n) return 0n;
327
+ return shares * MAX_BPS / totalSupply;
328
+ }
329
+ function proportionalAssetValue(assetValue, shares, totalSupply) {
330
+ if (totalSupply === 0n || shares === 0n) return 0n;
331
+ return assetValue * shares / totalSupply;
332
+ }
333
+ function computePositionValue(params) {
334
+ const { shares, totalSupply, elapsed, duration } = params;
335
+ const shareBps = shareProportionBps(shares, totalSupply);
336
+ const debt = params.debtAssets.map((asset) => ({
337
+ asset,
338
+ proportionalValue: proportionalAssetValue(asset.value, shares, totalSupply)
339
+ }));
340
+ const interest = params.interestAssets.map((asset) => {
341
+ const fullInterest = proportionalAssetValue(asset.value, shares, totalSupply);
342
+ const accruedInterest = duration === 0n ? fullInterest : proRataInterest(fullInterest, elapsed, duration);
343
+ return { asset, fullInterest, accruedInterest };
344
+ });
345
+ const collateral = params.collateralAssets.map((asset) => ({
346
+ asset,
347
+ proportionalValue: proportionalAssetValue(asset.value, shares, totalSupply)
348
+ }));
349
+ return {
350
+ inscriptionId: params.inscriptionId,
351
+ shares,
352
+ totalSupply,
353
+ shareBps,
354
+ debt,
355
+ interest,
356
+ collateral,
357
+ accrued: interest,
358
+ elapsed,
359
+ duration
360
+ };
361
+ }
362
+ function accruedInterestWithBuffer(amount, elapsed, duration, bufferSeconds = DEFAULT_DUST_BUFFER_SECONDS) {
363
+ if (duration === 0n) return amount;
364
+ const bufferedElapsed = elapsed + bufferSeconds;
365
+ return proRataInterest(amount, bufferedElapsed, duration);
366
+ }
367
+ function computeSafePositionFloor(params) {
368
+ const { shares, totalSupply, elapsed, duration } = params;
369
+ const buffer = params.bufferSeconds ?? DEFAULT_DUST_BUFFER_SECONDS;
370
+ const debtFloor = params.debtAssets.map((asset) => ({
371
+ asset,
372
+ proportionalValue: proportionalAssetValue(asset.value, shares, totalSupply)
373
+ }));
374
+ const interestFloor = params.interestAssets.map((asset) => {
375
+ const fullInterest = proportionalAssetValue(asset.value, shares, totalSupply);
376
+ const safeAccrued = accruedInterestWithBuffer(fullInterest, elapsed, duration, buffer);
377
+ return { asset, proportionalValue: safeAccrued };
378
+ });
379
+ return { debtFloor, interestFloor };
380
+ }
289
381
  var SELECTORS = {
290
382
  InscriptionCreated: hash.getSelectorFromName("InscriptionCreated"),
291
383
  InscriptionSigned: hash.getSelectorFromName("InscriptionSigned"),
@@ -3468,9 +3560,14 @@ function extractFieldU256(val) {
3468
3560
  }
3469
3561
  var ShareClient = class {
3470
3562
  contract;
3563
+ address;
3564
+ account;
3471
3565
  constructor(opts) {
3566
+ this.address = opts.stelaAddress;
3472
3567
  this.contract = new Contract(stela_default, opts.stelaAddress, opts.provider);
3568
+ this.account = opts.account;
3473
3569
  }
3570
+ // ── Read Methods ───────────────────────────────────────────────────
3474
3571
  /** Get share balance for an account on a specific inscription */
3475
3572
  async balanceOf(account, inscriptionId) {
3476
3573
  const result = await this.contract.call("balance_of", [account, ...toU256(inscriptionId)]);
@@ -3494,6 +3591,53 @@ var ShareClient = class {
3494
3591
  const result = await this.contract.call("is_approved_for_all", [owner, operator]);
3495
3592
  return Boolean(result[0]);
3496
3593
  }
3594
+ // ── Call Builders ──────────────────────────────────────────────────
3595
+ /**
3596
+ * Build a call to transfer shares (ERC1155 safeTransferFrom).
3597
+ * This enables secondary market trading of lending positions.
3598
+ *
3599
+ * @param from - Current share holder
3600
+ * @param to - Recipient address
3601
+ * @param inscriptionId - The inscription (token ID)
3602
+ * @param amount - Number of shares to transfer
3603
+ * @param data - Optional calldata (empty array by default)
3604
+ */
3605
+ buildTransferShares(from, to, inscriptionId, amount, data = []) {
3606
+ return {
3607
+ contractAddress: this.address,
3608
+ entrypoint: "safe_transfer_from",
3609
+ calldata: [from, to, ...toU256(inscriptionId), ...toU256(amount), String(data.length), ...data]
3610
+ };
3611
+ }
3612
+ /**
3613
+ * Build a call to approve an operator for all ERC1155 tokens.
3614
+ * Required before a marketplace contract can transfer shares on your behalf.
3615
+ *
3616
+ * @param operator - The address to approve (e.g., marketplace contract)
3617
+ * @param approved - Whether to approve or revoke
3618
+ */
3619
+ buildSetApprovalForAll(operator, approved) {
3620
+ return {
3621
+ contractAddress: this.address,
3622
+ entrypoint: "set_approval_for_all",
3623
+ calldata: [operator, approved ? "1" : "0"]
3624
+ };
3625
+ }
3626
+ // ── Execute Methods ────────────────────────────────────────────────
3627
+ /** Transfer shares to another address */
3628
+ async transferShares(from, to, inscriptionId, amount, data = []) {
3629
+ if (!this.account) throw new Error("Account required for write operations");
3630
+ const result = await this.account.execute([
3631
+ this.buildTransferShares(from, to, inscriptionId, amount, data)
3632
+ ]);
3633
+ return { transaction_hash: result.transaction_hash };
3634
+ }
3635
+ /** Approve or revoke an operator for all ERC1155 tokens */
3636
+ async setApprovalForAll(operator, approved) {
3637
+ if (!this.account) throw new Error("Account required for write operations");
3638
+ const result = await this.account.execute([this.buildSetApprovalForAll(operator, approved)]);
3639
+ return { transaction_hash: result.transaction_hash };
3640
+ }
3497
3641
  };
3498
3642
  function extractBigInt(result) {
3499
3643
  const arr = result;
@@ -3778,7 +3922,8 @@ var StelaSdk = class {
3778
3922
  });
3779
3923
  this.shares = new ShareClient({
3780
3924
  stelaAddress: this.stelaAddress,
3781
- provider: opts.provider
3925
+ provider: opts.provider,
3926
+ account: opts.account
3782
3927
  });
3783
3928
  const stelaContract = new Contract(stela_default, this.stelaAddress, opts.provider);
3784
3929
  this.locker = new LockerClient(stelaContract, opts.provider, opts.account);
@@ -3786,6 +3931,6 @@ var StelaSdk = class {
3786
3931
  }
3787
3932
  };
3788
3933
 
3789
- export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, AUCTION_DURATION, AUCTION_PENALTY_BPS, AUCTION_RESERVE_BPS, ApiClient, ApiError, CHAIN_ID, EXPLORER_TX_URL, GRACE_PERIOD, 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, getCollateralSaleOfferTypedData, getCollectionBorrowAcceptanceTypedData, getCollectionLendOfferTypedData, getInscriptionOrderTypedData, getLendOfferTypedData, getRefinanceApprovalTypedData, getRefinanceOfferTypedData, getRenegotiationProposalTypedData, getTokensForNetwork, hashAssets, hashBatchEntries, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
3934
+ export { ASSET_TYPE_ENUM, ASSET_TYPE_NAMES, AUCTION_DURATION, AUCTION_PENALTY_BPS, AUCTION_RESERVE_BPS, ApiClient, ApiError, CHAIN_ID, DEFAULT_DUST_BUFFER_SECONDS, EXPLORER_TX_URL, GRACE_PERIOD, InscriptionClient, LockerClient, MAX_BPS, SELECTORS, STATUS_LABELS, STELA_ADDRESS, ShareClient, StelaSdk, TOKENS, VALID_STATUSES, VIRTUAL_SHARE_OFFSET, accruedInterestWithBuffer, addressesEqual, calculateFeeShares, computePositionValue, computeSafePositionFloor, computeStatus, convertToShares, deserializeSignature, divCeil, findTokenByAddress, formatAddress, formatDuration, formatTimestamp, formatTokenValue, fromU256, getBatchLendOfferTypedData, getCollateralSaleOfferTypedData, getCollectionBorrowAcceptanceTypedData, getCollectionLendOfferTypedData, getInscriptionOrderTypedData, getLendOfferTypedData, getNFTCollections, getRefinanceApprovalTypedData, getRefinanceOfferTypedData, getRenegotiationProposalTypedData, getTokensForNetwork, hashAssets, hashBatchEntries, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, proRataInterest, proportionalAssetValue, resolveNetwork, scaleByPercentage, serializeSignature, shareProportionBps, sharesToPercentage, toHex, toU256 };
3790
3935
  //# sourceMappingURL=index.js.map
3791
3936
  //# sourceMappingURL=index.js.map