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

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.
@@ -0,0 +1,219 @@
1
+ export type GetCoinDetailsData = {
2
+ body?: never;
3
+ path?: never;
4
+ query: {
5
+ address: string;
6
+ chain?: number;
7
+ };
8
+ url: '/coinDetails';
9
+ };
10
+ export type GetCoinDetailsResponses = {
11
+ /**
12
+ * response
13
+ */
14
+ 200: {
15
+ zora20Token?: {
16
+ /**
17
+ * The Globally Unique ID of this object
18
+ */
19
+ id?: string;
20
+ name?: string;
21
+ description?: string;
22
+ address?: string;
23
+ symbol?: string;
24
+ totalSupply?: string;
25
+ totalVolume?: string;
26
+ volume24h?: string;
27
+ createdAt?: string;
28
+ creatorAddress?: string;
29
+ creatorEarnings?: Array<{
30
+ amount?: {
31
+ currency?: {
32
+ address?: string;
33
+ };
34
+ amountRaw?: string;
35
+ amountDecimal?: number;
36
+ };
37
+ amountUsd?: string;
38
+ }>;
39
+ marketCap?: string;
40
+ marketCapDelta24h?: string;
41
+ chainId?: number;
42
+ chainName?: 'EthereumMainnet' | 'EthereumRopsten' | 'EthereumRinkeby' | 'EthereumGoerli' | 'EthereumSepolia' | 'OptimismMainnet' | 'OptimismGoerli' | 'ZoraGoerli' | 'ZoraSepolia' | 'ZoraMainnet' | 'BaseMainnet' | 'BaseGoerli' | 'BaseSepolia' | 'BaseAnvil' | 'PGNMainnet' | 'ArbitrumMainnet' | 'BlastMainnet';
43
+ creatorProfile?: string;
44
+ handle?: string;
45
+ avatar?: {
46
+ small?: string;
47
+ medium?: string;
48
+ blurhash?: string;
49
+ };
50
+ bio?: string;
51
+ media?: {
52
+ mimeType?: string;
53
+ originalUri?: string;
54
+ format?: string;
55
+ previewImage?: string;
56
+ medium?: string;
57
+ blurhash?: string;
58
+ };
59
+ transfers?: {
60
+ count?: number;
61
+ };
62
+ uniqueHolders?: number;
63
+ };
64
+ };
65
+ };
66
+ export type GetCoinDetailsResponse = GetCoinDetailsResponses[keyof GetCoinDetailsResponses];
67
+ export type GetCoinCommentsData = {
68
+ body?: never;
69
+ path?: never;
70
+ query: {
71
+ address: string;
72
+ chain?: number;
73
+ after?: string;
74
+ count?: number;
75
+ };
76
+ url: '/coinComments';
77
+ };
78
+ export type GetCoinCommentsResponses = {
79
+ /**
80
+ * response
81
+ */
82
+ 200: {
83
+ zora20Token?: {
84
+ zoraComments?: {
85
+ /**
86
+ * Information to aid in pagination.
87
+ */
88
+ pageInfo?: {
89
+ /**
90
+ * When paginating forwards, the cursor to continue.
91
+ */
92
+ endCursor?: string;
93
+ /**
94
+ * When paginating forwards, are there more items?
95
+ */
96
+ hasNextPage?: boolean;
97
+ };
98
+ count?: number;
99
+ edges?: Array<{
100
+ node?: string;
101
+ txHash?: string;
102
+ comment?: string;
103
+ userAddress?: string;
104
+ timestamp?: number;
105
+ userProfile?: string;
106
+ /**
107
+ * The Globally Unique ID of this object
108
+ */
109
+ id?: string;
110
+ handle?: string;
111
+ avatar?: {
112
+ previewImage?: string;
113
+ blurhash?: string;
114
+ small?: string;
115
+ };
116
+ replies?: {
117
+ count?: number;
118
+ edges?: Array<{
119
+ node?: {
120
+ txHash?: string;
121
+ comment?: string;
122
+ userAddress?: string;
123
+ timestamp?: number;
124
+ userProfile?: string;
125
+ /**
126
+ * The Globally Unique ID of this object
127
+ */
128
+ id?: string;
129
+ handle?: string;
130
+ avatar?: {
131
+ previewImage?: string;
132
+ blurhash?: string;
133
+ small?: string;
134
+ };
135
+ };
136
+ }>;
137
+ };
138
+ }>;
139
+ };
140
+ };
141
+ };
142
+ };
143
+ export type GetCoinCommentsResponse = GetCoinCommentsResponses[keyof GetCoinCommentsResponses];
144
+ export type GetExploreData = {
145
+ body?: never;
146
+ path?: never;
147
+ query: {
148
+ listType: 'TOP_GAINERS' | 'TOP_VOLUME_24H' | 'MOST_VALUABLE' | 'NEW' | 'LAST_TRADED' | 'LAST_TRADED_UNIQUE';
149
+ count?: number;
150
+ after?: string;
151
+ };
152
+ url: '/explore';
153
+ };
154
+ export type GetExploreResponses = {
155
+ /**
156
+ * response
157
+ */
158
+ 200: {
159
+ exploreList?: {
160
+ edges?: Array<{
161
+ node?: {
162
+ /**
163
+ * The Globally Unique ID of this object
164
+ */
165
+ id?: string;
166
+ address?: string;
167
+ chainId?: number;
168
+ creatorProfile?: string;
169
+ profileId?: string;
170
+ handle?: string;
171
+ avatar?: {
172
+ mimeType?: string;
173
+ downloadableUri?: string;
174
+ height?: number;
175
+ width?: number;
176
+ blurhash?: string;
177
+ };
178
+ name?: string;
179
+ symbol?: string;
180
+ volume24h?: string;
181
+ uniqueHolders?: number;
182
+ createdAt?: string;
183
+ zoraComments?: {
184
+ count?: number;
185
+ };
186
+ mediaContent?: string;
187
+ mimeType?: string;
188
+ originalUri?: string;
189
+ downloadableUri?: string;
190
+ previewImage?: string;
191
+ height?: number;
192
+ width?: number;
193
+ blurhash?: string;
194
+ marketCap?: string;
195
+ marketCapDelta24h?: string;
196
+ };
197
+ cursor?: string;
198
+ }>;
199
+ /**
200
+ * Information to aid in pagination.
201
+ */
202
+ pageInfo?: {
203
+ /**
204
+ * When paginating forwards, the cursor to continue.
205
+ */
206
+ endCursor?: string;
207
+ /**
208
+ * When paginating forwards, are there more items?
209
+ */
210
+ hasNextPage?: boolean;
211
+ };
212
+ };
213
+ };
214
+ };
215
+ export type GetExploreResponse = GetExploreResponses[keyof GetExploreResponses];
216
+ export type ClientOptions = {
217
+ baseUrl: 'https://api-sdk.zora.engineering/' | 'https://api-sdk-staging.zora.engineering/' | (string & {});
218
+ };
219
+ //# sourceMappingURL=types.gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.gen.d.ts","sourceRoot":"","sources":["../../src/client/types.gen.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG;IAC7B,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,IAAI,CAAC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,CAAC;oBACnB,YAAY,CAAC,EAAE;wBACX,KAAK,CAAC,EAAE,MAAM,CAAC;qBAClB,CAAC;oBACF,YAAY,CAAC,EAAE,MAAM,CAAC;oBACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;oBAClB,WAAW,CAAC,EAAE,MAAM,CAAC;oBACrB,eAAe,CAAC,EAAE,MAAM,CAAC;oBACzB,YAAY,CAAC,EAAE,MAAM,CAAC;oBACtB,MAAM,CAAC,EAAE,MAAM,CAAC;oBAChB,KAAK,CAAC,EAAE,MAAM,CAAC;oBACf,QAAQ,CAAC,EAAE,MAAM,CAAC;oBAClB,SAAS,CAAC,EAAE,MAAM,CAAC;oBACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;iBAC9B,CAAC;gBACF,MAAM,CAAC,EAAE,MAAM,CAAC;aACnB,CAAC,CAAC;YACH;;eAEG;YACH,QAAQ,CAAC,EAAE;gBACP;;mBAEG;gBACH,SAAS,CAAC,EAAE,MAAM,CAAC;gBACnB;;mBAEG;gBACH,WAAW,CAAC,EAAE,OAAO,CAAC;aACzB,CAAC;SACL,CAAC;KACL,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,MAAM,mBAAmB,CAAC,CAAC;AAEhF,MAAM,MAAM,aAAa,GAAG;IACxB,OAAO,EAAE,mCAAmC,GAAG,2CAA2C,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;CAC9G,CAAC"}
package/dist/index.cjs CHANGED
@@ -22,8 +22,12 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  createCoin: () => createCoin,
24
24
  createCoinCall: () => createCoinCall,
25
+ explore: () => explore_exports,
26
+ getCoinComments: () => getCoinComments,
25
27
  getCoinCreateFromLogs: () => getCoinCreateFromLogs,
26
28
  getCoinDetails: () => getCoinDetails,
29
+ getExplore: () => getExplore,
30
+ getOnchainCoinDetails: () => getOnchainCoinDetails,
27
31
  getTradeFromLogs: () => getTradeFromLogs,
28
32
  tradeCoin: () => tradeCoin,
29
33
  tradeCoinCall: () => tradeCoinCall,
@@ -104,6 +108,9 @@ async function createCoin(call, walletClient, publicClient) {
104
108
  ...createCoinCall(call),
105
109
  account: walletClient.account
106
110
  });
111
+ if (request.gas) {
112
+ request.gas = request.gas * 6n / 5n;
113
+ }
107
114
  const hash = await walletClient.writeContract(request);
108
115
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
109
116
  const deployment = getCoinCreateFromLogs(receipt);
@@ -170,43 +177,52 @@ async function tradeCoin(params, walletClient, publicClient) {
170
177
  };
171
178
  }
172
179
 
173
- // src/actions/getCoinDetails.ts
180
+ // src/actions/getOnchainCoinDetails.ts
174
181
  var import_coins4 = require("@zoralabs/coins");
175
182
  var import_viem3 = require("viem");
176
- async function getCoinDetails({
183
+ async function getOnchainCoinDetails({
177
184
  coin,
178
185
  user = import_viem3.zeroAddress,
179
186
  publicClient
180
187
  }) {
181
188
  validateClientNetwork(publicClient);
182
- const [balance, pool, owners, payoutRecipient] = await publicClient.multicall({
183
- contracts: [
184
- {
185
- address: coin,
186
- abi: import_coins4.coinABI,
187
- functionName: "balanceOf",
188
- args: [user]
189
- },
190
- {
191
- address: coin,
192
- abi: import_coins4.coinABI,
193
- functionName: "poolAddress"
194
- },
195
- {
196
- address: coin,
197
- abi: import_coins4.coinABI,
198
- functionName: "owners"
199
- },
200
- {
201
- address: coin,
202
- abi: import_coins4.coinABI,
203
- functionName: "payoutRecipient"
204
- }
205
- ],
206
- allowFailure: false
207
- });
189
+ const [balance, pool, owners, payoutRecipient] = await publicClient.multicall(
190
+ {
191
+ contracts: [
192
+ {
193
+ address: coin,
194
+ abi: import_coins4.coinABI,
195
+ functionName: "balanceOf",
196
+ args: [user]
197
+ },
198
+ {
199
+ address: coin,
200
+ abi: import_coins4.coinABI,
201
+ functionName: "poolAddress"
202
+ },
203
+ {
204
+ address: coin,
205
+ abi: import_coins4.coinABI,
206
+ functionName: "owners"
207
+ },
208
+ {
209
+ address: coin,
210
+ abi: import_coins4.coinABI,
211
+ functionName: "payoutRecipient"
212
+ }
213
+ ],
214
+ allowFailure: false
215
+ }
216
+ );
208
217
  const USDC_WETH_POOL = USDC_WETH_POOLS_BY_CHAIN[publicClient.chain?.id || 0];
209
- const [coinWethPoolSlot0, coinWethPoolToken0, coinReservesRaw, coinTotalSupply, wethReservesRaw, usdcWethSlot0] = await publicClient.multicall({
218
+ const [
219
+ coinWethPoolSlot0,
220
+ coinWethPoolToken0,
221
+ coinReservesRaw,
222
+ coinTotalSupply,
223
+ wethReservesRaw,
224
+ usdcWethSlot0
225
+ ] = await publicClient.multicall({
210
226
  contracts: [
211
227
  {
212
228
  address: pool,
@@ -266,12 +282,20 @@ async function getCoinDetails({
266
282
  owners,
267
283
  payoutRecipient,
268
284
  marketCap: convertEthOutput(marketCap, wethPriceInUsdc),
269
- liquidity: convertEthOutput(wethLiquidity + tokenLiquidity, wethPriceInUsdc),
285
+ liquidity: convertEthOutput(
286
+ wethLiquidity + tokenLiquidity,
287
+ wethPriceInUsdc
288
+ ),
270
289
  poolState: coinWethPoolSlot0
271
290
  };
272
291
  }
273
292
  function convertEthOutput(amountETH, wethToUsdc) {
274
- return { eth: amountETH, ethDecimal: parseFloat((0, import_viem3.formatEther)(amountETH)), usdc: wethToUsdc ? amountETH * wethToUsdc : null, usdcDecimal: wethToUsdc ? parseFloat((0, import_viem3.formatEther)(amountETH * wethToUsdc / 10n ** 18n)) : null };
293
+ return {
294
+ eth: amountETH,
295
+ ethDecimal: parseFloat((0, import_viem3.formatEther)(amountETH)),
296
+ usdc: wethToUsdc ? amountETH * wethToUsdc : null,
297
+ usdcDecimal: wethToUsdc ? parseFloat((0, import_viem3.formatEther)(amountETH * wethToUsdc / 10n ** 18n)) : null
298
+ };
275
299
  }
276
300
  function uniswapV3SqrtPriceToBigIntScaled(sqrtPriceX96, token0Decimals, token1Decimals, isToken0Coin, scaleDecimals = 18) {
277
301
  const numerator = sqrtPriceX96 * sqrtPriceX96;
@@ -325,12 +349,77 @@ async function updateCoinURI(args, walletClient, publicClient) {
325
349
  );
326
350
  return { hash, receipt, uriUpdated };
327
351
  }
352
+
353
+ // src/client/client.gen.ts
354
+ var import_client_fetch = require("@hey-api/client-fetch");
355
+ var client = (0, import_client_fetch.createClient)((0, import_client_fetch.createConfig)({
356
+ baseUrl: "https://api-sdk.zora.engineering/"
357
+ }));
358
+
359
+ // src/client/sdk.gen.ts
360
+ var getCoinDetails = (options) => {
361
+ return (options.client ?? client).get({
362
+ url: "/coinDetails",
363
+ ...options
364
+ });
365
+ };
366
+ var getCoinComments = (options) => {
367
+ return (options.client ?? client).get({
368
+ url: "/coinComments",
369
+ ...options
370
+ });
371
+ };
372
+ var getExplore = (options) => {
373
+ return (options.client ?? client).get({
374
+ url: "/explore",
375
+ ...options
376
+ });
377
+ };
378
+
379
+ // src/client/explore.ts
380
+ var explore_exports = {};
381
+ __export(explore_exports, {
382
+ getLastTraded: () => getLastTraded,
383
+ getLastTradedUnique: () => getLastTradedUnique,
384
+ getMostValuable: () => getMostValuable,
385
+ getNew: () => getNew,
386
+ getTopGainers: () => getTopGainers,
387
+ getTopVolume24h: () => getTopVolume24h
388
+ });
389
+ var getTopGainers = (options) => getExplore({
390
+ ...options,
391
+ query: { ...options?.query, listType: "TOP_GAINERS" }
392
+ });
393
+ var getTopVolume24h = (options) => getExplore({
394
+ ...options,
395
+ query: { ...options?.query, listType: "TOP_VOLUME_24H" }
396
+ });
397
+ var getMostValuable = (options) => getExplore({
398
+ ...options,
399
+ query: { ...options?.query, listType: "MOST_VALUABLE" }
400
+ });
401
+ var getNew = (options) => getExplore({
402
+ ...options,
403
+ query: { ...options?.query, listType: "NEW" }
404
+ });
405
+ var getLastTraded = (options) => getExplore({
406
+ ...options,
407
+ query: { ...options?.query, listType: "LAST_TRADED" }
408
+ });
409
+ var getLastTradedUnique = (options) => getExplore({
410
+ ...options,
411
+ query: { ...options?.query, listType: "LAST_TRADED_UNIQUE" }
412
+ });
328
413
  // Annotate the CommonJS export names for ESM import in node:
329
414
  0 && (module.exports = {
330
415
  createCoin,
331
416
  createCoinCall,
417
+ explore,
418
+ getCoinComments,
332
419
  getCoinCreateFromLogs,
333
420
  getCoinDetails,
421
+ getExplore,
422
+ getOnchainCoinDetails,
334
423
  getTradeFromLogs,
335
424
  tradeCoin,
336
425
  tradeCoinCall,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/actions/createCoin.ts","../src/constants.ts","../src/utils/validateClientNetwork.ts","../src/actions/tradeCoin.ts","../src/actions/getCoinDetails.ts","../src/actions/updateCoinURI.ts"],"sourcesContent":["\nexport { createCoin, createCoinCall, getCoinCreateFromLogs } from \"./actions/createCoin\";\nexport { tradeCoin, tradeCoinCall, getTradeFromLogs } from \"./actions/tradeCoin\";\nexport { getCoinDetails, type CoinDetails } from \"./actions/getCoinDetails\";\nexport { updateCoinURI, updateCoinURICall } from \"./actions/updateCoinURI\";\n","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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAmC;AACnC,kBAQO;;;ACTP,mBAAuC;AAEvC,oBAAqB;AAGd,IAAM,uBAAuB,oCAAuB,MAAM;AAE1D,IAAM,0BAA0B;AAEhC,IAAM,2BAAoD;AAAA,EAC7D,CAAC,mBAAK,EAAE,GAAG;AACf;;;ACVA,IAAAC,iBAAkC;AAE3B,IAAM,wBAAwB,CAAC,iBAA+B;AACjE,QAAM,gBAAgB,cAAc,OAAO;AAC3C,MAAI,kBAAkB,oBAAK,IAAI;AAC3B;AAAA,EACJ;AACA,MAAI,kBAAkB,2BAAY,IAAI;AAClC;AAAA,EACJ;AAEA,QAAM,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AsB,cACpB,MACA,cACA,cACA;AACA,wBAAsB,YAAY;AAClC,QAAM,OAAO,kBAAkB,IAAI;AACnC,QAAM,EAAE,QAAQ,IAAI,MAAM,aAAa,iBAAiB;AAAA,IACtD,GAAG;AAAA,IACH,SAAS,aAAa;AAAA,EACxB,CAAC;AACD,QAAM,OAAO,MAAM,aAAa,cAAc,OAAO;AACrD,QAAM,UAAU,MAAM,aAAa,0BAA0B,EAAE,KAAK,CAAC;AACrE,QAAM,gBAAY,6BAAe,EAAE,KAAK,uBAAS,MAAM,QAAQ,KAAK,CAAC;AACrE,QAAM,aAAa,UAAU;AAAA,IAC3B,CAAC,QAAQ,IAAI,cAAc;AAAA,EAC7B;AAEA,SAAO,EAAE,MAAM,SAAS,WAAW;AACrC;","names":["import_coins","import_chains","import_coins","import_viem","import_chains","import_coins","import_viem","import_coins","import_viem"]}
1
+ {"version":3,"sources":["../src/index.ts","../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/client/explore.ts"],"sourcesContent":["\nexport { createCoin, createCoinCall, getCoinCreateFromLogs } from \"./actions/createCoin\";\nexport { tradeCoin, tradeCoinCall, getTradeFromLogs } from \"./actions/tradeCoin\";\nexport { getOnchainCoinDetails, type OnchainCoinDetails } from \"./actions/getOnchainCoinDetails\";\nexport { updateCoinURI, updateCoinURICall } from \"./actions/updateCoinURI\";\n\n// API Read Actions\nexport * from './client/sdk.gen';\nexport * as explore from './client/explore';","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) => {\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 { validateClientNetwork } from \"src/utils/validateClientNetwork\";\nimport {\n Address,\n erc20Abi,\n formatEther,\n isAddressEqual,\n PublicClient,\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: PublicClient;\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 { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';\nimport type { GetCoinDetailsData, GetCoinDetailsResponse, GetCoinCommentsData, GetCoinCommentsResponse, GetExploreData, GetExploreResponse } from './types.gen';\nimport { client as _heyApiClient } from './client.gen';\n\nexport type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = 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 getCoinDetails = <ThrowOnError extends boolean = false>(options: Options<GetCoinDetailsData, ThrowOnError>) => {\n return (options.client ?? _heyApiClient).get<GetCoinDetailsResponse, unknown, ThrowOnError>({\n url: '/coinDetails',\n ...options\n });\n};\n\nexport const getCoinComments = <ThrowOnError extends boolean = false>(options: Options<GetCoinCommentsData, ThrowOnError>) => {\n return (options.client ?? _heyApiClient).get<GetCoinCommentsResponse, unknown, ThrowOnError>({\n url: '/coinComments',\n ...options\n });\n};\n\nexport const getExplore = <ThrowOnError extends boolean = false>(options: Options<GetExploreData, ThrowOnError>) => {\n return (options.client ?? _heyApiClient).get<GetExploreResponse, unknown, ThrowOnError>({\n url: '/explore',\n ...options\n });\n};","import { getExplore } from \"./sdk.gen\";\nimport type { GetExploreData } from \"./types.gen\";\nimport { Options } from \"@hey-api/client-fetch\";\n\ntype QueryInnerType = {\n query: Omit<GetExploreData[\"query\"], \"listType\">;\n} & Omit<GetExploreData, \"query\">;\n\nexport const getTopGainers = <ThrowOnError extends boolean = false>(\n options?: Options<QueryInnerType, ThrowOnError>,\n) =>\n getExplore({\n ...options,\n query: { ...options?.query, listType: \"TOP_GAINERS\" },\n });\n\nexport const getTopVolume24h = <ThrowOnError extends boolean = false>(\n options?: Options<QueryInnerType, ThrowOnError>,\n) =>\n getExplore({\n ...options,\n query: { ...options?.query, listType: \"TOP_VOLUME_24H\" },\n });\n\nexport const getMostValuable = <ThrowOnError extends boolean = false>(\n options?: Options<QueryInnerType, ThrowOnError>,\n) =>\n getExplore({\n ...options,\n query: { ...options?.query, listType: \"MOST_VALUABLE\" },\n });\n\nexport const getNew = <ThrowOnError extends boolean = false>(\n options?: Options<QueryInnerType, ThrowOnError>,\n) =>\n getExplore({\n ...options,\n query: { ...options?.query, listType: \"NEW\" },\n });\n\nexport const getLastTraded = <ThrowOnError extends boolean = false>(\n options?: Options<QueryInnerType, ThrowOnError>,\n) =>\n getExplore({\n ...options,\n query: { ...options?.query, listType: \"LAST_TRADED\" },\n });\n\nexport const getLastTradedUnique = <ThrowOnError extends boolean = false>(\n options?: Options<QueryInnerType, ThrowOnError>,\n) =>\n getExplore({\n ...options,\n query: { ...options?.query, listType: \"LAST_TRADED_UNIQUE\" },\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACA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AM,kBAAkB,CAAuC,YAAwD;AAC1H,UAAQ,QAAQ,UAAU,QAAe,IAAoD;AAAA,IACzF,KAAK;AAAA,IACL,GAAG;AAAA,EACP,CAAC;AACL;AAEO,IAAM,aAAa,CAAuC,YAAmD;AAChH,UAAQ,QAAQ,UAAU,QAAe,IAA+C;AAAA,IACpF,KAAK;AAAA,IACL,GAAG;AAAA,EACP,CAAC;AACL;;;ACvCA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,IAAM,gBAAgB,CAC3B,YAEA,WAAW;AAAA,EACT,GAAG;AAAA,EACH,OAAO,EAAE,GAAG,SAAS,OAAO,UAAU,cAAc;AACtD,CAAC;AAEI,IAAM,kBAAkB,CAC7B,YAEA,WAAW;AAAA,EACT,GAAG;AAAA,EACH,OAAO,EAAE,GAAG,SAAS,OAAO,UAAU,iBAAiB;AACzD,CAAC;AAEI,IAAM,kBAAkB,CAC7B,YAEA,WAAW;AAAA,EACT,GAAG;AAAA,EACH,OAAO,EAAE,GAAG,SAAS,OAAO,UAAU,gBAAgB;AACxD,CAAC;AAEI,IAAM,SAAS,CACpB,YAEA,WAAW;AAAA,EACT,GAAG;AAAA,EACH,OAAO,EAAE,GAAG,SAAS,OAAO,UAAU,MAAM;AAC9C,CAAC;AAEI,IAAM,gBAAgB,CAC3B,YAEA,WAAW;AAAA,EACT,GAAG;AAAA,EACH,OAAO,EAAE,GAAG,SAAS,OAAO,UAAU,cAAc;AACtD,CAAC;AAEI,IAAM,sBAAsB,CACjC,YAEA,WAAW;AAAA,EACT,GAAG;AAAA,EACH,OAAO,EAAE,GAAG,SAAS,OAAO,UAAU,qBAAqB;AAC7D,CAAC;","names":["import_coins","import_chains","import_coins","import_viem","import_chains","import_coins","import_viem","import_coins","import_viem"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { createCoin, createCoinCall, getCoinCreateFromLogs } from "./actions/createCoin";
2
2
  export { tradeCoin, tradeCoinCall, getTradeFromLogs } from "./actions/tradeCoin";
3
- export { getCoinDetails, type CoinDetails } from "./actions/getCoinDetails";
3
+ export { getOnchainCoinDetails, type OnchainCoinDetails } from "./actions/getOnchainCoinDetails";
4
4
  export { updateCoinURI, updateCoinURICall } from "./actions/updateCoinURI";
5
+ export * from './client/sdk.gen';
6
+ export * as explore from './client/explore';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,KAAK,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG3E,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC"}