@fepvenancio/stela-sdk 0.4.3 → 0.5.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/README.md +29 -52
- package/dist/index.cjs +46 -265
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -158
- package/dist/index.d.ts +2 -158
- package/dist/index.js +48 -260
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/stela.json +44 -145
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hash,
|
|
1
|
+
import { hash, uint256, addAddressPadding, validateAndParseAddress, Contract } from 'starknet';
|
|
2
2
|
|
|
3
3
|
// src/types/common.ts
|
|
4
4
|
var VALID_STATUSES = [
|
|
@@ -22,7 +22,7 @@ var STATUS_LABELS = {
|
|
|
22
22
|
|
|
23
23
|
// src/constants/addresses.ts
|
|
24
24
|
var STELA_ADDRESS = {
|
|
25
|
-
sepolia: "
|
|
25
|
+
sepolia: "0x042f27b5cf82781d8fffd7daeec9184ac4f14c9e86e87b880bd81ef5197345ed",
|
|
26
26
|
mainnet: "0x0"
|
|
27
27
|
};
|
|
28
28
|
var VALID_NETWORKS = ["sepolia", "mainnet"];
|
|
@@ -490,16 +490,6 @@ function getInscriptionOrderTypedData(params) {
|
|
|
490
490
|
}
|
|
491
491
|
};
|
|
492
492
|
}
|
|
493
|
-
function getPrivateLendOfferTypedData(params) {
|
|
494
|
-
return getLendOfferTypedData({
|
|
495
|
-
orderHash: params.orderHash,
|
|
496
|
-
lender: "0x0",
|
|
497
|
-
issuedDebtPercentage: params.issuedDebtPercentage,
|
|
498
|
-
nonce: params.nonce,
|
|
499
|
-
chainId: params.chainId,
|
|
500
|
-
lenderCommitment: params.depositCommitment
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
493
|
function getLendOfferTypedData(params) {
|
|
504
494
|
return {
|
|
505
495
|
types: {
|
|
@@ -513,8 +503,7 @@ function getLendOfferTypedData(params) {
|
|
|
513
503
|
{ name: "order_hash", type: "felt" },
|
|
514
504
|
{ name: "lender", type: "ContractAddress" },
|
|
515
505
|
{ name: "issued_debt_percentage", type: "u256" },
|
|
516
|
-
{ name: "nonce", type: "felt" }
|
|
517
|
-
{ name: "lender_commitment", type: "felt" }
|
|
506
|
+
{ name: "nonce", type: "felt" }
|
|
518
507
|
],
|
|
519
508
|
u256: [
|
|
520
509
|
{ name: "low", type: "u128" },
|
|
@@ -533,8 +522,7 @@ function getLendOfferTypedData(params) {
|
|
|
533
522
|
low: (params.issuedDebtPercentage & (1n << 128n) - 1n).toString(),
|
|
534
523
|
high: (params.issuedDebtPercentage >> 128n).toString()
|
|
535
524
|
},
|
|
536
|
-
nonce: params.nonce.toString()
|
|
537
|
-
lender_commitment: params.lenderCommitment ?? "0"
|
|
525
|
+
nonce: params.nonce.toString()
|
|
538
526
|
}
|
|
539
527
|
};
|
|
540
528
|
}
|
|
@@ -546,54 +534,6 @@ function serializeSignature(sig) {
|
|
|
546
534
|
function deserializeSignature(stored) {
|
|
547
535
|
return [stored.r, stored.s];
|
|
548
536
|
}
|
|
549
|
-
var COMMITMENT_DOMAIN = shortString.encodeShortString("STELA_COMMITMENT_V1");
|
|
550
|
-
var NULLIFIER_DOMAIN = shortString.encodeShortString("STELA_NULLIFIER_V1");
|
|
551
|
-
function computeCommitment(owner, inscriptionId, shares, salt) {
|
|
552
|
-
const [idLow, idHigh] = toU256(inscriptionId);
|
|
553
|
-
const [sharesLow, sharesHigh] = toU256(shares);
|
|
554
|
-
return hash.computePoseidonHashOnElements([
|
|
555
|
-
COMMITMENT_DOMAIN,
|
|
556
|
-
owner,
|
|
557
|
-
idLow,
|
|
558
|
-
idHigh,
|
|
559
|
-
sharesLow,
|
|
560
|
-
sharesHigh,
|
|
561
|
-
salt
|
|
562
|
-
]);
|
|
563
|
-
}
|
|
564
|
-
function computeNullifier(commitment, ownerSecret) {
|
|
565
|
-
return hash.computePoseidonHashOnElements([NULLIFIER_DOMAIN, commitment, ownerSecret]);
|
|
566
|
-
}
|
|
567
|
-
function hashPair(left, right) {
|
|
568
|
-
return hash.computePoseidonHashOnElements([left, right]);
|
|
569
|
-
}
|
|
570
|
-
function generateSalt() {
|
|
571
|
-
const bytes = new Uint8Array(31);
|
|
572
|
-
crypto.getRandomValues(bytes);
|
|
573
|
-
return "0x" + Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
574
|
-
}
|
|
575
|
-
function computeDepositCommitment(depositor, token, amount, salt) {
|
|
576
|
-
const [amountLow, amountHigh] = toU256(amount);
|
|
577
|
-
return hash.computePoseidonHashOnElements([
|
|
578
|
-
COMMITMENT_DOMAIN,
|
|
579
|
-
depositor,
|
|
580
|
-
token,
|
|
581
|
-
amountLow,
|
|
582
|
-
amountHigh,
|
|
583
|
-
"0x" + salt.toString(16)
|
|
584
|
-
]);
|
|
585
|
-
}
|
|
586
|
-
function createPrivateNote(owner, inscriptionId, shares, salt) {
|
|
587
|
-
const noteSalt = salt ?? generateSalt();
|
|
588
|
-
const commitment = computeCommitment(owner, inscriptionId, shares, noteSalt);
|
|
589
|
-
return {
|
|
590
|
-
owner,
|
|
591
|
-
inscriptionId,
|
|
592
|
-
shares,
|
|
593
|
-
salt: noteSalt,
|
|
594
|
-
commitment
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
537
|
|
|
598
538
|
// src/abi/stela.json
|
|
599
539
|
var stela_default = [
|
|
@@ -708,46 +648,6 @@ var stela_default = [
|
|
|
708
648
|
}
|
|
709
649
|
]
|
|
710
650
|
},
|
|
711
|
-
{
|
|
712
|
-
type: "struct",
|
|
713
|
-
name: "stela::types::private_redeem::PrivateRedeemRequest",
|
|
714
|
-
members: [
|
|
715
|
-
{
|
|
716
|
-
name: "root",
|
|
717
|
-
type: "core::felt252"
|
|
718
|
-
},
|
|
719
|
-
{
|
|
720
|
-
name: "inscription_id",
|
|
721
|
-
type: "core::integer::u256"
|
|
722
|
-
},
|
|
723
|
-
{
|
|
724
|
-
name: "shares",
|
|
725
|
-
type: "core::integer::u256"
|
|
726
|
-
},
|
|
727
|
-
{
|
|
728
|
-
name: "nullifier",
|
|
729
|
-
type: "core::felt252"
|
|
730
|
-
},
|
|
731
|
-
{
|
|
732
|
-
name: "change_commitment",
|
|
733
|
-
type: "core::felt252"
|
|
734
|
-
},
|
|
735
|
-
{
|
|
736
|
-
name: "recipient",
|
|
737
|
-
type: "core::starknet::contract_address::ContractAddress"
|
|
738
|
-
}
|
|
739
|
-
]
|
|
740
|
-
},
|
|
741
|
-
{
|
|
742
|
-
type: "struct",
|
|
743
|
-
name: "core::array::Span::<core::felt252>",
|
|
744
|
-
members: [
|
|
745
|
-
{
|
|
746
|
-
name: "snapshot",
|
|
747
|
-
type: "@core::array::Array::<core::felt252>"
|
|
748
|
-
}
|
|
749
|
-
]
|
|
750
|
-
},
|
|
751
651
|
{
|
|
752
652
|
type: "struct",
|
|
753
653
|
name: "stela::snip12::InscriptionOrder",
|
|
@@ -817,10 +717,6 @@ var stela_default = [
|
|
|
817
717
|
{
|
|
818
718
|
name: "nonce",
|
|
819
719
|
type: "core::felt252"
|
|
820
|
-
},
|
|
821
|
-
{
|
|
822
|
-
name: "lender_commitment",
|
|
823
|
-
type: "core::felt252"
|
|
824
720
|
}
|
|
825
721
|
]
|
|
826
722
|
},
|
|
@@ -1000,22 +896,6 @@ var stela_default = [
|
|
|
1000
896
|
outputs: [],
|
|
1001
897
|
state_mutability: "external"
|
|
1002
898
|
},
|
|
1003
|
-
{
|
|
1004
|
-
type: "function",
|
|
1005
|
-
name: "private_redeem",
|
|
1006
|
-
inputs: [
|
|
1007
|
-
{
|
|
1008
|
-
name: "request",
|
|
1009
|
-
type: "stela::types::private_redeem::PrivateRedeemRequest"
|
|
1010
|
-
},
|
|
1011
|
-
{
|
|
1012
|
-
name: "proof",
|
|
1013
|
-
type: "core::array::Span::<core::felt252>"
|
|
1014
|
-
}
|
|
1015
|
-
],
|
|
1016
|
-
outputs: [],
|
|
1017
|
-
state_mutability: "external"
|
|
1018
|
-
},
|
|
1019
899
|
{
|
|
1020
900
|
type: "function",
|
|
1021
901
|
name: "settle",
|
|
@@ -1274,7 +1154,7 @@ var stela_default = [
|
|
|
1274
1154
|
},
|
|
1275
1155
|
{
|
|
1276
1156
|
type: "function",
|
|
1277
|
-
name: "
|
|
1157
|
+
name: "get_genesis_contract",
|
|
1278
1158
|
inputs: [],
|
|
1279
1159
|
outputs: [
|
|
1280
1160
|
{
|
|
@@ -1283,6 +1163,22 @@ var stela_default = [
|
|
|
1283
1163
|
],
|
|
1284
1164
|
state_mutability: "view"
|
|
1285
1165
|
},
|
|
1166
|
+
{
|
|
1167
|
+
type: "function",
|
|
1168
|
+
name: "get_volume_settled",
|
|
1169
|
+
inputs: [
|
|
1170
|
+
{
|
|
1171
|
+
name: "user",
|
|
1172
|
+
type: "core::starknet::contract_address::ContractAddress"
|
|
1173
|
+
}
|
|
1174
|
+
],
|
|
1175
|
+
outputs: [
|
|
1176
|
+
{
|
|
1177
|
+
type: "core::integer::u256"
|
|
1178
|
+
}
|
|
1179
|
+
],
|
|
1180
|
+
state_mutability: "view"
|
|
1181
|
+
},
|
|
1286
1182
|
{
|
|
1287
1183
|
type: "function",
|
|
1288
1184
|
name: "set_inscription_fee",
|
|
@@ -1357,10 +1253,10 @@ var stela_default = [
|
|
|
1357
1253
|
},
|
|
1358
1254
|
{
|
|
1359
1255
|
type: "function",
|
|
1360
|
-
name: "
|
|
1256
|
+
name: "set_genesis_contract",
|
|
1361
1257
|
inputs: [
|
|
1362
1258
|
{
|
|
1363
|
-
name: "
|
|
1259
|
+
name: "genesis_contract",
|
|
1364
1260
|
type: "core::starknet::contract_address::ContractAddress"
|
|
1365
1261
|
}
|
|
1366
1262
|
],
|
|
@@ -1369,40 +1265,28 @@ var stela_default = [
|
|
|
1369
1265
|
},
|
|
1370
1266
|
{
|
|
1371
1267
|
type: "function",
|
|
1372
|
-
name: "
|
|
1373
|
-
inputs: [
|
|
1374
|
-
{
|
|
1375
|
-
name: "fee_vault",
|
|
1376
|
-
type: "core::starknet::contract_address::ContractAddress"
|
|
1377
|
-
}
|
|
1378
|
-
],
|
|
1268
|
+
name: "pause",
|
|
1269
|
+
inputs: [],
|
|
1379
1270
|
outputs: [],
|
|
1380
1271
|
state_mutability: "external"
|
|
1381
1272
|
},
|
|
1382
1273
|
{
|
|
1383
1274
|
type: "function",
|
|
1384
|
-
name: "
|
|
1385
|
-
inputs: [],
|
|
1386
|
-
outputs: [
|
|
1387
|
-
{
|
|
1388
|
-
type: "core::starknet::contract_address::ContractAddress"
|
|
1389
|
-
}
|
|
1390
|
-
],
|
|
1391
|
-
state_mutability: "view"
|
|
1392
|
-
},
|
|
1393
|
-
{
|
|
1394
|
-
type: "function",
|
|
1395
|
-
name: "pause",
|
|
1275
|
+
name: "unpause",
|
|
1396
1276
|
inputs: [],
|
|
1397
1277
|
outputs: [],
|
|
1398
1278
|
state_mutability: "external"
|
|
1399
1279
|
},
|
|
1400
1280
|
{
|
|
1401
1281
|
type: "function",
|
|
1402
|
-
name: "
|
|
1282
|
+
name: "get_pauser",
|
|
1403
1283
|
inputs: [],
|
|
1404
|
-
outputs: [
|
|
1405
|
-
|
|
1284
|
+
outputs: [
|
|
1285
|
+
{
|
|
1286
|
+
type: "core::starknet::contract_address::ContractAddress"
|
|
1287
|
+
}
|
|
1288
|
+
],
|
|
1289
|
+
state_mutability: "view"
|
|
1406
1290
|
},
|
|
1407
1291
|
{
|
|
1408
1292
|
type: "function",
|
|
@@ -1451,6 +1335,16 @@ var stela_default = [
|
|
|
1451
1335
|
}
|
|
1452
1336
|
]
|
|
1453
1337
|
},
|
|
1338
|
+
{
|
|
1339
|
+
type: "struct",
|
|
1340
|
+
name: "core::array::Span::<core::felt252>",
|
|
1341
|
+
members: [
|
|
1342
|
+
{
|
|
1343
|
+
name: "snapshot",
|
|
1344
|
+
type: "@core::array::Array::<core::felt252>"
|
|
1345
|
+
}
|
|
1346
|
+
]
|
|
1347
|
+
},
|
|
1454
1348
|
{
|
|
1455
1349
|
type: "struct",
|
|
1456
1350
|
name: "core::byte_array::ByteArray",
|
|
@@ -1850,6 +1744,10 @@ var stela_default = [
|
|
|
1850
1744
|
{
|
|
1851
1745
|
name: "implementation_hash",
|
|
1852
1746
|
type: "core::felt252"
|
|
1747
|
+
},
|
|
1748
|
+
{
|
|
1749
|
+
name: "pauser",
|
|
1750
|
+
type: "core::starknet::contract_address::ContractAddress"
|
|
1853
1751
|
}
|
|
1854
1752
|
]
|
|
1855
1753
|
},
|
|
@@ -2318,55 +2216,6 @@ var stela_default = [
|
|
|
2318
2216
|
}
|
|
2319
2217
|
]
|
|
2320
2218
|
},
|
|
2321
|
-
{
|
|
2322
|
-
type: "event",
|
|
2323
|
-
name: "stela::stela::StelaProtocol::PrivateSettled",
|
|
2324
|
-
kind: "struct",
|
|
2325
|
-
members: [
|
|
2326
|
-
{
|
|
2327
|
-
name: "inscription_id",
|
|
2328
|
-
type: "core::integer::u256",
|
|
2329
|
-
kind: "key"
|
|
2330
|
-
},
|
|
2331
|
-
{
|
|
2332
|
-
name: "lender_commitment",
|
|
2333
|
-
type: "core::felt252",
|
|
2334
|
-
kind: "key"
|
|
2335
|
-
},
|
|
2336
|
-
{
|
|
2337
|
-
name: "shares_committed",
|
|
2338
|
-
type: "core::integer::u256",
|
|
2339
|
-
kind: "data"
|
|
2340
|
-
}
|
|
2341
|
-
]
|
|
2342
|
-
},
|
|
2343
|
-
{
|
|
2344
|
-
type: "event",
|
|
2345
|
-
name: "stela::stela::StelaProtocol::PrivateSharesRedeemed",
|
|
2346
|
-
kind: "struct",
|
|
2347
|
-
members: [
|
|
2348
|
-
{
|
|
2349
|
-
name: "inscription_id",
|
|
2350
|
-
type: "core::integer::u256",
|
|
2351
|
-
kind: "key"
|
|
2352
|
-
},
|
|
2353
|
-
{
|
|
2354
|
-
name: "nullifier",
|
|
2355
|
-
type: "core::felt252",
|
|
2356
|
-
kind: "key"
|
|
2357
|
-
},
|
|
2358
|
-
{
|
|
2359
|
-
name: "shares",
|
|
2360
|
-
type: "core::integer::u256",
|
|
2361
|
-
kind: "data"
|
|
2362
|
-
},
|
|
2363
|
-
{
|
|
2364
|
-
name: "recipient",
|
|
2365
|
-
type: "core::starknet::contract_address::ContractAddress",
|
|
2366
|
-
kind: "data"
|
|
2367
|
-
}
|
|
2368
|
-
]
|
|
2369
|
-
},
|
|
2370
2219
|
{
|
|
2371
2220
|
type: "event",
|
|
2372
2221
|
name: "stela::stela::StelaProtocol::Event",
|
|
@@ -2451,16 +2300,6 @@ var stela_default = [
|
|
|
2451
2300
|
name: "OrdersBulkCancelled",
|
|
2452
2301
|
type: "stela::stela::StelaProtocol::OrdersBulkCancelled",
|
|
2453
2302
|
kind: "nested"
|
|
2454
|
-
},
|
|
2455
|
-
{
|
|
2456
|
-
name: "PrivateSettled",
|
|
2457
|
-
type: "stela::stela::StelaProtocol::PrivateSettled",
|
|
2458
|
-
kind: "nested"
|
|
2459
|
-
},
|
|
2460
|
-
{
|
|
2461
|
-
name: "PrivateSharesRedeemed",
|
|
2462
|
-
type: "stela::stela::StelaProtocol::PrivateSharesRedeemed",
|
|
2463
|
-
kind: "nested"
|
|
2464
2303
|
}
|
|
2465
2304
|
]
|
|
2466
2305
|
}
|
|
@@ -2576,53 +2415,6 @@ var InscriptionClient = class {
|
|
|
2576
2415
|
calldata: [...toU256(inscriptionId), ...toU256(shares)]
|
|
2577
2416
|
};
|
|
2578
2417
|
}
|
|
2579
|
-
buildPrivateRedeem(request, proof) {
|
|
2580
|
-
const calldata = [
|
|
2581
|
-
// PrivateRedeemRequest struct fields (must match Cairo Serde order)
|
|
2582
|
-
request.root,
|
|
2583
|
-
...toU256(request.inscriptionId),
|
|
2584
|
-
...toU256(request.shares),
|
|
2585
|
-
request.nullifier,
|
|
2586
|
-
request.changeCommitment,
|
|
2587
|
-
request.recipient,
|
|
2588
|
-
// proof array
|
|
2589
|
-
String(proof.length),
|
|
2590
|
-
...proof
|
|
2591
|
-
];
|
|
2592
|
-
return { contractAddress: this.address, entrypoint: "private_redeem", calldata };
|
|
2593
|
-
}
|
|
2594
|
-
/**
|
|
2595
|
-
* Build a shield() call on the privacy pool contract.
|
|
2596
|
-
* The depositor shields tokens into the pool, creating a commitment that can
|
|
2597
|
-
* later be consumed during private settlement.
|
|
2598
|
-
*/
|
|
2599
|
-
buildShieldDeposit(params) {
|
|
2600
|
-
return {
|
|
2601
|
-
contractAddress: params.privacyPoolAddress,
|
|
2602
|
-
entrypoint: "shield",
|
|
2603
|
-
calldata: [
|
|
2604
|
-
params.token,
|
|
2605
|
-
...toU256(params.amount),
|
|
2606
|
-
params.commitment
|
|
2607
|
-
]
|
|
2608
|
-
};
|
|
2609
|
-
}
|
|
2610
|
-
/**
|
|
2611
|
-
* Build a settle() call for private settlement.
|
|
2612
|
-
*
|
|
2613
|
-
* In a private settlement, the lender is zero address and the lender_commitment
|
|
2614
|
-
* is the deposit commitment from the privacy pool. The contract skips lender
|
|
2615
|
-
* signature verification and instead consumes the deposit from the privacy pool.
|
|
2616
|
-
*/
|
|
2617
|
-
buildSettlePrivate(params) {
|
|
2618
|
-
return this.buildSettle({
|
|
2619
|
-
...params,
|
|
2620
|
-
offer: {
|
|
2621
|
-
...params.offer,
|
|
2622
|
-
lender: "0x0"
|
|
2623
|
-
}
|
|
2624
|
-
});
|
|
2625
|
-
}
|
|
2626
2418
|
buildSettle(params) {
|
|
2627
2419
|
const calldata = [
|
|
2628
2420
|
// Order struct fields
|
|
@@ -2651,7 +2443,6 @@ var InscriptionClient = class {
|
|
|
2651
2443
|
params.offer.lender,
|
|
2652
2444
|
...toU256(params.offer.issuedDebtPercentage),
|
|
2653
2445
|
params.offer.nonce.toString(),
|
|
2654
|
-
params.offer.lenderCommitment ?? "0",
|
|
2655
2446
|
// lender_sig array
|
|
2656
2447
|
String(params.lenderSig.length),
|
|
2657
2448
|
...params.lenderSig
|
|
@@ -2726,9 +2517,6 @@ var InscriptionClient = class {
|
|
|
2726
2517
|
async redeem(inscriptionId, shares) {
|
|
2727
2518
|
return this.execute([this.buildRedeem(inscriptionId, shares)]);
|
|
2728
2519
|
}
|
|
2729
|
-
async privateRedeem(request, proof) {
|
|
2730
|
-
return this.execute([this.buildPrivateRedeem(request, proof)]);
|
|
2731
|
-
}
|
|
2732
2520
|
async fillSignedOrder(order, signature, fillBps, approvals) {
|
|
2733
2521
|
const calls = [...approvals ?? [], this.buildFillSignedOrder(order, signature, fillBps)];
|
|
2734
2522
|
return this.execute(calls);
|
|
@@ -3108,6 +2896,6 @@ var StelaSdk = class {
|
|
|
3108
2896
|
}
|
|
3109
2897
|
};
|
|
3110
2898
|
|
|
3111
|
-
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,
|
|
2899
|
+
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, getInscriptionOrderTypedData, getLendOfferTypedData, getTokensForNetwork, hashAssets, inscriptionIdToHex, normalizeAddress, parseAmount, parseEvent, parseEvents, resolveNetwork, scaleByPercentage, serializeSignature, sharesToPercentage, toHex, toU256 };
|
|
3112
2900
|
//# sourceMappingURL=index.js.map
|
|
3113
2901
|
//# sourceMappingURL=index.js.map
|