@zoralabs/coins-sdk 0.2.10 → 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 (44) 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/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/api/queries.d.ts +9 -1
  11. package/dist/api/queries.d.ts.map +1 -1
  12. package/dist/client/sdk.gen.d.ts +307 -46
  13. package/dist/client/sdk.gen.d.ts.map +1 -1
  14. package/dist/client/types.gen.d.ts +874 -93
  15. package/dist/client/types.gen.d.ts.map +1 -1
  16. package/dist/index.cjs +419 -424
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.ts +2 -3
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +413 -418
  21. package/dist/index.js.map +1 -1
  22. package/dist/uploader/metadata.d.ts.map +1 -1
  23. package/dist/uploader/types.d.ts +4 -1
  24. package/dist/uploader/types.d.ts.map +1 -1
  25. package/dist/utils/rethrowDecodedRevert.d.ts +3 -0
  26. package/dist/utils/rethrowDecodedRevert.d.ts.map +1 -0
  27. package/package.json +1 -1
  28. package/src/actions/createCoin.ts +154 -112
  29. package/src/api/create.ts +24 -0
  30. package/src/api/index.ts +8 -0
  31. package/src/api/pool-config.ts +17 -0
  32. package/src/api/queries.ts +36 -0
  33. package/src/client/sdk.gen.ts +98 -0
  34. package/src/client/types.gen.ts +898 -93
  35. package/src/index.ts +4 -6
  36. package/src/uploader/metadata.ts +4 -1
  37. package/src/uploader/types.ts +4 -1
  38. package/src/utils/rethrowDecodedRevert.ts +50 -0
  39. package/dist/actions/getOnchainCoinDetails.d.ts +0 -32
  40. package/dist/actions/getOnchainCoinDetails.d.ts.map +0 -1
  41. package/dist/utils/getPrepurchaseHook.d.ts +0 -16
  42. package/dist/utils/getPrepurchaseHook.d.ts.map +0 -1
  43. package/src/actions/getOnchainCoinDetails.ts +0 -68
  44. package/src/utils/getPrepurchaseHook.ts +0 -59
package/dist/index.cjs CHANGED
@@ -1,21 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/actions/createCoin.ts
2
- var _protocoldeployments = require('@zoralabs/protocol-deployments');
3
2
 
4
3
 
5
4
 
5
+ var _protocoldeployments = require('@zoralabs/protocol-deployments');
6
+
6
7
 
7
8
 
8
9
  var _viem = require('viem');
9
10
  var _chains = require('viem/chains');
10
11
 
11
- // src/constants.ts
12
-
13
-
14
- var COIN_FACTORY_ADDRESS = _protocoldeployments.coinFactoryAddress["8453"];
15
- var USDC_WETH_POOLS_BY_CHAIN = {
16
- [_chains.base.id]: "0xd0b53D9277642d899DF5C87A3966A349A798F224"
17
- };
18
-
19
12
  // src/utils/validateClientNetwork.ts
20
13
 
21
14
  var validateClientNetwork = (publicClient) => {
@@ -126,94 +119,6 @@ async function validateMetadataURIContent(metadataURI) {
126
119
  return validateMetadataJSON(metadataJson);
127
120
  }
128
121
 
129
- // src/utils/attribution.ts
130
-
131
- function getAttribution() {
132
- const hash = _viem.keccak256.call(void 0, _viem.toHex.call(void 0, "api-sdk.zora.engineering"));
133
- return _viem.slice.call(void 0, hash, 0, 4);
134
- }
135
-
136
- // src/utils/poolConfigUtils.ts
137
-
138
-
139
-
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 = _viem.parseUnits.call(void 0, "0.05", 18);
146
- var COIN_ETH_PAIR_POOL_CONFIG = {
147
- [_chains.base.id]: _protocoldeployments.encodeMultiCurvePoolConfig.call(void 0, {
148
- currency: _viem.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
- [_chains.baseSepolia.id]: _protocoldeployments.encodeMultiCurvePoolConfig.call(void 0, {
155
- currency: _viem.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 = _viem.parseUnits.call(void 0,
166
- "0.05",
167
- ZORA_DECIMALS
168
- );
169
- var COIN_ZORA_PAIR_POOL_CONFIG = {
170
- [_chains.base.id]: _protocoldeployments.encodeMultiCurvePoolConfig.call(void 0, {
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
-
181
-
182
-
183
-
184
-
185
-
186
- var BASE_UDSC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
187
- var USDC_ZORA_FEE = 3e3;
188
- var WETH_BASE_FEE = 3e3;
189
- var encodeFee = (fee) => _viem.pad.call(void 0, _viem.toHex.call(void 0, fee), { size: 3 });
190
- var getPrepurchaseHook = async ({
191
- payoutRecipient,
192
- initialPurchase,
193
- chainId
194
- }) => {
195
- if (initialPurchase.currency !== 1 /* ETH */ && chainId !== _chains.base.id) {
196
- throw new Error("Initial purchase currency and/or chain not supported");
197
- }
198
- const path = _viem.concat.call(void 0, [
199
- _protocoldeployments.wethAddress[_chains.base.id],
200
- encodeFee(WETH_BASE_FEE),
201
- BASE_UDSC_ADDRESS,
202
- encodeFee(USDC_ZORA_FEE),
203
- ZORA_ADDRESS
204
- ]);
205
- return _protocoldeployments.encodeBuySupplyWithMultiHopSwapRouterHookCall.call(void 0, {
206
- ethValue: initialPurchase.amount,
207
- buyRecipient: payoutRecipient,
208
- exactInputParams: {
209
- path,
210
- amountIn: initialPurchase.amount,
211
- amountOutMinimum: initialPurchase.amountOutMinimum || 0n
212
- },
213
- chainId: _chains.base.id
214
- });
215
- };
216
-
217
122
  // src/utils/getChainFromId.ts
218
123
 
219
124
  function getChainFromId(chainId) {
@@ -226,224 +131,6 @@ function getChainFromId(chainId) {
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 == _chains.baseSepolia.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 = _chains.base.id,
260
- platformReferrer = "0x0000000000000000000000000000000000000000",
261
- initialPurchase
262
- }) {
263
- if (!owners) {
264
- owners = [payoutRecipient];
265
- }
266
- if (!currency) {
267
- currency = chainId !== _chains.base.id ? 2 /* ETH */ : 1 /* ZORA */;
268
- }
269
- const poolConfig = getPoolConfig(currency, chainId);
270
- await validateMetadataURIContent(uri);
271
- let deployHook = {
272
- hook: _viem.zeroAddress,
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: _protocoldeployments.coinFactoryABI,
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
- _viem.keccak256.call(void 0, _viem.toBytes.call(void 0, Math.random().toString()))
298
- // coinSalt
299
- ],
300
- value: deployHook.value,
301
- dataSuffix: getAttribution()
302
- };
303
- }
304
- function getCoinCreateFromLogs(receipt) {
305
- const eventLogs = _viem.parseEventLogs.call(void 0, {
306
- abi: _protocoldeployments.coinFactoryABI,
307
- logs: receipt.logs
308
- });
309
- return _optionalChain([eventLogs, 'access', _3 => _3.find, 'call', _4 => _4((log) => log.eventName === "CoinCreatedV4"), 'optionalAccess', _5 => _5.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: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _6 => _6.account]), () => ( walletClient.account))
317
- });
318
- if (request.gas) {
319
- request.gas = request.gas * BigInt(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _7 => _7.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: _optionalChain([deployment, 'optionalAccess', _8 => _8.coin]),
328
- deployment,
329
- chain: getChainFromId(publicClient.chain.id)
330
- };
331
- }
332
-
333
- // src/actions/getOnchainCoinDetails.ts
334
-
335
-
336
- async function getOnchainCoinDetails({
337
- coin,
338
- user = _viem.zeroAddress,
339
- publicClient
340
- }) {
341
- validateClientNetwork(publicClient);
342
- const [balance, owners, payoutRecipient] = await publicClient.multicall({
343
- contracts: [
344
- {
345
- address: coin,
346
- abi: _protocoldeployments.coinABI,
347
- functionName: "balanceOf",
348
- args: [user]
349
- },
350
- {
351
- address: coin,
352
- abi: _protocoldeployments.coinABI,
353
- functionName: "owners"
354
- },
355
- {
356
- address: coin,
357
- abi: _protocoldeployments.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
-
372
-
373
-
374
-
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: _protocoldeployments.coinABI,
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 = _viem.parseEventLogs.call(void 0, { abi: _protocoldeployments.coinABI, 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
-
408
-
409
-
410
-
411
- function updatePayoutRecipientCall({
412
- newPayoutRecipient,
413
- coin
414
- }) {
415
- return {
416
- abi: _protocoldeployments.coinABI,
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 = _viem.parseEventLogs.call(void 0, { abi: _protocoldeployments.coinABI, 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
-
441
-
442
-
443
-
444
-
445
-
446
-
447
134
  // src/client/client.gen.ts
448
135
 
449
136
 
@@ -480,6 +167,30 @@ var getCoinComments = (options) => {
480
167
  ...options
481
168
  });
482
169
  };
170
+ var getCoinHolders = (options) => {
171
+ return (_nullishCoalesce(options.client, () => ( client))).get({
172
+ security: [
173
+ {
174
+ name: "api-key",
175
+ type: "apiKey"
176
+ }
177
+ ],
178
+ url: "/coinHolders",
179
+ ...options
180
+ });
181
+ };
182
+ var getCoinSwaps = (options) => {
183
+ return (_nullishCoalesce(options.client, () => ( client))).get({
184
+ security: [
185
+ {
186
+ name: "api-key",
187
+ type: "apiKey"
188
+ }
189
+ ],
190
+ url: "/coinSwaps",
191
+ ...options
192
+ });
193
+ };
483
194
  var getCoins = (options) => {
484
195
  return (_nullishCoalesce(options.client, () => ( client))).get({
485
196
  security: [
@@ -493,7 +204,7 @@ var getCoins = (options) => {
493
204
  });
494
205
  };
495
206
  var setCreateUploadJwt = (options) => {
496
- return (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.client]), () => ( client))).post({
207
+ return (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _3 => _3.client]), () => ( client))).post({
497
208
  security: [
498
209
  {
499
210
  name: "api-key",
@@ -504,7 +215,7 @@ var setCreateUploadJwt = (options) => {
504
215
  ...options,
505
216
  headers: {
506
217
  "Content-Type": "application/json",
507
- ..._optionalChain([options, 'optionalAccess', _10 => _10.headers])
218
+ ..._optionalChain([options, 'optionalAccess', _4 => _4.headers])
508
219
  }
509
220
  });
510
221
  };
@@ -557,7 +268,7 @@ var getProfileCoins = (options) => {
557
268
  });
558
269
  };
559
270
  var postQuote = (options) => {
560
- return (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.client]), () => ( client))).post({
271
+ return (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _5 => _5.client]), () => ( client))).post({
561
272
  security: [
562
273
  {
563
274
  name: "api-key",
@@ -568,34 +279,395 @@ var postQuote = (options) => {
568
279
  ...options,
569
280
  headers: {
570
281
  "Content-Type": "application/json",
571
- ..._optionalChain([options, 'optionalAccess', _12 => _12.headers])
282
+ ..._optionalChain([options, 'optionalAccess', _6 => _6.headers])
283
+ }
284
+ });
285
+ };
286
+ var postCreateContent = (options) => {
287
+ return (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _7 => _7.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
+ ..._optionalChain([options, 'optionalAccess', _8 => _8.headers])
572
299
  }
573
300
  });
574
301
  };
575
302
 
576
- // src/actions/tradeCoin.ts
577
- function convertBigIntToString(permit) {
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
+ }
578
315
  return {
579
- ...permit,
580
- details: {
581
- ...permit.details,
582
- amount: `${permit.details.amount}`
583
- },
584
- sigDeadline: `${permit.sigDeadline}`
316
+ headers: {
317
+ "api-key": apiKey
318
+ }
585
319
  };
586
320
  }
587
- var PERMIT_SINGLE_TYPES = {
588
- PermitSingle: [
589
- { name: "details", type: "PermitDetails" },
590
- { name: "spender", type: "address" },
591
- { name: "sigDeadline", type: "uint256" }
592
- ],
593
- PermitDetails: [
594
- { name: "token", type: "address" },
595
- { name: "amount", type: "uint160" },
596
- { name: "expiration", type: "uint48" },
597
- { name: "nonce", type: "uint48" }
598
- ]
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
+
408
+
409
+
410
+
411
+
412
+ function rethrowDecodedRevert(err, abi) {
413
+ if (err instanceof _viem.BaseError) {
414
+ const revertError = err.walk(
415
+ (e) => e instanceof _viem.ContractFunctionRevertedError
416
+ );
417
+ if (revertError instanceof _viem.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 = _viem.decodeErrorResult.call(void 0, {
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 (e2) {
429
+ const errorName = _optionalChain([revertError, 'access', _9 => _9.data, 'optionalAccess', _10 => _10.errorName]);
430
+ if (errorName) {
431
+ const args = _optionalChain([revertError, 'access', _11 => _11.data, 'optionalAccess', _12 => _12.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 = _chains.base.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 (!_optionalChain([createContentRequest, 'access', _13 => _13.data, 'optionalAccess', _14 => _14.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 = _viem.parseEventLogs.call(void 0, {
493
+ abi: _protocoldeployments.coinFactoryABI,
494
+ logs: receipt.logs
495
+ });
496
+ return _optionalChain([eventLogs, 'access', _15 => _15.find, 'call', _16 => _16((log) => log.eventName === "CoinCreatedV4"), 'optionalAccess', _17 => _17.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 = _protocoldeployments.coinFactoryAddress[call.chainId];
514
+ if (!_viem.isAddressEqual.call(void 0, 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 = _nullishCoalesce((typeof _optionalChain([options, 'optionalAccess', _18 => _18.account]) === "string" ? void 0 : _optionalChain([options, 'optionalAccess', _19 => _19.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 (!_optionalChain([options, 'optionalAccess', _20 => _20.skipValidateTransaction])) {
531
+ try {
532
+ await publicClient.call(viemCall);
533
+ } catch (err) {
534
+ rethrowDecodedRevert(err, _protocoldeployments.coinFactoryABI);
535
+ }
536
+ }
537
+ const gasEstimate = _optionalChain([options, 'optionalAccess', _21 => _21.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, _protocoldeployments.coinFactoryABI);
549
+ }
550
+ })();
551
+ const receipt = await publicClient.waitForTransactionReceipt({
552
+ hash
553
+ });
554
+ const deployment = getCoinCreateFromLogs(receipt);
555
+ return {
556
+ hash,
557
+ receipt,
558
+ address: _optionalChain([deployment, 'optionalAccess', _22 => _22.coin]),
559
+ deployment,
560
+ chain: getChainFromId(publicClient.chain.id)
561
+ };
562
+ }
563
+
564
+ // src/actions/updateCoinURI.ts
565
+
566
+
567
+
568
+
569
+
570
+ // src/utils/attribution.ts
571
+
572
+ function getAttribution() {
573
+ const hash = _viem.keccak256.call(void 0, _viem.toHex.call(void 0, "api-sdk.zora.engineering"));
574
+ return _viem.slice.call(void 0, 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: _protocoldeployments.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 = _viem.parseEventLogs.call(void 0, { abi: _protocoldeployments.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
+
611
+
612
+
613
+
614
+ function updatePayoutRecipientCall({
615
+ newPayoutRecipient,
616
+ coin
617
+ }) {
618
+ return {
619
+ abi: _protocoldeployments.coinABI,
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 = _viem.parseEventLogs.call(void 0, { abi: _protocoldeployments.coinABI, logs: receipt.logs });
636
+ const payoutRecipientUpdated = eventLogs.find(
637
+ (log) => log.eventName === "CoinPayoutRecipientUpdated"
638
+ );
639
+ return { hash, receipt, payoutRecipientUpdated };
640
+ }
641
+
642
+ // src/actions/tradeCoin.ts
643
+
644
+
645
+
646
+
647
+
648
+
649
+ function convertBigIntToString(permit) {
650
+ return {
651
+ ...permit,
652
+ details: {
653
+ ...permit.details,
654
+ amount: `${permit.details.amount}`
655
+ },
656
+ sigDeadline: `${permit.sigDeadline}`
657
+ };
658
+ }
659
+ var PERMIT_SINGLE_TYPES = {
660
+ PermitSingle: [
661
+ { name: "details", type: "PermitDetails" },
662
+ { name: "spender", type: "address" },
663
+ { name: "sigDeadline", type: "uint256" }
664
+ ],
665
+ PermitDetails: [
666
+ { name: "token", type: "address" },
667
+ { name: "amount", type: "uint160" },
668
+ { name: "expiration", type: "uint48" },
669
+ { name: "nonce", type: "uint48" }
670
+ ]
599
671
  };
600
672
  async function tradeCoin({
601
673
  tradeParameters,
@@ -729,86 +801,6 @@ async function createTradeCall(tradeParameters) {
729
801
  return quote.data;
730
802
  }
731
803
 
732
- // src/api/api-key.ts
733
- var apiKey;
734
- function setApiKey(key) {
735
- apiKey = key;
736
- }
737
- function getApiKey() {
738
- return apiKey;
739
- }
740
- function getApiKeyMeta() {
741
- if (!apiKey) {
742
- return {};
743
- }
744
- return {
745
- headers: {
746
- "api-key": apiKey
747
- }
748
- };
749
- }
750
-
751
- // src/api/queries.ts
752
- var getCoin2 = async (query, options) => {
753
- return await getCoin({
754
- ...options,
755
- query,
756
- ...getApiKeyMeta()
757
- });
758
- };
759
- var getCoins2 = async (query, options) => {
760
- return await getCoins({
761
- query: {
762
- coins: query.coins.map((coinData) => JSON.stringify(coinData))
763
- },
764
- ...getApiKeyMeta(),
765
- ...options
766
- });
767
- };
768
- var getCoinComments2 = async (query, options) => {
769
- return await getCoinComments({
770
- query,
771
- ...getApiKeyMeta(),
772
- ...options
773
- });
774
- };
775
- var getProfile2 = async (query, options) => {
776
- return await getProfile({
777
- query,
778
- ...getApiKeyMeta(),
779
- ...options
780
- });
781
- };
782
- var getProfileCoins2 = async (query, options) => {
783
- return await getProfileCoins({
784
- query,
785
- ...getApiKeyMeta(),
786
- ...options
787
- });
788
- };
789
- var getProfileBalances2 = async (query, options) => {
790
- return await getProfileBalances({
791
- query,
792
- ...getApiKeyMeta(),
793
- ...options
794
- });
795
- };
796
-
797
- // src/api/explore.ts
798
- var createExploreQuery = (query, listType, options) => getExplore({
799
- ...options,
800
- query: { ...query, listType },
801
- ...getApiKeyMeta()
802
- });
803
- var getCoinsTopGainers = (query = {}, options) => createExploreQuery(query, "TOP_GAINERS", options);
804
- var getCoinsTopVolume24h = (query = {}, options) => createExploreQuery(query, "TOP_VOLUME_24H", options);
805
- var getCoinsMostValuable = (query = {}, options) => createExploreQuery(query, "MOST_VALUABLE", options);
806
- var getCoinsNew = (query = {}, options) => createExploreQuery(query, "NEW", options);
807
- var getCoinsLastTraded = (query = {}, options) => createExploreQuery(query, "LAST_TRADED", options);
808
- var getCoinsLastTradedUnique = (query = {}, options) => createExploreQuery(query, "LAST_TRADED_UNIQUE", options);
809
- var getCreatorCoins = (query = {}, options) => createExploreQuery(query, "NEW_CREATORS", options);
810
- var getMostValuableCreatorCoins = (query = {}, options) => createExploreQuery(query, "MOST_VALUABLE_CREATORS", options);
811
-
812
804
  // src/uploader/metadata.ts
813
805
  function validateImageMimeType(mimeType) {
814
806
  if (![
@@ -924,9 +916,9 @@ var CoinMetadataBuilder = class {
924
916
  symbol: this.symbol,
925
917
  description: this.description,
926
918
  image: this.imageURL.toString(),
927
- animation_url: _optionalChain([this, 'access', _13 => _13.mediaURL, 'optionalAccess', _14 => _14.toString, 'call', _15 => _15()]),
919
+ animation_url: _optionalChain([this, 'access', _23 => _23.mediaURL, 'optionalAccess', _24 => _24.toString, 'call', _25 => _25()]),
928
920
  content: this.mediaURL ? {
929
- uri: _optionalChain([this, 'access', _16 => _16.mediaURL, 'optionalAccess', _17 => _17.toString, 'call', _18 => _18()]),
921
+ uri: _optionalChain([this, 'access', _26 => _26.mediaURL, 'optionalAccess', _27 => _27.toString, 'call', _28 => _28()]),
930
922
  mime: this.mediaMimeType
931
923
  } : void 0,
932
924
  properties: this.properties
@@ -953,7 +945,10 @@ var CoinMetadataBuilder = class {
953
945
  createMetadataParameters: {
954
946
  name: this.name,
955
947
  symbol: this.symbol,
956
- uri: uploadResult.url
948
+ metadata: {
949
+ type: "RAW_URI",
950
+ uri: uploadResult.url
951
+ }
957
952
  },
958
953
  metadata
959
954
  };
@@ -988,7 +983,7 @@ var ZoraUploader = class {
988
983
  const response = await setCreateUploadJwt2({
989
984
  creatorAddress: this.creatorAddress
990
985
  });
991
- this.jwtApiKey = _optionalChain([response, 'access', _19 => _19.data, 'optionalAccess', _20 => _20.createUploadJwtFromApiKey]);
986
+ this.jwtApiKey = _optionalChain([response, 'access', _29 => _29.data, 'optionalAccess', _30 => _30.createUploadJwtFromApiKey]);
992
987
  if (!this.jwtApiKey) {
993
988
  throw new Error("Failed to create upload JWT");
994
989
  }
@@ -1061,5 +1056,5 @@ function createZoraUploaderForCreator(creatorAddress) {
1061
1056
 
1062
1057
 
1063
1058
 
1064
- exports.CoinMetadataBuilder = CoinMetadataBuilder; exports.DeployCurrency = DeployCurrency; exports.InitialPurchaseCurrency = InitialPurchaseCurrency; exports.ZoraUploader = ZoraUploader; exports.cleanAndValidateMetadataURI = cleanAndValidateMetadataURI; exports.createCoin = createCoin; exports.createCoinCall = createCoinCall; exports.createMetadataBuilder = createMetadataBuilder; exports.createTradeCall = createTradeCall; exports.createZoraUploaderForCreator = createZoraUploaderForCreator; exports.getCoin = getCoin2; exports.getCoinComments = getCoinComments2; exports.getCoinCreateFromLogs = getCoinCreateFromLogs; exports.getCoins = getCoins2; exports.getCoinsLastTraded = getCoinsLastTraded; exports.getCoinsLastTradedUnique = getCoinsLastTradedUnique; exports.getCoinsMostValuable = getCoinsMostValuable; exports.getCoinsNew = getCoinsNew; exports.getCoinsTopGainers = getCoinsTopGainers; exports.getCoinsTopVolume24h = getCoinsTopVolume24h; exports.getCreatorCoins = getCreatorCoins; exports.getMostValuableCreatorCoins = getMostValuableCreatorCoins; exports.getOnchainCoinDetails = getOnchainCoinDetails; exports.getProfile = getProfile2; exports.getProfileBalances = getProfileBalances2; exports.getProfileCoins = getProfileCoins2; exports.getURLFromUploadResult = getURLFromUploadResult; exports.setApiKey = setApiKey; exports.tradeCoin = tradeCoin; exports.updateCoinURI = updateCoinURI; exports.updateCoinURICall = updateCoinURICall; exports.updatePayoutRecipient = updatePayoutRecipient; exports.updatePayoutRecipientCall = updatePayoutRecipientCall; exports.validateImageMimeType = validateImageMimeType; exports.validateMetadataJSON = validateMetadataJSON; exports.validateMetadataURIContent = validateMetadataURIContent;
1059
+ exports.CoinMetadataBuilder = CoinMetadataBuilder; exports.CreateConstants = CreateConstants; exports.ZoraUploader = ZoraUploader; exports.cleanAndValidateMetadataURI = cleanAndValidateMetadataURI; exports.createCoin = createCoin; exports.createCoinCall = createCoinCall; exports.createMetadataBuilder = createMetadataBuilder; exports.createTradeCall = createTradeCall; exports.createZoraUploaderForCreator = createZoraUploaderForCreator; exports.getCoin = getCoin2; exports.getCoinComments = getCoinComments2; exports.getCoinCreateFromLogs = getCoinCreateFromLogs; exports.getCoinHolders = getCoinHolders2; exports.getCoinSwaps = getCoinSwaps2; exports.getCoins = getCoins2; exports.getCoinsLastTraded = getCoinsLastTraded; exports.getCoinsLastTradedUnique = getCoinsLastTradedUnique; exports.getCoinsMostValuable = getCoinsMostValuable; exports.getCoinsNew = getCoinsNew; exports.getCoinsTopGainers = getCoinsTopGainers; exports.getCoinsTopVolume24h = getCoinsTopVolume24h; exports.getCreatorCoins = getCreatorCoins; exports.getMostValuableCreatorCoins = getMostValuableCreatorCoins; exports.getProfile = getProfile2; exports.getProfileBalances = getProfileBalances2; exports.getProfileCoins = getProfileCoins2; exports.getURLFromUploadResult = getURLFromUploadResult; exports.setApiKey = setApiKey; exports.tradeCoin = tradeCoin; exports.updateCoinURI = updateCoinURI; exports.updateCoinURICall = updateCoinURICall; exports.updatePayoutRecipient = updatePayoutRecipient; exports.updatePayoutRecipientCall = updatePayoutRecipientCall; exports.validateImageMimeType = validateImageMimeType; exports.validateMetadataJSON = validateMetadataJSON; exports.validateMetadataURIContent = validateMetadataURIContent;
1065
1060
  //# sourceMappingURL=index.cjs.map