@zoralabs/coins-sdk 0.2.11 → 0.3.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/actions/createCoin.d.ts +52 -21
  3. package/dist/actions/createCoin.d.ts.map +1 -1
  4. package/dist/api/create.d.ts +8 -0
  5. package/dist/api/create.d.ts.map +1 -0
  6. package/dist/api/index.d.ts +4 -0
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/pool-config.d.ts +5 -0
  9. package/dist/api/pool-config.d.ts.map +1 -0
  10. package/dist/client/sdk.gen.d.ts +194 -1
  11. package/dist/client/sdk.gen.d.ts.map +1 -1
  12. package/dist/client/types.gen.d.ts +567 -0
  13. package/dist/client/types.gen.d.ts.map +1 -1
  14. package/dist/index.cjs +416 -461
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +2 -3
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +387 -432
  19. package/dist/index.js.map +1 -1
  20. package/dist/uploader/metadata.d.ts.map +1 -1
  21. package/dist/uploader/types.d.ts +4 -1
  22. package/dist/uploader/types.d.ts.map +1 -1
  23. package/dist/utils/rethrowDecodedRevert.d.ts +3 -0
  24. package/dist/utils/rethrowDecodedRevert.d.ts.map +1 -0
  25. package/package.json +1 -1
  26. package/src/actions/createCoin.ts +154 -112
  27. package/src/api/create.ts +24 -0
  28. package/src/api/index.ts +8 -0
  29. package/src/api/pool-config.ts +17 -0
  30. package/src/client/sdk.gen.ts +50 -0
  31. package/src/client/types.gen.ts +581 -0
  32. package/src/index.ts +4 -6
  33. package/src/uploader/metadata.ts +4 -1
  34. package/src/uploader/types.ts +4 -1
  35. package/src/utils/rethrowDecodedRevert.ts +50 -0
  36. package/dist/actions/getOnchainCoinDetails.d.ts +0 -32
  37. package/dist/actions/getOnchainCoinDetails.d.ts.map +0 -1
  38. package/dist/utils/getPrepurchaseHook.d.ts +0 -16
  39. package/dist/utils/getPrepurchaseHook.d.ts.map +0 -1
  40. package/src/actions/getOnchainCoinDetails.ts +0 -68
  41. package/src/utils/getPrepurchaseHook.ts +0 -59
package/dist/index.js CHANGED
@@ -1,26 +1,19 @@
1
1
  // src/actions/createCoin.ts
2
- import { coinFactoryABI as zoraFactoryImplABI } from "@zoralabs/protocol-deployments";
2
+ import {
3
+ coinFactoryAddress,
4
+ coinFactoryABI as zoraFactoryImplABI
5
+ } from "@zoralabs/protocol-deployments";
3
6
  import {
4
7
  parseEventLogs,
5
- zeroAddress as zeroAddress2,
6
- keccak256 as keccak2562,
7
- toBytes
8
+ isAddressEqual
8
9
  } from "viem";
9
- import { base as base6, baseSepolia as baseSepolia4 } from "viem/chains";
10
-
11
- // src/constants.ts
12
- import { coinFactoryAddress as zoraFactoryImplAddress } from "@zoralabs/protocol-deployments";
13
- import { base } from "viem/chains";
14
- var COIN_FACTORY_ADDRESS = zoraFactoryImplAddress["8453"];
15
- var USDC_WETH_POOLS_BY_CHAIN = {
16
- [base.id]: "0xd0b53D9277642d899DF5C87A3966A349A798F224"
17
- };
10
+ import { base as base3 } from "viem/chains";
18
11
 
19
12
  // src/utils/validateClientNetwork.ts
20
- import { base as base2, baseSepolia } from "viem/chains";
13
+ import { base, baseSepolia } from "viem/chains";
21
14
  var validateClientNetwork = (publicClient) => {
22
15
  const clientChainId = publicClient?.chain?.id;
23
- if (clientChainId === base2.id) {
16
+ if (clientChainId === base.id) {
24
17
  return;
25
18
  }
26
19
  if (clientChainId === baseSepolia.id) {
@@ -126,324 +119,18 @@ async function validateMetadataURIContent(metadataURI) {
126
119
  return validateMetadataJSON(metadataJson);
127
120
  }
128
121
 
129
- // src/utils/attribution.ts
130
- import { keccak256, slice, toHex } from "viem";
131
- function getAttribution() {
132
- const hash = keccak256(toHex("api-sdk.zora.engineering"));
133
- return slice(hash, 0, 4);
134
- }
135
-
136
- // src/utils/poolConfigUtils.ts
137
- import { encodeMultiCurvePoolConfig } from "@zoralabs/protocol-deployments";
138
- import { parseUnits, zeroAddress } from "viem";
139
- import { base as base3, baseSepolia as baseSepolia2 } from "viem/chains";
140
- var ZORA_DECIMALS = 18;
141
- var ZORA_ADDRESS = "0x1111111111166b7fe7bd91427724b487980afc69";
142
- var COIN_ETH_PAIR_LOWER_TICK = -25e4;
143
- var COIN_ETH_PAIR_UPPER_TICK = -195e3;
144
- var COIN_ETH_PAIR_NUM_DISCOVERY_POSITIONS = 11;
145
- var COIN_ETH_PAIR_MAX_DISCOVERY_SUPPLY_SHARE = parseUnits("0.05", 18);
146
- var COIN_ETH_PAIR_POOL_CONFIG = {
147
- [base3.id]: encodeMultiCurvePoolConfig({
148
- currency: zeroAddress,
149
- tickLower: [COIN_ETH_PAIR_LOWER_TICK],
150
- tickUpper: [COIN_ETH_PAIR_UPPER_TICK],
151
- numDiscoveryPositions: [COIN_ETH_PAIR_NUM_DISCOVERY_POSITIONS],
152
- maxDiscoverySupplyShare: [COIN_ETH_PAIR_MAX_DISCOVERY_SUPPLY_SHARE]
153
- }),
154
- [baseSepolia2.id]: encodeMultiCurvePoolConfig({
155
- currency: zeroAddress,
156
- tickLower: [COIN_ETH_PAIR_LOWER_TICK],
157
- tickUpper: [COIN_ETH_PAIR_UPPER_TICK],
158
- numDiscoveryPositions: [COIN_ETH_PAIR_NUM_DISCOVERY_POSITIONS],
159
- maxDiscoverySupplyShare: [COIN_ETH_PAIR_MAX_DISCOVERY_SUPPLY_SHARE]
160
- })
161
- };
162
- var COIN_ZORA_PAIR_LOWER_TICK = -138e3;
163
- var COIN_ZORA_PAIR_UPPER_TICK = -81e3;
164
- var COIN_ZORA_PAIR_NUM_DISCOVERY_POSITIONS = 11;
165
- var COIN_ZORA_PAIR_MAX_DISCOVERY_SUPPLY_SHARE = parseUnits(
166
- "0.05",
167
- ZORA_DECIMALS
168
- );
169
- var COIN_ZORA_PAIR_POOL_CONFIG = {
170
- [base3.id]: encodeMultiCurvePoolConfig({
171
- currency: ZORA_ADDRESS,
172
- tickLower: [COIN_ZORA_PAIR_LOWER_TICK],
173
- tickUpper: [COIN_ZORA_PAIR_UPPER_TICK],
174
- numDiscoveryPositions: [COIN_ZORA_PAIR_NUM_DISCOVERY_POSITIONS],
175
- maxDiscoverySupplyShare: [COIN_ZORA_PAIR_MAX_DISCOVERY_SUPPLY_SHARE]
176
- })
177
- };
178
-
179
- // src/utils/getPrepurchaseHook.ts
180
- import {
181
- encodeBuySupplyWithMultiHopSwapRouterHookCall,
182
- wethAddress
183
- } from "@zoralabs/protocol-deployments";
184
- import { concat, pad, toHex as toHex2 } from "viem";
185
- import { base as base4 } from "viem/chains";
186
- var BASE_UDSC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
187
- var USDC_ZORA_FEE = 3e3;
188
- var WETH_BASE_FEE = 3e3;
189
- var encodeFee = (fee) => pad(toHex2(fee), { size: 3 });
190
- var getPrepurchaseHook = async ({
191
- payoutRecipient,
192
- initialPurchase,
193
- chainId
194
- }) => {
195
- if (initialPurchase.currency !== 1 /* ETH */ && chainId !== base4.id) {
196
- throw new Error("Initial purchase currency and/or chain not supported");
197
- }
198
- const path = concat([
199
- wethAddress[base4.id],
200
- encodeFee(WETH_BASE_FEE),
201
- BASE_UDSC_ADDRESS,
202
- encodeFee(USDC_ZORA_FEE),
203
- ZORA_ADDRESS
204
- ]);
205
- return encodeBuySupplyWithMultiHopSwapRouterHookCall({
206
- ethValue: initialPurchase.amount,
207
- buyRecipient: payoutRecipient,
208
- exactInputParams: {
209
- path,
210
- amountIn: initialPurchase.amount,
211
- amountOutMinimum: initialPurchase.amountOutMinimum || 0n
212
- },
213
- chainId: base4.id
214
- });
215
- };
216
-
217
122
  // src/utils/getChainFromId.ts
218
- import { base as base5, baseSepolia as baseSepolia3 } from "viem/chains";
123
+ import { base as base2, baseSepolia as baseSepolia2 } from "viem/chains";
219
124
  function getChainFromId(chainId) {
220
- if (chainId === base5.id) {
221
- return base5;
125
+ if (chainId === base2.id) {
126
+ return base2;
222
127
  }
223
- if (chainId === baseSepolia3.id) {
224
- return baseSepolia3;
128
+ if (chainId === baseSepolia2.id) {
129
+ return baseSepolia2;
225
130
  }
226
131
  throw new Error(`Chain ID ${chainId} not supported`);
227
132
  }
228
133
 
229
- // src/actions/createCoin.ts
230
- var DeployCurrency = /* @__PURE__ */ ((DeployCurrency2) => {
231
- DeployCurrency2[DeployCurrency2["ZORA"] = 1] = "ZORA";
232
- DeployCurrency2[DeployCurrency2["ETH"] = 2] = "ETH";
233
- return DeployCurrency2;
234
- })(DeployCurrency || {});
235
- var InitialPurchaseCurrency = /* @__PURE__ */ ((InitialPurchaseCurrency2) => {
236
- InitialPurchaseCurrency2[InitialPurchaseCurrency2["ETH"] = 1] = "ETH";
237
- return InitialPurchaseCurrency2;
238
- })(InitialPurchaseCurrency || {});
239
- function getPoolConfig(currency, chainId) {
240
- if (currency === 1 /* ZORA */ && chainId == baseSepolia4.id) {
241
- throw new Error("ZORA is not supported on Base Sepolia");
242
- }
243
- switch (currency) {
244
- case 1 /* ZORA */:
245
- return COIN_ZORA_PAIR_POOL_CONFIG[chainId];
246
- case 2 /* ETH */:
247
- return COIN_ETH_PAIR_POOL_CONFIG[chainId];
248
- default:
249
- throw new Error("Invalid currency");
250
- }
251
- }
252
- async function createCoinCall({
253
- name,
254
- symbol,
255
- uri,
256
- owners,
257
- payoutRecipient,
258
- currency,
259
- chainId = base6.id,
260
- platformReferrer = "0x0000000000000000000000000000000000000000",
261
- initialPurchase
262
- }) {
263
- if (!owners) {
264
- owners = [payoutRecipient];
265
- }
266
- if (!currency) {
267
- currency = chainId !== base6.id ? 2 /* ETH */ : 1 /* ZORA */;
268
- }
269
- const poolConfig = getPoolConfig(currency, chainId);
270
- await validateMetadataURIContent(uri);
271
- let deployHook = {
272
- hook: zeroAddress2,
273
- hookData: "0x",
274
- value: 0n
275
- };
276
- if (initialPurchase) {
277
- deployHook = await getPrepurchaseHook({
278
- initialPurchase,
279
- payoutRecipient,
280
- chainId
281
- });
282
- }
283
- return {
284
- abi: zoraFactoryImplABI,
285
- functionName: "deploy",
286
- address: COIN_FACTORY_ADDRESS,
287
- args: [
288
- payoutRecipient,
289
- owners,
290
- uri,
291
- name,
292
- symbol,
293
- poolConfig,
294
- platformReferrer,
295
- deployHook.hook,
296
- deployHook.hookData,
297
- keccak2562(toBytes(Math.random().toString()))
298
- // coinSalt
299
- ],
300
- value: deployHook.value,
301
- dataSuffix: getAttribution()
302
- };
303
- }
304
- function getCoinCreateFromLogs(receipt) {
305
- const eventLogs = parseEventLogs({
306
- abi: zoraFactoryImplABI,
307
- logs: receipt.logs
308
- });
309
- return eventLogs.find((log) => log.eventName === "CoinCreatedV4")?.args;
310
- }
311
- async function createCoin(call, walletClient, publicClient, options) {
312
- validateClientNetwork(publicClient);
313
- const createCoinRequest = await createCoinCall(call);
314
- const { request } = await publicClient.simulateContract({
315
- ...createCoinRequest,
316
- account: options?.account ?? walletClient.account
317
- });
318
- if (request.gas) {
319
- request.gas = request.gas * BigInt(options?.gasMultiplier ?? 100) / 100n;
320
- }
321
- const hash = await walletClient.writeContract(request);
322
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
323
- const deployment = getCoinCreateFromLogs(receipt);
324
- return {
325
- hash,
326
- receipt,
327
- address: deployment?.coin,
328
- deployment,
329
- chain: getChainFromId(publicClient.chain.id)
330
- };
331
- }
332
-
333
- // src/actions/getOnchainCoinDetails.ts
334
- import { coinABI } from "@zoralabs/protocol-deployments";
335
- import { zeroAddress as zeroAddress3 } from "viem";
336
- async function getOnchainCoinDetails({
337
- coin,
338
- user = zeroAddress3,
339
- publicClient
340
- }) {
341
- validateClientNetwork(publicClient);
342
- const [balance, owners, payoutRecipient] = await publicClient.multicall({
343
- contracts: [
344
- {
345
- address: coin,
346
- abi: coinABI,
347
- functionName: "balanceOf",
348
- args: [user]
349
- },
350
- {
351
- address: coin,
352
- abi: coinABI,
353
- functionName: "owners"
354
- },
355
- {
356
- address: coin,
357
- abi: coinABI,
358
- functionName: "payoutRecipient"
359
- }
360
- ],
361
- allowFailure: false
362
- });
363
- return {
364
- balance,
365
- owners,
366
- payoutRecipient
367
- };
368
- }
369
-
370
- // src/actions/updateCoinURI.ts
371
- import { coinABI as coinABI2 } from "@zoralabs/protocol-deployments";
372
- import {
373
- parseEventLogs as parseEventLogs2
374
- } from "viem";
375
- function updateCoinURICall({
376
- newURI,
377
- coin
378
- }) {
379
- if (!newURI.startsWith("ipfs://")) {
380
- throw new Error("URI needs to be an ipfs:// prefix uri");
381
- }
382
- return {
383
- abi: coinABI2,
384
- address: coin,
385
- functionName: "setContractURI",
386
- args: [newURI],
387
- dataSuffix: getAttribution()
388
- };
389
- }
390
- async function updateCoinURI(args, walletClient, publicClient) {
391
- validateClientNetwork(publicClient);
392
- const call = updateCoinURICall(args);
393
- const { request } = await publicClient.simulateContract({
394
- ...call,
395
- account: walletClient.account
396
- });
397
- const hash = await walletClient.writeContract(request);
398
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
399
- const eventLogs = parseEventLogs2({ abi: coinABI2, logs: receipt.logs });
400
- const uriUpdated = eventLogs.find(
401
- (log) => log.eventName === "ContractURIUpdated"
402
- );
403
- return { hash, receipt, uriUpdated };
404
- }
405
-
406
- // src/actions/updatePayoutRecipient.ts
407
- import { coinABI as coinABI3 } from "@zoralabs/protocol-deployments";
408
- import {
409
- parseEventLogs as parseEventLogs3
410
- } from "viem";
411
- function updatePayoutRecipientCall({
412
- newPayoutRecipient,
413
- coin
414
- }) {
415
- return {
416
- abi: coinABI3,
417
- address: coin,
418
- functionName: "setPayoutRecipient",
419
- args: [newPayoutRecipient],
420
- dataSuffix: getAttribution()
421
- };
422
- }
423
- async function updatePayoutRecipient(args, walletClient, publicClient) {
424
- validateClientNetwork(publicClient);
425
- const call = updatePayoutRecipientCall(args);
426
- const { request } = await publicClient.simulateContract({
427
- ...call,
428
- account: walletClient.account
429
- });
430
- const hash = await walletClient.writeContract(request);
431
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
432
- const eventLogs = parseEventLogs3({ abi: coinABI3, logs: receipt.logs });
433
- const payoutRecipientUpdated = eventLogs.find(
434
- (log) => log.eventName === "CoinPayoutRecipientUpdated"
435
- );
436
- return { hash, receipt, payoutRecipientUpdated };
437
- }
438
-
439
- // src/actions/tradeCoin.ts
440
- import { permit2ABI, permit2Address } from "@zoralabs/protocol-deployments";
441
- import {
442
- erc20Abi,
443
- maxUint256
444
- } from "viem";
445
- import { base as base7 } from "viem/chains";
446
-
447
134
  // src/client/client.gen.ts
448
135
  import {
449
136
  createClient,
@@ -596,8 +283,369 @@ var postQuote = (options) => {
596
283
  }
597
284
  });
598
285
  };
286
+ var postCreateContent = (options) => {
287
+ return (options?.client ?? client).post({
288
+ security: [
289
+ {
290
+ name: "api-key",
291
+ type: "apiKey"
292
+ }
293
+ ],
294
+ url: "/create/content",
295
+ ...options,
296
+ headers: {
297
+ "Content-Type": "application/json",
298
+ ...options?.headers
299
+ }
300
+ });
301
+ };
302
+
303
+ // src/api/api-key.ts
304
+ var apiKey;
305
+ function setApiKey(key) {
306
+ apiKey = key;
307
+ }
308
+ function getApiKey() {
309
+ return apiKey;
310
+ }
311
+ function getApiKeyMeta() {
312
+ if (!apiKey) {
313
+ return {};
314
+ }
315
+ return {
316
+ headers: {
317
+ "api-key": apiKey
318
+ }
319
+ };
320
+ }
321
+
322
+ // src/api/explore.ts
323
+ var createExploreQuery = (query, listType, options) => getExplore({
324
+ ...options,
325
+ query: { ...query, listType },
326
+ ...getApiKeyMeta()
327
+ });
328
+ var getCoinsTopGainers = (query = {}, options) => createExploreQuery(query, "TOP_GAINERS", options);
329
+ var getCoinsTopVolume24h = (query = {}, options) => createExploreQuery(query, "TOP_VOLUME_24H", options);
330
+ var getCoinsMostValuable = (query = {}, options) => createExploreQuery(query, "MOST_VALUABLE", options);
331
+ var getCoinsNew = (query = {}, options) => createExploreQuery(query, "NEW", options);
332
+ var getCoinsLastTraded = (query = {}, options) => createExploreQuery(query, "LAST_TRADED", options);
333
+ var getCoinsLastTradedUnique = (query = {}, options) => createExploreQuery(query, "LAST_TRADED_UNIQUE", options);
334
+ var getCreatorCoins = (query = {}, options) => createExploreQuery(query, "NEW_CREATORS", options);
335
+ var getMostValuableCreatorCoins = (query = {}, options) => createExploreQuery(query, "MOST_VALUABLE_CREATORS", options);
336
+
337
+ // src/api/queries.ts
338
+ var getCoin2 = async (query, options) => {
339
+ return await getCoin({
340
+ ...options,
341
+ query,
342
+ ...getApiKeyMeta()
343
+ });
344
+ };
345
+ var getCoins2 = async (query, options) => {
346
+ return await getCoins({
347
+ query: {
348
+ coins: query.coins.map((coinData) => JSON.stringify(coinData))
349
+ },
350
+ ...getApiKeyMeta(),
351
+ ...options
352
+ });
353
+ };
354
+ var getCoinHolders2 = async (query, options) => {
355
+ return await getCoinHolders({
356
+ query,
357
+ ...getApiKeyMeta(),
358
+ ...options
359
+ });
360
+ };
361
+ var getCoinSwaps2 = async (query, options) => {
362
+ return await getCoinSwaps({
363
+ query,
364
+ ...getApiKeyMeta(),
365
+ ...options
366
+ });
367
+ };
368
+ var getCoinComments2 = async (query, options) => {
369
+ return await getCoinComments({
370
+ query,
371
+ ...getApiKeyMeta(),
372
+ ...options
373
+ });
374
+ };
375
+ var getProfile2 = async (query, options) => {
376
+ return await getProfile({
377
+ query,
378
+ ...getApiKeyMeta(),
379
+ ...options
380
+ });
381
+ };
382
+ var getProfileCoins2 = async (query, options) => {
383
+ return await getProfileCoins({
384
+ query,
385
+ ...getApiKeyMeta(),
386
+ ...options
387
+ });
388
+ };
389
+ var getProfileBalances2 = async (query, options) => {
390
+ return await getProfileBalances({
391
+ query,
392
+ ...getApiKeyMeta(),
393
+ ...options
394
+ });
395
+ };
396
+
397
+ // src/api/create.ts
398
+ var postCreateContent2 = async (body, options) => {
399
+ return await postCreateContent({
400
+ ...options,
401
+ body,
402
+ ...getApiKeyMeta()
403
+ });
404
+ };
405
+
406
+ // src/utils/rethrowDecodedRevert.ts
407
+ import {
408
+ BaseError,
409
+ ContractFunctionRevertedError,
410
+ decodeErrorResult
411
+ } from "viem";
412
+ function rethrowDecodedRevert(err, abi) {
413
+ if (err instanceof BaseError) {
414
+ const revertError = err.walk(
415
+ (e) => e instanceof ContractFunctionRevertedError
416
+ );
417
+ if (revertError instanceof ContractFunctionRevertedError) {
418
+ try {
419
+ const revertData = typeof revertError.data === "object" && revertError.data !== null && "data" in revertError.data ? revertError.data.data : revertError.data;
420
+ const decoded = decodeErrorResult({
421
+ abi,
422
+ data: revertData
423
+ });
424
+ const name = decoded.errorName;
425
+ const args = decoded.args;
426
+ const message = Array.isArray(args) && args.length > 0 ? `${name}(${args.map((a) => String(a)).join(", ")})` : name;
427
+ throw new Error(`Create coin transaction reverted: ${message}`);
428
+ } catch {
429
+ const errorName = revertError.data?.errorName;
430
+ if (errorName) {
431
+ const args = revertError.data?.args;
432
+ const message = Array.isArray(args) && args.length > 0 ? `${errorName}(${args.map((a) => String(a)).join(", ")})` : errorName;
433
+ throw new Error(`Create coin transaction reverted: ${message}`);
434
+ }
435
+ }
436
+ }
437
+ }
438
+ throw err;
439
+ }
440
+
441
+ // src/actions/createCoin.ts
442
+ var STARTING_MARKET_CAPS = {
443
+ LOW: "LOW",
444
+ HIGH: "HIGH"
445
+ };
446
+ var CONTENT_COIN_CURRENCIES = {
447
+ CREATOR_COIN: "CREATOR_COIN",
448
+ ZORA: "ZORA",
449
+ ETH: "ETH",
450
+ CREATOR_COIN_OR_ZORA: "CREATOR_COIN_OR_ZORA"
451
+ };
452
+ var CreateConstants = {
453
+ StartingMarketCaps: STARTING_MARKET_CAPS,
454
+ ContentCoinCurrencies: CONTENT_COIN_CURRENCIES
455
+ };
456
+ async function createCoinCall({
457
+ creator,
458
+ name,
459
+ symbol,
460
+ metadata,
461
+ currency,
462
+ chainId = base3.id,
463
+ payoutRecipientOverride,
464
+ additionalOwners,
465
+ platformReferrer,
466
+ skipMetadataValidation = false
467
+ }) {
468
+ if (!skipMetadataValidation) {
469
+ await validateMetadataURIContent(metadata.uri);
470
+ }
471
+ const createContentRequest = await postCreateContent2({
472
+ currency,
473
+ chainId,
474
+ metadata,
475
+ creator,
476
+ name,
477
+ symbol,
478
+ platformReferrer,
479
+ additionalOwners,
480
+ payoutRecipientOverride
481
+ });
482
+ if (!createContentRequest.data?.calls) {
483
+ throw new Error("Failed to create content calldata");
484
+ }
485
+ return createContentRequest.data.calls.map((data) => ({
486
+ to: data.to,
487
+ data: data.data,
488
+ value: BigInt(data.value)
489
+ }));
490
+ }
491
+ function getCoinCreateFromLogs(receipt) {
492
+ const eventLogs = parseEventLogs({
493
+ abi: zoraFactoryImplABI,
494
+ logs: receipt.logs
495
+ });
496
+ return eventLogs.find((log) => log.eventName === "CoinCreatedV4")?.args;
497
+ }
498
+ async function createCoin({
499
+ call,
500
+ walletClient,
501
+ publicClient,
502
+ options
503
+ }) {
504
+ validateClientNetwork(publicClient);
505
+ const callRequest = await createCoinCall(call);
506
+ if (callRequest.length !== 1) {
507
+ throw new Error("Only one call is supported for this SDK version");
508
+ }
509
+ const createContentCall = callRequest[0];
510
+ if (!createContentCall) {
511
+ throw new Error("Failed to load create content calldata from API");
512
+ }
513
+ const coinFactoryAddressForChain = coinFactoryAddress[call.chainId];
514
+ if (!isAddressEqual(createContentCall.to, coinFactoryAddressForChain)) {
515
+ throw new Error("Creator coin is not supported for this SDK version");
516
+ }
517
+ if (createContentCall.value !== 0n) {
518
+ throw new Error(
519
+ "Creator coin and purchase is not supported for this SDK version."
520
+ );
521
+ }
522
+ const selectedAccount = (typeof options?.account === "string" ? void 0 : options?.account) ?? walletClient.account;
523
+ if (!selectedAccount) {
524
+ throw new Error("Account is required");
525
+ }
526
+ const viemCall = {
527
+ ...createContentCall,
528
+ account: selectedAccount
529
+ };
530
+ if (!options?.skipValidateTransaction) {
531
+ try {
532
+ await publicClient.call(viemCall);
533
+ } catch (err) {
534
+ rethrowDecodedRevert(err, zoraFactoryImplABI);
535
+ }
536
+ }
537
+ const gasEstimate = options?.skipValidateTransaction ? 10000000n : await publicClient.estimateGas(viemCall);
538
+ const gasPrice = await publicClient.getGasPrice();
539
+ const hash = await (async () => {
540
+ try {
541
+ return await walletClient.sendTransaction({
542
+ ...viemCall,
543
+ gasPrice,
544
+ gas: gasEstimate,
545
+ chain: publicClient.chain
546
+ });
547
+ } catch (err) {
548
+ rethrowDecodedRevert(err, zoraFactoryImplABI);
549
+ }
550
+ })();
551
+ const receipt = await publicClient.waitForTransactionReceipt({
552
+ hash
553
+ });
554
+ const deployment = getCoinCreateFromLogs(receipt);
555
+ return {
556
+ hash,
557
+ receipt,
558
+ address: deployment?.coin,
559
+ deployment,
560
+ chain: getChainFromId(publicClient.chain.id)
561
+ };
562
+ }
563
+
564
+ // src/actions/updateCoinURI.ts
565
+ import { coinABI } from "@zoralabs/protocol-deployments";
566
+ import {
567
+ parseEventLogs as parseEventLogs2
568
+ } from "viem";
569
+
570
+ // src/utils/attribution.ts
571
+ import { keccak256, slice, toHex } from "viem";
572
+ function getAttribution() {
573
+ const hash = keccak256(toHex("api-sdk.zora.engineering"));
574
+ return slice(hash, 0, 4);
575
+ }
576
+
577
+ // src/actions/updateCoinURI.ts
578
+ function updateCoinURICall({
579
+ newURI,
580
+ coin
581
+ }) {
582
+ if (!newURI.startsWith("ipfs://")) {
583
+ throw new Error("URI needs to be an ipfs:// prefix uri");
584
+ }
585
+ return {
586
+ abi: coinABI,
587
+ address: coin,
588
+ functionName: "setContractURI",
589
+ args: [newURI],
590
+ dataSuffix: getAttribution()
591
+ };
592
+ }
593
+ async function updateCoinURI(args, walletClient, publicClient) {
594
+ validateClientNetwork(publicClient);
595
+ const call = updateCoinURICall(args);
596
+ const { request } = await publicClient.simulateContract({
597
+ ...call,
598
+ account: walletClient.account
599
+ });
600
+ const hash = await walletClient.writeContract(request);
601
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
602
+ const eventLogs = parseEventLogs2({ abi: coinABI, logs: receipt.logs });
603
+ const uriUpdated = eventLogs.find(
604
+ (log) => log.eventName === "ContractURIUpdated"
605
+ );
606
+ return { hash, receipt, uriUpdated };
607
+ }
608
+
609
+ // src/actions/updatePayoutRecipient.ts
610
+ import { coinABI as coinABI2 } from "@zoralabs/protocol-deployments";
611
+ import {
612
+ parseEventLogs as parseEventLogs3
613
+ } from "viem";
614
+ function updatePayoutRecipientCall({
615
+ newPayoutRecipient,
616
+ coin
617
+ }) {
618
+ return {
619
+ abi: coinABI2,
620
+ address: coin,
621
+ functionName: "setPayoutRecipient",
622
+ args: [newPayoutRecipient],
623
+ dataSuffix: getAttribution()
624
+ };
625
+ }
626
+ async function updatePayoutRecipient(args, walletClient, publicClient) {
627
+ validateClientNetwork(publicClient);
628
+ const call = updatePayoutRecipientCall(args);
629
+ const { request } = await publicClient.simulateContract({
630
+ ...call,
631
+ account: walletClient.account
632
+ });
633
+ const hash = await walletClient.writeContract(request);
634
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
635
+ const eventLogs = parseEventLogs3({ abi: coinABI2, logs: receipt.logs });
636
+ const payoutRecipientUpdated = eventLogs.find(
637
+ (log) => log.eventName === "CoinPayoutRecipientUpdated"
638
+ );
639
+ return { hash, receipt, payoutRecipientUpdated };
640
+ }
599
641
 
600
642
  // src/actions/tradeCoin.ts
643
+ import { permit2ABI, permit2Address } from "@zoralabs/protocol-deployments";
644
+ import {
645
+ erc20Abi,
646
+ maxUint256
647
+ } from "viem";
648
+ import { base as base4 } from "viem/chains";
601
649
  function convertBigIntToString(permit) {
602
650
  return {
603
651
  ...permit,
@@ -643,7 +691,7 @@ async function tradeCoin({
643
691
  for (const permit of quote.permits) {
644
692
  const [, , nonce] = await publicClient.readContract({
645
693
  abi: permit2ABI,
646
- address: permit2Address[base7.id],
694
+ address: permit2Address[base4.id],
647
695
  functionName: "allowance",
648
696
  args: [
649
697
  permit.permit.details.token,
@@ -658,7 +706,7 @@ async function tradeCoin({
658
706
  functionName: "allowance",
659
707
  args: [
660
708
  typeof account === "string" ? account : account.address,
661
- permit2Address[base7.id]
709
+ permit2Address[base4.id]
662
710
  ]
663
711
  });
664
712
  if (allowance < BigInt(permit.permit.details.amount)) {
@@ -666,8 +714,8 @@ async function tradeCoin({
666
714
  abi: erc20Abi,
667
715
  address: permitToken,
668
716
  functionName: "approve",
669
- chain: base7,
670
- args: [permit2Address[base7.id], maxUint256],
717
+ chain: base4,
718
+ args: [permit2Address[base4.id], maxUint256],
671
719
  account
672
720
  });
673
721
  await publicClient.waitForTransactionReceipt({
@@ -687,8 +735,8 @@ async function tradeCoin({
687
735
  const signature = await walletClient.signTypedData({
688
736
  domain: {
689
737
  name: "Permit2",
690
- chainId: base7.id,
691
- verifyingContract: permit2Address[base7.id]
738
+ chainId: base4.id,
739
+ verifyingContract: permit2Address[base4.id]
692
740
  },
693
741
  primaryType: "PermitSingle",
694
742
  types: PERMIT_SINGLE_TYPES,
@@ -709,7 +757,7 @@ async function tradeCoin({
709
757
  to: newQuote.call.target,
710
758
  data: newQuote.call.data,
711
759
  value: BigInt(newQuote.call.value),
712
- chain: base7,
760
+ chain: base4,
713
761
  account
714
762
  };
715
763
  if (validateTransaction) {
@@ -740,7 +788,7 @@ async function createTradeCall(tradeParameters) {
740
788
  tokenOut: tradeParameters.buy,
741
789
  amountIn: tradeParameters.amountIn.toString(),
742
790
  slippage: tradeParameters.slippage,
743
- chainId: base7.id,
791
+ chainId: base4.id,
744
792
  sender: tradeParameters.sender,
745
793
  recipient: tradeParameters.recipient || tradeParameters.sender,
746
794
  signatures: tradeParameters.signatures
@@ -753,100 +801,6 @@ async function createTradeCall(tradeParameters) {
753
801
  return quote.data;
754
802
  }
755
803
 
756
- // src/api/api-key.ts
757
- var apiKey;
758
- function setApiKey(key) {
759
- apiKey = key;
760
- }
761
- function getApiKey() {
762
- return apiKey;
763
- }
764
- function getApiKeyMeta() {
765
- if (!apiKey) {
766
- return {};
767
- }
768
- return {
769
- headers: {
770
- "api-key": apiKey
771
- }
772
- };
773
- }
774
-
775
- // src/api/queries.ts
776
- var getCoin2 = async (query, options) => {
777
- return await getCoin({
778
- ...options,
779
- query,
780
- ...getApiKeyMeta()
781
- });
782
- };
783
- var getCoins2 = async (query, options) => {
784
- return await getCoins({
785
- query: {
786
- coins: query.coins.map((coinData) => JSON.stringify(coinData))
787
- },
788
- ...getApiKeyMeta(),
789
- ...options
790
- });
791
- };
792
- var getCoinHolders2 = async (query, options) => {
793
- return await getCoinHolders({
794
- query,
795
- ...getApiKeyMeta(),
796
- ...options
797
- });
798
- };
799
- var getCoinSwaps2 = async (query, options) => {
800
- return await getCoinSwaps({
801
- query,
802
- ...getApiKeyMeta(),
803
- ...options
804
- });
805
- };
806
- var getCoinComments2 = async (query, options) => {
807
- return await getCoinComments({
808
- query,
809
- ...getApiKeyMeta(),
810
- ...options
811
- });
812
- };
813
- var getProfile2 = async (query, options) => {
814
- return await getProfile({
815
- query,
816
- ...getApiKeyMeta(),
817
- ...options
818
- });
819
- };
820
- var getProfileCoins2 = async (query, options) => {
821
- return await getProfileCoins({
822
- query,
823
- ...getApiKeyMeta(),
824
- ...options
825
- });
826
- };
827
- var getProfileBalances2 = async (query, options) => {
828
- return await getProfileBalances({
829
- query,
830
- ...getApiKeyMeta(),
831
- ...options
832
- });
833
- };
834
-
835
- // src/api/explore.ts
836
- var createExploreQuery = (query, listType, options) => getExplore({
837
- ...options,
838
- query: { ...query, listType },
839
- ...getApiKeyMeta()
840
- });
841
- var getCoinsTopGainers = (query = {}, options) => createExploreQuery(query, "TOP_GAINERS", options);
842
- var getCoinsTopVolume24h = (query = {}, options) => createExploreQuery(query, "TOP_VOLUME_24H", options);
843
- var getCoinsMostValuable = (query = {}, options) => createExploreQuery(query, "MOST_VALUABLE", options);
844
- var getCoinsNew = (query = {}, options) => createExploreQuery(query, "NEW", options);
845
- var getCoinsLastTraded = (query = {}, options) => createExploreQuery(query, "LAST_TRADED", options);
846
- var getCoinsLastTradedUnique = (query = {}, options) => createExploreQuery(query, "LAST_TRADED_UNIQUE", options);
847
- var getCreatorCoins = (query = {}, options) => createExploreQuery(query, "NEW_CREATORS", options);
848
- var getMostValuableCreatorCoins = (query = {}, options) => createExploreQuery(query, "MOST_VALUABLE_CREATORS", options);
849
-
850
804
  // src/uploader/metadata.ts
851
805
  function validateImageMimeType(mimeType) {
852
806
  if (![
@@ -991,7 +945,10 @@ var CoinMetadataBuilder = class {
991
945
  createMetadataParameters: {
992
946
  name: this.name,
993
947
  symbol: this.symbol,
994
- uri: uploadResult.url
948
+ metadata: {
949
+ type: "RAW_URI",
950
+ uri: uploadResult.url
951
+ }
995
952
  },
996
953
  metadata
997
954
  };
@@ -1064,8 +1021,7 @@ function createZoraUploaderForCreator(creatorAddress) {
1064
1021
  }
1065
1022
  export {
1066
1023
  CoinMetadataBuilder,
1067
- DeployCurrency,
1068
- InitialPurchaseCurrency,
1024
+ CreateConstants,
1069
1025
  ZoraUploader,
1070
1026
  cleanAndValidateMetadataURI,
1071
1027
  createCoin,
@@ -1087,7 +1043,6 @@ export {
1087
1043
  getCoinsTopVolume24h,
1088
1044
  getCreatorCoins,
1089
1045
  getMostValuableCreatorCoins,
1090
- getOnchainCoinDetails,
1091
1046
  getProfile2 as getProfile,
1092
1047
  getProfileBalances2 as getProfileBalances,
1093
1048
  getProfileCoins2 as getProfileCoins,