@medialane/sdk 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -63,6 +63,34 @@ var COLLECTION_1155_CONTRACT_MAINNET = "0x006b2dc7ca7c4f466bb4575ba043d934310f05
63
63
  var ERC1155_FACTORY_CONTRACT_MAINNET = COLLECTION_1155_CONTRACT_MAINNET;
64
64
  var COLLECTION_1155_CLASS_HASH_MAINNET = "0x39a85126c6627db263617e5bce2bb72e49d2bb1f20961efc8b8954665bcfd25";
65
65
  var ERC1155_COLLECTION_CLASS_HASH_MAINNET = COLLECTION_1155_CLASS_HASH_MAINNET;
66
+ var FeeConfigSchema = zod.z.object({
67
+ enabled: zod.z.boolean().default(true),
68
+ fundAddress: zod.z.string().min(1).optional(),
69
+ marketplaceBps: zod.z.number().int().min(0).max(1e4).default(100),
70
+ launchpadBps: zod.z.number().int().min(0).max(1e4).default(100)
71
+ });
72
+ function resolveFeeConfig(raw) {
73
+ const p = FeeConfigSchema.parse(raw ?? {});
74
+ return {
75
+ enabled: p.enabled,
76
+ fundAddress: p.fundAddress,
77
+ marketplaceBps: p.marketplaceBps,
78
+ launchpadBps: p.launchpadBps
79
+ };
80
+ }
81
+ function buildFeeCall(p, cfg) {
82
+ if (!cfg.enabled || !cfg.fundAddress) return null;
83
+ const bps = p.surface === "marketplace" ? cfg.marketplaceBps : cfg.launchpadBps;
84
+ if (bps <= 0) return null;
85
+ const fee = p.grossAmount * BigInt(bps) / 10000n;
86
+ if (fee <= 0n) return null;
87
+ const u = starknet.cairo.uint256(fee.toString());
88
+ return {
89
+ contractAddress: p.token,
90
+ entrypoint: "transfer",
91
+ calldata: [cfg.fundAddress, u.low.toString(), u.high.toString()]
92
+ };
93
+ }
66
94
 
67
95
  // src/config.ts
68
96
  var MedialaneConfigSchema = zod.z.object({
@@ -80,7 +108,8 @@ var MedialaneConfigSchema = zod.z.object({
80
108
  maxAttempts: zod.z.number().int().min(1).max(10).optional(),
81
109
  baseDelayMs: zod.z.number().int().min(0).optional(),
82
110
  maxDelayMs: zod.z.number().int().min(0).optional()
83
- }).optional()
111
+ }).optional(),
112
+ feeConfig: FeeConfigSchema.optional()
84
113
  });
85
114
  function resolveConfig(raw) {
86
115
  const parsed = MedialaneConfigSchema.parse(raw);
@@ -97,7 +126,8 @@ function resolveConfig(raw) {
97
126
  collection721Contract,
98
127
  collectionContract: collection721Contract,
99
128
  collection1155Contract: parsed.collection1155Contract ?? COLLECTION_1155_CONTRACT_MAINNET,
100
- retryOptions: parsed.retryOptions
129
+ retryOptions: parsed.retryOptions,
130
+ feeConfig: resolveFeeConfig(parsed.feeConfig)
101
131
  };
102
132
  }
103
133
  function buildOrderTypedData(message, chainId) {
@@ -3542,8 +3572,13 @@ async function fulfillOrder(account, params, config) {
3542
3572
  ]
3543
3573
  };
3544
3574
  const fulfillCall = contract.populate("fulfill_order", [fulfillPayload]);
3575
+ const feeCall = buildFeeCall(
3576
+ { surface: "marketplace", token: paymentToken, grossAmount: BigInt(totalPrice) },
3577
+ config.feeConfig
3578
+ );
3579
+ const calls = feeCall ? [approveCall, fulfillCall, feeCall] : [approveCall, fulfillCall];
3545
3580
  try {
3546
- const tx = await account.execute([approveCall, fulfillCall]);
3581
+ const tx = await account.execute(calls);
3547
3582
  await provider.waitForTransaction(tx.transaction_hash);
3548
3583
  return { txHash: tx.transaction_hash };
3549
3584
  } catch (err) {
@@ -3652,8 +3687,14 @@ async function checkoutCart(account, items, config) {
3652
3687
  });
3653
3688
  fulfillCalls.push(contract.populate("fulfill_order", [fulfillPayload]));
3654
3689
  }
3690
+ const feeCalls = Array.from(tokenTotals.entries()).map(
3691
+ ([tokenAddr, totalWei]) => buildFeeCall(
3692
+ { surface: "marketplace", token: tokenAddr, grossAmount: totalWei },
3693
+ config.feeConfig
3694
+ )
3695
+ ).filter((c) => c !== null);
3655
3696
  try {
3656
- const tx = await account.execute([...approveCalls, ...fulfillCalls]);
3697
+ const tx = await account.execute([...approveCalls, ...fulfillCalls, ...feeCalls]);
3657
3698
  await provider.waitForTransaction(tx.transaction_hash);
3658
3699
  return { txHash: tx.transaction_hash };
3659
3700
  } catch (err) {
@@ -4326,11 +4367,10 @@ var ApiClient = class {
4326
4367
  );
4327
4368
  }
4328
4369
  // ─── Collections ───────────────────────────────────────────────────────────
4329
- getCollections(page = 1, limit = 20, isKnown, sort, source, service) {
4370
+ getCollections(page = 1, limit = 20, isKnown, sort, service) {
4330
4371
  const params = new URLSearchParams({ page: String(page), limit: String(limit) });
4331
4372
  if (isKnown !== void 0) params.set("isKnown", String(isKnown));
4332
4373
  if (sort) params.set("sort", sort);
4333
- if (source) params.set("source", source);
4334
4374
  if (service) params.set("service", service);
4335
4375
  return this.get(`/v1/collections?${params}`);
4336
4376
  }
@@ -4837,15 +4877,26 @@ function toContractConditions(c) {
4837
4877
  };
4838
4878
  }
4839
4879
  var DropService = class {
4840
- constructor(_config) {
4880
+ constructor(config) {
4841
4881
  this.factoryAddress = DROP_FACTORY_CONTRACT_MAINNET;
4882
+ this.config = config;
4842
4883
  }
4843
4884
  _collection(address, account) {
4844
4885
  return new starknet.Contract(DropCollectionABI, normalizeAddress(address), account);
4845
4886
  }
4846
4887
  async claim(account, collectionAddress, quantity = 1) {
4847
- const call = this._collection(collectionAddress, account).populate("claim", [BigInt(quantity)]);
4848
- const res = await account.execute([call]);
4888
+ const collection = this._collection(collectionAddress, account);
4889
+ const qty = BigInt(quantity);
4890
+ const claimCall = collection.populate("claim", [qty]);
4891
+ const conditions = await collection.get_claim_conditions();
4892
+ const price = BigInt(conditions.price);
4893
+ const paymentToken = typeof conditions.payment_token === "bigint" ? "0x" + conditions.payment_token.toString(16) : conditions.payment_token;
4894
+ const feeCall = price > 0n ? buildFeeCall(
4895
+ { surface: "launchpad", token: paymentToken, grossAmount: price * qty },
4896
+ this.config.feeConfig
4897
+ ) : null;
4898
+ const calls = feeCall ? [claimCall, feeCall] : [claimCall];
4899
+ const res = await account.execute(calls);
4849
4900
  return { txHash: res.transaction_hash };
4850
4901
  }
4851
4902
  async adminMint(account, params) {
@@ -5177,6 +5228,7 @@ exports.DropService = DropService;
5177
5228
  exports.ERC1155CollectionService = ERC1155CollectionService;
5178
5229
  exports.ERC1155_COLLECTION_CLASS_HASH_MAINNET = ERC1155_COLLECTION_CLASS_HASH_MAINNET;
5179
5230
  exports.ERC1155_FACTORY_CONTRACT_MAINNET = ERC1155_FACTORY_CONTRACT_MAINNET;
5231
+ exports.FeeConfigSchema = FeeConfigSchema;
5180
5232
  exports.INDEXER_START_BLOCK_MAINNET = INDEXER_START_BLOCK_MAINNET;
5181
5233
  exports.IPCollection1155ABI = IPCollection1155ABI;
5182
5234
  exports.IPCollection1155FactoryABI = IPCollection1155FactoryABI;
@@ -5211,6 +5263,7 @@ exports.build1155CancellationTypedData = build1155CancellationTypedData;
5211
5263
  exports.build1155FulfillmentTypedData = build1155FulfillmentTypedData;
5212
5264
  exports.build1155OrderTypedData = build1155OrderTypedData;
5213
5265
  exports.buildCancellationTypedData = buildCancellationTypedData;
5266
+ exports.buildFeeCall = buildFeeCall;
5214
5267
  exports.buildFulfillmentTypedData = buildFulfillmentTypedData;
5215
5268
  exports.buildOrderTypedData = buildOrderTypedData;
5216
5269
  exports.encodeByteArray = encodeByteArray;
@@ -5224,6 +5277,7 @@ exports.listServices = listServices;
5224
5277
  exports.normalizeAddress = normalizeAddress;
5225
5278
  exports.parseAmount = parseAmount;
5226
5279
  exports.resolveConfig = resolveConfig;
5280
+ exports.resolveFeeConfig = resolveFeeConfig;
5227
5281
  exports.shortenAddress = shortenAddress;
5228
5282
  exports.stringifyBigInts = stringifyBigInts;
5229
5283
  exports.u256ToBigInt = u256ToBigInt;