@medialane/sdk 0.13.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) {
@@ -4836,15 +4877,26 @@ function toContractConditions(c) {
4836
4877
  };
4837
4878
  }
4838
4879
  var DropService = class {
4839
- constructor(_config) {
4880
+ constructor(config) {
4840
4881
  this.factoryAddress = DROP_FACTORY_CONTRACT_MAINNET;
4882
+ this.config = config;
4841
4883
  }
4842
4884
  _collection(address, account) {
4843
4885
  return new starknet.Contract(DropCollectionABI, normalizeAddress(address), account);
4844
4886
  }
4845
4887
  async claim(account, collectionAddress, quantity = 1) {
4846
- const call = this._collection(collectionAddress, account).populate("claim", [BigInt(quantity)]);
4847
- 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);
4848
4900
  return { txHash: res.transaction_hash };
4849
4901
  }
4850
4902
  async adminMint(account, params) {
@@ -5176,6 +5228,7 @@ exports.DropService = DropService;
5176
5228
  exports.ERC1155CollectionService = ERC1155CollectionService;
5177
5229
  exports.ERC1155_COLLECTION_CLASS_HASH_MAINNET = ERC1155_COLLECTION_CLASS_HASH_MAINNET;
5178
5230
  exports.ERC1155_FACTORY_CONTRACT_MAINNET = ERC1155_FACTORY_CONTRACT_MAINNET;
5231
+ exports.FeeConfigSchema = FeeConfigSchema;
5179
5232
  exports.INDEXER_START_BLOCK_MAINNET = INDEXER_START_BLOCK_MAINNET;
5180
5233
  exports.IPCollection1155ABI = IPCollection1155ABI;
5181
5234
  exports.IPCollection1155FactoryABI = IPCollection1155FactoryABI;
@@ -5210,6 +5263,7 @@ exports.build1155CancellationTypedData = build1155CancellationTypedData;
5210
5263
  exports.build1155FulfillmentTypedData = build1155FulfillmentTypedData;
5211
5264
  exports.build1155OrderTypedData = build1155OrderTypedData;
5212
5265
  exports.buildCancellationTypedData = buildCancellationTypedData;
5266
+ exports.buildFeeCall = buildFeeCall;
5213
5267
  exports.buildFulfillmentTypedData = buildFulfillmentTypedData;
5214
5268
  exports.buildOrderTypedData = buildOrderTypedData;
5215
5269
  exports.encodeByteArray = encodeByteArray;
@@ -5223,6 +5277,7 @@ exports.listServices = listServices;
5223
5277
  exports.normalizeAddress = normalizeAddress;
5224
5278
  exports.parseAmount = parseAmount;
5225
5279
  exports.resolveConfig = resolveConfig;
5280
+ exports.resolveFeeConfig = resolveFeeConfig;
5226
5281
  exports.shortenAddress = shortenAddress;
5227
5282
  exports.stringifyBigInts = stringifyBigInts;
5228
5283
  exports.u256ToBigInt = u256ToBigInt;