@medialane/sdk 0.50.0 → 0.52.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/README.md CHANGED
@@ -75,11 +75,11 @@ const client = new MedialaneClient({
75
75
 
76
76
  ## Marketplace Operations (On-Chain)
77
77
 
78
- All methods require a `starknet.js` `AccountInterface`. Nonce management, SNIP-12 signing, and `waitForTransaction` are handled automatically.
78
+ All methods require a `starknet.js` `AccountInterface`. SNIP-12 signing and `waitForTransaction` are handled automatically. Fulfilment is **unsigned** — the caller is the fulfiller, so there is no `fulfiller`/`offerer` field to pass; cancellation still signs, but without a nonce (a per-offerer `counter` replaces it, see `incrementCounter`).
79
79
 
80
80
  Two marketplace modules are available:
81
- - `client.marketplace` — ERC-721 marketplace (`Medialane` contract)
82
- - `client.marketplace1155` — ERC-1155 marketplace (`Medialane1155V2` contract, deployed 2026-04-28)
81
+ - `client.marketplace` — ERC-721 marketplace (`Medialane721`)
82
+ - `client.marketplace1155` — ERC-1155 marketplace (`Medialane1155`)
83
83
 
84
84
  ### Create a Listing (ERC-721)
85
85
 
@@ -88,10 +88,10 @@ import { Account } from "starknet";
88
88
 
89
89
  const result = await client.marketplace.createListing(account, {
90
90
  nftContract: "0x05e73b7...",
91
- tokenId: 42n,
91
+ tokenId: "42",
92
92
  currency: "USDC",
93
93
  price: "1000000", // 1 USDC (6 decimals)
94
- endTime: Math.floor(Date.now() / 1000) + 86400 * 30, // 30 days
94
+ durationSeconds: 86400 * 30, // 30 days
95
95
  });
96
96
  console.log("Listed:", result.txHash);
97
97
  ```
@@ -101,19 +101,23 @@ console.log("Listed:", result.txHash);
101
101
  ```typescript
102
102
  const result = await client.marketplace.makeOffer(account, {
103
103
  nftContract: "0x05e73b7...",
104
- tokenId: 42n,
104
+ tokenId: "42",
105
105
  currency: "USDC",
106
106
  price: "500000", // 0.5 USDC
107
- endTime: Math.floor(Date.now() / 1000) + 86400 * 7,
107
+ durationSeconds: 86400 * 7,
108
108
  });
109
109
  ```
110
110
 
111
111
  ### Fulfill an Order
112
112
 
113
113
  ```typescript
114
+ // Fetch order details first to get paymentToken and totalPrice
115
+ const details = await client.api.getOrder(orderHash);
116
+
114
117
  const result = await client.marketplace.fulfillOrder(account, {
115
118
  orderHash: "0x...",
116
- fulfiller: account.address,
119
+ paymentToken: "0x033068...", // from order details
120
+ totalPrice: "1000000", // raw token units
117
121
  });
118
122
  ```
119
123
 
@@ -121,8 +125,8 @@ const result = await client.marketplace.fulfillOrder(account, {
121
125
 
122
126
  ```typescript
123
127
  const result = await client.marketplace.checkoutCart(account, [
124
- { orderHash: "0x...", fulfiller: account.address },
125
- { orderHash: "0x...", fulfiller: account.address },
128
+ { orderHash: "0x...", considerationToken: "0x033068...", considerationAmount: "1000000" },
129
+ { orderHash: "0x...", considerationToken: "0x033068...", considerationAmount: "500000" },
126
130
  ]);
127
131
  ```
128
132
 
@@ -131,10 +135,16 @@ const result = await client.marketplace.checkoutCart(account, [
131
135
  ```typescript
132
136
  const result = await client.marketplace.cancelOrder(account, {
133
137
  orderHash: "0x...",
134
- offerer: account.address,
135
138
  });
136
139
  ```
137
140
 
141
+ ### Bulk-Cancel (Invalidate All Open Orders)
142
+
143
+ ```typescript
144
+ // Bumps the caller's counter — every previously-registered order becomes unfulfillable.
145
+ await client.marketplace.incrementCounter(account);
146
+ ```
147
+
138
148
  ### Mint an IP Asset
139
149
 
140
150
  ```typescript
@@ -142,6 +152,7 @@ const result = await client.marketplace.mint(account, {
142
152
  collectionId: "1", // collection ID on the registry
143
153
  recipient: account.address,
144
154
  tokenUri: "ipfs://...", // IPFS URI of the metadata JSON
155
+ royaltyBps: 500, // EIP-2981 secondary-sale royalty, 0-10_000 (required since MIP v0.4.0)
145
156
  });
146
157
  ```
147
158
 
@@ -159,7 +170,7 @@ const result = await client.marketplace.createCollection(account, {
159
170
 
160
171
  ## ERC-1155 Marketplace (Medialane1155)
161
172
 
162
- For IP assets from ERC-1155 collections (e.g. IP-Programmable-ERC1155-Collections). Contract: `0x02bfa521c25461a09d735889b469418608d7d92f8b26e3d37ef174a4c2e22f99`.
173
+ For IP assets from ERC-1155 collections (e.g. IP-Programmable-ERC1155-Collections). Contract address: see `getCoordinates("STARKNET").marketplace1155` in `src/chains.ts` (the single source — do not hardcode it here, it changes on redeploy).
163
174
 
164
175
  ### Create an ERC-1155 Listing
165
176
 
@@ -201,8 +212,11 @@ const result = await client.marketplace1155.cancelOrder(account, {
201
212
 
202
213
  ### SNIP-12 Typed Data Builders (ChipiPay / custom flows)
203
214
 
215
+ Listing/offer and cancellation are signed; fulfilment is an **unsigned** call (the buyer is
216
+ the fulfiller, since v0.26.0) — there is no fulfillment typed-data builder.
217
+
204
218
  ```typescript
205
- import { build1155OrderTypedData, build1155FulfillmentTypedData, build1155CancellationTypedData } from "@medialane/sdk";
219
+ import { build1155OrderTypedData, build1155CancellationTypedData } from "@medialane/sdk";
206
220
  import { constants } from "starknet";
207
221
 
208
222
  const typedData = build1155OrderTypedData(orderParams, constants.StarknetChainId.SN_MAIN);
@@ -0,0 +1,96 @@
1
+ /** Mirrors the backend Prisma `Chain` enum. */
2
+ declare const CHAINS: readonly ["STARKNET", "ETHEREUM", "SOLANA", "BASE", "STELLAR", "BITCOIN"];
3
+ type Chain = (typeof CHAINS)[number];
4
+ /** Starknet coordinates of Medialane services + venues. All fields optional
5
+ * because not every service exists on every chain. */
6
+ interface StarknetCoordinates {
7
+ rpcUrl: string;
8
+ marketplace721?: `0x${string}`;
9
+ marketplace721ClassHash?: `0x${string}`;
10
+ marketplace721StartBlock?: number;
11
+ marketplace1155?: `0x${string}`;
12
+ marketplace1155ClassHash?: `0x${string}`;
13
+ marketplace1155StartBlock?: number;
14
+ collection721?: `0x${string}`;
15
+ collection721StartBlock?: number;
16
+ ipNftClassHash?: `0x${string}`;
17
+ ipCollectionClassHash?: `0x${string}`;
18
+ collection1155?: `0x${string}`;
19
+ collection1155FactoryClassHash?: `0x${string}`;
20
+ collection1155ClassHash?: `0x${string}`;
21
+ collection1155StartBlock?: number;
22
+ popFactory?: `0x${string}`;
23
+ popCollectionClassHash?: `0x${string}`;
24
+ dropFactory?: `0x${string}`;
25
+ dropCollectionClassHash?: `0x${string}`;
26
+ nftComments?: `0x${string}`;
27
+ creatorCoinFactory?: `0x${string}`;
28
+ creatorCoinEkuboLauncher?: `0x${string}`;
29
+ creatorCoinClassHash?: `0x${string}`;
30
+ creatorCoinFactoryClassHash?: `0x${string}`;
31
+ creatorCoinStartBlock?: number;
32
+ ekuboCore?: `0x${string}`;
33
+ ipTicketsFactory?: `0x${string}`;
34
+ ipTicketCollectionClassHash?: `0x${string}`;
35
+ ipTicketsStartBlock?: number;
36
+ ipClubRegistry?: `0x${string}`;
37
+ ipClubNftClassHash?: `0x${string}`;
38
+ ipClubStartBlock?: number;
39
+ ipSponsorship?: `0x${string}`;
40
+ ipSponsorshipStartBlock?: number;
41
+ ipSponsorshipLicense?: `0x${string}`;
42
+ }
43
+ /** Coordinates per chain. Only STARKNET is populated today; adding a chain
44
+ * means adding an entry here (litmus test, spec §7). */
45
+ /** EVM coordinates — one shape for Ethereum and Base (same bytecode, two
46
+ * chains). Populated at deploy time (federation Phase 4). */
47
+ interface EvmCoordinates {
48
+ rpcUrl: string;
49
+ marketplace721?: `0x${string}`;
50
+ marketplace721StartBlock?: number;
51
+ marketplace1155?: `0x${string}`;
52
+ marketplace1155StartBlock?: number;
53
+ mipRegistry?: `0x${string}`;
54
+ mipRegistryStartBlock?: number;
55
+ mipEditionsRegistry?: `0x${string}`;
56
+ mipEditionsRegistryStartBlock?: number;
57
+ }
58
+ /** Solana coordinates — base58 program ids. Populated at deploy time. */
59
+ interface SolanaCoordinates {
60
+ rpcUrl: string;
61
+ mipCollectionsProgram?: string;
62
+ marketplaceProgram?: string;
63
+ startSlot?: number;
64
+ }
65
+ /** Stellar (Soroban) coordinates — strkey contract ids. Populated at deploy
66
+ * time; the registry takes the collection WASM hash as a constructor arg. */
67
+ interface StellarCoordinates {
68
+ rpcUrl: string;
69
+ mipRegistry?: string;
70
+ marketplace?: string;
71
+ collectionWasmHash?: string;
72
+ startLedger?: number;
73
+ }
74
+ /** Per-chain coordinate shapes. Every chain is an equal entry — no chain is
75
+ * privileged in core (chain-sovereignty I2/I4). */
76
+ interface CoordinatesByChain {
77
+ STARKNET?: StarknetCoordinates;
78
+ ETHEREUM?: EvmCoordinates;
79
+ BASE?: EvmCoordinates;
80
+ SOLANA?: SolanaCoordinates;
81
+ STELLAR?: StellarCoordinates;
82
+ BITCOIN?: never;
83
+ }
84
+ /** @deprecated Renamed — use `StarknetCoordinates` (coordinates are per-chain-shaped). */
85
+ type ChainCoordinates = StarknetCoordinates;
86
+ declare function getCoordinates(chain: "STARKNET"): StarknetCoordinates;
87
+ declare function getCoordinates(chain: "ETHEREUM" | "BASE"): EvmCoordinates;
88
+ declare function getCoordinates(chain: "SOLANA"): SolanaCoordinates;
89
+ declare function getCoordinates(chain: "STELLAR"): StellarCoordinates;
90
+ declare function getCoordinates(chain: Chain): StarknetCoordinates | EvmCoordinates | SolanaCoordinates | StellarCoordinates;
91
+ declare const DEFAULT_CHAIN: Chain;
92
+ /** Typed Starknet coordinates for Starknet-only modules; throws when the
93
+ * client is scoped to another chain. */
94
+ declare function getStarknetCoordinates(chain: Chain): StarknetCoordinates;
95
+
96
+ export { type Chain as C, DEFAULT_CHAIN as D, type EvmCoordinates as E, type SolanaCoordinates as S, CHAINS as a, type ChainCoordinates as b, type CoordinatesByChain as c, type StarknetCoordinates as d, type StellarCoordinates as e, getStarknetCoordinates as f, getCoordinates as g };
@@ -0,0 +1,96 @@
1
+ /** Mirrors the backend Prisma `Chain` enum. */
2
+ declare const CHAINS: readonly ["STARKNET", "ETHEREUM", "SOLANA", "BASE", "STELLAR", "BITCOIN"];
3
+ type Chain = (typeof CHAINS)[number];
4
+ /** Starknet coordinates of Medialane services + venues. All fields optional
5
+ * because not every service exists on every chain. */
6
+ interface StarknetCoordinates {
7
+ rpcUrl: string;
8
+ marketplace721?: `0x${string}`;
9
+ marketplace721ClassHash?: `0x${string}`;
10
+ marketplace721StartBlock?: number;
11
+ marketplace1155?: `0x${string}`;
12
+ marketplace1155ClassHash?: `0x${string}`;
13
+ marketplace1155StartBlock?: number;
14
+ collection721?: `0x${string}`;
15
+ collection721StartBlock?: number;
16
+ ipNftClassHash?: `0x${string}`;
17
+ ipCollectionClassHash?: `0x${string}`;
18
+ collection1155?: `0x${string}`;
19
+ collection1155FactoryClassHash?: `0x${string}`;
20
+ collection1155ClassHash?: `0x${string}`;
21
+ collection1155StartBlock?: number;
22
+ popFactory?: `0x${string}`;
23
+ popCollectionClassHash?: `0x${string}`;
24
+ dropFactory?: `0x${string}`;
25
+ dropCollectionClassHash?: `0x${string}`;
26
+ nftComments?: `0x${string}`;
27
+ creatorCoinFactory?: `0x${string}`;
28
+ creatorCoinEkuboLauncher?: `0x${string}`;
29
+ creatorCoinClassHash?: `0x${string}`;
30
+ creatorCoinFactoryClassHash?: `0x${string}`;
31
+ creatorCoinStartBlock?: number;
32
+ ekuboCore?: `0x${string}`;
33
+ ipTicketsFactory?: `0x${string}`;
34
+ ipTicketCollectionClassHash?: `0x${string}`;
35
+ ipTicketsStartBlock?: number;
36
+ ipClubRegistry?: `0x${string}`;
37
+ ipClubNftClassHash?: `0x${string}`;
38
+ ipClubStartBlock?: number;
39
+ ipSponsorship?: `0x${string}`;
40
+ ipSponsorshipStartBlock?: number;
41
+ ipSponsorshipLicense?: `0x${string}`;
42
+ }
43
+ /** Coordinates per chain. Only STARKNET is populated today; adding a chain
44
+ * means adding an entry here (litmus test, spec §7). */
45
+ /** EVM coordinates — one shape for Ethereum and Base (same bytecode, two
46
+ * chains). Populated at deploy time (federation Phase 4). */
47
+ interface EvmCoordinates {
48
+ rpcUrl: string;
49
+ marketplace721?: `0x${string}`;
50
+ marketplace721StartBlock?: number;
51
+ marketplace1155?: `0x${string}`;
52
+ marketplace1155StartBlock?: number;
53
+ mipRegistry?: `0x${string}`;
54
+ mipRegistryStartBlock?: number;
55
+ mipEditionsRegistry?: `0x${string}`;
56
+ mipEditionsRegistryStartBlock?: number;
57
+ }
58
+ /** Solana coordinates — base58 program ids. Populated at deploy time. */
59
+ interface SolanaCoordinates {
60
+ rpcUrl: string;
61
+ mipCollectionsProgram?: string;
62
+ marketplaceProgram?: string;
63
+ startSlot?: number;
64
+ }
65
+ /** Stellar (Soroban) coordinates — strkey contract ids. Populated at deploy
66
+ * time; the registry takes the collection WASM hash as a constructor arg. */
67
+ interface StellarCoordinates {
68
+ rpcUrl: string;
69
+ mipRegistry?: string;
70
+ marketplace?: string;
71
+ collectionWasmHash?: string;
72
+ startLedger?: number;
73
+ }
74
+ /** Per-chain coordinate shapes. Every chain is an equal entry — no chain is
75
+ * privileged in core (chain-sovereignty I2/I4). */
76
+ interface CoordinatesByChain {
77
+ STARKNET?: StarknetCoordinates;
78
+ ETHEREUM?: EvmCoordinates;
79
+ BASE?: EvmCoordinates;
80
+ SOLANA?: SolanaCoordinates;
81
+ STELLAR?: StellarCoordinates;
82
+ BITCOIN?: never;
83
+ }
84
+ /** @deprecated Renamed — use `StarknetCoordinates` (coordinates are per-chain-shaped). */
85
+ type ChainCoordinates = StarknetCoordinates;
86
+ declare function getCoordinates(chain: "STARKNET"): StarknetCoordinates;
87
+ declare function getCoordinates(chain: "ETHEREUM" | "BASE"): EvmCoordinates;
88
+ declare function getCoordinates(chain: "SOLANA"): SolanaCoordinates;
89
+ declare function getCoordinates(chain: "STELLAR"): StellarCoordinates;
90
+ declare function getCoordinates(chain: Chain): StarknetCoordinates | EvmCoordinates | SolanaCoordinates | StellarCoordinates;
91
+ declare const DEFAULT_CHAIN: Chain;
92
+ /** Typed Starknet coordinates for Starknet-only modules; throws when the
93
+ * client is scoped to another chain. */
94
+ declare function getStarknetCoordinates(chain: Chain): StarknetCoordinates;
95
+
96
+ export { type Chain as C, DEFAULT_CHAIN as D, type EvmCoordinates as E, type SolanaCoordinates as S, CHAINS as a, type ChainCoordinates as b, type CoordinatesByChain as c, type StarknetCoordinates as d, type StellarCoordinates as e, getStarknetCoordinates as f, getCoordinates as g };
@@ -0,0 +1,357 @@
1
+ 'use strict';
2
+
3
+ var viem = require('viem');
4
+
5
+ // src/evm/typedData.ts
6
+ var EVM_ORDER_TYPES = {
7
+ OfferItem: [
8
+ { name: "itemType", type: "uint8" },
9
+ { name: "token", type: "address" },
10
+ { name: "identifier", type: "uint256" },
11
+ { name: "amount", type: "uint256" }
12
+ ],
13
+ ConsiderationItem: [
14
+ { name: "itemType", type: "uint8" },
15
+ { name: "token", type: "address" },
16
+ { name: "identifier", type: "uint256" },
17
+ { name: "amount", type: "uint256" },
18
+ { name: "recipient", type: "address" }
19
+ ],
20
+ OrderParameters: [
21
+ { name: "offerer", type: "address" },
22
+ { name: "offer", type: "OfferItem" },
23
+ { name: "consideration", type: "ConsiderationItem" },
24
+ { name: "royaltyMaxBps", type: "uint256" },
25
+ { name: "startTime", type: "uint256" },
26
+ { name: "endTime", type: "uint256" },
27
+ { name: "salt", type: "uint256" },
28
+ { name: "counter", type: "uint256" }
29
+ ]
30
+ };
31
+ function evmOrderDomain(chainId, verifyingContract) {
32
+ return { name: "Medialane", version: "1", chainId, verifyingContract };
33
+ }
34
+ function evmOrderDigest(chainId, verifyingContract, parameters) {
35
+ return viem.hashTypedData({
36
+ domain: evmOrderDomain(chainId, verifyingContract),
37
+ types: EVM_ORDER_TYPES,
38
+ primaryType: "OrderParameters",
39
+ message: parameters
40
+ });
41
+ }
42
+
43
+ // src/chains.ts
44
+ var COORDINATES = {
45
+ STARKNET: {
46
+ rpcUrl: "https://rpc.starknet.lava.build",
47
+ marketplace721: "0x03eda9a2b6ad90845a43591bac8083ebaf677d51fdf20f503b2c01889e3131fc",
48
+ marketplace721ClassHash: "0x0700d9230d07e5203e27778c0dc70f9134d2b25bf319f7cf8348dc66a6923e90",
49
+ marketplace721StartBlock: 11198146,
50
+ marketplace1155: "0x07c4ce1c19ea48cc11135ed22b19ff745f5aec508c3828593002e4f76fdb1b38",
51
+ marketplace1155ClassHash: "0x0242f5c388da7cee2d99e2a69453c8159bf927fbec4e797a3cfdcbbcb5b68328",
52
+ marketplace1155StartBlock: 11198267,
53
+ collection721: "0x0225c3ae09506b8d97adc39649ca740dad5aac195b7f5f0441cc1852947acaea",
54
+ collection721StartBlock: 11198496,
55
+ ipNftClassHash: "0x012d3ae40ba35c7e2be0946532dac60e48932447912fdf96b674da67c029b9cc",
56
+ ipCollectionClassHash: "0x022155a1a130a40e57aac4b89c07fab3f616bc351b1270fc40f756b963afe8b4",
57
+ collection1155: "0x015368976d46fae5bfa1c58600f641d5aa5dbbf53ebc6b78aa3922194aad3551",
58
+ collection1155FactoryClassHash: "0x04eb6b419770f13bd191f120b9fc9ee624c0613ad4490062d293ca2016b3b1d2",
59
+ collection1155ClassHash: "0x06cf3f5a2322dac35e07a6064a5b8802f19fda8aa3f4726f0cb7bc05dea1bd78",
60
+ collection1155StartBlock: 11199527,
61
+ popFactory: "0x00b32c34b427d8f346b5843ada6a37bd3368d879fc752cd52b68a87287f60111",
62
+ popCollectionClassHash: "0x077c421686f10851872561953ea16898d933364b7f8937a5d7e2b1ba0a36263f",
63
+ dropFactory: "0x03587f42e29daee1b193f6cf83bf8627908ed6632d0d83fcb26225c50547d800",
64
+ dropCollectionClassHash: "0x00092e72cdb63067521e803aaf7d4101c3e3ce026ae6bc045ec4228027e58282",
65
+ nftComments: "0x02cdac70c94447189af0389dfea63f4d5e4154ea8a563de288a5ab1c39e37843",
66
+ creatorCoinFactory: "0x50fa807b5274079fb19374673d7bab6d2dc3af7e1032ea43eb6e44bcbde4c3c",
67
+ creatorCoinEkuboLauncher: "0x4f7fceb5ac10f12f9544a09580592e5bdf1b7f04f48765eecf12286d8ccb7b4",
68
+ creatorCoinClassHash: "0x743e4c8a5b96bb83bbf4af04edbbb482d5ece89eed9b729a79fb7df0cd0b6b6",
69
+ creatorCoinFactoryClassHash: "0x51765926b1344c9a20b8cd4b5abe7b7d47375ae97cf6804db3ea5d4b05a9b55",
70
+ creatorCoinStartBlock: 10474544,
71
+ ekuboCore: "0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b",
72
+ ipTicketsFactory: "0x0664c2d6a4da9ee3ff053ceeba7579c01f2fedfd9d2b57b4c07af3734bd4acab",
73
+ ipTicketCollectionClassHash: "0x086f59c416e365e2bee4ceff9f1dcb96198f2342d50ba4621f60b831863adb6",
74
+ ipTicketsStartBlock: 11404656,
75
+ ipClubRegistry: "0x00e189c619b6bb07d78973a149641c59c37eb0716f8584d7520bce12d303eede",
76
+ ipClubNftClassHash: "0x02bc9b20cca21b04245e9215bf7121f4d7295b195890e449b472b573017fb889",
77
+ ipClubStartBlock: 11404776,
78
+ ipSponsorship: "0x044d9b9c3bb29b94685b0a3fe27a5e2dfa30a3637ab55979c718ebcd3268bc2f",
79
+ ipSponsorshipStartBlock: 11405085,
80
+ // Dedicated ip-erc721/MIP instance for sponsorship receipts (class hash
81
+ // 0x01bd7e39c5135b32b664e34cbbb4eafbd707a0fbc3ec2ef28657f52577d277d7) —
82
+ // never the genesis-mint instance.
83
+ ipSponsorshipLicense: "0x06bcfc4e97758a2abf95af4bd49596efdbfd88ccd740caddc56ad0a4bd095839"
84
+ }
85
+ };
86
+ function getCoordinates(chain) {
87
+ const c = COORDINATES[chain];
88
+ if (!c) throw new Error(`No coordinates configured for chain "${chain}"`);
89
+ return c;
90
+ }
91
+ var EvmVenueABI = viem.parseAbi([
92
+ "struct OfferItem { uint8 itemType; address token; uint256 identifier; uint256 amount; }",
93
+ "struct ConsiderationItem { uint8 itemType; address token; uint256 identifier; uint256 amount; address recipient; }",
94
+ "struct OrderParameters { address offerer; OfferItem offer; ConsiderationItem consideration; uint256 royaltyMaxBps; uint256 startTime; uint256 endTime; uint256 salt; uint256 counter; }",
95
+ "function registerOrder(OrderParameters parameters, bytes signature)",
96
+ "function fulfillOrder(bytes32 orderHash) payable",
97
+ "function cancelOrder(bytes32 orderHash)",
98
+ "function incrementCounter()",
99
+ "function getOrderHash(OrderParameters parameters) view returns (bytes32)",
100
+ "function getCounter(address offerer) view returns (uint256)",
101
+ "function version() pure returns (string)",
102
+ "event OrderCreated(bytes32 indexed orderHash, address indexed offerer)",
103
+ "event OrderFulfilled(bytes32 indexed orderHash, address indexed offerer, address indexed fulfiller, uint256 saleAmount, address royaltyReceiver, uint256 royaltyAmount)",
104
+ "event OrderCancelled(bytes32 indexed orderHash, address indexed offerer)",
105
+ "event CounterIncremented(address indexed offerer, uint256 newCounter)"
106
+ ]);
107
+ var EvmVenue1155ABI = viem.parseAbi([
108
+ "function fulfillOrder(bytes32 orderHash, uint256 quantity) payable",
109
+ "event OrderFulfilled(bytes32 indexed orderHash, address indexed offerer, address indexed fulfiller, uint256 quantity, uint256 remainingAmount, uint256 saleAmount, address royaltyReceiver, uint256 royaltyAmount)"
110
+ ]);
111
+ var EvmMipRegistryABI = viem.parseAbi([
112
+ "function createCollection(string name, string symbol, string baseUri, uint96 royaltyBps) returns (uint256 collectionId, address collection)",
113
+ "function getCollection(uint256 collectionId) view returns (address collection, address creator)",
114
+ "function collectionCount() view returns (uint256)",
115
+ "event CollectionCreated(uint256 indexed collectionId, address indexed collection, address indexed creator, string name, string symbol, string baseUri)"
116
+ ]);
117
+ var EvmMipCollectionABI = viem.parseAbi([
118
+ "function mint(address to, string metadataUri) returns (uint256 tokenId)",
119
+ "function batchMint(address[] to, string[] metadataUris) returns (uint256[] tokenIds)",
120
+ "function tokenURI(uint256 tokenId) view returns (string)",
121
+ "function ownerOf(uint256 tokenId) view returns (address)",
122
+ "function balanceOf(address owner) view returns (uint256)",
123
+ "function owner() view returns (address)",
124
+ "event TokenMinted(uint256 indexed tokenId, address indexed owner, string metadataUri)",
125
+ "event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)"
126
+ ]);
127
+
128
+ // src/evm/venue.ts
129
+ var EvmVenue = class {
130
+ constructor(opts) {
131
+ this.chain = opts.chain;
132
+ this.chainId = opts.chainId;
133
+ this.publicClient = opts.publicClient;
134
+ this.variant = opts.variant;
135
+ const coords = maybeCoords(opts.chain);
136
+ const contract = opts.contract ?? (opts.variant === "721" ? coords?.marketplace721 : coords?.marketplace1155);
137
+ if (!contract) throw new Error(`No ${opts.variant} venue configured for ${opts.chain}`);
138
+ this.contract = contract;
139
+ }
140
+ /** Builds the order struct, signs the EIP-712 digest, and registers it.
141
+ * The digest is the canonical order id on EVM chains. */
142
+ async registerOrder(signer, params) {
143
+ const account = signer.account;
144
+ if (!account) throw new Error("WalletClient has no account");
145
+ const counter = await this.getCounter(account.address);
146
+ const nft = {
147
+ itemType: 2,
148
+ token: params.asset.contract,
149
+ identifier: BigInt(params.asset.tokenId),
150
+ amount: 1n
151
+ };
152
+ const payment = {
153
+ itemType: params.paymentToken === NATIVE_SENTINEL ? 0 : 1,
154
+ token: params.paymentToken === NATIVE_SENTINEL ? "0x0000000000000000000000000000000000000000" : params.paymentToken,
155
+ identifier: 0n,
156
+ amount: BigInt(params.amount)
157
+ };
158
+ const order = params.side === "listing" ? {
159
+ offerer: account.address,
160
+ offer: nft,
161
+ consideration: { ...payment, recipient: account.address },
162
+ ...commonFields(params)
163
+ } : {
164
+ offerer: account.address,
165
+ offer: payment,
166
+ consideration: { ...nft, recipient: account.address },
167
+ ...commonFields(params)
168
+ };
169
+ order.counter = counter;
170
+ const signature = await signer.signTypedData({
171
+ account,
172
+ domain: evmOrderDomain(this.chainId, this.contract),
173
+ types: EVM_ORDER_TYPES,
174
+ primaryType: "OrderParameters",
175
+ message: order
176
+ });
177
+ const txHash = await signer.writeContract({
178
+ account,
179
+ chain: signer.chain,
180
+ address: this.contract,
181
+ abi: EvmVenueABI,
182
+ functionName: "registerOrder",
183
+ args: [order, signature]
184
+ });
185
+ return { txHash, orderRef: evmOrderDigest(this.chainId, this.contract, order) };
186
+ }
187
+ async fulfillOrder(signer, orderRef, opts) {
188
+ const account = signer.account;
189
+ if (!account) throw new Error("WalletClient has no account");
190
+ const value = opts?.value ? BigInt(opts.value) : void 0;
191
+ const txHash = this.variant === "1155" ? await signer.writeContract({
192
+ account,
193
+ chain: signer.chain,
194
+ address: this.contract,
195
+ abi: EvmVenue1155ABI,
196
+ functionName: "fulfillOrder",
197
+ args: [orderRef, BigInt(opts?.quantity ?? "1")],
198
+ value
199
+ }) : await signer.writeContract({
200
+ account,
201
+ chain: signer.chain,
202
+ address: this.contract,
203
+ abi: EvmVenueABI,
204
+ functionName: "fulfillOrder",
205
+ args: [orderRef],
206
+ value
207
+ });
208
+ return { txHash };
209
+ }
210
+ async cancelOrder(signer, orderRef) {
211
+ const account = signer.account;
212
+ if (!account) throw new Error("WalletClient has no account");
213
+ const txHash = await signer.writeContract({
214
+ account,
215
+ chain: signer.chain,
216
+ address: this.contract,
217
+ abi: EvmVenueABI,
218
+ functionName: "cancelOrder",
219
+ args: [orderRef]
220
+ });
221
+ return { txHash };
222
+ }
223
+ async incrementCounter(signer) {
224
+ const account = signer.account;
225
+ if (!account) throw new Error("WalletClient has no account");
226
+ const txHash = await signer.writeContract({
227
+ account,
228
+ chain: signer.chain,
229
+ address: this.contract,
230
+ abi: EvmVenueABI,
231
+ functionName: "incrementCounter",
232
+ args: []
233
+ });
234
+ return { txHash };
235
+ }
236
+ async getOrderDetails(orderRef) {
237
+ return this.publicClient.readContract({
238
+ address: this.contract,
239
+ abi: [
240
+ {
241
+ type: "function",
242
+ name: "getOrderDetails",
243
+ stateMutability: "view",
244
+ inputs: [{ name: "orderHash", type: "bytes32" }],
245
+ outputs: [{ name: "", type: "bytes" }]
246
+ }
247
+ ],
248
+ functionName: "getOrderDetails",
249
+ args: [orderRef]
250
+ });
251
+ }
252
+ async getCounter(address) {
253
+ return this.publicClient.readContract({
254
+ address: this.contract,
255
+ abi: EvmVenueABI,
256
+ functionName: "getCounter",
257
+ args: [address]
258
+ });
259
+ }
260
+ };
261
+ var NATIVE_SENTINEL = "native";
262
+ function commonFields(params) {
263
+ return {
264
+ royaltyMaxBps: BigInt(params.royaltyMaxBps),
265
+ startTime: BigInt(params.startTime),
266
+ endTime: BigInt(params.endTime),
267
+ salt: BigInt(params.salt),
268
+ counter: 0n
269
+ };
270
+ }
271
+ function maybeCoords(chain) {
272
+ try {
273
+ return getCoordinates(chain);
274
+ } catch {
275
+ return void 0;
276
+ }
277
+ }
278
+ var EvmIssuance = class {
279
+ constructor(opts) {
280
+ this.chain = opts.chain;
281
+ this.publicClient = opts.publicClient;
282
+ const registry = opts.registry ?? maybeCoords2(opts.chain)?.mipRegistry;
283
+ if (!registry) throw new Error(`No MIP registry configured for ${opts.chain}`);
284
+ this.registry = registry;
285
+ }
286
+ async createCollection(signer, params) {
287
+ const account = signer.account;
288
+ if (!account) throw new Error("WalletClient has no account");
289
+ const txHash = await signer.writeContract({
290
+ account,
291
+ chain: signer.chain,
292
+ address: this.registry,
293
+ abi: EvmMipRegistryABI,
294
+ functionName: "createCollection",
295
+ args: [params.name, params.symbol, params.baseUri, BigInt(params.royaltyBps)]
296
+ });
297
+ const receipt = await this.publicClient.waitForTransactionReceipt({ hash: txHash });
298
+ const [created] = viem.parseEventLogs({
299
+ abi: EvmMipRegistryABI,
300
+ eventName: "CollectionCreated",
301
+ logs: receipt.logs
302
+ });
303
+ return { txHash, collection: created?.args.collection ?? "" };
304
+ }
305
+ async mint(signer, params) {
306
+ const account = signer.account;
307
+ if (!account) throw new Error("WalletClient has no account");
308
+ const txHash = await signer.writeContract({
309
+ account,
310
+ chain: signer.chain,
311
+ address: params.collection,
312
+ abi: EvmMipCollectionABI,
313
+ functionName: "mint",
314
+ args: [params.recipient, params.tokenUri]
315
+ });
316
+ const receipt = await this.publicClient.waitForTransactionReceipt({ hash: txHash });
317
+ const [minted] = viem.parseEventLogs({
318
+ abi: EvmMipCollectionABI,
319
+ eventName: "TokenMinted",
320
+ logs: receipt.logs
321
+ });
322
+ return { txHash, tokenId: (minted?.args.tokenId ?? 0n).toString() };
323
+ }
324
+ async batchMint(signer, params) {
325
+ const account = signer.account;
326
+ if (!account) throw new Error("WalletClient has no account");
327
+ const txHash = await signer.writeContract({
328
+ account,
329
+ chain: signer.chain,
330
+ address: params.collection,
331
+ abi: EvmMipCollectionABI,
332
+ functionName: "batchMint",
333
+ args: [params.recipients, params.tokenUris]
334
+ });
335
+ return { txHash };
336
+ }
337
+ };
338
+ function maybeCoords2(chain) {
339
+ try {
340
+ return getCoordinates(chain);
341
+ } catch {
342
+ return void 0;
343
+ }
344
+ }
345
+
346
+ exports.EVM_ORDER_TYPES = EVM_ORDER_TYPES;
347
+ exports.EvmIssuance = EvmIssuance;
348
+ exports.EvmMipCollectionABI = EvmMipCollectionABI;
349
+ exports.EvmMipRegistryABI = EvmMipRegistryABI;
350
+ exports.EvmVenue = EvmVenue;
351
+ exports.EvmVenue1155ABI = EvmVenue1155ABI;
352
+ exports.EvmVenueABI = EvmVenueABI;
353
+ exports.NATIVE_SENTINEL = NATIVE_SENTINEL;
354
+ exports.evmOrderDigest = evmOrderDigest;
355
+ exports.evmOrderDomain = evmOrderDomain;
356
+ //# sourceMappingURL=index.cjs.map
357
+ //# sourceMappingURL=index.cjs.map