@zoralabs/coins-sdk 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,13 +6,12 @@ import {
6
6
  keccak256 as keccak2562,
7
7
  toBytes
8
8
  } from "viem";
9
- import { base as base5, baseSepolia as baseSepolia3 } from "viem/chains";
9
+ import { base as base6, baseSepolia as baseSepolia4 } from "viem/chains";
10
10
 
11
11
  // src/constants.ts
12
12
  import { coinFactoryAddress as zoraFactoryImplAddress } from "@zoralabs/protocol-deployments";
13
13
  import { base } from "viem/chains";
14
14
  var COIN_FACTORY_ADDRESS = zoraFactoryImplAddress["8453"];
15
- var SUPERCHAIN_WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
16
15
  var USDC_WETH_POOLS_BY_CHAIN = {
17
16
  [base.id]: "0xd0b53D9277642d899DF5C87A3966A349A798F224"
18
17
  };
@@ -215,6 +214,18 @@ var getPrepurchaseHook = async ({
215
214
  });
216
215
  };
217
216
 
217
+ // src/utils/getChainFromId.ts
218
+ import { base as base5, baseSepolia as baseSepolia3 } from "viem/chains";
219
+ function getChainFromId(chainId) {
220
+ if (chainId === base5.id) {
221
+ return base5;
222
+ }
223
+ if (chainId === baseSepolia3.id) {
224
+ return baseSepolia3;
225
+ }
226
+ throw new Error(`Chain ID ${chainId} not supported`);
227
+ }
228
+
218
229
  // src/actions/createCoin.ts
219
230
  var DeployCurrency = /* @__PURE__ */ ((DeployCurrency2) => {
220
231
  DeployCurrency2[DeployCurrency2["ZORA"] = 1] = "ZORA";
@@ -226,7 +237,7 @@ var InitialPurchaseCurrency = /* @__PURE__ */ ((InitialPurchaseCurrency2) => {
226
237
  return InitialPurchaseCurrency2;
227
238
  })(InitialPurchaseCurrency || {});
228
239
  function getPoolConfig(currency, chainId) {
229
- if (currency === 1 /* ZORA */ && chainId == baseSepolia3.id) {
240
+ if (currency === 1 /* ZORA */ && chainId == baseSepolia4.id) {
230
241
  throw new Error("ZORA is not supported on Base Sepolia");
231
242
  }
232
243
  switch (currency) {
@@ -245,7 +256,7 @@ async function createCoinCall({
245
256
  owners,
246
257
  payoutRecipient,
247
258
  currency,
248
- chainId = base5.id,
259
+ chainId = base6.id,
249
260
  platformReferrer = "0x0000000000000000000000000000000000000000",
250
261
  initialPurchase
251
262
  }) {
@@ -253,7 +264,7 @@ async function createCoinCall({
253
264
  owners = [payoutRecipient];
254
265
  }
255
266
  if (!currency) {
256
- currency = chainId !== base5.id ? 2 /* ETH */ : 1 /* ZORA */;
267
+ currency = chainId !== base6.id ? 2 /* ETH */ : 1 /* ZORA */;
257
268
  }
258
269
  const poolConfig = getPoolConfig(currency, chainId);
259
270
  await validateMetadataURIContent(uri);
@@ -314,154 +325,47 @@ async function createCoin(call, walletClient, publicClient, options) {
314
325
  hash,
315
326
  receipt,
316
327
  address: deployment?.coin,
317
- deployment
328
+ deployment,
329
+ chain: getChainFromId(publicClient.chain.id)
318
330
  };
319
331
  }
320
332
 
321
333
  // src/actions/getOnchainCoinDetails.ts
322
- import { coinABI, iUniswapV3PoolABI } from "@zoralabs/protocol-deployments";
323
- import {
324
- erc20Abi,
325
- formatEther,
326
- isAddressEqual,
327
- zeroAddress as zeroAddress3
328
- } from "viem";
334
+ import { coinABI } from "@zoralabs/protocol-deployments";
335
+ import { zeroAddress as zeroAddress3 } from "viem";
329
336
  async function getOnchainCoinDetails({
330
337
  coin,
331
338
  user = zeroAddress3,
332
339
  publicClient
333
340
  }) {
334
341
  validateClientNetwork(publicClient);
335
- const [balance, pool, owners, payoutRecipient] = await publicClient.multicall(
336
- {
337
- contracts: [
338
- {
339
- address: coin,
340
- abi: coinABI,
341
- functionName: "balanceOf",
342
- args: [user]
343
- },
344
- {
345
- address: coin,
346
- abi: coinABI,
347
- functionName: "poolAddress"
348
- },
349
- {
350
- address: coin,
351
- abi: coinABI,
352
- functionName: "owners"
353
- },
354
- {
355
- address: coin,
356
- abi: coinABI,
357
- functionName: "payoutRecipient"
358
- }
359
- ],
360
- allowFailure: false
361
- }
362
- );
363
- const USDC_WETH_POOL = USDC_WETH_POOLS_BY_CHAIN[publicClient.chain?.id || 0];
364
- const [
365
- coinWethPoolSlot0,
366
- coinWethPoolToken0,
367
- coinReservesRaw,
368
- coinTotalSupply,
369
- wethReservesRaw,
370
- usdcWethSlot0
371
- ] = await publicClient.multicall({
342
+ const [balance, owners, payoutRecipient] = await publicClient.multicall({
372
343
  contracts: [
373
- {
374
- address: pool,
375
- abi: iUniswapV3PoolABI,
376
- functionName: "slot0"
377
- },
378
- {
379
- address: pool,
380
- abi: iUniswapV3PoolABI,
381
- functionName: "token0"
382
- },
383
344
  {
384
345
  address: coin,
385
- abi: erc20Abi,
346
+ abi: coinABI,
386
347
  functionName: "balanceOf",
387
- args: [pool]
348
+ args: [user]
388
349
  },
389
350
  {
390
351
  address: coin,
391
352
  abi: coinABI,
392
- functionName: "totalSupply"
353
+ functionName: "owners"
393
354
  },
394
355
  {
395
- address: SUPERCHAIN_WETH_ADDRESS,
396
- abi: erc20Abi,
397
- functionName: "balanceOf",
398
- args: [pool]
399
- },
400
- {
401
- address: USDC_WETH_POOL ?? coin,
402
- abi: iUniswapV3PoolABI,
403
- functionName: "slot0"
356
+ address: coin,
357
+ abi: coinABI,
358
+ functionName: "payoutRecipient"
404
359
  }
405
360
  ],
406
361
  allowFailure: false
407
362
  });
408
- const wethPriceInUsdc = USDC_WETH_POOL ? uniswapV3SqrtPriceToBigIntScaled(
409
- usdcWethSlot0.sqrtPriceX96,
410
- 18,
411
- 6,
412
- true,
413
- 18
414
- ) : null;
415
- const coinPriceInWeth = uniswapV3SqrtPriceToBigIntScaled(
416
- coinWethPoolSlot0.sqrtPriceX96,
417
- 18,
418
- 18,
419
- isAddressEqual(coinWethPoolToken0, coin),
420
- 18
421
- );
422
- const marketCap = coinPriceInWeth * coinTotalSupply / 10n ** 18n;
423
- const wethLiquidity = wethReservesRaw;
424
- const tokenLiquidity = coinReservesRaw * coinPriceInWeth / 10n ** 18n;
425
363
  return {
426
364
  balance,
427
- pool,
428
365
  owners,
429
- payoutRecipient,
430
- marketCap: convertEthOutput(marketCap, wethPriceInUsdc),
431
- liquidity: convertEthOutput(
432
- wethLiquidity + tokenLiquidity,
433
- wethPriceInUsdc
434
- ),
435
- poolState: coinWethPoolSlot0
436
- };
437
- }
438
- function convertEthOutput(amountETH, wethToUsdc) {
439
- return {
440
- eth: amountETH,
441
- ethDecimal: parseFloat(formatEther(amountETH)),
442
- usdc: wethToUsdc ? amountETH * wethToUsdc : null,
443
- usdcDecimal: wethToUsdc ? parseFloat(formatEther(amountETH * wethToUsdc / 10n ** 18n)) : null
366
+ payoutRecipient
444
367
  };
445
368
  }
446
- function uniswapV3SqrtPriceToBigIntScaled(sqrtPriceX96, token0Decimals, token1Decimals, isToken0Coin, scaleDecimals = 18) {
447
- const numerator = sqrtPriceX96 * sqrtPriceX96;
448
- const denominator = 2n ** 192n;
449
- const scaleFactor = 10n ** BigInt(scaleDecimals);
450
- let ratioScaled = numerator * scaleFactor / denominator;
451
- const decimalsDiff = BigInt(token0Decimals - token1Decimals);
452
- if (decimalsDiff > 0n) {
453
- ratioScaled *= 10n ** decimalsDiff;
454
- } else if (decimalsDiff < 0n) {
455
- ratioScaled /= 10n ** -decimalsDiff;
456
- }
457
- if (!isToken0Coin) {
458
- if (ratioScaled === 0n) {
459
- return 0n;
460
- }
461
- ratioScaled = scaleFactor * scaleFactor / ratioScaled;
462
- }
463
- return ratioScaled;
464
- }
465
369
 
466
370
  // src/actions/updateCoinURI.ts
467
371
  import { coinABI as coinABI2 } from "@zoralabs/protocol-deployments";
@@ -535,10 +439,10 @@ async function updatePayoutRecipient(args, walletClient, publicClient) {
535
439
  // src/actions/tradeCoin.ts
536
440
  import { permit2ABI, permit2Address } from "@zoralabs/protocol-deployments";
537
441
  import {
538
- erc20Abi as erc20Abi2,
442
+ erc20Abi,
539
443
  maxUint256
540
444
  } from "viem";
541
- import { base as base6 } from "viem/chains";
445
+ import { base as base7 } from "viem/chains";
542
446
 
543
447
  // src/client/client.gen.ts
544
448
  import {
@@ -701,36 +605,45 @@ async function tradeCoin({
701
605
  validateTransaction = true
702
606
  }) {
703
607
  const quote = await createTradeCall(tradeParameters);
608
+ if (!account) {
609
+ account = walletClient.account;
610
+ }
611
+ if (!account) {
612
+ throw new Error("Account is required");
613
+ }
704
614
  if (!tradeParameters.recipient) {
705
- tradeParameters.recipient = account.address;
615
+ tradeParameters.recipient = typeof account === "string" ? account : account.address;
706
616
  }
707
617
  const signatures = [];
708
618
  if (quote.permits) {
709
619
  for (const permit of quote.permits) {
710
620
  const [, , nonce] = await publicClient.readContract({
711
621
  abi: permit2ABI,
712
- address: permit2Address[base6.id],
622
+ address: permit2Address[base7.id],
713
623
  functionName: "allowance",
714
624
  args: [
715
625
  permit.permit.details.token,
716
- account.address,
626
+ typeof account === "string" ? account : account.address,
717
627
  permit.permit.spender
718
628
  ]
719
629
  });
720
630
  const permitToken = permit.permit.details.token;
721
631
  const allowance = await publicClient.readContract({
722
- abi: erc20Abi2,
632
+ abi: erc20Abi,
723
633
  address: permitToken,
724
634
  functionName: "allowance",
725
- args: [account.address, permit2Address[base6.id]]
635
+ args: [
636
+ typeof account === "string" ? account : account.address,
637
+ permit2Address[base7.id]
638
+ ]
726
639
  });
727
640
  if (allowance < BigInt(permit.permit.details.amount)) {
728
641
  const approvalTx = await walletClient.writeContract({
729
- abi: erc20Abi2,
642
+ abi: erc20Abi,
730
643
  address: permitToken,
731
644
  functionName: "approve",
732
- chain: base6,
733
- args: [permit2Address[base6.id], maxUint256],
645
+ chain: base7,
646
+ args: [permit2Address[base7.id], maxUint256],
734
647
  account
735
648
  });
736
649
  await publicClient.waitForTransactionReceipt({
@@ -750,13 +663,13 @@ async function tradeCoin({
750
663
  const signature = await walletClient.signTypedData({
751
664
  domain: {
752
665
  name: "Permit2",
753
- chainId: base6.id,
754
- verifyingContract: permit2Address[base6.id]
666
+ chainId: base7.id,
667
+ verifyingContract: permit2Address[base7.id]
755
668
  },
756
669
  primaryType: "PermitSingle",
757
670
  types: PERMIT_SINGLE_TYPES,
758
671
  message,
759
- account
672
+ account: typeof account === "string" ? account : account.address
760
673
  });
761
674
  signatures.push({
762
675
  signature,
@@ -772,7 +685,7 @@ async function tradeCoin({
772
685
  to: newQuote.call.target,
773
686
  data: newQuote.call.data,
774
687
  value: BigInt(newQuote.call.value),
775
- chain: base6,
688
+ chain: base7,
776
689
  account
777
690
  };
778
691
  if (validateTransaction) {
@@ -803,7 +716,7 @@ async function createTradeCall(tradeParameters) {
803
716
  tokenOut: tradeParameters.buy,
804
717
  amountIn: tradeParameters.amountIn.toString(),
805
718
  slippage: tradeParameters.slippage,
806
- chainId: base6.id,
719
+ chainId: base7.id,
807
720
  sender: tradeParameters.sender,
808
721
  recipient: tradeParameters.recipient || tradeParameters.sender,
809
722
  signatures: tradeParameters.signatures
@@ -893,6 +806,8 @@ var getCoinsMostValuable = (query = {}, options) => createExploreQuery(query, "M
893
806
  var getCoinsNew = (query = {}, options) => createExploreQuery(query, "NEW", options);
894
807
  var getCoinsLastTraded = (query = {}, options) => createExploreQuery(query, "LAST_TRADED", options);
895
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);
896
811
 
897
812
  // src/uploader/metadata.ts
898
813
  function validateImageMimeType(mimeType) {
@@ -1130,6 +1045,8 @@ export {
1130
1045
  getCoinsNew,
1131
1046
  getCoinsTopGainers,
1132
1047
  getCoinsTopVolume24h,
1048
+ getCreatorCoins,
1049
+ getMostValuableCreatorCoins,
1133
1050
  getOnchainCoinDetails,
1134
1051
  getProfile2 as getProfile,
1135
1052
  getProfileBalances2 as getProfileBalances,