@fepvenancio/stela-sdk 0.7.1 → 0.8.1

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 CHANGED
@@ -58,6 +58,10 @@ var ASSET_TYPE_NAMES = {
58
58
  2: "ERC1155",
59
59
  3: "ERC4626"
60
60
  };
61
+ var GRACE_PERIOD = 86400n;
62
+ var AUCTION_DURATION = 86400n;
63
+ var AUCTION_PENALTY_BPS = 500n;
64
+ var AUCTION_RESERVE_BPS = 1000n;
61
65
  var U128_MAX = (1n << 128n) - 1n;
62
66
  var U256_MAX = (1n << 256n) - 1n;
63
67
  var toU256 = (n) => {
@@ -568,6 +572,185 @@ function getBatchLendOfferTypedData(params) {
568
572
  }
569
573
  };
570
574
  }
575
+ function u256Message(value) {
576
+ return {
577
+ low: (value & (1n << 128n) - 1n).toString(),
578
+ high: (value >> 128n).toString()
579
+ };
580
+ }
581
+ var STARKNET_DOMAIN_TYPE = [
582
+ { name: "name", type: "shortstring" },
583
+ { name: "version", type: "shortstring" },
584
+ { name: "chainId", type: "shortstring" },
585
+ { name: "revision", type: "shortstring" }
586
+ ];
587
+ var U256_TYPE = [
588
+ { name: "low", type: "u128" },
589
+ { name: "high", type: "u128" }
590
+ ];
591
+ function getCollectionLendOfferTypedData(params) {
592
+ return {
593
+ types: {
594
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
595
+ CollectionLendOffer: [
596
+ { name: "lender", type: "ContractAddress" },
597
+ { name: "debt_hash", type: "felt" },
598
+ { name: "interest_hash", type: "felt" },
599
+ { name: "debt_count", type: "u128" },
600
+ { name: "interest_count", type: "u128" },
601
+ { name: "collection_address", type: "ContractAddress" },
602
+ { name: "duration", type: "u128" },
603
+ { name: "deadline", type: "u128" },
604
+ { name: "nonce", type: "felt" }
605
+ ]
606
+ },
607
+ primaryType: "CollectionLendOffer",
608
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
609
+ message: {
610
+ lender: params.lender,
611
+ debt_hash: hashAssets(params.debtAssets),
612
+ interest_hash: hashAssets(params.interestAssets),
613
+ debt_count: params.debtCount.toString(),
614
+ interest_count: params.interestCount.toString(),
615
+ collection_address: params.collectionAddress,
616
+ duration: params.duration.toString(),
617
+ deadline: params.deadline.toString(),
618
+ nonce: params.nonce.toString()
619
+ }
620
+ };
621
+ }
622
+ function getCollectionBorrowAcceptanceTypedData(params) {
623
+ return {
624
+ types: {
625
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
626
+ CollectionBorrowAcceptance: [
627
+ { name: "offer_hash", type: "felt" },
628
+ { name: "borrower", type: "ContractAddress" },
629
+ { name: "token_id", type: "u256" },
630
+ { name: "nonce", type: "felt" }
631
+ ],
632
+ u256: U256_TYPE
633
+ },
634
+ primaryType: "CollectionBorrowAcceptance",
635
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
636
+ message: {
637
+ offer_hash: params.offerHash,
638
+ borrower: params.borrower,
639
+ token_id: u256Message(params.tokenId),
640
+ nonce: params.nonce.toString()
641
+ }
642
+ };
643
+ }
644
+ function getRenegotiationProposalTypedData(params) {
645
+ return {
646
+ types: {
647
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
648
+ RenegotiationProposal: [
649
+ { name: "inscription_id", type: "u256" },
650
+ { name: "proposer", type: "ContractAddress" },
651
+ { name: "new_duration", type: "u128" },
652
+ { name: "new_interest_hash", type: "felt" },
653
+ { name: "new_interest_count", type: "u128" },
654
+ { name: "proposal_deadline", type: "u128" },
655
+ { name: "nonce", type: "felt" }
656
+ ],
657
+ u256: U256_TYPE
658
+ },
659
+ primaryType: "RenegotiationProposal",
660
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
661
+ message: {
662
+ inscription_id: u256Message(params.inscriptionId),
663
+ proposer: params.proposer,
664
+ new_duration: params.newDuration.toString(),
665
+ new_interest_hash: hashAssets(params.newInterestAssets),
666
+ new_interest_count: params.newInterestCount.toString(),
667
+ proposal_deadline: params.proposalDeadline.toString(),
668
+ nonce: params.nonce.toString()
669
+ }
670
+ };
671
+ }
672
+ function getCollateralSaleOfferTypedData(params) {
673
+ return {
674
+ types: {
675
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
676
+ CollateralSaleOffer: [
677
+ { name: "inscription_id", type: "u256" },
678
+ { name: "borrower", type: "ContractAddress" },
679
+ { name: "min_price", type: "u256" },
680
+ { name: "payment_token", type: "ContractAddress" },
681
+ { name: "allowed_buyer", type: "ContractAddress" },
682
+ { name: "deadline", type: "u128" },
683
+ { name: "nonce", type: "felt" }
684
+ ],
685
+ u256: U256_TYPE
686
+ },
687
+ primaryType: "CollateralSaleOffer",
688
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
689
+ message: {
690
+ inscription_id: u256Message(params.inscriptionId),
691
+ borrower: params.borrower,
692
+ min_price: u256Message(params.minPrice),
693
+ payment_token: params.paymentToken,
694
+ allowed_buyer: params.allowedBuyer,
695
+ deadline: params.deadline.toString(),
696
+ nonce: params.nonce.toString()
697
+ }
698
+ };
699
+ }
700
+ function getRefinanceOfferTypedData(params) {
701
+ return {
702
+ types: {
703
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
704
+ RefinanceOffer: [
705
+ { name: "inscription_id", type: "u256" },
706
+ { name: "new_lender", type: "ContractAddress" },
707
+ { name: "new_debt_hash", type: "felt" },
708
+ { name: "new_interest_hash", type: "felt" },
709
+ { name: "new_debt_count", type: "u128" },
710
+ { name: "new_interest_count", type: "u128" },
711
+ { name: "new_duration", type: "u128" },
712
+ { name: "deadline", type: "u128" },
713
+ { name: "nonce", type: "felt" }
714
+ ],
715
+ u256: U256_TYPE
716
+ },
717
+ primaryType: "RefinanceOffer",
718
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
719
+ message: {
720
+ inscription_id: u256Message(params.inscriptionId),
721
+ new_lender: params.newLender,
722
+ new_debt_hash: hashAssets(params.newDebtAssets),
723
+ new_interest_hash: hashAssets(params.newInterestAssets),
724
+ new_debt_count: params.newDebtCount.toString(),
725
+ new_interest_count: params.newInterestCount.toString(),
726
+ new_duration: params.newDuration.toString(),
727
+ deadline: params.deadline.toString(),
728
+ nonce: params.nonce.toString()
729
+ }
730
+ };
731
+ }
732
+ function getRefinanceApprovalTypedData(params) {
733
+ return {
734
+ types: {
735
+ StarknetDomain: STARKNET_DOMAIN_TYPE,
736
+ RefinanceApproval: [
737
+ { name: "inscription_id", type: "u256" },
738
+ { name: "offer_hash", type: "felt" },
739
+ { name: "borrower", type: "ContractAddress" },
740
+ { name: "nonce", type: "felt" }
741
+ ],
742
+ u256: U256_TYPE
743
+ },
744
+ primaryType: "RefinanceApproval",
745
+ domain: { ...STELA_DOMAIN, chainId: params.chainId },
746
+ message: {
747
+ inscription_id: u256Message(params.inscriptionId),
748
+ offer_hash: params.offerHash,
749
+ borrower: params.borrower,
750
+ nonce: params.nonce.toString()
751
+ }
752
+ };
753
+ }
571
754
 
572
755
  // src/offchain/signature.ts
573
756
  function serializeSignature(sig) {
@@ -869,6 +1052,210 @@ var stela_default = [
869
1052
  {
870
1053
  name: "collateral_asset_count",
871
1054
  type: "core::integer::u32"
1055
+ },
1056
+ {
1057
+ name: "auction_started",
1058
+ type: "core::bool"
1059
+ },
1060
+ {
1061
+ name: "auction_start_time",
1062
+ type: "core::integer::u64"
1063
+ }
1064
+ ]
1065
+ },
1066
+ {
1067
+ type: "struct",
1068
+ name: "stela::snip12::CollectionLendOffer",
1069
+ members: [
1070
+ {
1071
+ name: "lender",
1072
+ type: "core::starknet::contract_address::ContractAddress"
1073
+ },
1074
+ {
1075
+ name: "debt_hash",
1076
+ type: "core::felt252"
1077
+ },
1078
+ {
1079
+ name: "interest_hash",
1080
+ type: "core::felt252"
1081
+ },
1082
+ {
1083
+ name: "debt_count",
1084
+ type: "core::integer::u32"
1085
+ },
1086
+ {
1087
+ name: "interest_count",
1088
+ type: "core::integer::u32"
1089
+ },
1090
+ {
1091
+ name: "collection_address",
1092
+ type: "core::starknet::contract_address::ContractAddress"
1093
+ },
1094
+ {
1095
+ name: "duration",
1096
+ type: "core::integer::u64"
1097
+ },
1098
+ {
1099
+ name: "deadline",
1100
+ type: "core::integer::u64"
1101
+ },
1102
+ {
1103
+ name: "nonce",
1104
+ type: "core::felt252"
1105
+ }
1106
+ ]
1107
+ },
1108
+ {
1109
+ type: "struct",
1110
+ name: "stela::snip12::CollectionBorrowAcceptance",
1111
+ members: [
1112
+ {
1113
+ name: "offer_hash",
1114
+ type: "core::felt252"
1115
+ },
1116
+ {
1117
+ name: "borrower",
1118
+ type: "core::starknet::contract_address::ContractAddress"
1119
+ },
1120
+ {
1121
+ name: "token_id",
1122
+ type: "core::integer::u256"
1123
+ },
1124
+ {
1125
+ name: "nonce",
1126
+ type: "core::felt252"
1127
+ }
1128
+ ]
1129
+ },
1130
+ {
1131
+ type: "struct",
1132
+ name: "stela::snip12::RenegotiationProposal",
1133
+ members: [
1134
+ {
1135
+ name: "inscription_id",
1136
+ type: "core::integer::u256"
1137
+ },
1138
+ {
1139
+ name: "proposer",
1140
+ type: "core::starknet::contract_address::ContractAddress"
1141
+ },
1142
+ {
1143
+ name: "new_duration",
1144
+ type: "core::integer::u64"
1145
+ },
1146
+ {
1147
+ name: "new_interest_hash",
1148
+ type: "core::felt252"
1149
+ },
1150
+ {
1151
+ name: "new_interest_count",
1152
+ type: "core::integer::u32"
1153
+ },
1154
+ {
1155
+ name: "proposal_deadline",
1156
+ type: "core::integer::u64"
1157
+ },
1158
+ {
1159
+ name: "nonce",
1160
+ type: "core::felt252"
1161
+ }
1162
+ ]
1163
+ },
1164
+ {
1165
+ type: "struct",
1166
+ name: "stela::snip12::CollateralSaleOffer",
1167
+ members: [
1168
+ {
1169
+ name: "inscription_id",
1170
+ type: "core::integer::u256"
1171
+ },
1172
+ {
1173
+ name: "borrower",
1174
+ type: "core::starknet::contract_address::ContractAddress"
1175
+ },
1176
+ {
1177
+ name: "min_price",
1178
+ type: "core::integer::u256"
1179
+ },
1180
+ {
1181
+ name: "payment_token",
1182
+ type: "core::starknet::contract_address::ContractAddress"
1183
+ },
1184
+ {
1185
+ name: "allowed_buyer",
1186
+ type: "core::starknet::contract_address::ContractAddress"
1187
+ },
1188
+ {
1189
+ name: "deadline",
1190
+ type: "core::integer::u64"
1191
+ },
1192
+ {
1193
+ name: "nonce",
1194
+ type: "core::felt252"
1195
+ }
1196
+ ]
1197
+ },
1198
+ {
1199
+ type: "struct",
1200
+ name: "stela::snip12::RefinanceOffer",
1201
+ members: [
1202
+ {
1203
+ name: "inscription_id",
1204
+ type: "core::integer::u256"
1205
+ },
1206
+ {
1207
+ name: "new_lender",
1208
+ type: "core::starknet::contract_address::ContractAddress"
1209
+ },
1210
+ {
1211
+ name: "new_debt_hash",
1212
+ type: "core::felt252"
1213
+ },
1214
+ {
1215
+ name: "new_interest_hash",
1216
+ type: "core::felt252"
1217
+ },
1218
+ {
1219
+ name: "new_debt_count",
1220
+ type: "core::integer::u32"
1221
+ },
1222
+ {
1223
+ name: "new_interest_count",
1224
+ type: "core::integer::u32"
1225
+ },
1226
+ {
1227
+ name: "new_duration",
1228
+ type: "core::integer::u64"
1229
+ },
1230
+ {
1231
+ name: "deadline",
1232
+ type: "core::integer::u64"
1233
+ },
1234
+ {
1235
+ name: "nonce",
1236
+ type: "core::felt252"
1237
+ }
1238
+ ]
1239
+ },
1240
+ {
1241
+ type: "struct",
1242
+ name: "stela::snip12::RefinanceApproval",
1243
+ members: [
1244
+ {
1245
+ name: "inscription_id",
1246
+ type: "core::integer::u256"
1247
+ },
1248
+ {
1249
+ name: "offer_hash",
1250
+ type: "core::felt252"
1251
+ },
1252
+ {
1253
+ name: "borrower",
1254
+ type: "core::starknet::contract_address::ContractAddress"
1255
+ },
1256
+ {
1257
+ name: "nonce",
1258
+ type: "core::felt252"
872
1259
  }
873
1260
  ]
874
1261
  },
@@ -1421,6 +1808,206 @@ var stela_default = [
1421
1808
  ],
1422
1809
  outputs: [],
1423
1810
  state_mutability: "external"
1811
+ },
1812
+ {
1813
+ type: "function",
1814
+ name: "settle_collection",
1815
+ inputs: [
1816
+ {
1817
+ name: "offer",
1818
+ type: "stela::snip12::CollectionLendOffer"
1819
+ },
1820
+ {
1821
+ name: "acceptance",
1822
+ type: "stela::snip12::CollectionBorrowAcceptance"
1823
+ },
1824
+ {
1825
+ name: "debt_assets",
1826
+ type: "core::array::Array::<stela::types::asset::Asset>"
1827
+ },
1828
+ {
1829
+ name: "interest_assets",
1830
+ type: "core::array::Array::<stela::types::asset::Asset>"
1831
+ },
1832
+ {
1833
+ name: "lender_sig",
1834
+ type: "core::array::Array::<core::felt252>"
1835
+ },
1836
+ {
1837
+ name: "borrower_sig",
1838
+ type: "core::array::Array::<core::felt252>"
1839
+ }
1840
+ ],
1841
+ outputs: [],
1842
+ state_mutability: "external"
1843
+ },
1844
+ {
1845
+ type: "function",
1846
+ name: "commit_renegotiation",
1847
+ inputs: [
1848
+ {
1849
+ name: "inscription_id",
1850
+ type: "core::integer::u256"
1851
+ },
1852
+ {
1853
+ name: "proposal_hash",
1854
+ type: "core::felt252"
1855
+ }
1856
+ ],
1857
+ outputs: [],
1858
+ state_mutability: "external"
1859
+ },
1860
+ {
1861
+ type: "function",
1862
+ name: "execute_renegotiation",
1863
+ inputs: [
1864
+ {
1865
+ name: "inscription_id",
1866
+ type: "core::integer::u256"
1867
+ },
1868
+ {
1869
+ name: "proposal",
1870
+ type: "stela::snip12::RenegotiationProposal"
1871
+ },
1872
+ {
1873
+ name: "proposer_sig",
1874
+ type: "core::array::Array::<core::felt252>"
1875
+ },
1876
+ {
1877
+ name: "new_interest_assets",
1878
+ type: "core::array::Array::<stela::types::asset::Asset>"
1879
+ }
1880
+ ],
1881
+ outputs: [],
1882
+ state_mutability: "external"
1883
+ },
1884
+ {
1885
+ type: "function",
1886
+ name: "buy_collateral",
1887
+ inputs: [
1888
+ {
1889
+ name: "inscription_id",
1890
+ type: "core::integer::u256"
1891
+ },
1892
+ {
1893
+ name: "offer",
1894
+ type: "stela::snip12::CollateralSaleOffer"
1895
+ },
1896
+ {
1897
+ name: "borrower_sig",
1898
+ type: "core::array::Array::<core::felt252>"
1899
+ },
1900
+ {
1901
+ name: "sale_price",
1902
+ type: "core::integer::u256"
1903
+ }
1904
+ ],
1905
+ outputs: [],
1906
+ state_mutability: "external"
1907
+ },
1908
+ {
1909
+ type: "function",
1910
+ name: "refinance",
1911
+ inputs: [
1912
+ {
1913
+ name: "offer",
1914
+ type: "stela::snip12::RefinanceOffer"
1915
+ },
1916
+ {
1917
+ name: "new_debt_assets",
1918
+ type: "core::array::Array::<stela::types::asset::Asset>"
1919
+ },
1920
+ {
1921
+ name: "new_interest_assets",
1922
+ type: "core::array::Array::<stela::types::asset::Asset>"
1923
+ },
1924
+ {
1925
+ name: "new_lender_sig",
1926
+ type: "core::array::Array::<core::felt252>"
1927
+ },
1928
+ {
1929
+ name: "approval",
1930
+ type: "stela::snip12::RefinanceApproval"
1931
+ },
1932
+ {
1933
+ name: "borrower_sig",
1934
+ type: "core::array::Array::<core::felt252>"
1935
+ }
1936
+ ],
1937
+ outputs: [],
1938
+ state_mutability: "external"
1939
+ },
1940
+ {
1941
+ type: "function",
1942
+ name: "start_auction",
1943
+ inputs: [
1944
+ {
1945
+ name: "inscription_id",
1946
+ type: "core::integer::u256"
1947
+ }
1948
+ ],
1949
+ outputs: [],
1950
+ state_mutability: "external"
1951
+ },
1952
+ {
1953
+ type: "function",
1954
+ name: "bid",
1955
+ inputs: [
1956
+ {
1957
+ name: "inscription_id",
1958
+ type: "core::integer::u256"
1959
+ }
1960
+ ],
1961
+ outputs: [],
1962
+ state_mutability: "external"
1963
+ },
1964
+ {
1965
+ type: "function",
1966
+ name: "claim_collateral",
1967
+ inputs: [
1968
+ {
1969
+ name: "inscription_id",
1970
+ type: "core::integer::u256"
1971
+ }
1972
+ ],
1973
+ outputs: [],
1974
+ state_mutability: "external"
1975
+ },
1976
+ {
1977
+ type: "function",
1978
+ name: "get_auction_price",
1979
+ inputs: [
1980
+ {
1981
+ name: "inscription_id",
1982
+ type: "core::integer::u256"
1983
+ },
1984
+ {
1985
+ name: "debt_index",
1986
+ type: "core::integer::u32"
1987
+ }
1988
+ ],
1989
+ outputs: [
1990
+ {
1991
+ type: "core::integer::u256"
1992
+ }
1993
+ ],
1994
+ state_mutability: "view"
1995
+ },
1996
+ {
1997
+ type: "function",
1998
+ name: "get_auction_end_time",
1999
+ inputs: [
2000
+ {
2001
+ name: "inscription_id",
2002
+ type: "core::integer::u256"
2003
+ }
2004
+ ],
2005
+ outputs: [
2006
+ {
2007
+ type: "core::integer::u64"
2008
+ }
2009
+ ],
2010
+ state_mutability: "view"
1424
2011
  }
1425
2012
  ]
1426
2013
  },
@@ -2611,6 +3198,155 @@ var InscriptionClient = class {
2611
3198
  calldata: [minNonce]
2612
3199
  };
2613
3200
  }
3201
+ // ── T1 Call Builders ─────────────────────────────────────────────────
3202
+ /** T1-2: Settle a collection-wide lend offer */
3203
+ buildSettleCollection(params) {
3204
+ const calldata = [
3205
+ // CollectionLendOffer struct (9 fields)
3206
+ params.offer.lender,
3207
+ params.offer.debtHash,
3208
+ params.offer.interestHash,
3209
+ String(params.offer.debtCount),
3210
+ String(params.offer.interestCount),
3211
+ params.offer.collectionAddress,
3212
+ params.offer.duration.toString(),
3213
+ params.offer.deadline.toString(),
3214
+ params.offer.nonce.toString(),
3215
+ // CollectionBorrowAcceptance struct (4 fields)
3216
+ params.acceptance.offerHash,
3217
+ params.acceptance.borrower,
3218
+ ...toU256(params.acceptance.tokenId),
3219
+ params.acceptance.nonce.toString(),
3220
+ // debt_assets array
3221
+ ...serializeAssets(params.debtAssets),
3222
+ // interest_assets array
3223
+ ...serializeAssets(params.interestAssets),
3224
+ // lender_sig array
3225
+ String(params.lenderSig.length),
3226
+ ...params.lenderSig,
3227
+ // borrower_sig array
3228
+ String(params.borrowerSig.length),
3229
+ ...params.borrowerSig
3230
+ ];
3231
+ return { contractAddress: this.address, entrypoint: "settle_collection", calldata };
3232
+ }
3233
+ /** T1-4: Commit a renegotiation proposal hash on-chain */
3234
+ buildCommitRenegotiation(inscriptionId, proposalHash) {
3235
+ return {
3236
+ contractAddress: this.address,
3237
+ entrypoint: "commit_renegotiation",
3238
+ calldata: [...toU256(inscriptionId), proposalHash]
3239
+ };
3240
+ }
3241
+ /** T1-4: Execute a committed renegotiation proposal */
3242
+ buildExecuteRenegotiation(params) {
3243
+ const calldata = [
3244
+ ...toU256(params.inscriptionId),
3245
+ // RenegotiationProposal struct (7 fields)
3246
+ ...toU256(params.proposal.inscriptionId),
3247
+ params.proposal.proposer,
3248
+ params.proposal.newDuration.toString(),
3249
+ params.proposal.newInterestHash,
3250
+ String(params.proposal.newInterestCount),
3251
+ params.proposal.proposalDeadline.toString(),
3252
+ params.proposal.nonce.toString(),
3253
+ // proposer_sig array
3254
+ String(params.proposerSig.length),
3255
+ ...params.proposerSig,
3256
+ // new_interest_assets array
3257
+ ...serializeAssets(params.newInterestAssets)
3258
+ ];
3259
+ return { contractAddress: this.address, entrypoint: "execute_renegotiation", calldata };
3260
+ }
3261
+ /** T1-5: Buy collateral from a borrower's sale offer */
3262
+ buildBuyCollateral(params) {
3263
+ const calldata = [
3264
+ ...toU256(params.inscriptionId),
3265
+ // CollateralSaleOffer struct (7 fields)
3266
+ ...toU256(params.offer.inscriptionId),
3267
+ params.offer.borrower,
3268
+ ...toU256(params.offer.minPrice),
3269
+ params.offer.paymentToken,
3270
+ params.offer.allowedBuyer,
3271
+ params.offer.deadline.toString(),
3272
+ params.offer.nonce.toString(),
3273
+ // borrower_sig array
3274
+ String(params.borrowerSig.length),
3275
+ ...params.borrowerSig,
3276
+ // sale_price
3277
+ ...toU256(params.salePrice)
3278
+ ];
3279
+ return { contractAddress: this.address, entrypoint: "buy_collateral", calldata };
3280
+ }
3281
+ /** T1-1: Refinance an existing loan with a new lender */
3282
+ buildRefinance(params) {
3283
+ const calldata = [
3284
+ // RefinanceOffer struct (9 fields)
3285
+ ...toU256(params.offer.inscriptionId),
3286
+ params.offer.newLender,
3287
+ params.offer.newDebtHash,
3288
+ params.offer.newInterestHash,
3289
+ String(params.offer.newDebtCount),
3290
+ String(params.offer.newInterestCount),
3291
+ params.offer.newDuration.toString(),
3292
+ params.offer.deadline.toString(),
3293
+ params.offer.nonce.toString(),
3294
+ // new_debt_assets array
3295
+ ...serializeAssets(params.newDebtAssets),
3296
+ // new_interest_assets array
3297
+ ...serializeAssets(params.newInterestAssets),
3298
+ // new_lender_sig array
3299
+ String(params.newLenderSig.length),
3300
+ ...params.newLenderSig,
3301
+ // RefinanceApproval struct (4 fields)
3302
+ ...toU256(params.approval.inscriptionId),
3303
+ params.approval.offerHash,
3304
+ params.approval.borrower,
3305
+ params.approval.nonce.toString(),
3306
+ // borrower_sig array
3307
+ String(params.borrowerSig.length),
3308
+ ...params.borrowerSig
3309
+ ];
3310
+ return { contractAddress: this.address, entrypoint: "refinance", calldata };
3311
+ }
3312
+ /** T1-3: Start a Dutch auction on an expired, unfilled inscription */
3313
+ buildStartAuction(inscriptionId) {
3314
+ return {
3315
+ contractAddress: this.address,
3316
+ entrypoint: "start_auction",
3317
+ calldata: [...toU256(inscriptionId)]
3318
+ };
3319
+ }
3320
+ /** T1-3: Bid on an active Dutch auction */
3321
+ buildBid(inscriptionId) {
3322
+ return {
3323
+ contractAddress: this.address,
3324
+ entrypoint: "bid",
3325
+ calldata: [...toU256(inscriptionId)]
3326
+ };
3327
+ }
3328
+ /** T1-3: Claim collateral after an auction expires with no bids */
3329
+ buildClaimCollateral(inscriptionId) {
3330
+ return {
3331
+ contractAddress: this.address,
3332
+ entrypoint: "claim_collateral",
3333
+ calldata: [...toU256(inscriptionId)]
3334
+ };
3335
+ }
3336
+ // ── T1 Read Methods ──────────────────────────────────────────────────
3337
+ /** T1-3: Get the current Dutch auction price for a specific debt asset */
3338
+ async getAuctionPrice(inscriptionId, debtIndex) {
3339
+ const result = await this.contract.call("get_auction_price", [
3340
+ ...toU256(inscriptionId),
3341
+ String(debtIndex)
3342
+ ]);
3343
+ return extractU256(result);
3344
+ }
3345
+ /** T1-3: Get the auction end timestamp */
3346
+ async getAuctionEndTime(inscriptionId) {
3347
+ const result = await this.contract.call("get_auction_end_time", toU256(inscriptionId));
3348
+ return BigInt(String(result[0] ?? "0"));
3349
+ }
2614
3350
  // ── Execute Methods ────────────────────────────────────────────────
2615
3351
  /**
2616
3352
  * Execute one or more calls via the connected account.
@@ -2652,6 +3388,35 @@ var InscriptionClient = class {
2652
3388
  async cancelOrdersByNonce(minNonce) {
2653
3389
  return this.execute([this.buildCancelOrdersByNonce(minNonce)]);
2654
3390
  }
3391
+ // ── T1 Execute Methods ───────────────────────────────────────────────
3392
+ async settleCollection(params) {
3393
+ return this.execute([this.buildSettleCollection(params)]);
3394
+ }
3395
+ async commitRenegotiation(inscriptionId, proposalHash) {
3396
+ return this.execute([this.buildCommitRenegotiation(inscriptionId, proposalHash)]);
3397
+ }
3398
+ async executeRenegotiation(params, approvals) {
3399
+ const calls = [...approvals ?? [], this.buildExecuteRenegotiation(params)];
3400
+ return this.execute(calls);
3401
+ }
3402
+ async buyCollateral(params, approvals) {
3403
+ const calls = [...approvals ?? [], this.buildBuyCollateral(params)];
3404
+ return this.execute(calls);
3405
+ }
3406
+ async refinance(params, approvals) {
3407
+ const calls = [...approvals ?? [], this.buildRefinance(params)];
3408
+ return this.execute(calls);
3409
+ }
3410
+ async startAuction(inscriptionId) {
3411
+ return this.execute([this.buildStartAuction(inscriptionId)]);
3412
+ }
3413
+ async bid(inscriptionId, approvals) {
3414
+ const calls = [...approvals ?? [], this.buildBid(inscriptionId)];
3415
+ return this.execute(calls);
3416
+ }
3417
+ async claimCollateral(inscriptionId) {
3418
+ return this.execute([this.buildClaimCollateral(inscriptionId)]);
3419
+ }
2655
3420
  };
2656
3421
  function serializeAssets(assets) {
2657
3422
  const calldata = [String(assets.length)];
@@ -2691,7 +3456,9 @@ function parseStoredInscription(result) {
2691
3456
  multi_lender: Boolean(get("multi_lender", 8)),
2692
3457
  debt_asset_count: Number(get("debt_asset_count", 9)),
2693
3458
  interest_asset_count: Number(get("interest_asset_count", 10)),
2694
- collateral_asset_count: Number(get("collateral_asset_count", 11))
3459
+ collateral_asset_count: Number(get("collateral_asset_count", 11)),
3460
+ auction_started: Boolean(get("auction_started", 12)),
3461
+ auction_start_time: BigInt(String(get("auction_start_time", 13) ?? "0"))
2695
3462
  };
2696
3463
  }
2697
3464
  function extractFieldU256(val) {
@@ -3023,10 +3790,14 @@ var StelaSdk = class {
3023
3790
 
3024
3791
  exports.ASSET_TYPE_ENUM = ASSET_TYPE_ENUM;
3025
3792
  exports.ASSET_TYPE_NAMES = ASSET_TYPE_NAMES;
3793
+ exports.AUCTION_DURATION = AUCTION_DURATION;
3794
+ exports.AUCTION_PENALTY_BPS = AUCTION_PENALTY_BPS;
3795
+ exports.AUCTION_RESERVE_BPS = AUCTION_RESERVE_BPS;
3026
3796
  exports.ApiClient = ApiClient;
3027
3797
  exports.ApiError = ApiError;
3028
3798
  exports.CHAIN_ID = CHAIN_ID;
3029
3799
  exports.EXPLORER_TX_URL = EXPLORER_TX_URL;
3800
+ exports.GRACE_PERIOD = GRACE_PERIOD;
3030
3801
  exports.InscriptionClient = InscriptionClient;
3031
3802
  exports.LockerClient = LockerClient;
3032
3803
  exports.MAX_BPS = MAX_BPS;
@@ -3050,8 +3821,14 @@ exports.formatTimestamp = formatTimestamp;
3050
3821
  exports.formatTokenValue = formatTokenValue;
3051
3822
  exports.fromU256 = fromU256;
3052
3823
  exports.getBatchLendOfferTypedData = getBatchLendOfferTypedData;
3824
+ exports.getCollateralSaleOfferTypedData = getCollateralSaleOfferTypedData;
3825
+ exports.getCollectionBorrowAcceptanceTypedData = getCollectionBorrowAcceptanceTypedData;
3826
+ exports.getCollectionLendOfferTypedData = getCollectionLendOfferTypedData;
3053
3827
  exports.getInscriptionOrderTypedData = getInscriptionOrderTypedData;
3054
3828
  exports.getLendOfferTypedData = getLendOfferTypedData;
3829
+ exports.getRefinanceApprovalTypedData = getRefinanceApprovalTypedData;
3830
+ exports.getRefinanceOfferTypedData = getRefinanceOfferTypedData;
3831
+ exports.getRenegotiationProposalTypedData = getRenegotiationProposalTypedData;
3055
3832
  exports.getTokensForNetwork = getTokensForNetwork;
3056
3833
  exports.hashAssets = hashAssets;
3057
3834
  exports.hashBatchEntries = hashBatchEntries;