@medialane/sdk 0.52.0 → 0.53.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.
@@ -1,241 +0,0 @@
1
- import { sha256 } from '@noble/hashes/sha2.js';
2
- import { PublicKey, TransactionInstruction, SystemProgram, Transaction } from '@solana/web3.js';
3
-
4
- // src/solana/encoding.ts
5
- function instructionDiscriminator(name) {
6
- return sha256(new TextEncoder().encode(`global:${name}`)).slice(0, 8);
7
- }
8
- function eventDiscriminator(name) {
9
- return sha256(new TextEncoder().encode(`event:${name}`)).slice(0, 8);
10
- }
11
- var BorshWriter = class {
12
- constructor() {
13
- this.chunks = [];
14
- }
15
- u8(v) {
16
- this.chunks.push(Uint8Array.of(v));
17
- return this;
18
- }
19
- u16(v) {
20
- const b = new Uint8Array(2);
21
- new DataView(b.buffer).setUint16(0, v, true);
22
- this.chunks.push(b);
23
- return this;
24
- }
25
- u64(v) {
26
- const b = new Uint8Array(8);
27
- new DataView(b.buffer).setBigUint64(0, v, true);
28
- this.chunks.push(b);
29
- return this;
30
- }
31
- i64(v) {
32
- const b = new Uint8Array(8);
33
- new DataView(b.buffer).setBigInt64(0, v, true);
34
- this.chunks.push(b);
35
- return this;
36
- }
37
- string(v) {
38
- const bytes = new TextEncoder().encode(v);
39
- const len = new Uint8Array(4);
40
- new DataView(len.buffer).setUint32(0, bytes.length, true);
41
- this.chunks.push(len, bytes);
42
- return this;
43
- }
44
- pubkey(v) {
45
- this.chunks.push(v.toBytes());
46
- return this;
47
- }
48
- option(v, write) {
49
- if (v === null || v === void 0) {
50
- this.u8(0);
51
- } else {
52
- this.u8(1);
53
- write(v);
54
- }
55
- return this;
56
- }
57
- build(discriminator) {
58
- const total = this.chunks.reduce((n, c) => n + c.length, discriminator.length);
59
- const out = new Uint8Array(total);
60
- out.set(discriminator, 0);
61
- let offset = discriminator.length;
62
- for (const chunk of this.chunks) {
63
- out.set(chunk, offset);
64
- offset += chunk.length;
65
- }
66
- return out;
67
- }
68
- };
69
- function u64le(v) {
70
- const b = new Uint8Array(8);
71
- new DataView(b.buffer).setBigUint64(0, v, true);
72
- return b;
73
- }
74
- function orderPda(program, offerer, salt) {
75
- return PublicKey.findProgramAddressSync(
76
- [new TextEncoder().encode("order"), offerer.toBytes(), u64le(salt)],
77
- program
78
- )[0];
79
- }
80
- function counterPda(program, offerer) {
81
- return PublicKey.findProgramAddressSync(
82
- [new TextEncoder().encode("counter"), offerer.toBytes()],
83
- program
84
- )[0];
85
- }
86
- function settlementPda(program) {
87
- return PublicKey.findProgramAddressSync([new TextEncoder().encode("authority")], program)[0];
88
- }
89
- function registryCounterPda(program) {
90
- return PublicKey.findProgramAddressSync([new TextEncoder().encode("counter")], program)[0];
91
- }
92
- function collectionRecordPda(program, coreCollection) {
93
- return PublicKey.findProgramAddressSync(
94
- [new TextEncoder().encode("collection"), coreCollection.toBytes()],
95
- program
96
- )[0];
97
- }
98
- var MPL_CORE_PROGRAM_ID = new PublicKey("CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d");
99
-
100
- // src/chains.ts
101
- var COORDINATES = {
102
- STARKNET: {
103
- rpcUrl: "https://rpc.starknet.lava.build",
104
- marketplace721: "0x03eda9a2b6ad90845a43591bac8083ebaf677d51fdf20f503b2c01889e3131fc",
105
- marketplace721ClassHash: "0x0700d9230d07e5203e27778c0dc70f9134d2b25bf319f7cf8348dc66a6923e90",
106
- marketplace721StartBlock: 11198146,
107
- marketplace1155: "0x07c4ce1c19ea48cc11135ed22b19ff745f5aec508c3828593002e4f76fdb1b38",
108
- marketplace1155ClassHash: "0x0242f5c388da7cee2d99e2a69453c8159bf927fbec4e797a3cfdcbbcb5b68328",
109
- marketplace1155StartBlock: 11198267,
110
- collection721: "0x0225c3ae09506b8d97adc39649ca740dad5aac195b7f5f0441cc1852947acaea",
111
- collection721StartBlock: 11198496,
112
- ipNftClassHash: "0x012d3ae40ba35c7e2be0946532dac60e48932447912fdf96b674da67c029b9cc",
113
- ipCollectionClassHash: "0x022155a1a130a40e57aac4b89c07fab3f616bc351b1270fc40f756b963afe8b4",
114
- collection1155: "0x015368976d46fae5bfa1c58600f641d5aa5dbbf53ebc6b78aa3922194aad3551",
115
- collection1155FactoryClassHash: "0x04eb6b419770f13bd191f120b9fc9ee624c0613ad4490062d293ca2016b3b1d2",
116
- collection1155ClassHash: "0x06cf3f5a2322dac35e07a6064a5b8802f19fda8aa3f4726f0cb7bc05dea1bd78",
117
- collection1155StartBlock: 11199527,
118
- popFactory: "0x00b32c34b427d8f346b5843ada6a37bd3368d879fc752cd52b68a87287f60111",
119
- popCollectionClassHash: "0x077c421686f10851872561953ea16898d933364b7f8937a5d7e2b1ba0a36263f",
120
- dropFactory: "0x03587f42e29daee1b193f6cf83bf8627908ed6632d0d83fcb26225c50547d800",
121
- dropCollectionClassHash: "0x00092e72cdb63067521e803aaf7d4101c3e3ce026ae6bc045ec4228027e58282",
122
- nftComments: "0x02cdac70c94447189af0389dfea63f4d5e4154ea8a563de288a5ab1c39e37843",
123
- creatorCoinFactory: "0x50fa807b5274079fb19374673d7bab6d2dc3af7e1032ea43eb6e44bcbde4c3c",
124
- creatorCoinEkuboLauncher: "0x4f7fceb5ac10f12f9544a09580592e5bdf1b7f04f48765eecf12286d8ccb7b4",
125
- creatorCoinClassHash: "0x743e4c8a5b96bb83bbf4af04edbbb482d5ece89eed9b729a79fb7df0cd0b6b6",
126
- creatorCoinFactoryClassHash: "0x51765926b1344c9a20b8cd4b5abe7b7d47375ae97cf6804db3ea5d4b05a9b55",
127
- creatorCoinStartBlock: 10474544,
128
- ekuboCore: "0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b",
129
- ipTicketsFactory: "0x0664c2d6a4da9ee3ff053ceeba7579c01f2fedfd9d2b57b4c07af3734bd4acab",
130
- ipTicketCollectionClassHash: "0x086f59c416e365e2bee4ceff9f1dcb96198f2342d50ba4621f60b831863adb6",
131
- ipTicketsStartBlock: 11404656,
132
- ipClubRegistry: "0x00e189c619b6bb07d78973a149641c59c37eb0716f8584d7520bce12d303eede",
133
- ipClubNftClassHash: "0x02bc9b20cca21b04245e9215bf7121f4d7295b195890e449b472b573017fb889",
134
- ipClubStartBlock: 11404776,
135
- ipSponsorship: "0x044d9b9c3bb29b94685b0a3fe27a5e2dfa30a3637ab55979c718ebcd3268bc2f",
136
- ipSponsorshipStartBlock: 11405085,
137
- // Dedicated ip-erc721/MIP instance for sponsorship receipts (class hash
138
- // 0x01bd7e39c5135b32b664e34cbbb4eafbd707a0fbc3ec2ef28657f52577d277d7) —
139
- // never the genesis-mint instance.
140
- ipSponsorshipLicense: "0x06bcfc4e97758a2abf95af4bd49596efdbfd88ccd740caddc56ad0a4bd095839"
141
- }
142
- };
143
- function getCoordinates(chain) {
144
- const c = COORDINATES[chain];
145
- if (!c) throw new Error(`No coordinates configured for chain "${chain}"`);
146
- return c;
147
- }
148
-
149
- // src/solana/venue.ts
150
- var SolanaVenue = class {
151
- constructor(opts) {
152
- this.chain = "SOLANA";
153
- this.connection = opts.connection;
154
- const program = opts.programId ?? maybeCoords()?.marketplaceProgram;
155
- if (!program) throw new Error("No Solana marketplace program configured");
156
- this.program = new PublicKey(program);
157
- }
158
- async registerOrder(signer, params) {
159
- const offerer = signer.publicKey;
160
- const salt = BigInt(params.salt);
161
- const isNative = params.paymentToken === "native";
162
- const counter = await this.getCounter(offerer.toBase58());
163
- const writer = new BorshWriter().u64(salt).u8(params.side === "listing" ? 0 : 1).option(isNative ? null : new PublicKey(params.paymentToken), (mint) => writer.pubkey(mint)).u64(BigInt(params.amount)).u16(params.royaltyMaxBps).i64(BigInt(params.startTime)).i64(BigInt(params.endTime)).u64(counter);
164
- const order = orderPda(this.program, offerer, salt);
165
- const asset = new PublicKey(params.asset.contract);
166
- const instruction = new TransactionInstruction({
167
- programId: this.program,
168
- keys: [
169
- { pubkey: offerer, isSigner: true, isWritable: true },
170
- { pubkey: order, isSigner: false, isWritable: true },
171
- { pubkey: counterPda(this.program, offerer), isSigner: false, isWritable: true },
172
- { pubkey: settlementPda(this.program), isSigner: false, isWritable: false },
173
- { pubkey: asset, isSigner: false, isWritable: true },
174
- { pubkey: new PublicKey(params.asset.tokenId), isSigner: false, isWritable: true },
175
- { pubkey: MPL_CORE_PROGRAM_ID, isSigner: false, isWritable: false },
176
- { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
177
- ],
178
- data: Buffer.from(writer.build(instructionDiscriminator("register_order")))
179
- });
180
- const txHash = await this.send(signer, instruction);
181
- return { txHash, orderRef: order.toBase58() };
182
- }
183
- async fulfillOrder() {
184
- throw new Error(
185
- "Solana fulfillment requires the order's creator remaining-accounts; use buildFulfillInstruction with explicit accounts"
186
- );
187
- }
188
- async cancelOrder(signer, orderRef) {
189
- const instruction = new TransactionInstruction({
190
- programId: this.program,
191
- keys: [
192
- { pubkey: signer.publicKey, isSigner: true, isWritable: false },
193
- { pubkey: new PublicKey(orderRef), isSigner: false, isWritable: true }
194
- ],
195
- data: Buffer.from(new BorshWriter().build(instructionDiscriminator("cancel_order")))
196
- });
197
- const txHash = await this.send(signer, instruction);
198
- return { txHash };
199
- }
200
- async incrementCounter(signer) {
201
- const instruction = new TransactionInstruction({
202
- programId: this.program,
203
- keys: [
204
- { pubkey: signer.publicKey, isSigner: true, isWritable: true },
205
- { pubkey: counterPda(this.program, signer.publicKey), isSigner: false, isWritable: true },
206
- { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
207
- ],
208
- data: Buffer.from(new BorshWriter().build(instructionDiscriminator("increment_counter")))
209
- });
210
- const txHash = await this.send(signer, instruction);
211
- return { txHash };
212
- }
213
- async getOrderDetails(orderRef) {
214
- const info = await this.connection.getAccountInfo(new PublicKey(orderRef));
215
- return info?.data ?? null;
216
- }
217
- async getCounter(address) {
218
- const pda = counterPda(this.program, new PublicKey(address));
219
- const info = await this.connection.getAccountInfo(pda);
220
- if (!info || info.data.length < 16) return 0n;
221
- return new DataView(info.data.buffer, info.data.byteOffset + 8, 8).getBigUint64(0, true);
222
- }
223
- async send(signer, instruction) {
224
- const tx = new Transaction().add(instruction);
225
- tx.feePayer = signer.publicKey;
226
- tx.recentBlockhash = (await this.connection.getLatestBlockhash()).blockhash;
227
- const signed = await signer.signTransaction(tx);
228
- return this.connection.sendRawTransaction(signed.serialize());
229
- }
230
- };
231
- function maybeCoords() {
232
- try {
233
- return getCoordinates("SOLANA");
234
- } catch {
235
- return void 0;
236
- }
237
- }
238
-
239
- export { BorshWriter, MPL_CORE_PROGRAM_ID, SolanaVenue, collectionRecordPda, counterPda, eventDiscriminator, instructionDiscriminator, orderPda, registryCounterPda, settlementPda, u64le };
240
- //# sourceMappingURL=index.js.map
241
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/solana/encoding.ts","../../src/chains.ts","../../src/solana/venue.ts"],"names":["PublicKey"],"mappings":";;;;AAUO,SAAS,yBAAyB,IAAA,EAA0B;AACjE,EAAA,OAAO,MAAA,CAAO,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,CAAA,OAAA,EAAU,IAAI,CAAA,CAAE,CAAC,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA;AACtE;AAEO,SAAS,mBAAmB,IAAA,EAA0B;AAC3D,EAAA,OAAO,MAAA,CAAO,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,CAAA,MAAA,EAAS,IAAI,CAAA,CAAE,CAAC,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA;AACrE;AAGO,IAAM,cAAN,MAAkB;AAAA,EAAlB,WAAA,GAAA;AACL,IAAA,IAAA,CAAQ,SAAuB,EAAC;AAAA,EAAA;AAAA,EAEhC,GAAG,CAAA,EAAiB;AAClB,IAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,UAAA,CAAW,EAAA,CAAG,CAAC,CAAC,CAAA;AACjC,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EACA,IAAI,CA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AW,CAAA;AAC5C,IAAA,EAAA,CAAG,WAAW,MAAA,CAAO,SAAA;AACrB,IAAA,EAAA,CAAG,eAAA,GAAA,CAAmB,MAAM,IAAA,CAAK,UAAA,CAAW,oBAAmB,EAAG,SAAA;AAClE,IAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,eAAA,CAAgB,EAAE,CAAA;AAC9C,IAAA,OAAO,IAAA,CAAK,UAAA,CAAW,kBAAA,CAAmB,MAAA,CAAO,WAAW,CAAA;AAAA,EAC9D;AACF;AAEA,SAAS,WAAA,GAA6C;AACpD,EAAA,IAAI;AACF,IAAA,OAAO,eAAe,QAAQ,CAAA;AAAA,EAChC,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF","file":"index.js","sourcesContent":["import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { PublicKey } from \"@solana/web3.js\";\n\n/**\n * Anchor wire encoding for the Medialane Solana programs — discriminators,\n * a minimal borsh writer for our argument shapes, and the programs' PDAs.\n * Verified against the audited Rust (Solana-MIP-Collections,\n * Solana-Marketplace); no Anchor client dependency.\n */\n\nexport function instructionDiscriminator(name: string): Uint8Array {\n return sha256(new TextEncoder().encode(`global:${name}`)).slice(0, 8);\n}\n\nexport function eventDiscriminator(name: string): Uint8Array {\n return sha256(new TextEncoder().encode(`event:${name}`)).slice(0, 8);\n}\n\n/** Minimal borsh writer covering our programs' argument types. */\nexport class BorshWriter {\n private chunks: Uint8Array[] = [];\n\n u8(v: number): this {\n this.chunks.push(Uint8Array.of(v));\n return this;\n }\n u16(v: number): this {\n const b = new Uint8Array(2);\n new DataView(b.buffer).setUint16(0, v, true);\n this.chunks.push(b);\n return this;\n }\n u64(v: bigint): this {\n const b = new Uint8Array(8);\n new DataView(b.buffer).setBigUint64(0, v, true);\n this.chunks.push(b);\n return this;\n }\n i64(v: bigint): this {\n const b = new Uint8Array(8);\n new DataView(b.buffer).setBigInt64(0, v, true);\n this.chunks.push(b);\n return this;\n }\n string(v: string): this {\n const bytes = new TextEncoder().encode(v);\n const len = new Uint8Array(4);\n new DataView(len.buffer).setUint32(0, bytes.length, true);\n this.chunks.push(len, bytes);\n return this;\n }\n pubkey(v: PublicKey): this {\n this.chunks.push(v.toBytes());\n return this;\n }\n option<T>(v: T | null | undefined, write: (value: T) => void): this {\n if (v === null || v === undefined) {\n this.u8(0);\n } else {\n this.u8(1);\n write(v);\n }\n return this;\n }\n build(discriminator: Uint8Array): Uint8Array {\n const total = this.chunks.reduce((n, c) => n + c.length, discriminator.length);\n const out = new Uint8Array(total);\n out.set(discriminator, 0);\n let offset = discriminator.length;\n for (const chunk of this.chunks) {\n out.set(chunk, offset);\n offset += chunk.length;\n }\n return out;\n }\n}\n\nexport function u64le(v: bigint): Uint8Array {\n const b = new Uint8Array(8);\n new DataView(b.buffer).setBigUint64(0, v, true);\n return b;\n}\n\n// ─── PDAs (seeds copied from the Rust) ───────────────────────────────────────\n\nexport function orderPda(program: PublicKey, offerer: PublicKey, salt: bigint): PublicKey {\n return PublicKey.findProgramAddressSync(\n [new TextEncoder().encode(\"order\"), offerer.toBytes(), u64le(salt)],\n program,\n )[0];\n}\n\nexport function counterPda(program: PublicKey, offerer: PublicKey): PublicKey {\n return PublicKey.findProgramAddressSync(\n [new TextEncoder().encode(\"counter\"), offerer.toBytes()],\n program,\n )[0];\n}\n\nexport function settlementPda(program: PublicKey): PublicKey {\n return PublicKey.findProgramAddressSync([new TextEncoder().encode(\"authority\")], program)[0];\n}\n\nexport function registryCounterPda(program: PublicKey): PublicKey {\n return PublicKey.findProgramAddressSync([new TextEncoder().encode(\"counter\")], program)[0];\n}\n\nexport function collectionRecordPda(program: PublicKey, coreCollection: PublicKey): PublicKey {\n return PublicKey.findProgramAddressSync(\n [new TextEncoder().encode(\"collection\"), coreCollection.toBytes()],\n program,\n )[0];\n}\n\nexport const MPL_CORE_PROGRAM_ID = new PublicKey(\"CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d\");\n","// Single source of per-chain coordinates for Medialane's own services\n// (spec 2026-06-13 §3.1, Decision A). Keyed by CHAIN ALONE — Medialane is\n// mainnet-only, so there is no network axis (refines decisions.md D-9).\n\n/** Mirrors the backend Prisma `Chain` enum. */\nexport const CHAINS = [\"STARKNET\", \"ETHEREUM\", \"SOLANA\", \"BASE\", \"STELLAR\", \"BITCOIN\"] as const;\nexport type Chain = (typeof CHAINS)[number];\n\n/** Starknet coordinates of Medialane services + venues. All fields optional\n * because not every service exists on every chain. */\nexport interface StarknetCoordinates {\n rpcUrl: string;\n marketplace721?: `0x${string}`;\n marketplace721ClassHash?: `0x${string}`;\n marketplace721StartBlock?: number;\n marketplace1155?: `0x${string}`;\n marketplace1155ClassHash?: `0x${string}`;\n marketplace1155StartBlock?: number;\n collection721?: `0x${string}`;\n collection721StartBlock?: number;\n ipNftClassHash?: `0x${string}`;\n ipCollectionClassHash?: `0x${string}`;\n collection1155?: `0x${string}`;\n collection1155FactoryClassHash?: `0x${string}`;\n collection1155ClassHash?: `0x${string}`;\n collection1155StartBlock?: number;\n popFactory?: `0x${string}`;\n popCollectionClassHash?: `0x${string}`;\n dropFactory?: `0x${string}`;\n dropCollectionClassHash?: `0x${string}`;\n nftComments?: `0x${string}`;\n creatorCoinFactory?: `0x${string}`;\n creatorCoinEkuboLauncher?: `0x${string}`;\n creatorCoinClassHash?: `0x${string}`;\n creatorCoinFactoryClassHash?: `0x${string}`;\n creatorCoinStartBlock?: number;\n ekuboCore?: `0x${string}`;\n ipTicketsFactory?: `0x${string}`;\n ipTicketCollectionClassHash?: `0x${string}`;\n ipTicketsStartBlock?: number;\n ipClubRegistry?: `0x${string}`;\n ipClubNftClassHash?: `0x${string}`;\n ipClubStartBlock?: number;\n ipSponsorship?: `0x${string}`;\n ipSponsorshipStartBlock?: number;\n ipSponsorshipLicense?: `0x${string}`;\n}\n\n/** Coordinates per chain. Only STARKNET is populated today; adding a chain\n * means adding an entry here (litmus test, spec §7). */\n/** EVM coordinates — one shape for Ethereum and Base (same bytecode, two\n * chains). Populated at deploy time (federation Phase 4). */\nexport interface EvmCoordinates {\n rpcUrl: string;\n marketplace721?: `0x${string}`;\n marketplace721StartBlock?: number;\n marketplace1155?: `0x${string}`;\n marketplace1155StartBlock?: number;\n mipRegistry?: `0x${string}`;\n mipRegistryStartBlock?: number;\n mipEditionsRegistry?: `0x${string}`;\n mipEditionsRegistryStartBlock?: number;\n}\n\n/** Solana coordinates — base58 program ids. Populated at deploy time. */\nexport interface SolanaCoordinates {\n rpcUrl: string;\n mipCollectionsProgram?: string;\n marketplaceProgram?: string;\n startSlot?: number;\n}\n\n/** Stellar (Soroban) coordinates — strkey contract ids. Populated at deploy\n * time; the registry takes the collection WASM hash as a constructor arg. */\nexport interface StellarCoordinates {\n rpcUrl: string;\n mipRegistry?: string;\n marketplace?: string;\n collectionWasmHash?: string;\n startLedger?: number;\n}\n\n/** Per-chain coordinate shapes. Every chain is an equal entry — no chain is\n * privileged in core (chain-sovereignty I2/I4). */\nexport interface CoordinatesByChain {\n STARKNET?: StarknetCoordinates;\n ETHEREUM?: EvmCoordinates;\n BASE?: EvmCoordinates;\n SOLANA?: SolanaCoordinates;\n STELLAR?: StellarCoordinates;\n BITCOIN?: never;\n}\n\n/** @deprecated Renamed — use `StarknetCoordinates` (coordinates are per-chain-shaped). */\nexport type ChainCoordinates = StarknetCoordinates;\n\nconst COORDINATES: CoordinatesByChain = {\n STARKNET: {\n rpcUrl: \"https://rpc.starknet.lava.build\",\n marketplace721: \"0x03eda9a2b6ad90845a43591bac8083ebaf677d51fdf20f503b2c01889e3131fc\",\n marketplace721ClassHash: \"0x0700d9230d07e5203e27778c0dc70f9134d2b25bf319f7cf8348dc66a6923e90\",\n marketplace721StartBlock: 11198146,\n marketplace1155: \"0x07c4ce1c19ea48cc11135ed22b19ff745f5aec508c3828593002e4f76fdb1b38\",\n marketplace1155ClassHash: \"0x0242f5c388da7cee2d99e2a69453c8159bf927fbec4e797a3cfdcbbcb5b68328\",\n marketplace1155StartBlock: 11198267,\n collection721: \"0x0225c3ae09506b8d97adc39649ca740dad5aac195b7f5f0441cc1852947acaea\",\n collection721StartBlock: 11198496,\n ipNftClassHash: \"0x012d3ae40ba35c7e2be0946532dac60e48932447912fdf96b674da67c029b9cc\",\n ipCollectionClassHash: \"0x022155a1a130a40e57aac4b89c07fab3f616bc351b1270fc40f756b963afe8b4\",\n collection1155: \"0x015368976d46fae5bfa1c58600f641d5aa5dbbf53ebc6b78aa3922194aad3551\",\n collection1155FactoryClassHash: \"0x04eb6b419770f13bd191f120b9fc9ee624c0613ad4490062d293ca2016b3b1d2\",\n collection1155ClassHash: \"0x06cf3f5a2322dac35e07a6064a5b8802f19fda8aa3f4726f0cb7bc05dea1bd78\",\n collection1155StartBlock: 11199527,\n popFactory: \"0x00b32c34b427d8f346b5843ada6a37bd3368d879fc752cd52b68a87287f60111\",\n popCollectionClassHash: \"0x077c421686f10851872561953ea16898d933364b7f8937a5d7e2b1ba0a36263f\",\n dropFactory: \"0x03587f42e29daee1b193f6cf83bf8627908ed6632d0d83fcb26225c50547d800\",\n dropCollectionClassHash: \"0x00092e72cdb63067521e803aaf7d4101c3e3ce026ae6bc045ec4228027e58282\",\n nftComments: \"0x02cdac70c94447189af0389dfea63f4d5e4154ea8a563de288a5ab1c39e37843\",\n creatorCoinFactory: \"0x50fa807b5274079fb19374673d7bab6d2dc3af7e1032ea43eb6e44bcbde4c3c\",\n creatorCoinEkuboLauncher: \"0x4f7fceb5ac10f12f9544a09580592e5bdf1b7f04f48765eecf12286d8ccb7b4\",\n creatorCoinClassHash: \"0x743e4c8a5b96bb83bbf4af04edbbb482d5ece89eed9b729a79fb7df0cd0b6b6\",\n creatorCoinFactoryClassHash: \"0x51765926b1344c9a20b8cd4b5abe7b7d47375ae97cf6804db3ea5d4b05a9b55\",\n creatorCoinStartBlock: 10474544,\n ekuboCore: \"0x00000005dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b\",\n ipTicketsFactory: \"0x0664c2d6a4da9ee3ff053ceeba7579c01f2fedfd9d2b57b4c07af3734bd4acab\",\n ipTicketCollectionClassHash: \"0x086f59c416e365e2bee4ceff9f1dcb96198f2342d50ba4621f60b831863adb6\",\n ipTicketsStartBlock: 11404656,\n ipClubRegistry: \"0x00e189c619b6bb07d78973a149641c59c37eb0716f8584d7520bce12d303eede\",\n ipClubNftClassHash: \"0x02bc9b20cca21b04245e9215bf7121f4d7295b195890e449b472b573017fb889\",\n ipClubStartBlock: 11404776,\n ipSponsorship: \"0x044d9b9c3bb29b94685b0a3fe27a5e2dfa30a3637ab55979c718ebcd3268bc2f\",\n ipSponsorshipStartBlock: 11405085,\n // Dedicated ip-erc721/MIP instance for sponsorship receipts (class hash\n // 0x01bd7e39c5135b32b664e34cbbb4eafbd707a0fbc3ec2ef28657f52577d277d7) —\n // never the genesis-mint instance.\n ipSponsorshipLicense: \"0x06bcfc4e97758a2abf95af4bd49596efdbfd88ccd740caddc56ad0a4bd095839\",\n },\n};\n\nexport function getCoordinates(chain: \"STARKNET\"): StarknetCoordinates;\nexport function getCoordinates(chain: \"ETHEREUM\" | \"BASE\"): EvmCoordinates;\nexport function getCoordinates(chain: \"SOLANA\"): SolanaCoordinates;\nexport function getCoordinates(chain: \"STELLAR\"): StellarCoordinates;\nexport function getCoordinates(\n chain: Chain,\n): StarknetCoordinates | EvmCoordinates | SolanaCoordinates | StellarCoordinates;\nexport function getCoordinates(\n chain: Chain,\n): StarknetCoordinates | EvmCoordinates | SolanaCoordinates | StellarCoordinates {\n const c = COORDINATES[chain];\n if (!c) throw new Error(`No coordinates configured for chain \"${chain}\"`);\n return c;\n}\n\nexport const DEFAULT_CHAIN: Chain = \"STARKNET\";\n\n/** Typed Starknet coordinates for Starknet-only modules; throws when the\n * client is scoped to another chain. */\nexport function getStarknetCoordinates(chain: Chain): StarknetCoordinates {\n if (chain !== \"STARKNET\") {\n throw new Error(`This module is Starknet-only (client chain: \"${chain}\")`);\n }\n return getCoordinates(\"STARKNET\");\n}\n","import {\n PublicKey,\n SystemProgram,\n Transaction,\n TransactionInstruction,\n type Connection,\n} from \"@solana/web3.js\";\nimport type { Chain } from \"../chains.js\";\nimport { getCoordinates, type SolanaCoordinates } from \"../chains.js\";\nimport type {\n AdapterTxResult,\n OrderRef,\n RegisterOrderParams,\n VenueAdapter,\n} from \"../adapters/types.js\";\nimport {\n BorshWriter,\n MPL_CORE_PROGRAM_ID,\n counterPda,\n instructionDiscriminator,\n orderPda,\n settlementPda,\n} from \"./encoding.js\";\n\n/** Wallet-adapter-compatible signer. */\nexport interface SolanaSigner {\n publicKey: PublicKey;\n signTransaction(tx: Transaction): Promise<Transaction>;\n}\n\nexport interface SolanaVenueOptions {\n connection: Connection;\n /** Defaults to the chain registry's marketplace program (populated at deploy). */\n programId?: string;\n}\n\n/** The Medialane venue adapter for Solana. The canonical order id is the\n * order PDA (spec §3.2b). Native SOL is the payment when `paymentToken`\n * is the \"native\" sentinel; SPL mints otherwise (bids are SPL-only,\n * enforced by the program). */\nexport class SolanaVenue implements VenueAdapter<SolanaSigner> {\n readonly chain: Chain = \"SOLANA\";\n private readonly connection: Connection;\n private readonly program: PublicKey;\n\n constructor(opts: SolanaVenueOptions) {\n this.connection = opts.connection;\n const program = opts.programId ?? maybeCoords()?.marketplaceProgram;\n if (!program) throw new Error(\"No Solana marketplace program configured\");\n this.program = new PublicKey(program);\n }\n\n async registerOrder(\n signer: SolanaSigner,\n params: RegisterOrderParams,\n ): Promise<AdapterTxResult & { orderRef: OrderRef }> {\n const offerer = signer.publicKey;\n const salt = BigInt(params.salt);\n const isNative = params.paymentToken === \"native\";\n const counter = await this.getCounter(offerer.toBase58());\n const writer = new BorshWriter()\n .u64(salt)\n .u8(params.side === \"listing\" ? 0 : 1)\n .option(isNative ? null : new PublicKey(params.paymentToken), (mint) => writer.pubkey(mint))\n .u64(BigInt(params.amount))\n .u16(params.royaltyMaxBps)\n .i64(BigInt(params.startTime))\n .i64(BigInt(params.endTime))\n .u64(counter);\n const order = orderPda(this.program, offerer, salt);\n const asset = new PublicKey(params.asset.contract);\n const instruction = new TransactionInstruction({\n programId: this.program,\n keys: [\n { pubkey: offerer, isSigner: true, isWritable: true },\n { pubkey: order, isSigner: false, isWritable: true },\n { pubkey: counterPda(this.program, offerer), isSigner: false, isWritable: true },\n { pubkey: settlementPda(this.program), isSigner: false, isWritable: false },\n { pubkey: asset, isSigner: false, isWritable: true },\n { pubkey: new PublicKey(params.asset.tokenId), isSigner: false, isWritable: true },\n { pubkey: MPL_CORE_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n ],\n data: Buffer.from(writer.build(instructionDiscriminator(\"register_order\"))),\n });\n const txHash = await this.send(signer, instruction);\n return { txHash, orderRef: order.toBase58() };\n }\n\n async fulfillOrder(): Promise<AdapterTxResult> {\n throw new Error(\n \"Solana fulfillment requires the order's creator remaining-accounts; use buildFulfillInstruction with explicit accounts\",\n );\n }\n\n async cancelOrder(signer: SolanaSigner, orderRef: OrderRef): Promise<AdapterTxResult> {\n const instruction = new TransactionInstruction({\n programId: this.program,\n keys: [\n { pubkey: signer.publicKey, isSigner: true, isWritable: false },\n { pubkey: new PublicKey(orderRef), isSigner: false, isWritable: true },\n ],\n data: Buffer.from(new BorshWriter().build(instructionDiscriminator(\"cancel_order\"))),\n });\n const txHash = await this.send(signer, instruction);\n return { txHash };\n }\n\n async incrementCounter(signer: SolanaSigner): Promise<AdapterTxResult> {\n const instruction = new TransactionInstruction({\n programId: this.program,\n keys: [\n { pubkey: signer.publicKey, isSigner: true, isWritable: true },\n { pubkey: counterPda(this.program, signer.publicKey), isSigner: false, isWritable: true },\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n ],\n data: Buffer.from(new BorshWriter().build(instructionDiscriminator(\"increment_counter\"))),\n });\n const txHash = await this.send(signer, instruction);\n return { txHash };\n }\n\n async getOrderDetails(orderRef: OrderRef): Promise<unknown> {\n const info = await this.connection.getAccountInfo(new PublicKey(orderRef));\n return info?.data ?? null;\n }\n\n async getCounter(address: string): Promise<bigint> {\n const pda = counterPda(this.program, new PublicKey(address));\n const info = await this.connection.getAccountInfo(pda);\n if (!info || info.data.length < 16) return 0n;\n // Anchor account: 8-byte discriminator + u64 count (LE).\n return new DataView(info.data.buffer, info.data.byteOffset + 8, 8).getBigUint64(0, true);\n }\n\n private async send(signer: SolanaSigner, instruction: TransactionInstruction): Promise<string> {\n const tx = new Transaction().add(instruction);\n tx.feePayer = signer.publicKey;\n tx.recentBlockhash = (await this.connection.getLatestBlockhash()).blockhash;\n const signed = await signer.signTransaction(tx);\n return this.connection.sendRawTransaction(signed.serialize());\n }\n}\n\nfunction maybeCoords(): SolanaCoordinates | undefined {\n try {\n return getCoordinates(\"SOLANA\");\n } catch {\n return undefined;\n }\n}\n"]}