@fepvenancio/stela-sdk 0.5.4 → 0.6.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 +80 -0
- 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 +79 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -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) {
|
|
@@ -2451,6 +2491,44 @@ var InscriptionClient = class {
|
|
|
2451
2491
|
];
|
|
2452
2492
|
return { contractAddress: this.address, entrypoint: "settle", calldata };
|
|
2453
2493
|
}
|
|
2494
|
+
buildBatchSettle(params) {
|
|
2495
|
+
const calldata = [];
|
|
2496
|
+
calldata.push(String(params.orders.length));
|
|
2497
|
+
for (const order of params.orders) {
|
|
2498
|
+
calldata.push(
|
|
2499
|
+
order.borrower,
|
|
2500
|
+
order.debtHash,
|
|
2501
|
+
order.interestHash,
|
|
2502
|
+
order.collateralHash,
|
|
2503
|
+
String(order.debtCount),
|
|
2504
|
+
String(order.interestCount),
|
|
2505
|
+
String(order.collateralCount),
|
|
2506
|
+
order.duration.toString(),
|
|
2507
|
+
order.deadline.toString(),
|
|
2508
|
+
order.multiLender ? "1" : "0",
|
|
2509
|
+
order.nonce.toString()
|
|
2510
|
+
);
|
|
2511
|
+
}
|
|
2512
|
+
calldata.push(...serializeAssets(params.debtAssetsFlat));
|
|
2513
|
+
calldata.push(...serializeAssets(params.interestAssetsFlat));
|
|
2514
|
+
calldata.push(...serializeAssets(params.collateralAssetsFlat));
|
|
2515
|
+
calldata.push(String(params.borrowerSigs.length));
|
|
2516
|
+
for (const sig of params.borrowerSigs) {
|
|
2517
|
+
calldata.push(String(sig.length), ...sig);
|
|
2518
|
+
}
|
|
2519
|
+
calldata.push(
|
|
2520
|
+
params.batchOffer.batchHash,
|
|
2521
|
+
String(params.batchOffer.count),
|
|
2522
|
+
params.batchOffer.lender,
|
|
2523
|
+
params.batchOffer.startNonce.toString()
|
|
2524
|
+
);
|
|
2525
|
+
calldata.push(String(params.lenderSig.length), ...params.lenderSig);
|
|
2526
|
+
calldata.push(String(params.bpsList.length));
|
|
2527
|
+
for (const bps of params.bpsList) {
|
|
2528
|
+
calldata.push(...toU256(bps));
|
|
2529
|
+
}
|
|
2530
|
+
return { contractAddress: this.address, entrypoint: "batch_settle", calldata };
|
|
2531
|
+
}
|
|
2454
2532
|
buildFillSignedOrder(order, signature, fillBps) {
|
|
2455
2533
|
const calldata = [
|
|
2456
2534
|
// SignedOrder struct fields
|
|
@@ -2926,10 +3004,12 @@ exports.formatDuration = formatDuration;
|
|
|
2926
3004
|
exports.formatTimestamp = formatTimestamp;
|
|
2927
3005
|
exports.formatTokenValue = formatTokenValue;
|
|
2928
3006
|
exports.fromU256 = fromU256;
|
|
3007
|
+
exports.getBatchLendOfferTypedData = getBatchLendOfferTypedData;
|
|
2929
3008
|
exports.getInscriptionOrderTypedData = getInscriptionOrderTypedData;
|
|
2930
3009
|
exports.getLendOfferTypedData = getLendOfferTypedData;
|
|
2931
3010
|
exports.getTokensForNetwork = getTokensForNetwork;
|
|
2932
3011
|
exports.hashAssets = hashAssets;
|
|
3012
|
+
exports.hashBatchEntries = hashBatchEntries;
|
|
2933
3013
|
exports.inscriptionIdToHex = inscriptionIdToHex;
|
|
2934
3014
|
exports.normalizeAddress = normalizeAddress;
|
|
2935
3015
|
exports.parseAmount = parseAmount;
|