@medialane/sdk 0.62.0 → 0.64.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/evm/index.cjs +3 -3
- package/dist/evm/index.cjs.map +1 -1
- package/dist/evm/index.d.cts +1 -1
- package/dist/evm/index.d.ts +1 -1
- package/dist/evm/index.js +3 -3
- package/dist/evm/index.js.map +1 -1
- package/dist/{index-CsiUiS0q.d.ts → index-DMNv-Oj0.d.ts} +38 -189
- package/dist/{index-CyZH_h8o.d.cts → index-_q2B0g3M.d.cts} +38 -189
- package/dist/index.cjs +601 -1041
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +599 -1041
- package/dist/index.js.map +1 -1
- package/dist/solana/index.cjs +3 -3
- package/dist/solana/index.cjs.map +1 -1
- package/dist/solana/index.d.cts +1 -1
- package/dist/solana/index.d.ts +1 -1
- package/dist/solana/index.js +3 -3
- package/dist/solana/index.js.map +1 -1
- package/dist/starknet/index.cjs +2133 -2585
- package/dist/starknet/index.cjs.map +1 -1
- package/dist/starknet/index.d.cts +3 -3
- package/dist/starknet/index.d.ts +3 -3
- package/dist/starknet/index.js +7247 -7701
- package/dist/starknet/index.js.map +1 -1
- package/dist/stellar/index.cjs +3 -3
- package/dist/stellar/index.cjs.map +1 -1
- package/dist/stellar/index.d.cts +1 -1
- package/dist/stellar/index.d.ts +1 -1
- package/dist/stellar/index.js +3 -3
- package/dist/stellar/index.js.map +1 -1
- package/dist/{types-V6imkXvR.d.cts → types-Bx3ax9lW.d.cts} +20 -3
- package/dist/{types-V6imkXvR.d.ts → types-Bx3ax9lW.d.ts} +20 -3
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -37,9 +37,9 @@ var COORDINATES = {
|
|
|
37
37
|
creatorCoinFactoryClassHash: "0x51765926b1344c9a20b8cd4b5abe7b7d47375ae97cf6804db3ea5d4b05a9b55",
|
|
38
38
|
creatorCoinStartBlock: 10474544,
|
|
39
39
|
ekuboCore: "0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b",
|
|
40
|
-
ipTicketsFactory: "
|
|
41
|
-
ipTicketCollectionClassHash: "
|
|
42
|
-
ipTicketsStartBlock:
|
|
40
|
+
ipTicketsFactory: "0x03ffef4162fe2c44e17d6be2aad3553cab0ac2274cd0b1bb3fafb12fd66695c1",
|
|
41
|
+
ipTicketCollectionClassHash: "0x036393fb4241ed55bd12d8b328ed877d08100fadf9150a650e2b84cbab95e1d4",
|
|
42
|
+
ipTicketsStartBlock: 11689800,
|
|
43
43
|
ipClubRegistry: "0x00e189c619b6bb07d78973a149641c59c37eb0716f8584d7520bce12d303eede",
|
|
44
44
|
ipClubNftClassHash: "0x02bc9b20cca21b04245e9215bf7121f4d7295b195890e449b472b573017fb889",
|
|
45
45
|
ipClubStartBlock: 11404776,
|
|
@@ -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/
|
|
11448
|
-
var
|
|
11449
|
-
constructor(
|
|
11450
|
-
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
|
|
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,856 +11406,39 @@ function buildFeeCall(p, cfg) {
|
|
|
11466
11406
|
calldata: [cfg.fundAddress, u.low.toString(), u.high.toString()]
|
|
11467
11407
|
};
|
|
11468
11408
|
}
|
|
11469
|
-
|
|
11470
|
-
|
|
11471
|
-
|
|
11472
|
-
|
|
11473
|
-
|
|
11474
|
-
|
|
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
|
-
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
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
|
-
|
|
11491
|
-
if (Array.isArray(sig)) return sig;
|
|
11492
|
-
const s = sig;
|
|
11493
|
-
return [s.r.toString(), s.s.toString()];
|
|
11494
|
-
}
|
|
11495
|
-
function getChainId(config) {
|
|
11496
|
-
if (config.chain !== "STARKNET") {
|
|
11497
|
-
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);
|
|
11498
11427
|
}
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
}
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
p = new starknet.RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
|
|
11514
|
-
_providerCache.set(config, p);
|
|
11515
|
-
}
|
|
11516
|
-
return p;
|
|
11517
|
-
}
|
|
11518
|
-
|
|
11519
|
-
// src/starknet/marketplace/orders.ts
|
|
11520
|
-
var _contractCache = /* @__PURE__ */ new WeakMap();
|
|
11521
|
-
function makeContract(config) {
|
|
11522
|
-
const cached = _contractCache.get(config);
|
|
11523
|
-
const provider = getProvider(config);
|
|
11524
|
-
if (cached) return { ...cached, provider };
|
|
11525
|
-
const contract = new starknet.Contract(
|
|
11526
|
-
IPMarketplaceABI,
|
|
11527
|
-
config.marketplaceContract,
|
|
11528
|
-
provider
|
|
11529
|
-
);
|
|
11530
|
-
_contractCache.set(config, { contract });
|
|
11531
|
-
return { contract, provider };
|
|
11532
|
-
}
|
|
11533
|
-
async function createListing(account, params, config) {
|
|
11534
|
-
const { nftContract, tokenId, price, currency = DEFAULT_CURRENCY, durationSeconds } = params;
|
|
11535
|
-
const { contract, provider } = makeContract(config);
|
|
11536
|
-
const token = resolveToken(currency);
|
|
11537
|
-
const priceWei = parseAmount(price, token.decimals);
|
|
11538
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
11539
|
-
const startTime = now + START_TIME_BUFFER_SECS;
|
|
11540
|
-
const endTime = now + durationSeconds;
|
|
11541
|
-
const counter = (await contract.get_counter(account.address)).toString();
|
|
11542
|
-
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11543
|
-
const orderParams = {
|
|
11544
|
-
offerer: account.address,
|
|
11545
|
-
marketplace: config.marketplaceContract,
|
|
11546
|
-
offer: {
|
|
11547
|
-
item_type: "ERC721",
|
|
11548
|
-
token: nftContract,
|
|
11549
|
-
identifier_or_criteria: tokenId,
|
|
11550
|
-
amount: "1"
|
|
11551
|
-
},
|
|
11552
|
-
consideration: {
|
|
11553
|
-
item_type: "ERC20",
|
|
11554
|
-
token: token.address,
|
|
11555
|
-
identifier_or_criteria: "0",
|
|
11556
|
-
amount: priceWei,
|
|
11557
|
-
recipient: account.address
|
|
11558
|
-
},
|
|
11559
|
-
royalty_max_bps: royaltyMaxBps,
|
|
11560
|
-
start_time: startTime.toString(),
|
|
11561
|
-
end_time: endTime.toString(),
|
|
11562
|
-
salt: generateSalt(),
|
|
11563
|
-
counter
|
|
11564
|
-
};
|
|
11565
|
-
const chainId = getChainId(config);
|
|
11566
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
11567
|
-
const signature = await account.signMessage(typedData);
|
|
11568
|
-
const signatureArray = toSignatureArray(signature);
|
|
11569
|
-
const registerPayload = stringifyBigInts({
|
|
11570
|
-
parameters: {
|
|
11571
|
-
...orderParams,
|
|
11572
|
-
offer: {
|
|
11573
|
-
...orderParams.offer,
|
|
11574
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
11575
|
-
},
|
|
11576
|
-
consideration: {
|
|
11577
|
-
...orderParams.consideration,
|
|
11578
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11579
|
-
}
|
|
11580
|
-
},
|
|
11581
|
-
signature: signatureArray
|
|
11582
|
-
});
|
|
11583
|
-
const tokenIdUint256 = starknet.cairo.uint256(tokenId);
|
|
11584
|
-
let isAlreadyApproved = false;
|
|
11585
|
-
try {
|
|
11586
|
-
const result = await provider.callContract({
|
|
11587
|
-
contractAddress: nftContract,
|
|
11588
|
-
entrypoint: "get_approved",
|
|
11589
|
-
calldata: [tokenIdUint256.low.toString(), tokenIdUint256.high.toString()]
|
|
11590
|
-
});
|
|
11591
|
-
isAlreadyApproved = BigInt(result[0]).toString() === BigInt(config.marketplaceContract).toString();
|
|
11592
|
-
} catch {
|
|
11593
|
-
}
|
|
11594
|
-
const registerCall = contract.populate("register_order", [registerPayload]);
|
|
11595
|
-
const calls = isAlreadyApproved ? [registerCall] : [
|
|
11596
|
-
{
|
|
11597
|
-
contractAddress: nftContract,
|
|
11598
|
-
entrypoint: "approve",
|
|
11599
|
-
calldata: [
|
|
11600
|
-
config.marketplaceContract,
|
|
11601
|
-
tokenIdUint256.low.toString(),
|
|
11602
|
-
tokenIdUint256.high.toString()
|
|
11603
|
-
]
|
|
11604
|
-
},
|
|
11605
|
-
registerCall
|
|
11606
|
-
];
|
|
11607
|
-
try {
|
|
11608
|
-
const tx = await account.execute(calls);
|
|
11609
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11610
|
-
return { txHash: tx.transaction_hash };
|
|
11611
|
-
} catch (err) {
|
|
11612
|
-
throw new MedialaneError("Failed to create listing", "TRANSACTION_FAILED", err);
|
|
11613
|
-
}
|
|
11614
|
-
}
|
|
11615
|
-
async function makeOffer(account, params, config) {
|
|
11616
|
-
const { nftContract, tokenId, price, currency = DEFAULT_CURRENCY, durationSeconds } = params;
|
|
11617
|
-
const { contract, provider } = makeContract(config);
|
|
11618
|
-
const token = resolveToken(currency);
|
|
11619
|
-
const priceWei = parseAmount(price, token.decimals);
|
|
11620
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
11621
|
-
const startTime = now + START_TIME_BUFFER_SECS;
|
|
11622
|
-
const endTime = now + durationSeconds;
|
|
11623
|
-
const counter = (await contract.get_counter(account.address)).toString();
|
|
11624
|
-
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11625
|
-
const orderParams = {
|
|
11626
|
-
offerer: account.address,
|
|
11627
|
-
marketplace: config.marketplaceContract,
|
|
11628
|
-
offer: {
|
|
11629
|
-
item_type: "ERC20",
|
|
11630
|
-
token: token.address,
|
|
11631
|
-
identifier_or_criteria: "0",
|
|
11632
|
-
amount: priceWei
|
|
11633
|
-
},
|
|
11634
|
-
consideration: {
|
|
11635
|
-
item_type: "ERC721",
|
|
11636
|
-
token: nftContract,
|
|
11637
|
-
identifier_or_criteria: tokenId,
|
|
11638
|
-
amount: "1",
|
|
11639
|
-
recipient: account.address
|
|
11640
|
-
},
|
|
11641
|
-
royalty_max_bps: royaltyMaxBps,
|
|
11642
|
-
start_time: startTime.toString(),
|
|
11643
|
-
end_time: endTime.toString(),
|
|
11644
|
-
salt: generateSalt(),
|
|
11645
|
-
counter
|
|
11646
|
-
};
|
|
11647
|
-
const chainId = getChainId(config);
|
|
11648
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
11649
|
-
const signature = await account.signMessage(typedData);
|
|
11650
|
-
const signatureArray = toSignatureArray(signature);
|
|
11651
|
-
const registerPayload = stringifyBigInts({
|
|
11652
|
-
parameters: {
|
|
11653
|
-
...orderParams,
|
|
11654
|
-
offer: {
|
|
11655
|
-
...orderParams.offer,
|
|
11656
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
11657
|
-
},
|
|
11658
|
-
consideration: {
|
|
11659
|
-
...orderParams.consideration,
|
|
11660
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11661
|
-
}
|
|
11662
|
-
},
|
|
11663
|
-
signature: signatureArray
|
|
11664
|
-
});
|
|
11665
|
-
const amountUint256 = starknet.cairo.uint256(priceWei);
|
|
11666
|
-
const approveCall = {
|
|
11667
|
-
contractAddress: token.address,
|
|
11668
|
-
entrypoint: "approve",
|
|
11669
|
-
calldata: [
|
|
11670
|
-
config.marketplaceContract,
|
|
11671
|
-
amountUint256.low.toString(),
|
|
11672
|
-
amountUint256.high.toString()
|
|
11673
|
-
]
|
|
11674
|
-
};
|
|
11675
|
-
const registerCall = contract.populate("register_order", [registerPayload]);
|
|
11676
|
-
try {
|
|
11677
|
-
const tx = await account.execute([approveCall, registerCall]);
|
|
11678
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11679
|
-
return { txHash: tx.transaction_hash };
|
|
11680
|
-
} catch (err) {
|
|
11681
|
-
throw new MedialaneError("Failed to make offer", "TRANSACTION_FAILED", err);
|
|
11682
|
-
}
|
|
11683
|
-
}
|
|
11684
|
-
async function fulfillOrder(account, params, config) {
|
|
11685
|
-
const { orderHash, paymentToken, totalPrice } = params;
|
|
11686
|
-
const { contract, provider } = makeContract(config);
|
|
11687
|
-
const totalPriceU256 = starknet.cairo.uint256(totalPrice);
|
|
11688
|
-
const approveCall = {
|
|
11689
|
-
contractAddress: paymentToken,
|
|
11690
|
-
entrypoint: "approve",
|
|
11691
|
-
calldata: [
|
|
11692
|
-
config.marketplaceContract,
|
|
11693
|
-
totalPriceU256.low.toString(),
|
|
11694
|
-
totalPriceU256.high.toString()
|
|
11695
|
-
]
|
|
11696
|
-
};
|
|
11697
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash]);
|
|
11698
|
-
const feeCall = buildFeeCall(
|
|
11699
|
-
{ surface: "marketplace", token: paymentToken, grossAmount: BigInt(totalPrice) },
|
|
11700
|
-
config.feeConfig
|
|
11701
|
-
);
|
|
11702
|
-
const calls = feeCall ? [approveCall, fulfillCall, feeCall] : [approveCall, fulfillCall];
|
|
11703
|
-
try {
|
|
11704
|
-
const tx = await account.execute(calls);
|
|
11705
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11706
|
-
return { txHash: tx.transaction_hash };
|
|
11707
|
-
} catch (err) {
|
|
11708
|
-
throw new MedialaneError("Failed to fulfill order", "TRANSACTION_FAILED", err);
|
|
11709
|
-
}
|
|
11710
|
-
}
|
|
11711
|
-
async function cancelOrder(account, params, config) {
|
|
11712
|
-
const { orderHash } = params;
|
|
11713
|
-
const { contract, provider } = makeContract(config);
|
|
11714
|
-
const chainId = getChainId(config);
|
|
11715
|
-
const cancelParams = {
|
|
11716
|
-
order_hash: orderHash,
|
|
11717
|
-
offerer: account.address
|
|
11718
|
-
};
|
|
11719
|
-
const typedData = stringifyBigInts(
|
|
11720
|
-
buildCancellationTypedData(cancelParams, chainId)
|
|
11721
|
-
);
|
|
11722
|
-
const signature = await account.signMessage(typedData);
|
|
11723
|
-
const signatureArray = toSignatureArray(signature);
|
|
11724
|
-
const cancelRequest = stringifyBigInts({
|
|
11725
|
-
cancelation: cancelParams,
|
|
11726
|
-
signature: signatureArray
|
|
11727
|
-
});
|
|
11728
|
-
const call = contract.populate("cancel_order", [cancelRequest]);
|
|
11729
|
-
try {
|
|
11730
|
-
const tx = await account.execute(call);
|
|
11731
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11732
|
-
return { txHash: tx.transaction_hash };
|
|
11733
|
-
} catch (err) {
|
|
11734
|
-
throw new MedialaneError("Failed to cancel order", "TRANSACTION_FAILED", err);
|
|
11735
|
-
}
|
|
11736
|
-
}
|
|
11737
|
-
async function mint(account, params, config) {
|
|
11738
|
-
const { collectionId, recipient, tokenUri, royaltyBps, collectionContract } = params;
|
|
11739
|
-
const provider = getProvider(config);
|
|
11740
|
-
const contractAddress = collectionContract ?? config.collectionContract;
|
|
11741
|
-
const id = starknet.cairo.uint256(collectionId);
|
|
11742
|
-
const calldata = [
|
|
11743
|
-
id.low.toString(),
|
|
11744
|
-
id.high.toString(),
|
|
11745
|
-
recipient,
|
|
11746
|
-
...encodeByteArray(tokenUri),
|
|
11747
|
-
royaltyBps.toString()
|
|
11748
|
-
];
|
|
11749
|
-
try {
|
|
11750
|
-
const tx = await account.execute([{ contractAddress, entrypoint: "mint", calldata }]);
|
|
11751
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11752
|
-
return { txHash: tx.transaction_hash };
|
|
11753
|
-
} catch (err) {
|
|
11754
|
-
throw new MedialaneError("Failed to mint NFT", "TRANSACTION_FAILED", err);
|
|
11755
|
-
}
|
|
11756
|
-
}
|
|
11757
|
-
async function createCollection(account, params, config) {
|
|
11758
|
-
const { name, symbol, baseUri, collectionContract } = params;
|
|
11759
|
-
const provider = getProvider(config);
|
|
11760
|
-
const contractAddress = collectionContract ?? config.collectionContract;
|
|
11761
|
-
const calldata = [
|
|
11762
|
-
...encodeByteArray(name),
|
|
11763
|
-
...encodeByteArray(symbol),
|
|
11764
|
-
...encodeByteArray(baseUri)
|
|
11765
|
-
];
|
|
11766
|
-
try {
|
|
11767
|
-
const tx = await account.execute([{ contractAddress, entrypoint: "create_collection", calldata }]);
|
|
11768
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11769
|
-
return { txHash: tx.transaction_hash };
|
|
11770
|
-
} catch (err) {
|
|
11771
|
-
throw new MedialaneError("Failed to create collection", "TRANSACTION_FAILED", err);
|
|
11772
|
-
}
|
|
11773
|
-
}
|
|
11774
|
-
async function checkoutCart(account, items, config) {
|
|
11775
|
-
if (items.length === 0) throw new MedialaneError("Cart is empty", "INVALID_PARAMS");
|
|
11776
|
-
const { contract, provider } = makeContract(config);
|
|
11777
|
-
const tokenTotals = /* @__PURE__ */ new Map();
|
|
11778
|
-
for (const item of items) {
|
|
11779
|
-
const prev = tokenTotals.get(item.considerationToken) ?? 0n;
|
|
11780
|
-
tokenTotals.set(item.considerationToken, prev + BigInt(item.considerationAmount));
|
|
11781
|
-
}
|
|
11782
|
-
const approveCalls = Array.from(tokenTotals.entries()).map(([tokenAddr, totalWei]) => {
|
|
11783
|
-
const amount = starknet.cairo.uint256(totalWei.toString());
|
|
11784
|
-
return {
|
|
11785
|
-
contractAddress: tokenAddr,
|
|
11786
|
-
entrypoint: "approve",
|
|
11787
|
-
calldata: [
|
|
11788
|
-
config.marketplaceContract,
|
|
11789
|
-
amount.low.toString(),
|
|
11790
|
-
amount.high.toString()
|
|
11791
|
-
]
|
|
11792
|
-
};
|
|
11793
|
-
});
|
|
11794
|
-
const fulfillCalls = items.map(
|
|
11795
|
-
(item) => contract.populate("fulfill_order", [item.orderHash])
|
|
11796
|
-
);
|
|
11797
|
-
const feeCalls = Array.from(tokenTotals.entries()).map(
|
|
11798
|
-
([tokenAddr, totalWei]) => buildFeeCall(
|
|
11799
|
-
{ surface: "marketplace", token: tokenAddr, grossAmount: totalWei },
|
|
11800
|
-
config.feeConfig
|
|
11801
|
-
)
|
|
11802
|
-
).filter((c) => c !== null);
|
|
11803
|
-
try {
|
|
11804
|
-
const tx = await account.execute([...approveCalls, ...fulfillCalls, ...feeCalls]);
|
|
11805
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11806
|
-
return { txHash: tx.transaction_hash };
|
|
11807
|
-
} catch (err) {
|
|
11808
|
-
throw new MedialaneError("Cart checkout failed", "TRANSACTION_FAILED", err);
|
|
11809
|
-
}
|
|
11810
|
-
}
|
|
11811
|
-
async function getOrderDetails(orderHash, config) {
|
|
11812
|
-
const { contract } = makeContract(config);
|
|
11813
|
-
return contract.get_order_details(orderHash);
|
|
11814
|
-
}
|
|
11815
|
-
async function getCounter(address, config) {
|
|
11816
|
-
const { contract } = makeContract(config);
|
|
11817
|
-
return BigInt((await contract.get_counter(address)).toString());
|
|
11818
|
-
}
|
|
11819
|
-
async function incrementCounter(account, config) {
|
|
11820
|
-
const { contract, provider } = makeContract(config);
|
|
11821
|
-
const call = contract.populate("increment_counter", []);
|
|
11822
|
-
try {
|
|
11823
|
-
const tx = await account.execute(call);
|
|
11824
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11825
|
-
return { txHash: tx.transaction_hash };
|
|
11826
|
-
} catch (err) {
|
|
11827
|
-
throw new MedialaneError("Failed to increment counter", "TRANSACTION_FAILED", err);
|
|
11828
|
-
}
|
|
11829
|
-
}
|
|
11830
|
-
|
|
11831
|
-
// src/starknet/marketplace/index.ts
|
|
11832
|
-
var MarketplaceModule = class {
|
|
11833
|
-
constructor(config) {
|
|
11834
|
-
this.config = config;
|
|
11835
|
-
}
|
|
11836
|
-
// ─── Writes ───────────────────────────────────────────────────────────────
|
|
11837
|
-
createListing(account, params) {
|
|
11838
|
-
return createListing(account, params, this.config);
|
|
11839
|
-
}
|
|
11840
|
-
makeOffer(account, params) {
|
|
11841
|
-
return makeOffer(account, params, this.config);
|
|
11842
|
-
}
|
|
11843
|
-
fulfillOrder(account, params) {
|
|
11844
|
-
return fulfillOrder(account, params, this.config);
|
|
11845
|
-
}
|
|
11846
|
-
cancelOrder(account, params) {
|
|
11847
|
-
return cancelOrder(account, params, this.config);
|
|
11848
|
-
}
|
|
11849
|
-
checkoutCart(account, items) {
|
|
11850
|
-
return checkoutCart(account, items, this.config);
|
|
11851
|
-
}
|
|
11852
|
-
mint(account, params) {
|
|
11853
|
-
return mint(account, params, this.config);
|
|
11854
|
-
}
|
|
11855
|
-
createCollection(account, params) {
|
|
11856
|
-
return createCollection(account, params, this.config);
|
|
11857
|
-
}
|
|
11858
|
-
/** Bulk-cancel: bump the caller's counter, invalidating all their open orders. */
|
|
11859
|
-
incrementCounter(account) {
|
|
11860
|
-
return incrementCounter(account, this.config);
|
|
11861
|
-
}
|
|
11862
|
-
// ─── View calls ───────────────────────────────────────────────────────────
|
|
11863
|
-
getOrderDetails(orderHash) {
|
|
11864
|
-
return getOrderDetails(orderHash, this.config);
|
|
11865
|
-
}
|
|
11866
|
-
getCounter(address) {
|
|
11867
|
-
return getCounter(address, this.config);
|
|
11868
|
-
}
|
|
11869
|
-
// ─── Typed data builders (for ChipiPay / custom signing flows) ───────────
|
|
11870
|
-
buildListingTypedData(params, chainId) {
|
|
11871
|
-
return buildOrderTypedData(params, chainId);
|
|
11872
|
-
}
|
|
11873
|
-
buildCancellationTypedData(params, chainId) {
|
|
11874
|
-
return buildCancellationTypedData(params, chainId);
|
|
11875
|
-
}
|
|
11876
|
-
};
|
|
11877
|
-
var _contractCache2 = /* @__PURE__ */ new WeakMap();
|
|
11878
|
-
function getContract(config) {
|
|
11879
|
-
let c = _contractCache2.get(config);
|
|
11880
|
-
if (!c) {
|
|
11881
|
-
const provider = getProvider(config);
|
|
11882
|
-
c = new starknet.Contract(
|
|
11883
|
-
Medialane1155ABI,
|
|
11884
|
-
config.marketplace1155Contract,
|
|
11885
|
-
provider
|
|
11886
|
-
);
|
|
11887
|
-
_contractCache2.set(config, c);
|
|
11888
|
-
}
|
|
11889
|
-
return c;
|
|
11890
|
-
}
|
|
11891
|
-
async function createListing1155(account, params, config) {
|
|
11892
|
-
const {
|
|
11893
|
-
nftContract,
|
|
11894
|
-
tokenId,
|
|
11895
|
-
amount,
|
|
11896
|
-
pricePerUnit,
|
|
11897
|
-
currency = DEFAULT_CURRENCY,
|
|
11898
|
-
durationSeconds
|
|
11899
|
-
} = params;
|
|
11900
|
-
const contract = getContract(config);
|
|
11901
|
-
const provider = getProvider(config);
|
|
11902
|
-
const token = resolveToken(currency);
|
|
11903
|
-
const priceWei = parseAmount(pricePerUnit, token.decimals);
|
|
11904
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
11905
|
-
const endTime = now + durationSeconds;
|
|
11906
|
-
const chainId = getChainId(config);
|
|
11907
|
-
const counter = (await contract.get_counter(account.address)).toString();
|
|
11908
|
-
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11909
|
-
const orderParams = {
|
|
11910
|
-
offerer: account.address,
|
|
11911
|
-
marketplace: config.marketplace1155Contract,
|
|
11912
|
-
offer: {
|
|
11913
|
-
item_type: "ERC1155",
|
|
11914
|
-
token: nftContract,
|
|
11915
|
-
identifier_or_criteria: tokenId,
|
|
11916
|
-
amount
|
|
11917
|
-
// ERC-1155 leg amount = unit quantity
|
|
11918
|
-
},
|
|
11919
|
-
consideration: {
|
|
11920
|
-
item_type: "ERC20",
|
|
11921
|
-
token: token.address,
|
|
11922
|
-
identifier_or_criteria: "0",
|
|
11923
|
-
amount: priceWei,
|
|
11924
|
-
// payment leg amount = price PER UNIT
|
|
11925
|
-
recipient: account.address
|
|
11926
|
-
},
|
|
11927
|
-
royalty_max_bps: royaltyMaxBps,
|
|
11928
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
11929
|
-
end_time: endTime.toString(),
|
|
11930
|
-
salt: generateSalt(),
|
|
11931
|
-
counter
|
|
11932
|
-
};
|
|
11933
|
-
const typedData = stringifyBigInts(
|
|
11934
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
11935
|
-
);
|
|
11936
|
-
const signature = await account.signMessage(typedData);
|
|
11937
|
-
const signatureArray = toSignatureArray(signature);
|
|
11938
|
-
const orderPayload = stringifyBigInts({
|
|
11939
|
-
parameters: {
|
|
11940
|
-
...orderParams,
|
|
11941
|
-
offer: {
|
|
11942
|
-
...orderParams.offer,
|
|
11943
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
11944
|
-
},
|
|
11945
|
-
consideration: {
|
|
11946
|
-
...orderParams.consideration,
|
|
11947
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11948
|
-
}
|
|
11949
|
-
},
|
|
11950
|
-
signature: signatureArray
|
|
11951
|
-
});
|
|
11952
|
-
let isApproved = false;
|
|
11953
|
-
try {
|
|
11954
|
-
const result = await provider.callContract({
|
|
11955
|
-
contractAddress: nftContract,
|
|
11956
|
-
entrypoint: "is_approved_for_all",
|
|
11957
|
-
calldata: [account.address, config.marketplace1155Contract]
|
|
11958
|
-
});
|
|
11959
|
-
isApproved = BigInt(result[0]) === 1n;
|
|
11960
|
-
} catch {
|
|
11961
|
-
}
|
|
11962
|
-
const registerCall = contract.populate("register_order", [orderPayload]);
|
|
11963
|
-
const calls = isApproved ? [registerCall] : [
|
|
11964
|
-
{
|
|
11965
|
-
contractAddress: nftContract,
|
|
11966
|
-
entrypoint: "set_approval_for_all",
|
|
11967
|
-
calldata: [config.marketplace1155Contract, "1"]
|
|
11968
|
-
},
|
|
11969
|
-
registerCall
|
|
11970
|
-
];
|
|
11971
|
-
try {
|
|
11972
|
-
const tx = await account.execute(calls);
|
|
11973
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11974
|
-
return { txHash: tx.transaction_hash };
|
|
11975
|
-
} catch (err) {
|
|
11976
|
-
throw new MedialaneError("Failed to create ERC-1155 listing", "TRANSACTION_FAILED", err);
|
|
11977
|
-
}
|
|
11978
|
-
}
|
|
11979
|
-
async function fulfillOrder1155(account, params, config) {
|
|
11980
|
-
const { orderHash, paymentToken, totalPrice, quantity = "1" } = params;
|
|
11981
|
-
const contract = getContract(config);
|
|
11982
|
-
const provider = getProvider(config);
|
|
11983
|
-
const totalPriceU256 = starknet.cairo.uint256(totalPrice);
|
|
11984
|
-
const approveCall = {
|
|
11985
|
-
contractAddress: paymentToken,
|
|
11986
|
-
entrypoint: "approve",
|
|
11987
|
-
calldata: [
|
|
11988
|
-
config.marketplace1155Contract,
|
|
11989
|
-
totalPriceU256.low.toString(),
|
|
11990
|
-
totalPriceU256.high.toString()
|
|
11991
|
-
]
|
|
11992
|
-
};
|
|
11993
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash, quantity]);
|
|
11994
|
-
try {
|
|
11995
|
-
const tx = await account.execute([approveCall, fulfillCall]);
|
|
11996
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
11997
|
-
return { txHash: tx.transaction_hash };
|
|
11998
|
-
} catch (err) {
|
|
11999
|
-
throw new MedialaneError("Failed to fulfill ERC-1155 order", "TRANSACTION_FAILED", err);
|
|
12000
|
-
}
|
|
12001
|
-
}
|
|
12002
|
-
async function cancelOrder1155(account, params, config) {
|
|
12003
|
-
const { orderHash } = params;
|
|
12004
|
-
const contract = getContract(config);
|
|
12005
|
-
const provider = getProvider(config);
|
|
12006
|
-
const chainId = getChainId(config);
|
|
12007
|
-
const cancelParams = {
|
|
12008
|
-
order_hash: orderHash,
|
|
12009
|
-
offerer: account.address
|
|
12010
|
-
};
|
|
12011
|
-
const typedData = stringifyBigInts(
|
|
12012
|
-
build1155CancellationTypedData(cancelParams, chainId)
|
|
12013
|
-
);
|
|
12014
|
-
const signature = await account.signMessage(typedData);
|
|
12015
|
-
const signatureArray = toSignatureArray(signature);
|
|
12016
|
-
const cancelPayload = stringifyBigInts({
|
|
12017
|
-
cancelation: cancelParams,
|
|
12018
|
-
signature: signatureArray
|
|
12019
|
-
});
|
|
12020
|
-
const cancelCall = contract.populate("cancel_order", [cancelPayload]);
|
|
12021
|
-
try {
|
|
12022
|
-
const tx = await account.execute(cancelCall);
|
|
12023
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
12024
|
-
return { txHash: tx.transaction_hash };
|
|
12025
|
-
} catch (err) {
|
|
12026
|
-
throw new MedialaneError("Failed to cancel ERC-1155 order", "TRANSACTION_FAILED", err);
|
|
12027
|
-
}
|
|
12028
|
-
}
|
|
12029
|
-
async function makeOffer1155(account, params, config) {
|
|
12030
|
-
const {
|
|
12031
|
-
nftContract,
|
|
12032
|
-
tokenId,
|
|
12033
|
-
amount,
|
|
12034
|
-
price,
|
|
12035
|
-
currency = DEFAULT_CURRENCY,
|
|
12036
|
-
durationSeconds
|
|
12037
|
-
} = params;
|
|
12038
|
-
const contract = getContract(config);
|
|
12039
|
-
const provider = getProvider(config);
|
|
12040
|
-
const chainId = getChainId(config);
|
|
12041
|
-
const token = resolveToken(currency);
|
|
12042
|
-
const priceWei = parseAmount(price, token.decimals);
|
|
12043
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
12044
|
-
const endTime = now + durationSeconds;
|
|
12045
|
-
const counter = (await contract.get_counter(account.address)).toString();
|
|
12046
|
-
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
12047
|
-
const orderParams = {
|
|
12048
|
-
offerer: account.address,
|
|
12049
|
-
marketplace: config.marketplace1155Contract,
|
|
12050
|
-
offer: {
|
|
12051
|
-
item_type: "ERC20",
|
|
12052
|
-
token: token.address,
|
|
12053
|
-
identifier_or_criteria: "0",
|
|
12054
|
-
amount: priceWei
|
|
12055
|
-
// price PER UNIT
|
|
12056
|
-
},
|
|
12057
|
-
consideration: {
|
|
12058
|
-
item_type: "ERC1155",
|
|
12059
|
-
token: nftContract,
|
|
12060
|
-
identifier_or_criteria: tokenId,
|
|
12061
|
-
amount,
|
|
12062
|
-
// unit quantity
|
|
12063
|
-
recipient: account.address
|
|
12064
|
-
},
|
|
12065
|
-
royalty_max_bps: royaltyMaxBps,
|
|
12066
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
12067
|
-
end_time: endTime.toString(),
|
|
12068
|
-
salt: generateSalt(),
|
|
12069
|
-
counter
|
|
12070
|
-
};
|
|
12071
|
-
const typedData = stringifyBigInts(
|
|
12072
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
12073
|
-
);
|
|
12074
|
-
const signature = await account.signMessage(typedData);
|
|
12075
|
-
const signatureArray = toSignatureArray(signature);
|
|
12076
|
-
const registerPayload = stringifyBigInts({
|
|
12077
|
-
parameters: {
|
|
12078
|
-
...orderParams,
|
|
12079
|
-
offer: {
|
|
12080
|
-
...orderParams.offer,
|
|
12081
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
12082
|
-
},
|
|
12083
|
-
consideration: {
|
|
12084
|
-
...orderParams.consideration,
|
|
12085
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
12086
|
-
}
|
|
12087
|
-
},
|
|
12088
|
-
signature: signatureArray
|
|
12089
|
-
});
|
|
12090
|
-
const totalWei = BigInt(priceWei) * BigInt(amount);
|
|
12091
|
-
const amountU256 = starknet.cairo.uint256(totalWei.toString());
|
|
12092
|
-
const approveCall = {
|
|
12093
|
-
contractAddress: token.address,
|
|
12094
|
-
entrypoint: "approve",
|
|
12095
|
-
calldata: [
|
|
12096
|
-
config.marketplace1155Contract,
|
|
12097
|
-
amountU256.low.toString(),
|
|
12098
|
-
amountU256.high.toString()
|
|
12099
|
-
]
|
|
12100
|
-
};
|
|
12101
|
-
const registerCall = contract.populate("register_order", [registerPayload]);
|
|
12102
|
-
try {
|
|
12103
|
-
const tx = await account.execute([approveCall, registerCall]);
|
|
12104
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
12105
|
-
return { txHash: tx.transaction_hash };
|
|
12106
|
-
} catch (err) {
|
|
12107
|
-
throw new MedialaneError("Failed to make ERC-1155 offer", "TRANSACTION_FAILED", err);
|
|
12108
|
-
}
|
|
12109
|
-
}
|
|
12110
|
-
async function checkoutCart1155(account, items, config) {
|
|
12111
|
-
if (items.length === 0) throw new MedialaneError("Cart is empty", "INVALID_PARAMS");
|
|
12112
|
-
const contract = getContract(config);
|
|
12113
|
-
const provider = getProvider(config);
|
|
12114
|
-
const tokenTotals = /* @__PURE__ */ new Map();
|
|
12115
|
-
for (const item of items) {
|
|
12116
|
-
const prev = tokenTotals.get(item.considerationToken) ?? 0n;
|
|
12117
|
-
tokenTotals.set(item.considerationToken, prev + BigInt(item.considerationAmount));
|
|
12118
|
-
}
|
|
12119
|
-
const approveCalls = Array.from(tokenTotals.entries()).map(([tokenAddr, totalWei]) => {
|
|
12120
|
-
const amount = starknet.cairo.uint256(totalWei.toString());
|
|
12121
|
-
return {
|
|
12122
|
-
contractAddress: tokenAddr,
|
|
12123
|
-
entrypoint: "approve",
|
|
12124
|
-
calldata: [
|
|
12125
|
-
config.marketplace1155Contract,
|
|
12126
|
-
amount.low.toString(),
|
|
12127
|
-
amount.high.toString()
|
|
12128
|
-
]
|
|
12129
|
-
};
|
|
12130
|
-
});
|
|
12131
|
-
const fulfillCalls = items.map(
|
|
12132
|
-
(item) => contract.populate("fulfill_order", [item.orderHash, item.quantity ?? "1"])
|
|
12133
|
-
);
|
|
12134
|
-
try {
|
|
12135
|
-
const tx = await account.execute([...approveCalls, ...fulfillCalls]);
|
|
12136
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
12137
|
-
return { txHash: tx.transaction_hash };
|
|
12138
|
-
} catch (err) {
|
|
12139
|
-
throw new MedialaneError("ERC-1155 cart checkout failed", "TRANSACTION_FAILED", err);
|
|
12140
|
-
}
|
|
12141
|
-
}
|
|
12142
|
-
async function getOrderDetails1155(orderHash, config) {
|
|
12143
|
-
const contract = getContract(config);
|
|
12144
|
-
return contract.get_order_details(orderHash);
|
|
12145
|
-
}
|
|
12146
|
-
async function getCounter1155(address, config) {
|
|
12147
|
-
const contract = getContract(config);
|
|
12148
|
-
return BigInt((await contract.get_counter(address)).toString());
|
|
12149
|
-
}
|
|
12150
|
-
async function incrementCounter1155(account, config) {
|
|
12151
|
-
const contract = getContract(config);
|
|
12152
|
-
const provider = getProvider(config);
|
|
12153
|
-
const call = contract.populate("increment_counter", []);
|
|
12154
|
-
try {
|
|
12155
|
-
const tx = await account.execute(call);
|
|
12156
|
-
await provider.waitForTransaction(tx.transaction_hash);
|
|
12157
|
-
return { txHash: tx.transaction_hash };
|
|
12158
|
-
} catch (err) {
|
|
12159
|
-
throw new MedialaneError("Failed to increment counter (1155)", "TRANSACTION_FAILED", err);
|
|
12160
|
-
}
|
|
12161
|
-
}
|
|
12162
|
-
|
|
12163
|
-
// src/starknet/marketplace1155/index.ts
|
|
12164
|
-
var Medialane1155Module = class {
|
|
12165
|
-
constructor(config) {
|
|
12166
|
-
this.config = config;
|
|
12167
|
-
}
|
|
12168
|
-
// ─── Writes ───────────────────────────────────────────────────────────────
|
|
12169
|
-
/**
|
|
12170
|
-
* Create an ERC-1155 sell listing.
|
|
12171
|
-
* Optionally grants `set_approval_for_all` if not already approved.
|
|
12172
|
-
*/
|
|
12173
|
-
createListing(account, params) {
|
|
12174
|
-
return createListing1155(account, params, this.config);
|
|
12175
|
-
}
|
|
12176
|
-
/**
|
|
12177
|
-
* Make an offer (bid) on an ERC-1155 token.
|
|
12178
|
-
* Approves the ERC-20 spend then calls `register_order` atomically.
|
|
12179
|
-
*/
|
|
12180
|
-
makeOffer(account, params) {
|
|
12181
|
-
return makeOffer1155(account, params, this.config);
|
|
12182
|
-
}
|
|
12183
|
-
/**
|
|
12184
|
-
* Fulfill (buy) an ERC-1155 listing.
|
|
12185
|
-
* Approves the payment token then calls `fulfill_order` atomically.
|
|
12186
|
-
*/
|
|
12187
|
-
fulfillOrder(account, params) {
|
|
12188
|
-
return fulfillOrder1155(account, params, this.config);
|
|
12189
|
-
}
|
|
12190
|
-
/**
|
|
12191
|
-
* Cancel an ERC-1155 listing (offerer only).
|
|
12192
|
-
*/
|
|
12193
|
-
cancelOrder(account, params) {
|
|
12194
|
-
return cancelOrder1155(account, params, this.config);
|
|
12195
|
-
}
|
|
12196
|
-
/**
|
|
12197
|
-
* Checkout a cart of ERC-1155 orders atomically.
|
|
12198
|
-
* Signs one fulfillment per item (with quantity), sums ERC-20 approvals by token.
|
|
12199
|
-
*/
|
|
12200
|
-
checkoutCart(account, items) {
|
|
12201
|
-
return checkoutCart1155(account, items, this.config);
|
|
12202
|
-
}
|
|
12203
|
-
/** Bulk-cancel on the 1155 venue: bump the caller's counter. */
|
|
12204
|
-
incrementCounter(account) {
|
|
12205
|
-
return incrementCounter1155(account, this.config);
|
|
12206
|
-
}
|
|
12207
|
-
// ─── View calls ───────────────────────────────────────────────────────────
|
|
12208
|
-
getOrderDetails(orderHash) {
|
|
12209
|
-
return getOrderDetails1155(orderHash, this.config);
|
|
12210
|
-
}
|
|
12211
|
-
getCounter(address) {
|
|
12212
|
-
return getCounter1155(address, this.config);
|
|
12213
|
-
}
|
|
12214
|
-
// ─── Typed data builders (for ChipiPay / custom signing flows) ───────────
|
|
12215
|
-
buildListingTypedData(params, chainId) {
|
|
12216
|
-
return build1155OrderTypedData(params, chainId);
|
|
12217
|
-
}
|
|
12218
|
-
buildCancellationTypedData(params, chainId) {
|
|
12219
|
-
return build1155CancellationTypedData(params, chainId);
|
|
12220
|
-
}
|
|
12221
|
-
};
|
|
12222
|
-
var PopService = class {
|
|
12223
|
-
constructor(config) {
|
|
12224
|
-
this.factoryAddress = getStarknetCoordinates(config.chain).popFactory;
|
|
12225
|
-
}
|
|
12226
|
-
_collection(address, account) {
|
|
12227
|
-
return new starknet.Contract(POPCollectionABI, normalizeAddress("STARKNET", address), account);
|
|
12228
|
-
}
|
|
12229
|
-
async claim(account, collectionAddress) {
|
|
12230
|
-
const call = this._collection(collectionAddress, account).populate("claim", []);
|
|
12231
|
-
const res = await account.execute([call]);
|
|
12232
|
-
return { txHash: res.transaction_hash };
|
|
12233
|
-
}
|
|
12234
|
-
async adminMint(account, params) {
|
|
12235
|
-
const call = this._collection(params.collection, account).populate("admin_mint", [
|
|
12236
|
-
params.recipient,
|
|
12237
|
-
params.customUri ?? ""
|
|
12238
|
-
]);
|
|
12239
|
-
const res = await account.execute([call]);
|
|
12240
|
-
return { txHash: res.transaction_hash };
|
|
12241
|
-
}
|
|
12242
|
-
async addToAllowlist(account, params) {
|
|
12243
|
-
const call = this._collection(params.collection, account).populate("add_to_allowlist", [params.address]);
|
|
12244
|
-
const res = await account.execute([call]);
|
|
12245
|
-
return { txHash: res.transaction_hash };
|
|
12246
|
-
}
|
|
12247
|
-
async batchAddToAllowlist(account, params) {
|
|
12248
|
-
const collection = this._collection(params.collection, account);
|
|
12249
|
-
const CHUNK = 200;
|
|
12250
|
-
const calls = [];
|
|
12251
|
-
for (let i = 0; i < params.addresses.length; i += CHUNK) {
|
|
12252
|
-
calls.push(collection.populate("batch_add_to_allowlist", [params.addresses.slice(i, i + CHUNK)]));
|
|
12253
|
-
}
|
|
12254
|
-
const res = await account.execute(calls);
|
|
12255
|
-
return { txHash: res.transaction_hash };
|
|
12256
|
-
}
|
|
12257
|
-
async removeFromAllowlist(account, params) {
|
|
12258
|
-
const call = this._collection(params.collection, account).populate("remove_from_allowlist", [params.address]);
|
|
12259
|
-
const res = await account.execute([call]);
|
|
12260
|
-
return { txHash: res.transaction_hash };
|
|
12261
|
-
}
|
|
12262
|
-
async setTokenUri(account, params) {
|
|
12263
|
-
const call = this._collection(params.collection, account).populate("set_token_uri", [
|
|
12264
|
-
BigInt(params.tokenId),
|
|
12265
|
-
params.uri
|
|
12266
|
-
]);
|
|
12267
|
-
const res = await account.execute([call]);
|
|
12268
|
-
return { txHash: res.transaction_hash };
|
|
12269
|
-
}
|
|
12270
|
-
async setPaused(account, params) {
|
|
12271
|
-
const call = this._collection(params.collection, account).populate("set_paused", [params.paused]);
|
|
12272
|
-
const res = await account.execute([call]);
|
|
12273
|
-
return { txHash: res.transaction_hash };
|
|
12274
|
-
}
|
|
12275
|
-
async createCollection(account, params) {
|
|
12276
|
-
const factory = new starknet.Contract(POPFactoryABI, this.factoryAddress, account);
|
|
12277
|
-
const call = factory.populate("create_collection", [
|
|
12278
|
-
params.name,
|
|
12279
|
-
params.symbol,
|
|
12280
|
-
params.baseUri,
|
|
12281
|
-
params.claimEndTime,
|
|
12282
|
-
{ [params.eventType]: {} }
|
|
12283
|
-
]);
|
|
12284
|
-
const res = await account.execute([call]);
|
|
12285
|
-
return { txHash: res.transaction_hash };
|
|
12286
|
-
}
|
|
12287
|
-
};
|
|
12288
|
-
function toContractConditions(c) {
|
|
12289
|
-
return {
|
|
12290
|
-
start_time: c.startTime,
|
|
12291
|
-
end_time: c.endTime,
|
|
12292
|
-
price: BigInt(c.price),
|
|
12293
|
-
payment_token: c.paymentToken,
|
|
12294
|
-
max_quantity_per_wallet: BigInt(c.maxQuantityPerWallet)
|
|
12295
|
-
};
|
|
12296
|
-
}
|
|
12297
|
-
var DropService = class {
|
|
12298
|
-
constructor(config) {
|
|
12299
|
-
this.factoryAddress = getStarknetCoordinates(config.chain).dropFactory;
|
|
12300
|
-
this.config = config;
|
|
12301
|
-
}
|
|
12302
|
-
_collection(address, account) {
|
|
12303
|
-
return new starknet.Contract(DropCollectionABI, normalizeAddress("STARKNET", address), account);
|
|
12304
|
-
}
|
|
12305
|
-
async claim(account, collectionAddress, quantity = 1) {
|
|
12306
|
-
const collection = this._collection(collectionAddress, account);
|
|
12307
|
-
const qty = BigInt(quantity);
|
|
12308
|
-
const claimCall = collection.populate("claim", [qty]);
|
|
12309
|
-
const conditions = await collection.get_claim_conditions();
|
|
12310
|
-
const price = BigInt(conditions.price);
|
|
12311
|
-
const paymentToken = typeof conditions.payment_token === "bigint" ? "0x" + conditions.payment_token.toString(16) : conditions.payment_token;
|
|
12312
|
-
const feeCall = price > 0n ? buildFeeCall(
|
|
12313
|
-
{ surface: "launchpad", token: paymentToken, grossAmount: price * qty },
|
|
12314
|
-
this.config.feeConfig
|
|
12315
|
-
) : null;
|
|
12316
|
-
const calls = feeCall ? [claimCall, feeCall] : [claimCall];
|
|
12317
|
-
const res = await account.execute(calls);
|
|
12318
|
-
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 };
|
|
12319
11442
|
}
|
|
12320
11443
|
async adminMint(account, params) {
|
|
12321
11444
|
const call = this._collection(params.collection, account).populate("admin_mint", [
|
|
@@ -12941,8 +12064,6 @@ var SponsorshipService = class {
|
|
|
12941
12064
|
var MedialaneClient = class {
|
|
12942
12065
|
constructor(rawConfig = {}) {
|
|
12943
12066
|
this.config = resolveConfig(rawConfig);
|
|
12944
|
-
this.marketplace = new MarketplaceModule(this.config);
|
|
12945
|
-
this.marketplace1155 = new Medialane1155Module(this.config);
|
|
12946
12067
|
this.services = {
|
|
12947
12068
|
pop: new PopService(this.config),
|
|
12948
12069
|
drop: new DropService(this.config),
|
|
@@ -12985,99 +12106,512 @@ var MedialaneClient = class {
|
|
|
12985
12106
|
return this.config.marketplaceContract;
|
|
12986
12107
|
}
|
|
12987
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
|
|
12988
12469
|
var NO_EXPIRY_SECONDS = 100 * 365 * 24 * 3600;
|
|
12989
12470
|
var StarknetVenue = class {
|
|
12990
12471
|
constructor(deps) {
|
|
12991
12472
|
this.deps = deps;
|
|
12992
12473
|
this.chain = "STARKNET";
|
|
12993
|
-
this.m721 = new MarketplaceModule(deps.config);
|
|
12994
|
-
this.m1155 = new Medialane1155Module(deps.config);
|
|
12995
12474
|
}
|
|
12996
|
-
incrementCounter(signer) {
|
|
12997
|
-
return
|
|
12475
|
+
async incrementCounter(signer) {
|
|
12476
|
+
return signer.execute([
|
|
12477
|
+
{ contractAddress: this.deps.config.marketplaceContract, entrypoint: "increment_counter", calldata: [] }
|
|
12478
|
+
]);
|
|
12998
12479
|
}
|
|
12999
12480
|
getOrderDetails(orderRef) {
|
|
13000
|
-
return this.
|
|
12481
|
+
return getOrderDetails(orderRef, this.deps.config);
|
|
13001
12482
|
}
|
|
13002
|
-
getCounter(address) {
|
|
13003
|
-
return this.
|
|
12483
|
+
async getCounter(address) {
|
|
12484
|
+
return this.readCounter(this.deps.config.marketplaceContract, address);
|
|
13004
12485
|
}
|
|
13005
12486
|
async fulfillOrder(signer, orderRef, opts) {
|
|
13006
12487
|
const o = await this.deps.resolveOrder(orderRef);
|
|
13007
12488
|
const quantity = opts?.quantity ?? "1";
|
|
13008
12489
|
const totalPrice = (BigInt(o.unitPrice) * BigInt(quantity)).toString();
|
|
13009
|
-
|
|
13010
|
-
|
|
13011
|
-
orderHash: orderRef,
|
|
13012
|
-
paymentToken: o.paymentToken,
|
|
13013
|
-
totalPrice,
|
|
13014
|
-
quantity
|
|
13015
|
-
});
|
|
13016
|
-
}
|
|
13017
|
-
return this.m721.fulfillOrder(signer, {
|
|
13018
|
-
orderHash: orderRef,
|
|
13019
|
-
paymentToken: o.paymentToken,
|
|
13020
|
-
totalPrice
|
|
13021
|
-
});
|
|
12490
|
+
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);
|
|
12491
|
+
return signer.execute(calls);
|
|
13022
12492
|
}
|
|
13023
12493
|
async cancelOrder(signer, orderRef) {
|
|
13024
12494
|
const o = await this.deps.resolveOrder(orderRef);
|
|
13025
|
-
|
|
13026
|
-
|
|
13027
|
-
}
|
|
13028
|
-
return
|
|
12495
|
+
const typedData = o.standard === "ERC1155" ? buildCancel1155TypedData(orderRef, signer.address, this.deps.config) : buildCancelTypedData(orderRef, signer.address, this.deps.config);
|
|
12496
|
+
const signature = await signer.signTypedData(typedData);
|
|
12497
|
+
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);
|
|
12498
|
+
return signer.execute(calls);
|
|
13029
12499
|
}
|
|
13030
12500
|
async registerOrder(signer, p) {
|
|
13031
12501
|
const standard = await this.deps.resolveStandard(p.asset.contract);
|
|
13032
|
-
const
|
|
13033
|
-
const humanPrice = formatAmount(p.amount, token.decimals);
|
|
13034
|
-
const durationSeconds = this.durationSeconds(p.endTime);
|
|
12502
|
+
const paymentTokenAddress = resolveToken(p.paymentToken).address;
|
|
13035
12503
|
const royaltyMaxBps = String(p.royaltyMaxBps);
|
|
12504
|
+
const startTime = Math.floor(Date.now() / 1e3) + START_TIME_BUFFER_SECS;
|
|
12505
|
+
const endTime = p.endTime && p.endTime > 0 ? p.endTime : startTime + NO_EXPIRY_SECONDS;
|
|
13036
12506
|
const quantity = p.quantity ?? "1";
|
|
13037
|
-
|
|
12507
|
+
const marketplace = standard === "ERC1155" ? this.deps.config.marketplace1155Contract : this.deps.config.marketplaceContract;
|
|
12508
|
+
const counter = String(await this.readCounter(marketplace, signer.address));
|
|
12509
|
+
let typedData;
|
|
12510
|
+
let buildCalls;
|
|
13038
12511
|
if (standard === "ERC1155") {
|
|
13039
|
-
|
|
13040
|
-
|
|
12512
|
+
const built = (p.side === "listing" ? buildListing1155Order : buildOffer1155Order)(
|
|
12513
|
+
{
|
|
12514
|
+
offerer: signer.address,
|
|
13041
12515
|
nftContract: p.asset.contract,
|
|
13042
12516
|
tokenId: p.asset.tokenId,
|
|
13043
|
-
|
|
13044
|
-
|
|
13045
|
-
|
|
13046
|
-
|
|
13047
|
-
|
|
13048
|
-
|
|
13049
|
-
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
12517
|
+
quantity,
|
|
12518
|
+
priceWeiPerUnit: p.amount,
|
|
12519
|
+
paymentTokenAddress,
|
|
12520
|
+
royaltyMaxBps,
|
|
12521
|
+
startTime,
|
|
12522
|
+
endTime,
|
|
12523
|
+
salt: p.salt,
|
|
12524
|
+
counter
|
|
12525
|
+
},
|
|
12526
|
+
this.deps.config
|
|
12527
|
+
);
|
|
12528
|
+
typedData = built.typedData;
|
|
12529
|
+
const approval = p.side === "listing" ? await this.approval1155ForListing(signer.address, p.asset.contract) : this.approvalForErc20(paymentTokenAddress, (BigInt(p.amount) * BigInt(quantity)).toString(), marketplace);
|
|
12530
|
+
buildCalls = (sig) => buildRegister1155Calls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
12531
|
+
} else {
|
|
12532
|
+
const built = (p.side === "listing" ? buildListingOrder : buildOfferOrder)(
|
|
12533
|
+
{
|
|
12534
|
+
offerer: signer.address,
|
|
13053
12535
|
nftContract: p.asset.contract,
|
|
13054
12536
|
tokenId: p.asset.tokenId,
|
|
13055
|
-
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
|
|
13060
|
-
|
|
13061
|
-
|
|
13062
|
-
|
|
13063
|
-
|
|
13064
|
-
|
|
13065
|
-
|
|
13066
|
-
|
|
13067
|
-
|
|
13068
|
-
currency: p.paymentToken,
|
|
13069
|
-
durationSeconds,
|
|
13070
|
-
royaltyMaxBps
|
|
13071
|
-
};
|
|
13072
|
-
const res = p.side === "listing" ? await this.m721.createListing(signer, params) : await this.m721.makeOffer(signer, params);
|
|
13073
|
-
txHash = res.txHash;
|
|
12537
|
+
priceWei: p.amount,
|
|
12538
|
+
paymentTokenAddress,
|
|
12539
|
+
royaltyMaxBps,
|
|
12540
|
+
startTime,
|
|
12541
|
+
endTime,
|
|
12542
|
+
salt: p.salt,
|
|
12543
|
+
counter
|
|
12544
|
+
},
|
|
12545
|
+
this.deps.config
|
|
12546
|
+
);
|
|
12547
|
+
typedData = built.typedData;
|
|
12548
|
+
const approval = p.side === "listing" ? await this.approval721ForListing(signer.address, p.asset.contract, p.asset.tokenId) : this.approvalForErc20(paymentTokenAddress, p.amount, marketplace);
|
|
12549
|
+
buildCalls = (sig) => buildRegisterCalls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
13074
12550
|
}
|
|
12551
|
+
const signature = await signer.signTypedData(typedData);
|
|
12552
|
+
const { txHash } = await signer.execute(buildCalls(signature));
|
|
13075
12553
|
const orderRef = await this.orderRefFromReceipt(txHash);
|
|
13076
12554
|
return { txHash, orderRef };
|
|
13077
12555
|
}
|
|
13078
|
-
|
|
13079
|
-
|
|
13080
|
-
|
|
12556
|
+
// ─── reads (all on deps.provider) ─────────────────────────────────────────
|
|
12557
|
+
async readCounter(marketplace, address) {
|
|
12558
|
+
const res = await this.deps.provider.callContract({
|
|
12559
|
+
contractAddress: marketplace,
|
|
12560
|
+
entrypoint: "get_counter",
|
|
12561
|
+
calldata: [address]
|
|
12562
|
+
});
|
|
12563
|
+
return BigInt(res[0] ?? "0");
|
|
12564
|
+
}
|
|
12565
|
+
/** 721 listing approval: `get_approved(tokenId) == marketplace` ⇒ no approve. */
|
|
12566
|
+
async approval721ForListing(_owner, nftContract, tokenId) {
|
|
12567
|
+
const id = starknet.cairo.uint256(tokenId);
|
|
12568
|
+
const approve = {
|
|
12569
|
+
contractAddress: nftContract,
|
|
12570
|
+
entrypoint: "approve",
|
|
12571
|
+
calldata: [this.deps.config.marketplaceContract, id.low.toString(), id.high.toString()]
|
|
12572
|
+
};
|
|
12573
|
+
let approved = false;
|
|
12574
|
+
try {
|
|
12575
|
+
const res = await this.deps.provider.callContract({
|
|
12576
|
+
contractAddress: nftContract,
|
|
12577
|
+
entrypoint: "get_approved",
|
|
12578
|
+
calldata: [id.low.toString(), id.high.toString()]
|
|
12579
|
+
});
|
|
12580
|
+
approved = BigInt(res[0]).toString() === BigInt(this.deps.config.marketplaceContract).toString();
|
|
12581
|
+
} catch {
|
|
12582
|
+
}
|
|
12583
|
+
return { approvalNeeded: !approved, approve };
|
|
12584
|
+
}
|
|
12585
|
+
/** 1155 listing approval: `is_approved_for_all(owner, marketplace)`. */
|
|
12586
|
+
async approval1155ForListing(owner, nftContract) {
|
|
12587
|
+
const approve = {
|
|
12588
|
+
contractAddress: nftContract,
|
|
12589
|
+
entrypoint: "set_approval_for_all",
|
|
12590
|
+
calldata: [this.deps.config.marketplace1155Contract, "1"]
|
|
12591
|
+
};
|
|
12592
|
+
let approved = false;
|
|
12593
|
+
try {
|
|
12594
|
+
const res = await this.deps.provider.callContract({
|
|
12595
|
+
contractAddress: nftContract,
|
|
12596
|
+
entrypoint: "is_approved_for_all",
|
|
12597
|
+
calldata: [owner, this.deps.config.marketplace1155Contract]
|
|
12598
|
+
});
|
|
12599
|
+
approved = BigInt(res[0]) === 1n;
|
|
12600
|
+
} catch {
|
|
12601
|
+
}
|
|
12602
|
+
return { approvalNeeded: !approved, approve };
|
|
12603
|
+
}
|
|
12604
|
+
/** Offers always approve the ERC-20 spend (no read). */
|
|
12605
|
+
approvalForErc20(token, amountWei, marketplace) {
|
|
12606
|
+
const u = starknet.cairo.uint256(amountWei);
|
|
12607
|
+
return {
|
|
12608
|
+
approvalNeeded: true,
|
|
12609
|
+
approve: {
|
|
12610
|
+
contractAddress: token,
|
|
12611
|
+
entrypoint: "approve",
|
|
12612
|
+
calldata: [marketplace, u.low.toString(), u.high.toString()]
|
|
12613
|
+
}
|
|
12614
|
+
};
|
|
13081
12615
|
}
|
|
13082
12616
|
/** The canonical Starknet order id = the contract-emitted `OrderCreated`
|
|
13083
12617
|
* hash (`keys[1]`), which is exactly what the indexer stores. */
|
|
@@ -13350,6 +12884,30 @@ function buybackQuoteRaw(teamCoinsRawValue, quoteDecimals) {
|
|
|
13350
12884
|
function fdvHuman(supplyHuman) {
|
|
13351
12885
|
return supplyHuman * LAUNCH_PRICE_QUOTE_PER_COIN;
|
|
13352
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
|
+
}
|
|
13353
12911
|
|
|
13354
12912
|
exports.ADMIN_HEADERS = ADMIN_HEADERS;
|
|
13355
12913
|
exports.ADMIN_SCOPE = ADMIN_SCOPE;
|
|
@@ -13382,9 +12940,7 @@ exports.IPSponsorshipLicenseABI = IPSponsorshipLicenseABI;
|
|
|
13382
12940
|
exports.IPTicketCollectionABI = IPTicketCollectionABI;
|
|
13383
12941
|
exports.IPTicketCollectionFactoryABI = IPTicketCollectionFactoryABI;
|
|
13384
12942
|
exports.LAUNCH_PRICE_QUOTE_PER_COIN = LAUNCH_PRICE_QUOTE_PER_COIN;
|
|
13385
|
-
exports.MarketplaceModule = MarketplaceModule;
|
|
13386
12943
|
exports.Medialane1155ABI = Medialane1155ABI;
|
|
13387
|
-
exports.Medialane1155Module = Medialane1155Module;
|
|
13388
12944
|
exports.MedialaneApiError = MedialaneApiError;
|
|
13389
12945
|
exports.MedialaneClient = MedialaneClient;
|
|
13390
12946
|
exports.MedialaneError = MedialaneError;
|
|
@@ -13449,8 +13005,12 @@ exports.encodeByteArray = encodeByteArray;
|
|
|
13449
13005
|
exports.fdvHuman = fdvHuman;
|
|
13450
13006
|
exports.formatAmount = formatAmount;
|
|
13451
13007
|
exports.getCoordinates = getCoordinates;
|
|
13008
|
+
exports.getCounter = getCounter;
|
|
13009
|
+
exports.getCounter1155 = getCounter1155;
|
|
13452
13010
|
exports.getCreatorCoinPrice = getCreatorCoinPrice;
|
|
13453
13011
|
exports.getListableTokens = getListableTokens;
|
|
13012
|
+
exports.getOrderDetails = getOrderDetails;
|
|
13013
|
+
exports.getOrderDetails1155 = getOrderDetails1155;
|
|
13454
13014
|
exports.getService = getService;
|
|
13455
13015
|
exports.getServicesByCapability = getServicesByCapability;
|
|
13456
13016
|
exports.getSiwsStorageKey = getSiwsStorageKey;
|