@fepvenancio/stela-sdk 0.5.4 → 0.6.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 +7 -1
- package/dist/index.cjs +143 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -1
- package/dist/index.d.ts +50 -1
- package/dist/index.js +142 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/stela.json +62 -0
package/README.md
CHANGED
|
@@ -118,6 +118,7 @@ Return a `Call` object for use with `account.execute()`. Bundle multiple calls (
|
|
|
118
118
|
| `buildLiquidate(id)` | Liquidate an expired inscription |
|
|
119
119
|
| `buildRedeem(id, shares)` | Redeem shares for underlying assets |
|
|
120
120
|
| `buildSettle(params)` | Settle an off-chain order (used by relayer bots) |
|
|
121
|
+
| `buildBatchSettle(params)` | Settle multiple off-chain orders atomically with 1 lender signature (BatchLendOffer) |
|
|
121
122
|
| `buildFillSignedOrder(order, sig, fillBps)` | Fill a signed order on-chain |
|
|
122
123
|
| `buildCancelOrder(order)` | Cancel a specific signed order |
|
|
123
124
|
| `buildCancelOrdersByNonce(minNonce)` | Bulk cancel orders below a nonce |
|
|
@@ -197,7 +198,9 @@ Functions for creating SNIP-12 typed data for gasless order creation and settlem
|
|
|
197
198
|
import {
|
|
198
199
|
getInscriptionOrderTypedData,
|
|
199
200
|
getLendOfferTypedData,
|
|
201
|
+
getBatchLendOfferTypedData,
|
|
200
202
|
hashAssets,
|
|
203
|
+
hashBatchEntries,
|
|
201
204
|
serializeSignature,
|
|
202
205
|
deserializeSignature,
|
|
203
206
|
} from '@fepvenancio/stela-sdk'
|
|
@@ -207,7 +210,9 @@ import {
|
|
|
207
210
|
|----------|-------------|
|
|
208
211
|
| `getInscriptionOrderTypedData(params)` | Build SNIP-12 typed data for a borrower's InscriptionOrder |
|
|
209
212
|
| `getLendOfferTypedData(params)` | Build SNIP-12 typed data for a lender's LendOffer |
|
|
213
|
+
| `getBatchLendOfferTypedData(params)` | Build SNIP-12 typed data for a lender's BatchLendOffer (multi-order settlement) |
|
|
210
214
|
| `hashAssets(assets)` | Poseidon hash of an asset array (matches Cairo's `hash_assets()`) |
|
|
215
|
+
| `hashBatchEntries(entries)` | Poseidon hash of BatchEntry array for batch_settle() |
|
|
211
216
|
| `serializeSignature(sig)` | Convert `string[]` signature to `{ r, s }` for storage |
|
|
212
217
|
| `deserializeSignature(stored)` | Convert `{ r, s }` back to `string[]` |
|
|
213
218
|
|
|
@@ -313,6 +318,7 @@ All exported types from the SDK:
|
|
|
313
318
|
| `StoredInscription` | Raw on-chain inscription data |
|
|
314
319
|
| `Inscription` | Parsed inscription with computed status |
|
|
315
320
|
| `SignedOrder` | Signed order for the matching engine |
|
|
321
|
+
| `BatchEntry` | Entry in a batch settle (order hash + fill BPS) |
|
|
316
322
|
| `InscriptionRow` | API response row for inscriptions |
|
|
317
323
|
| `AssetRow` | API response row for assets |
|
|
318
324
|
| `ApiListResponse<T>` | Paginated list response envelope |
|
|
@@ -397,7 +403,7 @@ npm publish --access public
|
|
|
397
403
|
|
|
398
404
|
## Running a Relayer
|
|
399
405
|
|
|
400
|
-
The Stela protocol is fully permissionless — anyone can run a relayer to settle matched orders and earn **
|
|
406
|
+
The Stela protocol is fully permissionless — anyone can run a relayer to settle matched orders and earn **0.05%** on every settlement. See [RELAYER.md](RELAYER.md) for the SDK integration guide and the [stela-relayer](https://github.com/fepvenancio/stela-relayer) repo for a standalone implementation.
|
|
401
407
|
|
|
402
408
|
## License
|
|
403
409
|
|
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: "0x012998e49cc8205d0bb56b5c10202bd32994091b1cacdb7bcbd03dc6781d4974",
|
|
28
28
|
mainnet: "0x0"
|
|
29
29
|
};
|
|
30
30
|
var VALID_NETWORKS = ["sepolia", "mainnet"];
|
|
@@ -428,6 +428,17 @@ function parseEvents(rawEvents) {
|
|
|
428
428
|
}
|
|
429
429
|
return results;
|
|
430
430
|
}
|
|
431
|
+
var U256_TYPE_HASH = "0x3b143be38b811560b45593fb2a071ec4ddd0a020e10782be62ffe6f39e0e82c";
|
|
432
|
+
function hashBatchEntries(entries) {
|
|
433
|
+
const elements = [String(entries.length)];
|
|
434
|
+
for (const entry of entries) {
|
|
435
|
+
elements.push(entry.orderHash);
|
|
436
|
+
const [low, high] = toU256(entry.bps);
|
|
437
|
+
const bpsHash = starknet.hash.computePoseidonHashOnElements([U256_TYPE_HASH, low, high]);
|
|
438
|
+
elements.push(bpsHash);
|
|
439
|
+
}
|
|
440
|
+
return starknet.hash.computePoseidonHashOnElements(elements);
|
|
441
|
+
}
|
|
431
442
|
function hashAssets(assets) {
|
|
432
443
|
const elements = [String(assets.length)];
|
|
433
444
|
for (const asset of assets) {
|
|
@@ -528,6 +539,35 @@ function getLendOfferTypedData(params) {
|
|
|
528
539
|
}
|
|
529
540
|
};
|
|
530
541
|
}
|
|
542
|
+
function getBatchLendOfferTypedData(params) {
|
|
543
|
+
return {
|
|
544
|
+
types: {
|
|
545
|
+
StarknetDomain: [
|
|
546
|
+
{ name: "name", type: "shortstring" },
|
|
547
|
+
{ name: "version", type: "shortstring" },
|
|
548
|
+
{ name: "chainId", type: "shortstring" },
|
|
549
|
+
{ name: "revision", type: "shortstring" }
|
|
550
|
+
],
|
|
551
|
+
BatchLendOffer: [
|
|
552
|
+
{ name: "batch_hash", type: "felt" },
|
|
553
|
+
{ name: "count", type: "u128" },
|
|
554
|
+
{ name: "lender", type: "ContractAddress" },
|
|
555
|
+
{ name: "start_nonce", type: "felt" }
|
|
556
|
+
]
|
|
557
|
+
},
|
|
558
|
+
primaryType: "BatchLendOffer",
|
|
559
|
+
domain: {
|
|
560
|
+
...STELA_DOMAIN,
|
|
561
|
+
chainId: params.chainId
|
|
562
|
+
},
|
|
563
|
+
message: {
|
|
564
|
+
batch_hash: params.batchHash,
|
|
565
|
+
count: params.count.toString(),
|
|
566
|
+
lender: params.lender,
|
|
567
|
+
start_nonce: params.startNonce.toString()
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
}
|
|
531
571
|
|
|
532
572
|
// src/offchain/signature.ts
|
|
533
573
|
function serializeSignature(sig) {
|
|
@@ -722,6 +762,28 @@ var stela_default = [
|
|
|
722
762
|
}
|
|
723
763
|
]
|
|
724
764
|
},
|
|
765
|
+
{
|
|
766
|
+
type: "struct",
|
|
767
|
+
name: "stela::snip12::BatchLendOffer",
|
|
768
|
+
members: [
|
|
769
|
+
{
|
|
770
|
+
name: "batch_hash",
|
|
771
|
+
type: "core::felt252"
|
|
772
|
+
},
|
|
773
|
+
{
|
|
774
|
+
name: "count",
|
|
775
|
+
type: "core::integer::u32"
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
name: "lender",
|
|
779
|
+
type: "core::starknet::contract_address::ContractAddress"
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
name: "start_nonce",
|
|
783
|
+
type: "core::felt252"
|
|
784
|
+
}
|
|
785
|
+
]
|
|
786
|
+
},
|
|
725
787
|
{
|
|
726
788
|
type: "struct",
|
|
727
789
|
name: "stela::types::signed_order::SignedOrder",
|
|
@@ -934,6 +996,46 @@ var stela_default = [
|
|
|
934
996
|
outputs: [],
|
|
935
997
|
state_mutability: "external"
|
|
936
998
|
},
|
|
999
|
+
{
|
|
1000
|
+
type: "function",
|
|
1001
|
+
name: "batch_settle",
|
|
1002
|
+
inputs: [
|
|
1003
|
+
{
|
|
1004
|
+
name: "orders",
|
|
1005
|
+
type: "core::array::Array::<stela::snip12::InscriptionOrder>"
|
|
1006
|
+
},
|
|
1007
|
+
{
|
|
1008
|
+
name: "debt_assets_flat",
|
|
1009
|
+
type: "core::array::Array::<stela::types::asset::Asset>"
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
name: "interest_assets_flat",
|
|
1013
|
+
type: "core::array::Array::<stela::types::asset::Asset>"
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
name: "collateral_assets_flat",
|
|
1017
|
+
type: "core::array::Array::<stela::types::asset::Asset>"
|
|
1018
|
+
},
|
|
1019
|
+
{
|
|
1020
|
+
name: "borrower_sigs",
|
|
1021
|
+
type: "core::array::Array::<core::array::Array::<core::felt252>>"
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
name: "batch_offer",
|
|
1025
|
+
type: "stela::snip12::BatchLendOffer"
|
|
1026
|
+
},
|
|
1027
|
+
{
|
|
1028
|
+
name: "lender_sig",
|
|
1029
|
+
type: "core::array::Array::<core::felt252>"
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
name: "bps_list",
|
|
1033
|
+
type: "core::array::Array::<core::integer::u256>"
|
|
1034
|
+
}
|
|
1035
|
+
],
|
|
1036
|
+
outputs: [],
|
|
1037
|
+
state_mutability: "external"
|
|
1038
|
+
},
|
|
937
1039
|
{
|
|
938
1040
|
type: "function",
|
|
939
1041
|
name: "fill_signed_order",
|
|
@@ -2451,6 +2553,44 @@ var InscriptionClient = class {
|
|
|
2451
2553
|
];
|
|
2452
2554
|
return { contractAddress: this.address, entrypoint: "settle", calldata };
|
|
2453
2555
|
}
|
|
2556
|
+
buildBatchSettle(params) {
|
|
2557
|
+
const calldata = [];
|
|
2558
|
+
calldata.push(String(params.orders.length));
|
|
2559
|
+
for (const order of params.orders) {
|
|
2560
|
+
calldata.push(
|
|
2561
|
+
order.borrower,
|
|
2562
|
+
order.debtHash,
|
|
2563
|
+
order.interestHash,
|
|
2564
|
+
order.collateralHash,
|
|
2565
|
+
String(order.debtCount),
|
|
2566
|
+
String(order.interestCount),
|
|
2567
|
+
String(order.collateralCount),
|
|
2568
|
+
order.duration.toString(),
|
|
2569
|
+
order.deadline.toString(),
|
|
2570
|
+
order.multiLender ? "1" : "0",
|
|
2571
|
+
order.nonce.toString()
|
|
2572
|
+
);
|
|
2573
|
+
}
|
|
2574
|
+
calldata.push(...serializeAssets(params.debtAssetsFlat));
|
|
2575
|
+
calldata.push(...serializeAssets(params.interestAssetsFlat));
|
|
2576
|
+
calldata.push(...serializeAssets(params.collateralAssetsFlat));
|
|
2577
|
+
calldata.push(String(params.borrowerSigs.length));
|
|
2578
|
+
for (const sig of params.borrowerSigs) {
|
|
2579
|
+
calldata.push(String(sig.length), ...sig);
|
|
2580
|
+
}
|
|
2581
|
+
calldata.push(
|
|
2582
|
+
params.batchOffer.batchHash,
|
|
2583
|
+
String(params.batchOffer.count),
|
|
2584
|
+
params.batchOffer.lender,
|
|
2585
|
+
params.batchOffer.startNonce.toString()
|
|
2586
|
+
);
|
|
2587
|
+
calldata.push(String(params.lenderSig.length), ...params.lenderSig);
|
|
2588
|
+
calldata.push(String(params.bpsList.length));
|
|
2589
|
+
for (const bps of params.bpsList) {
|
|
2590
|
+
calldata.push(...toU256(bps));
|
|
2591
|
+
}
|
|
2592
|
+
return { contractAddress: this.address, entrypoint: "batch_settle", calldata };
|
|
2593
|
+
}
|
|
2454
2594
|
buildFillSignedOrder(order, signature, fillBps) {
|
|
2455
2595
|
const calldata = [
|
|
2456
2596
|
// SignedOrder struct fields
|
|
@@ -2926,10 +3066,12 @@ exports.formatDuration = formatDuration;
|
|
|
2926
3066
|
exports.formatTimestamp = formatTimestamp;
|
|
2927
3067
|
exports.formatTokenValue = formatTokenValue;
|
|
2928
3068
|
exports.fromU256 = fromU256;
|
|
3069
|
+
exports.getBatchLendOfferTypedData = getBatchLendOfferTypedData;
|
|
2929
3070
|
exports.getInscriptionOrderTypedData = getInscriptionOrderTypedData;
|
|
2930
3071
|
exports.getLendOfferTypedData = getLendOfferTypedData;
|
|
2931
3072
|
exports.getTokensForNetwork = getTokensForNetwork;
|
|
2932
3073
|
exports.hashAssets = hashAssets;
|
|
3074
|
+
exports.hashBatchEntries = hashBatchEntries;
|
|
2933
3075
|
exports.inscriptionIdToHex = inscriptionIdToHex;
|
|
2934
3076
|
exports.normalizeAddress = normalizeAddress;
|
|
2935
3077
|
exports.parseAmount = parseAmount;
|