@zoralabs/protocol-sdk 0.11.12 → 0.12.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.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +10 -0
- package/dist/apis/network-config.d.ts +3 -0
- package/dist/apis/network-config.d.ts.map +1 -0
- package/dist/create/contract-setup.d.ts +3 -4
- package/dist/create/contract-setup.d.ts.map +1 -1
- package/dist/create/create-client.d.ts +53 -0
- package/dist/create/create-client.d.ts.map +1 -0
- package/dist/create/types.d.ts +11 -3
- package/dist/create/types.d.ts.map +1 -1
- package/dist/fixtures/contract-setup.d.ts +2 -2
- package/dist/fixtures/contract-setup.d.ts.map +1 -1
- package/dist/fixtures/rewards-query-results.d.ts +0 -1
- package/dist/fixtures/rewards-query-results.d.ts.map +1 -1
- package/dist/fixtures/secondary.d.ts +3 -6
- package/dist/fixtures/secondary.d.ts.map +1 -1
- package/dist/index.cjs +1509 -1396
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1559 -1465
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +21 -9
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +24 -22
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/strategies-parsing.d.ts +28 -0
- package/dist/mint/strategies-parsing.d.ts.map +1 -0
- package/dist/mint/subgraph-mint-getter.d.ts +2 -6
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/types.d.ts +25 -8
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/rewards/rewards-client.d.ts +7 -3
- package/dist/rewards/rewards-client.d.ts.map +1 -1
- package/dist/rewards/rewards-queries.d.ts +14 -11
- package/dist/rewards/rewards-queries.d.ts.map +1 -1
- package/dist/rewards/subgraph-queries.d.ts +0 -1
- package/dist/rewards/subgraph-queries.d.ts.map +1 -1
- package/dist/rewards/subgraph-rewards-getter.d.ts +2 -8
- package/dist/rewards/subgraph-rewards-getter.d.ts.map +1 -1
- package/dist/sdk.d.ts +9 -3
- package/dist/sdk.d.ts.map +1 -1
- package/dist/secondary/secondary-client.d.ts +7 -8
- package/dist/secondary/secondary-client.d.ts.map +1 -1
- package/dist/secondary/uniswap/uniswapQuote.d.ts +0 -1
- package/dist/secondary/uniswap/uniswapQuote.d.ts.map +1 -1
- package/dist/secondary/utils.d.ts +1 -2
- package/dist/secondary/utils.d.ts.map +1 -1
- package/dist/types.d.ts +6 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/apis/network-config.ts +8 -0
- package/src/apis/subgraph-getter.ts +1 -1
- package/src/comments/comments.test.ts +11 -22
- package/src/create/contract-setup.ts +3 -4
- package/src/create/{1155-create-helper.test.ts → create-client.test.ts} +52 -88
- package/src/create/{1155-create-helper.ts → create-client.ts} +129 -63
- package/src/create/types.ts +13 -3
- package/src/fixtures/contract-setup.ts +3 -3
- package/src/fixtures/rewards-query-results.ts +2 -9
- package/src/fixtures/secondary.ts +16 -10
- package/src/index.ts +34 -4
- package/src/mint/mint-client.test.ts +37 -64
- package/src/mint/mint-client.ts +36 -32
- package/src/mint/mint-queries.ts +73 -54
- package/src/mint/strategies-parsing.ts +311 -0
- package/src/mint/subgraph-mint-getter.ts +4 -304
- package/src/mint/types.ts +36 -7
- package/src/premint/premint-api-client.ts +1 -1
- package/src/premint/premint-client.ts +1 -1
- package/src/rewards/rewards-client.test.ts +318 -21
- package/src/rewards/rewards-client.ts +15 -16
- package/src/rewards/rewards-queries.ts +116 -36
- package/src/rewards/subgraph-queries.ts +0 -2
- package/src/rewards/subgraph-rewards-getter.ts +3 -13
- package/src/sdk.ts +9 -7
- package/src/secondary/secondary-client.test.ts +39 -40
- package/src/secondary/secondary-client.ts +14 -33
- package/src/secondary/uniswap/uniswapQuote.ts +3 -2
- package/src/secondary/utils.ts +2 -2
- package/src/types.ts +15 -4
- package/src/utils.ts +9 -3
- package/dist/create/1155-create-helper.d.ts +0 -29
- package/dist/create/1155-create-helper.d.ts.map +0 -1
package/src/mint/types.ts
CHANGED
|
@@ -2,8 +2,11 @@ import { Account, Address } from "viem";
|
|
|
2
2
|
import {
|
|
3
3
|
GenericTokenIdTypes,
|
|
4
4
|
SimulateContractParametersWithAccount,
|
|
5
|
+
WithPublicClient,
|
|
5
6
|
} from "src/types";
|
|
6
7
|
import { AllowListEntry } from "src/allow-list/types";
|
|
8
|
+
import { TokenQueryResult } from "./subgraph-queries";
|
|
9
|
+
import { IPremintGetter } from "src/premint/premint-api-client";
|
|
7
10
|
|
|
8
11
|
export type MintParameters<MintType> = {
|
|
9
12
|
/** Type of the collection to be minted. */
|
|
@@ -33,18 +36,40 @@ export type MintTypes =
|
|
|
33
36
|
| Erc721MintParameters
|
|
34
37
|
| PremintMintParameters;
|
|
35
38
|
|
|
36
|
-
export type
|
|
39
|
+
export type GetMintParametersArguments = MintTypes & {
|
|
37
40
|
/** Address of the contract that the item belongs to */
|
|
38
41
|
tokenContract: Address;
|
|
39
42
|
preferredSaleType?: SaleType;
|
|
40
43
|
};
|
|
41
44
|
|
|
42
|
-
|
|
45
|
+
type WithOptionalGetters<T> = T & {
|
|
46
|
+
/** Optional override for getting onchain mints using indexed events */
|
|
47
|
+
mintGetter?: IOnchainMintGetter;
|
|
48
|
+
/** Optional override for getting premints */
|
|
49
|
+
premintGetter?: IPremintGetter;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type WithPublicClientAndOptionalGetters<T> = WithOptionalGetters<
|
|
53
|
+
WithPublicClient<T>
|
|
54
|
+
>;
|
|
55
|
+
|
|
56
|
+
export type WithPublicClientAndRequiredGetters<T> = WithPublicClient<T> & {
|
|
57
|
+
mintGetter: IOnchainMintGetter;
|
|
58
|
+
premintGetter: IPremintGetter;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type GetMintParameters =
|
|
62
|
+
WithPublicClientAndOptionalGetters<GetMintParametersArguments>;
|
|
63
|
+
|
|
64
|
+
export type GetMintsOfContractParametersArguments = {
|
|
43
65
|
/** Address of the contract to get the tokens of */
|
|
44
66
|
tokenContract: Address;
|
|
45
67
|
preferredSaleType?: SaleType;
|
|
46
68
|
};
|
|
47
69
|
|
|
70
|
+
export type GetMintsOfContractParameters =
|
|
71
|
+
WithPublicClientAndOptionalGetters<GetMintsOfContractParametersArguments>;
|
|
72
|
+
|
|
48
73
|
export const isOnChainMint = (mint: MintTypes): mint is OnChainMintParameters =>
|
|
49
74
|
mint.mintType !== "premint";
|
|
50
75
|
|
|
@@ -95,7 +120,13 @@ export type MakeMintParametersArguments =
|
|
|
95
120
|
| Make721MintArguments
|
|
96
121
|
| MakePremintMintParametersArguments;
|
|
97
122
|
|
|
98
|
-
export type
|
|
123
|
+
export type MakeMintParameters =
|
|
124
|
+
WithPublicClient<MakeMintParametersArguments> & {
|
|
125
|
+
mintGetter?: IOnchainMintGetter;
|
|
126
|
+
premintGetter?: IPremintGetter;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export type GetMintCostsParameterArguments = {
|
|
99
130
|
/** Address of token contract/collection to get the mint costs for */
|
|
100
131
|
collection: Address;
|
|
101
132
|
/** Quantity of tokens that will be minted */
|
|
@@ -144,7 +175,7 @@ type AllowListSaleStrategy = SaleStrategy<"allowlist"> & {
|
|
|
144
175
|
merkleRoot: string;
|
|
145
176
|
};
|
|
146
177
|
|
|
147
|
-
type ZoraTimedSaleStrategy = SaleStrategy<"timed"> & {
|
|
178
|
+
export type ZoraTimedSaleStrategy = SaleStrategy<"timed"> & {
|
|
148
179
|
mintFee: bigint;
|
|
149
180
|
erc20Z: Address;
|
|
150
181
|
pool: Address;
|
|
@@ -237,9 +268,7 @@ export interface IOnchainMintGetter {
|
|
|
237
268
|
getMintable(params: {
|
|
238
269
|
tokenAddress: Address;
|
|
239
270
|
tokenId?: GenericTokenIdTypes;
|
|
240
|
-
|
|
241
|
-
blockTime: bigint;
|
|
242
|
-
}): Promise<GetMintableReturn>;
|
|
271
|
+
}): Promise<TokenQueryResult>;
|
|
243
272
|
|
|
244
273
|
getContractMintable(params: {
|
|
245
274
|
tokenAddress: Address;
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
} from "../apis/http-api-base";
|
|
5
5
|
import { components, paths } from "../apis/generated/premint-api-types";
|
|
6
6
|
import { ZORA_API_BASE } from "../constants";
|
|
7
|
-
import { getApiNetworkConfigForChain } from "src/mint/subgraph-mint-getter";
|
|
8
7
|
import {
|
|
9
8
|
PremintConfigVersion,
|
|
10
9
|
PremintConfigWithVersion,
|
|
@@ -20,6 +19,7 @@ import {
|
|
|
20
19
|
encodePostSignatureInput,
|
|
21
20
|
} from "./conversions";
|
|
22
21
|
import { ContractCreationConfigOrAddress } from "./contract-types";
|
|
22
|
+
import { getApiNetworkConfigForChain } from "src/apis/network-config";
|
|
23
23
|
|
|
24
24
|
type PremintNextUIDGetType =
|
|
25
25
|
paths["/signature/{chain_name}/{collection_address}/next_uid"]["get"];
|
|
@@ -42,7 +42,6 @@ import {
|
|
|
42
42
|
import { IPremintAPI, IPremintGetter } from "./premint-api-client";
|
|
43
43
|
import type { DecodeEventLogReturnType } from "viem";
|
|
44
44
|
import { OPEN_EDITION_MINT_SIZE } from "../constants";
|
|
45
|
-
import { getApiNetworkConfigForChain } from "src/mint/subgraph-mint-getter";
|
|
46
45
|
import {
|
|
47
46
|
makeContractParameters,
|
|
48
47
|
mintRecipientOrAccount,
|
|
@@ -59,6 +58,7 @@ import {
|
|
|
59
58
|
} from "src/mint/types";
|
|
60
59
|
import { PremintFromApi } from "./conversions";
|
|
61
60
|
import { SimulateContractParametersWithAccount } from "src/types";
|
|
61
|
+
import { getApiNetworkConfigForChain } from "src/apis/network-config";
|
|
62
62
|
|
|
63
63
|
type PremintedV2LogType = DecodeEventLogReturnType<
|
|
64
64
|
typeof zoraCreator1155PremintExecutorImplABI,
|
|
@@ -3,7 +3,6 @@ import { encodeAbiParameters, erc20Abi, parseEther } from "viem";
|
|
|
3
3
|
import { zoraSepolia, base } from "viem/chains";
|
|
4
4
|
import { forkUrls, makeAnvilTest } from "src/anvil";
|
|
5
5
|
import { simulateAndWriteContractWithRetries } from "src/test-utils";
|
|
6
|
-
import { createCollectorClient, createCreatorClient } from "src/sdk";
|
|
7
6
|
import { new1155ContractVersion } from "src/create/contract-setup";
|
|
8
7
|
import { ISubgraphQuerier } from "src/apis/subgraph-querier";
|
|
9
8
|
import { mockTimedSaleStrategyTokenQueryResult } from "src/fixtures/mint-query-results";
|
|
@@ -16,6 +15,9 @@ import { makeContractParameters } from "src/utils";
|
|
|
16
15
|
import { setupContractAndToken } from "src/fixtures/contract-setup";
|
|
17
16
|
import { advanceToSaleAndAndLaunchMarket } from "src/fixtures/secondary";
|
|
18
17
|
import { CreatorERC20zQueryResult } from "./subgraph-queries";
|
|
18
|
+
import { getRewardsBalances } from "./rewards-queries";
|
|
19
|
+
import { mint } from "src/mint/mint-client";
|
|
20
|
+
import { getSecondaryInfo } from "src/secondary/utils";
|
|
19
21
|
|
|
20
22
|
describe("rewardsClient", () => {
|
|
21
23
|
makeAnvilTest({
|
|
@@ -24,13 +26,10 @@ describe("rewardsClient", () => {
|
|
|
24
26
|
anvilChainId: base.id,
|
|
25
27
|
})(
|
|
26
28
|
"it can query rewards balances where there are multiple minters",
|
|
27
|
-
async ({ viemClients: { publicClient
|
|
28
|
-
const
|
|
29
|
-
chainId: chain.id,
|
|
30
|
-
publicClient,
|
|
31
|
-
});
|
|
32
|
-
const rewardsBalance = await creatorClient.getRewardsBalances({
|
|
29
|
+
async ({ viemClients: { publicClient } }) => {
|
|
30
|
+
const rewardsBalance = await getRewardsBalances({
|
|
33
31
|
account: "0x129F04B140Acc1AA350be2F9f048C178103c62f3",
|
|
32
|
+
publicClient,
|
|
34
33
|
});
|
|
35
34
|
|
|
36
35
|
const erc20zKeys = Object.keys(rewardsBalance.secondaryRoyalties.erc20);
|
|
@@ -80,18 +79,14 @@ describe("rewardsClient", () => {
|
|
|
80
79
|
}),
|
|
81
80
|
});
|
|
82
81
|
|
|
83
|
-
const
|
|
84
|
-
chainId: chain.id,
|
|
85
|
-
publicClient,
|
|
86
|
-
mintGetter,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const { parameters: collectParameters } = await collectorClient.mint({
|
|
82
|
+
const { parameters: collectParameters } = await mint({
|
|
90
83
|
minterAccount: collectorAccount,
|
|
91
84
|
mintType: "1155",
|
|
92
85
|
quantityToMint,
|
|
93
86
|
tokenId: newTokenId,
|
|
94
87
|
tokenContract: contractAddress,
|
|
88
|
+
publicClient,
|
|
89
|
+
mintGetter,
|
|
95
90
|
});
|
|
96
91
|
|
|
97
92
|
await simulateAndWriteContractWithRetries({
|
|
@@ -180,18 +175,210 @@ describe("rewardsClient", () => {
|
|
|
180
175
|
}),
|
|
181
176
|
});
|
|
182
177
|
|
|
183
|
-
const
|
|
184
|
-
|
|
178
|
+
const { parameters: collectParameters } = await mint({
|
|
179
|
+
minterAccount: collectorAccount,
|
|
180
|
+
mintType: "1155",
|
|
181
|
+
quantityToMint,
|
|
182
|
+
tokenId: newTokenId,
|
|
183
|
+
tokenContract: contractAddress,
|
|
185
184
|
publicClient,
|
|
186
185
|
mintGetter,
|
|
187
186
|
});
|
|
188
187
|
|
|
189
|
-
|
|
188
|
+
await simulateAndWriteContractWithRetries({
|
|
189
|
+
parameters: collectParameters,
|
|
190
|
+
walletClient,
|
|
191
|
+
publicClient,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
await advanceToSaleAndAndLaunchMarket({
|
|
195
|
+
account: collectorAccount,
|
|
196
|
+
publicClient,
|
|
197
|
+
walletClient,
|
|
198
|
+
testClient,
|
|
199
|
+
contractAddress,
|
|
200
|
+
tokenId: newTokenId,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const erc20z = (await getSecondaryInfo({
|
|
204
|
+
contract: contractAddress,
|
|
205
|
+
tokenId: newTokenId,
|
|
206
|
+
publicClient,
|
|
207
|
+
}))!.erc20z!;
|
|
208
|
+
|
|
209
|
+
// after market is launched, by 100 from the pool. there should be some rewards
|
|
210
|
+
// balances from secondary royalties
|
|
211
|
+
await simulateAndWriteContractWithRetries({
|
|
212
|
+
parameters: makeContractParameters({
|
|
213
|
+
abi: secondarySwapABI,
|
|
214
|
+
address:
|
|
215
|
+
secondarySwapAddress[chain.id as keyof typeof secondarySwapAddress],
|
|
216
|
+
functionName: "buy1155",
|
|
217
|
+
args: [
|
|
218
|
+
erc20z,
|
|
219
|
+
100n,
|
|
220
|
+
collectorAccount,
|
|
221
|
+
collectorAccount,
|
|
222
|
+
parseEther("1"),
|
|
223
|
+
0n,
|
|
224
|
+
],
|
|
225
|
+
account: collectorAccount,
|
|
226
|
+
value: parseEther("1"),
|
|
227
|
+
}),
|
|
228
|
+
walletClient,
|
|
229
|
+
publicClient,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const abiParameters = [
|
|
233
|
+
{ name: "recipient", internalType: "address payable", type: "address" },
|
|
234
|
+
{ name: "minEthToAcquire", internalType: "uint256", type: "uint256" },
|
|
235
|
+
{ name: "sqrtPriceLimitX96", internalType: "uint160", type: "uint160" },
|
|
236
|
+
] as const;
|
|
237
|
+
const sellData = encodeAbiParameters(abiParameters, [
|
|
238
|
+
collectorAccount,
|
|
239
|
+
0n,
|
|
240
|
+
0n,
|
|
241
|
+
]);
|
|
242
|
+
await simulateAndWriteContractWithRetries({
|
|
243
|
+
parameters: makeContractParameters({
|
|
244
|
+
functionName: "safeTransferFrom",
|
|
245
|
+
address: contractAddress,
|
|
246
|
+
abi: zoraCreator1155ImplABI,
|
|
247
|
+
account: collectorAccount,
|
|
248
|
+
args: [
|
|
249
|
+
collectorAccount,
|
|
250
|
+
secondarySwapAddress[chain.id as keyof typeof secondarySwapAddress],
|
|
251
|
+
newTokenId,
|
|
252
|
+
100n,
|
|
253
|
+
sellData,
|
|
254
|
+
],
|
|
255
|
+
}),
|
|
256
|
+
walletClient,
|
|
257
|
+
publicClient,
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// now we should be able to get rewards balances for these royalties
|
|
261
|
+
|
|
262
|
+
const mockResult: CreatorERC20zQueryResult = {
|
|
263
|
+
zoraCreateTokens: [
|
|
264
|
+
{
|
|
265
|
+
salesStrategies: [
|
|
266
|
+
{
|
|
267
|
+
zoraTimedMinter: {
|
|
268
|
+
erc20Z: { id: erc20z },
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// we need to stub the subgraph return
|
|
277
|
+
rewardsGetter.subgraphQuerier.query = vi
|
|
278
|
+
.fn<ISubgraphQuerier["query"]>()
|
|
279
|
+
.mockResolvedValue(mockResult);
|
|
280
|
+
|
|
281
|
+
const rewardsBalance = await creatorClient.getRewardsBalances({
|
|
282
|
+
account: creatorAccount,
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
expect(rewardsBalance.protocolRewards).toBeGreaterThan(0n);
|
|
286
|
+
expect(rewardsBalance.secondaryRoyalties.erc20[erc20z]).toBeGreaterThan(
|
|
287
|
+
0,
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const beforeBalance = await publicClient.getBalance({
|
|
291
|
+
address: creatorAccount,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// it can withdraw all rewards
|
|
295
|
+
await simulateAndWriteContractWithRetries({
|
|
296
|
+
parameters: (
|
|
297
|
+
await creatorClient.withdrawRewards({
|
|
298
|
+
account: collectorAccount,
|
|
299
|
+
withdrawFor: creatorAccount,
|
|
300
|
+
claimSecondaryRoyalties: true,
|
|
301
|
+
})
|
|
302
|
+
).parameters,
|
|
303
|
+
publicClient,
|
|
304
|
+
walletClient,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const afterBalance = await publicClient.getBalance({
|
|
308
|
+
address: creatorAccount,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// make sure that some additional royalties were withdrawn, this is how we can do greater than
|
|
312
|
+
// we cant get exact precision
|
|
313
|
+
expect(afterBalance - beforeBalance).toBeGreaterThan(
|
|
314
|
+
rewardsBalance.protocolRewards,
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
const erc20balance = await publicClient.readContract({
|
|
318
|
+
abi: erc20Abi,
|
|
319
|
+
address: erc20z,
|
|
320
|
+
functionName: "balanceOf",
|
|
321
|
+
args: [creatorAccount],
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
expect(erc20balance).toBeGreaterThan(0);
|
|
325
|
+
},
|
|
326
|
+
30_000,
|
|
327
|
+
);
|
|
328
|
+
makeAnvilTest({
|
|
329
|
+
forkBlockNumber: 17938475,
|
|
330
|
+
forkUrl: forkUrls.zoraSepolia,
|
|
331
|
+
anvilChainId: zoraSepolia.id,
|
|
332
|
+
})(
|
|
333
|
+
"it can view and withdraw rewards and secondary royalties for mints",
|
|
334
|
+
async ({
|
|
335
|
+
viemClients: { publicClient, chain, walletClient, testClient },
|
|
336
|
+
}) => {
|
|
337
|
+
const creatorAccount = (await walletClient.getAddresses()!)[0]!;
|
|
338
|
+
const collectorAccount = (await walletClient.getAddresses()!)[1]!;
|
|
339
|
+
|
|
340
|
+
const {
|
|
341
|
+
creatorClient,
|
|
342
|
+
contractAddress,
|
|
343
|
+
newTokenId,
|
|
344
|
+
mintGetter,
|
|
345
|
+
rewardsGetter,
|
|
346
|
+
} = await setupContractAndToken({
|
|
347
|
+
chain,
|
|
348
|
+
publicClient,
|
|
349
|
+
creatorAccount,
|
|
350
|
+
walletClient,
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
await testClient.setBalance({
|
|
354
|
+
address: collectorAccount,
|
|
355
|
+
value: parseEther("100"),
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const quantityToMint = 1111n;
|
|
359
|
+
|
|
360
|
+
mintGetter.subgraphQuerier.query = vi
|
|
361
|
+
.fn<ISubgraphQuerier["query"]>()
|
|
362
|
+
.mockResolvedValue({
|
|
363
|
+
zoraCreateToken: mockTimedSaleStrategyTokenQueryResult({
|
|
364
|
+
chainId: chain.id,
|
|
365
|
+
tokenId: newTokenId,
|
|
366
|
+
contractAddress,
|
|
367
|
+
contractVersion:
|
|
368
|
+
new1155ContractVersion[
|
|
369
|
+
chain.id as keyof typeof new1155ContractVersion
|
|
370
|
+
],
|
|
371
|
+
}),
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
const { parameters: collectParameters } = await mint({
|
|
190
375
|
minterAccount: collectorAccount,
|
|
191
376
|
mintType: "1155",
|
|
192
377
|
quantityToMint,
|
|
193
378
|
tokenId: newTokenId,
|
|
194
379
|
tokenContract: contractAddress,
|
|
380
|
+
publicClient,
|
|
381
|
+
mintGetter,
|
|
195
382
|
});
|
|
196
383
|
|
|
197
384
|
await simulateAndWriteContractWithRetries({
|
|
@@ -201,19 +388,18 @@ describe("rewardsClient", () => {
|
|
|
201
388
|
});
|
|
202
389
|
|
|
203
390
|
await advanceToSaleAndAndLaunchMarket({
|
|
204
|
-
chainId: chain.id,
|
|
205
391
|
account: collectorAccount,
|
|
206
392
|
publicClient,
|
|
207
393
|
walletClient,
|
|
208
|
-
collectorClient,
|
|
209
394
|
testClient,
|
|
210
395
|
contractAddress,
|
|
211
396
|
tokenId: newTokenId,
|
|
212
397
|
});
|
|
213
398
|
|
|
214
|
-
const erc20z = (await
|
|
399
|
+
const erc20z = (await getSecondaryInfo({
|
|
215
400
|
contract: contractAddress,
|
|
216
401
|
tokenId: newTokenId,
|
|
402
|
+
publicClient,
|
|
217
403
|
}))!.erc20z!;
|
|
218
404
|
|
|
219
405
|
// after market is launched, by 100 from the pool. there should be some rewards
|
|
@@ -275,7 +461,6 @@ describe("rewardsClient", () => {
|
|
|
275
461
|
salesStrategies: [
|
|
276
462
|
{
|
|
277
463
|
zoraTimedMinter: {
|
|
278
|
-
secondaryActivated: true,
|
|
279
464
|
erc20Z: { id: erc20z },
|
|
280
465
|
},
|
|
281
466
|
},
|
|
@@ -336,4 +521,116 @@ describe("rewardsClient", () => {
|
|
|
336
521
|
},
|
|
337
522
|
30_000,
|
|
338
523
|
);
|
|
524
|
+
makeAnvilTest({
|
|
525
|
+
forkBlockNumber: 17938475,
|
|
526
|
+
forkUrl: forkUrls.zoraSepolia,
|
|
527
|
+
anvilChainId: zoraSepolia.id,
|
|
528
|
+
})(
|
|
529
|
+
"it can view and withdraw rewards and secondary royalties for mints when secondary market is not activated yet",
|
|
530
|
+
async ({
|
|
531
|
+
viemClients: { publicClient, chain, walletClient, testClient },
|
|
532
|
+
}) => {
|
|
533
|
+
const creatorAccount = (await walletClient.getAddresses()!)[0]!;
|
|
534
|
+
const collectorAccount = (await walletClient.getAddresses()!)[1]!;
|
|
535
|
+
|
|
536
|
+
const {
|
|
537
|
+
creatorClient,
|
|
538
|
+
contractAddress,
|
|
539
|
+
newTokenId,
|
|
540
|
+
mintGetter,
|
|
541
|
+
rewardsGetter,
|
|
542
|
+
} = await setupContractAndToken({
|
|
543
|
+
chain,
|
|
544
|
+
publicClient,
|
|
545
|
+
creatorAccount,
|
|
546
|
+
walletClient,
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
await testClient.setBalance({
|
|
550
|
+
address: collectorAccount,
|
|
551
|
+
value: parseEther("100"),
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
const quantityToMint = 1111n;
|
|
555
|
+
|
|
556
|
+
mintGetter.subgraphQuerier.query = vi
|
|
557
|
+
.fn<ISubgraphQuerier["query"]>()
|
|
558
|
+
.mockResolvedValue({
|
|
559
|
+
zoraCreateToken: mockTimedSaleStrategyTokenQueryResult({
|
|
560
|
+
chainId: chain.id,
|
|
561
|
+
tokenId: newTokenId,
|
|
562
|
+
contractAddress,
|
|
563
|
+
contractVersion:
|
|
564
|
+
new1155ContractVersion[
|
|
565
|
+
chain.id as keyof typeof new1155ContractVersion
|
|
566
|
+
],
|
|
567
|
+
}),
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
const { parameters: collectParameters } = await mint({
|
|
571
|
+
minterAccount: collectorAccount,
|
|
572
|
+
mintType: "1155",
|
|
573
|
+
quantityToMint,
|
|
574
|
+
tokenId: newTokenId,
|
|
575
|
+
tokenContract: contractAddress,
|
|
576
|
+
publicClient,
|
|
577
|
+
mintGetter,
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
await simulateAndWriteContractWithRetries({
|
|
581
|
+
parameters: collectParameters,
|
|
582
|
+
walletClient,
|
|
583
|
+
publicClient,
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
const erc20z = (await getSecondaryInfo({
|
|
587
|
+
contract: contractAddress,
|
|
588
|
+
tokenId: newTokenId,
|
|
589
|
+
publicClient,
|
|
590
|
+
}))!.erc20z!;
|
|
591
|
+
|
|
592
|
+
// now we should be able to get query rewards balances without any errors
|
|
593
|
+
// even though secondary market is not activated yet
|
|
594
|
+
|
|
595
|
+
const mockResult: CreatorERC20zQueryResult = {
|
|
596
|
+
zoraCreateTokens: [
|
|
597
|
+
{
|
|
598
|
+
salesStrategies: [
|
|
599
|
+
{
|
|
600
|
+
zoraTimedMinter: {
|
|
601
|
+
erc20Z: { id: erc20z },
|
|
602
|
+
},
|
|
603
|
+
},
|
|
604
|
+
],
|
|
605
|
+
},
|
|
606
|
+
],
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// we need to stub the subgraph return
|
|
610
|
+
rewardsGetter.subgraphQuerier.query = vi
|
|
611
|
+
.fn<ISubgraphQuerier["query"]>()
|
|
612
|
+
.mockResolvedValue(mockResult);
|
|
613
|
+
|
|
614
|
+
const rewardsBalance = await creatorClient.getRewardsBalances({
|
|
615
|
+
account: creatorAccount,
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
expect(rewardsBalance.protocolRewards).toBeGreaterThan(0n);
|
|
619
|
+
expect(rewardsBalance.secondaryRoyalties.erc20[erc20z]).toBeUndefined();
|
|
620
|
+
|
|
621
|
+
// it can withdraw all rewards
|
|
622
|
+
await simulateAndWriteContractWithRetries({
|
|
623
|
+
parameters: (
|
|
624
|
+
await creatorClient.withdrawRewards({
|
|
625
|
+
account: collectorAccount,
|
|
626
|
+
withdrawFor: creatorAccount,
|
|
627
|
+
claimSecondaryRoyalties: true,
|
|
628
|
+
})
|
|
629
|
+
).parameters,
|
|
630
|
+
publicClient,
|
|
631
|
+
walletClient,
|
|
632
|
+
});
|
|
633
|
+
},
|
|
634
|
+
30_000,
|
|
635
|
+
);
|
|
339
636
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IPublicClient } from "src/types";
|
|
2
2
|
import { IRewardsGetter } from "./subgraph-rewards-getter";
|
|
3
3
|
import { Account, Address } from "viem";
|
|
4
|
-
import {
|
|
4
|
+
import { getRewardsBalances, withdrawRewards } from "./rewards-queries";
|
|
5
5
|
|
|
6
6
|
export type WithdrawRewardsParams = {
|
|
7
7
|
// account is the address that is withdrawing the rewards
|
|
@@ -17,23 +17,25 @@ export type GetRewardsBalancesParams = {
|
|
|
17
17
|
account: Address | Account;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Please use functions directly without creating a client.
|
|
22
|
+
* Example: Instead of `new RewardsClient().withdrawRewards()`, use `withdrawRewards()`
|
|
23
|
+
* Import the functions you need directly from their respective modules:
|
|
24
|
+
* import { withdrawRewards, getRewardsBalances } from '@zoralabs/protocol-sdk'
|
|
25
|
+
*/
|
|
20
26
|
export class RewardsClient {
|
|
21
27
|
// Private properties to store chain ID, public client, and rewards getter
|
|
22
|
-
private readonly chainId: number;
|
|
23
28
|
private readonly publicClient: IPublicClient;
|
|
24
29
|
private readonly rewardsGetter: IRewardsGetter;
|
|
25
30
|
|
|
26
31
|
constructor({
|
|
27
|
-
chainId,
|
|
28
32
|
publicClient,
|
|
29
33
|
rewardsGetter,
|
|
30
34
|
}: {
|
|
31
|
-
chainId: number;
|
|
32
35
|
publicClient: IPublicClient;
|
|
33
36
|
rewardsGetter: IRewardsGetter;
|
|
34
37
|
}) {
|
|
35
38
|
// Initialize the private properties
|
|
36
|
-
this.chainId = chainId;
|
|
37
39
|
this.publicClient = publicClient;
|
|
38
40
|
this.rewardsGetter = rewardsGetter;
|
|
39
41
|
}
|
|
@@ -44,22 +46,19 @@ export class RewardsClient {
|
|
|
44
46
|
withdrawFor,
|
|
45
47
|
claimSecondaryRoyalties,
|
|
46
48
|
}: WithdrawRewardsParams) {
|
|
47
|
-
return {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}),
|
|
55
|
-
};
|
|
49
|
+
return await withdrawRewards({
|
|
50
|
+
rewardsGetter: this.rewardsGetter,
|
|
51
|
+
withdrawFor,
|
|
52
|
+
claimSecondaryRoyalties,
|
|
53
|
+
account,
|
|
54
|
+
publicClient: this.publicClient,
|
|
55
|
+
});
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/** Retrieves the rewards balances for a given account */
|
|
59
59
|
async getRewardsBalances(params: GetRewardsBalancesParams) {
|
|
60
|
-
return
|
|
60
|
+
return getRewardsBalances({
|
|
61
61
|
account: params.account,
|
|
62
|
-
chainId: this.chainId,
|
|
63
62
|
publicClient: this.publicClient,
|
|
64
63
|
rewardsGetter: this.rewardsGetter,
|
|
65
64
|
});
|