@fepvenancio/stela-sdk 0.7.1 → 0.8.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.js CHANGED
@@ -56,6 +56,10 @@ var ASSET_TYPE_NAMES = {
56
56
  2: "ERC1155",
57
57
  3: "ERC4626"
58
58
  };
59
+ var GRACE_PERIOD = 86400n;
60
+ var AUCTION_DURATION = 86400n;
61
+ var AUCTION_PENALTY_BPS = 500n;
62
+ var AUCTION_RESERVE_BPS = 1000n;
59
63
  var U128_MAX = (1n << 128n) - 1n;
60
64
  var U256_MAX = (1n << 256n) - 1n;
61
65
  var toU256 = (n) => {
@@ -566,6 +570,185 @@ function getBatchLendOfferTypedData(params) {
566
570
  }
567
571
  };
568
572
  }
573
+ function u256Message(value) {
574
+ return {
575
+ low: (value & (1n << 128n) - 1n).toString(),
576
+ high: (value >> 128n).toString()
577
+ };
578
+ }
579
+ var STARKNET_DOMAIN_TYPE = [
580
+ { name: "name", type: "shortstring" },
581
+ { name: "version", type: "shortstring" },
582
+ { name: "chainId", type: "shortstring" },
583
+ { name: "revision", type: "shortstring" }
584
+ ];
585
+ var U256_TYPE = [
586
+ { name: "low", type: "u128" },
587
+ { name: "high", type: "u128" }
588
+ ];
589
+ function getCollectionLendOfferTypedData(params) {
590
+ return {
591
+ types: {
592
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
593
+ CollectionLendOffer: [
594
+ { name: "lender", type: "ContractAddress" },
595
+ { name: "debt_hash", type: "felt" },
596
+ { name: "interest_hash", type: "felt" },
597
+ { name: "debt_count", type: "u128" },
598
+ { name: "interest_count", type: "u128" },
599
+ { name: "collection_address", type: "ContractAddress" },
600
+ { name: "duration", type: "u128" },
601
+ { name: "deadline", type: "u128" },
602
+ { name: "nonce", type: "felt" }
603
+ ]
604
+ },
605
+ primaryType: "CollectionLendOffer",
606
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
607
+ message: {
608
+ lender: params.lender,
609
+ debt_hash: hashAssets(params.debtAssets),
610
+ interest_hash: hashAssets(params.interestAssets),
611
+ debt_count: params.debtCount.toString(),
612
+ interest_count: params.interestCount.toString(),
613
+ collection_address: params.collectionAddress,
614
+ duration: params.duration.toString(),
615
+ deadline: params.deadline.toString(),
616
+ nonce: params.nonce.toString()
617
+ }
618
+ };
619
+ }
620
+ function getCollectionBorrowAcceptanceTypedData(params) {
621
+ return {
622
+ types: {
623
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
624
+ CollectionBorrowAcceptance: [
625
+ { name: "offer_hash", type: "felt" },
626
+ { name: "borrower", type: "ContractAddress" },
627
+ { name: "token_id", type: "u256" },
628
+ { name: "nonce", type: "felt" }
629
+ ],
630
+ u256: U256_TYPE
631
+ },
632
+ primaryType: "CollectionBorrowAcceptance",
633
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
634
+ message: {
635
+ offer_hash: params.offerHash,
636
+ borrower: params.borrower,
637
+ token_id: u256Message(params.tokenId),
638
+ nonce: params.nonce.toString()
639
+ }
640
+ };
641
+ }
642
+ function getRenegotiationProposalTypedData(params) {
643
+ return {
644
+ types: {
645
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
646
+ RenegotiationProposal: [
647
+ { name: "inscription_id", type: "u256" },
648
+ { name: "proposer", type: "ContractAddress" },
649
+ { name: "new_duration", type: "u128" },
650
+ { name: "new_interest_hash", type: "felt" },
651
+ { name: "new_interest_count", type: "u128" },
652
+ { name: "proposal_deadline", type: "u128" },
653
+ { name: "nonce", type: "felt" }
654
+ ],
655
+ u256: U256_TYPE
656
+ },
657
+ primaryType: "RenegotiationProposal",
658
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
659
+ message: {
660
+ inscription_id: u256Message(params.inscriptionId),
661
+ proposer: params.proposer,
662
+ new_duration: params.newDuration.toString(),
663
+ new_interest_hash: hashAssets(params.newInterestAssets),
664
+ new_interest_count: params.newInterestCount.toString(),
665
+ proposal_deadline: params.proposalDeadline.toString(),
666
+ nonce: params.nonce.toString()
667
+ }
668
+ };
669
+ }
670
+ function getCollateralSaleOfferTypedData(params) {
671
+ return {
672
+ types: {
673
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
674
+ CollateralSaleOffer: [
675
+ { name: "inscription_id", type: "u256" },
676
+ { name: "borrower", type: "ContractAddress" },
677
+ { name: "min_price", type: "u256" },
678
+ { name: "payment_token", type: "ContractAddress" },
679
+ { name: "allowed_buyer", type: "ContractAddress" },
680
+ { name: "deadline", type: "u128" },
681
+ { name: "nonce", type: "felt" }
682
+ ],
683
+ u256: U256_TYPE
684
+ },
685
+ primaryType: "CollateralSaleOffer",
686
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
687
+ message: {
688
+ inscription_id: u256Message(params.inscriptionId),
689
+ borrower: params.borrower,
690
+ min_price: u256Message(params.minPrice),
691
+ payment_token: params.paymentToken,
692
+ allowed_buyer: params.allowedBuyer,
693
+ deadline: params.deadline.toString(),
694
+ nonce: params.nonce.toString()
695
+ }
696
+ };
697
+ }
698
+ function getRefinanceOfferTypedData(params) {
699
+ return {
700
+ types: {
701
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
702
+ RefinanceOffer: [
703
+ { name: "inscription_id", type: "u256" },
704
+ { name: "new_lender", type: "ContractAddress" },
705
+ { name: "new_debt_hash", type: "felt" },
706
+ { name: "new_interest_hash", type: "felt" },
707
+ { name: "new_debt_count", type: "u128" },
708
+ { name: "new_interest_count", type: "u128" },
709
+ { name: "new_duration", type: "u128" },
710
+ { name: "deadline", type: "u128" },
711
+ { name: "nonce", type: "felt" }
712
+ ],
713
+ u256: U256_TYPE
714
+ },
715
+ primaryType: "RefinanceOffer",
716
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
717
+ message: {
718
+ inscription_id: u256Message(params.inscriptionId),
719
+ new_lender: params.newLender,
720
+ new_debt_hash: hashAssets(params.newDebtAssets),
721
+ new_interest_hash: hashAssets(params.newInterestAssets),
722
+ new_debt_count: params.newDebtCount.toString(),
723
+ new_interest_count: params.newInterestCount.toString(),
724
+ new_duration: params.newDuration.toString(),
725
+ deadline: params.deadline.toString(),
726
+ nonce: params.nonce.toString()
727
+ }
728
+ };
729
+ }
730
+ function getRefinanceApprovalTypedData(params) {
731
+ return {
732
+ types: {
733
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
734
+ RefinanceApproval: [
735
+ { name: "inscription_id", type: "u256" },
736
+ { name: "offer_hash", type: "felt" },
737
+ { name: "borrower", type: "ContractAddress" },
738
+ { name: "nonce", type: "felt" }
739
+ ],
740
+ u256: U256_TYPE
741
+ },
742
+ primaryType: "RefinanceApproval",
743
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
744
+ message: {
745
+ inscription_id: u256Message(params.inscriptionId),
746
+ offer_hash: params.offerHash,
747
+ borrower: params.borrower,
748
+ nonce: params.nonce.toString()
749
+ }
750
+ };
751
+ }
569
752
 
570
753
  // src/offchain/signature.ts
571
754
  function serializeSignature(sig) {
@@ -2609,6 +2792,155 @@ var InscriptionClient = class {
2609
2792
  calldata: [minNonce]
2610
2793
  };
2611
2794
  }
2795
+ // ── T1 Call Builders ─────────────────────────────────────────────────
2796
+ /** T1-2: Settle a collection-wide lend offer */
2797
+ buildSettleCollection(params) {
2798
+ const calldata = [
2799
+ // CollectionLendOffer struct (9 fields)
2800
+ params.offer.lender,
2801
+ params.offer.debtHash,
2802
+ params.offer.interestHash,
2803
+ String(params.offer.debtCount),
2804
+ String(params.offer.interestCount),
2805
+ params.offer.collectionAddress,
2806
+ params.offer.duration.toString(),
2807
+ params.offer.deadline.toString(),
2808
+ params.offer.nonce.toString(),
2809
+ // CollectionBorrowAcceptance struct (4 fields)
2810
+ params.acceptance.offerHash,
2811
+ params.acceptance.borrower,
2812
+ ...toU256(params.acceptance.tokenId),
2813
+ params.acceptance.nonce.toString(),
2814
+ // debt_assets array
2815
+ ...serializeAssets(params.debtAssets),
2816
+ // interest_assets array
2817
+ ...serializeAssets(params.interestAssets),
2818
+ // lender_sig array
2819
+ String(params.lenderSig.length),
2820
+ ...params.lenderSig,
2821
+ // borrower_sig array
2822
+ String(params.borrowerSig.length),
2823
+ ...params.borrowerSig
2824
+ ];
2825
+ return { contractAddress: this.address, entrypoint: "settle_collection", calldata };
2826
+ }
2827
+ /** T1-4: Commit a renegotiation proposal hash on-chain */
2828
+ buildCommitRenegotiation(inscriptionId, proposalHash) {
2829
+ return {
2830
+ contractAddress: this.address,
2831
+ entrypoint: "commit_renegotiation",
2832
+ calldata: [...toU256(inscriptionId), proposalHash]
2833
+ };
2834
+ }
2835
+ /** T1-4: Execute a committed renegotiation proposal */
2836
+ buildExecuteRenegotiation(params) {
2837
+ const calldata = [
2838
+ ...toU256(params.inscriptionId),
2839
+ // RenegotiationProposal struct (7 fields)
2840
+ ...toU256(params.proposal.inscriptionId),
2841
+ params.proposal.proposer,
2842
+ params.proposal.newDuration.toString(),
2843
+ params.proposal.newInterestHash,
2844
+ String(params.proposal.newInterestCount),
2845
+ params.proposal.proposalDeadline.toString(),
2846
+ params.proposal.nonce.toString(),
2847
+ // proposer_sig array
2848
+ String(params.proposerSig.length),
2849
+ ...params.proposerSig,
2850
+ // new_interest_assets array
2851
+ ...serializeAssets(params.newInterestAssets)
2852
+ ];
2853
+ return { contractAddress: this.address, entrypoint: "execute_renegotiation", calldata };
2854
+ }
2855
+ /** T1-5: Buy collateral from a borrower's sale offer */
2856
+ buildBuyCollateral(params) {
2857
+ const calldata = [
2858
+ ...toU256(params.inscriptionId),
2859
+ // CollateralSaleOffer struct (7 fields)
2860
+ ...toU256(params.offer.inscriptionId),
2861
+ params.offer.borrower,
2862
+ ...toU256(params.offer.minPrice),
2863
+ params.offer.paymentToken,
2864
+ params.offer.allowedBuyer,
2865
+ params.offer.deadline.toString(),
2866
+ params.offer.nonce.toString(),
2867
+ // borrower_sig array
2868
+ String(params.borrowerSig.length),
2869
+ ...params.borrowerSig,
2870
+ // sale_price
2871
+ ...toU256(params.salePrice)
2872
+ ];
2873
+ return { contractAddress: this.address, entrypoint: "buy_collateral", calldata };
2874
+ }
2875
+ /** T1-1: Refinance an existing loan with a new lender */
2876
+ buildRefinance(params) {
2877
+ const calldata = [
2878
+ // RefinanceOffer struct (9 fields)
2879
+ ...toU256(params.offer.inscriptionId),
2880
+ params.offer.newLender,
2881
+ params.offer.newDebtHash,
2882
+ params.offer.newInterestHash,
2883
+ String(params.offer.newDebtCount),
2884
+ String(params.offer.newInterestCount),
2885
+ params.offer.newDuration.toString(),
2886
+ params.offer.deadline.toString(),
2887
+ params.offer.nonce.toString(),
2888
+ // new_debt_assets array
2889
+ ...serializeAssets(params.newDebtAssets),
2890
+ // new_interest_assets array
2891
+ ...serializeAssets(params.newInterestAssets),
2892
+ // new_lender_sig array
2893
+ String(params.newLenderSig.length),
2894
+ ...params.newLenderSig,
2895
+ // RefinanceApproval struct (4 fields)
2896
+ ...toU256(params.approval.inscriptionId),
2897
+ params.approval.offerHash,
2898
+ params.approval.borrower,
2899
+ params.approval.nonce.toString(),
2900
+ // borrower_sig array
2901
+ String(params.borrowerSig.length),
2902
+ ...params.borrowerSig
2903
+ ];
2904
+ return { contractAddress: this.address, entrypoint: "refinance", calldata };
2905
+ }
2906
+ /** T1-3: Start a Dutch auction on an expired, unfilled inscription */
2907
+ buildStartAuction(inscriptionId) {
2908
+ return {
2909
+ contractAddress: this.address,
2910
+ entrypoint: "start_auction",
2911
+ calldata: [...toU256(inscriptionId)]
2912
+ };
2913
+ }
2914
+ /** T1-3: Bid on an active Dutch auction */
2915
+ buildBid(inscriptionId) {
2916
+ return {
2917
+ contractAddress: this.address,
2918
+ entrypoint: "bid",
2919
+ calldata: [...toU256(inscriptionId)]
2920
+ };
2921
+ }
2922
+ /** T1-3: Claim collateral after an auction expires with no bids */
2923
+ buildClaimCollateral(inscriptionId) {
2924
+ return {
2925
+ contractAddress: this.address,
2926
+ entrypoint: "claim_collateral",
2927
+ calldata: [...toU256(inscriptionId)]
2928
+ };
2929
+ }
2930
+ // ── T1 Read Methods ──────────────────────────────────────────────────
2931
+ /** T1-3: Get the current Dutch auction price for a specific debt asset */
2932
+ async getAuctionPrice(inscriptionId, debtIndex) {
2933
+ const result = await this.contract.call("get_auction_price", [
2934
+ ...toU256(inscriptionId),
2935
+ String(debtIndex)
2936
+ ]);
2937
+ return extractU256(result);
2938
+ }
2939
+ /** T1-3: Get the auction end timestamp */
2940
+ async getAuctionEndTime(inscriptionId) {
2941
+ const result = await this.contract.call("get_auction_end_time", toU256(inscriptionId));
2942
+ return BigInt(String(result[0] ?? "0"));
2943
+ }
2612
2944
  // ── Execute Methods ────────────────────────────────────────────────
2613
2945
  /**
2614
2946
  * Execute one or more calls via the connected account.
@@ -2650,6 +2982,35 @@ var InscriptionClient = class {
2650
2982
  async cancelOrdersByNonce(minNonce) {
2651
2983
  return this.execute([this.buildCancelOrdersByNonce(minNonce)]);
2652
2984
  }
2985
+ // ── T1 Execute Methods ───────────────────────────────────────────────
2986
+ async settleCollection(params) {
2987
+ return this.execute([this.buildSettleCollection(params)]);
2988
+ }
2989
+ async commitRenegotiation(inscriptionId, proposalHash) {
2990
+ return this.execute([this.buildCommitRenegotiation(inscriptionId, proposalHash)]);
2991
+ }
2992
+ async executeRenegotiation(params, approvals) {
2993
+ const calls = [...approvals ?? [], this.buildExecuteRenegotiation(params)];
2994
+ return this.execute(calls);
2995
+ }
2996
+ async buyCollateral(params, approvals) {
2997
+ const calls = [...approvals ?? [], this.buildBuyCollateral(params)];
2998
+ return this.execute(calls);
2999
+ }
3000
+ async refinance(params, approvals) {
3001
+ const calls = [...approvals ?? [], this.buildRefinance(params)];
3002
+ return this.execute(calls);
3003
+ }
3004
+ async startAuction(inscriptionId) {
3005
+ return this.execute([this.buildStartAuction(inscriptionId)]);
3006
+ }
3007
+ async bid(inscriptionId, approvals) {
3008
+ const calls = [...approvals ?? [], this.buildBid(inscriptionId)];
3009
+ return this.execute(calls);
3010
+ }
3011
+ async claimCollateral(inscriptionId) {
3012
+ return this.execute([this.buildClaimCollateral(inscriptionId)]);
3013
+ }
2653
3014
  };
2654
3015
  function serializeAssets(assets) {
2655
3016
  const calldata = [String(assets.length)];
@@ -2689,7 +3050,9 @@ function parseStoredInscription(result) {
2689
3050
  multi_lender: Boolean(get("multi_lender", 8)),
2690
3051
  debt_asset_count: Number(get("debt_asset_count", 9)),
2691
3052
  interest_asset_count: Number(get("interest_asset_count", 10)),
2692
- collateral_asset_count: Number(get("collateral_asset_count", 11))
3053
+ collateral_asset_count: Number(get("collateral_asset_count", 11)),
3054
+ auction_started: Boolean(get("auction_started", 12)),
3055
+ auction_start_time: BigInt(String(get("auction_start_time", 13) ?? "0"))
2693
3056
  };
2694
3057
  }
2695
3058
  function extractFieldU256(val) {
@@ -3019,6 +3382,6 @@ var StelaSdk = class {
3019
3382
  }
3020
3383
  };
3021
3384
 
3022
- 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 };
3385
+ 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 };
3023
3386
  //# sourceMappingURL=index.js.map
3024
3387
  //# sourceMappingURL=index.js.map