@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.
- package/CHANGELOG.md +13 -0
- package/dist/actions/createCoin.d.ts +11 -4
- package/dist/actions/createCoin.d.ts.map +1 -1
- package/dist/actions/updateCoinURI.d.ts +1 -1
- package/dist/actions/updateCoinURI.d.ts.map +1 -1
- package/dist/actions/updatePayoutRecipient.d.ts +1 -1
- package/dist/actions/updatePayoutRecipient.d.ts.map +1 -1
- package/dist/api/api-key.d.ts +2 -1
- package/dist/api/api-key.d.ts.map +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/internal.d.ts +2 -2
- package/dist/api/internal.d.ts.map +1 -1
- package/dist/index.cjs +301 -103
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +320 -122
- package/dist/index.js.map +1 -1
- package/dist/metadata/cleanAndValidateMetadataURI.d.ts +1 -1
- package/dist/metadata/cleanAndValidateMetadataURI.d.ts.map +1 -1
- package/dist/metadata/index.d.ts +1 -1
- package/dist/metadata/index.d.ts.map +1 -1
- package/dist/metadata/validateMetadataURIContent.d.ts +1 -1
- package/dist/metadata/validateMetadataURIContent.d.ts.map +1 -1
- package/dist/uploader/index.d.ts +10 -0
- package/dist/uploader/index.d.ts.map +1 -0
- package/dist/uploader/metadata.d.ts +44 -0
- package/dist/uploader/metadata.d.ts.map +1 -0
- package/dist/uploader/providers/zora.d.ts +18 -0
- package/dist/uploader/providers/zora.d.ts.map +1 -0
- package/dist/uploader/types.d.ts +21 -0
- package/dist/uploader/types.d.ts.map +1 -0
- package/dist/utils/getPrepurchaseHook.d.ts +16 -0
- package/dist/utils/getPrepurchaseHook.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/actions/createCoin.ts +33 -7
- package/src/actions/updateCoinURI.ts +1 -1
- package/src/actions/updatePayoutRecipient.ts +1 -1
- package/src/api/api-key.ts +5 -1
- package/src/api/index.ts +1 -0
- package/src/api/internal.ts +3 -3
- package/src/index.ts +9 -9
- package/src/metadata/cleanAndValidateMetadataURI.ts +1 -5
- package/src/metadata/index.ts +1 -4
- package/src/metadata/validateMetadataURIContent.ts +2 -4
- package/src/uploader/index.ts +16 -0
- package/src/uploader/metadata.ts +214 -0
- package/src/uploader/providers/zora.ts +86 -0
- package/src/uploader/tests/metadata.test.ts +331 -0
- package/src/uploader/tests/providers.test.ts +131 -0
- package/src/uploader/types.ts +27 -0
- package/src/utils/getPrepurchaseHook.ts +59 -0
- package/dist/actions/tradeCoin.d.ts +0 -75
- package/dist/actions/tradeCoin.d.ts.map +0 -1
- package/src/actions/tradeCoin.ts +0 -182
package/src/actions/tradeCoin.ts
DELETED
|
@@ -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
|
-
}
|