@medialane/sdk 0.13.0 → 0.14.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
@@ -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) {
@@ -4610,14 +4651,18 @@ var ApiClient = class {
4610
4651
  * Call after onboarding when ChipiPay confirms the wallet address.
4611
4652
  * Requires Clerk JWT; no tenant API key needed.
4612
4653
  */
4613
- async upsertMyWallet(clerkToken) {
4654
+ async upsertMyWallet(clerkToken, options = {}) {
4614
4655
  const url = `${this.baseUrl.replace(/\/$/, "")}/v1/users/me`;
4615
4656
  const res = await fetch(url, {
4616
4657
  method: "POST",
4617
4658
  headers: {
4618
4659
  "Content-Type": "application/json",
4619
4660
  "Authorization": `Bearer ${clerkToken}`
4620
- }
4661
+ },
4662
+ body: JSON.stringify({
4663
+ walletType: options.walletType ?? "UNKNOWN",
4664
+ appSource: options.appSource ?? "MEDIALANE_SDK"
4665
+ })
4621
4666
  });
4622
4667
  return this.checkResponse(res);
4623
4668
  }
@@ -4836,15 +4881,26 @@ function toContractConditions(c) {
4836
4881
  };
4837
4882
  }
4838
4883
  var DropService = class {
4839
- constructor(_config) {
4884
+ constructor(config) {
4840
4885
  this.factoryAddress = DROP_FACTORY_CONTRACT_MAINNET;
4886
+ this.config = config;
4841
4887
  }
4842
4888
  _collection(address, account) {
4843
4889
  return new starknet.Contract(DropCollectionABI, normalizeAddress(address), account);
4844
4890
  }
4845
4891
  async claim(account, collectionAddress, quantity = 1) {
4846
- const call = this._collection(collectionAddress, account).populate("claim", [BigInt(quantity)]);
4847
- const res = await account.execute([call]);
4892
+ const collection = this._collection(collectionAddress, account);
4893
+ const qty = BigInt(quantity);
4894
+ const claimCall = collection.populate("claim", [qty]);
4895
+ const conditions = await collection.get_claim_conditions();
4896
+ const price = BigInt(conditions.price);
4897
+ const paymentToken = typeof conditions.payment_token === "bigint" ? "0x" + conditions.payment_token.toString(16) : conditions.payment_token;
4898
+ const feeCall = price > 0n ? buildFeeCall(
4899
+ { surface: "launchpad", token: paymentToken, grossAmount: price * qty },
4900
+ this.config.feeConfig
4901
+ ) : null;
4902
+ const calls = feeCall ? [claimCall, feeCall] : [claimCall];
4903
+ const res = await account.execute(calls);
4848
4904
  return { txHash: res.transaction_hash };
4849
4905
  }
4850
4906
  async adminMint(account, params) {
@@ -5176,6 +5232,7 @@ exports.DropService = DropService;
5176
5232
  exports.ERC1155CollectionService = ERC1155CollectionService;
5177
5233
  exports.ERC1155_COLLECTION_CLASS_HASH_MAINNET = ERC1155_COLLECTION_CLASS_HASH_MAINNET;
5178
5234
  exports.ERC1155_FACTORY_CONTRACT_MAINNET = ERC1155_FACTORY_CONTRACT_MAINNET;
5235
+ exports.FeeConfigSchema = FeeConfigSchema;
5179
5236
  exports.INDEXER_START_BLOCK_MAINNET = INDEXER_START_BLOCK_MAINNET;
5180
5237
  exports.IPCollection1155ABI = IPCollection1155ABI;
5181
5238
  exports.IPCollection1155FactoryABI = IPCollection1155FactoryABI;
@@ -5210,6 +5267,7 @@ exports.build1155CancellationTypedData = build1155CancellationTypedData;
5210
5267
  exports.build1155FulfillmentTypedData = build1155FulfillmentTypedData;
5211
5268
  exports.build1155OrderTypedData = build1155OrderTypedData;
5212
5269
  exports.buildCancellationTypedData = buildCancellationTypedData;
5270
+ exports.buildFeeCall = buildFeeCall;
5213
5271
  exports.buildFulfillmentTypedData = buildFulfillmentTypedData;
5214
5272
  exports.buildOrderTypedData = buildOrderTypedData;
5215
5273
  exports.encodeByteArray = encodeByteArray;
@@ -5223,6 +5281,7 @@ exports.listServices = listServices;
5223
5281
  exports.normalizeAddress = normalizeAddress;
5224
5282
  exports.parseAmount = parseAmount;
5225
5283
  exports.resolveConfig = resolveConfig;
5284
+ exports.resolveFeeConfig = resolveFeeConfig;
5226
5285
  exports.shortenAddress = shortenAddress;
5227
5286
  exports.stringifyBigInts = stringifyBigInts;
5228
5287
  exports.u256ToBigInt = u256ToBigInt;