@medialane/sdk 0.62.0 → 0.63.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/evm/index.cjs +3 -3
- package/dist/evm/index.cjs.map +1 -1
- package/dist/evm/index.d.cts +1 -1
- package/dist/evm/index.d.ts +1 -1
- package/dist/evm/index.js +3 -3
- package/dist/evm/index.js.map +1 -1
- package/dist/{index-CsiUiS0q.d.ts → index-7_t9LEnt.d.ts} +25 -14
- package/dist/{index-CyZH_h8o.d.cts → index-C94WNlgk.d.cts} +25 -14
- package/dist/index.cjs +417 -327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +418 -328
- package/dist/index.js.map +1 -1
- package/dist/solana/index.cjs +3 -3
- package/dist/solana/index.cjs.map +1 -1
- package/dist/solana/index.d.cts +1 -1
- package/dist/solana/index.d.ts +1 -1
- package/dist/solana/index.js +3 -3
- package/dist/solana/index.js.map +1 -1
- package/dist/starknet/index.cjs +436 -354
- package/dist/starknet/index.cjs.map +1 -1
- package/dist/starknet/index.d.cts +3 -3
- package/dist/starknet/index.d.ts +3 -3
- package/dist/starknet/index.js +437 -355
- package/dist/starknet/index.js.map +1 -1
- package/dist/stellar/index.cjs +3 -3
- package/dist/stellar/index.cjs.map +1 -1
- package/dist/stellar/index.d.cts +1 -1
- package/dist/stellar/index.d.ts +1 -1
- package/dist/stellar/index.js +3 -3
- package/dist/stellar/index.js.map +1 -1
- package/dist/{types-V6imkXvR.d.cts → types-Bx3ax9lW.d.cts} +20 -3
- package/dist/{types-V6imkXvR.d.ts → types-Bx3ax9lW.d.ts} +20 -3
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -37,9 +37,9 @@ var COORDINATES = {
|
|
|
37
37
|
creatorCoinFactoryClassHash: "0x51765926b1344c9a20b8cd4b5abe7b7d47375ae97cf6804db3ea5d4b05a9b55",
|
|
38
38
|
creatorCoinStartBlock: 10474544,
|
|
39
39
|
ekuboCore: "0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b",
|
|
40
|
-
ipTicketsFactory: "
|
|
41
|
-
ipTicketCollectionClassHash: "
|
|
42
|
-
ipTicketsStartBlock:
|
|
40
|
+
ipTicketsFactory: "0x03ffef4162fe2c44e17d6be2aad3553cab0ac2274cd0b1bb3fafb12fd66695c1",
|
|
41
|
+
ipTicketCollectionClassHash: "0x036393fb4241ed55bd12d8b328ed877d08100fadf9150a650e2b84cbab95e1d4",
|
|
42
|
+
ipTicketsStartBlock: 11689800,
|
|
43
43
|
ipClubRegistry: "0x00e189c619b6bb07d78973a149641c59c37eb0716f8584d7520bce12d303eede",
|
|
44
44
|
ipClubNftClassHash: "0x02bc9b20cca21b04245e9215bf7121f4d7295b195890e449b472b573017fb889",
|
|
45
45
|
ipClubStartBlock: 11404776,
|
|
@@ -11492,6 +11492,14 @@ function toSignatureArray(sig) {
|
|
|
11492
11492
|
const s = sig;
|
|
11493
11493
|
return [s.r.toString(), s.s.toString()];
|
|
11494
11494
|
}
|
|
11495
|
+
function newContract(abi, address, providerOrAccount) {
|
|
11496
|
+
const C = starknet.Contract;
|
|
11497
|
+
return C.length === 1 ? new starknet.Contract({ abi, address, providerOrAccount }) : new starknet.Contract(
|
|
11498
|
+
abi,
|
|
11499
|
+
address,
|
|
11500
|
+
providerOrAccount
|
|
11501
|
+
);
|
|
11502
|
+
}
|
|
11495
11503
|
function getChainId(config) {
|
|
11496
11504
|
if (config.chain !== "STARKNET") {
|
|
11497
11505
|
throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
|
|
@@ -11516,17 +11524,101 @@ function getProvider(config) {
|
|
|
11516
11524
|
return p;
|
|
11517
11525
|
}
|
|
11518
11526
|
|
|
11527
|
+
// src/starknet/marketplace/build.ts
|
|
11528
|
+
function contractFor(cfg) {
|
|
11529
|
+
return newContract(IPMarketplaceABI, cfg.marketplaceContract, getProvider(cfg));
|
|
11530
|
+
}
|
|
11531
|
+
function buildListingOrder(i, cfg) {
|
|
11532
|
+
const orderParams = {
|
|
11533
|
+
offerer: i.offerer,
|
|
11534
|
+
marketplace: cfg.marketplaceContract,
|
|
11535
|
+
offer: { item_type: "ERC721", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: "1" },
|
|
11536
|
+
consideration: {
|
|
11537
|
+
item_type: "ERC20",
|
|
11538
|
+
token: i.paymentTokenAddress,
|
|
11539
|
+
identifier_or_criteria: "0",
|
|
11540
|
+
amount: i.priceWei,
|
|
11541
|
+
recipient: i.offerer
|
|
11542
|
+
},
|
|
11543
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
11544
|
+
start_time: String(i.startTime),
|
|
11545
|
+
end_time: String(i.endTime),
|
|
11546
|
+
salt: i.salt,
|
|
11547
|
+
counter: i.counter
|
|
11548
|
+
};
|
|
11549
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
11550
|
+
return { orderParams, typedData };
|
|
11551
|
+
}
|
|
11552
|
+
function buildOfferOrder(i, cfg) {
|
|
11553
|
+
const orderParams = {
|
|
11554
|
+
offerer: i.offerer,
|
|
11555
|
+
marketplace: cfg.marketplaceContract,
|
|
11556
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWei },
|
|
11557
|
+
consideration: {
|
|
11558
|
+
item_type: "ERC721",
|
|
11559
|
+
token: i.nftContract,
|
|
11560
|
+
identifier_or_criteria: i.tokenId,
|
|
11561
|
+
amount: "1",
|
|
11562
|
+
recipient: i.offerer
|
|
11563
|
+
},
|
|
11564
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
11565
|
+
start_time: String(i.startTime),
|
|
11566
|
+
end_time: String(i.endTime),
|
|
11567
|
+
salt: i.salt,
|
|
11568
|
+
counter: i.counter
|
|
11569
|
+
};
|
|
11570
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
11571
|
+
return { orderParams, typedData };
|
|
11572
|
+
}
|
|
11573
|
+
function registerPayload(orderParams, signature) {
|
|
11574
|
+
return stringifyBigInts({
|
|
11575
|
+
parameters: {
|
|
11576
|
+
...orderParams,
|
|
11577
|
+
offer: { ...orderParams.offer, item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type) },
|
|
11578
|
+
consideration: {
|
|
11579
|
+
...orderParams.consideration,
|
|
11580
|
+
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11581
|
+
}
|
|
11582
|
+
},
|
|
11583
|
+
signature
|
|
11584
|
+
});
|
|
11585
|
+
}
|
|
11586
|
+
function buildRegisterCalls(a, cfg) {
|
|
11587
|
+
const registerCall = contractFor(cfg).populate("register_order", [registerPayload(a.orderParams, a.signature)]);
|
|
11588
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
11589
|
+
}
|
|
11590
|
+
function buildFulfillCalls(a, cfg) {
|
|
11591
|
+
const u = starknet.cairo.uint256(a.totalPrice);
|
|
11592
|
+
const approve = {
|
|
11593
|
+
contractAddress: a.paymentToken,
|
|
11594
|
+
entrypoint: "approve",
|
|
11595
|
+
calldata: [cfg.marketplaceContract, u.low.toString(), u.high.toString()]
|
|
11596
|
+
};
|
|
11597
|
+
const fulfill = contractFor(cfg).populate("fulfill_order", [a.orderHash]);
|
|
11598
|
+
const fee = buildFeeCall(
|
|
11599
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
11600
|
+
cfg.feeConfig
|
|
11601
|
+
);
|
|
11602
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
11603
|
+
}
|
|
11604
|
+
function buildCancelCalls(a, cfg) {
|
|
11605
|
+
const cancelRequest = stringifyBigInts({
|
|
11606
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
11607
|
+
signature: a.signature
|
|
11608
|
+
});
|
|
11609
|
+
return [contractFor(cfg).populate("cancel_order", [cancelRequest])];
|
|
11610
|
+
}
|
|
11611
|
+
function buildCancelTypedData(orderHash, offerer, cfg) {
|
|
11612
|
+
return stringifyBigInts(buildCancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg)));
|
|
11613
|
+
}
|
|
11614
|
+
|
|
11519
11615
|
// src/starknet/marketplace/orders.ts
|
|
11520
11616
|
var _contractCache = /* @__PURE__ */ new WeakMap();
|
|
11521
11617
|
function makeContract(config) {
|
|
11522
11618
|
const cached = _contractCache.get(config);
|
|
11523
11619
|
const provider = getProvider(config);
|
|
11524
11620
|
if (cached) return { ...cached, provider };
|
|
11525
|
-
const contract =
|
|
11526
|
-
IPMarketplaceABI,
|
|
11527
|
-
config.marketplaceContract,
|
|
11528
|
-
provider
|
|
11529
|
-
);
|
|
11621
|
+
const contract = newContract(IPMarketplaceABI, config.marketplaceContract, provider);
|
|
11530
11622
|
_contractCache.set(config, { contract });
|
|
11531
11623
|
return { contract, provider };
|
|
11532
11624
|
}
|
|
@@ -11540,46 +11632,22 @@ async function createListing(account, params, config) {
|
|
|
11540
11632
|
const endTime = now + durationSeconds;
|
|
11541
11633
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
11542
11634
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11543
|
-
const orderParams =
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11552
|
-
|
|
11553
|
-
|
|
11554
|
-
|
|
11555
|
-
identifier_or_criteria: "0",
|
|
11556
|
-
amount: priceWei,
|
|
11557
|
-
recipient: account.address
|
|
11558
|
-
},
|
|
11559
|
-
royalty_max_bps: royaltyMaxBps,
|
|
11560
|
-
start_time: startTime.toString(),
|
|
11561
|
-
end_time: endTime.toString(),
|
|
11562
|
-
salt: generateSalt(),
|
|
11563
|
-
counter
|
|
11564
|
-
};
|
|
11565
|
-
const chainId = getChainId(config);
|
|
11566
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
11567
|
-
const signature = await account.signMessage(typedData);
|
|
11568
|
-
const signatureArray = toSignatureArray(signature);
|
|
11569
|
-
const registerPayload = stringifyBigInts({
|
|
11570
|
-
parameters: {
|
|
11571
|
-
...orderParams,
|
|
11572
|
-
offer: {
|
|
11573
|
-
...orderParams.offer,
|
|
11574
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
11575
|
-
},
|
|
11576
|
-
consideration: {
|
|
11577
|
-
...orderParams.consideration,
|
|
11578
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11579
|
-
}
|
|
11635
|
+
const { orderParams, typedData } = buildListingOrder(
|
|
11636
|
+
{
|
|
11637
|
+
offerer: account.address,
|
|
11638
|
+
nftContract,
|
|
11639
|
+
tokenId,
|
|
11640
|
+
priceWei,
|
|
11641
|
+
paymentTokenAddress: token.address,
|
|
11642
|
+
royaltyMaxBps,
|
|
11643
|
+
startTime,
|
|
11644
|
+
endTime,
|
|
11645
|
+
salt: generateSalt(),
|
|
11646
|
+
counter
|
|
11580
11647
|
},
|
|
11581
|
-
|
|
11582
|
-
|
|
11648
|
+
config
|
|
11649
|
+
);
|
|
11650
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11583
11651
|
const tokenIdUint256 = starknet.cairo.uint256(tokenId);
|
|
11584
11652
|
let isAlreadyApproved = false;
|
|
11585
11653
|
try {
|
|
@@ -11591,19 +11659,19 @@ async function createListing(account, params, config) {
|
|
|
11591
11659
|
isAlreadyApproved = BigInt(result[0]).toString() === BigInt(config.marketplaceContract).toString();
|
|
11592
11660
|
} catch {
|
|
11593
11661
|
}
|
|
11594
|
-
const
|
|
11595
|
-
|
|
11596
|
-
|
|
11597
|
-
|
|
11598
|
-
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
|
|
11602
|
-
|
|
11603
|
-
|
|
11604
|
-
},
|
|
11605
|
-
|
|
11606
|
-
|
|
11662
|
+
const approve = {
|
|
11663
|
+
contractAddress: nftContract,
|
|
11664
|
+
entrypoint: "approve",
|
|
11665
|
+
calldata: [
|
|
11666
|
+
config.marketplaceContract,
|
|
11667
|
+
tokenIdUint256.low.toString(),
|
|
11668
|
+
tokenIdUint256.high.toString()
|
|
11669
|
+
]
|
|
11670
|
+
};
|
|
11671
|
+
const calls = buildRegisterCalls(
|
|
11672
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isAlreadyApproved, approve },
|
|
11673
|
+
config
|
|
11674
|
+
);
|
|
11607
11675
|
try {
|
|
11608
11676
|
const tx = await account.execute(calls);
|
|
11609
11677
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -11622,46 +11690,22 @@ async function makeOffer(account, params, config) {
|
|
|
11622
11690
|
const endTime = now + durationSeconds;
|
|
11623
11691
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
11624
11692
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11625
|
-
const orderParams =
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
|
|
11635
|
-
|
|
11636
|
-
|
|
11637
|
-
identifier_or_criteria: tokenId,
|
|
11638
|
-
amount: "1",
|
|
11639
|
-
recipient: account.address
|
|
11640
|
-
},
|
|
11641
|
-
royalty_max_bps: royaltyMaxBps,
|
|
11642
|
-
start_time: startTime.toString(),
|
|
11643
|
-
end_time: endTime.toString(),
|
|
11644
|
-
salt: generateSalt(),
|
|
11645
|
-
counter
|
|
11646
|
-
};
|
|
11647
|
-
const chainId = getChainId(config);
|
|
11648
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
11649
|
-
const signature = await account.signMessage(typedData);
|
|
11650
|
-
const signatureArray = toSignatureArray(signature);
|
|
11651
|
-
const registerPayload = stringifyBigInts({
|
|
11652
|
-
parameters: {
|
|
11653
|
-
...orderParams,
|
|
11654
|
-
offer: {
|
|
11655
|
-
...orderParams.offer,
|
|
11656
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
11657
|
-
},
|
|
11658
|
-
consideration: {
|
|
11659
|
-
...orderParams.consideration,
|
|
11660
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11661
|
-
}
|
|
11693
|
+
const { orderParams, typedData } = buildOfferOrder(
|
|
11694
|
+
{
|
|
11695
|
+
offerer: account.address,
|
|
11696
|
+
nftContract,
|
|
11697
|
+
tokenId,
|
|
11698
|
+
priceWei,
|
|
11699
|
+
paymentTokenAddress: token.address,
|
|
11700
|
+
royaltyMaxBps,
|
|
11701
|
+
startTime,
|
|
11702
|
+
endTime,
|
|
11703
|
+
salt: generateSalt(),
|
|
11704
|
+
counter
|
|
11662
11705
|
},
|
|
11663
|
-
|
|
11664
|
-
|
|
11706
|
+
config
|
|
11707
|
+
);
|
|
11708
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11665
11709
|
const amountUint256 = starknet.cairo.uint256(priceWei);
|
|
11666
11710
|
const approveCall = {
|
|
11667
11711
|
contractAddress: token.address,
|
|
@@ -11672,9 +11716,12 @@ async function makeOffer(account, params, config) {
|
|
|
11672
11716
|
amountUint256.high.toString()
|
|
11673
11717
|
]
|
|
11674
11718
|
};
|
|
11675
|
-
const
|
|
11719
|
+
const calls = buildRegisterCalls(
|
|
11720
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
11721
|
+
config
|
|
11722
|
+
);
|
|
11676
11723
|
try {
|
|
11677
|
-
const tx = await account.execute(
|
|
11724
|
+
const tx = await account.execute(calls);
|
|
11678
11725
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11679
11726
|
return { txHash: tx.transaction_hash };
|
|
11680
11727
|
} catch (err) {
|
|
@@ -11683,23 +11730,8 @@ async function makeOffer(account, params, config) {
|
|
|
11683
11730
|
}
|
|
11684
11731
|
async function fulfillOrder(account, params, config) {
|
|
11685
11732
|
const { orderHash, paymentToken, totalPrice } = params;
|
|
11686
|
-
const {
|
|
11687
|
-
const
|
|
11688
|
-
const approveCall = {
|
|
11689
|
-
contractAddress: paymentToken,
|
|
11690
|
-
entrypoint: "approve",
|
|
11691
|
-
calldata: [
|
|
11692
|
-
config.marketplaceContract,
|
|
11693
|
-
totalPriceU256.low.toString(),
|
|
11694
|
-
totalPriceU256.high.toString()
|
|
11695
|
-
]
|
|
11696
|
-
};
|
|
11697
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash]);
|
|
11698
|
-
const feeCall = buildFeeCall(
|
|
11699
|
-
{ surface: "marketplace", token: paymentToken, grossAmount: BigInt(totalPrice) },
|
|
11700
|
-
config.feeConfig
|
|
11701
|
-
);
|
|
11702
|
-
const calls = feeCall ? [approveCall, fulfillCall, feeCall] : [approveCall, fulfillCall];
|
|
11733
|
+
const { provider } = makeContract(config);
|
|
11734
|
+
const calls = buildFulfillCalls({ orderHash, paymentToken, totalPrice }, config);
|
|
11703
11735
|
try {
|
|
11704
11736
|
const tx = await account.execute(calls);
|
|
11705
11737
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -11710,24 +11742,12 @@ async function fulfillOrder(account, params, config) {
|
|
|
11710
11742
|
}
|
|
11711
11743
|
async function cancelOrder(account, params, config) {
|
|
11712
11744
|
const { orderHash } = params;
|
|
11713
|
-
const {
|
|
11714
|
-
const
|
|
11715
|
-
const
|
|
11716
|
-
|
|
11717
|
-
offerer: account.address
|
|
11718
|
-
};
|
|
11719
|
-
const typedData = stringifyBigInts(
|
|
11720
|
-
buildCancellationTypedData(cancelParams, chainId)
|
|
11721
|
-
);
|
|
11722
|
-
const signature = await account.signMessage(typedData);
|
|
11723
|
-
const signatureArray = toSignatureArray(signature);
|
|
11724
|
-
const cancelRequest = stringifyBigInts({
|
|
11725
|
-
cancelation: cancelParams,
|
|
11726
|
-
signature: signatureArray
|
|
11727
|
-
});
|
|
11728
|
-
const call = contract.populate("cancel_order", [cancelRequest]);
|
|
11745
|
+
const { provider } = makeContract(config);
|
|
11746
|
+
const typedData = buildCancelTypedData(orderHash, account.address, config);
|
|
11747
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11748
|
+
const calls = buildCancelCalls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
11729
11749
|
try {
|
|
11730
|
-
const tx = await account.execute(
|
|
11750
|
+
const tx = await account.execute(calls);
|
|
11731
11751
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11732
11752
|
return { txHash: tx.transaction_hash };
|
|
11733
11753
|
} catch (err) {
|
|
@@ -11874,16 +11894,106 @@ var MarketplaceModule = class {
|
|
|
11874
11894
|
return buildCancellationTypedData(params, chainId);
|
|
11875
11895
|
}
|
|
11876
11896
|
};
|
|
11897
|
+
function contractFor2(cfg) {
|
|
11898
|
+
return newContract(Medialane1155ABI, cfg.marketplace1155Contract, getProvider(cfg));
|
|
11899
|
+
}
|
|
11900
|
+
function buildListing1155Order(i, cfg) {
|
|
11901
|
+
const orderParams = {
|
|
11902
|
+
offerer: i.offerer,
|
|
11903
|
+
marketplace: cfg.marketplace1155Contract,
|
|
11904
|
+
offer: { item_type: "ERC1155", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: i.quantity },
|
|
11905
|
+
consideration: {
|
|
11906
|
+
item_type: "ERC20",
|
|
11907
|
+
token: i.paymentTokenAddress,
|
|
11908
|
+
identifier_or_criteria: "0",
|
|
11909
|
+
amount: i.priceWeiPerUnit,
|
|
11910
|
+
recipient: i.offerer
|
|
11911
|
+
},
|
|
11912
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
11913
|
+
start_time: String(i.startTime),
|
|
11914
|
+
end_time: String(i.endTime),
|
|
11915
|
+
salt: i.salt,
|
|
11916
|
+
counter: i.counter
|
|
11917
|
+
};
|
|
11918
|
+
const typedData = stringifyBigInts(
|
|
11919
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
11920
|
+
);
|
|
11921
|
+
return { orderParams, typedData };
|
|
11922
|
+
}
|
|
11923
|
+
function buildOffer1155Order(i, cfg) {
|
|
11924
|
+
const orderParams = {
|
|
11925
|
+
offerer: i.offerer,
|
|
11926
|
+
marketplace: cfg.marketplace1155Contract,
|
|
11927
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWeiPerUnit },
|
|
11928
|
+
consideration: {
|
|
11929
|
+
item_type: "ERC1155",
|
|
11930
|
+
token: i.nftContract,
|
|
11931
|
+
identifier_or_criteria: i.tokenId,
|
|
11932
|
+
amount: i.quantity,
|
|
11933
|
+
recipient: i.offerer
|
|
11934
|
+
},
|
|
11935
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
11936
|
+
start_time: String(i.startTime),
|
|
11937
|
+
end_time: String(i.endTime),
|
|
11938
|
+
salt: i.salt,
|
|
11939
|
+
counter: i.counter
|
|
11940
|
+
};
|
|
11941
|
+
const typedData = stringifyBigInts(
|
|
11942
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
11943
|
+
);
|
|
11944
|
+
return { orderParams, typedData };
|
|
11945
|
+
}
|
|
11946
|
+
function registerPayload2(orderParams, signature) {
|
|
11947
|
+
return stringifyBigInts({
|
|
11948
|
+
parameters: {
|
|
11949
|
+
...orderParams,
|
|
11950
|
+
offer: { ...orderParams.offer, item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type) },
|
|
11951
|
+
consideration: {
|
|
11952
|
+
...orderParams.consideration,
|
|
11953
|
+
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11954
|
+
}
|
|
11955
|
+
},
|
|
11956
|
+
signature
|
|
11957
|
+
});
|
|
11958
|
+
}
|
|
11959
|
+
function buildRegister1155Calls(a, cfg) {
|
|
11960
|
+
const registerCall = contractFor2(cfg).populate("register_order", [registerPayload2(a.orderParams, a.signature)]);
|
|
11961
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
11962
|
+
}
|
|
11963
|
+
function buildFulfill1155Calls(a, cfg) {
|
|
11964
|
+
const u = starknet.cairo.uint256(a.totalPrice);
|
|
11965
|
+
const approve = {
|
|
11966
|
+
contractAddress: a.paymentToken,
|
|
11967
|
+
entrypoint: "approve",
|
|
11968
|
+
calldata: [cfg.marketplace1155Contract, u.low.toString(), u.high.toString()]
|
|
11969
|
+
};
|
|
11970
|
+
const fulfill = contractFor2(cfg).populate("fulfill_order", [a.orderHash, a.quantity]);
|
|
11971
|
+
const fee = buildFeeCall(
|
|
11972
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
11973
|
+
cfg.feeConfig
|
|
11974
|
+
);
|
|
11975
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
11976
|
+
}
|
|
11977
|
+
function buildCancel1155Calls(a, cfg) {
|
|
11978
|
+
const cancelPayload = stringifyBigInts({
|
|
11979
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
11980
|
+
signature: a.signature
|
|
11981
|
+
});
|
|
11982
|
+
return [contractFor2(cfg).populate("cancel_order", [cancelPayload])];
|
|
11983
|
+
}
|
|
11984
|
+
function buildCancel1155TypedData(orderHash, offerer, cfg) {
|
|
11985
|
+
return stringifyBigInts(
|
|
11986
|
+
build1155CancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg))
|
|
11987
|
+
);
|
|
11988
|
+
}
|
|
11989
|
+
|
|
11990
|
+
// src/starknet/marketplace1155/orders.ts
|
|
11877
11991
|
var _contractCache2 = /* @__PURE__ */ new WeakMap();
|
|
11878
11992
|
function getContract(config) {
|
|
11879
11993
|
let c = _contractCache2.get(config);
|
|
11880
11994
|
if (!c) {
|
|
11881
11995
|
const provider = getProvider(config);
|
|
11882
|
-
c =
|
|
11883
|
-
Medialane1155ABI,
|
|
11884
|
-
config.marketplace1155Contract,
|
|
11885
|
-
provider
|
|
11886
|
-
);
|
|
11996
|
+
c = newContract(Medialane1155ABI, config.marketplace1155Contract, provider);
|
|
11887
11997
|
_contractCache2.set(config, c);
|
|
11888
11998
|
}
|
|
11889
11999
|
return c;
|
|
@@ -11902,53 +12012,27 @@ async function createListing1155(account, params, config) {
|
|
|
11902
12012
|
const token = resolveToken(currency);
|
|
11903
12013
|
const priceWei = parseAmount(pricePerUnit, token.decimals);
|
|
11904
12014
|
const now = Math.floor(Date.now() / 1e3);
|
|
12015
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
11905
12016
|
const endTime = now + durationSeconds;
|
|
11906
|
-
const chainId = getChainId(config);
|
|
11907
12017
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
11908
12018
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11909
|
-
const orderParams =
|
|
11910
|
-
|
|
11911
|
-
|
|
11912
|
-
|
|
11913
|
-
|
|
11914
|
-
|
|
11915
|
-
|
|
11916
|
-
|
|
11917
|
-
|
|
11918
|
-
|
|
11919
|
-
|
|
11920
|
-
|
|
11921
|
-
|
|
11922
|
-
identifier_or_criteria: "0",
|
|
11923
|
-
amount: priceWei,
|
|
11924
|
-
// payment leg amount = price PER UNIT
|
|
11925
|
-
recipient: account.address
|
|
12019
|
+
const { orderParams, typedData } = buildListing1155Order(
|
|
12020
|
+
{
|
|
12021
|
+
offerer: account.address,
|
|
12022
|
+
nftContract,
|
|
12023
|
+
tokenId,
|
|
12024
|
+
quantity: amount,
|
|
12025
|
+
priceWeiPerUnit: priceWei,
|
|
12026
|
+
paymentTokenAddress: token.address,
|
|
12027
|
+
royaltyMaxBps,
|
|
12028
|
+
startTime,
|
|
12029
|
+
endTime,
|
|
12030
|
+
salt: generateSalt(),
|
|
12031
|
+
counter
|
|
11926
12032
|
},
|
|
11927
|
-
|
|
11928
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
11929
|
-
end_time: endTime.toString(),
|
|
11930
|
-
salt: generateSalt(),
|
|
11931
|
-
counter
|
|
11932
|
-
};
|
|
11933
|
-
const typedData = stringifyBigInts(
|
|
11934
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
12033
|
+
config
|
|
11935
12034
|
);
|
|
11936
|
-
const
|
|
11937
|
-
const signatureArray = toSignatureArray(signature);
|
|
11938
|
-
const orderPayload = stringifyBigInts({
|
|
11939
|
-
parameters: {
|
|
11940
|
-
...orderParams,
|
|
11941
|
-
offer: {
|
|
11942
|
-
...orderParams.offer,
|
|
11943
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
11944
|
-
},
|
|
11945
|
-
consideration: {
|
|
11946
|
-
...orderParams.consideration,
|
|
11947
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11948
|
-
}
|
|
11949
|
-
},
|
|
11950
|
-
signature: signatureArray
|
|
11951
|
-
});
|
|
12035
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11952
12036
|
let isApproved = false;
|
|
11953
12037
|
try {
|
|
11954
12038
|
const result = await provider.callContract({
|
|
@@ -11959,15 +12043,15 @@ async function createListing1155(account, params, config) {
|
|
|
11959
12043
|
isApproved = BigInt(result[0]) === 1n;
|
|
11960
12044
|
} catch {
|
|
11961
12045
|
}
|
|
11962
|
-
const
|
|
11963
|
-
|
|
11964
|
-
|
|
11965
|
-
|
|
11966
|
-
|
|
11967
|
-
|
|
11968
|
-
},
|
|
11969
|
-
|
|
11970
|
-
|
|
12046
|
+
const approve = {
|
|
12047
|
+
contractAddress: nftContract,
|
|
12048
|
+
entrypoint: "set_approval_for_all",
|
|
12049
|
+
calldata: [config.marketplace1155Contract, "1"]
|
|
12050
|
+
};
|
|
12051
|
+
const calls = buildRegister1155Calls(
|
|
12052
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isApproved, approve },
|
|
12053
|
+
config
|
|
12054
|
+
);
|
|
11971
12055
|
try {
|
|
11972
12056
|
const tx = await account.execute(calls);
|
|
11973
12057
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -11978,21 +12062,10 @@ async function createListing1155(account, params, config) {
|
|
|
11978
12062
|
}
|
|
11979
12063
|
async function fulfillOrder1155(account, params, config) {
|
|
11980
12064
|
const { orderHash, paymentToken, totalPrice, quantity = "1" } = params;
|
|
11981
|
-
const contract = getContract(config);
|
|
11982
12065
|
const provider = getProvider(config);
|
|
11983
|
-
const
|
|
11984
|
-
const approveCall = {
|
|
11985
|
-
contractAddress: paymentToken,
|
|
11986
|
-
entrypoint: "approve",
|
|
11987
|
-
calldata: [
|
|
11988
|
-
config.marketplace1155Contract,
|
|
11989
|
-
totalPriceU256.low.toString(),
|
|
11990
|
-
totalPriceU256.high.toString()
|
|
11991
|
-
]
|
|
11992
|
-
};
|
|
11993
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash, quantity]);
|
|
12066
|
+
const calls = buildFulfill1155Calls({ orderHash, paymentToken, totalPrice, quantity }, config);
|
|
11994
12067
|
try {
|
|
11995
|
-
const tx = await account.execute(
|
|
12068
|
+
const tx = await account.execute(calls);
|
|
11996
12069
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11997
12070
|
return { txHash: tx.transaction_hash };
|
|
11998
12071
|
} catch (err) {
|
|
@@ -12001,25 +12074,12 @@ async function fulfillOrder1155(account, params, config) {
|
|
|
12001
12074
|
}
|
|
12002
12075
|
async function cancelOrder1155(account, params, config) {
|
|
12003
12076
|
const { orderHash } = params;
|
|
12004
|
-
const contract = getContract(config);
|
|
12005
12077
|
const provider = getProvider(config);
|
|
12006
|
-
const
|
|
12007
|
-
const
|
|
12008
|
-
|
|
12009
|
-
offerer: account.address
|
|
12010
|
-
};
|
|
12011
|
-
const typedData = stringifyBigInts(
|
|
12012
|
-
build1155CancellationTypedData(cancelParams, chainId)
|
|
12013
|
-
);
|
|
12014
|
-
const signature = await account.signMessage(typedData);
|
|
12015
|
-
const signatureArray = toSignatureArray(signature);
|
|
12016
|
-
const cancelPayload = stringifyBigInts({
|
|
12017
|
-
cancelation: cancelParams,
|
|
12018
|
-
signature: signatureArray
|
|
12019
|
-
});
|
|
12020
|
-
const cancelCall = contract.populate("cancel_order", [cancelPayload]);
|
|
12078
|
+
const typedData = buildCancel1155TypedData(orderHash, account.address, config);
|
|
12079
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
12080
|
+
const calls = buildCancel1155Calls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
12021
12081
|
try {
|
|
12022
|
-
const tx = await account.execute(
|
|
12082
|
+
const tx = await account.execute(calls);
|
|
12023
12083
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
12024
12084
|
return { txHash: tx.transaction_hash };
|
|
12025
12085
|
} catch (err) {
|
|
@@ -12037,56 +12097,30 @@ async function makeOffer1155(account, params, config) {
|
|
|
12037
12097
|
} = params;
|
|
12038
12098
|
const contract = getContract(config);
|
|
12039
12099
|
const provider = getProvider(config);
|
|
12040
|
-
const chainId = getChainId(config);
|
|
12041
12100
|
const token = resolveToken(currency);
|
|
12042
12101
|
const priceWei = parseAmount(price, token.decimals);
|
|
12043
12102
|
const now = Math.floor(Date.now() / 1e3);
|
|
12103
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
12044
12104
|
const endTime = now + durationSeconds;
|
|
12045
12105
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
12046
12106
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
12047
|
-
const orderParams =
|
|
12048
|
-
|
|
12049
|
-
|
|
12050
|
-
|
|
12051
|
-
|
|
12052
|
-
|
|
12053
|
-
|
|
12054
|
-
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
|
|
12058
|
-
|
|
12059
|
-
|
|
12060
|
-
identifier_or_criteria: tokenId,
|
|
12061
|
-
amount,
|
|
12062
|
-
// unit quantity
|
|
12063
|
-
recipient: account.address
|
|
12107
|
+
const { orderParams, typedData } = buildOffer1155Order(
|
|
12108
|
+
{
|
|
12109
|
+
offerer: account.address,
|
|
12110
|
+
nftContract,
|
|
12111
|
+
tokenId,
|
|
12112
|
+
quantity: amount,
|
|
12113
|
+
priceWeiPerUnit: priceWei,
|
|
12114
|
+
paymentTokenAddress: token.address,
|
|
12115
|
+
royaltyMaxBps,
|
|
12116
|
+
startTime,
|
|
12117
|
+
endTime,
|
|
12118
|
+
salt: generateSalt(),
|
|
12119
|
+
counter
|
|
12064
12120
|
},
|
|
12065
|
-
|
|
12066
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
12067
|
-
end_time: endTime.toString(),
|
|
12068
|
-
salt: generateSalt(),
|
|
12069
|
-
counter
|
|
12070
|
-
};
|
|
12071
|
-
const typedData = stringifyBigInts(
|
|
12072
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
12121
|
+
config
|
|
12073
12122
|
);
|
|
12074
|
-
const
|
|
12075
|
-
const signatureArray = toSignatureArray(signature);
|
|
12076
|
-
const registerPayload = stringifyBigInts({
|
|
12077
|
-
parameters: {
|
|
12078
|
-
...orderParams,
|
|
12079
|
-
offer: {
|
|
12080
|
-
...orderParams.offer,
|
|
12081
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
12082
|
-
},
|
|
12083
|
-
consideration: {
|
|
12084
|
-
...orderParams.consideration,
|
|
12085
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
12086
|
-
}
|
|
12087
|
-
},
|
|
12088
|
-
signature: signatureArray
|
|
12089
|
-
});
|
|
12123
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
12090
12124
|
const totalWei = BigInt(priceWei) * BigInt(amount);
|
|
12091
12125
|
const amountU256 = starknet.cairo.uint256(totalWei.toString());
|
|
12092
12126
|
const approveCall = {
|
|
@@ -12098,9 +12132,12 @@ async function makeOffer1155(account, params, config) {
|
|
|
12098
12132
|
amountU256.high.toString()
|
|
12099
12133
|
]
|
|
12100
12134
|
};
|
|
12101
|
-
const
|
|
12135
|
+
const calls = buildRegister1155Calls(
|
|
12136
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
12137
|
+
config
|
|
12138
|
+
);
|
|
12102
12139
|
try {
|
|
12103
|
-
const tx = await account.execute(
|
|
12140
|
+
const tx = await account.execute(calls);
|
|
12104
12141
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
12105
12142
|
return { txHash: tx.transaction_hash };
|
|
12106
12143
|
} catch (err) {
|
|
@@ -12990,94 +13027,147 @@ var StarknetVenue = class {
|
|
|
12990
13027
|
constructor(deps) {
|
|
12991
13028
|
this.deps = deps;
|
|
12992
13029
|
this.chain = "STARKNET";
|
|
12993
|
-
this.m721 = new MarketplaceModule(deps.config);
|
|
12994
|
-
this.m1155 = new Medialane1155Module(deps.config);
|
|
12995
13030
|
}
|
|
12996
|
-
incrementCounter(signer) {
|
|
12997
|
-
return
|
|
13031
|
+
async incrementCounter(signer) {
|
|
13032
|
+
return signer.execute([
|
|
13033
|
+
{ contractAddress: this.deps.config.marketplaceContract, entrypoint: "increment_counter", calldata: [] }
|
|
13034
|
+
]);
|
|
12998
13035
|
}
|
|
12999
13036
|
getOrderDetails(orderRef) {
|
|
13000
|
-
return this.
|
|
13037
|
+
return getOrderDetails(orderRef, this.deps.config);
|
|
13001
13038
|
}
|
|
13002
|
-
getCounter(address) {
|
|
13003
|
-
return this.
|
|
13039
|
+
async getCounter(address) {
|
|
13040
|
+
return this.readCounter(this.deps.config.marketplaceContract, address);
|
|
13004
13041
|
}
|
|
13005
13042
|
async fulfillOrder(signer, orderRef, opts) {
|
|
13006
13043
|
const o = await this.deps.resolveOrder(orderRef);
|
|
13007
13044
|
const quantity = opts?.quantity ?? "1";
|
|
13008
13045
|
const totalPrice = (BigInt(o.unitPrice) * BigInt(quantity)).toString();
|
|
13009
|
-
|
|
13010
|
-
|
|
13011
|
-
orderHash: orderRef,
|
|
13012
|
-
paymentToken: o.paymentToken,
|
|
13013
|
-
totalPrice,
|
|
13014
|
-
quantity
|
|
13015
|
-
});
|
|
13016
|
-
}
|
|
13017
|
-
return this.m721.fulfillOrder(signer, {
|
|
13018
|
-
orderHash: orderRef,
|
|
13019
|
-
paymentToken: o.paymentToken,
|
|
13020
|
-
totalPrice
|
|
13021
|
-
});
|
|
13046
|
+
const calls = o.standard === "ERC1155" ? buildFulfill1155Calls({ orderHash: orderRef, paymentToken: o.paymentToken, totalPrice, quantity }, this.deps.config) : buildFulfillCalls({ orderHash: orderRef, paymentToken: o.paymentToken, totalPrice }, this.deps.config);
|
|
13047
|
+
return signer.execute(calls);
|
|
13022
13048
|
}
|
|
13023
13049
|
async cancelOrder(signer, orderRef) {
|
|
13024
13050
|
const o = await this.deps.resolveOrder(orderRef);
|
|
13025
|
-
|
|
13026
|
-
|
|
13027
|
-
}
|
|
13028
|
-
return
|
|
13051
|
+
const typedData = o.standard === "ERC1155" ? buildCancel1155TypedData(orderRef, signer.address, this.deps.config) : buildCancelTypedData(orderRef, signer.address, this.deps.config);
|
|
13052
|
+
const signature = await signer.signTypedData(typedData);
|
|
13053
|
+
const calls = o.standard === "ERC1155" ? buildCancel1155Calls({ orderHash: orderRef, offerer: signer.address, signature }, this.deps.config) : buildCancelCalls({ orderHash: orderRef, offerer: signer.address, signature }, this.deps.config);
|
|
13054
|
+
return signer.execute(calls);
|
|
13029
13055
|
}
|
|
13030
13056
|
async registerOrder(signer, p) {
|
|
13031
13057
|
const standard = await this.deps.resolveStandard(p.asset.contract);
|
|
13032
|
-
const
|
|
13033
|
-
const humanPrice = formatAmount(p.amount, token.decimals);
|
|
13034
|
-
const durationSeconds = this.durationSeconds(p.endTime);
|
|
13058
|
+
const paymentTokenAddress = resolveToken(p.paymentToken).address;
|
|
13035
13059
|
const royaltyMaxBps = String(p.royaltyMaxBps);
|
|
13060
|
+
const startTime = Math.floor(Date.now() / 1e3) + START_TIME_BUFFER_SECS;
|
|
13061
|
+
const endTime = p.endTime && p.endTime > 0 ? p.endTime : startTime + NO_EXPIRY_SECONDS;
|
|
13036
13062
|
const quantity = p.quantity ?? "1";
|
|
13037
|
-
|
|
13063
|
+
const marketplace = standard === "ERC1155" ? this.deps.config.marketplace1155Contract : this.deps.config.marketplaceContract;
|
|
13064
|
+
const counter = String(await this.readCounter(marketplace, signer.address));
|
|
13065
|
+
let typedData;
|
|
13066
|
+
let buildCalls;
|
|
13038
13067
|
if (standard === "ERC1155") {
|
|
13039
|
-
|
|
13040
|
-
|
|
13068
|
+
const built = (p.side === "listing" ? buildListing1155Order : buildOffer1155Order)(
|
|
13069
|
+
{
|
|
13070
|
+
offerer: signer.address,
|
|
13041
13071
|
nftContract: p.asset.contract,
|
|
13042
13072
|
tokenId: p.asset.tokenId,
|
|
13043
|
-
|
|
13044
|
-
|
|
13045
|
-
|
|
13046
|
-
|
|
13047
|
-
|
|
13048
|
-
|
|
13049
|
-
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
13073
|
+
quantity,
|
|
13074
|
+
priceWeiPerUnit: p.amount,
|
|
13075
|
+
paymentTokenAddress,
|
|
13076
|
+
royaltyMaxBps,
|
|
13077
|
+
startTime,
|
|
13078
|
+
endTime,
|
|
13079
|
+
salt: p.salt,
|
|
13080
|
+
counter
|
|
13081
|
+
},
|
|
13082
|
+
this.deps.config
|
|
13083
|
+
);
|
|
13084
|
+
typedData = built.typedData;
|
|
13085
|
+
const approval = p.side === "listing" ? await this.approval1155ForListing(signer.address, p.asset.contract) : this.approvalForErc20(paymentTokenAddress, (BigInt(p.amount) * BigInt(quantity)).toString(), marketplace);
|
|
13086
|
+
buildCalls = (sig) => buildRegister1155Calls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
13087
|
+
} else {
|
|
13088
|
+
const built = (p.side === "listing" ? buildListingOrder : buildOfferOrder)(
|
|
13089
|
+
{
|
|
13090
|
+
offerer: signer.address,
|
|
13053
13091
|
nftContract: p.asset.contract,
|
|
13054
13092
|
tokenId: p.asset.tokenId,
|
|
13055
|
-
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
|
|
13060
|
-
|
|
13061
|
-
|
|
13062
|
-
|
|
13063
|
-
|
|
13064
|
-
|
|
13065
|
-
|
|
13066
|
-
|
|
13067
|
-
|
|
13068
|
-
currency: p.paymentToken,
|
|
13069
|
-
durationSeconds,
|
|
13070
|
-
royaltyMaxBps
|
|
13071
|
-
};
|
|
13072
|
-
const res = p.side === "listing" ? await this.m721.createListing(signer, params) : await this.m721.makeOffer(signer, params);
|
|
13073
|
-
txHash = res.txHash;
|
|
13093
|
+
priceWei: p.amount,
|
|
13094
|
+
paymentTokenAddress,
|
|
13095
|
+
royaltyMaxBps,
|
|
13096
|
+
startTime,
|
|
13097
|
+
endTime,
|
|
13098
|
+
salt: p.salt,
|
|
13099
|
+
counter
|
|
13100
|
+
},
|
|
13101
|
+
this.deps.config
|
|
13102
|
+
);
|
|
13103
|
+
typedData = built.typedData;
|
|
13104
|
+
const approval = p.side === "listing" ? await this.approval721ForListing(signer.address, p.asset.contract, p.asset.tokenId) : this.approvalForErc20(paymentTokenAddress, p.amount, marketplace);
|
|
13105
|
+
buildCalls = (sig) => buildRegisterCalls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
13074
13106
|
}
|
|
13107
|
+
const signature = await signer.signTypedData(typedData);
|
|
13108
|
+
const { txHash } = await signer.execute(buildCalls(signature));
|
|
13075
13109
|
const orderRef = await this.orderRefFromReceipt(txHash);
|
|
13076
13110
|
return { txHash, orderRef };
|
|
13077
13111
|
}
|
|
13078
|
-
|
|
13079
|
-
|
|
13080
|
-
|
|
13112
|
+
// ─── reads (all on deps.provider) ─────────────────────────────────────────
|
|
13113
|
+
async readCounter(marketplace, address) {
|
|
13114
|
+
const res = await this.deps.provider.callContract({
|
|
13115
|
+
contractAddress: marketplace,
|
|
13116
|
+
entrypoint: "get_counter",
|
|
13117
|
+
calldata: [address]
|
|
13118
|
+
});
|
|
13119
|
+
return BigInt(res[0] ?? "0");
|
|
13120
|
+
}
|
|
13121
|
+
/** 721 listing approval: `get_approved(tokenId) == marketplace` ⇒ no approve. */
|
|
13122
|
+
async approval721ForListing(_owner, nftContract, tokenId) {
|
|
13123
|
+
const id = starknet.cairo.uint256(tokenId);
|
|
13124
|
+
const approve = {
|
|
13125
|
+
contractAddress: nftContract,
|
|
13126
|
+
entrypoint: "approve",
|
|
13127
|
+
calldata: [this.deps.config.marketplaceContract, id.low.toString(), id.high.toString()]
|
|
13128
|
+
};
|
|
13129
|
+
let approved = false;
|
|
13130
|
+
try {
|
|
13131
|
+
const res = await this.deps.provider.callContract({
|
|
13132
|
+
contractAddress: nftContract,
|
|
13133
|
+
entrypoint: "get_approved",
|
|
13134
|
+
calldata: [id.low.toString(), id.high.toString()]
|
|
13135
|
+
});
|
|
13136
|
+
approved = BigInt(res[0]).toString() === BigInt(this.deps.config.marketplaceContract).toString();
|
|
13137
|
+
} catch {
|
|
13138
|
+
}
|
|
13139
|
+
return { approvalNeeded: !approved, approve };
|
|
13140
|
+
}
|
|
13141
|
+
/** 1155 listing approval: `is_approved_for_all(owner, marketplace)`. */
|
|
13142
|
+
async approval1155ForListing(owner, nftContract) {
|
|
13143
|
+
const approve = {
|
|
13144
|
+
contractAddress: nftContract,
|
|
13145
|
+
entrypoint: "set_approval_for_all",
|
|
13146
|
+
calldata: [this.deps.config.marketplace1155Contract, "1"]
|
|
13147
|
+
};
|
|
13148
|
+
let approved = false;
|
|
13149
|
+
try {
|
|
13150
|
+
const res = await this.deps.provider.callContract({
|
|
13151
|
+
contractAddress: nftContract,
|
|
13152
|
+
entrypoint: "is_approved_for_all",
|
|
13153
|
+
calldata: [owner, this.deps.config.marketplace1155Contract]
|
|
13154
|
+
});
|
|
13155
|
+
approved = BigInt(res[0]) === 1n;
|
|
13156
|
+
} catch {
|
|
13157
|
+
}
|
|
13158
|
+
return { approvalNeeded: !approved, approve };
|
|
13159
|
+
}
|
|
13160
|
+
/** Offers always approve the ERC-20 spend (no read). */
|
|
13161
|
+
approvalForErc20(token, amountWei, marketplace) {
|
|
13162
|
+
const u = starknet.cairo.uint256(amountWei);
|
|
13163
|
+
return {
|
|
13164
|
+
approvalNeeded: true,
|
|
13165
|
+
approve: {
|
|
13166
|
+
contractAddress: token,
|
|
13167
|
+
entrypoint: "approve",
|
|
13168
|
+
calldata: [marketplace, u.low.toString(), u.high.toString()]
|
|
13169
|
+
}
|
|
13170
|
+
};
|
|
13081
13171
|
}
|
|
13082
13172
|
/** The canonical Starknet order id = the contract-emitted `OrderCreated`
|
|
13083
13173
|
* hash (`keys[1]`), which is exactly what the indexer stores. */
|