@fepvenancio/stela-sdk 0.7.0 → 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.cjs +438 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +228 -2
- package/dist/index.d.ts +228 -2
- package/dist/index.js +429 -81
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/stela.json +63 -78
package/dist/index.cjs
CHANGED
|
@@ -24,7 +24,7 @@ var STATUS_LABELS = {
|
|
|
24
24
|
|
|
25
25
|
// src/constants/addresses.ts
|
|
26
26
|
var STELA_ADDRESS = {
|
|
27
|
-
sepolia: "
|
|
27
|
+
sepolia: "0x0109c6caae0c5b4da6e063ed6c02ae784be05aa90806501a48dcfbb213bd7c03",
|
|
28
28
|
mainnet: "0x0"
|
|
29
29
|
};
|
|
30
30
|
var VALID_NETWORKS = ["sepolia", "mainnet"];
|
|
@@ -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) {
|
|
@@ -1159,17 +1342,6 @@ var stela_default = [
|
|
|
1159
1342
|
],
|
|
1160
1343
|
state_mutability: "view"
|
|
1161
1344
|
},
|
|
1162
|
-
{
|
|
1163
|
-
type: "function",
|
|
1164
|
-
name: "is_paused",
|
|
1165
|
-
inputs: [],
|
|
1166
|
-
outputs: [
|
|
1167
|
-
{
|
|
1168
|
-
type: "core::bool"
|
|
1169
|
-
}
|
|
1170
|
-
],
|
|
1171
|
-
state_mutability: "view"
|
|
1172
|
-
},
|
|
1173
1345
|
{
|
|
1174
1346
|
type: "function",
|
|
1175
1347
|
name: "is_order_registered",
|
|
@@ -1355,36 +1527,55 @@ var stela_default = [
|
|
|
1355
1527
|
},
|
|
1356
1528
|
{
|
|
1357
1529
|
type: "function",
|
|
1358
|
-
name: "
|
|
1359
|
-
inputs: [
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1530
|
+
name: "set_governance_target",
|
|
1531
|
+
inputs: [
|
|
1532
|
+
{
|
|
1533
|
+
name: "target",
|
|
1534
|
+
type: "core::starknet::contract_address::ContractAddress"
|
|
1535
|
+
},
|
|
1536
|
+
{
|
|
1537
|
+
name: "whitelisted",
|
|
1538
|
+
type: "core::bool"
|
|
1539
|
+
}
|
|
1540
|
+
],
|
|
1367
1541
|
outputs: [],
|
|
1368
1542
|
state_mutability: "external"
|
|
1369
1543
|
},
|
|
1370
1544
|
{
|
|
1371
1545
|
type: "function",
|
|
1372
|
-
name: "
|
|
1373
|
-
inputs: [
|
|
1374
|
-
outputs: [
|
|
1546
|
+
name: "is_governance_target_whitelisted",
|
|
1547
|
+
inputs: [
|
|
1375
1548
|
{
|
|
1549
|
+
name: "target",
|
|
1376
1550
|
type: "core::starknet::contract_address::ContractAddress"
|
|
1377
1551
|
}
|
|
1378
1552
|
],
|
|
1553
|
+
outputs: [
|
|
1554
|
+
{
|
|
1555
|
+
type: "core::bool"
|
|
1556
|
+
}
|
|
1557
|
+
],
|
|
1379
1558
|
state_mutability: "view"
|
|
1380
1559
|
},
|
|
1381
1560
|
{
|
|
1382
1561
|
type: "function",
|
|
1383
|
-
name: "
|
|
1562
|
+
name: "set_locker_allowed_selector",
|
|
1384
1563
|
inputs: [
|
|
1385
1564
|
{
|
|
1386
|
-
name: "
|
|
1565
|
+
name: "locker",
|
|
1566
|
+
type: "core::starknet::contract_address::ContractAddress"
|
|
1567
|
+
},
|
|
1568
|
+
{
|
|
1569
|
+
name: "target",
|
|
1387
1570
|
type: "core::starknet::contract_address::ContractAddress"
|
|
1571
|
+
},
|
|
1572
|
+
{
|
|
1573
|
+
name: "selector",
|
|
1574
|
+
type: "core::felt252"
|
|
1575
|
+
},
|
|
1576
|
+
{
|
|
1577
|
+
name: "allowed",
|
|
1578
|
+
type: "core::bool"
|
|
1388
1579
|
}
|
|
1389
1580
|
],
|
|
1390
1581
|
outputs: [],
|
|
@@ -1392,11 +1583,11 @@ var stela_default = [
|
|
|
1392
1583
|
},
|
|
1393
1584
|
{
|
|
1394
1585
|
type: "function",
|
|
1395
|
-
name: "
|
|
1586
|
+
name: "set_borrower_governance_selector",
|
|
1396
1587
|
inputs: [
|
|
1397
1588
|
{
|
|
1398
|
-
name: "
|
|
1399
|
-
type: "core::
|
|
1589
|
+
name: "inscription_id",
|
|
1590
|
+
type: "core::integer::u256"
|
|
1400
1591
|
},
|
|
1401
1592
|
{
|
|
1402
1593
|
name: "target",
|
|
@@ -1850,10 +2041,6 @@ var stela_default = [
|
|
|
1850
2041
|
{
|
|
1851
2042
|
name: "implementation_hash",
|
|
1852
2043
|
type: "core::felt252"
|
|
1853
|
-
},
|
|
1854
|
-
{
|
|
1855
|
-
name: "pauser",
|
|
1856
|
-
type: "core::starknet::contract_address::ContractAddress"
|
|
1857
2044
|
}
|
|
1858
2045
|
]
|
|
1859
2046
|
},
|
|
@@ -2050,47 +2237,6 @@ var stela_default = [
|
|
|
2050
2237
|
kind: "enum",
|
|
2051
2238
|
variants: []
|
|
2052
2239
|
},
|
|
2053
|
-
{
|
|
2054
|
-
type: "event",
|
|
2055
|
-
name: "openzeppelin_security::pausable::PausableComponent::Paused",
|
|
2056
|
-
kind: "struct",
|
|
2057
|
-
members: [
|
|
2058
|
-
{
|
|
2059
|
-
name: "account",
|
|
2060
|
-
type: "core::starknet::contract_address::ContractAddress",
|
|
2061
|
-
kind: "data"
|
|
2062
|
-
}
|
|
2063
|
-
]
|
|
2064
|
-
},
|
|
2065
|
-
{
|
|
2066
|
-
type: "event",
|
|
2067
|
-
name: "openzeppelin_security::pausable::PausableComponent::Unpaused",
|
|
2068
|
-
kind: "struct",
|
|
2069
|
-
members: [
|
|
2070
|
-
{
|
|
2071
|
-
name: "account",
|
|
2072
|
-
type: "core::starknet::contract_address::ContractAddress",
|
|
2073
|
-
kind: "data"
|
|
2074
|
-
}
|
|
2075
|
-
]
|
|
2076
|
-
},
|
|
2077
|
-
{
|
|
2078
|
-
type: "event",
|
|
2079
|
-
name: "openzeppelin_security::pausable::PausableComponent::Event",
|
|
2080
|
-
kind: "enum",
|
|
2081
|
-
variants: [
|
|
2082
|
-
{
|
|
2083
|
-
name: "Paused",
|
|
2084
|
-
type: "openzeppelin_security::pausable::PausableComponent::Paused",
|
|
2085
|
-
kind: "nested"
|
|
2086
|
-
},
|
|
2087
|
-
{
|
|
2088
|
-
name: "Unpaused",
|
|
2089
|
-
type: "openzeppelin_security::pausable::PausableComponent::Unpaused",
|
|
2090
|
-
kind: "nested"
|
|
2091
|
-
}
|
|
2092
|
-
]
|
|
2093
|
-
},
|
|
2094
2240
|
{
|
|
2095
2241
|
type: "event",
|
|
2096
2242
|
name: "openzeppelin_utils::cryptography::nonces::NoncesComponent::Event",
|
|
@@ -2322,6 +2468,28 @@ var stela_default = [
|
|
|
2322
2468
|
}
|
|
2323
2469
|
]
|
|
2324
2470
|
},
|
|
2471
|
+
{
|
|
2472
|
+
type: "event",
|
|
2473
|
+
name: "stela::stela::StelaProtocol::CollateralReturned",
|
|
2474
|
+
kind: "struct",
|
|
2475
|
+
members: [
|
|
2476
|
+
{
|
|
2477
|
+
name: "inscription_id",
|
|
2478
|
+
type: "core::integer::u256",
|
|
2479
|
+
kind: "key"
|
|
2480
|
+
},
|
|
2481
|
+
{
|
|
2482
|
+
name: "borrower",
|
|
2483
|
+
type: "core::starknet::contract_address::ContractAddress",
|
|
2484
|
+
kind: "data"
|
|
2485
|
+
},
|
|
2486
|
+
{
|
|
2487
|
+
name: "asset_count",
|
|
2488
|
+
type: "core::integer::u32",
|
|
2489
|
+
kind: "data"
|
|
2490
|
+
}
|
|
2491
|
+
]
|
|
2492
|
+
},
|
|
2325
2493
|
{
|
|
2326
2494
|
type: "event",
|
|
2327
2495
|
name: "stela::stela::StelaProtocol::Event",
|
|
@@ -2347,11 +2515,6 @@ var stela_default = [
|
|
|
2347
2515
|
type: "openzeppelin_security::reentrancyguard::ReentrancyGuardComponent::Event",
|
|
2348
2516
|
kind: "flat"
|
|
2349
2517
|
},
|
|
2350
|
-
{
|
|
2351
|
-
name: "PausableEvent",
|
|
2352
|
-
type: "openzeppelin_security::pausable::PausableComponent::Event",
|
|
2353
|
-
kind: "flat"
|
|
2354
|
-
},
|
|
2355
2518
|
{
|
|
2356
2519
|
name: "NoncesEvent",
|
|
2357
2520
|
type: "openzeppelin_utils::cryptography::nonces::NoncesComponent::Event",
|
|
@@ -2406,6 +2569,11 @@ var stela_default = [
|
|
|
2406
2569
|
name: "OrdersBulkCancelled",
|
|
2407
2570
|
type: "stela::stela::StelaProtocol::OrdersBulkCancelled",
|
|
2408
2571
|
kind: "nested"
|
|
2572
|
+
},
|
|
2573
|
+
{
|
|
2574
|
+
name: "CollateralReturned",
|
|
2575
|
+
type: "stela::stela::StelaProtocol::CollateralReturned",
|
|
2576
|
+
kind: "nested"
|
|
2409
2577
|
}
|
|
2410
2578
|
]
|
|
2411
2579
|
}
|
|
@@ -2626,6 +2794,155 @@ var InscriptionClient = class {
|
|
|
2626
2794
|
calldata: [minNonce]
|
|
2627
2795
|
};
|
|
2628
2796
|
}
|
|
2797
|
+
// ── T1 Call Builders ─────────────────────────────────────────────────
|
|
2798
|
+
/** T1-2: Settle a collection-wide lend offer */
|
|
2799
|
+
buildSettleCollection(params) {
|
|
2800
|
+
const calldata = [
|
|
2801
|
+
// CollectionLendOffer struct (9 fields)
|
|
2802
|
+
params.offer.lender,
|
|
2803
|
+
params.offer.debtHash,
|
|
2804
|
+
params.offer.interestHash,
|
|
2805
|
+
String(params.offer.debtCount),
|
|
2806
|
+
String(params.offer.interestCount),
|
|
2807
|
+
params.offer.collectionAddress,
|
|
2808
|
+
params.offer.duration.toString(),
|
|
2809
|
+
params.offer.deadline.toString(),
|
|
2810
|
+
params.offer.nonce.toString(),
|
|
2811
|
+
// CollectionBorrowAcceptance struct (4 fields)
|
|
2812
|
+
params.acceptance.offerHash,
|
|
2813
|
+
params.acceptance.borrower,
|
|
2814
|
+
...toU256(params.acceptance.tokenId),
|
|
2815
|
+
params.acceptance.nonce.toString(),
|
|
2816
|
+
// debt_assets array
|
|
2817
|
+
...serializeAssets(params.debtAssets),
|
|
2818
|
+
// interest_assets array
|
|
2819
|
+
...serializeAssets(params.interestAssets),
|
|
2820
|
+
// lender_sig array
|
|
2821
|
+
String(params.lenderSig.length),
|
|
2822
|
+
...params.lenderSig,
|
|
2823
|
+
// borrower_sig array
|
|
2824
|
+
String(params.borrowerSig.length),
|
|
2825
|
+
...params.borrowerSig
|
|
2826
|
+
];
|
|
2827
|
+
return { contractAddress: this.address, entrypoint: "settle_collection", calldata };
|
|
2828
|
+
}
|
|
2829
|
+
/** T1-4: Commit a renegotiation proposal hash on-chain */
|
|
2830
|
+
buildCommitRenegotiation(inscriptionId, proposalHash) {
|
|
2831
|
+
return {
|
|
2832
|
+
contractAddress: this.address,
|
|
2833
|
+
entrypoint: "commit_renegotiation",
|
|
2834
|
+
calldata: [...toU256(inscriptionId), proposalHash]
|
|
2835
|
+
};
|
|
2836
|
+
}
|
|
2837
|
+
/** T1-4: Execute a committed renegotiation proposal */
|
|
2838
|
+
buildExecuteRenegotiation(params) {
|
|
2839
|
+
const calldata = [
|
|
2840
|
+
...toU256(params.inscriptionId),
|
|
2841
|
+
// RenegotiationProposal struct (7 fields)
|
|
2842
|
+
...toU256(params.proposal.inscriptionId),
|
|
2843
|
+
params.proposal.proposer,
|
|
2844
|
+
params.proposal.newDuration.toString(),
|
|
2845
|
+
params.proposal.newInterestHash,
|
|
2846
|
+
String(params.proposal.newInterestCount),
|
|
2847
|
+
params.proposal.proposalDeadline.toString(),
|
|
2848
|
+
params.proposal.nonce.toString(),
|
|
2849
|
+
// proposer_sig array
|
|
2850
|
+
String(params.proposerSig.length),
|
|
2851
|
+
...params.proposerSig,
|
|
2852
|
+
// new_interest_assets array
|
|
2853
|
+
...serializeAssets(params.newInterestAssets)
|
|
2854
|
+
];
|
|
2855
|
+
return { contractAddress: this.address, entrypoint: "execute_renegotiation", calldata };
|
|
2856
|
+
}
|
|
2857
|
+
/** T1-5: Buy collateral from a borrower's sale offer */
|
|
2858
|
+
buildBuyCollateral(params) {
|
|
2859
|
+
const calldata = [
|
|
2860
|
+
...toU256(params.inscriptionId),
|
|
2861
|
+
// CollateralSaleOffer struct (7 fields)
|
|
2862
|
+
...toU256(params.offer.inscriptionId),
|
|
2863
|
+
params.offer.borrower,
|
|
2864
|
+
...toU256(params.offer.minPrice),
|
|
2865
|
+
params.offer.paymentToken,
|
|
2866
|
+
params.offer.allowedBuyer,
|
|
2867
|
+
params.offer.deadline.toString(),
|
|
2868
|
+
params.offer.nonce.toString(),
|
|
2869
|
+
// borrower_sig array
|
|
2870
|
+
String(params.borrowerSig.length),
|
|
2871
|
+
...params.borrowerSig,
|
|
2872
|
+
// sale_price
|
|
2873
|
+
...toU256(params.salePrice)
|
|
2874
|
+
];
|
|
2875
|
+
return { contractAddress: this.address, entrypoint: "buy_collateral", calldata };
|
|
2876
|
+
}
|
|
2877
|
+
/** T1-1: Refinance an existing loan with a new lender */
|
|
2878
|
+
buildRefinance(params) {
|
|
2879
|
+
const calldata = [
|
|
2880
|
+
// RefinanceOffer struct (9 fields)
|
|
2881
|
+
...toU256(params.offer.inscriptionId),
|
|
2882
|
+
params.offer.newLender,
|
|
2883
|
+
params.offer.newDebtHash,
|
|
2884
|
+
params.offer.newInterestHash,
|
|
2885
|
+
String(params.offer.newDebtCount),
|
|
2886
|
+
String(params.offer.newInterestCount),
|
|
2887
|
+
params.offer.newDuration.toString(),
|
|
2888
|
+
params.offer.deadline.toString(),
|
|
2889
|
+
params.offer.nonce.toString(),
|
|
2890
|
+
// new_debt_assets array
|
|
2891
|
+
...serializeAssets(params.newDebtAssets),
|
|
2892
|
+
// new_interest_assets array
|
|
2893
|
+
...serializeAssets(params.newInterestAssets),
|
|
2894
|
+
// new_lender_sig array
|
|
2895
|
+
String(params.newLenderSig.length),
|
|
2896
|
+
...params.newLenderSig,
|
|
2897
|
+
// RefinanceApproval struct (4 fields)
|
|
2898
|
+
...toU256(params.approval.inscriptionId),
|
|
2899
|
+
params.approval.offerHash,
|
|
2900
|
+
params.approval.borrower,
|
|
2901
|
+
params.approval.nonce.toString(),
|
|
2902
|
+
// borrower_sig array
|
|
2903
|
+
String(params.borrowerSig.length),
|
|
2904
|
+
...params.borrowerSig
|
|
2905
|
+
];
|
|
2906
|
+
return { contractAddress: this.address, entrypoint: "refinance", calldata };
|
|
2907
|
+
}
|
|
2908
|
+
/** T1-3: Start a Dutch auction on an expired, unfilled inscription */
|
|
2909
|
+
buildStartAuction(inscriptionId) {
|
|
2910
|
+
return {
|
|
2911
|
+
contractAddress: this.address,
|
|
2912
|
+
entrypoint: "start_auction",
|
|
2913
|
+
calldata: [...toU256(inscriptionId)]
|
|
2914
|
+
};
|
|
2915
|
+
}
|
|
2916
|
+
/** T1-3: Bid on an active Dutch auction */
|
|
2917
|
+
buildBid(inscriptionId) {
|
|
2918
|
+
return {
|
|
2919
|
+
contractAddress: this.address,
|
|
2920
|
+
entrypoint: "bid",
|
|
2921
|
+
calldata: [...toU256(inscriptionId)]
|
|
2922
|
+
};
|
|
2923
|
+
}
|
|
2924
|
+
/** T1-3: Claim collateral after an auction expires with no bids */
|
|
2925
|
+
buildClaimCollateral(inscriptionId) {
|
|
2926
|
+
return {
|
|
2927
|
+
contractAddress: this.address,
|
|
2928
|
+
entrypoint: "claim_collateral",
|
|
2929
|
+
calldata: [...toU256(inscriptionId)]
|
|
2930
|
+
};
|
|
2931
|
+
}
|
|
2932
|
+
// ── T1 Read Methods ──────────────────────────────────────────────────
|
|
2933
|
+
/** T1-3: Get the current Dutch auction price for a specific debt asset */
|
|
2934
|
+
async getAuctionPrice(inscriptionId, debtIndex) {
|
|
2935
|
+
const result = await this.contract.call("get_auction_price", [
|
|
2936
|
+
...toU256(inscriptionId),
|
|
2937
|
+
String(debtIndex)
|
|
2938
|
+
]);
|
|
2939
|
+
return extractU256(result);
|
|
2940
|
+
}
|
|
2941
|
+
/** T1-3: Get the auction end timestamp */
|
|
2942
|
+
async getAuctionEndTime(inscriptionId) {
|
|
2943
|
+
const result = await this.contract.call("get_auction_end_time", toU256(inscriptionId));
|
|
2944
|
+
return BigInt(String(result[0] ?? "0"));
|
|
2945
|
+
}
|
|
2629
2946
|
// ── Execute Methods ────────────────────────────────────────────────
|
|
2630
2947
|
/**
|
|
2631
2948
|
* Execute one or more calls via the connected account.
|
|
@@ -2667,6 +2984,35 @@ var InscriptionClient = class {
|
|
|
2667
2984
|
async cancelOrdersByNonce(minNonce) {
|
|
2668
2985
|
return this.execute([this.buildCancelOrdersByNonce(minNonce)]);
|
|
2669
2986
|
}
|
|
2987
|
+
// ── T1 Execute Methods ───────────────────────────────────────────────
|
|
2988
|
+
async settleCollection(params) {
|
|
2989
|
+
return this.execute([this.buildSettleCollection(params)]);
|
|
2990
|
+
}
|
|
2991
|
+
async commitRenegotiation(inscriptionId, proposalHash) {
|
|
2992
|
+
return this.execute([this.buildCommitRenegotiation(inscriptionId, proposalHash)]);
|
|
2993
|
+
}
|
|
2994
|
+
async executeRenegotiation(params, approvals) {
|
|
2995
|
+
const calls = [...approvals ?? [], this.buildExecuteRenegotiation(params)];
|
|
2996
|
+
return this.execute(calls);
|
|
2997
|
+
}
|
|
2998
|
+
async buyCollateral(params, approvals) {
|
|
2999
|
+
const calls = [...approvals ?? [], this.buildBuyCollateral(params)];
|
|
3000
|
+
return this.execute(calls);
|
|
3001
|
+
}
|
|
3002
|
+
async refinance(params, approvals) {
|
|
3003
|
+
const calls = [...approvals ?? [], this.buildRefinance(params)];
|
|
3004
|
+
return this.execute(calls);
|
|
3005
|
+
}
|
|
3006
|
+
async startAuction(inscriptionId) {
|
|
3007
|
+
return this.execute([this.buildStartAuction(inscriptionId)]);
|
|
3008
|
+
}
|
|
3009
|
+
async bid(inscriptionId, approvals) {
|
|
3010
|
+
const calls = [...approvals ?? [], this.buildBid(inscriptionId)];
|
|
3011
|
+
return this.execute(calls);
|
|
3012
|
+
}
|
|
3013
|
+
async claimCollateral(inscriptionId) {
|
|
3014
|
+
return this.execute([this.buildClaimCollateral(inscriptionId)]);
|
|
3015
|
+
}
|
|
2670
3016
|
};
|
|
2671
3017
|
function serializeAssets(assets) {
|
|
2672
3018
|
const calldata = [String(assets.length)];
|
|
@@ -2706,7 +3052,9 @@ function parseStoredInscription(result) {
|
|
|
2706
3052
|
multi_lender: Boolean(get("multi_lender", 8)),
|
|
2707
3053
|
debt_asset_count: Number(get("debt_asset_count", 9)),
|
|
2708
3054
|
interest_asset_count: Number(get("interest_asset_count", 10)),
|
|
2709
|
-
collateral_asset_count: Number(get("collateral_asset_count", 11))
|
|
3055
|
+
collateral_asset_count: Number(get("collateral_asset_count", 11)),
|
|
3056
|
+
auction_started: Boolean(get("auction_started", 12)),
|
|
3057
|
+
auction_start_time: BigInt(String(get("auction_start_time", 13) ?? "0"))
|
|
2710
3058
|
};
|
|
2711
3059
|
}
|
|
2712
3060
|
function extractFieldU256(val) {
|
|
@@ -3038,10 +3386,14 @@ var StelaSdk = class {
|
|
|
3038
3386
|
|
|
3039
3387
|
exports.ASSET_TYPE_ENUM = ASSET_TYPE_ENUM;
|
|
3040
3388
|
exports.ASSET_TYPE_NAMES = ASSET_TYPE_NAMES;
|
|
3389
|
+
exports.AUCTION_DURATION = AUCTION_DURATION;
|
|
3390
|
+
exports.AUCTION_PENALTY_BPS = AUCTION_PENALTY_BPS;
|
|
3391
|
+
exports.AUCTION_RESERVE_BPS = AUCTION_RESERVE_BPS;
|
|
3041
3392
|
exports.ApiClient = ApiClient;
|
|
3042
3393
|
exports.ApiError = ApiError;
|
|
3043
3394
|
exports.CHAIN_ID = CHAIN_ID;
|
|
3044
3395
|
exports.EXPLORER_TX_URL = EXPLORER_TX_URL;
|
|
3396
|
+
exports.GRACE_PERIOD = GRACE_PERIOD;
|
|
3045
3397
|
exports.InscriptionClient = InscriptionClient;
|
|
3046
3398
|
exports.LockerClient = LockerClient;
|
|
3047
3399
|
exports.MAX_BPS = MAX_BPS;
|
|
@@ -3065,8 +3417,14 @@ exports.formatTimestamp = formatTimestamp;
|
|
|
3065
3417
|
exports.formatTokenValue = formatTokenValue;
|
|
3066
3418
|
exports.fromU256 = fromU256;
|
|
3067
3419
|
exports.getBatchLendOfferTypedData = getBatchLendOfferTypedData;
|
|
3420
|
+
exports.getCollateralSaleOfferTypedData = getCollateralSaleOfferTypedData;
|
|
3421
|
+
exports.getCollectionBorrowAcceptanceTypedData = getCollectionBorrowAcceptanceTypedData;
|
|
3422
|
+
exports.getCollectionLendOfferTypedData = getCollectionLendOfferTypedData;
|
|
3068
3423
|
exports.getInscriptionOrderTypedData = getInscriptionOrderTypedData;
|
|
3069
3424
|
exports.getLendOfferTypedData = getLendOfferTypedData;
|
|
3425
|
+
exports.getRefinanceApprovalTypedData = getRefinanceApprovalTypedData;
|
|
3426
|
+
exports.getRefinanceOfferTypedData = getRefinanceOfferTypedData;
|
|
3427
|
+
exports.getRenegotiationProposalTypedData = getRenegotiationProposalTypedData;
|
|
3070
3428
|
exports.getTokensForNetwork = getTokensForNetwork;
|
|
3071
3429
|
exports.hashAssets = hashAssets;
|
|
3072
3430
|
exports.hashBatchEntries = hashBatchEntries;
|