@fepvenancio/stela-sdk 0.8.0 → 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.cjs +559 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +161 -2
- package/dist/index.d.ts +161 -2
- package/dist/index.js +551 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/stela.json +404 -0
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
|
|
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
|
|
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 };
|