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