@zoralabs/coins-sdk 0.0.2-sdkalpha.2 → 0.0.2-sdkalpha.4

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 (46) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +448 -18
  3. package/dist/actions/createCoin.d.ts.map +1 -1
  4. package/dist/actions/{getCoinDetails.d.ts → getOnchainCoinDetails.d.ts} +9 -8
  5. package/dist/actions/getOnchainCoinDetails.d.ts.map +1 -0
  6. package/dist/api/api-key.d.ts +9 -0
  7. package/dist/api/api-key.d.ts.map +1 -0
  8. package/dist/api/explore.d.ts +347 -0
  9. package/dist/api/explore.d.ts.map +1 -0
  10. package/dist/api/index.d.ts +4 -0
  11. package/dist/api/index.d.ts.map +1 -0
  12. package/dist/api/queries.d.ts +345 -0
  13. package/dist/api/queries.d.ts.map +1 -0
  14. package/dist/client/client.gen.d.ts +13 -0
  15. package/dist/client/client.gen.d.ts.map +1 -0
  16. package/dist/client/index.d.ts +3 -0
  17. package/dist/client/index.d.ts.map +1 -0
  18. package/dist/client/sdk.gen.d.ts +366 -0
  19. package/dist/client/sdk.gen.d.ts.map +1 -0
  20. package/dist/client/types.gen.d.ts +549 -0
  21. package/dist/client/types.gen.d.ts.map +1 -0
  22. package/dist/index.cjs +185 -33
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +5 -3
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +179 -33
  27. package/dist/index.js.map +1 -1
  28. package/dist/utils/genericPublicClient.d.ts +3 -0
  29. package/dist/utils/genericPublicClient.d.ts.map +1 -0
  30. package/dist/utils/validateClientNetwork.d.ts +1 -1
  31. package/dist/utils/validateClientNetwork.d.ts.map +1 -1
  32. package/package.json +7 -4
  33. package/src/actions/createCoin.ts +5 -0
  34. package/src/actions/{getCoinDetails.ts → getOnchainCoinDetails.ts} +111 -76
  35. package/src/api/api-key.ts +15 -0
  36. package/src/api/explore.ts +55 -0
  37. package/src/api/index.ts +8 -0
  38. package/src/api/queries.ts +60 -0
  39. package/src/client/client.gen.ts +18 -0
  40. package/src/client/index.ts +3 -0
  41. package/src/client/sdk.gen.ts +117 -0
  42. package/src/client/types.gen.ts +580 -0
  43. package/src/index.ts +18 -4
  44. package/src/utils/genericPublicClient.ts +5 -0
  45. package/src/utils/validateClientNetwork.ts +16 -12
  46. package/dist/actions/getCoinDetails.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -72,6 +72,9 @@ async function createCoin(call, walletClient, publicClient) {
72
72
  ...createCoinCall(call),
73
73
  account: walletClient.account
74
74
  });
75
+ if (request.gas) {
76
+ request.gas = request.gas * 6n / 5n;
77
+ }
75
78
  const hash = await walletClient.writeContract(request);
76
79
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
77
80
  const deployment = getCoinCreateFromLogs(receipt);
@@ -142,43 +145,57 @@ async function tradeCoin(params, walletClient, publicClient) {
142
145
  };
143
146
  }
144
147
 
145
- // src/actions/getCoinDetails.ts
148
+ // src/actions/getOnchainCoinDetails.ts
146
149
  import { coinABI as coinABI2, iUniswapV3PoolABI } from "@zoralabs/coins";
147
- import { erc20Abi, formatEther, isAddressEqual, zeroAddress as zeroAddress2 } from "viem";
148
- async function getCoinDetails({
150
+ import {
151
+ erc20Abi,
152
+ formatEther,
153
+ isAddressEqual,
154
+ zeroAddress as zeroAddress2
155
+ } from "viem";
156
+ async function getOnchainCoinDetails({
149
157
  coin,
150
158
  user = zeroAddress2,
151
159
  publicClient
152
160
  }) {
153
161
  validateClientNetwork(publicClient);
154
- const [balance, pool, owners, payoutRecipient] = await publicClient.multicall({
155
- contracts: [
156
- {
157
- address: coin,
158
- abi: coinABI2,
159
- functionName: "balanceOf",
160
- args: [user]
161
- },
162
- {
163
- address: coin,
164
- abi: coinABI2,
165
- functionName: "poolAddress"
166
- },
167
- {
168
- address: coin,
169
- abi: coinABI2,
170
- functionName: "owners"
171
- },
172
- {
173
- address: coin,
174
- abi: coinABI2,
175
- functionName: "payoutRecipient"
176
- }
177
- ],
178
- allowFailure: false
179
- });
162
+ const [balance, pool, owners, payoutRecipient] = await publicClient.multicall(
163
+ {
164
+ contracts: [
165
+ {
166
+ address: coin,
167
+ abi: coinABI2,
168
+ functionName: "balanceOf",
169
+ args: [user]
170
+ },
171
+ {
172
+ address: coin,
173
+ abi: coinABI2,
174
+ functionName: "poolAddress"
175
+ },
176
+ {
177
+ address: coin,
178
+ abi: coinABI2,
179
+ functionName: "owners"
180
+ },
181
+ {
182
+ address: coin,
183
+ abi: coinABI2,
184
+ functionName: "payoutRecipient"
185
+ }
186
+ ],
187
+ allowFailure: false
188
+ }
189
+ );
180
190
  const USDC_WETH_POOL = USDC_WETH_POOLS_BY_CHAIN[publicClient.chain?.id || 0];
181
- const [coinWethPoolSlot0, coinWethPoolToken0, coinReservesRaw, coinTotalSupply, wethReservesRaw, usdcWethSlot0] = await publicClient.multicall({
191
+ const [
192
+ coinWethPoolSlot0,
193
+ coinWethPoolToken0,
194
+ coinReservesRaw,
195
+ coinTotalSupply,
196
+ wethReservesRaw,
197
+ usdcWethSlot0
198
+ ] = await publicClient.multicall({
182
199
  contracts: [
183
200
  {
184
201
  address: pool,
@@ -238,12 +255,20 @@ async function getCoinDetails({
238
255
  owners,
239
256
  payoutRecipient,
240
257
  marketCap: convertEthOutput(marketCap, wethPriceInUsdc),
241
- liquidity: convertEthOutput(wethLiquidity + tokenLiquidity, wethPriceInUsdc),
258
+ liquidity: convertEthOutput(
259
+ wethLiquidity + tokenLiquidity,
260
+ wethPriceInUsdc
261
+ ),
242
262
  poolState: coinWethPoolSlot0
243
263
  };
244
264
  }
245
265
  function convertEthOutput(amountETH, wethToUsdc) {
246
- return { eth: amountETH, ethDecimal: parseFloat(formatEther(amountETH)), usdc: wethToUsdc ? amountETH * wethToUsdc : null, usdcDecimal: wethToUsdc ? parseFloat(formatEther(amountETH * wethToUsdc / 10n ** 18n)) : null };
266
+ return {
267
+ eth: amountETH,
268
+ ethDecimal: parseFloat(formatEther(amountETH)),
269
+ usdc: wethToUsdc ? amountETH * wethToUsdc : null,
270
+ usdcDecimal: wethToUsdc ? parseFloat(formatEther(amountETH * wethToUsdc / 10n ** 18n)) : null
271
+ };
247
272
  }
248
273
  function uniswapV3SqrtPriceToBigIntScaled(sqrtPriceX96, token0Decimals, token1Decimals, isToken0Coin, scaleDecimals = 18) {
249
274
  const numerator = sqrtPriceX96 * sqrtPriceX96;
@@ -299,11 +324,132 @@ async function updateCoinURI(args, walletClient, publicClient) {
299
324
  );
300
325
  return { hash, receipt, uriUpdated };
301
326
  }
327
+
328
+ // src/client/client.gen.ts
329
+ import { createClient, createConfig } from "@hey-api/client-fetch";
330
+ var client = createClient(createConfig({
331
+ baseUrl: "https://api-sdk.zora.engineering/"
332
+ }));
333
+
334
+ // src/client/sdk.gen.ts
335
+ var getCoin = (options) => {
336
+ return (options.client ?? client).get({
337
+ url: "/coin",
338
+ ...options
339
+ });
340
+ };
341
+ var getCoinComments = (options) => {
342
+ return (options.client ?? client).get({
343
+ url: "/coinComments",
344
+ ...options
345
+ });
346
+ };
347
+ var getCoins = (options) => {
348
+ return (options.client ?? client).get({
349
+ url: "/coins",
350
+ ...options
351
+ });
352
+ };
353
+ var getExplore = (options) => {
354
+ return (options.client ?? client).get({
355
+ url: "/explore",
356
+ ...options
357
+ });
358
+ };
359
+ var getProfile = (options) => {
360
+ return (options.client ?? client).get({
361
+ url: "/profile",
362
+ ...options
363
+ });
364
+ };
365
+ var getProfileOwned = (options) => {
366
+ return (options.client ?? client).get({
367
+ url: "/profileOwned",
368
+ ...options
369
+ });
370
+ };
371
+
372
+ // src/api/api-key.ts
373
+ var apiKey;
374
+ function getApiKeyMeta() {
375
+ if (!apiKey) {
376
+ return {};
377
+ }
378
+ return {
379
+ headers: {
380
+ "api-key": apiKey
381
+ }
382
+ };
383
+ }
384
+
385
+ // src/api/queries.ts
386
+ var getCoin2 = async (query) => {
387
+ return await getCoin({
388
+ query,
389
+ meta: getApiKeyMeta()
390
+ });
391
+ };
392
+ var getCoins2 = async ({
393
+ coinAddresses,
394
+ chainId
395
+ }) => {
396
+ return await getCoins({
397
+ query: {
398
+ coins: coinAddresses.map((collectionAddress) => ({
399
+ chainId,
400
+ collectionAddress
401
+ }))
402
+ },
403
+ meta: getApiKeyMeta()
404
+ });
405
+ };
406
+ var getCoinComments2 = async (query) => {
407
+ return await getCoinComments({
408
+ query,
409
+ meta: getApiKeyMeta()
410
+ });
411
+ };
412
+ var getProfile2 = async (query) => {
413
+ return await getProfile({
414
+ query,
415
+ meta: getApiKeyMeta()
416
+ });
417
+ };
418
+ var getProfileOwned2 = async (query) => {
419
+ return await getProfileOwned({
420
+ query,
421
+ meta: getApiKeyMeta()
422
+ });
423
+ };
424
+
425
+ // src/api/explore.ts
426
+ var createExploreQuery = (listType, options) => getExplore({
427
+ ...options,
428
+ query: { ...options?.query, listType },
429
+ meta: getApiKeyMeta()
430
+ });
431
+ var getExploreTopGainers = (options) => createExploreQuery("TOP_GAINERS", options);
432
+ var getExploreTopVolume24h = (options) => createExploreQuery("TOP_VOLUME_24H", options);
433
+ var getExploreMostValuable = (options) => createExploreQuery("MOST_VALUABLE", options);
434
+ var getExploreNew = (options) => createExploreQuery("NEW", options);
435
+ var getExploreLastTraded = (options) => createExploreQuery("LAST_TRADED", options);
436
+ var getExploreLastTradedUnique = (options) => createExploreQuery("LAST_TRADED_UNIQUE", options);
302
437
  export {
303
438
  createCoin,
304
439
  createCoinCall,
440
+ getCoin2 as getCoin,
441
+ getCoinComments2 as getCoinComments,
305
442
  getCoinCreateFromLogs,
306
- getCoinDetails,
443
+ getCoins2 as getCoins,
444
+ getExploreLastTraded,
445
+ getExploreLastTradedUnique,
446
+ getExploreMostValuable,
447
+ getExploreNew,
448
+ getExploreTopGainers,
449
+ getExploreTopVolume24h,
450
+ getOnchainCoinDetails,
451
+ getProfile2 as getProfile,
452
+ getProfileOwned2 as getProfileOwned,
307
453
  getTradeFromLogs,
308
454
  tradeCoin,
309
455
  tradeCoinCall,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/actions/createCoin.ts","../src/constants.ts","../src/utils/validateClientNetwork.ts","../src/actions/tradeCoin.ts","../src/actions/getCoinDetails.ts","../src/actions/updateCoinURI.ts"],"sourcesContent":["import { zoraFactoryImplABI } from \"@zoralabs/coins\";\nimport {\n Address,\n PublicClient,\n TransactionReceipt,\n WalletClient,\n SimulateContractParameters,\n ContractEventArgsFromTopics,\n parseEventLogs,\n} from \"viem\";\nimport { COIN_FACTORY_ADDRESS } from \"../constants\";\nimport { validateClientNetwork } from \"src/utils/validateClientNetwork\";\n\nexport type CoinDeploymentLogArgs = ContractEventArgsFromTopics<\n typeof zoraFactoryImplABI,\n \"CoinCreated\"\n>;\n\ntype CreateCoinArgs = {\n name: string;\n symbol: string;\n uri: string;\n owners?: Address[];\n tickLower?: number;\n payoutRecipient: Address;\n platformReferrer?: Address;\n initialPurchaseWei?: bigint;\n};\n\nexport function createCoinCall({\n name,\n symbol,\n uri,\n owners,\n payoutRecipient,\n initialPurchaseWei = 0n,\n tickLower = -199200,\n platformReferrer = \"0x0000000000000000000000000000000000000000\",\n}: CreateCoinArgs): SimulateContractParameters<\n typeof zoraFactoryImplABI,\n \"deploy\"\n> {\n if (!owners) {\n owners = [payoutRecipient];\n }\n\n const currency = \"0x4200000000000000000000000000000000000006\";\n return {\n abi: zoraFactoryImplABI,\n functionName: \"deploy\",\n address: COIN_FACTORY_ADDRESS,\n args: [\n payoutRecipient,\n owners,\n uri,\n name,\n symbol,\n platformReferrer,\n currency,\n tickLower,\n initialPurchaseWei,\n ],\n value: initialPurchaseWei,\n } as const;\n}\n\n/**\n * Gets the deployed coin address from transaction receipt logs\n * @param receipt Transaction receipt containing the CoinCreated event\n * @returns The deployment information if found\n */\nexport function getCoinCreateFromLogs(\n receipt: TransactionReceipt,\n): CoinDeploymentLogArgs | undefined {\n const eventLogs = parseEventLogs({\n abi: zoraFactoryImplABI,\n logs: receipt.logs,\n });\n return eventLogs.find((log) => log.eventName === \"CoinCreated\")?.args;\n}\n\n// Update createCoin to return both receipt and coin address\nexport async function createCoin(\n call: CreateCoinArgs,\n walletClient: WalletClient,\n publicClient: PublicClient,\n) {\n validateClientNetwork(publicClient);\n const { request } = await publicClient.simulateContract({\n ...createCoinCall(call),\n account: walletClient.account,\n });\n const hash = await walletClient.writeContract(request);\n const receipt = await publicClient.waitForTransactionReceipt({ hash });\n const deployment = getCoinCreateFromLogs(receipt);\n\n return {\n hash,\n receipt,\n address: deployment?.coin,\n deployment,\n };\n}\n","import { zoraFactoryImplAddress } from \"@zoralabs/coins\";\nimport { Address } from \"viem\";\nimport { base } from \"viem/chains\";\n\n// this is the same across all chains due to deterministic deploys.\nexport const COIN_FACTORY_ADDRESS = zoraFactoryImplAddress[\"8453\"] as Address;\n\nexport const SUPERCHAIN_WETH_ADDRESS = '0x4200000000000000000000000000000000000006';\n\nexport const USDC_WETH_POOLS_BY_CHAIN: Record<number, Address> = {\n [base.id]: '0xd0b53D9277642d899DF5C87A3966A349A798F224',\n}\n","import { PublicClient } from \"viem\"\nimport { base, baseSepolia } from \"viem/chains\"\n\nexport const validateClientNetwork = (publicClient: PublicClient) => {\n const clientChainId = publicClient?.chain?.id;\n if (clientChainId === base.id) {\n return;\n }\n if (clientChainId === baseSepolia.id) {\n return;\n }\n\n throw new Error('Client network needs to be base or baseSepolia for current coin deployments.');\n}","import { coinABI } from \"@zoralabs/coins\";\nimport { validateClientNetwork } from \"src/utils/validateClientNetwork\";\nimport {\n Address,\n PublicClient,\n TransactionReceipt,\n WalletClient,\n SimulateContractParameters,\n parseEther,\n zeroAddress,\n ContractEventArgsFromTopics,\n parseEventLogs,\n} from \"viem\";\nimport { baseSepolia } from \"viem/chains\";\n\n// Define trade event args type\n\nexport type SellEventArgs = ContractEventArgsFromTopics<\n typeof coinABI,\n \"CoinSell\"\n>;\nexport type BuyEventArgs = ContractEventArgsFromTopics<\n typeof coinABI,\n \"CoinBuy\"\n>;\n\nexport type TradeEventArgs = SellEventArgs | BuyEventArgs;\n\n/**\n * Simulates a buy order to get the expected output amount\n * @param {Object} params - The simulation parameters\n * @param {Address} params.target - The target coin contract address\n * @param {bigint} params.requestedOrderSize - The desired input amount for the buy\n * @param {PublicClient} params.publicClient - The viem public client instance\n * @returns {Promise<{orderSize: bigint, amountOut: bigint}>} The simulated order size and output amount\n */\nexport async function simulateBuy({\n target,\n requestedOrderSize,\n publicClient,\n}: {\n target: Address;\n requestedOrderSize: bigint;\n publicClient: PublicClient;\n}): Promise<{ orderSize: bigint; amountOut: bigint }> {\n const numberResult = await publicClient.simulateContract({\n address: target,\n abi: coinABI,\n functionName: \"buy\",\n args: [\n zeroAddress,\n requestedOrderSize,\n 0n, // minAmountOut\n 0n, // sqrtPriceLimitX96\n zeroAddress, // tradeReferrer\n ],\n stateOverride: [\n {\n address: baseSepolia.contracts.multicall3.address,\n balance: parseEther(\"100000\"),\n },\n ],\n });\n const orderSize = numberResult.result[0];\n const amountOut = numberResult.result[1];\n return { orderSize, amountOut };\n}\n\n/**\n * Parameters for creating a trade call\n * @typedef {Object} TradeParams\n * @property {'sell' | 'buy'} direction - The trade direction\n * @property {Address} target - The target coin contract address\n * @property {Object} args - The trade arguments\n * @property {Address} args.recipient - The recipient of the trade output\n * @property {bigint} args.orderSize - The size of the order\n * @property {bigint} [args.minAmountOut] - The minimum amount to receive\n * @property {bigint} [args.sqrtPriceLimitX96] - The price limit for the trade\n * @property {Address} [args.tradeReferrer] - The referrer address for the trade\n */\ntype TradeParams = {\n direction: \"sell\" | \"buy\";\n target: Address;\n args: {\n recipient: Address;\n orderSize: bigint;\n minAmountOut?: bigint;\n sqrtPriceLimitX96?: bigint;\n tradeReferrer?: Address;\n };\n};\n\n/**\n * Creates a trade call parameters object for buy or sell\n * @param {TradeParams} params - The trade parameters\n * @returns {SimulateContractParameters} The contract call parameters\n */\nexport function tradeCoinCall({\n target,\n direction,\n args: {\n recipient,\n orderSize,\n minAmountOut = 0n,\n sqrtPriceLimitX96 = 0n,\n tradeReferrer = zeroAddress,\n },\n}: TradeParams): SimulateContractParameters {\n return {\n abi: coinABI,\n functionName: direction,\n address: target,\n args: [\n recipient,\n orderSize,\n minAmountOut,\n sqrtPriceLimitX96,\n tradeReferrer,\n ],\n value: direction === \"buy\" ? orderSize : 0n,\n } as const;\n}\n\n/**\n * Gets the trade event from transaction receipt logs\n * @param {TransactionReceipt} receipt - The transaction receipt containing the logs\n * @param {'buy' | 'sell'} direction - The direction of the trade\n * @returns {TradeEventArgs | undefined} The decoded trade event args if found\n */\nexport function getTradeFromLogs(\n receipt: TransactionReceipt,\n direction: \"buy\" | \"sell\",\n): TradeEventArgs | undefined {\n const eventLogs = parseEventLogs({\n abi: coinABI,\n logs: receipt.logs,\n });\n\n if (direction === \"buy\") {\n return eventLogs.find((log) => log.eventName === \"CoinBuy\")?.args;\n }\n return eventLogs.find((log) => log.eventName === \"CoinSell\")?.args;\n}\n\n/**\n * Executes a trade transaction\n * @param {TradeParams} params - The trade parameters\n * @param {PublicClient} publicClient - The viem public client instance\n * @param {WalletClient} walletClient - The viem wallet client instance\n * @returns {Promise<{\n * hash: `0x${string}`,\n * receipt: TransactionReceipt,\n * trade: TradeEventArgs | undefined\n * }>} The transaction result with trade details\n */\nexport async function tradeCoin(\n params: TradeParams,\n walletClient: WalletClient,\n publicClient: PublicClient,\n) {\n validateClientNetwork(publicClient);\n const { request } = await publicClient.simulateContract({\n ...tradeCoinCall(params),\n account: walletClient.account,\n });\n const hash = await walletClient.writeContract(request);\n const receipt = await publicClient.waitForTransactionReceipt({ hash });\n const trade = getTradeFromLogs(receipt, params.direction);\n\n return {\n hash,\n receipt,\n trade,\n };\n}\n","import { coinABI, iUniswapV3PoolABI } from \"@zoralabs/coins\";\nimport { SUPERCHAIN_WETH_ADDRESS, USDC_WETH_POOLS_BY_CHAIN } from \"src/constants\";\nimport { validateClientNetwork } from \"src/utils/validateClientNetwork\";\nimport { Address, erc20Abi, formatEther, isAddressEqual, PublicClient, zeroAddress } from \"viem\";\n\n\ntype Slot0Result = {\n sqrtPriceX96: bigint;\n tick: number;\n observationIndex: number;\n observationCardinality: number;\n observationCardinalityNext: number;\n feeProtocol: number;\n unlocked: boolean;\n};\n\ntype PricingResult = {\n eth: bigint,\n usdc: bigint | null,\n usdcDecimal: number | null,\n ethDecimal: number,\n}\n\n/**\n * Represents the current state of a coin\n * @typedef {Object} CoinDetails\n * @property {bigint} balance - The user's balance of the coin\n * @property {PricingResult} marketCap - The market cap of the coin\n * @property {PricingResult} liquidity - The liquidity of the coin\n * @property {Address} pool - Pool address\n * @property {Slot0Result} poolState - Current state of the UniswapV3 pool\n * @property {Address[]} owners - List of owners for the coin\n * @property {Address} payoutRecipient - The payout recipient address\n */\nexport type CoinDetails = {\n balance: bigint;\n marketCap: PricingResult;\n liquidity: PricingResult;\n pool: Address;\n poolState: Slot0Result;\n owners: readonly Address[],\n payoutRecipient: Address,\n};\n\n/**\n * Gets the current state of a coin for a user\n * @param {Object} params - The query parameters\n * @param {Address} params.coin - The coin contract address\n * @param {Address} params.user - The user address to check balance for\n * @param {PublicClient} params.publicClient - The viem public client instance\n * @returns {Promise<CoinDetails>} The coin's current state\n */\nexport async function getCoinDetails({\n coin,\n user = zeroAddress,\n publicClient,\n}: {\n coin: Address;\n user?: Address;\n publicClient: PublicClient;\n}): Promise<CoinDetails> {\n validateClientNetwork(publicClient);\n const [balance, pool, owners, payoutRecipient] = await publicClient.multicall({\n contracts: [\n {\n address: coin,\n abi: coinABI,\n functionName: \"balanceOf\",\n args: [user],\n },\n {\n address: coin,\n abi: coinABI,\n functionName: \"poolAddress\",\n },\n {\n address: coin,\n abi: coinABI,\n functionName: 'owners',\n },\n {\n address: coin,\n abi: coinABI,\n functionName: 'payoutRecipient',\n }\n ],\n allowFailure: false,\n });\n\n const USDC_WETH_POOL = USDC_WETH_POOLS_BY_CHAIN[publicClient.chain?.id || 0];\n\n const [coinWethPoolSlot0, coinWethPoolToken0, coinReservesRaw, coinTotalSupply, wethReservesRaw, usdcWethSlot0] = await publicClient.multicall({\n contracts: [{\n address: pool,\n abi: iUniswapV3PoolABI,\n functionName: \"slot0\",\n },\n {\n address: pool,\n abi: iUniswapV3PoolABI,\n functionName: 'token0'\n }, {\n address: coin,\n abi: erc20Abi,\n functionName: 'balanceOf',\n args: [pool],\n },\n {\n address: coin,\n abi: coinABI,\n functionName: 'totalSupply',\n }, {\n address: SUPERCHAIN_WETH_ADDRESS,\n abi: erc20Abi,\n functionName: 'balanceOf',\n args: [pool],\n }, {\n address: USDC_WETH_POOL ?? coin,\n abi: iUniswapV3PoolABI,\n functionName: 'slot0',\n }], allowFailure: false\n });\n\n const wethPriceInUsdc = USDC_WETH_POOL ? uniswapV3SqrtPriceToBigIntScaled(\n usdcWethSlot0.sqrtPriceX96,\n 18,\n 6,\n true,\n 18\n ) : null;\n\n const coinPriceInWeth = uniswapV3SqrtPriceToBigIntScaled(\n coinWethPoolSlot0.sqrtPriceX96,\n 18,\n 18,\n isAddressEqual(coinWethPoolToken0, coin),\n 18\n );\n\n // Divide by 10^18 to remove percision from `coinPriceInWeth` after math since bigint is decimal.\n const marketCap = coinPriceInWeth * coinTotalSupply / 10n ** 18n;\n\n const wethLiquidity = wethReservesRaw;\n // Divide by 10^18 to remove percision from `coinPriceInWeth` after math since bigint is decimal.\n const tokenLiquidity = coinReservesRaw * coinPriceInWeth / 10n ** 18n;\n\n return {\n balance,\n pool,\n owners,\n payoutRecipient,\n marketCap: convertEthOutput(marketCap, wethPriceInUsdc),\n liquidity: convertEthOutput(wethLiquidity + tokenLiquidity, wethPriceInUsdc),\n poolState: coinWethPoolSlot0,\n };\n}\n\n\nfunction convertEthOutput(amountETH: bigint, wethToUsdc: bigint | null) {\n return { eth: amountETH, ethDecimal: parseFloat(formatEther(amountETH)), usdc: wethToUsdc ? amountETH * wethToUsdc : null, usdcDecimal: wethToUsdc ? parseFloat(formatEther(amountETH * wethToUsdc / 10n ** 18n)) : null }\n}\n\nfunction uniswapV3SqrtPriceToBigIntScaled(\n sqrtPriceX96: bigint,\n token0Decimals: number,\n token1Decimals: number,\n isToken0Coin: boolean,\n scaleDecimals: number = 18\n): bigint {\n // (sqrtPrice^2 / 2^192) => ratio\n // We'll do: ratioScaled = (sqrtPrice^2 * 10^scaleDecimals) / 2^192\n const numerator = sqrtPriceX96 * sqrtPriceX96;\n const denominator = 2n ** 192n;\n const scaleFactor = 10n ** BigInt(scaleDecimals);\n\n // raw ratioScaled\n let ratioScaled = (numerator * scaleFactor) / denominator; // BigInt\n\n // Adjust for difference in decimals:\n // ratioScaled *= 10^(dec0 - dec1)\n const decimalsDiff = BigInt(token0Decimals - token1Decimals);\n if (decimalsDiff > 0n) {\n ratioScaled *= 10n ** decimalsDiff;\n } else if (decimalsDiff < 0n) {\n ratioScaled /= 10n ** (-decimalsDiff);\n }\n\n if (!isToken0Coin) {\n // We want the reciprocal: coin is token1 => coinPriceInToken0 = 1 / ratio\n // But we also want it scaled by 10^scaleDecimals\n // reciprocalScaled = (10^scaleDecimals * 10^(decimalsDiff)) / ratioScaled\n // (assuming ratioScaled != 0)\n if (ratioScaled === 0n) {\n return 0n; // or some huge number representing infinity\n }\n ratioScaled = (scaleFactor * scaleFactor) / ratioScaled;\n // or if we already included decimalsDiff above, handle carefully.\n }\n\n return ratioScaled;\n}\n","import { coinABI } from \"@zoralabs/coins\";\nimport { validateClientNetwork } from \"src/utils/validateClientNetwork\";\nimport {\n Address,\n parseEventLogs,\n PublicClient,\n SimulateContractParameters,\n WalletClient,\n} from \"viem\";\n\ntype UpdateCoinURIArgs = {\n coin: Address;\n newURI: string;\n};\n\nexport function updateCoinURICall({\n newURI,\n coin,\n}: UpdateCoinURIArgs): SimulateContractParameters {\n if (!newURI.startsWith(\"ipfs://\")) {\n throw new Error(\"URI needs to be an ipfs:// prefix uri\");\n }\n\n return {\n abi: coinABI,\n address: coin,\n functionName: \"setContractURI\",\n args: [newURI],\n };\n}\n\nexport async function updateCoinURI(\n args: UpdateCoinURIArgs,\n walletClient: WalletClient,\n publicClient: PublicClient,\n) {\n validateClientNetwork(publicClient);\n const call = updateCoinURICall(args);\n const { request } = await publicClient.simulateContract({\n ...call,\n account: walletClient.account!,\n });\n const hash = await walletClient.writeContract(request);\n const receipt = await publicClient.waitForTransactionReceipt({ hash });\n const eventLogs = parseEventLogs({ abi: coinABI, logs: receipt.logs });\n const uriUpdated = eventLogs.find(\n (log) => log.eventName === \"ContractURIUpdated\",\n );\n\n return { hash, receipt, uriUpdated };\n}\n"],"mappings":";AAAA,SAAS,0BAA0B;AACnC;AAAA,EAOE;AAAA,OACK;;;ACTP,SAAS,8BAA8B;AAEvC,SAAS,YAAY;AAGd,IAAM,uBAAuB,uBAAuB,MAAM;AAE1D,IAAM,0BAA0B;AAEhC,IAAM,2BAAoD;AAAA,EAC7D,CAAC,KAAK,EAAE,GAAG;AACf;;;ACVA,SAAS,QAAAA,OAAM,mBAAmB;AAE3B,IAAM,wBAAwB,CAAC,iBAA+B;AACjE,QAAM,gBAAgB,cAAc,OAAO;AAC3C,MAAI,kBAAkBA,MAAK,IAAI;AAC3B;AAAA,EACJ;AACA,MAAI,kBAAkB,YAAY,IAAI;AAClC;AAAA,EACJ;AAEA,QAAM,IAAI,MAAM,8EAA8E;AAClG;;;AFgBO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB,YAAY;AAAA,EACZ,mBAAmB;AACrB,GAGE;AACA,MAAI,CAAC,QAAQ;AACX,aAAS,CAAC,eAAe;AAAA,EAC3B;AAEA,QAAM,WAAW;AACjB,SAAO;AAAA,IACL,KAAK;AAAA,IACL,cAAc;AAAA,IACd,SAAS;AAAA,IACT,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,OAAO;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,CAAC;AACrE,QAAM,aAAa,UAAU;AAAA,IAC3B,CAAC,QAAQ,IAAI,cAAc;AAAA,EAC7B;AAEA,SAAO,EAAE,MAAM,SAAS,WAAW;AACrC;","names":["base","parseEventLogs","baseSepolia","parseEventLogs","coinABI","zeroAddress","coinABI","coinABI","parseEventLogs","coinABI"]}
1
+ {"version":3,"sources":["../src/actions/createCoin.ts","../src/constants.ts","../src/utils/validateClientNetwork.ts","../src/actions/tradeCoin.ts","../src/actions/getOnchainCoinDetails.ts","../src/actions/updateCoinURI.ts","../src/client/client.gen.ts","../src/client/sdk.gen.ts","../src/api/api-key.ts","../src/api/queries.ts","../src/api/explore.ts"],"sourcesContent":["import { zoraFactoryImplABI } from \"@zoralabs/coins\";\nimport {\n Address,\n PublicClient,\n TransactionReceipt,\n WalletClient,\n SimulateContractParameters,\n ContractEventArgsFromTopics,\n parseEventLogs,\n} from \"viem\";\nimport { COIN_FACTORY_ADDRESS } from \"../constants\";\nimport { validateClientNetwork } from \"src/utils/validateClientNetwork\";\n\nexport type CoinDeploymentLogArgs = ContractEventArgsFromTopics<\n typeof zoraFactoryImplABI,\n \"CoinCreated\"\n>;\n\ntype CreateCoinArgs = {\n name: string;\n symbol: string;\n uri: string;\n owners?: Address[];\n tickLower?: number;\n payoutRecipient: Address;\n platformReferrer?: Address;\n initialPurchaseWei?: bigint;\n};\n\nexport function createCoinCall({\n name,\n symbol,\n uri,\n owners,\n payoutRecipient,\n initialPurchaseWei = 0n,\n tickLower = -199200,\n platformReferrer = \"0x0000000000000000000000000000000000000000\",\n}: CreateCoinArgs): SimulateContractParameters<\n typeof zoraFactoryImplABI,\n \"deploy\"\n> {\n if (!owners) {\n owners = [payoutRecipient];\n }\n\n const currency = \"0x4200000000000000000000000000000000000006\";\n return {\n abi: zoraFactoryImplABI,\n functionName: \"deploy\",\n address: COIN_FACTORY_ADDRESS,\n args: [\n payoutRecipient,\n owners,\n uri,\n name,\n symbol,\n platformReferrer,\n currency,\n tickLower,\n initialPurchaseWei,\n ],\n value: initialPurchaseWei,\n } as const;\n}\n\n/**\n * Gets the deployed coin address from transaction receipt logs\n * @param receipt Transaction receipt containing the CoinCreated event\n * @returns The deployment information if found\n */\nexport function getCoinCreateFromLogs(\n receipt: TransactionReceipt,\n): CoinDeploymentLogArgs | undefined {\n const eventLogs = parseEventLogs({\n abi: zoraFactoryImplABI,\n logs: receipt.logs,\n });\n return eventLogs.find((log) => log.eventName === \"CoinCreated\")?.args;\n}\n\n// Update createCoin to return both receipt and coin address\nexport async function createCoin(\n call: CreateCoinArgs,\n walletClient: WalletClient,\n publicClient: PublicClient,\n) {\n validateClientNetwork(publicClient);\n const { request } = await publicClient.simulateContract({\n ...createCoinCall(call),\n account: walletClient.account,\n });\n\n // Add a 1/5th buffer on gas.\n if (request.gas) {\n request.gas = request.gas * 6n / 5n;\n }\n const hash = await walletClient.writeContract(request);\n const receipt = await publicClient.waitForTransactionReceipt({ hash });\n const deployment = getCoinCreateFromLogs(receipt);\n\n return {\n hash,\n receipt,\n address: deployment?.coin,\n deployment,\n };\n}\n","import { zoraFactoryImplAddress } from \"@zoralabs/coins\";\nimport { Address } from \"viem\";\nimport { base } from \"viem/chains\";\n\n// this is the same across all chains due to deterministic deploys.\nexport const COIN_FACTORY_ADDRESS = zoraFactoryImplAddress[\"8453\"] as Address;\n\nexport const SUPERCHAIN_WETH_ADDRESS = '0x4200000000000000000000000000000000000006';\n\nexport const USDC_WETH_POOLS_BY_CHAIN: Record<number, Address> = {\n [base.id]: '0xd0b53D9277642d899DF5C87A3966A349A798F224',\n}\n","import { PublicClient } from \"viem\"\nimport { base, baseSepolia } from \"viem/chains\"\n\nexport const validateClientNetwork = (publicClient: PublicClient<any, any, any, any>) => {\n const clientChainId = publicClient?.chain?.id;\n if (clientChainId === base.id) {\n return;\n }\n if (clientChainId === baseSepolia.id) {\n return;\n }\n\n throw new Error('Client network needs to be base or baseSepolia for current coin deployments.');\n}","import { coinABI } from \"@zoralabs/coins\";\nimport { validateClientNetwork } from \"src/utils/validateClientNetwork\";\nimport {\n Address,\n PublicClient,\n TransactionReceipt,\n WalletClient,\n SimulateContractParameters,\n parseEther,\n zeroAddress,\n ContractEventArgsFromTopics,\n parseEventLogs,\n} from \"viem\";\nimport { baseSepolia } from \"viem/chains\";\n\n// Define trade event args type\n\nexport type SellEventArgs = ContractEventArgsFromTopics<\n typeof coinABI,\n \"CoinSell\"\n>;\nexport type BuyEventArgs = ContractEventArgsFromTopics<\n typeof coinABI,\n \"CoinBuy\"\n>;\n\nexport type TradeEventArgs = SellEventArgs | BuyEventArgs;\n\n/**\n * Simulates a buy order to get the expected output amount\n * @param {Object} params - The simulation parameters\n * @param {Address} params.target - The target coin contract address\n * @param {bigint} params.requestedOrderSize - The desired input amount for the buy\n * @param {PublicClient} params.publicClient - The viem public client instance\n * @returns {Promise<{orderSize: bigint, amountOut: bigint}>} The simulated order size and output amount\n */\nexport async function simulateBuy({\n target,\n requestedOrderSize,\n publicClient,\n}: {\n target: Address;\n requestedOrderSize: bigint;\n publicClient: PublicClient;\n}): Promise<{ orderSize: bigint; amountOut: bigint }> {\n const numberResult = await publicClient.simulateContract({\n address: target,\n abi: coinABI,\n functionName: \"buy\",\n args: [\n zeroAddress,\n requestedOrderSize,\n 0n, // minAmountOut\n 0n, // sqrtPriceLimitX96\n zeroAddress, // tradeReferrer\n ],\n stateOverride: [\n {\n address: baseSepolia.contracts.multicall3.address,\n balance: parseEther(\"100000\"),\n },\n ],\n });\n const orderSize = numberResult.result[0];\n const amountOut = numberResult.result[1];\n return { orderSize, amountOut };\n}\n\n/**\n * Parameters for creating a trade call\n * @typedef {Object} TradeParams\n * @property {'sell' | 'buy'} direction - The trade direction\n * @property {Address} target - The target coin contract address\n * @property {Object} args - The trade arguments\n * @property {Address} args.recipient - The recipient of the trade output\n * @property {bigint} args.orderSize - The size of the order\n * @property {bigint} [args.minAmountOut] - The minimum amount to receive\n * @property {bigint} [args.sqrtPriceLimitX96] - The price limit for the trade\n * @property {Address} [args.tradeReferrer] - The referrer address for the trade\n */\ntype TradeParams = {\n direction: \"sell\" | \"buy\";\n target: Address;\n args: {\n recipient: Address;\n orderSize: bigint;\n minAmountOut?: bigint;\n sqrtPriceLimitX96?: bigint;\n tradeReferrer?: Address;\n };\n};\n\n/**\n * Creates a trade call parameters object for buy or sell\n * @param {TradeParams} params - The trade parameters\n * @returns {SimulateContractParameters} The contract call parameters\n */\nexport function tradeCoinCall({\n target,\n direction,\n args: {\n recipient,\n orderSize,\n minAmountOut = 0n,\n sqrtPriceLimitX96 = 0n,\n tradeReferrer = zeroAddress,\n },\n}: TradeParams): SimulateContractParameters {\n return {\n abi: coinABI,\n functionName: direction,\n address: target,\n args: [\n recipient,\n orderSize,\n minAmountOut,\n sqrtPriceLimitX96,\n tradeReferrer,\n ],\n value: direction === \"buy\" ? orderSize : 0n,\n } as const;\n}\n\n/**\n * Gets the trade event from transaction receipt logs\n * @param {TransactionReceipt} receipt - The transaction receipt containing the logs\n * @param {'buy' | 'sell'} direction - The direction of the trade\n * @returns {TradeEventArgs | undefined} The decoded trade event args if found\n */\nexport function getTradeFromLogs(\n receipt: TransactionReceipt,\n direction: \"buy\" | \"sell\",\n): TradeEventArgs | undefined {\n const eventLogs = parseEventLogs({\n abi: coinABI,\n logs: receipt.logs,\n });\n\n if (direction === \"buy\") {\n return eventLogs.find((log) => log.eventName === \"CoinBuy\")?.args;\n }\n return eventLogs.find((log) => log.eventName === \"CoinSell\")?.args;\n}\n\n/**\n * Executes a trade transaction\n * @param {TradeParams} params - The trade parameters\n * @param {PublicClient} publicClient - The viem public client instance\n * @param {WalletClient} walletClient - The viem wallet client instance\n * @returns {Promise<{\n * hash: `0x${string}`,\n * receipt: TransactionReceipt,\n * trade: TradeEventArgs | undefined\n * }>} The transaction result with trade details\n */\nexport async function tradeCoin(\n params: TradeParams,\n walletClient: WalletClient,\n publicClient: PublicClient,\n) {\n validateClientNetwork(publicClient);\n const { request } = await publicClient.simulateContract({\n ...tradeCoinCall(params),\n account: walletClient.account,\n });\n const hash = await walletClient.writeContract(request);\n const receipt = await publicClient.waitForTransactionReceipt({ hash });\n const trade = getTradeFromLogs(receipt, params.direction);\n\n return {\n hash,\n receipt,\n trade,\n };\n}\n","import { coinABI, iUniswapV3PoolABI } from \"@zoralabs/coins\";\nimport {\n SUPERCHAIN_WETH_ADDRESS,\n USDC_WETH_POOLS_BY_CHAIN,\n} from \"src/constants\";\nimport { GenericPublicClient } from \"src/utils/genericPublicClient\";\nimport { validateClientNetwork } from \"src/utils/validateClientNetwork\";\nimport {\n Address,\n erc20Abi,\n formatEther,\n isAddressEqual,\n zeroAddress,\n} from \"viem\";\n\ntype Slot0Result = {\n sqrtPriceX96: bigint;\n tick: number;\n observationIndex: number;\n observationCardinality: number;\n observationCardinalityNext: number;\n feeProtocol: number;\n unlocked: boolean;\n};\n\ntype PricingResult = {\n eth: bigint;\n usdc: bigint | null;\n usdcDecimal: number | null;\n ethDecimal: number;\n};\n\n/**\n * Represents the current state of a coin\n * @typedef {Object} OnchainCoinDetails\n * @property {bigint} balance - The user's balance of the coin\n * @property {PricingResult} marketCap - The market cap of the coin\n * @property {PricingResult} liquidity - The liquidity of the coin\n * @property {Address} pool - Pool address\n * @property {Slot0Result} poolState - Current state of the UniswapV3 pool\n * @property {Address[]} owners - List of owners for the coin\n * @property {Address} payoutRecipient - The payout recipient address\n */\nexport type OnchainCoinDetails = {\n balance: bigint;\n marketCap: PricingResult;\n liquidity: PricingResult;\n pool: Address;\n poolState: Slot0Result;\n owners: readonly Address[];\n payoutRecipient: Address;\n};\n\n/**\n * Gets the current state of a coin for a user\n * @param {Object} params - The query parameters\n * @param {Address} params.coin - The coin contract address\n * @param {Address} params.user - The user address to check balance for\n * @param {PublicClient} params.publicClient - The viem public client instance\n * @returns {Promise<OnchainCoinDetails>} The coin's current state\n */\nexport async function getOnchainCoinDetails({\n coin,\n user = zeroAddress,\n publicClient,\n}: {\n coin: Address;\n user?: Address;\n publicClient: GenericPublicClient;\n}): Promise<OnchainCoinDetails> {\n validateClientNetwork(publicClient);\n const [balance, pool, owners, payoutRecipient] = await publicClient.multicall(\n {\n contracts: [\n {\n address: coin,\n abi: coinABI,\n functionName: \"balanceOf\",\n args: [user],\n },\n {\n address: coin,\n abi: coinABI,\n functionName: \"poolAddress\",\n },\n {\n address: coin,\n abi: coinABI,\n functionName: \"owners\",\n },\n {\n address: coin,\n abi: coinABI,\n functionName: \"payoutRecipient\",\n },\n ],\n allowFailure: false,\n },\n );\n\n const USDC_WETH_POOL = USDC_WETH_POOLS_BY_CHAIN[publicClient.chain?.id || 0];\n\n const [\n coinWethPoolSlot0,\n coinWethPoolToken0,\n coinReservesRaw,\n coinTotalSupply,\n wethReservesRaw,\n usdcWethSlot0,\n ] = await publicClient.multicall({\n contracts: [\n {\n address: pool,\n abi: iUniswapV3PoolABI,\n functionName: \"slot0\",\n },\n {\n address: pool,\n abi: iUniswapV3PoolABI,\n functionName: \"token0\",\n },\n {\n address: coin,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [pool],\n },\n {\n address: coin,\n abi: coinABI,\n functionName: \"totalSupply\",\n },\n {\n address: SUPERCHAIN_WETH_ADDRESS,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [pool],\n },\n {\n address: USDC_WETH_POOL ?? coin,\n abi: iUniswapV3PoolABI,\n functionName: \"slot0\",\n },\n ],\n allowFailure: false,\n });\n\n const wethPriceInUsdc = USDC_WETH_POOL\n ? uniswapV3SqrtPriceToBigIntScaled(\n usdcWethSlot0.sqrtPriceX96,\n 18,\n 6,\n true,\n 18,\n )\n : null;\n\n const coinPriceInWeth = uniswapV3SqrtPriceToBigIntScaled(\n coinWethPoolSlot0.sqrtPriceX96,\n 18,\n 18,\n isAddressEqual(coinWethPoolToken0, coin),\n 18,\n );\n\n // Divide by 10^18 to remove percision from `coinPriceInWeth` after math since bigint is decimal.\n const marketCap = (coinPriceInWeth * coinTotalSupply) / 10n ** 18n;\n\n const wethLiquidity = wethReservesRaw;\n // Divide by 10^18 to remove percision from `coinPriceInWeth` after math since bigint is decimal.\n const tokenLiquidity = (coinReservesRaw * coinPriceInWeth) / 10n ** 18n;\n\n return {\n balance,\n pool,\n owners,\n payoutRecipient,\n marketCap: convertEthOutput(marketCap, wethPriceInUsdc),\n liquidity: convertEthOutput(\n wethLiquidity + tokenLiquidity,\n wethPriceInUsdc,\n ),\n poolState: coinWethPoolSlot0,\n };\n}\n\nfunction convertEthOutput(amountETH: bigint, wethToUsdc: bigint | null) {\n return {\n eth: amountETH,\n ethDecimal: parseFloat(formatEther(amountETH)),\n usdc: wethToUsdc ? amountETH * wethToUsdc : null,\n usdcDecimal: wethToUsdc\n ? parseFloat(formatEther((amountETH * wethToUsdc) / 10n ** 18n))\n : null,\n };\n}\n\nfunction uniswapV3SqrtPriceToBigIntScaled(\n sqrtPriceX96: bigint,\n token0Decimals: number,\n token1Decimals: number,\n isToken0Coin: boolean,\n scaleDecimals: number = 18,\n): bigint {\n // (sqrtPrice^2 / 2^192) => ratio\n // We'll do: ratioScaled = (sqrtPrice^2 * 10^scaleDecimals) / 2^192\n const numerator = sqrtPriceX96 * sqrtPriceX96;\n const denominator = 2n ** 192n;\n const scaleFactor = 10n ** BigInt(scaleDecimals);\n\n // raw ratioScaled\n let ratioScaled = (numerator * scaleFactor) / denominator; // BigInt\n\n // Adjust for difference in decimals:\n // ratioScaled *= 10^(dec0 - dec1)\n const decimalsDiff = BigInt(token0Decimals - token1Decimals);\n if (decimalsDiff > 0n) {\n ratioScaled *= 10n ** decimalsDiff;\n } else if (decimalsDiff < 0n) {\n ratioScaled /= 10n ** -decimalsDiff;\n }\n\n if (!isToken0Coin) {\n // We want the reciprocal: coin is token1 => coinPriceInToken0 = 1 / ratio\n // But we also want it scaled by 10^scaleDecimals\n // reciprocalScaled = (10^scaleDecimals * 10^(decimalsDiff)) / ratioScaled\n // (assuming ratioScaled != 0)\n if (ratioScaled === 0n) {\n return 0n; // or some huge number representing infinity\n }\n ratioScaled = (scaleFactor * scaleFactor) / ratioScaled;\n // or if we already included decimalsDiff above, handle carefully.\n }\n\n return ratioScaled;\n}\n","import { coinABI } from \"@zoralabs/coins\";\nimport { validateClientNetwork } from \"src/utils/validateClientNetwork\";\nimport {\n Address,\n parseEventLogs,\n PublicClient,\n SimulateContractParameters,\n WalletClient,\n} from \"viem\";\n\ntype UpdateCoinURIArgs = {\n coin: Address;\n newURI: string;\n};\n\nexport function updateCoinURICall({\n newURI,\n coin,\n}: UpdateCoinURIArgs): SimulateContractParameters {\n if (!newURI.startsWith(\"ipfs://\")) {\n throw new Error(\"URI needs to be an ipfs:// prefix uri\");\n }\n\n return {\n abi: coinABI,\n address: coin,\n functionName: \"setContractURI\",\n args: [newURI],\n };\n}\n\nexport async function updateCoinURI(\n args: UpdateCoinURIArgs,\n walletClient: WalletClient,\n publicClient: PublicClient,\n) {\n validateClientNetwork(publicClient);\n const call = updateCoinURICall(args);\n const { request } = await publicClient.simulateContract({\n ...call,\n account: walletClient.account!,\n });\n const hash = await walletClient.writeContract(request);\n const receipt = await publicClient.waitForTransactionReceipt({ hash });\n const eventLogs = parseEventLogs({ abi: coinABI, logs: receipt.logs });\n const uriUpdated = eventLogs.find(\n (log) => log.eventName === \"ContractURIUpdated\",\n );\n\n return { hash, receipt, uriUpdated };\n}\n","// This file is auto-generated by @hey-api/openapi-ts\n\nimport type { ClientOptions } from './types.gen';\nimport { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';\n\n/**\n * The `createClientConfig()` function will be called on client initialization\n * and the returned object will become the client's initial configuration.\n *\n * You may want to initialize your client this way instead of calling\n * `setConfig()`. This is useful for example if you're using Next.js\n * to ensure your client always has the correct values.\n */\nexport type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;\n\nexport const client = createClient(createConfig<ClientOptions>({\n baseUrl: 'https://api-sdk.zora.engineering/'\n}));","// This file is auto-generated by @hey-api/openapi-ts\n\nimport type {\n Options as ClientOptions,\n TDataShape,\n Client,\n} from \"@hey-api/client-fetch\";\nimport type {\n GetCoinData,\n GetCoinResponse,\n GetCoinCommentsData,\n GetCoinCommentsResponse,\n GetCoinsData,\n GetCoinsResponse,\n GetExploreData,\n GetExploreResponse,\n GetProfileData,\n GetProfileResponse,\n GetProfileOwnedData,\n GetProfileOwnedResponse,\n} from \"./types.gen\";\nimport { client as _heyApiClient } from \"./client.gen\";\n\nexport type Options<\n TData extends TDataShape = TDataShape,\n ThrowOnError extends boolean = boolean,\n> = ClientOptions<TData, ThrowOnError> & {\n /**\n * You can provide a client instance returned by `createClient()` instead of\n * individual options. This might be also useful if you want to implement a\n * custom client.\n */\n client?: Client;\n /**\n * You can pass arbitrary values through the `meta` object. This can be\n * used to access values that aren't defined as part of the SDK function.\n */\n meta?: Record<string, unknown>;\n};\n\nexport const getCoin = <ThrowOnError extends boolean = false>(\n options: Options<GetCoinData, ThrowOnError>,\n) => {\n return (options.client ?? _heyApiClient).get<\n GetCoinResponse,\n unknown,\n ThrowOnError\n >({\n url: \"/coin\",\n ...options,\n });\n};\n\nexport const getCoinComments = <ThrowOnError extends boolean = false>(\n options: Options<GetCoinCommentsData, ThrowOnError>,\n) => {\n return (options.client ?? _heyApiClient).get<\n GetCoinCommentsResponse,\n unknown,\n ThrowOnError\n >({\n url: \"/coinComments\",\n ...options,\n });\n};\n\nexport const getCoins = <ThrowOnError extends boolean = false>(\n options: Options<GetCoinsData, ThrowOnError>,\n) => {\n return (options.client ?? _heyApiClient).get<\n GetCoinsResponse,\n unknown,\n ThrowOnError\n >({\n url: \"/coins\",\n ...options,\n });\n};\n\nexport const getExplore = <ThrowOnError extends boolean = false>(\n options: Options<GetExploreData, ThrowOnError>,\n) => {\n return (options.client ?? _heyApiClient).get<\n GetExploreResponse,\n unknown,\n ThrowOnError\n >({\n url: \"/explore\",\n ...options,\n });\n};\n\nexport const getProfile = <ThrowOnError extends boolean = false>(\n options: Options<GetProfileData, ThrowOnError>,\n) => {\n return (options.client ?? _heyApiClient).get<\n GetProfileResponse,\n unknown,\n ThrowOnError\n >({\n url: \"/profile\",\n ...options,\n });\n};\n\nexport const getProfileOwned = <ThrowOnError extends boolean = false>(\n options: Options<GetProfileOwnedData, ThrowOnError>,\n) => {\n return (options.client ?? _heyApiClient).get<\n GetProfileOwnedResponse,\n unknown,\n ThrowOnError\n >({\n url: \"/profileOwned\",\n ...options,\n });\n};\n","let apiKey: string | undefined;\nexport function setApiKey(key: string) {\n apiKey = key;\n}\n\nexport function getApiKeyMeta() {\n if (!apiKey) {\n return {};\n }\n return {\n headers: {\n \"api-key\": apiKey,\n },\n };\n}\n","import {\n GetCoinCommentsData,\n GetCoinData,\n GetProfileData,\n GetProfileOwnedData,\n} from \"src/client\";\nimport {\n getCoin as getCoinSDK,\n getCoins as getCoinsSDK,\n getCoinComments as getCoinCommentsSDK,\n getProfile as getProfileSDK,\n getProfileOwned as getProfileOwnedSDK,\n} from \"../client/sdk.gen\";\nimport { getApiKeyMeta } from \"./api-key\";\n\nexport const getCoin = async (query: GetCoinData[\"query\"]) => {\n return await getCoinSDK({\n query,\n meta: getApiKeyMeta(),\n });\n};\n\nexport const getCoins = async ({\n coinAddresses,\n chainId,\n}: {\n coinAddresses: string[];\n chainId?: number;\n}) => {\n return await getCoinsSDK({\n query: {\n coins: coinAddresses.map((collectionAddress) => ({\n chainId,\n collectionAddress,\n })),\n },\n meta: getApiKeyMeta(),\n });\n};\n\nexport const getCoinComments = async (query: GetCoinCommentsData[\"query\"]) => {\n return await getCoinCommentsSDK({\n query,\n meta: getApiKeyMeta(),\n });\n};\n\nexport const getProfile = async (query: GetProfileData[\"query\"]) => {\n return await getProfileSDK({\n query,\n meta: getApiKeyMeta(),\n });\n};\n\nexport const getProfileOwned = async (query: GetProfileOwnedData[\"query\"]) => {\n return await getProfileOwnedSDK({\n query,\n meta: getApiKeyMeta(),\n });\n};\n","import { getExplore as getExploreSDK } from \"../client/sdk.gen\";\nimport type { GetExploreData } from \"../client/types.gen\";\nimport { Options } from \"@hey-api/client-fetch\";\nimport { getApiKeyMeta } from \"./api-key\";\n\n/**\n * The inner type for the explore queries that omits listType.\n * This is used to create the query object for the explore queries.\n */\ntype QueryInnerType = {\n query: Omit<GetExploreData[\"query\"], \"listType\">;\n} & Omit<GetExploreData, \"query\">;\n\n/**\n * Creates an explore query with the specified list type\n */\nconst createExploreQuery = <T extends boolean = false>(\n listType: GetExploreData[\"query\"][\"listType\"],\n options?: Options<QueryInnerType, T>,\n) =>\n getExploreSDK({\n ...options,\n query: { ...options?.query, listType },\n meta: getApiKeyMeta(),\n });\n\n/** Get top gaining coins */\nexport const getExploreTopGainers = <T extends boolean = false>(\n options?: Options<QueryInnerType, T>,\n) => createExploreQuery(\"TOP_GAINERS\", options);\n\n/** Get coins with highest 24h volume */\nexport const getExploreTopVolume24h = <T extends boolean = false>(\n options?: Options<QueryInnerType, T>,\n) => createExploreQuery(\"TOP_VOLUME_24H\", options);\n\n/** Get most valuable coins */\nexport const getExploreMostValuable = <T extends boolean = false>(\n options?: Options<QueryInnerType, T>,\n) => createExploreQuery(\"MOST_VALUABLE\", options);\n\n/** Get newly created coins */\nexport const getExploreNew = <T extends boolean = false>(\n options?: Options<QueryInnerType, T>,\n) => createExploreQuery(\"NEW\", options);\n\n/** Get recently traded coins */\nexport const getExploreLastTraded = <T extends boolean = false>(\n options?: Options<QueryInnerType, T>,\n) => createExploreQuery(\"LAST_TRADED\", options);\n\n/** Get recently traded unique coins */\nexport const getExploreLastTradedUnique = <T extends boolean = false>(\n options?: Options<QueryInnerType, T>,\n) => createExploreQuery(\"LAST_TRADED_UNIQUE\", options);\n"],"mappings":";AAAA,SAAS,0BAA0B;AACnC;AAAA,EAOE;AAAA,OACK;;;ACTP,SAAS,8BAA8B;AAEvC,SAAS,YAAY;AAGd,IAAM,uBAAuB,uBAAuB,MAAM;AAE1D,IAAM,0BAA0B;AAEhC,IAAM,2BAAoD;AAAA,EAC7D,CAAC,KA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AACH;AAEO,IAAMC,cAAa,OAAO,UAAmC;AAClE,SAAO,MAAM,WAAc;AAAA,IACzB;AAAA,IACA,MAAM,cAAc;AAAA,EACtB,CAAC;AACH;AAEO,IAAMC,mBAAkB,OAAO,UAAwC;AAC5E,SAAO,MAAM,gBAAmB;AAAA,IAC9B;AAAA,IACA,MAAM,cAAc;AAAA,EACtB,CAAC;AACH;;;AC3CA,IAAM,qBAAqB,CACzB,UACA,YAEA,WAAc;AAAA,EACZ,GAAG;AAAA,EACH,OAAO,EAAE,GAAG,SAAS,OAAO,SAAS;AAAA,EACrC,MAAM,cAAc;AACtB,CAAC;AAGI,IAAM,uBAAuB,CAClC,YACG,mBAAmB,eAAe,OAAO;AAGvC,IAAM,yBAAyB,CACpC,YACG,mBAAmB,kBAAkB,OAAO;AAG1C,IAAM,yBAAyB,CACpC,YACG,mBAAmB,iBAAiB,OAAO;AAGzC,IAAM,gBAAgB,CAC3B,YACG,mBAAmB,OAAO,OAAO;AAG/B,IAAM,uBAAuB,CAClC,YACG,mBAAmB,eAAe,OAAO;AAGvC,IAAM,6BAA6B,CACxC,YACG,mBAAmB,sBAAsB,OAAO;","names":["base","parseEventLogs","baseSepolia","parseEventLogs","coinABI","zeroAddress","coinABI","coinABI","parseEventLogs","coinABI","getCoin","getCoins","getCoinComments","getProfile","getProfileOwned"]}
@@ -0,0 +1,3 @@
1
+ import { PublicClient as VanillaPublicClient } from "viem";
2
+ export type GenericPublicClient = VanillaPublicClient<any, any, any, any>;
3
+ //# sourceMappingURL=genericPublicClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genericPublicClient.d.ts","sourceRoot":"","sources":["../../src/utils/genericPublicClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAI3D,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import { PublicClient } from "viem";
2
- export declare const validateClientNetwork: (publicClient: PublicClient) => void;
2
+ export declare const validateClientNetwork: (publicClient: PublicClient<any, any, any, any>) => void;
3
3
  //# sourceMappingURL=validateClientNetwork.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateClientNetwork.d.ts","sourceRoot":"","sources":["../../src/utils/validateClientNetwork.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAGnC,eAAO,MAAM,qBAAqB,iBAAkB,YAAY,SAU/D,CAAA"}
1
+ {"version":3,"file":"validateClientNetwork.d.ts","sourceRoot":"","sources":["../../src/utils/validateClientNetwork.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAGnC,eAAO,MAAM,qBAAqB,iBAAkB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,SAUnF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoralabs/coins-sdk",
3
- "version": "0.0.2-sdkalpha.2",
3
+ "version": "0.0.2-sdkalpha.4",
4
4
  "repository": "https://github.com/ourzora/zora-protocol",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,13 +22,15 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
+ "@hey-api/client-fetch": "^0.8.3",
25
26
  "@zoralabs/coins": "^0.5.1-sdkalpha.0"
26
27
  },
27
28
  "peerDependencies": {
28
- "viem": "^2.21.55",
29
- "abitype": "^1.0.8"
29
+ "abitype": "^1.0.8",
30
+ "viem": "^2.21.55"
30
31
  },
31
32
  "devDependencies": {
33
+ "@hey-api/openapi-ts": "^0.64.10",
32
34
  "@lavamoat/preinstall-always-fail": "2.0.0",
33
35
  "@types/node": "^20.13.0",
34
36
  "@types/semver": "^7.5.8",
@@ -48,6 +50,7 @@
48
50
  "test:js": "vitest src",
49
51
  "test:integration": "vitest test-integration",
50
52
  "prettier:write": "prettier --write 'src/**/*.ts' 'test-integration/**/*.ts'",
51
- "lint": "prettier --check 'src/**/*.ts' 'test-integration/**/*.ts'"
53
+ "lint": "prettier --check 'src/**/*.ts' 'test-integration/**/*.ts'",
54
+ "api-codegen": "openapi-ts"
52
55
  }
53
56
  }
@@ -90,6 +90,11 @@ export async function createCoin(
90
90
  ...createCoinCall(call),
91
91
  account: walletClient.account,
92
92
  });
93
+
94
+ // Add a 1/5th buffer on gas.
95
+ if (request.gas) {
96
+ request.gas = request.gas * 6n / 5n;
97
+ }
93
98
  const hash = await walletClient.writeContract(request);
94
99
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
95
100
  const deployment = getCoinCreateFromLogs(receipt);