@medialane/sdk 0.64.0 → 0.65.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 +63 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -60
- package/dist/index.js.map +1 -1
- package/dist/starknet/index.cjs +185 -183
- package/dist/starknet/index.cjs.map +1 -1
- package/dist/starknet/index.js +186 -184
- package/dist/starknet/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
3
3
|
import { base58, base32 } from '@scure/base';
|
|
4
|
-
import { hash,
|
|
4
|
+
import { hash, cairo, uint256, RpcProvider, CairoOption, CairoOptionVariant, num, ec, encode, Contract, TypedDataRevision, constants, shortString } from 'starknet';
|
|
5
5
|
|
|
6
6
|
// src/config.ts
|
|
7
7
|
|
|
@@ -1295,6 +1295,50 @@ function createFailoverFetch(urls, options = {}) {
|
|
|
1295
1295
|
return failover;
|
|
1296
1296
|
}
|
|
1297
1297
|
|
|
1298
|
+
// src/starknet/marketplace/errors.ts
|
|
1299
|
+
var MedialaneError = class extends Error {
|
|
1300
|
+
constructor(message, code = "UNKNOWN", cause) {
|
|
1301
|
+
super(message);
|
|
1302
|
+
this.code = code;
|
|
1303
|
+
this.cause = cause;
|
|
1304
|
+
this.name = "MedialaneError";
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
// src/starknet/marketplace/utils.ts
|
|
1309
|
+
var START_TIME_BUFFER_SECS = 30;
|
|
1310
|
+
function newContract(abi, address, providerOrAccount) {
|
|
1311
|
+
const C = Contract;
|
|
1312
|
+
return C.length === 1 ? new Contract({ abi, address, providerOrAccount }) : new Contract(
|
|
1313
|
+
abi,
|
|
1314
|
+
address,
|
|
1315
|
+
providerOrAccount
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
function getChainId(config) {
|
|
1319
|
+
if (config.chain !== "STARKNET") {
|
|
1320
|
+
throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
|
|
1321
|
+
}
|
|
1322
|
+
return constants.StarknetChainId.SN_MAIN;
|
|
1323
|
+
}
|
|
1324
|
+
function resolveToken(currency) {
|
|
1325
|
+
const token = SUPPORTED_TOKENS.find(
|
|
1326
|
+
(t) => t.symbol === currency.toUpperCase() || t.address.toLowerCase() === currency.toLowerCase()
|
|
1327
|
+
);
|
|
1328
|
+
if (!token) throw new MedialaneError(`Unsupported currency: ${currency}`, "INVALID_PARAMS");
|
|
1329
|
+
return token;
|
|
1330
|
+
}
|
|
1331
|
+
var _providerCache = /* @__PURE__ */ new WeakMap();
|
|
1332
|
+
function getProvider(config) {
|
|
1333
|
+
let p = _providerCache.get(config);
|
|
1334
|
+
if (!p) {
|
|
1335
|
+
const urls = Array.from(/* @__PURE__ */ new Set([config.rpcUrl, ...PUBLIC_RPC_FALLBACKS]));
|
|
1336
|
+
p = new RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
|
|
1337
|
+
_providerCache.set(config, p);
|
|
1338
|
+
}
|
|
1339
|
+
return p;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1298
1342
|
// src/starknet/abis/ipMarketplace.ts
|
|
1299
1343
|
var IPMarketplaceABI = [
|
|
1300
1344
|
{
|
|
@@ -11330,7 +11374,7 @@ var PopService = class {
|
|
|
11330
11374
|
this.factoryAddress = getStarknetCoordinates(config.chain).popFactory;
|
|
11331
11375
|
}
|
|
11332
11376
|
_collection(address, account) {
|
|
11333
|
-
return
|
|
11377
|
+
return newContract(POPCollectionABI, normalizeAddress("STARKNET", address), account);
|
|
11334
11378
|
}
|
|
11335
11379
|
async claim(account, collectionAddress) {
|
|
11336
11380
|
const call = this._collection(collectionAddress, account).populate("claim", []);
|
|
@@ -11379,7 +11423,7 @@ var PopService = class {
|
|
|
11379
11423
|
return { txHash: res.transaction_hash };
|
|
11380
11424
|
}
|
|
11381
11425
|
async createCollection(account, params) {
|
|
11382
|
-
const factory =
|
|
11426
|
+
const factory = newContract(POPFactoryABI, this.factoryAddress, account);
|
|
11383
11427
|
const call = factory.populate("create_collection", [
|
|
11384
11428
|
params.name,
|
|
11385
11429
|
params.symbol,
|
|
@@ -11421,7 +11465,7 @@ var DropService = class {
|
|
|
11421
11465
|
this.config = config;
|
|
11422
11466
|
}
|
|
11423
11467
|
_collection(address, account) {
|
|
11424
|
-
return
|
|
11468
|
+
return newContract(DropCollectionABI, normalizeAddress("STARKNET", address), account);
|
|
11425
11469
|
}
|
|
11426
11470
|
async claim(account, collectionAddress, quantity = 1) {
|
|
11427
11471
|
const collection = this._collection(collectionAddress, account);
|
|
@@ -11485,7 +11529,7 @@ var DropService = class {
|
|
|
11485
11529
|
return { txHash: res.transaction_hash };
|
|
11486
11530
|
}
|
|
11487
11531
|
async createDrop(account, params) {
|
|
11488
|
-
const factory =
|
|
11532
|
+
const factory = newContract(DropFactoryABI, this.factoryAddress, account);
|
|
11489
11533
|
const call = factory.populate("create_drop", [
|
|
11490
11534
|
params.name,
|
|
11491
11535
|
params.symbol,
|
|
@@ -11497,19 +11541,21 @@ var DropService = class {
|
|
|
11497
11541
|
return { txHash: res.transaction_hash };
|
|
11498
11542
|
}
|
|
11499
11543
|
};
|
|
11544
|
+
|
|
11545
|
+
// src/starknet/services/erc1155collection.ts
|
|
11500
11546
|
var ERC1155CollectionService = class {
|
|
11501
11547
|
constructor(config) {
|
|
11502
11548
|
this.factoryAddress = config.collection1155Contract ?? getStarknetCoordinates(config.chain).collection1155;
|
|
11503
11549
|
}
|
|
11504
11550
|
_factory(account) {
|
|
11505
|
-
return
|
|
11551
|
+
return newContract(
|
|
11506
11552
|
IPCollection1155FactoryABI,
|
|
11507
11553
|
normalizeAddress("STARKNET", this.factoryAddress),
|
|
11508
11554
|
account
|
|
11509
11555
|
);
|
|
11510
11556
|
}
|
|
11511
11557
|
_collection(address, account) {
|
|
11512
|
-
return
|
|
11558
|
+
return newContract(
|
|
11513
11559
|
IPCollection1155ABI,
|
|
11514
11560
|
normalizeAddress("STARKNET", address),
|
|
11515
11561
|
account
|
|
@@ -11654,7 +11700,7 @@ async function getCreatorCoinPrice(coinAddress, provider) {
|
|
|
11654
11700
|
var _factoryContract = null;
|
|
11655
11701
|
function factoryContract() {
|
|
11656
11702
|
if (!_factoryContract) {
|
|
11657
|
-
_factoryContract =
|
|
11703
|
+
_factoryContract = newContract(
|
|
11658
11704
|
CreatorCoinFactoryABI,
|
|
11659
11705
|
getStarknetCoordinates("STARKNET").creatorCoinFactory
|
|
11660
11706
|
);
|
|
@@ -11724,7 +11770,7 @@ var CreatorCoinService = class {
|
|
|
11724
11770
|
this.config = config;
|
|
11725
11771
|
}
|
|
11726
11772
|
_factory(account) {
|
|
11727
|
-
return
|
|
11773
|
+
return newContract(CreatorCoinFactoryABI, this.factoryAddress, account);
|
|
11728
11774
|
}
|
|
11729
11775
|
/** Deploy a fixed-supply CreatorCoin (full supply minted to the Factory). */
|
|
11730
11776
|
async createCreatorCoin(account, params) {
|
|
@@ -11759,14 +11805,14 @@ var TicketService = class {
|
|
|
11759
11805
|
_factory(account, factoryAddress) {
|
|
11760
11806
|
const address = factoryAddress ?? this.factoryAddress;
|
|
11761
11807
|
if (!address) throw new Error("IP-Tickets factory address not configured for this chain");
|
|
11762
|
-
return
|
|
11808
|
+
return newContract(IPTicketCollectionFactoryABI, normalizeAddress("STARKNET", address), account);
|
|
11763
11809
|
}
|
|
11764
11810
|
_collection(address, account) {
|
|
11765
|
-
return
|
|
11811
|
+
return newContract(IPTicketCollectionABI, normalizeAddress("STARKNET", address), account);
|
|
11766
11812
|
}
|
|
11767
11813
|
_collectionRead(address) {
|
|
11768
11814
|
const provider = new RpcProvider({ nodeUrl: this.config.rpcUrl });
|
|
11769
|
-
return
|
|
11815
|
+
return newContract(IPTicketCollectionABI, normalizeAddress("STARKNET", address), provider);
|
|
11770
11816
|
}
|
|
11771
11817
|
/** Deploys a new IPTicketCollection via the factory. Caller becomes owner. */
|
|
11772
11818
|
async deployCollection(account, params) {
|
|
@@ -11841,15 +11887,15 @@ var ClubService = class {
|
|
|
11841
11887
|
_registry(account, registryAddress) {
|
|
11842
11888
|
const address = registryAddress ?? this.registryAddress;
|
|
11843
11889
|
if (!address) throw new Error("IP-Club registry address not configured for this chain");
|
|
11844
|
-
return
|
|
11890
|
+
return newContract(IPClubABI, normalizeAddress("STARKNET", address), account);
|
|
11845
11891
|
}
|
|
11846
11892
|
_factory(account, factoryAddress) {
|
|
11847
11893
|
const address = factoryAddress ?? this.factoryAddress;
|
|
11848
11894
|
if (!address) throw new Error("IP-Club factory address not configured for this chain");
|
|
11849
|
-
return
|
|
11895
|
+
return newContract(IPClubFactoryABI, normalizeAddress("STARKNET", address), account);
|
|
11850
11896
|
}
|
|
11851
11897
|
_collection(account, collectionAddress) {
|
|
11852
|
-
return
|
|
11898
|
+
return newContract(IPClubCollectionABI, normalizeAddress("STARKNET", collectionAddress), account);
|
|
11853
11899
|
}
|
|
11854
11900
|
/** Deploy a new per-creator membership ERC-721 collection via the factory. */
|
|
11855
11901
|
async deployClub(account, params) {
|
|
@@ -11961,7 +12007,7 @@ var SponsorshipService = class {
|
|
|
11961
12007
|
if (!resolved) {
|
|
11962
12008
|
throw new Error("IP-Sponsorship address not configured for this chain");
|
|
11963
12009
|
}
|
|
11964
|
-
return
|
|
12010
|
+
return newContract(IPSponsorshipABI, normalizeAddress("STARKNET", resolved), account);
|
|
11965
12011
|
}
|
|
11966
12012
|
/** The offer author must currently own (nftContract, tokenId) — enforced on-chain at create and accept. */
|
|
11967
12013
|
async createOffer(account, params) {
|
|
@@ -12030,7 +12076,7 @@ var SponsorshipService = class {
|
|
|
12030
12076
|
cairo.uint256(params.offerId),
|
|
12031
12077
|
params.sponsor
|
|
12032
12078
|
]);
|
|
12033
|
-
const receipt =
|
|
12079
|
+
const receipt = newContract(IPGenesisABI, normalizeAddress("STARKNET", receiptAddress), account);
|
|
12034
12080
|
const mintCall = receipt.populate("mint_item", [params.sponsor, params.licenseTermsUri]);
|
|
12035
12081
|
const res = await account.execute([acceptCall, mintCall]);
|
|
12036
12082
|
return { txHash: res.transaction_hash };
|
|
@@ -12050,7 +12096,7 @@ var SponsorshipService = class {
|
|
|
12050
12096
|
];
|
|
12051
12097
|
const receiptAddress = params.licenseReceiptAddress ?? this.licenseReceiptAddress;
|
|
12052
12098
|
if (receiptAddress && params.receiptTokenId != null) {
|
|
12053
|
-
const receipt =
|
|
12099
|
+
const receipt = newContract(IPGenesisABI, normalizeAddress("STARKNET", receiptAddress), account);
|
|
12054
12100
|
calls.push(receipt.populate("transfer_from", [account.address, params.to, cairo.uint256(params.receiptTokenId)]));
|
|
12055
12101
|
}
|
|
12056
12102
|
const res = await account.execute(calls);
|
|
@@ -12105,48 +12151,6 @@ var MedialaneClient = class {
|
|
|
12105
12151
|
}
|
|
12106
12152
|
};
|
|
12107
12153
|
|
|
12108
|
-
// src/starknet/marketplace/errors.ts
|
|
12109
|
-
var MedialaneError = class extends Error {
|
|
12110
|
-
constructor(message, code = "UNKNOWN", cause) {
|
|
12111
|
-
super(message);
|
|
12112
|
-
this.code = code;
|
|
12113
|
-
this.cause = cause;
|
|
12114
|
-
this.name = "MedialaneError";
|
|
12115
|
-
}
|
|
12116
|
-
};
|
|
12117
|
-
var START_TIME_BUFFER_SECS = 30;
|
|
12118
|
-
function newContract(abi, address, providerOrAccount) {
|
|
12119
|
-
const C = Contract;
|
|
12120
|
-
return C.length === 1 ? new Contract({ abi, address, providerOrAccount }) : new Contract(
|
|
12121
|
-
abi,
|
|
12122
|
-
address,
|
|
12123
|
-
providerOrAccount
|
|
12124
|
-
);
|
|
12125
|
-
}
|
|
12126
|
-
function getChainId(config) {
|
|
12127
|
-
if (config.chain !== "STARKNET") {
|
|
12128
|
-
throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
|
|
12129
|
-
}
|
|
12130
|
-
return constants.StarknetChainId.SN_MAIN;
|
|
12131
|
-
}
|
|
12132
|
-
function resolveToken(currency) {
|
|
12133
|
-
const token = SUPPORTED_TOKENS.find(
|
|
12134
|
-
(t) => t.symbol === currency.toUpperCase() || t.address.toLowerCase() === currency.toLowerCase()
|
|
12135
|
-
);
|
|
12136
|
-
if (!token) throw new MedialaneError(`Unsupported currency: ${currency}`, "INVALID_PARAMS");
|
|
12137
|
-
return token;
|
|
12138
|
-
}
|
|
12139
|
-
var _providerCache = /* @__PURE__ */ new WeakMap();
|
|
12140
|
-
function getProvider(config) {
|
|
12141
|
-
let p = _providerCache.get(config);
|
|
12142
|
-
if (!p) {
|
|
12143
|
-
const urls = Array.from(/* @__PURE__ */ new Set([config.rpcUrl, ...PUBLIC_RPC_FALLBACKS]));
|
|
12144
|
-
p = new RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
|
|
12145
|
-
_providerCache.set(config, p);
|
|
12146
|
-
}
|
|
12147
|
-
return p;
|
|
12148
|
-
}
|
|
12149
|
-
|
|
12150
12154
|
// src/starknet/marketplace/orders.ts
|
|
12151
12155
|
var _contractCache = /* @__PURE__ */ new WeakMap();
|
|
12152
12156
|
function makeContract(config) {
|