@medialane/sdk 0.63.0 → 0.64.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1296,124 +1296,6 @@ function createFailoverFetch(urls, options = {}) {
1296
1296
  };
1297
1297
  return failover;
1298
1298
  }
1299
- var STARKNET_DOMAIN = [
1300
- { name: "name", type: "shortstring" },
1301
- { name: "version", type: "shortstring" },
1302
- { name: "chainId", type: "shortstring" },
1303
- { name: "revision", type: "shortstring" }
1304
- ];
1305
- var OFFER_ITEM = [
1306
- { name: "item_type", type: "shortstring" },
1307
- { name: "token", type: "ContractAddress" },
1308
- { name: "identifier_or_criteria", type: "felt" },
1309
- { name: "amount", type: "felt" }
1310
- ];
1311
- var CONSIDERATION_ITEM = [
1312
- { name: "item_type", type: "shortstring" },
1313
- { name: "token", type: "ContractAddress" },
1314
- { name: "identifier_or_criteria", type: "felt" },
1315
- { name: "amount", type: "felt" },
1316
- { name: "recipient", type: "ContractAddress" }
1317
- ];
1318
- var ORDER_PARAMETERS = [
1319
- { name: "offerer", type: "ContractAddress" },
1320
- { name: "marketplace", type: "ContractAddress" },
1321
- { name: "offer", type: "OfferItem" },
1322
- { name: "consideration", type: "ConsiderationItem" },
1323
- { name: "royalty_max_bps", type: "felt" },
1324
- { name: "start_time", type: "felt" },
1325
- { name: "end_time", type: "felt" },
1326
- { name: "salt", type: "felt" },
1327
- { name: "counter", type: "felt" }
1328
- ];
1329
- var ORDER_CANCELLATION = [
1330
- { name: "order_hash", type: "felt" },
1331
- { name: "offerer", type: "ContractAddress" }
1332
- ];
1333
- var DOMAIN_VERSION = {
1334
- erc721: "5",
1335
- erc1155: "4"
1336
- };
1337
- function buildDomain(standard, chainId) {
1338
- return {
1339
- name: "Medialane",
1340
- version: DOMAIN_VERSION[standard],
1341
- chainId,
1342
- revision: starknet.TypedDataRevision.ACTIVE
1343
- };
1344
- }
1345
- function buildOrderTypedData(message, chainId) {
1346
- return {
1347
- domain: buildDomain("erc721", chainId),
1348
- primaryType: "OrderParameters",
1349
- types: {
1350
- StarknetDomain: STARKNET_DOMAIN,
1351
- OrderParameters: ORDER_PARAMETERS,
1352
- OfferItem: OFFER_ITEM,
1353
- ConsiderationItem: CONSIDERATION_ITEM
1354
- },
1355
- message
1356
- };
1357
- }
1358
- function build1155OrderTypedData(message, chainId) {
1359
- return {
1360
- domain: buildDomain("erc1155", chainId),
1361
- primaryType: "OrderParameters",
1362
- types: {
1363
- StarknetDomain: STARKNET_DOMAIN,
1364
- OrderParameters: ORDER_PARAMETERS,
1365
- OfferItem: OFFER_ITEM,
1366
- ConsiderationItem: CONSIDERATION_ITEM
1367
- },
1368
- message
1369
- };
1370
- }
1371
- function buildCancellationTypedData(message, chainId) {
1372
- return {
1373
- domain: buildDomain("erc721", chainId),
1374
- primaryType: "OrderCancellation",
1375
- types: {
1376
- StarknetDomain: STARKNET_DOMAIN,
1377
- OrderCancellation: ORDER_CANCELLATION
1378
- },
1379
- message
1380
- };
1381
- }
1382
- function build1155CancellationTypedData(message, chainId) {
1383
- return {
1384
- domain: buildDomain("erc1155", chainId),
1385
- primaryType: "OrderCancellation",
1386
- types: {
1387
- StarknetDomain: STARKNET_DOMAIN,
1388
- OrderCancellation: ORDER_CANCELLATION
1389
- },
1390
- message
1391
- };
1392
- }
1393
- function encodeByteArray(str) {
1394
- const bytes = new TextEncoder().encode(str);
1395
- const fullChunks = [];
1396
- let i = 0;
1397
- while (i + 31 <= bytes.length) {
1398
- let val = 0n;
1399
- for (const b of bytes.slice(i, i + 31)) {
1400
- val = val << 8n | BigInt(b);
1401
- }
1402
- fullChunks.push(starknet.num.toHex(val));
1403
- i += 31;
1404
- }
1405
- const remaining = bytes.slice(i);
1406
- let pendingVal = 0n;
1407
- for (const b of remaining) {
1408
- pendingVal = pendingVal << 8n | BigInt(b);
1409
- }
1410
- return [
1411
- fullChunks.length.toString(),
1412
- ...fullChunks,
1413
- starknet.num.toHex(pendingVal),
1414
- remaining.length.toString()
1415
- ];
1416
- }
1417
1299
 
1418
1300
  // src/starknet/abis/ipMarketplace.ts
1419
1301
  var IPMarketplaceABI = [
@@ -11444,13 +11326,71 @@ var IPGenesisABI = [
11444
11326
  }
11445
11327
  ];
11446
11328
 
11447
- // src/starknet/marketplace/errors.ts
11448
- var MedialaneError = class extends Error {
11449
- constructor(message, code = "UNKNOWN", cause) {
11450
- super(message);
11451
- this.code = code;
11452
- this.cause = cause;
11453
- this.name = "MedialaneError";
11329
+ // src/starknet/services/pop.ts
11330
+ var PopService = class {
11331
+ constructor(config) {
11332
+ this.factoryAddress = getStarknetCoordinates(config.chain).popFactory;
11333
+ }
11334
+ _collection(address, account) {
11335
+ return new starknet.Contract(POPCollectionABI, normalizeAddress("STARKNET", address), account);
11336
+ }
11337
+ async claim(account, collectionAddress) {
11338
+ const call = this._collection(collectionAddress, account).populate("claim", []);
11339
+ const res = await account.execute([call]);
11340
+ return { txHash: res.transaction_hash };
11341
+ }
11342
+ async adminMint(account, params) {
11343
+ const call = this._collection(params.collection, account).populate("admin_mint", [
11344
+ params.recipient,
11345
+ params.customUri ?? ""
11346
+ ]);
11347
+ const res = await account.execute([call]);
11348
+ return { txHash: res.transaction_hash };
11349
+ }
11350
+ async addToAllowlist(account, params) {
11351
+ const call = this._collection(params.collection, account).populate("add_to_allowlist", [params.address]);
11352
+ const res = await account.execute([call]);
11353
+ return { txHash: res.transaction_hash };
11354
+ }
11355
+ async batchAddToAllowlist(account, params) {
11356
+ const collection = this._collection(params.collection, account);
11357
+ const CHUNK = 200;
11358
+ const calls = [];
11359
+ for (let i = 0; i < params.addresses.length; i += CHUNK) {
11360
+ calls.push(collection.populate("batch_add_to_allowlist", [params.addresses.slice(i, i + CHUNK)]));
11361
+ }
11362
+ const res = await account.execute(calls);
11363
+ return { txHash: res.transaction_hash };
11364
+ }
11365
+ async removeFromAllowlist(account, params) {
11366
+ const call = this._collection(params.collection, account).populate("remove_from_allowlist", [params.address]);
11367
+ const res = await account.execute([call]);
11368
+ return { txHash: res.transaction_hash };
11369
+ }
11370
+ async setTokenUri(account, params) {
11371
+ const call = this._collection(params.collection, account).populate("set_token_uri", [
11372
+ BigInt(params.tokenId),
11373
+ params.uri
11374
+ ]);
11375
+ const res = await account.execute([call]);
11376
+ return { txHash: res.transaction_hash };
11377
+ }
11378
+ async setPaused(account, params) {
11379
+ const call = this._collection(params.collection, account).populate("set_paused", [params.paused]);
11380
+ const res = await account.execute([call]);
11381
+ return { txHash: res.transaction_hash };
11382
+ }
11383
+ async createCollection(account, params) {
11384
+ const factory = new starknet.Contract(POPFactoryABI, this.factoryAddress, account);
11385
+ const call = factory.populate("create_collection", [
11386
+ params.name,
11387
+ params.symbol,
11388
+ params.baseUri,
11389
+ params.claimEndTime,
11390
+ { [params.eventType]: {} }
11391
+ ]);
11392
+ const res = await account.execute([call]);
11393
+ return { txHash: res.transaction_hash };
11454
11394
  }
11455
11395
  };
11456
11396
  function buildFeeCall(p, cfg) {
@@ -11466,893 +11406,39 @@ function buildFeeCall(p, cfg) {
11466
11406
  calldata: [cfg.fundAddress, u.low.toString(), u.high.toString()]
11467
11407
  };
11468
11408
  }
11469
- var START_TIME_BUFFER_SECS = 30;
11470
- function generateSalt() {
11471
- const bytes = new Uint8Array(31);
11472
- crypto.getRandomValues(bytes);
11473
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
11474
- return starknet.num.toHex(BigInt("0x" + hex));
11409
+
11410
+ // src/starknet/services/drop.ts
11411
+ function toContractConditions(c) {
11412
+ return {
11413
+ start_time: c.startTime,
11414
+ end_time: c.endTime,
11415
+ price: BigInt(c.price),
11416
+ payment_token: c.paymentToken,
11417
+ max_quantity_per_wallet: BigInt(c.maxQuantityPerWallet)
11418
+ };
11475
11419
  }
11476
- async function resolveRoyaltyMaxBps(provider, nft, tokenId, override) {
11477
- if (override !== void 0) return override;
11478
- try {
11479
- const id = starknet.cairo.uint256(tokenId);
11480
- const res = await provider.callContract({
11481
- contractAddress: nft,
11482
- entrypoint: "royalty_info",
11483
- calldata: [id.low.toString(), id.high.toString(), "10000", "0"]
11484
- });
11485
- return BigInt(res[1] ?? "0").toString();
11486
- } catch {
11487
- return "0";
11420
+ var DropService = class {
11421
+ constructor(config) {
11422
+ this.factoryAddress = getStarknetCoordinates(config.chain).dropFactory;
11423
+ this.config = config;
11488
11424
  }
11489
- }
11490
- function toSignatureArray(sig) {
11491
- if (Array.isArray(sig)) return sig;
11492
- const s = sig;
11493
- return [s.r.toString(), s.s.toString()];
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
- }
11503
- function getChainId(config) {
11504
- if (config.chain !== "STARKNET") {
11505
- throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
11425
+ _collection(address, account) {
11426
+ return new starknet.Contract(DropCollectionABI, normalizeAddress("STARKNET", address), account);
11506
11427
  }
11507
- return starknet.constants.StarknetChainId.SN_MAIN;
11508
- }
11509
- function resolveToken(currency) {
11510
- const token = SUPPORTED_TOKENS.find(
11511
- (t) => t.symbol === currency.toUpperCase() || t.address.toLowerCase() === currency.toLowerCase()
11512
- );
11513
- if (!token) throw new MedialaneError(`Unsupported currency: ${currency}`, "INVALID_PARAMS");
11514
- return token;
11515
- }
11516
- var _providerCache = /* @__PURE__ */ new WeakMap();
11517
- function getProvider(config) {
11518
- let p = _providerCache.get(config);
11519
- if (!p) {
11520
- const urls = Array.from(/* @__PURE__ */ new Set([config.rpcUrl, ...PUBLIC_RPC_FALLBACKS]));
11521
- p = new starknet.RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
11522
- _providerCache.set(config, p);
11523
- }
11524
- return p;
11525
- }
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
-
11615
- // src/starknet/marketplace/orders.ts
11616
- var _contractCache = /* @__PURE__ */ new WeakMap();
11617
- function makeContract(config) {
11618
- const cached = _contractCache.get(config);
11619
- const provider = getProvider(config);
11620
- if (cached) return { ...cached, provider };
11621
- const contract = newContract(IPMarketplaceABI, config.marketplaceContract, provider);
11622
- _contractCache.set(config, { contract });
11623
- return { contract, provider };
11624
- }
11625
- async function createListing(account, params, config) {
11626
- const { nftContract, tokenId, price, currency = DEFAULT_CURRENCY, durationSeconds } = params;
11627
- const { contract, provider } = makeContract(config);
11628
- const token = resolveToken(currency);
11629
- const priceWei = parseAmount(price, token.decimals);
11630
- const now = Math.floor(Date.now() / 1e3);
11631
- const startTime = now + START_TIME_BUFFER_SECS;
11632
- const endTime = now + durationSeconds;
11633
- const counter = (await contract.get_counter(account.address)).toString();
11634
- const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
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
11647
- },
11648
- config
11649
- );
11650
- const signatureArray = toSignatureArray(await account.signMessage(typedData));
11651
- const tokenIdUint256 = starknet.cairo.uint256(tokenId);
11652
- let isAlreadyApproved = false;
11653
- try {
11654
- const result = await provider.callContract({
11655
- contractAddress: nftContract,
11656
- entrypoint: "get_approved",
11657
- calldata: [tokenIdUint256.low.toString(), tokenIdUint256.high.toString()]
11658
- });
11659
- isAlreadyApproved = BigInt(result[0]).toString() === BigInt(config.marketplaceContract).toString();
11660
- } catch {
11661
- }
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
- );
11675
- try {
11676
- const tx = await account.execute(calls);
11677
- await provider.waitForTransaction(tx.transaction_hash);
11678
- return { txHash: tx.transaction_hash };
11679
- } catch (err) {
11680
- throw new MedialaneError("Failed to create listing", "TRANSACTION_FAILED", err);
11681
- }
11682
- }
11683
- async function makeOffer(account, params, config) {
11684
- const { nftContract, tokenId, price, currency = DEFAULT_CURRENCY, durationSeconds } = params;
11685
- const { contract, provider } = makeContract(config);
11686
- const token = resolveToken(currency);
11687
- const priceWei = parseAmount(price, token.decimals);
11688
- const now = Math.floor(Date.now() / 1e3);
11689
- const startTime = now + START_TIME_BUFFER_SECS;
11690
- const endTime = now + durationSeconds;
11691
- const counter = (await contract.get_counter(account.address)).toString();
11692
- const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
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
11705
- },
11706
- config
11707
- );
11708
- const signatureArray = toSignatureArray(await account.signMessage(typedData));
11709
- const amountUint256 = starknet.cairo.uint256(priceWei);
11710
- const approveCall = {
11711
- contractAddress: token.address,
11712
- entrypoint: "approve",
11713
- calldata: [
11714
- config.marketplaceContract,
11715
- amountUint256.low.toString(),
11716
- amountUint256.high.toString()
11717
- ]
11718
- };
11719
- const calls = buildRegisterCalls(
11720
- { orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
11721
- config
11722
- );
11723
- try {
11724
- const tx = await account.execute(calls);
11725
- await provider.waitForTransaction(tx.transaction_hash);
11726
- return { txHash: tx.transaction_hash };
11727
- } catch (err) {
11728
- throw new MedialaneError("Failed to make offer", "TRANSACTION_FAILED", err);
11729
- }
11730
- }
11731
- async function fulfillOrder(account, params, config) {
11732
- const { orderHash, paymentToken, totalPrice } = params;
11733
- const { provider } = makeContract(config);
11734
- const calls = buildFulfillCalls({ orderHash, paymentToken, totalPrice }, config);
11735
- try {
11736
- const tx = await account.execute(calls);
11737
- await provider.waitForTransaction(tx.transaction_hash);
11738
- return { txHash: tx.transaction_hash };
11739
- } catch (err) {
11740
- throw new MedialaneError("Failed to fulfill order", "TRANSACTION_FAILED", err);
11741
- }
11742
- }
11743
- async function cancelOrder(account, params, config) {
11744
- const { orderHash } = params;
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);
11749
- try {
11750
- const tx = await account.execute(calls);
11751
- await provider.waitForTransaction(tx.transaction_hash);
11752
- return { txHash: tx.transaction_hash };
11753
- } catch (err) {
11754
- throw new MedialaneError("Failed to cancel order", "TRANSACTION_FAILED", err);
11755
- }
11756
- }
11757
- async function mint(account, params, config) {
11758
- const { collectionId, recipient, tokenUri, royaltyBps, collectionContract } = params;
11759
- const provider = getProvider(config);
11760
- const contractAddress = collectionContract ?? config.collectionContract;
11761
- const id = starknet.cairo.uint256(collectionId);
11762
- const calldata = [
11763
- id.low.toString(),
11764
- id.high.toString(),
11765
- recipient,
11766
- ...encodeByteArray(tokenUri),
11767
- royaltyBps.toString()
11768
- ];
11769
- try {
11770
- const tx = await account.execute([{ contractAddress, entrypoint: "mint", calldata }]);
11771
- await provider.waitForTransaction(tx.transaction_hash);
11772
- return { txHash: tx.transaction_hash };
11773
- } catch (err) {
11774
- throw new MedialaneError("Failed to mint NFT", "TRANSACTION_FAILED", err);
11775
- }
11776
- }
11777
- async function createCollection(account, params, config) {
11778
- const { name, symbol, baseUri, collectionContract } = params;
11779
- const provider = getProvider(config);
11780
- const contractAddress = collectionContract ?? config.collectionContract;
11781
- const calldata = [
11782
- ...encodeByteArray(name),
11783
- ...encodeByteArray(symbol),
11784
- ...encodeByteArray(baseUri)
11785
- ];
11786
- try {
11787
- const tx = await account.execute([{ contractAddress, entrypoint: "create_collection", calldata }]);
11788
- await provider.waitForTransaction(tx.transaction_hash);
11789
- return { txHash: tx.transaction_hash };
11790
- } catch (err) {
11791
- throw new MedialaneError("Failed to create collection", "TRANSACTION_FAILED", err);
11792
- }
11793
- }
11794
- async function checkoutCart(account, items, config) {
11795
- if (items.length === 0) throw new MedialaneError("Cart is empty", "INVALID_PARAMS");
11796
- const { contract, provider } = makeContract(config);
11797
- const tokenTotals = /* @__PURE__ */ new Map();
11798
- for (const item of items) {
11799
- const prev = tokenTotals.get(item.considerationToken) ?? 0n;
11800
- tokenTotals.set(item.considerationToken, prev + BigInt(item.considerationAmount));
11801
- }
11802
- const approveCalls = Array.from(tokenTotals.entries()).map(([tokenAddr, totalWei]) => {
11803
- const amount = starknet.cairo.uint256(totalWei.toString());
11804
- return {
11805
- contractAddress: tokenAddr,
11806
- entrypoint: "approve",
11807
- calldata: [
11808
- config.marketplaceContract,
11809
- amount.low.toString(),
11810
- amount.high.toString()
11811
- ]
11812
- };
11813
- });
11814
- const fulfillCalls = items.map(
11815
- (item) => contract.populate("fulfill_order", [item.orderHash])
11816
- );
11817
- const feeCalls = Array.from(tokenTotals.entries()).map(
11818
- ([tokenAddr, totalWei]) => buildFeeCall(
11819
- { surface: "marketplace", token: tokenAddr, grossAmount: totalWei },
11820
- config.feeConfig
11821
- )
11822
- ).filter((c) => c !== null);
11823
- try {
11824
- const tx = await account.execute([...approveCalls, ...fulfillCalls, ...feeCalls]);
11825
- await provider.waitForTransaction(tx.transaction_hash);
11826
- return { txHash: tx.transaction_hash };
11827
- } catch (err) {
11828
- throw new MedialaneError("Cart checkout failed", "TRANSACTION_FAILED", err);
11829
- }
11830
- }
11831
- async function getOrderDetails(orderHash, config) {
11832
- const { contract } = makeContract(config);
11833
- return contract.get_order_details(orderHash);
11834
- }
11835
- async function getCounter(address, config) {
11836
- const { contract } = makeContract(config);
11837
- return BigInt((await contract.get_counter(address)).toString());
11838
- }
11839
- async function incrementCounter(account, config) {
11840
- const { contract, provider } = makeContract(config);
11841
- const call = contract.populate("increment_counter", []);
11842
- try {
11843
- const tx = await account.execute(call);
11844
- await provider.waitForTransaction(tx.transaction_hash);
11845
- return { txHash: tx.transaction_hash };
11846
- } catch (err) {
11847
- throw new MedialaneError("Failed to increment counter", "TRANSACTION_FAILED", err);
11848
- }
11849
- }
11850
-
11851
- // src/starknet/marketplace/index.ts
11852
- var MarketplaceModule = class {
11853
- constructor(config) {
11854
- this.config = config;
11855
- }
11856
- // ─── Writes ───────────────────────────────────────────────────────────────
11857
- createListing(account, params) {
11858
- return createListing(account, params, this.config);
11859
- }
11860
- makeOffer(account, params) {
11861
- return makeOffer(account, params, this.config);
11862
- }
11863
- fulfillOrder(account, params) {
11864
- return fulfillOrder(account, params, this.config);
11865
- }
11866
- cancelOrder(account, params) {
11867
- return cancelOrder(account, params, this.config);
11868
- }
11869
- checkoutCart(account, items) {
11870
- return checkoutCart(account, items, this.config);
11871
- }
11872
- mint(account, params) {
11873
- return mint(account, params, this.config);
11874
- }
11875
- createCollection(account, params) {
11876
- return createCollection(account, params, this.config);
11877
- }
11878
- /** Bulk-cancel: bump the caller's counter, invalidating all their open orders. */
11879
- incrementCounter(account) {
11880
- return incrementCounter(account, this.config);
11881
- }
11882
- // ─── View calls ───────────────────────────────────────────────────────────
11883
- getOrderDetails(orderHash) {
11884
- return getOrderDetails(orderHash, this.config);
11885
- }
11886
- getCounter(address) {
11887
- return getCounter(address, this.config);
11888
- }
11889
- // ─── Typed data builders (for ChipiPay / custom signing flows) ───────────
11890
- buildListingTypedData(params, chainId) {
11891
- return buildOrderTypedData(params, chainId);
11892
- }
11893
- buildCancellationTypedData(params, chainId) {
11894
- return buildCancellationTypedData(params, chainId);
11895
- }
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
11991
- var _contractCache2 = /* @__PURE__ */ new WeakMap();
11992
- function getContract(config) {
11993
- let c = _contractCache2.get(config);
11994
- if (!c) {
11995
- const provider = getProvider(config);
11996
- c = newContract(Medialane1155ABI, config.marketplace1155Contract, provider);
11997
- _contractCache2.set(config, c);
11998
- }
11999
- return c;
12000
- }
12001
- async function createListing1155(account, params, config) {
12002
- const {
12003
- nftContract,
12004
- tokenId,
12005
- amount,
12006
- pricePerUnit,
12007
- currency = DEFAULT_CURRENCY,
12008
- durationSeconds
12009
- } = params;
12010
- const contract = getContract(config);
12011
- const provider = getProvider(config);
12012
- const token = resolveToken(currency);
12013
- const priceWei = parseAmount(pricePerUnit, token.decimals);
12014
- const now = Math.floor(Date.now() / 1e3);
12015
- const startTime = now + START_TIME_BUFFER_SECS;
12016
- const endTime = now + durationSeconds;
12017
- const counter = (await contract.get_counter(account.address)).toString();
12018
- const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
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
12032
- },
12033
- config
12034
- );
12035
- const signatureArray = toSignatureArray(await account.signMessage(typedData));
12036
- let isApproved = false;
12037
- try {
12038
- const result = await provider.callContract({
12039
- contractAddress: nftContract,
12040
- entrypoint: "is_approved_for_all",
12041
- calldata: [account.address, config.marketplace1155Contract]
12042
- });
12043
- isApproved = BigInt(result[0]) === 1n;
12044
- } catch {
12045
- }
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
- );
12055
- try {
12056
- const tx = await account.execute(calls);
12057
- await provider.waitForTransaction(tx.transaction_hash);
12058
- return { txHash: tx.transaction_hash };
12059
- } catch (err) {
12060
- throw new MedialaneError("Failed to create ERC-1155 listing", "TRANSACTION_FAILED", err);
12061
- }
12062
- }
12063
- async function fulfillOrder1155(account, params, config) {
12064
- const { orderHash, paymentToken, totalPrice, quantity = "1" } = params;
12065
- const provider = getProvider(config);
12066
- const calls = buildFulfill1155Calls({ orderHash, paymentToken, totalPrice, quantity }, config);
12067
- try {
12068
- const tx = await account.execute(calls);
12069
- await provider.waitForTransaction(tx.transaction_hash);
12070
- return { txHash: tx.transaction_hash };
12071
- } catch (err) {
12072
- throw new MedialaneError("Failed to fulfill ERC-1155 order", "TRANSACTION_FAILED", err);
12073
- }
12074
- }
12075
- async function cancelOrder1155(account, params, config) {
12076
- const { orderHash } = params;
12077
- const provider = getProvider(config);
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);
12081
- try {
12082
- const tx = await account.execute(calls);
12083
- await provider.waitForTransaction(tx.transaction_hash);
12084
- return { txHash: tx.transaction_hash };
12085
- } catch (err) {
12086
- throw new MedialaneError("Failed to cancel ERC-1155 order", "TRANSACTION_FAILED", err);
12087
- }
12088
- }
12089
- async function makeOffer1155(account, params, config) {
12090
- const {
12091
- nftContract,
12092
- tokenId,
12093
- amount,
12094
- price,
12095
- currency = DEFAULT_CURRENCY,
12096
- durationSeconds
12097
- } = params;
12098
- const contract = getContract(config);
12099
- const provider = getProvider(config);
12100
- const token = resolveToken(currency);
12101
- const priceWei = parseAmount(price, token.decimals);
12102
- const now = Math.floor(Date.now() / 1e3);
12103
- const startTime = now + START_TIME_BUFFER_SECS;
12104
- const endTime = now + durationSeconds;
12105
- const counter = (await contract.get_counter(account.address)).toString();
12106
- const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
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
12120
- },
12121
- config
12122
- );
12123
- const signatureArray = toSignatureArray(await account.signMessage(typedData));
12124
- const totalWei = BigInt(priceWei) * BigInt(amount);
12125
- const amountU256 = starknet.cairo.uint256(totalWei.toString());
12126
- const approveCall = {
12127
- contractAddress: token.address,
12128
- entrypoint: "approve",
12129
- calldata: [
12130
- config.marketplace1155Contract,
12131
- amountU256.low.toString(),
12132
- amountU256.high.toString()
12133
- ]
12134
- };
12135
- const calls = buildRegister1155Calls(
12136
- { orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
12137
- config
12138
- );
12139
- try {
12140
- const tx = await account.execute(calls);
12141
- await provider.waitForTransaction(tx.transaction_hash);
12142
- return { txHash: tx.transaction_hash };
12143
- } catch (err) {
12144
- throw new MedialaneError("Failed to make ERC-1155 offer", "TRANSACTION_FAILED", err);
12145
- }
12146
- }
12147
- async function checkoutCart1155(account, items, config) {
12148
- if (items.length === 0) throw new MedialaneError("Cart is empty", "INVALID_PARAMS");
12149
- const contract = getContract(config);
12150
- const provider = getProvider(config);
12151
- const tokenTotals = /* @__PURE__ */ new Map();
12152
- for (const item of items) {
12153
- const prev = tokenTotals.get(item.considerationToken) ?? 0n;
12154
- tokenTotals.set(item.considerationToken, prev + BigInt(item.considerationAmount));
12155
- }
12156
- const approveCalls = Array.from(tokenTotals.entries()).map(([tokenAddr, totalWei]) => {
12157
- const amount = starknet.cairo.uint256(totalWei.toString());
12158
- return {
12159
- contractAddress: tokenAddr,
12160
- entrypoint: "approve",
12161
- calldata: [
12162
- config.marketplace1155Contract,
12163
- amount.low.toString(),
12164
- amount.high.toString()
12165
- ]
12166
- };
12167
- });
12168
- const fulfillCalls = items.map(
12169
- (item) => contract.populate("fulfill_order", [item.orderHash, item.quantity ?? "1"])
12170
- );
12171
- try {
12172
- const tx = await account.execute([...approveCalls, ...fulfillCalls]);
12173
- await provider.waitForTransaction(tx.transaction_hash);
12174
- return { txHash: tx.transaction_hash };
12175
- } catch (err) {
12176
- throw new MedialaneError("ERC-1155 cart checkout failed", "TRANSACTION_FAILED", err);
12177
- }
12178
- }
12179
- async function getOrderDetails1155(orderHash, config) {
12180
- const contract = getContract(config);
12181
- return contract.get_order_details(orderHash);
12182
- }
12183
- async function getCounter1155(address, config) {
12184
- const contract = getContract(config);
12185
- return BigInt((await contract.get_counter(address)).toString());
12186
- }
12187
- async function incrementCounter1155(account, config) {
12188
- const contract = getContract(config);
12189
- const provider = getProvider(config);
12190
- const call = contract.populate("increment_counter", []);
12191
- try {
12192
- const tx = await account.execute(call);
12193
- await provider.waitForTransaction(tx.transaction_hash);
12194
- return { txHash: tx.transaction_hash };
12195
- } catch (err) {
12196
- throw new MedialaneError("Failed to increment counter (1155)", "TRANSACTION_FAILED", err);
12197
- }
12198
- }
12199
-
12200
- // src/starknet/marketplace1155/index.ts
12201
- var Medialane1155Module = class {
12202
- constructor(config) {
12203
- this.config = config;
12204
- }
12205
- // ─── Writes ───────────────────────────────────────────────────────────────
12206
- /**
12207
- * Create an ERC-1155 sell listing.
12208
- * Optionally grants `set_approval_for_all` if not already approved.
12209
- */
12210
- createListing(account, params) {
12211
- return createListing1155(account, params, this.config);
12212
- }
12213
- /**
12214
- * Make an offer (bid) on an ERC-1155 token.
12215
- * Approves the ERC-20 spend then calls `register_order` atomically.
12216
- */
12217
- makeOffer(account, params) {
12218
- return makeOffer1155(account, params, this.config);
12219
- }
12220
- /**
12221
- * Fulfill (buy) an ERC-1155 listing.
12222
- * Approves the payment token then calls `fulfill_order` atomically.
12223
- */
12224
- fulfillOrder(account, params) {
12225
- return fulfillOrder1155(account, params, this.config);
12226
- }
12227
- /**
12228
- * Cancel an ERC-1155 listing (offerer only).
12229
- */
12230
- cancelOrder(account, params) {
12231
- return cancelOrder1155(account, params, this.config);
12232
- }
12233
- /**
12234
- * Checkout a cart of ERC-1155 orders atomically.
12235
- * Signs one fulfillment per item (with quantity), sums ERC-20 approvals by token.
12236
- */
12237
- checkoutCart(account, items) {
12238
- return checkoutCart1155(account, items, this.config);
12239
- }
12240
- /** Bulk-cancel on the 1155 venue: bump the caller's counter. */
12241
- incrementCounter(account) {
12242
- return incrementCounter1155(account, this.config);
12243
- }
12244
- // ─── View calls ───────────────────────────────────────────────────────────
12245
- getOrderDetails(orderHash) {
12246
- return getOrderDetails1155(orderHash, this.config);
12247
- }
12248
- getCounter(address) {
12249
- return getCounter1155(address, this.config);
12250
- }
12251
- // ─── Typed data builders (for ChipiPay / custom signing flows) ───────────
12252
- buildListingTypedData(params, chainId) {
12253
- return build1155OrderTypedData(params, chainId);
12254
- }
12255
- buildCancellationTypedData(params, chainId) {
12256
- return build1155CancellationTypedData(params, chainId);
12257
- }
12258
- };
12259
- var PopService = class {
12260
- constructor(config) {
12261
- this.factoryAddress = getStarknetCoordinates(config.chain).popFactory;
12262
- }
12263
- _collection(address, account) {
12264
- return new starknet.Contract(POPCollectionABI, normalizeAddress("STARKNET", address), account);
12265
- }
12266
- async claim(account, collectionAddress) {
12267
- const call = this._collection(collectionAddress, account).populate("claim", []);
12268
- const res = await account.execute([call]);
12269
- return { txHash: res.transaction_hash };
12270
- }
12271
- async adminMint(account, params) {
12272
- const call = this._collection(params.collection, account).populate("admin_mint", [
12273
- params.recipient,
12274
- params.customUri ?? ""
12275
- ]);
12276
- const res = await account.execute([call]);
12277
- return { txHash: res.transaction_hash };
12278
- }
12279
- async addToAllowlist(account, params) {
12280
- const call = this._collection(params.collection, account).populate("add_to_allowlist", [params.address]);
12281
- const res = await account.execute([call]);
12282
- return { txHash: res.transaction_hash };
12283
- }
12284
- async batchAddToAllowlist(account, params) {
12285
- const collection = this._collection(params.collection, account);
12286
- const CHUNK = 200;
12287
- const calls = [];
12288
- for (let i = 0; i < params.addresses.length; i += CHUNK) {
12289
- calls.push(collection.populate("batch_add_to_allowlist", [params.addresses.slice(i, i + CHUNK)]));
12290
- }
12291
- const res = await account.execute(calls);
12292
- return { txHash: res.transaction_hash };
12293
- }
12294
- async removeFromAllowlist(account, params) {
12295
- const call = this._collection(params.collection, account).populate("remove_from_allowlist", [params.address]);
12296
- const res = await account.execute([call]);
12297
- return { txHash: res.transaction_hash };
12298
- }
12299
- async setTokenUri(account, params) {
12300
- const call = this._collection(params.collection, account).populate("set_token_uri", [
12301
- BigInt(params.tokenId),
12302
- params.uri
12303
- ]);
12304
- const res = await account.execute([call]);
12305
- return { txHash: res.transaction_hash };
12306
- }
12307
- async setPaused(account, params) {
12308
- const call = this._collection(params.collection, account).populate("set_paused", [params.paused]);
12309
- const res = await account.execute([call]);
12310
- return { txHash: res.transaction_hash };
12311
- }
12312
- async createCollection(account, params) {
12313
- const factory = new starknet.Contract(POPFactoryABI, this.factoryAddress, account);
12314
- const call = factory.populate("create_collection", [
12315
- params.name,
12316
- params.symbol,
12317
- params.baseUri,
12318
- params.claimEndTime,
12319
- { [params.eventType]: {} }
12320
- ]);
12321
- const res = await account.execute([call]);
12322
- return { txHash: res.transaction_hash };
12323
- }
12324
- };
12325
- function toContractConditions(c) {
12326
- return {
12327
- start_time: c.startTime,
12328
- end_time: c.endTime,
12329
- price: BigInt(c.price),
12330
- payment_token: c.paymentToken,
12331
- max_quantity_per_wallet: BigInt(c.maxQuantityPerWallet)
12332
- };
12333
- }
12334
- var DropService = class {
12335
- constructor(config) {
12336
- this.factoryAddress = getStarknetCoordinates(config.chain).dropFactory;
12337
- this.config = config;
12338
- }
12339
- _collection(address, account) {
12340
- return new starknet.Contract(DropCollectionABI, normalizeAddress("STARKNET", address), account);
12341
- }
12342
- async claim(account, collectionAddress, quantity = 1) {
12343
- const collection = this._collection(collectionAddress, account);
12344
- const qty = BigInt(quantity);
12345
- const claimCall = collection.populate("claim", [qty]);
12346
- const conditions = await collection.get_claim_conditions();
12347
- const price = BigInt(conditions.price);
12348
- const paymentToken = typeof conditions.payment_token === "bigint" ? "0x" + conditions.payment_token.toString(16) : conditions.payment_token;
12349
- const feeCall = price > 0n ? buildFeeCall(
12350
- { surface: "launchpad", token: paymentToken, grossAmount: price * qty },
12351
- this.config.feeConfig
12352
- ) : null;
12353
- const calls = feeCall ? [claimCall, feeCall] : [claimCall];
12354
- const res = await account.execute(calls);
12355
- return { txHash: res.transaction_hash };
11428
+ async claim(account, collectionAddress, quantity = 1) {
11429
+ const collection = this._collection(collectionAddress, account);
11430
+ const qty = BigInt(quantity);
11431
+ const claimCall = collection.populate("claim", [qty]);
11432
+ const conditions = await collection.get_claim_conditions();
11433
+ const price = BigInt(conditions.price);
11434
+ const paymentToken = typeof conditions.payment_token === "bigint" ? "0x" + conditions.payment_token.toString(16) : conditions.payment_token;
11435
+ const feeCall = price > 0n ? buildFeeCall(
11436
+ { surface: "launchpad", token: paymentToken, grossAmount: price * qty },
11437
+ this.config.feeConfig
11438
+ ) : null;
11439
+ const calls = feeCall ? [claimCall, feeCall] : [claimCall];
11440
+ const res = await account.execute(calls);
11441
+ return { txHash: res.transaction_hash };
12356
11442
  }
12357
11443
  async adminMint(account, params) {
12358
11444
  const call = this._collection(params.collection, account).populate("admin_mint", [
@@ -12974,54 +12060,412 @@ var SponsorshipService = class {
12974
12060
  }
12975
12061
  };
12976
12062
 
12977
- // src/starknet/client.ts
12978
- var MedialaneClient = class {
12979
- constructor(rawConfig = {}) {
12980
- this.config = resolveConfig(rawConfig);
12981
- this.marketplace = new MarketplaceModule(this.config);
12982
- this.marketplace1155 = new Medialane1155Module(this.config);
12983
- this.services = {
12984
- pop: new PopService(this.config),
12985
- drop: new DropService(this.config),
12986
- erc1155Collection: new ERC1155CollectionService(this.config),
12987
- creatorCoin: new CreatorCoinService(this.config),
12988
- ticket: new TicketService(this.config),
12989
- club: new ClubService(this.config),
12990
- sponsorship: new SponsorshipService(this.config)
12991
- };
12992
- if (!this.config.backendUrl) {
12993
- const sentinel = new ApiClient("https://medialane-sdk-no-backend.invalid", this.config.apiKey);
12994
- const apiMethodNames = new Set(
12995
- Object.getOwnPropertyNames(ApiClient.prototype).filter(
12996
- (k) => k !== "constructor" && typeof sentinel[k] === "function"
12997
- )
12998
- );
12999
- this.api = new Proxy(sentinel, {
13000
- get(target, prop, receiver) {
13001
- if (typeof prop === "symbol" || !apiMethodNames.has(prop)) {
13002
- return Reflect.get(target, prop, receiver);
13003
- }
13004
- return () => {
13005
- throw new Error(
13006
- `backendUrl not configured. Pass backendUrl to MedialaneClient to use .api.${String(prop)}()`
13007
- );
13008
- };
13009
- }
13010
- });
13011
- } else {
13012
- this.api = new ApiClient(this.config.backendUrl, this.config.apiKey, this.config.retryOptions, this.config.chain);
13013
- }
13014
- }
13015
- get chain() {
13016
- return this.config.chain;
13017
- }
13018
- get rpcUrl() {
13019
- return this.config.rpcUrl;
13020
- }
13021
- get marketplaceContract() {
13022
- return this.config.marketplaceContract;
13023
- }
13024
- };
12063
+ // src/starknet/client.ts
12064
+ var MedialaneClient = class {
12065
+ constructor(rawConfig = {}) {
12066
+ this.config = resolveConfig(rawConfig);
12067
+ this.services = {
12068
+ pop: new PopService(this.config),
12069
+ drop: new DropService(this.config),
12070
+ erc1155Collection: new ERC1155CollectionService(this.config),
12071
+ creatorCoin: new CreatorCoinService(this.config),
12072
+ ticket: new TicketService(this.config),
12073
+ club: new ClubService(this.config),
12074
+ sponsorship: new SponsorshipService(this.config)
12075
+ };
12076
+ if (!this.config.backendUrl) {
12077
+ const sentinel = new ApiClient("https://medialane-sdk-no-backend.invalid", this.config.apiKey);
12078
+ const apiMethodNames = new Set(
12079
+ Object.getOwnPropertyNames(ApiClient.prototype).filter(
12080
+ (k) => k !== "constructor" && typeof sentinel[k] === "function"
12081
+ )
12082
+ );
12083
+ this.api = new Proxy(sentinel, {
12084
+ get(target, prop, receiver) {
12085
+ if (typeof prop === "symbol" || !apiMethodNames.has(prop)) {
12086
+ return Reflect.get(target, prop, receiver);
12087
+ }
12088
+ return () => {
12089
+ throw new Error(
12090
+ `backendUrl not configured. Pass backendUrl to MedialaneClient to use .api.${String(prop)}()`
12091
+ );
12092
+ };
12093
+ }
12094
+ });
12095
+ } else {
12096
+ this.api = new ApiClient(this.config.backendUrl, this.config.apiKey, this.config.retryOptions, this.config.chain);
12097
+ }
12098
+ }
12099
+ get chain() {
12100
+ return this.config.chain;
12101
+ }
12102
+ get rpcUrl() {
12103
+ return this.config.rpcUrl;
12104
+ }
12105
+ get marketplaceContract() {
12106
+ return this.config.marketplaceContract;
12107
+ }
12108
+ };
12109
+
12110
+ // src/starknet/marketplace/errors.ts
12111
+ var MedialaneError = class extends Error {
12112
+ constructor(message, code = "UNKNOWN", cause) {
12113
+ super(message);
12114
+ this.code = code;
12115
+ this.cause = cause;
12116
+ this.name = "MedialaneError";
12117
+ }
12118
+ };
12119
+ var START_TIME_BUFFER_SECS = 30;
12120
+ function newContract(abi, address, providerOrAccount) {
12121
+ const C = starknet.Contract;
12122
+ return C.length === 1 ? new starknet.Contract({ abi, address, providerOrAccount }) : new starknet.Contract(
12123
+ abi,
12124
+ address,
12125
+ providerOrAccount
12126
+ );
12127
+ }
12128
+ function getChainId(config) {
12129
+ if (config.chain !== "STARKNET") {
12130
+ throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
12131
+ }
12132
+ return starknet.constants.StarknetChainId.SN_MAIN;
12133
+ }
12134
+ function resolveToken(currency) {
12135
+ const token = SUPPORTED_TOKENS.find(
12136
+ (t) => t.symbol === currency.toUpperCase() || t.address.toLowerCase() === currency.toLowerCase()
12137
+ );
12138
+ if (!token) throw new MedialaneError(`Unsupported currency: ${currency}`, "INVALID_PARAMS");
12139
+ return token;
12140
+ }
12141
+ var _providerCache = /* @__PURE__ */ new WeakMap();
12142
+ function getProvider(config) {
12143
+ let p = _providerCache.get(config);
12144
+ if (!p) {
12145
+ const urls = Array.from(/* @__PURE__ */ new Set([config.rpcUrl, ...PUBLIC_RPC_FALLBACKS]));
12146
+ p = new starknet.RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
12147
+ _providerCache.set(config, p);
12148
+ }
12149
+ return p;
12150
+ }
12151
+
12152
+ // src/starknet/marketplace/orders.ts
12153
+ var _contractCache = /* @__PURE__ */ new WeakMap();
12154
+ function makeContract(config) {
12155
+ const cached = _contractCache.get(config);
12156
+ if (cached) return cached;
12157
+ const contract = newContract(
12158
+ IPMarketplaceABI,
12159
+ config.marketplaceContract,
12160
+ getProvider(config)
12161
+ );
12162
+ const entry = { contract };
12163
+ _contractCache.set(config, entry);
12164
+ return entry;
12165
+ }
12166
+ async function getOrderDetails(orderHash, config) {
12167
+ const { contract } = makeContract(config);
12168
+ return contract.get_order_details(orderHash);
12169
+ }
12170
+ async function getCounter(address, config) {
12171
+ const { contract } = makeContract(config);
12172
+ return BigInt((await contract.get_counter(address)).toString());
12173
+ }
12174
+
12175
+ // src/starknet/marketplace1155/orders.ts
12176
+ var _contractCache2 = /* @__PURE__ */ new WeakMap();
12177
+ function getContract(config) {
12178
+ let c = _contractCache2.get(config);
12179
+ if (!c) {
12180
+ c = newContract(Medialane1155ABI, config.marketplace1155Contract, getProvider(config));
12181
+ _contractCache2.set(config, c);
12182
+ }
12183
+ return c;
12184
+ }
12185
+ async function getOrderDetails1155(orderHash, config) {
12186
+ const contract = getContract(config);
12187
+ return contract.get_order_details(orderHash);
12188
+ }
12189
+ async function getCounter1155(address, config) {
12190
+ const contract = getContract(config);
12191
+ return BigInt((await contract.get_counter(address)).toString());
12192
+ }
12193
+ var STARKNET_DOMAIN = [
12194
+ { name: "name", type: "shortstring" },
12195
+ { name: "version", type: "shortstring" },
12196
+ { name: "chainId", type: "shortstring" },
12197
+ { name: "revision", type: "shortstring" }
12198
+ ];
12199
+ var OFFER_ITEM = [
12200
+ { name: "item_type", type: "shortstring" },
12201
+ { name: "token", type: "ContractAddress" },
12202
+ { name: "identifier_or_criteria", type: "felt" },
12203
+ { name: "amount", type: "felt" }
12204
+ ];
12205
+ var CONSIDERATION_ITEM = [
12206
+ { name: "item_type", type: "shortstring" },
12207
+ { name: "token", type: "ContractAddress" },
12208
+ { name: "identifier_or_criteria", type: "felt" },
12209
+ { name: "amount", type: "felt" },
12210
+ { name: "recipient", type: "ContractAddress" }
12211
+ ];
12212
+ var ORDER_PARAMETERS = [
12213
+ { name: "offerer", type: "ContractAddress" },
12214
+ { name: "marketplace", type: "ContractAddress" },
12215
+ { name: "offer", type: "OfferItem" },
12216
+ { name: "consideration", type: "ConsiderationItem" },
12217
+ { name: "royalty_max_bps", type: "felt" },
12218
+ { name: "start_time", type: "felt" },
12219
+ { name: "end_time", type: "felt" },
12220
+ { name: "salt", type: "felt" },
12221
+ { name: "counter", type: "felt" }
12222
+ ];
12223
+ var ORDER_CANCELLATION = [
12224
+ { name: "order_hash", type: "felt" },
12225
+ { name: "offerer", type: "ContractAddress" }
12226
+ ];
12227
+ var DOMAIN_VERSION = {
12228
+ erc721: "5",
12229
+ erc1155: "4"
12230
+ };
12231
+ function buildDomain(standard, chainId) {
12232
+ return {
12233
+ name: "Medialane",
12234
+ version: DOMAIN_VERSION[standard],
12235
+ chainId,
12236
+ revision: starknet.TypedDataRevision.ACTIVE
12237
+ };
12238
+ }
12239
+ function buildOrderTypedData(message, chainId) {
12240
+ return {
12241
+ domain: buildDomain("erc721", chainId),
12242
+ primaryType: "OrderParameters",
12243
+ types: {
12244
+ StarknetDomain: STARKNET_DOMAIN,
12245
+ OrderParameters: ORDER_PARAMETERS,
12246
+ OfferItem: OFFER_ITEM,
12247
+ ConsiderationItem: CONSIDERATION_ITEM
12248
+ },
12249
+ message
12250
+ };
12251
+ }
12252
+ function build1155OrderTypedData(message, chainId) {
12253
+ return {
12254
+ domain: buildDomain("erc1155", chainId),
12255
+ primaryType: "OrderParameters",
12256
+ types: {
12257
+ StarknetDomain: STARKNET_DOMAIN,
12258
+ OrderParameters: ORDER_PARAMETERS,
12259
+ OfferItem: OFFER_ITEM,
12260
+ ConsiderationItem: CONSIDERATION_ITEM
12261
+ },
12262
+ message
12263
+ };
12264
+ }
12265
+ function buildCancellationTypedData(message, chainId) {
12266
+ return {
12267
+ domain: buildDomain("erc721", chainId),
12268
+ primaryType: "OrderCancellation",
12269
+ types: {
12270
+ StarknetDomain: STARKNET_DOMAIN,
12271
+ OrderCancellation: ORDER_CANCELLATION
12272
+ },
12273
+ message
12274
+ };
12275
+ }
12276
+ function build1155CancellationTypedData(message, chainId) {
12277
+ return {
12278
+ domain: buildDomain("erc1155", chainId),
12279
+ primaryType: "OrderCancellation",
12280
+ types: {
12281
+ StarknetDomain: STARKNET_DOMAIN,
12282
+ OrderCancellation: ORDER_CANCELLATION
12283
+ },
12284
+ message
12285
+ };
12286
+ }
12287
+
12288
+ // src/starknet/marketplace/build.ts
12289
+ function contractFor(cfg) {
12290
+ return newContract(IPMarketplaceABI, cfg.marketplaceContract, getProvider(cfg));
12291
+ }
12292
+ function buildListingOrder(i, cfg) {
12293
+ const orderParams = {
12294
+ offerer: i.offerer,
12295
+ marketplace: cfg.marketplaceContract,
12296
+ offer: { item_type: "ERC721", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: "1" },
12297
+ consideration: {
12298
+ item_type: "ERC20",
12299
+ token: i.paymentTokenAddress,
12300
+ identifier_or_criteria: "0",
12301
+ amount: i.priceWei,
12302
+ recipient: i.offerer
12303
+ },
12304
+ royalty_max_bps: i.royaltyMaxBps,
12305
+ start_time: String(i.startTime),
12306
+ end_time: String(i.endTime),
12307
+ salt: i.salt,
12308
+ counter: i.counter
12309
+ };
12310
+ const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
12311
+ return { orderParams, typedData };
12312
+ }
12313
+ function buildOfferOrder(i, cfg) {
12314
+ const orderParams = {
12315
+ offerer: i.offerer,
12316
+ marketplace: cfg.marketplaceContract,
12317
+ offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWei },
12318
+ consideration: {
12319
+ item_type: "ERC721",
12320
+ token: i.nftContract,
12321
+ identifier_or_criteria: i.tokenId,
12322
+ amount: "1",
12323
+ recipient: i.offerer
12324
+ },
12325
+ royalty_max_bps: i.royaltyMaxBps,
12326
+ start_time: String(i.startTime),
12327
+ end_time: String(i.endTime),
12328
+ salt: i.salt,
12329
+ counter: i.counter
12330
+ };
12331
+ const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
12332
+ return { orderParams, typedData };
12333
+ }
12334
+ function registerPayload(orderParams, signature) {
12335
+ return stringifyBigInts({
12336
+ parameters: {
12337
+ ...orderParams,
12338
+ offer: { ...orderParams.offer, item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type) },
12339
+ consideration: {
12340
+ ...orderParams.consideration,
12341
+ item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
12342
+ }
12343
+ },
12344
+ signature
12345
+ });
12346
+ }
12347
+ function buildRegisterCalls(a, cfg) {
12348
+ const registerCall = contractFor(cfg).populate("register_order", [registerPayload(a.orderParams, a.signature)]);
12349
+ return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
12350
+ }
12351
+ function buildFulfillCalls(a, cfg) {
12352
+ const u = starknet.cairo.uint256(a.totalPrice);
12353
+ const approve = {
12354
+ contractAddress: a.paymentToken,
12355
+ entrypoint: "approve",
12356
+ calldata: [cfg.marketplaceContract, u.low.toString(), u.high.toString()]
12357
+ };
12358
+ const fulfill = contractFor(cfg).populate("fulfill_order", [a.orderHash]);
12359
+ const fee = buildFeeCall(
12360
+ { surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
12361
+ cfg.feeConfig
12362
+ );
12363
+ return fee ? [approve, fulfill, fee] : [approve, fulfill];
12364
+ }
12365
+ function buildCancelCalls(a, cfg) {
12366
+ const cancelRequest = stringifyBigInts({
12367
+ cancelation: { order_hash: a.orderHash, offerer: a.offerer },
12368
+ signature: a.signature
12369
+ });
12370
+ return [contractFor(cfg).populate("cancel_order", [cancelRequest])];
12371
+ }
12372
+ function buildCancelTypedData(orderHash, offerer, cfg) {
12373
+ return stringifyBigInts(buildCancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg)));
12374
+ }
12375
+ function contractFor2(cfg) {
12376
+ return newContract(Medialane1155ABI, cfg.marketplace1155Contract, getProvider(cfg));
12377
+ }
12378
+ function buildListing1155Order(i, cfg) {
12379
+ const orderParams = {
12380
+ offerer: i.offerer,
12381
+ marketplace: cfg.marketplace1155Contract,
12382
+ offer: { item_type: "ERC1155", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: i.quantity },
12383
+ consideration: {
12384
+ item_type: "ERC20",
12385
+ token: i.paymentTokenAddress,
12386
+ identifier_or_criteria: "0",
12387
+ amount: i.priceWeiPerUnit,
12388
+ recipient: i.offerer
12389
+ },
12390
+ royalty_max_bps: i.royaltyMaxBps,
12391
+ start_time: String(i.startTime),
12392
+ end_time: String(i.endTime),
12393
+ salt: i.salt,
12394
+ counter: i.counter
12395
+ };
12396
+ const typedData = stringifyBigInts(
12397
+ build1155OrderTypedData(orderParams, getChainId(cfg))
12398
+ );
12399
+ return { orderParams, typedData };
12400
+ }
12401
+ function buildOffer1155Order(i, cfg) {
12402
+ const orderParams = {
12403
+ offerer: i.offerer,
12404
+ marketplace: cfg.marketplace1155Contract,
12405
+ offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWeiPerUnit },
12406
+ consideration: {
12407
+ item_type: "ERC1155",
12408
+ token: i.nftContract,
12409
+ identifier_or_criteria: i.tokenId,
12410
+ amount: i.quantity,
12411
+ recipient: i.offerer
12412
+ },
12413
+ royalty_max_bps: i.royaltyMaxBps,
12414
+ start_time: String(i.startTime),
12415
+ end_time: String(i.endTime),
12416
+ salt: i.salt,
12417
+ counter: i.counter
12418
+ };
12419
+ const typedData = stringifyBigInts(
12420
+ build1155OrderTypedData(orderParams, getChainId(cfg))
12421
+ );
12422
+ return { orderParams, typedData };
12423
+ }
12424
+ function registerPayload2(orderParams, signature) {
12425
+ return stringifyBigInts({
12426
+ parameters: {
12427
+ ...orderParams,
12428
+ offer: { ...orderParams.offer, item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type) },
12429
+ consideration: {
12430
+ ...orderParams.consideration,
12431
+ item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
12432
+ }
12433
+ },
12434
+ signature
12435
+ });
12436
+ }
12437
+ function buildRegister1155Calls(a, cfg) {
12438
+ const registerCall = contractFor2(cfg).populate("register_order", [registerPayload2(a.orderParams, a.signature)]);
12439
+ return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
12440
+ }
12441
+ function buildFulfill1155Calls(a, cfg) {
12442
+ const u = starknet.cairo.uint256(a.totalPrice);
12443
+ const approve = {
12444
+ contractAddress: a.paymentToken,
12445
+ entrypoint: "approve",
12446
+ calldata: [cfg.marketplace1155Contract, u.low.toString(), u.high.toString()]
12447
+ };
12448
+ const fulfill = contractFor2(cfg).populate("fulfill_order", [a.orderHash, a.quantity]);
12449
+ const fee = buildFeeCall(
12450
+ { surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
12451
+ cfg.feeConfig
12452
+ );
12453
+ return fee ? [approve, fulfill, fee] : [approve, fulfill];
12454
+ }
12455
+ function buildCancel1155Calls(a, cfg) {
12456
+ const cancelPayload = stringifyBigInts({
12457
+ cancelation: { order_hash: a.orderHash, offerer: a.offerer },
12458
+ signature: a.signature
12459
+ });
12460
+ return [contractFor2(cfg).populate("cancel_order", [cancelPayload])];
12461
+ }
12462
+ function buildCancel1155TypedData(orderHash, offerer, cfg) {
12463
+ return stringifyBigInts(
12464
+ build1155CancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg))
12465
+ );
12466
+ }
12467
+
12468
+ // src/starknet/venue.ts
13025
12469
  var NO_EXPIRY_SECONDS = 100 * 365 * 24 * 3600;
13026
12470
  var StarknetVenue = class {
13027
12471
  constructor(deps) {
@@ -13440,6 +12884,30 @@ function buybackQuoteRaw(teamCoinsRawValue, quoteDecimals) {
13440
12884
  function fdvHuman(supplyHuman) {
13441
12885
  return supplyHuman * LAUNCH_PRICE_QUOTE_PER_COIN;
13442
12886
  }
12887
+ function encodeByteArray(str) {
12888
+ const bytes = new TextEncoder().encode(str);
12889
+ const fullChunks = [];
12890
+ let i = 0;
12891
+ while (i + 31 <= bytes.length) {
12892
+ let val = 0n;
12893
+ for (const b of bytes.slice(i, i + 31)) {
12894
+ val = val << 8n | BigInt(b);
12895
+ }
12896
+ fullChunks.push(starknet.num.toHex(val));
12897
+ i += 31;
12898
+ }
12899
+ const remaining = bytes.slice(i);
12900
+ let pendingVal = 0n;
12901
+ for (const b of remaining) {
12902
+ pendingVal = pendingVal << 8n | BigInt(b);
12903
+ }
12904
+ return [
12905
+ fullChunks.length.toString(),
12906
+ ...fullChunks,
12907
+ starknet.num.toHex(pendingVal),
12908
+ remaining.length.toString()
12909
+ ];
12910
+ }
13443
12911
 
13444
12912
  exports.ADMIN_HEADERS = ADMIN_HEADERS;
13445
12913
  exports.ADMIN_SCOPE = ADMIN_SCOPE;
@@ -13472,9 +12940,7 @@ exports.IPSponsorshipLicenseABI = IPSponsorshipLicenseABI;
13472
12940
  exports.IPTicketCollectionABI = IPTicketCollectionABI;
13473
12941
  exports.IPTicketCollectionFactoryABI = IPTicketCollectionFactoryABI;
13474
12942
  exports.LAUNCH_PRICE_QUOTE_PER_COIN = LAUNCH_PRICE_QUOTE_PER_COIN;
13475
- exports.MarketplaceModule = MarketplaceModule;
13476
12943
  exports.Medialane1155ABI = Medialane1155ABI;
13477
- exports.Medialane1155Module = Medialane1155Module;
13478
12944
  exports.MedialaneApiError = MedialaneApiError;
13479
12945
  exports.MedialaneClient = MedialaneClient;
13480
12946
  exports.MedialaneError = MedialaneError;
@@ -13539,8 +13005,12 @@ exports.encodeByteArray = encodeByteArray;
13539
13005
  exports.fdvHuman = fdvHuman;
13540
13006
  exports.formatAmount = formatAmount;
13541
13007
  exports.getCoordinates = getCoordinates;
13008
+ exports.getCounter = getCounter;
13009
+ exports.getCounter1155 = getCounter1155;
13542
13010
  exports.getCreatorCoinPrice = getCreatorCoinPrice;
13543
13011
  exports.getListableTokens = getListableTokens;
13012
+ exports.getOrderDetails = getOrderDetails;
13013
+ exports.getOrderDetails1155 = getOrderDetails1155;
13544
13014
  exports.getService = getService;
13545
13015
  exports.getServicesByCapability = getServicesByCapability;
13546
13016
  exports.getSiwsStorageKey = getSiwsStorageKey;