Skip to content

Commit bd37142

Browse files
authored
Fix params for docs (#1309)
* Fix params for docs * small code cleanup * fix base client src
1 parent a001721 commit bd37142

File tree

4 files changed

+79
-28
lines changed

4 files changed

+79
-28
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zoralabs/coins-sdk": patch
3+
---
4+
5+
Small trade types fixes

docs/pages/coins/sdk/create-coin.mdx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { DeployCurrency, InitialPurchaseCurrency, ValidMetadataURI } from "@zora
1717
type CreateCoinArgs = {
1818
name: string; // The name of the coin (e.g., "My Awesome Coin")
1919
symbol: string; // The trading symbol for the coin (e.g., "MAC")
20-
uri: ValidMetadataURI; // Metadata URI (an IPFS URI is recommended)
20+
uri: ValidMetadataURI; // Metadata URI (an IPFS URI is recommended)
2121
chainId?: number; // The chain ID (defaults to base mainnet)
2222
owners?: Address[]; // Optional array of owner addresses, defaults to [payoutRecipient]
2323
payoutRecipient: Address; // Address that receives creator earnings
@@ -163,8 +163,9 @@ If you're using WAGMI in your frontend application, you can use the lower-level
163163
```typescript
164164
import * as React from "react";
165165
import { createCoinCall, DeployCurrency, InitialPurchaseCurrency, ValidMetadataURI } from "@zoralabs/coins-sdk";
166-
import { Address } from "viem";
166+
import { Address, parseEther } from "viem";
167167
import { useWriteContract, useSimulateContract } from "wagmi";
168+
import { base } from "viem/chains";
168169

169170
// Define coin parameters
170171
const coinParams = {
@@ -173,12 +174,12 @@ const coinParams = {
173174
uri: "ipfs://bafybeigoxzqzbnxsn35vq7lls3ljxdcwjafxvbvkivprsodzrptpiguysy" as ValidMetadataURI,
174175
payoutRecipient: "0xYourAddress" as Address,
175176
platformReferrer: "0xOptionalPlatformReferrerAddress" as Address,
176-
// chainId: base.id, // Optional: defaults to base.id
177-
// currency: DeployCurrency.ZORA, // Optional: ZORA or ETH
178-
// initialPurchase: { // Optional: Purchase initial supply during creation
179-
// currency: InitialPurchaseCurrency.ETH,
180-
// amount: 0.01n * 10n ** 18n, // 0.01 ETH in wei
181-
// },
177+
chainId: base.id, // Optional: defaults to base.id
178+
currency: DeployCurrency.ZORA, // Optional: ZORA or ETH
179+
initialPurchase: { // Optional: Purchase initial supply during creation
180+
currency: InitialPurchaseCurrency.ETH,
181+
amount: parseEther("0.01"), // 0.01 ETH in wei
182+
},
182183
};
183184

184185
// Create configuration for wagmi

docs/pages/coins/sdk/trade-coin.mdx

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ const tradeParameters: TradeParameters = {
4343
sender: account.address,
4444
};
4545

46-
const receipt = await tradeCoin(
46+
const receipt = await tradeCoin({
4747
tradeParameters,
4848
walletClient,
4949
account,
50-
publicClient
51-
);
50+
publicClient,
51+
});
5252
```
5353

5454
### Trading Creator Coin for ETH
@@ -65,12 +65,12 @@ const tradeParameters: TradeParameters = {
6565
sender: account.address,
6666
};
6767

68-
const receipt = await tradeCoin(
68+
const receipt = await tradeCoin({
6969
tradeParameters,
7070
walletClient,
7171
account,
72-
publicClient
73-
);
72+
publicClient,
73+
});
7474
```
7575

7676
### Trading USDC for Creator Coin (with Permits)
@@ -94,12 +94,12 @@ const tradeParameters: TradeParameters = {
9494
sender: account.address,
9595
};
9696

97-
const receipt = await tradeCoin(
97+
const receipt = await tradeCoin({
9898
tradeParameters,
9999
walletClient,
100100
account,
101-
publicClient
102-
);
101+
publicClient,
102+
});
103103
```
104104

105105
### Trading Between ERC20 Tokens
@@ -124,12 +124,44 @@ const tradeParameters: TradeParameters = {
124124
sender: account.address,
125125
};
126126

127-
const receipt = await tradeCoin(
127+
const receipt = await tradeCoin({
128+
tradeParameters,
129+
walletClient,
130+
account,
131+
publicClient,
132+
});
133+
```
134+
135+
### Disabling Transaction Validation
136+
137+
By default, `tradeCoin` validates transactions before execution. You can disable this for faster execution:
138+
139+
```typescript
140+
const receipt = await tradeCoin({
141+
tradeParameters,
142+
walletClient,
143+
account,
144+
publicClient,
145+
validateTransaction: false, // Skip validation and gas estimation
146+
});
147+
```
148+
149+
## Function Signature
150+
151+
```typescript
152+
async function tradeCoin({
128153
tradeParameters,
129154
walletClient,
130155
account,
131-
publicClient
132-
);
156+
publicClient,
157+
validateTransaction = true,
158+
}: {
159+
tradeParameters: TradeParameters;
160+
walletClient: WalletClient;
161+
account: Account;
162+
publicClient: GenericPublicClient;
163+
validateTransaction?: boolean;
164+
})
133165
```
134166

135167
## Trade Parameters

packages/coins-sdk/src/actions/tradeCoin.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,32 @@ export type TradeParameters = {
9292
permitActiveSeconds?: number;
9393
};
9494

95-
export async function tradeCoin(
96-
tradeParameters: TradeParameters,
97-
walletClient: WalletClient,
98-
account: Account,
99-
publicClient: GenericPublicClient,
95+
export async function tradeCoin({
96+
tradeParameters,
97+
walletClient,
98+
account,
99+
publicClient,
100100
validateTransaction = true,
101-
) {
101+
}: {
102+
tradeParameters: TradeParameters;
103+
walletClient: WalletClient;
104+
account: Account;
105+
publicClient: GenericPublicClient;
106+
validateTransaction?: boolean;
107+
}) {
102108
const quote = await createTradeCall(tradeParameters);
103109

110+
// Set default recipient to wallet sender address if not provided
111+
if (!tradeParameters.recipient) {
112+
tradeParameters.recipient = account.address;
113+
}
114+
104115
// todo replace any
105116
const signatures: { signature: Hex; permit: any }[] = [];
106117
if (quote.permits) {
107118
for (const permit of quote.permits) {
108-
const [, nonce] = await publicClient.readContract({
119+
// return values: amount, expiration, nonce
120+
const [, , nonce] = await publicClient.readContract({
109121
abi: permit2ABI,
110122
address: permit2Address[base.id],
111123
functionName: "allowance",
@@ -120,7 +132,7 @@ export async function tradeCoin(
120132
abi: erc20Abi,
121133
address: permitToken,
122134
functionName: "allowance",
123-
args: [permitToken, permit2Address[base.id]],
135+
args: [account.address, permit2Address[base.id]],
124136
});
125137
if (allowance < BigInt(permit.permit.details.amount)) {
126138
const approvalTx = await walletClient.writeContract({
@@ -223,6 +235,7 @@ export async function createTradeCall(
223235
});
224236

225237
if (!quote.data) {
238+
console.error(quote);
226239
throw new Error("Quote failed");
227240
}
228241

0 commit comments

Comments
 (0)