@fepvenancio/stela-sdk 0.1.0 → 0.2.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 +351 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -2
- package/dist/index.d.ts +84 -2
- package/dist/index.js +347 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/stela.json +195 -0
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: "0x076ca0af65ad05398076ddc067dc856a43dc1c665dc2898aea6b78dd3e120822",
|
|
28
28
|
mainnet: "0x0"
|
|
29
29
|
};
|
|
30
30
|
var VALID_NETWORKS = ["sepolia", "mainnet"];
|
|
@@ -372,6 +372,114 @@ function parseEvents(rawEvents) {
|
|
|
372
372
|
}
|
|
373
373
|
return results;
|
|
374
374
|
}
|
|
375
|
+
function hashAssets(assets) {
|
|
376
|
+
const elements = [String(assets.length)];
|
|
377
|
+
for (const asset of assets) {
|
|
378
|
+
elements.push(asset.asset_address);
|
|
379
|
+
elements.push(String(ASSET_TYPE_ENUM[asset.asset_type]));
|
|
380
|
+
const [vLow, vHigh] = toU256(asset.value);
|
|
381
|
+
elements.push(vLow, vHigh);
|
|
382
|
+
const [tidLow, tidHigh] = toU256(asset.token_id);
|
|
383
|
+
elements.push(tidLow, tidHigh);
|
|
384
|
+
}
|
|
385
|
+
return starknet.hash.computePoseidonHashOnElements(elements);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/offchain/typed-data.ts
|
|
389
|
+
var STELA_DOMAIN = {
|
|
390
|
+
name: "Stela",
|
|
391
|
+
version: "v1",
|
|
392
|
+
chainId: "",
|
|
393
|
+
// filled at call time
|
|
394
|
+
revision: "1"
|
|
395
|
+
};
|
|
396
|
+
function getInscriptionOrderTypedData(params) {
|
|
397
|
+
return {
|
|
398
|
+
types: {
|
|
399
|
+
StarknetDomain: [
|
|
400
|
+
{ name: "name", type: "shortstring" },
|
|
401
|
+
{ name: "version", type: "shortstring" },
|
|
402
|
+
{ name: "chainId", type: "shortstring" },
|
|
403
|
+
{ name: "revision", type: "shortstring" }
|
|
404
|
+
],
|
|
405
|
+
InscriptionOrder: [
|
|
406
|
+
{ name: "borrower", type: "ContractAddress" },
|
|
407
|
+
{ name: "debt_hash", type: "felt" },
|
|
408
|
+
{ name: "interest_hash", type: "felt" },
|
|
409
|
+
{ name: "collateral_hash", type: "felt" },
|
|
410
|
+
{ name: "debt_count", type: "u128" },
|
|
411
|
+
{ name: "interest_count", type: "u128" },
|
|
412
|
+
{ name: "collateral_count", type: "u128" },
|
|
413
|
+
{ name: "duration", type: "u128" },
|
|
414
|
+
{ name: "deadline", type: "u128" },
|
|
415
|
+
{ name: "multi_lender", type: "bool" },
|
|
416
|
+
{ name: "nonce", type: "felt" }
|
|
417
|
+
]
|
|
418
|
+
},
|
|
419
|
+
primaryType: "InscriptionOrder",
|
|
420
|
+
domain: {
|
|
421
|
+
...STELA_DOMAIN,
|
|
422
|
+
chainId: params.chainId
|
|
423
|
+
},
|
|
424
|
+
message: {
|
|
425
|
+
borrower: params.borrower,
|
|
426
|
+
debt_hash: hashAssets(params.debtAssets),
|
|
427
|
+
interest_hash: hashAssets(params.interestAssets),
|
|
428
|
+
collateral_hash: hashAssets(params.collateralAssets),
|
|
429
|
+
debt_count: params.debtCount.toString(),
|
|
430
|
+
interest_count: params.interestCount.toString(),
|
|
431
|
+
collateral_count: params.collateralCount.toString(),
|
|
432
|
+
duration: params.duration.toString(),
|
|
433
|
+
deadline: params.deadline.toString(),
|
|
434
|
+
multi_lender: params.multiLender,
|
|
435
|
+
nonce: params.nonce.toString()
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
function getLendOfferTypedData(params) {
|
|
440
|
+
return {
|
|
441
|
+
types: {
|
|
442
|
+
StarknetDomain: [
|
|
443
|
+
{ name: "name", type: "shortstring" },
|
|
444
|
+
{ name: "version", type: "shortstring" },
|
|
445
|
+
{ name: "chainId", type: "shortstring" },
|
|
446
|
+
{ name: "revision", type: "shortstring" }
|
|
447
|
+
],
|
|
448
|
+
LendOffer: [
|
|
449
|
+
{ name: "order_hash", type: "felt" },
|
|
450
|
+
{ name: "lender", type: "ContractAddress" },
|
|
451
|
+
{ name: "issued_debt_percentage", type: "u256" },
|
|
452
|
+
{ name: "nonce", type: "felt" }
|
|
453
|
+
],
|
|
454
|
+
u256: [
|
|
455
|
+
{ name: "low", type: "u128" },
|
|
456
|
+
{ name: "high", type: "u128" }
|
|
457
|
+
]
|
|
458
|
+
},
|
|
459
|
+
primaryType: "LendOffer",
|
|
460
|
+
domain: {
|
|
461
|
+
...STELA_DOMAIN,
|
|
462
|
+
chainId: params.chainId
|
|
463
|
+
},
|
|
464
|
+
message: {
|
|
465
|
+
order_hash: params.orderHash,
|
|
466
|
+
lender: params.lender,
|
|
467
|
+
issued_debt_percentage: {
|
|
468
|
+
low: (params.issuedDebtPercentage & (1n << 128n) - 1n).toString(),
|
|
469
|
+
high: (params.issuedDebtPercentage >> 128n).toString()
|
|
470
|
+
},
|
|
471
|
+
nonce: params.nonce.toString()
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// src/offchain/signature.ts
|
|
477
|
+
function serializeSignature(sig) {
|
|
478
|
+
return { r: sig[0], s: sig[1] };
|
|
479
|
+
}
|
|
480
|
+
function deserializeSignature(stored) {
|
|
481
|
+
return [stored.r, stored.s];
|
|
482
|
+
}
|
|
375
483
|
|
|
376
484
|
// src/abi/stela.json
|
|
377
485
|
var stela_default = [
|
|
@@ -486,6 +594,78 @@ var stela_default = [
|
|
|
486
594
|
}
|
|
487
595
|
]
|
|
488
596
|
},
|
|
597
|
+
{
|
|
598
|
+
type: "struct",
|
|
599
|
+
name: "stela::snip12::InscriptionOrder",
|
|
600
|
+
members: [
|
|
601
|
+
{
|
|
602
|
+
name: "borrower",
|
|
603
|
+
type: "core::starknet::contract_address::ContractAddress"
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
name: "debt_hash",
|
|
607
|
+
type: "core::felt252"
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
name: "interest_hash",
|
|
611
|
+
type: "core::felt252"
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
name: "collateral_hash",
|
|
615
|
+
type: "core::felt252"
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
name: "debt_count",
|
|
619
|
+
type: "core::integer::u32"
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
name: "interest_count",
|
|
623
|
+
type: "core::integer::u32"
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
name: "collateral_count",
|
|
627
|
+
type: "core::integer::u32"
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
name: "duration",
|
|
631
|
+
type: "core::integer::u64"
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
name: "deadline",
|
|
635
|
+
type: "core::integer::u64"
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: "multi_lender",
|
|
639
|
+
type: "core::bool"
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
name: "nonce",
|
|
643
|
+
type: "core::felt252"
|
|
644
|
+
}
|
|
645
|
+
]
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
type: "struct",
|
|
649
|
+
name: "stela::snip12::LendOffer",
|
|
650
|
+
members: [
|
|
651
|
+
{
|
|
652
|
+
name: "order_hash",
|
|
653
|
+
type: "core::felt252"
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
name: "lender",
|
|
657
|
+
type: "core::starknet::contract_address::ContractAddress"
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
name: "issued_debt_percentage",
|
|
661
|
+
type: "core::integer::u256"
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
name: "nonce",
|
|
665
|
+
type: "core::felt252"
|
|
666
|
+
}
|
|
667
|
+
]
|
|
668
|
+
},
|
|
489
669
|
{
|
|
490
670
|
type: "struct",
|
|
491
671
|
name: "stela::types::inscription::StoredInscription",
|
|
@@ -628,6 +808,42 @@ var stela_default = [
|
|
|
628
808
|
outputs: [],
|
|
629
809
|
state_mutability: "external"
|
|
630
810
|
},
|
|
811
|
+
{
|
|
812
|
+
type: "function",
|
|
813
|
+
name: "settle",
|
|
814
|
+
inputs: [
|
|
815
|
+
{
|
|
816
|
+
name: "order",
|
|
817
|
+
type: "stela::snip12::InscriptionOrder"
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
name: "debt_assets",
|
|
821
|
+
type: "core::array::Array::<stela::types::asset::Asset>"
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
name: "interest_assets",
|
|
825
|
+
type: "core::array::Array::<stela::types::asset::Asset>"
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
name: "collateral_assets",
|
|
829
|
+
type: "core::array::Array::<stela::types::asset::Asset>"
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
name: "borrower_sig",
|
|
833
|
+
type: "core::array::Array::<core::felt252>"
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
name: "offer",
|
|
837
|
+
type: "stela::snip12::LendOffer"
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
name: "lender_sig",
|
|
841
|
+
type: "core::array::Array::<core::felt252>"
|
|
842
|
+
}
|
|
843
|
+
],
|
|
844
|
+
outputs: [],
|
|
845
|
+
state_mutability: "external"
|
|
846
|
+
},
|
|
631
847
|
{
|
|
632
848
|
type: "function",
|
|
633
849
|
name: "get_inscription",
|
|
@@ -691,6 +907,33 @@ var stela_default = [
|
|
|
691
907
|
],
|
|
692
908
|
state_mutability: "view"
|
|
693
909
|
},
|
|
910
|
+
{
|
|
911
|
+
type: "function",
|
|
912
|
+
name: "nonces",
|
|
913
|
+
inputs: [
|
|
914
|
+
{
|
|
915
|
+
name: "owner",
|
|
916
|
+
type: "core::starknet::contract_address::ContractAddress"
|
|
917
|
+
}
|
|
918
|
+
],
|
|
919
|
+
outputs: [
|
|
920
|
+
{
|
|
921
|
+
type: "core::felt252"
|
|
922
|
+
}
|
|
923
|
+
],
|
|
924
|
+
state_mutability: "view"
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
type: "function",
|
|
928
|
+
name: "get_relayer_fee",
|
|
929
|
+
inputs: [],
|
|
930
|
+
outputs: [
|
|
931
|
+
{
|
|
932
|
+
type: "core::integer::u256"
|
|
933
|
+
}
|
|
934
|
+
],
|
|
935
|
+
state_mutability: "view"
|
|
936
|
+
},
|
|
694
937
|
{
|
|
695
938
|
type: "function",
|
|
696
939
|
name: "set_inscription_fee",
|
|
@@ -738,6 +981,18 @@ var stela_default = [
|
|
|
738
981
|
],
|
|
739
982
|
outputs: [],
|
|
740
983
|
state_mutability: "external"
|
|
984
|
+
},
|
|
985
|
+
{
|
|
986
|
+
type: "function",
|
|
987
|
+
name: "set_relayer_fee",
|
|
988
|
+
inputs: [
|
|
989
|
+
{
|
|
990
|
+
name: "fee",
|
|
991
|
+
type: "core::integer::u256"
|
|
992
|
+
}
|
|
993
|
+
],
|
|
994
|
+
outputs: [],
|
|
995
|
+
state_mutability: "external"
|
|
741
996
|
}
|
|
742
997
|
]
|
|
743
998
|
},
|
|
@@ -1375,6 +1630,12 @@ var stela_default = [
|
|
|
1375
1630
|
kind: "enum",
|
|
1376
1631
|
variants: []
|
|
1377
1632
|
},
|
|
1633
|
+
{
|
|
1634
|
+
type: "event",
|
|
1635
|
+
name: "openzeppelin_utils::cryptography::nonces::NoncesComponent::Event",
|
|
1636
|
+
kind: "enum",
|
|
1637
|
+
variants: []
|
|
1638
|
+
},
|
|
1378
1639
|
{
|
|
1379
1640
|
type: "event",
|
|
1380
1641
|
name: "stela::stela::StelaProtocol::InscriptionCreated",
|
|
@@ -1502,6 +1763,38 @@ var stela_default = [
|
|
|
1502
1763
|
}
|
|
1503
1764
|
]
|
|
1504
1765
|
},
|
|
1766
|
+
{
|
|
1767
|
+
type: "event",
|
|
1768
|
+
name: "stela::stela::StelaProtocol::OrderSettled",
|
|
1769
|
+
kind: "struct",
|
|
1770
|
+
members: [
|
|
1771
|
+
{
|
|
1772
|
+
name: "inscription_id",
|
|
1773
|
+
type: "core::integer::u256",
|
|
1774
|
+
kind: "key"
|
|
1775
|
+
},
|
|
1776
|
+
{
|
|
1777
|
+
name: "borrower",
|
|
1778
|
+
type: "core::starknet::contract_address::ContractAddress",
|
|
1779
|
+
kind: "key"
|
|
1780
|
+
},
|
|
1781
|
+
{
|
|
1782
|
+
name: "lender",
|
|
1783
|
+
type: "core::starknet::contract_address::ContractAddress",
|
|
1784
|
+
kind: "key"
|
|
1785
|
+
},
|
|
1786
|
+
{
|
|
1787
|
+
name: "relayer",
|
|
1788
|
+
type: "core::starknet::contract_address::ContractAddress",
|
|
1789
|
+
kind: "data"
|
|
1790
|
+
},
|
|
1791
|
+
{
|
|
1792
|
+
name: "relayer_fee_amount",
|
|
1793
|
+
type: "core::integer::u256",
|
|
1794
|
+
kind: "data"
|
|
1795
|
+
}
|
|
1796
|
+
]
|
|
1797
|
+
},
|
|
1505
1798
|
{
|
|
1506
1799
|
type: "event",
|
|
1507
1800
|
name: "stela::stela::StelaProtocol::Event",
|
|
@@ -1527,6 +1820,11 @@ var stela_default = [
|
|
|
1527
1820
|
type: "openzeppelin_security::reentrancyguard::ReentrancyGuardComponent::Event",
|
|
1528
1821
|
kind: "flat"
|
|
1529
1822
|
},
|
|
1823
|
+
{
|
|
1824
|
+
name: "NoncesEvent",
|
|
1825
|
+
type: "openzeppelin_utils::cryptography::nonces::NoncesComponent::Event",
|
|
1826
|
+
kind: "flat"
|
|
1827
|
+
},
|
|
1530
1828
|
{
|
|
1531
1829
|
name: "InscriptionCreated",
|
|
1532
1830
|
type: "stela::stela::StelaProtocol::InscriptionCreated",
|
|
@@ -1556,6 +1854,11 @@ var stela_default = [
|
|
|
1556
1854
|
name: "SharesRedeemed",
|
|
1557
1855
|
type: "stela::stela::StelaProtocol::SharesRedeemed",
|
|
1558
1856
|
kind: "nested"
|
|
1857
|
+
},
|
|
1858
|
+
{
|
|
1859
|
+
name: "OrderSettled",
|
|
1860
|
+
type: "stela::stela::StelaProtocol::OrderSettled",
|
|
1861
|
+
kind: "nested"
|
|
1559
1862
|
}
|
|
1560
1863
|
]
|
|
1561
1864
|
}
|
|
@@ -1591,6 +1894,14 @@ var InscriptionClient = class {
|
|
|
1591
1894
|
]);
|
|
1592
1895
|
return extractU256(result);
|
|
1593
1896
|
}
|
|
1897
|
+
async getNonce(address) {
|
|
1898
|
+
const result = await this.contract.call("nonces", [address]);
|
|
1899
|
+
return BigInt(String(result[0] ?? "0"));
|
|
1900
|
+
}
|
|
1901
|
+
async getRelayerFee() {
|
|
1902
|
+
const result = await this.contract.call("get_relayer_fee");
|
|
1903
|
+
return extractU256(result);
|
|
1904
|
+
}
|
|
1594
1905
|
// ── Call Builders ──────────────────────────────────────────────────
|
|
1595
1906
|
buildCreateInscription(params) {
|
|
1596
1907
|
const calldata = [
|
|
@@ -1639,6 +1950,40 @@ var InscriptionClient = class {
|
|
|
1639
1950
|
calldata: [...toU256(inscriptionId), ...toU256(shares)]
|
|
1640
1951
|
};
|
|
1641
1952
|
}
|
|
1953
|
+
buildSettle(params) {
|
|
1954
|
+
const calldata = [
|
|
1955
|
+
// Order struct fields
|
|
1956
|
+
params.order.borrower,
|
|
1957
|
+
params.order.debtHash,
|
|
1958
|
+
params.order.interestHash,
|
|
1959
|
+
params.order.collateralHash,
|
|
1960
|
+
String(params.order.debtCount),
|
|
1961
|
+
String(params.order.interestCount),
|
|
1962
|
+
String(params.order.collateralCount),
|
|
1963
|
+
params.order.duration.toString(),
|
|
1964
|
+
params.order.deadline.toString(),
|
|
1965
|
+
params.order.multiLender ? "1" : "0",
|
|
1966
|
+
params.order.nonce.toString(),
|
|
1967
|
+
// debt_assets array
|
|
1968
|
+
...serializeAssets(params.debtAssets),
|
|
1969
|
+
// interest_assets array
|
|
1970
|
+
...serializeAssets(params.interestAssets),
|
|
1971
|
+
// collateral_assets array
|
|
1972
|
+
...serializeAssets(params.collateralAssets),
|
|
1973
|
+
// borrower_sig array
|
|
1974
|
+
String(params.borrowerSig.length),
|
|
1975
|
+
...params.borrowerSig,
|
|
1976
|
+
// offer struct
|
|
1977
|
+
params.offer.orderHash,
|
|
1978
|
+
params.offer.lender,
|
|
1979
|
+
...toU256(params.offer.issuedDebtPercentage),
|
|
1980
|
+
params.offer.nonce.toString(),
|
|
1981
|
+
// lender_sig array
|
|
1982
|
+
String(params.lenderSig.length),
|
|
1983
|
+
...params.lenderSig
|
|
1984
|
+
];
|
|
1985
|
+
return { contractAddress: this.address, entrypoint: "settle", calldata };
|
|
1986
|
+
}
|
|
1642
1987
|
// ── Execute Methods ────────────────────────────────────────────────
|
|
1643
1988
|
/**
|
|
1644
1989
|
* Execute one or more calls via the connected account.
|
|
@@ -2057,13 +2402,17 @@ exports.addressesEqual = addressesEqual;
|
|
|
2057
2402
|
exports.calculateFeeShares = calculateFeeShares;
|
|
2058
2403
|
exports.computeStatus = computeStatus;
|
|
2059
2404
|
exports.convertToShares = convertToShares;
|
|
2405
|
+
exports.deserializeSignature = deserializeSignature;
|
|
2060
2406
|
exports.findTokenByAddress = findTokenByAddress;
|
|
2061
2407
|
exports.formatAddress = formatAddress;
|
|
2062
2408
|
exports.formatDuration = formatDuration;
|
|
2063
2409
|
exports.formatTimestamp = formatTimestamp;
|
|
2064
2410
|
exports.formatTokenValue = formatTokenValue;
|
|
2065
2411
|
exports.fromU256 = fromU256;
|
|
2412
|
+
exports.getInscriptionOrderTypedData = getInscriptionOrderTypedData;
|
|
2413
|
+
exports.getLendOfferTypedData = getLendOfferTypedData;
|
|
2066
2414
|
exports.getTokensForNetwork = getTokensForNetwork;
|
|
2415
|
+
exports.hashAssets = hashAssets;
|
|
2067
2416
|
exports.inscriptionIdToHex = inscriptionIdToHex;
|
|
2068
2417
|
exports.normalizeAddress = normalizeAddress;
|
|
2069
2418
|
exports.parseAmount = parseAmount;
|
|
@@ -2071,6 +2420,7 @@ exports.parseEvent = parseEvent;
|
|
|
2071
2420
|
exports.parseEvents = parseEvents;
|
|
2072
2421
|
exports.resolveNetwork = resolveNetwork;
|
|
2073
2422
|
exports.scaleByPercentage = scaleByPercentage;
|
|
2423
|
+
exports.serializeSignature = serializeSignature;
|
|
2074
2424
|
exports.sharesToPercentage = sharesToPercentage;
|
|
2075
2425
|
exports.toHex = toHex;
|
|
2076
2426
|
exports.toU256 = toU256;
|