@zoralabs/coins-sdk 0.2.11 → 0.3.1

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 (48) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/actions/createCoin.d.ts +52 -21
  3. package/dist/actions/createCoin.d.ts.map +1 -1
  4. package/dist/actions/updateCoinURI.d.ts +2 -2
  5. package/dist/actions/updateCoinURI.d.ts.map +1 -1
  6. package/dist/actions/updatePayoutRecipient.d.ts +2 -2
  7. package/dist/actions/updatePayoutRecipient.d.ts.map +1 -1
  8. package/dist/api/create.d.ts +8 -0
  9. package/dist/api/create.d.ts.map +1 -0
  10. package/dist/api/index.d.ts +4 -0
  11. package/dist/api/index.d.ts.map +1 -1
  12. package/dist/api/pool-config.d.ts +5 -0
  13. package/dist/api/pool-config.d.ts.map +1 -0
  14. package/dist/client/sdk.gen.d.ts +194 -1
  15. package/dist/client/sdk.gen.d.ts.map +1 -1
  16. package/dist/client/types.gen.d.ts +567 -0
  17. package/dist/client/types.gen.d.ts.map +1 -1
  18. package/dist/index.cjs +423 -464
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +2 -3
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +393 -434
  23. package/dist/index.js.map +1 -1
  24. package/dist/uploader/metadata.d.ts.map +1 -1
  25. package/dist/uploader/types.d.ts +4 -1
  26. package/dist/uploader/types.d.ts.map +1 -1
  27. package/dist/utils/rethrowDecodedRevert.d.ts +3 -0
  28. package/dist/utils/rethrowDecodedRevert.d.ts.map +1 -0
  29. package/package.json +2 -1
  30. package/src/actions/createCoin.ts +158 -111
  31. package/src/actions/tradeCoin.ts +2 -2
  32. package/src/actions/updateCoinURI.ts +3 -1
  33. package/src/actions/updatePayoutRecipient.ts +3 -1
  34. package/src/api/create.ts +24 -0
  35. package/src/api/index.ts +8 -0
  36. package/src/api/pool-config.ts +17 -0
  37. package/src/client/sdk.gen.ts +50 -0
  38. package/src/client/types.gen.ts +581 -0
  39. package/src/index.ts +4 -6
  40. package/src/uploader/metadata.ts +4 -1
  41. package/src/uploader/types.ts +4 -1
  42. package/src/utils/rethrowDecodedRevert.ts +50 -0
  43. package/dist/actions/getOnchainCoinDetails.d.ts +0 -32
  44. package/dist/actions/getOnchainCoinDetails.d.ts.map +0 -1
  45. package/dist/utils/getPrepurchaseHook.d.ts +0 -16
  46. package/dist/utils/getPrepurchaseHook.d.ts.map +0 -1
  47. package/src/actions/getOnchainCoinDetails.ts +0 -68
  48. 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,373 @@ 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 chainId = call.chainId ?? publicClient.chain.id;
506
+ const callRequest = await createCoinCall({
507
+ ...call,
508
+ chainId
509
+ });
510
+ if (callRequest.length !== 1) {
511
+ throw new Error("Only one call is supported for this SDK version");
512
+ }
513
+ const createContentCall = callRequest[0];
514
+ if (!createContentCall) {
515
+ throw new Error("Failed to load create content calldata from API");
516
+ }
517
+ const coinFactoryAddressForChain = coinFactoryAddress[call.chainId];
518
+ if (!isAddressEqual(createContentCall.to, coinFactoryAddressForChain)) {
519
+ throw new Error("Creator coin is not supported for this SDK version");
520
+ }
521
+ if (createContentCall.value !== 0n) {
522
+ throw new Error(
523
+ "Creator coin and purchase is not supported for this SDK version."
524
+ );
525
+ }
526
+ const selectedAccount = (typeof options?.account === "string" ? void 0 : options?.account) ?? walletClient.account;
527
+ if (!selectedAccount) {
528
+ throw new Error("Account is required");
529
+ }
530
+ const viemCall = {
531
+ ...createContentCall,
532
+ account: selectedAccount
533
+ };
534
+ if (!options?.skipValidateTransaction) {
535
+ try {
536
+ await publicClient.call(viemCall);
537
+ } catch (err) {
538
+ rethrowDecodedRevert(err, zoraFactoryImplABI);
539
+ }
540
+ }
541
+ const gasEstimate = options?.skipValidateTransaction ? 10000000n : await publicClient.estimateGas(viemCall);
542
+ const gasPrice = await publicClient.getGasPrice();
543
+ const hash = await (async () => {
544
+ try {
545
+ return await walletClient.sendTransaction({
546
+ ...viemCall,
547
+ gasPrice,
548
+ gas: gasEstimate,
549
+ chain: publicClient.chain
550
+ });
551
+ } catch (err) {
552
+ rethrowDecodedRevert(err, zoraFactoryImplABI);
553
+ }
554
+ })();
555
+ const receipt = await publicClient.waitForTransactionReceipt({
556
+ hash
557
+ });
558
+ const deployment = getCoinCreateFromLogs(receipt);
559
+ return {
560
+ hash,
561
+ receipt,
562
+ address: deployment?.coin,
563
+ deployment,
564
+ chain: getChainFromId(publicClient.chain.id)
565
+ };
566
+ }
567
+
568
+ // src/actions/updateCoinURI.ts
569
+ import { coinABI } from "@zoralabs/protocol-deployments";
570
+ import {
571
+ parseEventLogs as parseEventLogs2
572
+ } from "viem";
573
+
574
+ // src/utils/attribution.ts
575
+ import { keccak256, slice, toHex } from "viem";
576
+ function getAttribution() {
577
+ const hash = keccak256(toHex("api-sdk.zora.engineering"));
578
+ return slice(hash, 0, 4);
579
+ }
580
+
581
+ // src/actions/updateCoinURI.ts
582
+ function updateCoinURICall({
583
+ newURI,
584
+ coin
585
+ }) {
586
+ if (!newURI.startsWith("ipfs://")) {
587
+ throw new Error("URI needs to be an ipfs:// prefix uri");
588
+ }
589
+ return {
590
+ abi: coinABI,
591
+ address: coin,
592
+ functionName: "setContractURI",
593
+ args: [newURI],
594
+ dataSuffix: getAttribution()
595
+ };
596
+ }
597
+ async function updateCoinURI(args, walletClient, publicClient, account) {
598
+ validateClientNetwork(publicClient);
599
+ const call = updateCoinURICall(args);
600
+ const { request } = await publicClient.simulateContract({
601
+ ...call,
602
+ account: account ?? walletClient.account
603
+ });
604
+ const hash = await walletClient.writeContract(request);
605
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
606
+ const eventLogs = parseEventLogs2({ abi: coinABI, logs: receipt.logs });
607
+ const uriUpdated = eventLogs.find(
608
+ (log) => log.eventName === "ContractURIUpdated"
609
+ );
610
+ return { hash, receipt, uriUpdated };
611
+ }
612
+
613
+ // src/actions/updatePayoutRecipient.ts
614
+ import { coinABI as coinABI2 } from "@zoralabs/protocol-deployments";
615
+ import {
616
+ parseEventLogs as parseEventLogs3
617
+ } from "viem";
618
+ function updatePayoutRecipientCall({
619
+ newPayoutRecipient,
620
+ coin
621
+ }) {
622
+ return {
623
+ abi: coinABI2,
624
+ address: coin,
625
+ functionName: "setPayoutRecipient",
626
+ args: [newPayoutRecipient],
627
+ dataSuffix: getAttribution()
628
+ };
629
+ }
630
+ async function updatePayoutRecipient(args, walletClient, publicClient, account) {
631
+ validateClientNetwork(publicClient);
632
+ const call = updatePayoutRecipientCall(args);
633
+ const { request } = await publicClient.simulateContract({
634
+ ...call,
635
+ account: account ?? walletClient.account
636
+ });
637
+ const hash = await walletClient.writeContract(request);
638
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
639
+ const eventLogs = parseEventLogs3({ abi: coinABI2, logs: receipt.logs });
640
+ const payoutRecipientUpdated = eventLogs.find(
641
+ (log) => log.eventName === "CoinPayoutRecipientUpdated"
642
+ );
643
+ return { hash, receipt, payoutRecipientUpdated };
644
+ }
599
645
 
600
646
  // src/actions/tradeCoin.ts
647
+ import { permit2ABI, permit2Address } from "@zoralabs/protocol-deployments";
648
+ import {
649
+ erc20Abi,
650
+ maxUint256
651
+ } from "viem";
652
+ import { base as base4 } from "viem/chains";
601
653
  function convertBigIntToString(permit) {
602
654
  return {
603
655
  ...permit,
@@ -643,11 +695,11 @@ async function tradeCoin({
643
695
  for (const permit of quote.permits) {
644
696
  const [, , nonce] = await publicClient.readContract({
645
697
  abi: permit2ABI,
646
- address: permit2Address[base7.id],
698
+ address: permit2Address[base4.id],
647
699
  functionName: "allowance",
648
700
  args: [
649
- permit.permit.details.token,
650
701
  typeof account === "string" ? account : account.address,
702
+ permit.permit.details.token,
651
703
  permit.permit.spender
652
704
  ]
653
705
  });
@@ -658,7 +710,7 @@ async function tradeCoin({
658
710
  functionName: "allowance",
659
711
  args: [
660
712
  typeof account === "string" ? account : account.address,
661
- permit2Address[base7.id]
713
+ permit2Address[base4.id]
662
714
  ]
663
715
  });
664
716
  if (allowance < BigInt(permit.permit.details.amount)) {
@@ -666,8 +718,8 @@ async function tradeCoin({
666
718
  abi: erc20Abi,
667
719
  address: permitToken,
668
720
  functionName: "approve",
669
- chain: base7,
670
- args: [permit2Address[base7.id], maxUint256],
721
+ chain: base4,
722
+ args: [permit2Address[base4.id], maxUint256],
671
723
  account
672
724
  });
673
725
  await publicClient.waitForTransactionReceipt({
@@ -687,13 +739,13 @@ async function tradeCoin({
687
739
  const signature = await walletClient.signTypedData({
688
740
  domain: {
689
741
  name: "Permit2",
690
- chainId: base7.id,
691
- verifyingContract: permit2Address[base7.id]
742
+ chainId: base4.id,
743
+ verifyingContract: permit2Address[base4.id]
692
744
  },
693
745
  primaryType: "PermitSingle",
694
746
  types: PERMIT_SINGLE_TYPES,
695
747
  message,
696
- account: typeof account === "string" ? account : account.address
748
+ account
697
749
  });
698
750
  signatures.push({
699
751
  signature,
@@ -709,7 +761,7 @@ async function tradeCoin({
709
761
  to: newQuote.call.target,
710
762
  data: newQuote.call.data,
711
763
  value: BigInt(newQuote.call.value),
712
- chain: base7,
764
+ chain: base4,
713
765
  account
714
766
  };
715
767
  if (validateTransaction) {
@@ -740,7 +792,7 @@ async function createTradeCall(tradeParameters) {
740
792
  tokenOut: tradeParameters.buy,
741
793
  amountIn: tradeParameters.amountIn.toString(),
742
794
  slippage: tradeParameters.slippage,
743
- chainId: base7.id,
795
+ chainId: base4.id,
744
796
  sender: tradeParameters.sender,
745
797
  recipient: tradeParameters.recipient || tradeParameters.sender,
746
798
  signatures: tradeParameters.signatures
@@ -753,100 +805,6 @@ async function createTradeCall(tradeParameters) {
753
805
  return quote.data;
754
806
  }
755
807
 
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
808
  // src/uploader/metadata.ts
851
809
  function validateImageMimeType(mimeType) {
852
810
  if (![
@@ -991,7 +949,10 @@ var CoinMetadataBuilder = class {
991
949
  createMetadataParameters: {
992
950
  name: this.name,
993
951
  symbol: this.symbol,
994
- uri: uploadResult.url
952
+ metadata: {
953
+ type: "RAW_URI",
954
+ uri: uploadResult.url
955
+ }
995
956
  },
996
957
  metadata
997
958
  };
@@ -1064,8 +1025,7 @@ function createZoraUploaderForCreator(creatorAddress) {
1064
1025
  }
1065
1026
  export {
1066
1027
  CoinMetadataBuilder,
1067
- DeployCurrency,
1068
- InitialPurchaseCurrency,
1028
+ CreateConstants,
1069
1029
  ZoraUploader,
1070
1030
  cleanAndValidateMetadataURI,
1071
1031
  createCoin,
@@ -1087,7 +1047,6 @@ export {
1087
1047
  getCoinsTopVolume24h,
1088
1048
  getCreatorCoins,
1089
1049
  getMostValuableCreatorCoins,
1090
- getOnchainCoinDetails,
1091
1050
  getProfile2 as getProfile,
1092
1051
  getProfileBalances2 as getProfileBalances,
1093
1052
  getProfileCoins2 as getProfileCoins,