@zoralabs/coins-sdk 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,40 +6,71 @@ import {
6
6
  SimulateContractParameters,
7
7
  ContractEventArgsFromTopics,
8
8
  parseEventLogs,
9
+ zeroAddress,
10
+ keccak256,
11
+ toBytes,
9
12
  Hex,
13
+ Account,
10
14
  } from "viem";
11
15
  import { COIN_FACTORY_ADDRESS } from "../constants";
12
16
  import { validateClientNetwork } from "../utils/validateClientNetwork";
13
17
  import { GenericPublicClient } from "src/utils/genericPublicClient";
14
18
  import { validateMetadataURIContent, ValidMetadataURI } from "src/metadata";
15
19
  import { getAttribution } from "../utils/attribution";
20
+ import { base, baseSepolia } from "viem/chains";
21
+ import {
22
+ COIN_ETH_PAIR_POOL_CONFIG,
23
+ COIN_ZORA_PAIR_POOL_CONFIG,
24
+ } from "src/utils/poolConfigUtils";
16
25
 
17
26
  export type CoinDeploymentLogArgs = ContractEventArgsFromTopics<
18
27
  typeof zoraFactoryImplABI,
19
- "CoinCreated"
28
+ "CoinCreatedV4"
20
29
  >;
21
30
 
22
- // This is the default pool config matching zora.co front-end. TODO: Allow users to customize further parameters within safe contract limits.
23
- const POOL_CONFIG =
24
- "0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc2f70fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcf2c0000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000b1a2bc2ec50000" as Hex;
31
+ export enum DeployCurrency {
32
+ ZORA = 1,
33
+ ETH = 2,
34
+ }
25
35
 
26
36
  export type CreateCoinArgs = {
27
37
  name: string;
28
38
  symbol: string;
29
39
  uri: ValidMetadataURI;
40
+ chainId: number;
30
41
  owners?: Address[];
31
42
  payoutRecipient: Address;
32
43
  platformReferrer?: Address;
33
- initialPurchaseWei?: bigint;
44
+ currency?: DeployCurrency;
34
45
  };
35
46
 
47
+ function getPoolConfig(currency: DeployCurrency, chainId: number) {
48
+ if (currency === DeployCurrency.ZORA && chainId == baseSepolia.id) {
49
+ throw new Error("ZORA is not supported on Base Sepolia");
50
+ }
51
+
52
+ switch (currency) {
53
+ case DeployCurrency.ZORA:
54
+ return COIN_ZORA_PAIR_POOL_CONFIG[
55
+ chainId as keyof typeof COIN_ZORA_PAIR_POOL_CONFIG
56
+ ];
57
+ case DeployCurrency.ETH:
58
+ return COIN_ETH_PAIR_POOL_CONFIG[
59
+ chainId as keyof typeof COIN_ETH_PAIR_POOL_CONFIG
60
+ ];
61
+ default:
62
+ throw new Error("Invalid currency");
63
+ }
64
+ }
65
+
36
66
  export async function createCoinCall({
37
67
  name,
38
68
  symbol,
39
69
  uri,
40
70
  owners,
41
71
  payoutRecipient,
42
- initialPurchaseWei = 0n,
72
+ currency,
73
+ chainId = base.id,
43
74
  platformReferrer = "0x0000000000000000000000000000000000000000",
44
75
  }: CreateCoinArgs): Promise<
45
76
  SimulateContractParameters<typeof zoraFactoryImplABI, "deploy">
@@ -48,9 +79,11 @@ export async function createCoinCall({
48
79
  owners = [payoutRecipient];
49
80
  }
50
81
 
51
- const orderSize: bigint = initialPurchaseWei;
52
- // The default pool config for
53
- const poolConfig = POOL_CONFIG;
82
+ if (!currency) {
83
+ currency = chainId !== base.id ? DeployCurrency.ETH : DeployCurrency.ZORA;
84
+ }
85
+
86
+ const poolConfig = getPoolConfig(currency, chainId);
54
87
 
55
88
  // This will throw an error if the metadata is not valid
56
89
  await validateMetadataURIContent(uri);
@@ -67,9 +100,10 @@ export async function createCoinCall({
67
100
  symbol,
68
101
  poolConfig,
69
102
  platformReferrer,
70
- orderSize,
103
+ zeroAddress, // hookAddress
104
+ "0x" as Hex, // hookData
105
+ keccak256(toBytes(Math.random().toString())), // coinSalt
71
106
  ],
72
- value: initialPurchaseWei,
73
107
  dataSuffix: getAttribution(),
74
108
  } as const;
75
109
  }
@@ -86,7 +120,8 @@ export function getCoinCreateFromLogs(
86
120
  abi: zoraFactoryImplABI,
87
121
  logs: receipt.logs,
88
122
  });
89
- return eventLogs.find((log) => log.eventName === "CoinCreated")?.args;
123
+
124
+ return eventLogs.find((log) => log.eventName === "CoinCreatedV4")?.args;
90
125
  }
91
126
 
92
127
  // Update createCoin to return both receipt and coin address
@@ -96,6 +131,7 @@ export async function createCoin(
96
131
  publicClient: GenericPublicClient,
97
132
  options?: {
98
133
  gasMultiplier?: number;
134
+ account?: Account | Address;
99
135
  },
100
136
  ) {
101
137
  validateClientNetwork(publicClient);
@@ -103,7 +139,7 @@ export async function createCoin(
103
139
  const createCoinRequest = await createCoinCall(call);
104
140
  const { request } = await publicClient.simulateContract({
105
141
  ...createCoinRequest,
106
- account: walletClient.account,
142
+ account: options?.account ?? walletClient.account,
107
143
  });
108
144
 
109
145
  // Add a 2/5th buffer on gas.
@@ -0,0 +1,23 @@
1
+ import {
2
+ SetCreateUploadJwtData,
3
+ SetCreateUploadJwtResponse,
4
+ } from "../client/types.gen";
5
+ import { setCreateUploadJwt as setCreateUploadJwtSDK } from "../client/sdk.gen";
6
+ import { getApiKeyMeta } from "./api-key";
7
+ import { RequestOptionsType } from "./query-types";
8
+ import { RequestResult } from "@hey-api/client-fetch";
9
+
10
+ type SetCreateUploadJwtQuery = SetCreateUploadJwtData["query"];
11
+ export type { SetCreateUploadJwtQuery, SetCreateUploadJwtData };
12
+ export type { SetCreateUploadJwtResponse } from "../client/types.gen";
13
+
14
+ export const setCreateUploadJwt = async (
15
+ query: SetCreateUploadJwtQuery,
16
+ options?: RequestOptionsType<SetCreateUploadJwtData>,
17
+ ): Promise<RequestResult<SetCreateUploadJwtResponse>> => {
18
+ return await setCreateUploadJwtSDK({
19
+ query,
20
+ meta: getApiKeyMeta(),
21
+ ...options,
22
+ });
23
+ };
@@ -7,6 +7,8 @@ import {
7
7
  GetCoinsResponse,
8
8
  GetProfileBalancesData,
9
9
  GetProfileBalancesResponse,
10
+ GetProfileCoinsData,
11
+ GetProfileCoinsResponse,
10
12
  GetProfileData,
11
13
  GetProfileResponse,
12
14
  } from "../client/types.gen";
@@ -16,6 +18,7 @@ import {
16
18
  getCoinComments as getCoinCommentsSDK,
17
19
  getProfile as getProfileSDK,
18
20
  getProfileBalances as getProfileBalancesSDK,
21
+ getProfileCoins as getProfileCoinsSDK,
19
22
  } from "../client/sdk.gen";
20
23
  import { getApiKeyMeta } from "./api-key";
21
24
  import { RequestOptionsType } from "./query-types";
@@ -87,6 +90,21 @@ export const getProfile = async (
87
90
  });
88
91
  };
89
92
 
93
+ type GetProfileCoinsQuery = GetProfileCoinsData["query"];
94
+ export type { GetProfileCoinsQuery, GetProfileCoinsData };
95
+ export type { GetProfileCoinsResponse } from "../client/types.gen";
96
+
97
+ export const getProfileCoins = async (
98
+ query: GetProfileCoinsQuery,
99
+ options?: RequestOptionsType<GetProfileCoinsData>,
100
+ ): Promise<RequestResult<GetProfileCoinsResponse>> => {
101
+ return await getProfileCoinsSDK({
102
+ query,
103
+ meta: getApiKeyMeta(),
104
+ ...options,
105
+ });
106
+ };
107
+
90
108
  type GetProfileBalancesQuery = GetProfileBalancesData["query"];
91
109
  export type { GetProfileBalancesQuery, GetProfileBalancesData };
92
110
  export type { GetProfileBalancesResponse } from "../client/types.gen";
@@ -6,18 +6,24 @@ import type {
6
6
  Client,
7
7
  } from "@hey-api/client-fetch";
8
8
  import type {
9
+ GetApiKeyData,
10
+ GetApiKeyResponse,
9
11
  GetCoinData,
10
12
  GetCoinResponse,
11
13
  GetCoinCommentsData,
12
14
  GetCoinCommentsResponse,
13
15
  GetCoinsData,
14
16
  GetCoinsResponse,
17
+ SetCreateUploadJwtData,
18
+ SetCreateUploadJwtResponse,
15
19
  GetExploreData,
16
20
  GetExploreResponse,
17
21
  GetProfileData,
18
22
  GetProfileResponse,
19
23
  GetProfileBalancesData,
20
24
  GetProfileBalancesResponse,
25
+ GetProfileCoinsData,
26
+ GetProfileCoinsResponse,
21
27
  } from "./types.gen";
22
28
  import { client as _heyApiClient } from "./client.gen";
23
29
 
@@ -38,6 +44,28 @@ export type Options<
38
44
  meta?: Record<string, unknown>;
39
45
  };
40
46
 
47
+ /**
48
+ * zoraSDK_apiKey query
49
+ */
50
+ export const getApiKey = <ThrowOnError extends boolean = false>(
51
+ options: Options<GetApiKeyData, ThrowOnError>,
52
+ ) => {
53
+ return (options.client ?? _heyApiClient).get<
54
+ GetApiKeyResponse,
55
+ unknown,
56
+ ThrowOnError
57
+ >({
58
+ security: [
59
+ {
60
+ name: "api-key",
61
+ type: "apiKey",
62
+ },
63
+ ],
64
+ url: "/apiKey",
65
+ ...options,
66
+ });
67
+ };
68
+
41
69
  /**
42
70
  * zoraSDK_coin query
43
71
  */
@@ -49,6 +77,12 @@ export const getCoin = <ThrowOnError extends boolean = false>(
49
77
  unknown,
50
78
  ThrowOnError
51
79
  >({
80
+ security: [
81
+ {
82
+ name: "api-key",
83
+ type: "apiKey",
84
+ },
85
+ ],
52
86
  url: "/coin",
53
87
  ...options,
54
88
  });
@@ -65,6 +99,12 @@ export const getCoinComments = <ThrowOnError extends boolean = false>(
65
99
  unknown,
66
100
  ThrowOnError
67
101
  >({
102
+ security: [
103
+ {
104
+ name: "api-key",
105
+ type: "apiKey",
106
+ },
107
+ ],
68
108
  url: "/coinComments",
69
109
  ...options,
70
110
  });
@@ -81,11 +121,43 @@ export const getCoins = <ThrowOnError extends boolean = false>(
81
121
  unknown,
82
122
  ThrowOnError
83
123
  >({
124
+ security: [
125
+ {
126
+ name: "api-key",
127
+ type: "apiKey",
128
+ },
129
+ ],
84
130
  url: "/coins",
85
131
  ...options,
86
132
  });
87
133
  };
88
134
 
135
+ /**
136
+ * zoraSDK_createUploadJWT mutation
137
+ */
138
+ export const setCreateUploadJwt = <ThrowOnError extends boolean = false>(
139
+ options?: Options<SetCreateUploadJwtData, ThrowOnError>,
140
+ ) => {
141
+ return (options?.client ?? _heyApiClient).post<
142
+ SetCreateUploadJwtResponse,
143
+ unknown,
144
+ ThrowOnError
145
+ >({
146
+ security: [
147
+ {
148
+ name: "api-key",
149
+ type: "apiKey",
150
+ },
151
+ ],
152
+ url: "/createUploadJWT",
153
+ ...options,
154
+ headers: {
155
+ "Content-Type": "application/json",
156
+ ...options?.headers,
157
+ },
158
+ });
159
+ };
160
+
89
161
  /**
90
162
  * zoraSDK_explore query
91
163
  */
@@ -97,6 +169,12 @@ export const getExplore = <ThrowOnError extends boolean = false>(
97
169
  unknown,
98
170
  ThrowOnError
99
171
  >({
172
+ security: [
173
+ {
174
+ name: "api-key",
175
+ type: "apiKey",
176
+ },
177
+ ],
100
178
  url: "/explore",
101
179
  ...options,
102
180
  });
@@ -113,6 +191,12 @@ export const getProfile = <ThrowOnError extends boolean = false>(
113
191
  unknown,
114
192
  ThrowOnError
115
193
  >({
194
+ security: [
195
+ {
196
+ name: "api-key",
197
+ type: "apiKey",
198
+ },
199
+ ],
116
200
  url: "/profile",
117
201
  ...options,
118
202
  });
@@ -129,7 +213,35 @@ export const getProfileBalances = <ThrowOnError extends boolean = false>(
129
213
  unknown,
130
214
  ThrowOnError
131
215
  >({
216
+ security: [
217
+ {
218
+ name: "api-key",
219
+ type: "apiKey",
220
+ },
221
+ ],
132
222
  url: "/profileBalances",
133
223
  ...options,
134
224
  });
135
225
  };
226
+
227
+ /**
228
+ * zoraSDK_profileCoins query
229
+ */
230
+ export const getProfileCoins = <ThrowOnError extends boolean = false>(
231
+ options: Options<GetProfileCoinsData, ThrowOnError>,
232
+ ) => {
233
+ return (options.client ?? _heyApiClient).get<
234
+ GetProfileCoinsResponse,
235
+ unknown,
236
+ ThrowOnError
237
+ >({
238
+ security: [
239
+ {
240
+ name: "api-key",
241
+ type: "apiKey",
242
+ },
243
+ ],
244
+ url: "/profileCoins",
245
+ ...options,
246
+ });
247
+ };