@zoralabs/coins-sdk 0.2.11 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/actions/createCoin.d.ts +52 -21
  3. package/dist/actions/createCoin.d.ts.map +1 -1
  4. package/dist/api/create.d.ts +8 -0
  5. package/dist/api/create.d.ts.map +1 -0
  6. package/dist/api/index.d.ts +4 -0
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/pool-config.d.ts +5 -0
  9. package/dist/api/pool-config.d.ts.map +1 -0
  10. package/dist/client/sdk.gen.d.ts +194 -1
  11. package/dist/client/sdk.gen.d.ts.map +1 -1
  12. package/dist/client/types.gen.d.ts +567 -0
  13. package/dist/client/types.gen.d.ts.map +1 -1
  14. package/dist/index.cjs +416 -461
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +2 -3
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +387 -432
  19. package/dist/index.js.map +1 -1
  20. package/dist/uploader/metadata.d.ts.map +1 -1
  21. package/dist/uploader/types.d.ts +4 -1
  22. package/dist/uploader/types.d.ts.map +1 -1
  23. package/dist/utils/rethrowDecodedRevert.d.ts +3 -0
  24. package/dist/utils/rethrowDecodedRevert.d.ts.map +1 -0
  25. package/package.json +1 -1
  26. package/src/actions/createCoin.ts +154 -112
  27. package/src/api/create.ts +24 -0
  28. package/src/api/index.ts +8 -0
  29. package/src/api/pool-config.ts +17 -0
  30. package/src/client/sdk.gen.ts +50 -0
  31. package/src/client/types.gen.ts +581 -0
  32. package/src/index.ts +4 -6
  33. package/src/uploader/metadata.ts +4 -1
  34. package/src/uploader/types.ts +4 -1
  35. package/src/utils/rethrowDecodedRevert.ts +50 -0
  36. package/dist/actions/getOnchainCoinDetails.d.ts +0 -32
  37. package/dist/actions/getOnchainCoinDetails.d.ts.map +0 -1
  38. package/dist/utils/getPrepurchaseHook.d.ts +0 -16
  39. package/dist/utils/getPrepurchaseHook.d.ts.map +0 -1
  40. package/src/actions/getOnchainCoinDetails.ts +0 -68
  41. package/src/utils/getPrepurchaseHook.ts +0 -59
package/src/index.ts CHANGED
@@ -2,18 +2,16 @@ export {
2
2
  createCoin,
3
3
  createCoinCall,
4
4
  getCoinCreateFromLogs,
5
- DeployCurrency,
6
- InitialPurchaseCurrency,
5
+ CreateConstants,
7
6
  } from "./actions/createCoin";
8
7
  export type {
9
8
  CreateCoinArgs,
10
9
  CoinDeploymentLogArgs,
10
+ RawUriMetadata,
11
+ StartingMarketCap,
12
+ ContentCoinCurrency,
11
13
  } from "./actions/createCoin";
12
14
 
13
- export {
14
- getOnchainCoinDetails,
15
- type OnchainCoinDetails,
16
- } from "./actions/getOnchainCoinDetails";
17
15
  export { updateCoinURI, updateCoinURICall } from "./actions/updateCoinURI";
18
16
  export type { UpdateCoinURIArgs } from "./actions/updateCoinURI";
19
17
 
@@ -202,7 +202,10 @@ export class CoinMetadataBuilder {
202
202
  createMetadataParameters: {
203
203
  name: this.name!,
204
204
  symbol: this.symbol!,
205
- uri: uploadResult.url as `ipfs://${string}`,
205
+ metadata: {
206
+ type: "RAW_URI",
207
+ uri: uploadResult.url,
208
+ },
206
209
  },
207
210
  metadata,
208
211
  };
@@ -23,5 +23,8 @@ export interface Uploader {
23
23
  export type CreateMetadataParameters = {
24
24
  name: string;
25
25
  symbol: string;
26
- uri: `ipfs://${string}`;
26
+ metadata: {
27
+ type: "RAW_URI";
28
+ uri: ValidMetadataURI;
29
+ };
27
30
  };
@@ -0,0 +1,50 @@
1
+ import {
2
+ Abi,
3
+ BaseError,
4
+ ContractFunctionRevertedError,
5
+ decodeErrorResult,
6
+ Hex,
7
+ } from "viem";
8
+
9
+ export function rethrowDecodedRevert(err: unknown, abi: Abi): never {
10
+ if (err instanceof BaseError) {
11
+ const revertError = err.walk(
12
+ (e) => e instanceof ContractFunctionRevertedError,
13
+ );
14
+ if (revertError instanceof ContractFunctionRevertedError) {
15
+ // Try to decode using factory ABI
16
+ try {
17
+ const revertData =
18
+ typeof (revertError as any).data === "object" &&
19
+ (revertError as any).data !== null &&
20
+ "data" in (revertError as any).data
21
+ ? (revertError as any).data.data
22
+ : (revertError as any).data;
23
+ const decoded = decodeErrorResult({
24
+ abi,
25
+ data: revertData as Hex,
26
+ });
27
+ const name = decoded.errorName;
28
+ const args = decoded.args as ReadonlyArray<unknown> | undefined;
29
+ const message =
30
+ Array.isArray(args) && args.length > 0
31
+ ? `${name}(${args.map((a) => String(a)).join(", ")})`
32
+ : name;
33
+ throw new Error(`Create coin transaction reverted: ${message}`);
34
+ } catch {
35
+ const errorName = (revertError as any).data?.errorName as
36
+ | string
37
+ | undefined;
38
+ if (errorName) {
39
+ const args = (revertError as any).data?.args as unknown[] | undefined;
40
+ const message =
41
+ Array.isArray(args) && args.length > 0
42
+ ? `${errorName}(${args.map((a) => String(a)).join(", ")})`
43
+ : errorName;
44
+ throw new Error(`Create coin transaction reverted: ${message}`);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ throw err;
50
+ }
@@ -1,32 +0,0 @@
1
- import { GenericPublicClient } from "../utils/genericPublicClient";
2
- import { Address } from "viem";
3
- /**
4
- * Represents the current state of a coin
5
- * @typedef {Object} OnchainCoinDetails
6
- * @property {bigint} balance - The user's balance of the coin
7
- * @property {PricingResult} marketCap - The market cap of the coin
8
- * @property {PricingResult} liquidity - The liquidity of the coin
9
- * @property {Address} pool - Pool address
10
- * @property {Slot0Result} poolState - Current state of the UniswapV3 pool
11
- * @property {Address[]} owners - List of owners for the coin
12
- * @property {Address} payoutRecipient - The payout recipient address
13
- */
14
- export type OnchainCoinDetails = {
15
- balance: bigint;
16
- owners: readonly Address[];
17
- payoutRecipient: Address;
18
- };
19
- /**
20
- * Gets the current state of a coin for a user
21
- * @param {Object} params - The query parameters
22
- * @param {Address} params.coin - The coin contract address
23
- * @param {Address} params.user - The user address to check balance for
24
- * @param {PublicClient} params.publicClient - The viem public client instance
25
- * @returns {Promise<OnchainCoinDetails>} The coin's current state
26
- */
27
- export declare function getOnchainCoinDetails({ coin, user, publicClient, }: {
28
- coin: Address;
29
- user?: Address;
30
- publicClient: GenericPublicClient;
31
- }): Promise<OnchainCoinDetails>;
32
- //# sourceMappingURL=getOnchainCoinDetails.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getOnchainCoinDetails.d.ts","sourceRoot":"","sources":["../../src/actions/getOnchainCoinDetails.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAe,MAAM,MAAM,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,IAAI,EACJ,IAAkB,EAClB,YAAY,GACb,EAAE;IACD,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,mBAAmB,CAAC;CACnC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6B9B"}
@@ -1,16 +0,0 @@
1
- import { InitialPurchaseCurrency } from "../actions/createCoin";
2
- import { Address, Hex } from "viem";
3
- export declare const getPrepurchaseHook: ({ payoutRecipient, initialPurchase, chainId, }: {
4
- initialPurchase: {
5
- currency: InitialPurchaseCurrency;
6
- amount: bigint;
7
- amountOutMinimum?: bigint;
8
- };
9
- payoutRecipient: Address;
10
- chainId: number;
11
- }) => Promise<{
12
- hook: Address;
13
- hookData: Hex;
14
- value: bigint;
15
- }>;
16
- //# sourceMappingURL=getPrepurchaseHook.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPrepurchaseHook.d.ts","sourceRoot":"","sources":["../../src/utils/getPrepurchaseHook.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAU,GAAG,EAAc,MAAM,MAAM,CAAC;AAWxD,eAAO,MAAM,kBAAkB,GAAU,gDAItC;IACD,eAAe,EAAE;QACf,QAAQ,EAAE,uBAAuB,CAAC;QAClC,MAAM,EAAE,MAAM,CAAC;QACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;UA0BS,OAAO;cACH,GAAG;WACN,MAAM;EAEhB,CAAC"}
@@ -1,68 +0,0 @@
1
- import { coinABI } from "@zoralabs/protocol-deployments";
2
- import { GenericPublicClient } from "../utils/genericPublicClient";
3
- import { validateClientNetwork } from "../utils/validateClientNetwork";
4
- import { Address, zeroAddress } from "viem";
5
-
6
- /**
7
- * Represents the current state of a coin
8
- * @typedef {Object} OnchainCoinDetails
9
- * @property {bigint} balance - The user's balance of the coin
10
- * @property {PricingResult} marketCap - The market cap of the coin
11
- * @property {PricingResult} liquidity - The liquidity of the coin
12
- * @property {Address} pool - Pool address
13
- * @property {Slot0Result} poolState - Current state of the UniswapV3 pool
14
- * @property {Address[]} owners - List of owners for the coin
15
- * @property {Address} payoutRecipient - The payout recipient address
16
- */
17
- export type OnchainCoinDetails = {
18
- balance: bigint;
19
- owners: readonly Address[];
20
- payoutRecipient: Address;
21
- };
22
-
23
- /**
24
- * Gets the current state of a coin for a user
25
- * @param {Object} params - The query parameters
26
- * @param {Address} params.coin - The coin contract address
27
- * @param {Address} params.user - The user address to check balance for
28
- * @param {PublicClient} params.publicClient - The viem public client instance
29
- * @returns {Promise<OnchainCoinDetails>} The coin's current state
30
- */
31
- export async function getOnchainCoinDetails({
32
- coin,
33
- user = zeroAddress,
34
- publicClient,
35
- }: {
36
- coin: Address;
37
- user?: Address;
38
- publicClient: GenericPublicClient;
39
- }): Promise<OnchainCoinDetails> {
40
- validateClientNetwork(publicClient);
41
- const [balance, owners, payoutRecipient] = await publicClient.multicall({
42
- contracts: [
43
- {
44
- address: coin,
45
- abi: coinABI,
46
- functionName: "balanceOf",
47
- args: [user],
48
- },
49
- {
50
- address: coin,
51
- abi: coinABI,
52
- functionName: "owners",
53
- },
54
- {
55
- address: coin,
56
- abi: coinABI,
57
- functionName: "payoutRecipient",
58
- },
59
- ],
60
- allowFailure: false,
61
- });
62
-
63
- return {
64
- balance,
65
- owners,
66
- payoutRecipient,
67
- };
68
- }
@@ -1,59 +0,0 @@
1
- import {
2
- encodeBuySupplyWithMultiHopSwapRouterHookCall,
3
- wethAddress,
4
- } from "@zoralabs/protocol-deployments";
5
- import { InitialPurchaseCurrency } from "../actions/createCoin";
6
- import { Address, concat, Hex, pad, toHex } from "viem";
7
- import { ZORA_ADDRESS } from "./poolConfigUtils";
8
- import { base } from "viem/chains";
9
-
10
- const BASE_UDSC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
11
-
12
- const USDC_ZORA_FEE = 3000;
13
- const WETH_BASE_FEE = 3000;
14
-
15
- const encodeFee = (fee: number) => pad(toHex(fee), { size: 3 });
16
-
17
- export const getPrepurchaseHook = async ({
18
- payoutRecipient,
19
- initialPurchase,
20
- chainId,
21
- }: {
22
- initialPurchase: {
23
- currency: InitialPurchaseCurrency;
24
- amount: bigint;
25
- amountOutMinimum?: bigint;
26
- };
27
- payoutRecipient: Address;
28
- chainId: number;
29
- }) => {
30
- if (
31
- initialPurchase.currency !== InitialPurchaseCurrency.ETH &&
32
- chainId !== base.id
33
- ) {
34
- throw new Error("Initial purchase currency and/or chain not supported");
35
- }
36
-
37
- const path = concat([
38
- wethAddress[base.id],
39
- encodeFee(WETH_BASE_FEE),
40
- BASE_UDSC_ADDRESS,
41
- encodeFee(USDC_ZORA_FEE),
42
- ZORA_ADDRESS,
43
- ]);
44
-
45
- return encodeBuySupplyWithMultiHopSwapRouterHookCall({
46
- ethValue: initialPurchase.amount,
47
- buyRecipient: payoutRecipient,
48
- exactInputParams: {
49
- path,
50
- amountIn: initialPurchase.amount,
51
- amountOutMinimum: initialPurchase.amountOutMinimum || 0n,
52
- },
53
- chainId: base.id,
54
- }) as {
55
- hook: Address;
56
- hookData: Hex;
57
- value: bigint;
58
- };
59
- };