@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/starknet/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { hash, num, cairo, Contract, uint256, RpcProvider, CairoOption, CairoOptionVariant, ec, encode, TypedDataRevision,
|
|
2
|
+
import { hash, num, cairo, Contract, uint256, RpcProvider, CairoOption, CairoOptionVariant, ec, encode, TypedDataRevision, constants, shortString } from 'starknet';
|
|
3
3
|
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
4
4
|
import { base32, base58 } from '@scure/base';
|
|
5
5
|
|
|
@@ -35,9 +35,9 @@ var COORDINATES = {
|
|
|
35
35
|
creatorCoinFactoryClassHash: "0x51765926b1344c9a20b8cd4b5abe7b7d47375ae97cf6804db3ea5d4b05a9b55",
|
|
36
36
|
creatorCoinStartBlock: 10474544,
|
|
37
37
|
ekuboCore: "0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b",
|
|
38
|
-
ipTicketsFactory: "
|
|
39
|
-
ipTicketCollectionClassHash: "
|
|
40
|
-
ipTicketsStartBlock:
|
|
38
|
+
ipTicketsFactory: "0x03ffef4162fe2c44e17d6be2aad3553cab0ac2274cd0b1bb3fafb12fd66695c1",
|
|
39
|
+
ipTicketCollectionClassHash: "0x036393fb4241ed55bd12d8b328ed877d08100fadf9150a650e2b84cbab95e1d4",
|
|
40
|
+
ipTicketsStartBlock: 11689800,
|
|
41
41
|
ipClubRegistry: "0x00e189c619b6bb07d78973a149641c59c37eb0716f8584d7520bce12d303eede",
|
|
42
42
|
ipClubNftClassHash: "0x02bc9b20cca21b04245e9215bf7121f4d7295b195890e449b472b573017fb889",
|
|
43
43
|
ipClubStartBlock: 11404776,
|
|
@@ -10342,39 +10342,12 @@ var SUPPORTED_TOKENS = [
|
|
|
10342
10342
|
];
|
|
10343
10343
|
var DEFAULT_CURRENCY = "USDC";
|
|
10344
10344
|
|
|
10345
|
-
// src/utils/bigint.ts
|
|
10346
|
-
function stringifyBigInts(obj) {
|
|
10347
|
-
if (typeof obj === "bigint") {
|
|
10348
|
-
return obj.toString();
|
|
10349
|
-
}
|
|
10350
|
-
if (Array.isArray(obj)) {
|
|
10351
|
-
return obj.map(stringifyBigInts);
|
|
10352
|
-
}
|
|
10353
|
-
if (obj !== null && typeof obj === "object") {
|
|
10354
|
-
return Object.fromEntries(
|
|
10355
|
-
Object.entries(obj).map(([key, value]) => [
|
|
10356
|
-
key,
|
|
10357
|
-
stringifyBigInts(value)
|
|
10358
|
-
])
|
|
10359
|
-
);
|
|
10360
|
-
}
|
|
10361
|
-
return obj;
|
|
10362
|
-
}
|
|
10363
|
-
|
|
10364
10345
|
// src/utils/token.ts
|
|
10365
10346
|
function parseAmount(human, decimals) {
|
|
10366
10347
|
const [whole, frac = ""] = human.split(".");
|
|
10367
10348
|
const fracPadded = frac.padEnd(decimals, "0").slice(0, decimals);
|
|
10368
10349
|
return (BigInt(whole) * BigInt(10) ** BigInt(decimals) + BigInt(fracPadded)).toString();
|
|
10369
10350
|
}
|
|
10370
|
-
function formatAmount(raw, decimals) {
|
|
10371
|
-
const value = BigInt(raw);
|
|
10372
|
-
const factor = BigInt(Math.pow(10, decimals));
|
|
10373
|
-
const whole = value / factor;
|
|
10374
|
-
const remainder = value % factor;
|
|
10375
|
-
const fractional = remainder.toString().padStart(decimals, "0");
|
|
10376
|
-
return `${whole}.${fractional}`;
|
|
10377
|
-
}
|
|
10378
10351
|
function getTokenByAddress(address) {
|
|
10379
10352
|
const lower = address.toLowerCase();
|
|
10380
10353
|
return SUPPORTED_TOKENS.find((t) => t.address.toLowerCase() === lower);
|
|
@@ -10403,6 +10376,25 @@ function buildFeeCall(p, cfg) {
|
|
|
10403
10376
|
};
|
|
10404
10377
|
}
|
|
10405
10378
|
|
|
10379
|
+
// src/utils/bigint.ts
|
|
10380
|
+
function stringifyBigInts(obj) {
|
|
10381
|
+
if (typeof obj === "bigint") {
|
|
10382
|
+
return obj.toString();
|
|
10383
|
+
}
|
|
10384
|
+
if (Array.isArray(obj)) {
|
|
10385
|
+
return obj.map(stringifyBigInts);
|
|
10386
|
+
}
|
|
10387
|
+
if (obj !== null && typeof obj === "object") {
|
|
10388
|
+
return Object.fromEntries(
|
|
10389
|
+
Object.entries(obj).map(([key, value]) => [
|
|
10390
|
+
key,
|
|
10391
|
+
stringifyBigInts(value)
|
|
10392
|
+
])
|
|
10393
|
+
);
|
|
10394
|
+
}
|
|
10395
|
+
return obj;
|
|
10396
|
+
}
|
|
10397
|
+
|
|
10406
10398
|
// src/utils/rpc.ts
|
|
10407
10399
|
var PUBLIC_RPC_FALLBACKS = [
|
|
10408
10400
|
"https://rpc.starknet.lava.build"
|
|
@@ -10483,6 +10475,14 @@ function toSignatureArray(sig) {
|
|
|
10483
10475
|
const s = sig;
|
|
10484
10476
|
return [s.r.toString(), s.s.toString()];
|
|
10485
10477
|
}
|
|
10478
|
+
function newContract(abi, address, providerOrAccount) {
|
|
10479
|
+
const C = Contract;
|
|
10480
|
+
return C.length === 1 ? new Contract({ abi, address, providerOrAccount }) : new Contract(
|
|
10481
|
+
abi,
|
|
10482
|
+
address,
|
|
10483
|
+
providerOrAccount
|
|
10484
|
+
);
|
|
10485
|
+
}
|
|
10486
10486
|
function getChainId(config) {
|
|
10487
10487
|
if (config.chain !== "STARKNET") {
|
|
10488
10488
|
throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
|
|
@@ -10507,17 +10507,101 @@ function getProvider(config) {
|
|
|
10507
10507
|
return p;
|
|
10508
10508
|
}
|
|
10509
10509
|
|
|
10510
|
+
// src/starknet/marketplace/build.ts
|
|
10511
|
+
function contractFor(cfg) {
|
|
10512
|
+
return newContract(IPMarketplaceABI, cfg.marketplaceContract, getProvider(cfg));
|
|
10513
|
+
}
|
|
10514
|
+
function buildListingOrder(i, cfg) {
|
|
10515
|
+
const orderParams = {
|
|
10516
|
+
offerer: i.offerer,
|
|
10517
|
+
marketplace: cfg.marketplaceContract,
|
|
10518
|
+
offer: { item_type: "ERC721", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: "1" },
|
|
10519
|
+
consideration: {
|
|
10520
|
+
item_type: "ERC20",
|
|
10521
|
+
token: i.paymentTokenAddress,
|
|
10522
|
+
identifier_or_criteria: "0",
|
|
10523
|
+
amount: i.priceWei,
|
|
10524
|
+
recipient: i.offerer
|
|
10525
|
+
},
|
|
10526
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
10527
|
+
start_time: String(i.startTime),
|
|
10528
|
+
end_time: String(i.endTime),
|
|
10529
|
+
salt: i.salt,
|
|
10530
|
+
counter: i.counter
|
|
10531
|
+
};
|
|
10532
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
10533
|
+
return { orderParams, typedData };
|
|
10534
|
+
}
|
|
10535
|
+
function buildOfferOrder(i, cfg) {
|
|
10536
|
+
const orderParams = {
|
|
10537
|
+
offerer: i.offerer,
|
|
10538
|
+
marketplace: cfg.marketplaceContract,
|
|
10539
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWei },
|
|
10540
|
+
consideration: {
|
|
10541
|
+
item_type: "ERC721",
|
|
10542
|
+
token: i.nftContract,
|
|
10543
|
+
identifier_or_criteria: i.tokenId,
|
|
10544
|
+
amount: "1",
|
|
10545
|
+
recipient: i.offerer
|
|
10546
|
+
},
|
|
10547
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
10548
|
+
start_time: String(i.startTime),
|
|
10549
|
+
end_time: String(i.endTime),
|
|
10550
|
+
salt: i.salt,
|
|
10551
|
+
counter: i.counter
|
|
10552
|
+
};
|
|
10553
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
10554
|
+
return { orderParams, typedData };
|
|
10555
|
+
}
|
|
10556
|
+
function registerPayload(orderParams, signature) {
|
|
10557
|
+
return stringifyBigInts({
|
|
10558
|
+
parameters: {
|
|
10559
|
+
...orderParams,
|
|
10560
|
+
offer: { ...orderParams.offer, item_type: shortString.encodeShortString(orderParams.offer.item_type) },
|
|
10561
|
+
consideration: {
|
|
10562
|
+
...orderParams.consideration,
|
|
10563
|
+
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10564
|
+
}
|
|
10565
|
+
},
|
|
10566
|
+
signature
|
|
10567
|
+
});
|
|
10568
|
+
}
|
|
10569
|
+
function buildRegisterCalls(a, cfg) {
|
|
10570
|
+
const registerCall = contractFor(cfg).populate("register_order", [registerPayload(a.orderParams, a.signature)]);
|
|
10571
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
10572
|
+
}
|
|
10573
|
+
function buildFulfillCalls(a, cfg) {
|
|
10574
|
+
const u = cairo.uint256(a.totalPrice);
|
|
10575
|
+
const approve = {
|
|
10576
|
+
contractAddress: a.paymentToken,
|
|
10577
|
+
entrypoint: "approve",
|
|
10578
|
+
calldata: [cfg.marketplaceContract, u.low.toString(), u.high.toString()]
|
|
10579
|
+
};
|
|
10580
|
+
const fulfill = contractFor(cfg).populate("fulfill_order", [a.orderHash]);
|
|
10581
|
+
const fee = buildFeeCall(
|
|
10582
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
10583
|
+
cfg.feeConfig
|
|
10584
|
+
);
|
|
10585
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
10586
|
+
}
|
|
10587
|
+
function buildCancelCalls(a, cfg) {
|
|
10588
|
+
const cancelRequest = stringifyBigInts({
|
|
10589
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
10590
|
+
signature: a.signature
|
|
10591
|
+
});
|
|
10592
|
+
return [contractFor(cfg).populate("cancel_order", [cancelRequest])];
|
|
10593
|
+
}
|
|
10594
|
+
function buildCancelTypedData(orderHash, offerer, cfg) {
|
|
10595
|
+
return stringifyBigInts(buildCancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg)));
|
|
10596
|
+
}
|
|
10597
|
+
|
|
10510
10598
|
// src/starknet/marketplace/orders.ts
|
|
10511
10599
|
var _contractCache = /* @__PURE__ */ new WeakMap();
|
|
10512
10600
|
function makeContract(config) {
|
|
10513
10601
|
const cached = _contractCache.get(config);
|
|
10514
10602
|
const provider = getProvider(config);
|
|
10515
10603
|
if (cached) return { ...cached, provider };
|
|
10516
|
-
const contract =
|
|
10517
|
-
IPMarketplaceABI,
|
|
10518
|
-
config.marketplaceContract,
|
|
10519
|
-
provider
|
|
10520
|
-
);
|
|
10604
|
+
const contract = newContract(IPMarketplaceABI, config.marketplaceContract, provider);
|
|
10521
10605
|
_contractCache.set(config, { contract });
|
|
10522
10606
|
return { contract, provider };
|
|
10523
10607
|
}
|
|
@@ -10531,46 +10615,22 @@ async function createListing(account, params, config) {
|
|
|
10531
10615
|
const endTime = now + durationSeconds;
|
|
10532
10616
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
10533
10617
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
10534
|
-
const orderParams =
|
|
10535
|
-
|
|
10536
|
-
|
|
10537
|
-
|
|
10538
|
-
|
|
10539
|
-
|
|
10540
|
-
|
|
10541
|
-
|
|
10542
|
-
|
|
10543
|
-
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
identifier_or_criteria: "0",
|
|
10547
|
-
amount: priceWei,
|
|
10548
|
-
recipient: account.address
|
|
10549
|
-
},
|
|
10550
|
-
royalty_max_bps: royaltyMaxBps,
|
|
10551
|
-
start_time: startTime.toString(),
|
|
10552
|
-
end_time: endTime.toString(),
|
|
10553
|
-
salt: generateSalt(),
|
|
10554
|
-
counter
|
|
10555
|
-
};
|
|
10556
|
-
const chainId = getChainId(config);
|
|
10557
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
10558
|
-
const signature = await account.signMessage(typedData);
|
|
10559
|
-
const signatureArray = toSignatureArray(signature);
|
|
10560
|
-
const registerPayload = stringifyBigInts({
|
|
10561
|
-
parameters: {
|
|
10562
|
-
...orderParams,
|
|
10563
|
-
offer: {
|
|
10564
|
-
...orderParams.offer,
|
|
10565
|
-
item_type: shortString.encodeShortString(orderParams.offer.item_type)
|
|
10566
|
-
},
|
|
10567
|
-
consideration: {
|
|
10568
|
-
...orderParams.consideration,
|
|
10569
|
-
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10570
|
-
}
|
|
10618
|
+
const { orderParams, typedData } = buildListingOrder(
|
|
10619
|
+
{
|
|
10620
|
+
offerer: account.address,
|
|
10621
|
+
nftContract,
|
|
10622
|
+
tokenId,
|
|
10623
|
+
priceWei,
|
|
10624
|
+
paymentTokenAddress: token.address,
|
|
10625
|
+
royaltyMaxBps,
|
|
10626
|
+
startTime,
|
|
10627
|
+
endTime,
|
|
10628
|
+
salt: generateSalt(),
|
|
10629
|
+
counter
|
|
10571
10630
|
},
|
|
10572
|
-
|
|
10573
|
-
|
|
10631
|
+
config
|
|
10632
|
+
);
|
|
10633
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10574
10634
|
const tokenIdUint256 = cairo.uint256(tokenId);
|
|
10575
10635
|
let isAlreadyApproved = false;
|
|
10576
10636
|
try {
|
|
@@ -10582,19 +10642,19 @@ async function createListing(account, params, config) {
|
|
|
10582
10642
|
isAlreadyApproved = BigInt(result[0]).toString() === BigInt(config.marketplaceContract).toString();
|
|
10583
10643
|
} catch {
|
|
10584
10644
|
}
|
|
10585
|
-
const
|
|
10586
|
-
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
|
|
10595
|
-
},
|
|
10596
|
-
|
|
10597
|
-
|
|
10645
|
+
const approve = {
|
|
10646
|
+
contractAddress: nftContract,
|
|
10647
|
+
entrypoint: "approve",
|
|
10648
|
+
calldata: [
|
|
10649
|
+
config.marketplaceContract,
|
|
10650
|
+
tokenIdUint256.low.toString(),
|
|
10651
|
+
tokenIdUint256.high.toString()
|
|
10652
|
+
]
|
|
10653
|
+
};
|
|
10654
|
+
const calls = buildRegisterCalls(
|
|
10655
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isAlreadyApproved, approve },
|
|
10656
|
+
config
|
|
10657
|
+
);
|
|
10598
10658
|
try {
|
|
10599
10659
|
const tx = await account.execute(calls);
|
|
10600
10660
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -10613,46 +10673,22 @@ async function makeOffer(account, params, config) {
|
|
|
10613
10673
|
const endTime = now + durationSeconds;
|
|
10614
10674
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
10615
10675
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
10616
|
-
const orderParams =
|
|
10617
|
-
|
|
10618
|
-
|
|
10619
|
-
|
|
10620
|
-
|
|
10621
|
-
|
|
10622
|
-
|
|
10623
|
-
|
|
10624
|
-
|
|
10625
|
-
|
|
10626
|
-
|
|
10627
|
-
|
|
10628
|
-
identifier_or_criteria: tokenId,
|
|
10629
|
-
amount: "1",
|
|
10630
|
-
recipient: account.address
|
|
10631
|
-
},
|
|
10632
|
-
royalty_max_bps: royaltyMaxBps,
|
|
10633
|
-
start_time: startTime.toString(),
|
|
10634
|
-
end_time: endTime.toString(),
|
|
10635
|
-
salt: generateSalt(),
|
|
10636
|
-
counter
|
|
10637
|
-
};
|
|
10638
|
-
const chainId = getChainId(config);
|
|
10639
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
10640
|
-
const signature = await account.signMessage(typedData);
|
|
10641
|
-
const signatureArray = toSignatureArray(signature);
|
|
10642
|
-
const registerPayload = stringifyBigInts({
|
|
10643
|
-
parameters: {
|
|
10644
|
-
...orderParams,
|
|
10645
|
-
offer: {
|
|
10646
|
-
...orderParams.offer,
|
|
10647
|
-
item_type: shortString.encodeShortString(orderParams.offer.item_type)
|
|
10648
|
-
},
|
|
10649
|
-
consideration: {
|
|
10650
|
-
...orderParams.consideration,
|
|
10651
|
-
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10652
|
-
}
|
|
10676
|
+
const { orderParams, typedData } = buildOfferOrder(
|
|
10677
|
+
{
|
|
10678
|
+
offerer: account.address,
|
|
10679
|
+
nftContract,
|
|
10680
|
+
tokenId,
|
|
10681
|
+
priceWei,
|
|
10682
|
+
paymentTokenAddress: token.address,
|
|
10683
|
+
royaltyMaxBps,
|
|
10684
|
+
startTime,
|
|
10685
|
+
endTime,
|
|
10686
|
+
salt: generateSalt(),
|
|
10687
|
+
counter
|
|
10653
10688
|
},
|
|
10654
|
-
|
|
10655
|
-
|
|
10689
|
+
config
|
|
10690
|
+
);
|
|
10691
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10656
10692
|
const amountUint256 = cairo.uint256(priceWei);
|
|
10657
10693
|
const approveCall = {
|
|
10658
10694
|
contractAddress: token.address,
|
|
@@ -10663,9 +10699,12 @@ async function makeOffer(account, params, config) {
|
|
|
10663
10699
|
amountUint256.high.toString()
|
|
10664
10700
|
]
|
|
10665
10701
|
};
|
|
10666
|
-
const
|
|
10702
|
+
const calls = buildRegisterCalls(
|
|
10703
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
10704
|
+
config
|
|
10705
|
+
);
|
|
10667
10706
|
try {
|
|
10668
|
-
const tx = await account.execute(
|
|
10707
|
+
const tx = await account.execute(calls);
|
|
10669
10708
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
10670
10709
|
return { txHash: tx.transaction_hash };
|
|
10671
10710
|
} catch (err) {
|
|
@@ -10674,23 +10713,8 @@ async function makeOffer(account, params, config) {
|
|
|
10674
10713
|
}
|
|
10675
10714
|
async function fulfillOrder(account, params, config) {
|
|
10676
10715
|
const { orderHash, paymentToken, totalPrice } = params;
|
|
10677
|
-
const {
|
|
10678
|
-
const
|
|
10679
|
-
const approveCall = {
|
|
10680
|
-
contractAddress: paymentToken,
|
|
10681
|
-
entrypoint: "approve",
|
|
10682
|
-
calldata: [
|
|
10683
|
-
config.marketplaceContract,
|
|
10684
|
-
totalPriceU256.low.toString(),
|
|
10685
|
-
totalPriceU256.high.toString()
|
|
10686
|
-
]
|
|
10687
|
-
};
|
|
10688
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash]);
|
|
10689
|
-
const feeCall = buildFeeCall(
|
|
10690
|
-
{ surface: "marketplace", token: paymentToken, grossAmount: BigInt(totalPrice) },
|
|
10691
|
-
config.feeConfig
|
|
10692
|
-
);
|
|
10693
|
-
const calls = feeCall ? [approveCall, fulfillCall, feeCall] : [approveCall, fulfillCall];
|
|
10716
|
+
const { provider } = makeContract(config);
|
|
10717
|
+
const calls = buildFulfillCalls({ orderHash, paymentToken, totalPrice }, config);
|
|
10694
10718
|
try {
|
|
10695
10719
|
const tx = await account.execute(calls);
|
|
10696
10720
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -10701,24 +10725,12 @@ async function fulfillOrder(account, params, config) {
|
|
|
10701
10725
|
}
|
|
10702
10726
|
async function cancelOrder(account, params, config) {
|
|
10703
10727
|
const { orderHash } = params;
|
|
10704
|
-
const {
|
|
10705
|
-
const
|
|
10706
|
-
const
|
|
10707
|
-
|
|
10708
|
-
offerer: account.address
|
|
10709
|
-
};
|
|
10710
|
-
const typedData = stringifyBigInts(
|
|
10711
|
-
buildCancellationTypedData(cancelParams, chainId)
|
|
10712
|
-
);
|
|
10713
|
-
const signature = await account.signMessage(typedData);
|
|
10714
|
-
const signatureArray = toSignatureArray(signature);
|
|
10715
|
-
const cancelRequest = stringifyBigInts({
|
|
10716
|
-
cancelation: cancelParams,
|
|
10717
|
-
signature: signatureArray
|
|
10718
|
-
});
|
|
10719
|
-
const call = contract.populate("cancel_order", [cancelRequest]);
|
|
10728
|
+
const { provider } = makeContract(config);
|
|
10729
|
+
const typedData = buildCancelTypedData(orderHash, account.address, config);
|
|
10730
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10731
|
+
const calls = buildCancelCalls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
10720
10732
|
try {
|
|
10721
|
-
const tx = await account.execute(
|
|
10733
|
+
const tx = await account.execute(calls);
|
|
10722
10734
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
10723
10735
|
return { txHash: tx.transaction_hash };
|
|
10724
10736
|
} catch (err) {
|
|
@@ -10865,16 +10877,106 @@ var MarketplaceModule = class {
|
|
|
10865
10877
|
return buildCancellationTypedData(params, chainId);
|
|
10866
10878
|
}
|
|
10867
10879
|
};
|
|
10880
|
+
function contractFor2(cfg) {
|
|
10881
|
+
return newContract(Medialane1155ABI, cfg.marketplace1155Contract, getProvider(cfg));
|
|
10882
|
+
}
|
|
10883
|
+
function buildListing1155Order(i, cfg) {
|
|
10884
|
+
const orderParams = {
|
|
10885
|
+
offerer: i.offerer,
|
|
10886
|
+
marketplace: cfg.marketplace1155Contract,
|
|
10887
|
+
offer: { item_type: "ERC1155", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: i.quantity },
|
|
10888
|
+
consideration: {
|
|
10889
|
+
item_type: "ERC20",
|
|
10890
|
+
token: i.paymentTokenAddress,
|
|
10891
|
+
identifier_or_criteria: "0",
|
|
10892
|
+
amount: i.priceWeiPerUnit,
|
|
10893
|
+
recipient: i.offerer
|
|
10894
|
+
},
|
|
10895
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
10896
|
+
start_time: String(i.startTime),
|
|
10897
|
+
end_time: String(i.endTime),
|
|
10898
|
+
salt: i.salt,
|
|
10899
|
+
counter: i.counter
|
|
10900
|
+
};
|
|
10901
|
+
const typedData = stringifyBigInts(
|
|
10902
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
10903
|
+
);
|
|
10904
|
+
return { orderParams, typedData };
|
|
10905
|
+
}
|
|
10906
|
+
function buildOffer1155Order(i, cfg) {
|
|
10907
|
+
const orderParams = {
|
|
10908
|
+
offerer: i.offerer,
|
|
10909
|
+
marketplace: cfg.marketplace1155Contract,
|
|
10910
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWeiPerUnit },
|
|
10911
|
+
consideration: {
|
|
10912
|
+
item_type: "ERC1155",
|
|
10913
|
+
token: i.nftContract,
|
|
10914
|
+
identifier_or_criteria: i.tokenId,
|
|
10915
|
+
amount: i.quantity,
|
|
10916
|
+
recipient: i.offerer
|
|
10917
|
+
},
|
|
10918
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
10919
|
+
start_time: String(i.startTime),
|
|
10920
|
+
end_time: String(i.endTime),
|
|
10921
|
+
salt: i.salt,
|
|
10922
|
+
counter: i.counter
|
|
10923
|
+
};
|
|
10924
|
+
const typedData = stringifyBigInts(
|
|
10925
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
10926
|
+
);
|
|
10927
|
+
return { orderParams, typedData };
|
|
10928
|
+
}
|
|
10929
|
+
function registerPayload2(orderParams, signature) {
|
|
10930
|
+
return stringifyBigInts({
|
|
10931
|
+
parameters: {
|
|
10932
|
+
...orderParams,
|
|
10933
|
+
offer: { ...orderParams.offer, item_type: shortString.encodeShortString(orderParams.offer.item_type) },
|
|
10934
|
+
consideration: {
|
|
10935
|
+
...orderParams.consideration,
|
|
10936
|
+
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10937
|
+
}
|
|
10938
|
+
},
|
|
10939
|
+
signature
|
|
10940
|
+
});
|
|
10941
|
+
}
|
|
10942
|
+
function buildRegister1155Calls(a, cfg) {
|
|
10943
|
+
const registerCall = contractFor2(cfg).populate("register_order", [registerPayload2(a.orderParams, a.signature)]);
|
|
10944
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
10945
|
+
}
|
|
10946
|
+
function buildFulfill1155Calls(a, cfg) {
|
|
10947
|
+
const u = cairo.uint256(a.totalPrice);
|
|
10948
|
+
const approve = {
|
|
10949
|
+
contractAddress: a.paymentToken,
|
|
10950
|
+
entrypoint: "approve",
|
|
10951
|
+
calldata: [cfg.marketplace1155Contract, u.low.toString(), u.high.toString()]
|
|
10952
|
+
};
|
|
10953
|
+
const fulfill = contractFor2(cfg).populate("fulfill_order", [a.orderHash, a.quantity]);
|
|
10954
|
+
const fee = buildFeeCall(
|
|
10955
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
10956
|
+
cfg.feeConfig
|
|
10957
|
+
);
|
|
10958
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
10959
|
+
}
|
|
10960
|
+
function buildCancel1155Calls(a, cfg) {
|
|
10961
|
+
const cancelPayload = stringifyBigInts({
|
|
10962
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
10963
|
+
signature: a.signature
|
|
10964
|
+
});
|
|
10965
|
+
return [contractFor2(cfg).populate("cancel_order", [cancelPayload])];
|
|
10966
|
+
}
|
|
10967
|
+
function buildCancel1155TypedData(orderHash, offerer, cfg) {
|
|
10968
|
+
return stringifyBigInts(
|
|
10969
|
+
build1155CancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg))
|
|
10970
|
+
);
|
|
10971
|
+
}
|
|
10972
|
+
|
|
10973
|
+
// src/starknet/marketplace1155/orders.ts
|
|
10868
10974
|
var _contractCache2 = /* @__PURE__ */ new WeakMap();
|
|
10869
10975
|
function getContract(config) {
|
|
10870
10976
|
let c = _contractCache2.get(config);
|
|
10871
10977
|
if (!c) {
|
|
10872
10978
|
const provider = getProvider(config);
|
|
10873
|
-
c =
|
|
10874
|
-
Medialane1155ABI,
|
|
10875
|
-
config.marketplace1155Contract,
|
|
10876
|
-
provider
|
|
10877
|
-
);
|
|
10979
|
+
c = newContract(Medialane1155ABI, config.marketplace1155Contract, provider);
|
|
10878
10980
|
_contractCache2.set(config, c);
|
|
10879
10981
|
}
|
|
10880
10982
|
return c;
|
|
@@ -10893,53 +10995,27 @@ async function createListing1155(account, params, config) {
|
|
|
10893
10995
|
const token = resolveToken(currency);
|
|
10894
10996
|
const priceWei = parseAmount(pricePerUnit, token.decimals);
|
|
10895
10997
|
const now = Math.floor(Date.now() / 1e3);
|
|
10998
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
10896
10999
|
const endTime = now + durationSeconds;
|
|
10897
|
-
const chainId = getChainId(config);
|
|
10898
11000
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
10899
11001
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
10900
|
-
const orderParams =
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
identifier_or_criteria: "0",
|
|
10914
|
-
amount: priceWei,
|
|
10915
|
-
// payment leg amount = price PER UNIT
|
|
10916
|
-
recipient: account.address
|
|
11002
|
+
const { orderParams, typedData } = buildListing1155Order(
|
|
11003
|
+
{
|
|
11004
|
+
offerer: account.address,
|
|
11005
|
+
nftContract,
|
|
11006
|
+
tokenId,
|
|
11007
|
+
quantity: amount,
|
|
11008
|
+
priceWeiPerUnit: priceWei,
|
|
11009
|
+
paymentTokenAddress: token.address,
|
|
11010
|
+
royaltyMaxBps,
|
|
11011
|
+
startTime,
|
|
11012
|
+
endTime,
|
|
11013
|
+
salt: generateSalt(),
|
|
11014
|
+
counter
|
|
10917
11015
|
},
|
|
10918
|
-
|
|
10919
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
10920
|
-
end_time: endTime.toString(),
|
|
10921
|
-
salt: generateSalt(),
|
|
10922
|
-
counter
|
|
10923
|
-
};
|
|
10924
|
-
const typedData = stringifyBigInts(
|
|
10925
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
11016
|
+
config
|
|
10926
11017
|
);
|
|
10927
|
-
const
|
|
10928
|
-
const signatureArray = toSignatureArray(signature);
|
|
10929
|
-
const orderPayload = stringifyBigInts({
|
|
10930
|
-
parameters: {
|
|
10931
|
-
...orderParams,
|
|
10932
|
-
offer: {
|
|
10933
|
-
...orderParams.offer,
|
|
10934
|
-
item_type: shortString.encodeShortString(orderParams.offer.item_type)
|
|
10935
|
-
},
|
|
10936
|
-
consideration: {
|
|
10937
|
-
...orderParams.consideration,
|
|
10938
|
-
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10939
|
-
}
|
|
10940
|
-
},
|
|
10941
|
-
signature: signatureArray
|
|
10942
|
-
});
|
|
11018
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10943
11019
|
let isApproved = false;
|
|
10944
11020
|
try {
|
|
10945
11021
|
const result = await provider.callContract({
|
|
@@ -10950,15 +11026,15 @@ async function createListing1155(account, params, config) {
|
|
|
10950
11026
|
isApproved = BigInt(result[0]) === 1n;
|
|
10951
11027
|
} catch {
|
|
10952
11028
|
}
|
|
10953
|
-
const
|
|
10954
|
-
|
|
10955
|
-
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
},
|
|
10960
|
-
|
|
10961
|
-
|
|
11029
|
+
const approve = {
|
|
11030
|
+
contractAddress: nftContract,
|
|
11031
|
+
entrypoint: "set_approval_for_all",
|
|
11032
|
+
calldata: [config.marketplace1155Contract, "1"]
|
|
11033
|
+
};
|
|
11034
|
+
const calls = buildRegister1155Calls(
|
|
11035
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isApproved, approve },
|
|
11036
|
+
config
|
|
11037
|
+
);
|
|
10962
11038
|
try {
|
|
10963
11039
|
const tx = await account.execute(calls);
|
|
10964
11040
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -10969,21 +11045,10 @@ async function createListing1155(account, params, config) {
|
|
|
10969
11045
|
}
|
|
10970
11046
|
async function fulfillOrder1155(account, params, config) {
|
|
10971
11047
|
const { orderHash, paymentToken, totalPrice, quantity = "1" } = params;
|
|
10972
|
-
const contract = getContract(config);
|
|
10973
11048
|
const provider = getProvider(config);
|
|
10974
|
-
const
|
|
10975
|
-
const approveCall = {
|
|
10976
|
-
contractAddress: paymentToken,
|
|
10977
|
-
entrypoint: "approve",
|
|
10978
|
-
calldata: [
|
|
10979
|
-
config.marketplace1155Contract,
|
|
10980
|
-
totalPriceU256.low.toString(),
|
|
10981
|
-
totalPriceU256.high.toString()
|
|
10982
|
-
]
|
|
10983
|
-
};
|
|
10984
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash, quantity]);
|
|
11049
|
+
const calls = buildFulfill1155Calls({ orderHash, paymentToken, totalPrice, quantity }, config);
|
|
10985
11050
|
try {
|
|
10986
|
-
const tx = await account.execute(
|
|
11051
|
+
const tx = await account.execute(calls);
|
|
10987
11052
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
10988
11053
|
return { txHash: tx.transaction_hash };
|
|
10989
11054
|
} catch (err) {
|
|
@@ -10992,25 +11057,12 @@ async function fulfillOrder1155(account, params, config) {
|
|
|
10992
11057
|
}
|
|
10993
11058
|
async function cancelOrder1155(account, params, config) {
|
|
10994
11059
|
const { orderHash } = params;
|
|
10995
|
-
const contract = getContract(config);
|
|
10996
11060
|
const provider = getProvider(config);
|
|
10997
|
-
const
|
|
10998
|
-
const
|
|
10999
|
-
|
|
11000
|
-
offerer: account.address
|
|
11001
|
-
};
|
|
11002
|
-
const typedData = stringifyBigInts(
|
|
11003
|
-
build1155CancellationTypedData(cancelParams, chainId)
|
|
11004
|
-
);
|
|
11005
|
-
const signature = await account.signMessage(typedData);
|
|
11006
|
-
const signatureArray = toSignatureArray(signature);
|
|
11007
|
-
const cancelPayload = stringifyBigInts({
|
|
11008
|
-
cancelation: cancelParams,
|
|
11009
|
-
signature: signatureArray
|
|
11010
|
-
});
|
|
11011
|
-
const cancelCall = contract.populate("cancel_order", [cancelPayload]);
|
|
11061
|
+
const typedData = buildCancel1155TypedData(orderHash, account.address, config);
|
|
11062
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11063
|
+
const calls = buildCancel1155Calls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
11012
11064
|
try {
|
|
11013
|
-
const tx = await account.execute(
|
|
11065
|
+
const tx = await account.execute(calls);
|
|
11014
11066
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11015
11067
|
return { txHash: tx.transaction_hash };
|
|
11016
11068
|
} catch (err) {
|
|
@@ -11028,56 +11080,30 @@ async function makeOffer1155(account, params, config) {
|
|
|
11028
11080
|
} = params;
|
|
11029
11081
|
const contract = getContract(config);
|
|
11030
11082
|
const provider = getProvider(config);
|
|
11031
|
-
const chainId = getChainId(config);
|
|
11032
11083
|
const token = resolveToken(currency);
|
|
11033
11084
|
const priceWei = parseAmount(price, token.decimals);
|
|
11034
11085
|
const now = Math.floor(Date.now() / 1e3);
|
|
11086
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
11035
11087
|
const endTime = now + durationSeconds;
|
|
11036
11088
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
11037
11089
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11038
|
-
const orderParams =
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
identifier_or_criteria: tokenId,
|
|
11052
|
-
amount,
|
|
11053
|
-
// unit quantity
|
|
11054
|
-
recipient: account.address
|
|
11090
|
+
const { orderParams, typedData } = buildOffer1155Order(
|
|
11091
|
+
{
|
|
11092
|
+
offerer: account.address,
|
|
11093
|
+
nftContract,
|
|
11094
|
+
tokenId,
|
|
11095
|
+
quantity: amount,
|
|
11096
|
+
priceWeiPerUnit: priceWei,
|
|
11097
|
+
paymentTokenAddress: token.address,
|
|
11098
|
+
royaltyMaxBps,
|
|
11099
|
+
startTime,
|
|
11100
|
+
endTime,
|
|
11101
|
+
salt: generateSalt(),
|
|
11102
|
+
counter
|
|
11055
11103
|
},
|
|
11056
|
-
|
|
11057
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
11058
|
-
end_time: endTime.toString(),
|
|
11059
|
-
salt: generateSalt(),
|
|
11060
|
-
counter
|
|
11061
|
-
};
|
|
11062
|
-
const typedData = stringifyBigInts(
|
|
11063
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
11104
|
+
config
|
|
11064
11105
|
);
|
|
11065
|
-
const
|
|
11066
|
-
const signatureArray = toSignatureArray(signature);
|
|
11067
|
-
const registerPayload = stringifyBigInts({
|
|
11068
|
-
parameters: {
|
|
11069
|
-
...orderParams,
|
|
11070
|
-
offer: {
|
|
11071
|
-
...orderParams.offer,
|
|
11072
|
-
item_type: shortString.encodeShortString(orderParams.offer.item_type)
|
|
11073
|
-
},
|
|
11074
|
-
consideration: {
|
|
11075
|
-
...orderParams.consideration,
|
|
11076
|
-
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11077
|
-
}
|
|
11078
|
-
},
|
|
11079
|
-
signature: signatureArray
|
|
11080
|
-
});
|
|
11106
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11081
11107
|
const totalWei = BigInt(priceWei) * BigInt(amount);
|
|
11082
11108
|
const amountU256 = cairo.uint256(totalWei.toString());
|
|
11083
11109
|
const approveCall = {
|
|
@@ -11089,9 +11115,12 @@ async function makeOffer1155(account, params, config) {
|
|
|
11089
11115
|
amountU256.high.toString()
|
|
11090
11116
|
]
|
|
11091
11117
|
};
|
|
11092
|
-
const
|
|
11118
|
+
const calls = buildRegister1155Calls(
|
|
11119
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
11120
|
+
config
|
|
11121
|
+
);
|
|
11093
11122
|
try {
|
|
11094
|
-
const tx = await account.execute(
|
|
11123
|
+
const tx = await account.execute(calls);
|
|
11095
11124
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11096
11125
|
return { txHash: tx.transaction_hash };
|
|
11097
11126
|
} catch (err) {
|
|
@@ -12709,94 +12738,147 @@ var StarknetVenue = class {
|
|
|
12709
12738
|
constructor(deps) {
|
|
12710
12739
|
this.deps = deps;
|
|
12711
12740
|
this.chain = "STARKNET";
|
|
12712
|
-
this.m721 = new MarketplaceModule(deps.config);
|
|
12713
|
-
this.m1155 = new Medialane1155Module(deps.config);
|
|
12714
12741
|
}
|
|
12715
|
-
incrementCounter(signer) {
|
|
12716
|
-
return
|
|
12742
|
+
async incrementCounter(signer) {
|
|
12743
|
+
return signer.execute([
|
|
12744
|
+
{ contractAddress: this.deps.config.marketplaceContract, entrypoint: "increment_counter", calldata: [] }
|
|
12745
|
+
]);
|
|
12717
12746
|
}
|
|
12718
12747
|
getOrderDetails(orderRef) {
|
|
12719
|
-
return this.
|
|
12748
|
+
return getOrderDetails(orderRef, this.deps.config);
|
|
12720
12749
|
}
|
|
12721
|
-
getCounter(address) {
|
|
12722
|
-
return this.
|
|
12750
|
+
async getCounter(address) {
|
|
12751
|
+
return this.readCounter(this.deps.config.marketplaceContract, address);
|
|
12723
12752
|
}
|
|
12724
12753
|
async fulfillOrder(signer, orderRef, opts) {
|
|
12725
12754
|
const o = await this.deps.resolveOrder(orderRef);
|
|
12726
12755
|
const quantity = opts?.quantity ?? "1";
|
|
12727
12756
|
const totalPrice = (BigInt(o.unitPrice) * BigInt(quantity)).toString();
|
|
12728
|
-
|
|
12729
|
-
|
|
12730
|
-
orderHash: orderRef,
|
|
12731
|
-
paymentToken: o.paymentToken,
|
|
12732
|
-
totalPrice,
|
|
12733
|
-
quantity
|
|
12734
|
-
});
|
|
12735
|
-
}
|
|
12736
|
-
return this.m721.fulfillOrder(signer, {
|
|
12737
|
-
orderHash: orderRef,
|
|
12738
|
-
paymentToken: o.paymentToken,
|
|
12739
|
-
totalPrice
|
|
12740
|
-
});
|
|
12757
|
+
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);
|
|
12758
|
+
return signer.execute(calls);
|
|
12741
12759
|
}
|
|
12742
12760
|
async cancelOrder(signer, orderRef) {
|
|
12743
12761
|
const o = await this.deps.resolveOrder(orderRef);
|
|
12744
|
-
|
|
12745
|
-
|
|
12746
|
-
}
|
|
12747
|
-
return
|
|
12762
|
+
const typedData = o.standard === "ERC1155" ? buildCancel1155TypedData(orderRef, signer.address, this.deps.config) : buildCancelTypedData(orderRef, signer.address, this.deps.config);
|
|
12763
|
+
const signature = await signer.signTypedData(typedData);
|
|
12764
|
+
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);
|
|
12765
|
+
return signer.execute(calls);
|
|
12748
12766
|
}
|
|
12749
12767
|
async registerOrder(signer, p) {
|
|
12750
12768
|
const standard = await this.deps.resolveStandard(p.asset.contract);
|
|
12751
|
-
const
|
|
12752
|
-
const humanPrice = formatAmount(p.amount, token.decimals);
|
|
12753
|
-
const durationSeconds = this.durationSeconds(p.endTime);
|
|
12769
|
+
const paymentTokenAddress = resolveToken(p.paymentToken).address;
|
|
12754
12770
|
const royaltyMaxBps = String(p.royaltyMaxBps);
|
|
12771
|
+
const startTime = Math.floor(Date.now() / 1e3) + START_TIME_BUFFER_SECS;
|
|
12772
|
+
const endTime = p.endTime && p.endTime > 0 ? p.endTime : startTime + NO_EXPIRY_SECONDS;
|
|
12755
12773
|
const quantity = p.quantity ?? "1";
|
|
12756
|
-
|
|
12774
|
+
const marketplace = standard === "ERC1155" ? this.deps.config.marketplace1155Contract : this.deps.config.marketplaceContract;
|
|
12775
|
+
const counter = String(await this.readCounter(marketplace, signer.address));
|
|
12776
|
+
let typedData;
|
|
12777
|
+
let buildCalls;
|
|
12757
12778
|
if (standard === "ERC1155") {
|
|
12758
|
-
|
|
12759
|
-
|
|
12779
|
+
const built = (p.side === "listing" ? buildListing1155Order : buildOffer1155Order)(
|
|
12780
|
+
{
|
|
12781
|
+
offerer: signer.address,
|
|
12760
12782
|
nftContract: p.asset.contract,
|
|
12761
12783
|
tokenId: p.asset.tokenId,
|
|
12762
|
-
|
|
12763
|
-
|
|
12764
|
-
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
|
|
12769
|
-
|
|
12770
|
-
|
|
12771
|
-
|
|
12784
|
+
quantity,
|
|
12785
|
+
priceWeiPerUnit: p.amount,
|
|
12786
|
+
paymentTokenAddress,
|
|
12787
|
+
royaltyMaxBps,
|
|
12788
|
+
startTime,
|
|
12789
|
+
endTime,
|
|
12790
|
+
salt: p.salt,
|
|
12791
|
+
counter
|
|
12792
|
+
},
|
|
12793
|
+
this.deps.config
|
|
12794
|
+
);
|
|
12795
|
+
typedData = built.typedData;
|
|
12796
|
+
const approval = p.side === "listing" ? await this.approval1155ForListing(signer.address, p.asset.contract) : this.approvalForErc20(paymentTokenAddress, (BigInt(p.amount) * BigInt(quantity)).toString(), marketplace);
|
|
12797
|
+
buildCalls = (sig) => buildRegister1155Calls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
12798
|
+
} else {
|
|
12799
|
+
const built = (p.side === "listing" ? buildListingOrder : buildOfferOrder)(
|
|
12800
|
+
{
|
|
12801
|
+
offerer: signer.address,
|
|
12772
12802
|
nftContract: p.asset.contract,
|
|
12773
12803
|
tokenId: p.asset.tokenId,
|
|
12774
|
-
|
|
12775
|
-
|
|
12776
|
-
|
|
12777
|
-
|
|
12778
|
-
|
|
12779
|
-
|
|
12780
|
-
|
|
12781
|
-
|
|
12782
|
-
|
|
12783
|
-
|
|
12784
|
-
|
|
12785
|
-
|
|
12786
|
-
|
|
12787
|
-
currency: p.paymentToken,
|
|
12788
|
-
durationSeconds,
|
|
12789
|
-
royaltyMaxBps
|
|
12790
|
-
};
|
|
12791
|
-
const res = p.side === "listing" ? await this.m721.createListing(signer, params) : await this.m721.makeOffer(signer, params);
|
|
12792
|
-
txHash = res.txHash;
|
|
12804
|
+
priceWei: p.amount,
|
|
12805
|
+
paymentTokenAddress,
|
|
12806
|
+
royaltyMaxBps,
|
|
12807
|
+
startTime,
|
|
12808
|
+
endTime,
|
|
12809
|
+
salt: p.salt,
|
|
12810
|
+
counter
|
|
12811
|
+
},
|
|
12812
|
+
this.deps.config
|
|
12813
|
+
);
|
|
12814
|
+
typedData = built.typedData;
|
|
12815
|
+
const approval = p.side === "listing" ? await this.approval721ForListing(signer.address, p.asset.contract, p.asset.tokenId) : this.approvalForErc20(paymentTokenAddress, p.amount, marketplace);
|
|
12816
|
+
buildCalls = (sig) => buildRegisterCalls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
12793
12817
|
}
|
|
12818
|
+
const signature = await signer.signTypedData(typedData);
|
|
12819
|
+
const { txHash } = await signer.execute(buildCalls(signature));
|
|
12794
12820
|
const orderRef = await this.orderRefFromReceipt(txHash);
|
|
12795
12821
|
return { txHash, orderRef };
|
|
12796
12822
|
}
|
|
12797
|
-
|
|
12798
|
-
|
|
12799
|
-
|
|
12823
|
+
// ─── reads (all on deps.provider) ─────────────────────────────────────────
|
|
12824
|
+
async readCounter(marketplace, address) {
|
|
12825
|
+
const res = await this.deps.provider.callContract({
|
|
12826
|
+
contractAddress: marketplace,
|
|
12827
|
+
entrypoint: "get_counter",
|
|
12828
|
+
calldata: [address]
|
|
12829
|
+
});
|
|
12830
|
+
return BigInt(res[0] ?? "0");
|
|
12831
|
+
}
|
|
12832
|
+
/** 721 listing approval: `get_approved(tokenId) == marketplace` ⇒ no approve. */
|
|
12833
|
+
async approval721ForListing(_owner, nftContract, tokenId) {
|
|
12834
|
+
const id = cairo.uint256(tokenId);
|
|
12835
|
+
const approve = {
|
|
12836
|
+
contractAddress: nftContract,
|
|
12837
|
+
entrypoint: "approve",
|
|
12838
|
+
calldata: [this.deps.config.marketplaceContract, id.low.toString(), id.high.toString()]
|
|
12839
|
+
};
|
|
12840
|
+
let approved = false;
|
|
12841
|
+
try {
|
|
12842
|
+
const res = await this.deps.provider.callContract({
|
|
12843
|
+
contractAddress: nftContract,
|
|
12844
|
+
entrypoint: "get_approved",
|
|
12845
|
+
calldata: [id.low.toString(), id.high.toString()]
|
|
12846
|
+
});
|
|
12847
|
+
approved = BigInt(res[0]).toString() === BigInt(this.deps.config.marketplaceContract).toString();
|
|
12848
|
+
} catch {
|
|
12849
|
+
}
|
|
12850
|
+
return { approvalNeeded: !approved, approve };
|
|
12851
|
+
}
|
|
12852
|
+
/** 1155 listing approval: `is_approved_for_all(owner, marketplace)`. */
|
|
12853
|
+
async approval1155ForListing(owner, nftContract) {
|
|
12854
|
+
const approve = {
|
|
12855
|
+
contractAddress: nftContract,
|
|
12856
|
+
entrypoint: "set_approval_for_all",
|
|
12857
|
+
calldata: [this.deps.config.marketplace1155Contract, "1"]
|
|
12858
|
+
};
|
|
12859
|
+
let approved = false;
|
|
12860
|
+
try {
|
|
12861
|
+
const res = await this.deps.provider.callContract({
|
|
12862
|
+
contractAddress: nftContract,
|
|
12863
|
+
entrypoint: "is_approved_for_all",
|
|
12864
|
+
calldata: [owner, this.deps.config.marketplace1155Contract]
|
|
12865
|
+
});
|
|
12866
|
+
approved = BigInt(res[0]) === 1n;
|
|
12867
|
+
} catch {
|
|
12868
|
+
}
|
|
12869
|
+
return { approvalNeeded: !approved, approve };
|
|
12870
|
+
}
|
|
12871
|
+
/** Offers always approve the ERC-20 spend (no read). */
|
|
12872
|
+
approvalForErc20(token, amountWei, marketplace) {
|
|
12873
|
+
const u = cairo.uint256(amountWei);
|
|
12874
|
+
return {
|
|
12875
|
+
approvalNeeded: true,
|
|
12876
|
+
approve: {
|
|
12877
|
+
contractAddress: token,
|
|
12878
|
+
entrypoint: "approve",
|
|
12879
|
+
calldata: [marketplace, u.low.toString(), u.high.toString()]
|
|
12880
|
+
}
|
|
12881
|
+
};
|
|
12800
12882
|
}
|
|
12801
12883
|
/** The canonical Starknet order id = the contract-emitted `OrderCreated`
|
|
12802
12884
|
* hash (`keys[1]`), which is exactly what the indexer stores. */
|