@zoralabs/coins-sdk 0.2.3 → 0.2.5

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 (55) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/actions/createCoin.d.ts +11 -4
  3. package/dist/actions/createCoin.d.ts.map +1 -1
  4. package/dist/actions/updateCoinURI.d.ts +1 -1
  5. package/dist/actions/updateCoinURI.d.ts.map +1 -1
  6. package/dist/actions/updatePayoutRecipient.d.ts +1 -1
  7. package/dist/actions/updatePayoutRecipient.d.ts.map +1 -1
  8. package/dist/api/api-key.d.ts +2 -1
  9. package/dist/api/api-key.d.ts.map +1 -1
  10. package/dist/api/index.d.ts.map +1 -1
  11. package/dist/api/internal.d.ts +2 -2
  12. package/dist/api/internal.d.ts.map +1 -1
  13. package/dist/index.cjs +301 -103
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +3 -4
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +320 -122
  18. package/dist/index.js.map +1 -1
  19. package/dist/metadata/cleanAndValidateMetadataURI.d.ts +1 -1
  20. package/dist/metadata/cleanAndValidateMetadataURI.d.ts.map +1 -1
  21. package/dist/metadata/index.d.ts +1 -1
  22. package/dist/metadata/index.d.ts.map +1 -1
  23. package/dist/metadata/validateMetadataURIContent.d.ts +1 -1
  24. package/dist/metadata/validateMetadataURIContent.d.ts.map +1 -1
  25. package/dist/uploader/index.d.ts +10 -0
  26. package/dist/uploader/index.d.ts.map +1 -0
  27. package/dist/uploader/metadata.d.ts +44 -0
  28. package/dist/uploader/metadata.d.ts.map +1 -0
  29. package/dist/uploader/providers/zora.d.ts +18 -0
  30. package/dist/uploader/providers/zora.d.ts.map +1 -0
  31. package/dist/uploader/types.d.ts +21 -0
  32. package/dist/uploader/types.d.ts.map +1 -0
  33. package/dist/utils/getPrepurchaseHook.d.ts +16 -0
  34. package/dist/utils/getPrepurchaseHook.d.ts.map +1 -0
  35. package/package.json +1 -1
  36. package/src/actions/createCoin.ts +33 -7
  37. package/src/actions/updateCoinURI.ts +1 -1
  38. package/src/actions/updatePayoutRecipient.ts +1 -1
  39. package/src/api/api-key.ts +5 -1
  40. package/src/api/index.ts +1 -0
  41. package/src/api/internal.ts +3 -3
  42. package/src/index.ts +9 -9
  43. package/src/metadata/cleanAndValidateMetadataURI.ts +1 -5
  44. package/src/metadata/index.ts +1 -4
  45. package/src/metadata/validateMetadataURIContent.ts +2 -4
  46. package/src/uploader/index.ts +16 -0
  47. package/src/uploader/metadata.ts +214 -0
  48. package/src/uploader/providers/zora.ts +86 -0
  49. package/src/uploader/tests/metadata.test.ts +331 -0
  50. package/src/uploader/tests/providers.test.ts +131 -0
  51. package/src/uploader/types.ts +27 -0
  52. package/src/utils/getPrepurchaseHook.ts +59 -0
  53. package/dist/actions/tradeCoin.d.ts +0 -75
  54. package/dist/actions/tradeCoin.d.ts.map +0 -1
  55. package/src/actions/tradeCoin.ts +0 -182
@@ -1,182 +0,0 @@
1
- import { coinABI } from "@zoralabs/protocol-deployments";
2
- import { validateClientNetwork } from "../utils/validateClientNetwork";
3
- import {
4
- Address,
5
- TransactionReceipt,
6
- WalletClient,
7
- SimulateContractParameters,
8
- parseEther,
9
- zeroAddress,
10
- ContractEventArgsFromTopics,
11
- parseEventLogs,
12
- } from "viem";
13
- import { baseSepolia } from "viem/chains";
14
- import { GenericPublicClient } from "src/utils/genericPublicClient";
15
- import { getAttribution } from "../utils/attribution";
16
- // Define trade event args type
17
-
18
- export type SellEventArgs = ContractEventArgsFromTopics<
19
- typeof coinABI,
20
- "CoinSell"
21
- >;
22
- export type BuyEventArgs = ContractEventArgsFromTopics<
23
- typeof coinABI,
24
- "CoinBuy"
25
- >;
26
-
27
- export type TradeEventArgs = SellEventArgs | BuyEventArgs;
28
-
29
- // We'll use this address to ensure it will have funds to simulate an eth trade.
30
- // @dev: This only works on OP chains and is a fix for a bug. Another approach should be taken long term.
31
- const OP_BRIDGE_ADDRESS =
32
- "0x4200000000000000000000000000000000000016" as Address;
33
-
34
- /**
35
- * Simulates a buy order to get the expected output amount
36
- * @param {Object} params - The simulation parameters
37
- * @param {Address} params.target - The target coin contract address
38
- * @param {bigint} params.requestedOrderSize - The desired input amount for the buy
39
- * @param {PublicClient} params.publicClient - The viem public client instance
40
- * @returns {Promise<{orderSize: bigint, amountOut: bigint}>} The simulated order size and output amount
41
- */
42
- export async function simulateBuy({
43
- target,
44
- requestedOrderSize,
45
- publicClient,
46
- }: {
47
- target: Address;
48
- requestedOrderSize: bigint;
49
- publicClient: GenericPublicClient;
50
- }): Promise<{ orderSize: bigint; amountOut: bigint }> {
51
- const numberResult = await publicClient.simulateContract({
52
- address: target,
53
- abi: coinABI,
54
- functionName: "buy",
55
- dataSuffix: getAttribution(),
56
- args: [
57
- OP_BRIDGE_ADDRESS,
58
- requestedOrderSize,
59
- 0n, // minAmountOut
60
- 0n, // sqrtPriceLimitX96
61
- zeroAddress, // tradeReferrer
62
- ],
63
- // We want to ensure that the multicall3 contract has enough ETH to buy in the simulation
64
- stateOverride: [
65
- {
66
- address: baseSepolia.contracts.multicall3.address,
67
- balance: parseEther("10000000"),
68
- },
69
- ],
70
- });
71
- const orderSize = numberResult.result[0];
72
- const amountOut = numberResult.result[1];
73
- return { orderSize, amountOut };
74
- }
75
-
76
- /**
77
- * Parameters for creating a trade call
78
- * @typedef {Object} TradeParams
79
- * @property {'sell' | 'buy'} direction - The trade direction
80
- * @property {Address} target - The target coin contract address
81
- * @property {Object} args - The trade arguments
82
- * @property {Address} args.recipient - The recipient of the trade output
83
- * @property {bigint} args.orderSize - The size of the order
84
- * @property {bigint} [args.minAmountOut] - The minimum amount to receive
85
- * @property {bigint} [args.sqrtPriceLimitX96] - The price limit for the trade
86
- * @property {Address} [args.tradeReferrer] - The referrer address for the trade
87
- */
88
- export type TradeParams = {
89
- direction: "sell" | "buy";
90
- target: Address;
91
- args: {
92
- recipient: Address;
93
- orderSize: bigint;
94
- minAmountOut?: bigint;
95
- sqrtPriceLimitX96?: bigint;
96
- tradeReferrer?: Address;
97
- };
98
- };
99
-
100
- /**
101
- * Creates a trade call parameters object for buy or sell
102
- * @param {TradeParams} params - The trade parameters
103
- * @returns {SimulateContractParameters} The contract call parameters
104
- */
105
- export function tradeCoinCall({
106
- target,
107
- direction,
108
- args: {
109
- recipient,
110
- orderSize,
111
- minAmountOut = 0n,
112
- sqrtPriceLimitX96 = 0n,
113
- tradeReferrer = zeroAddress,
114
- },
115
- }: TradeParams): SimulateContractParameters {
116
- return {
117
- abi: coinABI,
118
- functionName: direction,
119
- address: target,
120
- args: [
121
- recipient,
122
- orderSize,
123
- minAmountOut,
124
- sqrtPriceLimitX96,
125
- tradeReferrer,
126
- ],
127
- value: direction === "buy" ? orderSize : 0n,
128
- } as const;
129
- }
130
-
131
- /**
132
- * Gets the trade event from transaction receipt logs
133
- * @param {TransactionReceipt} receipt - The transaction receipt containing the logs
134
- * @param {'buy' | 'sell'} direction - The direction of the trade
135
- * @returns {TradeEventArgs | undefined} The decoded trade event args if found
136
- */
137
- export function getTradeFromLogs(
138
- receipt: TransactionReceipt,
139
- direction: "buy" | "sell",
140
- ): TradeEventArgs | undefined {
141
- const eventLogs = parseEventLogs({
142
- abi: coinABI,
143
- logs: receipt.logs,
144
- });
145
-
146
- if (direction === "buy") {
147
- return eventLogs.find((log) => log.eventName === "CoinBuy")?.args;
148
- }
149
- return eventLogs.find((log) => log.eventName === "CoinSell")?.args;
150
- }
151
-
152
- /**
153
- * Executes a trade transaction
154
- * @param {TradeParams} params - The trade parameters
155
- * @param {PublicClient} publicClient - The viem public client instance
156
- * @param {WalletClient} walletClient - The viem wallet client instance
157
- * @returns {Promise<{
158
- * hash: `0x${string}`,
159
- * receipt: TransactionReceipt,
160
- * trade: TradeEventArgs | undefined
161
- * }>} The transaction result with trade details
162
- */
163
- export async function tradeCoin(
164
- params: TradeParams,
165
- walletClient: WalletClient,
166
- publicClient: GenericPublicClient,
167
- ) {
168
- validateClientNetwork(publicClient);
169
- const { request } = await publicClient.simulateContract({
170
- ...tradeCoinCall(params),
171
- account: walletClient.account,
172
- });
173
- const hash = await walletClient.writeContract(request);
174
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
175
- const trade = getTradeFromLogs(receipt, params.direction);
176
-
177
- return {
178
- hash,
179
- receipt,
180
- trade,
181
- };
182
- }