Skip to content

Commit e127b33

Browse files
iainnashkulkarohan
authored andcommitted
Update mint client to fix reading from subgraph (#392)
* update mint client to fix reading from subgraph * update mint-client * update mint client to use subgraph price * add changeset and update the fixedPrice subgraph fetch
1 parent 733d85a commit e127b33

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

Diff for: .changeset/sharp-bobcats-sin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zoralabs/protocol-sdk": patch
3+
---
4+
5+
Fix reading the FIXED_PRICE_MINTER from the subgraph

Diff for: packages/protocol-sdk/src/create/1155-create-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const DEFAULT_SALE_SETTINGS = {
4545
};
4646

4747
// Hardcode the permission bit for the minter
48-
const PERMISSION_BIT_MINTER = 2n ** 2n;
48+
const PERMISSION_BIT_MINTER = 4n;
4949

5050
type ContractType =
5151
| {

Diff for: packages/protocol-sdk/src/mint/mint-api-client.ts

+27-5
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,40 @@ export class MintAPIClient {
5656
}: {
5757
contractAddress: string;
5858
tokenId: bigint;
59-
}): Promise<undefined | string> {
59+
}): Promise<undefined | { address: Address; pricePerToken: bigint }> {
6060
const { retries, post } = this.httpClient;
6161
return retries(async () => {
6262
const response = await post<any>(this.networkConfig.subgraphUrl, {
63-
query:
64-
"query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
63+
query: `query ($id: ID!) {
64+
zoraCreateToken(id: $id) {
65+
id
66+
salesStrategies(where: {type: "FIXED_PRICE"}) {
67+
type
68+
fixedPrice {
69+
address
70+
pricePerToken
71+
saleEnd
72+
saleStart
73+
maxTokensPerAddress
74+
}
75+
}
76+
}
77+
}`,
6578
variables: {
6679
id: `${contractAddress.toLowerCase()}-${tokenId.toString()}`,
6780
},
6881
});
69-
return response.zoraCreateToken?.salesStrategies?.find(() => true)
70-
?.fixedPriceMinterAddress;
82+
83+
const fixedPrice: {
84+
address: Address;
85+
pricePerToken: string;
86+
} = response.data?.zoraCreateToken?.salesStrategies?.find(() => true)
87+
?.fixedPrice;
88+
89+
return {
90+
address: fixedPrice.address as Address,
91+
pricePerToken: BigInt(fixedPrice.pricePerToken),
92+
};
7193
});
7294
}
7395

Diff for: packages/protocol-sdk/src/mint/mint-client.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class MintClient {
109109
if (mintContextType === "zora_create_1155") {
110110
return await get1155MintCosts({
111111
mintable,
112+
price: BigInt(mintable.cost.native_price.raw),
112113
publicClient: this.publicClient,
113114
quantityToMint: BigInt(quantityToMint),
114115
});
@@ -306,10 +307,12 @@ export type MintCosts = {
306307

307308
export async function get1155MintCosts({
308309
mintable,
310+
price,
309311
publicClient,
310312
quantityToMint,
311313
}: {
312314
mintable: MintableGetTokenResponse;
315+
price: bigint;
313316
publicClient: PublicClient;
314317
quantityToMint: bigint;
315318
}): Promise<MintCosts> {
@@ -321,8 +324,7 @@ export async function get1155MintCosts({
321324
});
322325

323326
const mintFeeForTokens = mintFee * quantityToMint;
324-
const tokenPurchaseCost =
325-
BigInt(mintable.cost.native_price.raw) * quantityToMint;
327+
const tokenPurchaseCost = price * quantityToMint;
326328

327329
return {
328330
mintFee: mintFeeForTokens,
@@ -354,19 +356,22 @@ async function makePrepareMint1155TokenParams({
354356

355357
const address = mintable.collection.address as Address;
356358

359+
const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
360+
contractAddress: address,
361+
tokenId: BigInt(mintable.token_id!),
362+
});
363+
357364
const mintValue = (
358365
await get1155MintCosts({
359366
mintable,
367+
price:
368+
tokenFixedPriceMinter?.pricePerToken ||
369+
BigInt(mintable.cost.native_price.raw),
360370
publicClient,
361371
quantityToMint: mintQuantity,
362372
})
363373
).totalCost;
364374

365-
const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
366-
contractAddress: address,
367-
tokenId: BigInt(mintable.token_id!),
368-
});
369-
370375
const result = {
371376
abi: zoraCreator1155ImplABI,
372377
functionName: "mintWithRewards",
@@ -375,7 +380,7 @@ async function makePrepareMint1155TokenParams({
375380
address,
376381
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
377382
args: [
378-
(tokenFixedPriceMinter ||
383+
(tokenFixedPriceMinter?.address ||
379384
zoraCreatorFixedPriceSaleStrategyAddress[999]) as Address,
380385
BigInt(mintable.token_id!),
381386
mintQuantity,

0 commit comments

Comments
 (0)