@zoralabs/protocol-sdk 0.11.12 → 0.12.1
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 +17 -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 +1613 -1483
- 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 +1594 -1483
- 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/preminter.d.ts +5 -5
- package/dist/preminter.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 +2 -2
- 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
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
multicall3Address,
|
|
15
15
|
Multicall3Call3,
|
|
16
16
|
} from "src/apis/multicall3";
|
|
17
|
-
|
|
17
|
+
import { SubgraphRewardsGetter } from "./subgraph-rewards-getter";
|
|
18
|
+
import { SimulateContractParametersWithAccount } from "src/types";
|
|
18
19
|
// Aggregates unclaimed fees and separates ETH from other ERC20 tokens
|
|
19
20
|
function aggregateUnclaimedFees(
|
|
20
21
|
unclaimedFees: readonly {
|
|
@@ -65,25 +66,64 @@ type RewardsBalance = {
|
|
|
65
66
|
};
|
|
66
67
|
};
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
const getErc20zsWithPositions = async ({
|
|
70
|
+
address,
|
|
71
|
+
publicClient,
|
|
72
|
+
rewardsGetter,
|
|
73
|
+
}: {
|
|
74
|
+
address: Address;
|
|
75
|
+
publicClient: PublicClient;
|
|
76
|
+
rewardsGetter?: IRewardsGetter;
|
|
77
|
+
}): Promise<Address[]> => {
|
|
78
|
+
const chainId = publicClient.chain.id;
|
|
79
|
+
const rewardsGetterOrDefault =
|
|
80
|
+
rewardsGetter ?? new SubgraphRewardsGetter(chainId);
|
|
81
|
+
|
|
82
|
+
const erc20zsForCreator = await rewardsGetterOrDefault.getErc20ZzForCreator({
|
|
83
|
+
address,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const royaltiesAddress =
|
|
87
|
+
erc20ZRoyaltiesAddress[chainId as keyof typeof erc20ZRoyaltiesAddress];
|
|
88
|
+
|
|
89
|
+
const positionsByErc20z = await (
|
|
90
|
+
publicClient as PublicClientWithMulticall
|
|
91
|
+
).multicall({
|
|
92
|
+
contracts: erc20zsForCreator.map((erc20z) => ({
|
|
93
|
+
address: royaltiesAddress,
|
|
94
|
+
abi: erc20ZRoyaltiesABI,
|
|
95
|
+
functionName: "positionsByErc20z",
|
|
96
|
+
args: [erc20z],
|
|
97
|
+
})),
|
|
98
|
+
multicallAddress: multicall3Address,
|
|
99
|
+
allowFailure: false,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const erc20zsWithPositions = erc20zsForCreator.filter(
|
|
103
|
+
(_, i) => positionsByErc20z[i] !== 0n,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return erc20zsWithPositions;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const getRewardsBalances = async ({
|
|
69
110
|
account, // The account to check rewards for (Address or Account object)
|
|
70
111
|
publicClient, // The public client for making blockchain queries
|
|
71
|
-
chainId, // The ID of the blockchain network
|
|
72
112
|
rewardsGetter, // Interface for getting ERC20Z tokens for a creator
|
|
73
113
|
}: {
|
|
74
114
|
account: Account | Address;
|
|
75
115
|
publicClient: PublicClient;
|
|
76
|
-
|
|
77
|
-
rewardsGetter: IRewardsGetter;
|
|
116
|
+
rewardsGetter?: IRewardsGetter;
|
|
78
117
|
}): Promise<RewardsBalance> => {
|
|
118
|
+
const chainId = publicClient.chain.id;
|
|
79
119
|
const address = typeof account === "string" ? account : account.address;
|
|
80
|
-
const erc20ZsAndSecondaryActivated = await rewardsGetter.getErc20ZzForCreator(
|
|
81
|
-
{ address },
|
|
82
|
-
);
|
|
83
120
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
121
|
+
// get erc20z that have positions in the royalties contract
|
|
122
|
+
const erc20zsWithPositions = await getErc20zsWithPositions({
|
|
123
|
+
address,
|
|
124
|
+
publicClient,
|
|
125
|
+
rewardsGetter,
|
|
126
|
+
});
|
|
87
127
|
|
|
88
128
|
// Perform multicall to get protocol rewards balance and unclaimed fees
|
|
89
129
|
const result = await (publicClient as PublicClientWithMulticall).multicall({
|
|
@@ -104,7 +144,7 @@ export const getRewardsBalance = async ({
|
|
|
104
144
|
],
|
|
105
145
|
abi: erc20ZRoyaltiesABI,
|
|
106
146
|
functionName: "getUnclaimedFeesBatch",
|
|
107
|
-
args: [
|
|
147
|
+
args: [erc20zsWithPositions],
|
|
108
148
|
},
|
|
109
149
|
],
|
|
110
150
|
multicallAddress: multicall3Address,
|
|
@@ -148,18 +188,18 @@ const makeClaimSecondaryRoyaltiesCalls = async ({
|
|
|
148
188
|
claimFor,
|
|
149
189
|
chainId,
|
|
150
190
|
rewardsGetter,
|
|
191
|
+
publicClient,
|
|
151
192
|
}: {
|
|
152
193
|
claimFor: Address;
|
|
153
194
|
chainId: number;
|
|
154
|
-
rewardsGetter
|
|
195
|
+
rewardsGetter?: IRewardsGetter;
|
|
196
|
+
publicClient: PublicClient;
|
|
155
197
|
}) => {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
.filter(({ secondaryActivated }) => secondaryActivated)
|
|
162
|
-
.map(({ erc20z }) => erc20z);
|
|
198
|
+
const erc20z = await getErc20zsWithPositions({
|
|
199
|
+
address: claimFor,
|
|
200
|
+
publicClient,
|
|
201
|
+
rewardsGetter,
|
|
202
|
+
});
|
|
163
203
|
|
|
164
204
|
const royaltiesAddress =
|
|
165
205
|
erc20ZRoyaltiesAddress[chainId as keyof typeof erc20ZRoyaltiesAddress];
|
|
@@ -183,15 +223,18 @@ export async function withdrawSecondaryRoyalties({
|
|
|
183
223
|
claimFor,
|
|
184
224
|
chainId,
|
|
185
225
|
rewardsGetter,
|
|
226
|
+
publicClient,
|
|
186
227
|
}: {
|
|
187
228
|
claimFor: Address;
|
|
188
229
|
chainId: number;
|
|
189
|
-
rewardsGetter
|
|
230
|
+
rewardsGetter?: IRewardsGetter;
|
|
231
|
+
publicClient: PublicClient;
|
|
190
232
|
}) {
|
|
191
233
|
const calls = await makeClaimSecondaryRoyaltiesCalls({
|
|
192
234
|
claimFor,
|
|
193
235
|
chainId,
|
|
194
236
|
rewardsGetter,
|
|
237
|
+
publicClient,
|
|
195
238
|
});
|
|
196
239
|
|
|
197
240
|
return makeContractParameters({
|
|
@@ -230,34 +273,71 @@ const createMulticallParameters = (
|
|
|
230
273
|
account,
|
|
231
274
|
});
|
|
232
275
|
|
|
233
|
-
//
|
|
234
|
-
|
|
276
|
+
// Handle the simple case of protocol rewards only
|
|
277
|
+
const handleProtocolRewardsOnly = ({
|
|
278
|
+
chainId,
|
|
279
|
+
withdrawFor,
|
|
280
|
+
account,
|
|
281
|
+
}: {
|
|
282
|
+
chainId: number;
|
|
283
|
+
withdrawFor: Address;
|
|
284
|
+
account: Address | Account;
|
|
285
|
+
}) => ({
|
|
286
|
+
...withdrawProtocolRewards({ chainId, withdrawFor }),
|
|
235
287
|
account,
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Handle both protocol and secondary rewards
|
|
291
|
+
const handleAllRewards = async ({
|
|
236
292
|
withdrawFor,
|
|
237
|
-
|
|
238
|
-
chainId,
|
|
293
|
+
account,
|
|
239
294
|
rewardsGetter,
|
|
295
|
+
publicClient,
|
|
240
296
|
}: {
|
|
241
|
-
account: Address | Account;
|
|
242
297
|
withdrawFor: Address;
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
298
|
+
account: Address | Account;
|
|
299
|
+
rewardsGetter?: IRewardsGetter;
|
|
300
|
+
publicClient: PublicClient;
|
|
246
301
|
}) => {
|
|
247
|
-
|
|
248
|
-
return {
|
|
249
|
-
...withdrawProtocolRewards({ chainId, withdrawFor }),
|
|
250
|
-
account,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
302
|
+
const chainId = publicClient.chain.id;
|
|
254
303
|
const protocolRewardsCall = createProtocolRewardsCall(chainId, withdrawFor);
|
|
255
304
|
const secondaryRoyaltiesCalls = await makeClaimSecondaryRoyaltiesCalls({
|
|
256
305
|
chainId,
|
|
257
306
|
claimFor: withdrawFor,
|
|
258
307
|
rewardsGetter,
|
|
308
|
+
publicClient,
|
|
259
309
|
});
|
|
260
310
|
|
|
261
311
|
const allCalls = [protocolRewardsCall, ...secondaryRoyaltiesCalls];
|
|
262
312
|
return createMulticallParameters(allCalls, account);
|
|
263
313
|
};
|
|
314
|
+
|
|
315
|
+
// Main withdrawRewards function now acts as a router
|
|
316
|
+
export const withdrawRewards = async ({
|
|
317
|
+
account,
|
|
318
|
+
withdrawFor,
|
|
319
|
+
claimSecondaryRoyalties = true,
|
|
320
|
+
rewardsGetter,
|
|
321
|
+
publicClient,
|
|
322
|
+
}: {
|
|
323
|
+
account: Address | Account;
|
|
324
|
+
withdrawFor: Address;
|
|
325
|
+
claimSecondaryRoyalties?: boolean;
|
|
326
|
+
rewardsGetter?: IRewardsGetter;
|
|
327
|
+
publicClient: PublicClient;
|
|
328
|
+
}): Promise<{ parameters: SimulateContractParametersWithAccount }> => {
|
|
329
|
+
const parameters = claimSecondaryRoyalties
|
|
330
|
+
? await handleAllRewards({
|
|
331
|
+
withdrawFor,
|
|
332
|
+
account,
|
|
333
|
+
rewardsGetter,
|
|
334
|
+
publicClient,
|
|
335
|
+
})
|
|
336
|
+
: await handleProtocolRewardsOnly({
|
|
337
|
+
chainId: publicClient.chain.id,
|
|
338
|
+
withdrawFor,
|
|
339
|
+
account,
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
return { parameters };
|
|
343
|
+
};
|
|
@@ -5,7 +5,6 @@ export type RewardsToken = {
|
|
|
5
5
|
salesStrategies: [
|
|
6
6
|
{
|
|
7
7
|
zoraTimedMinter?: {
|
|
8
|
-
secondaryActivated: boolean;
|
|
9
8
|
erc20Z: {
|
|
10
9
|
id: Address;
|
|
11
10
|
};
|
|
@@ -34,7 +33,6 @@ export function buildCreatorERC20zs({
|
|
|
34
33
|
}
|
|
35
34
|
salesStrategies {
|
|
36
35
|
zoraTimedMinter {
|
|
37
|
-
secondaryActivated
|
|
38
36
|
erc20Z {
|
|
39
37
|
id
|
|
40
38
|
}
|
|
@@ -4,9 +4,7 @@ import { Address } from "viem";
|
|
|
4
4
|
import { buildCreatorERC20zs } from "./subgraph-queries";
|
|
5
5
|
|
|
6
6
|
export interface IRewardsGetter {
|
|
7
|
-
getErc20ZzForCreator: (params: {
|
|
8
|
-
address: Address;
|
|
9
|
-
}) => Promise<{ secondaryActivated: boolean; erc20z: Address }[]>;
|
|
7
|
+
getErc20ZzForCreator: (params: { address: Address }) => Promise<Address[]>;
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
export class SubgraphRewardsGetter
|
|
@@ -30,17 +28,9 @@ export class SubgraphRewardsGetter
|
|
|
30
28
|
return null;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
return
|
|
34
|
-
secondaryActivated: timedMinter.secondaryActivated,
|
|
35
|
-
erc20z: timedMinter.erc20Z.id,
|
|
36
|
-
};
|
|
31
|
+
return timedMinter.erc20Z.id;
|
|
37
32
|
}) || []
|
|
38
|
-
).filter(
|
|
39
|
-
(
|
|
40
|
-
idAndActivated,
|
|
41
|
-
): idAndActivated is { secondaryActivated: boolean; erc20z: Address } =>
|
|
42
|
-
!!idAndActivated,
|
|
43
|
-
);
|
|
33
|
+
).filter((id): id is Address => !!id);
|
|
44
34
|
|
|
45
35
|
return results;
|
|
46
36
|
}
|
package/src/sdk.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
PremintClient,
|
|
3
3
|
getDataFromPremintReceipt,
|
|
4
4
|
} from "./premint/premint-client";
|
|
5
|
-
import { Create1155Client } from "./create/
|
|
5
|
+
import { Create1155Client } from "./create/create-client";
|
|
6
6
|
import { MintClient } from "./mint/mint-client";
|
|
7
7
|
import { ClientConfig } from "./utils";
|
|
8
8
|
import { IPremintAPI, PremintAPIClient } from "./premint/premint-api-client";
|
|
@@ -49,7 +49,10 @@ export type CreatorClientConfig = ClientConfig & {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* @deprecated Please use functions directly without creating a client.
|
|
53
|
+
* Example: Instead of `createCreatorClient().create1155()`, use `create1155()`
|
|
54
|
+
* Import the functions you need directly from their respective modules:
|
|
55
|
+
* import { create1155 } from '@zoralabs/protocol-sdk'
|
|
53
56
|
*
|
|
54
57
|
* @param clientConfig - Configuration for the client {@link CreatorClientConfig}
|
|
55
58
|
* @returns CreatorClient {@link CreatorClient}
|
|
@@ -65,7 +68,6 @@ export function createCreatorClient(
|
|
|
65
68
|
});
|
|
66
69
|
|
|
67
70
|
const create1155CreatorClient = new Create1155Client({
|
|
68
|
-
chainId: clientConfig.chainId,
|
|
69
71
|
publicClient: clientConfig.publicClient,
|
|
70
72
|
contractGetter:
|
|
71
73
|
clientConfig.contractGetter ||
|
|
@@ -73,7 +75,6 @@ export function createCreatorClient(
|
|
|
73
75
|
});
|
|
74
76
|
|
|
75
77
|
const rewardsClient = new RewardsClient({
|
|
76
|
-
chainId: clientConfig.chainId,
|
|
77
78
|
publicClient: clientConfig.publicClient,
|
|
78
79
|
rewardsGetter:
|
|
79
80
|
clientConfig.rewardsGetter ||
|
|
@@ -100,7 +101,10 @@ export type CollectorClientConfig = ClientConfig & {
|
|
|
100
101
|
};
|
|
101
102
|
|
|
102
103
|
/**
|
|
103
|
-
*
|
|
104
|
+
* @deprecated Please use functions directly without creating a client.
|
|
105
|
+
* Example: Instead of `createCollectorClient().mint()`, use `mint()`
|
|
106
|
+
* Import the functions you need directly from their respective modules:
|
|
107
|
+
* import { mint } from '@zoralabs/protocol-sdk'
|
|
104
108
|
*
|
|
105
109
|
* @param clientConfig - Configuration for the client {@link CollectorClientConfig}
|
|
106
110
|
* @returns CollectorClient {@link CollectorClient}
|
|
@@ -116,11 +120,9 @@ export function createCollectorClient(
|
|
|
116
120
|
publicClient: params.publicClient,
|
|
117
121
|
premintGetter: premintGetterToUse,
|
|
118
122
|
mintGetter: mintGetterToUse,
|
|
119
|
-
chainId: params.chainId,
|
|
120
123
|
});
|
|
121
124
|
const secondaryClient = new SecondaryClient({
|
|
122
125
|
publicClient: params.publicClient,
|
|
123
|
-
chainId: params.chainId,
|
|
124
126
|
});
|
|
125
127
|
|
|
126
128
|
return {
|
|
@@ -3,7 +3,6 @@ import { parseEther, Address, parseEventLogs } from "viem";
|
|
|
3
3
|
import { zoraSepolia } from "viem/chains";
|
|
4
4
|
import { forkUrls, makeAnvilTest } from "src/anvil";
|
|
5
5
|
import { simulateAndWriteContractWithRetries } from "src/test-utils";
|
|
6
|
-
import { createCollectorClient } from "src/sdk";
|
|
7
6
|
import {
|
|
8
7
|
zoraCreator1155ImplABI,
|
|
9
8
|
commentsABI,
|
|
@@ -14,12 +13,18 @@ import {
|
|
|
14
13
|
sparkValue,
|
|
15
14
|
} from "@zoralabs/protocol-deployments";
|
|
16
15
|
import { SubgraphMintGetter } from "src/mint/subgraph-mint-getter";
|
|
17
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
buy1155OnSecondary,
|
|
18
|
+
ERROR_SECONDARY_NOT_STARTED,
|
|
19
|
+
sell1155OnSecondary,
|
|
20
|
+
} from "./secondary-client";
|
|
18
21
|
import { ISubgraphQuerier } from "src/apis/subgraph-querier";
|
|
19
22
|
import { mockTimedSaleStrategyTokenQueryResult } from "src/fixtures/mint-query-results";
|
|
20
23
|
import { new1155ContractVersion } from "src/create/contract-setup";
|
|
21
24
|
import { advanceToSaleAndAndLaunchMarket } from "src/fixtures/secondary";
|
|
22
25
|
import { randomNonce } from "src/test-utils";
|
|
26
|
+
import { getSecondaryInfo } from "./utils";
|
|
27
|
+
import { mint } from "src/mint/mint-client";
|
|
23
28
|
|
|
24
29
|
describe("secondary", () => {
|
|
25
30
|
makeAnvilTest({
|
|
@@ -28,9 +33,7 @@ describe("secondary", () => {
|
|
|
28
33
|
anvilChainId: zoraSepolia.id,
|
|
29
34
|
})(
|
|
30
35
|
"it returns an error when the market is not launched",
|
|
31
|
-
async ({
|
|
32
|
-
viemClients: { publicClient, chain, walletClient, testClient },
|
|
33
|
-
}) => {
|
|
36
|
+
async ({ viemClients: { publicClient, walletClient, testClient } }) => {
|
|
34
37
|
const collectorAccount = (await walletClient.getAddresses()!)[1]!;
|
|
35
38
|
|
|
36
39
|
const contractAddress: Address =
|
|
@@ -41,14 +44,10 @@ describe("secondary", () => {
|
|
|
41
44
|
value: parseEther("100"),
|
|
42
45
|
});
|
|
43
46
|
|
|
44
|
-
const
|
|
45
|
-
chainId: chain.id,
|
|
46
|
-
publicClient,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const secondaryInfo = await collectorClient.getSecondaryInfo({
|
|
47
|
+
const secondaryInfo = await getSecondaryInfo({
|
|
50
48
|
contract: contractAddress,
|
|
51
49
|
tokenId: newTokenId,
|
|
50
|
+
publicClient,
|
|
52
51
|
});
|
|
53
52
|
|
|
54
53
|
expect(secondaryInfo).toBeDefined();
|
|
@@ -56,11 +55,12 @@ describe("secondary", () => {
|
|
|
56
55
|
expect(secondaryInfo!.minimumMintsForCountdown).toBe(1111n);
|
|
57
56
|
expect(secondaryInfo!.secondaryActivated).toBe(false);
|
|
58
57
|
|
|
59
|
-
const buyResult = await
|
|
58
|
+
const buyResult = await buy1155OnSecondary({
|
|
60
59
|
account: collectorAccount,
|
|
61
60
|
quantity: 100n,
|
|
62
61
|
contract: contractAddress,
|
|
63
62
|
tokenId: newTokenId,
|
|
63
|
+
publicClient,
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
expect(buyResult.error).toEqual(ERROR_SECONDARY_NOT_STARTED);
|
|
@@ -103,15 +103,10 @@ describe("secondary", () => {
|
|
|
103
103
|
}),
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
const
|
|
107
|
-
chainId: chain.id,
|
|
108
|
-
publicClient,
|
|
109
|
-
mintGetter,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const secondaryInfo = await collectorClient.getSecondaryInfo({
|
|
106
|
+
const secondaryInfo = await getSecondaryInfo({
|
|
113
107
|
contract: contractAddress,
|
|
114
108
|
tokenId: newTokenId,
|
|
109
|
+
publicClient,
|
|
115
110
|
});
|
|
116
111
|
|
|
117
112
|
expect(secondaryInfo).toBeDefined();
|
|
@@ -124,12 +119,14 @@ describe("secondary", () => {
|
|
|
124
119
|
secondaryInfo!.mintCount -
|
|
125
120
|
1n;
|
|
126
121
|
|
|
127
|
-
const { parameters: collectParameters } = await
|
|
122
|
+
const { parameters: collectParameters } = await mint({
|
|
128
123
|
minterAccount: collectorAccount,
|
|
129
124
|
mintType: "1155",
|
|
130
125
|
quantityToMint: quantityToMintFirst,
|
|
131
126
|
tokenId: newTokenId,
|
|
132
127
|
tokenContract: contractAddress,
|
|
128
|
+
publicClient,
|
|
129
|
+
mintGetter,
|
|
133
130
|
});
|
|
134
131
|
|
|
135
132
|
await simulateAndWriteContractWithRetries({
|
|
@@ -139,20 +136,23 @@ describe("secondary", () => {
|
|
|
139
136
|
});
|
|
140
137
|
|
|
141
138
|
// make sure that there is no sale end
|
|
142
|
-
let saleEnd = (await
|
|
139
|
+
let saleEnd = (await getSecondaryInfo({
|
|
143
140
|
contract: contractAddress,
|
|
144
141
|
tokenId: newTokenId,
|
|
142
|
+
publicClient,
|
|
145
143
|
}))!.saleEnd;
|
|
146
144
|
|
|
147
145
|
expect(saleEnd).toBeUndefined();
|
|
148
146
|
|
|
149
147
|
// mint 1 more - this should cause the countdown to start
|
|
150
|
-
const { parameters: collectMoreParameters } = await
|
|
148
|
+
const { parameters: collectMoreParameters } = await mint({
|
|
151
149
|
minterAccount: collectorAccount,
|
|
152
150
|
mintType: "1155",
|
|
153
151
|
quantityToMint: 1n,
|
|
154
152
|
tokenId: newTokenId,
|
|
155
153
|
tokenContract: contractAddress,
|
|
154
|
+
publicClient,
|
|
155
|
+
mintGetter,
|
|
156
156
|
});
|
|
157
157
|
|
|
158
158
|
await simulateAndWriteContractWithRetries({
|
|
@@ -162,9 +162,10 @@ describe("secondary", () => {
|
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
// now there should be a sale end
|
|
165
|
-
saleEnd = (await
|
|
165
|
+
saleEnd = (await getSecondaryInfo({
|
|
166
166
|
contract: contractAddress,
|
|
167
167
|
tokenId: newTokenId,
|
|
168
|
+
publicClient,
|
|
168
169
|
}))!.saleEnd;
|
|
169
170
|
|
|
170
171
|
expect(saleEnd).toBeDefined();
|
|
@@ -175,8 +176,6 @@ describe("secondary", () => {
|
|
|
175
176
|
testClient,
|
|
176
177
|
publicClient,
|
|
177
178
|
walletClient,
|
|
178
|
-
collectorClient,
|
|
179
|
-
chainId: chain.id,
|
|
180
179
|
account: collectorAccount,
|
|
181
180
|
});
|
|
182
181
|
|
|
@@ -190,11 +189,12 @@ describe("secondary", () => {
|
|
|
190
189
|
// now get the price ot buy on secondary
|
|
191
190
|
const quantityToBuy = 10n;
|
|
192
191
|
|
|
193
|
-
const buyResult = await
|
|
192
|
+
const buyResult = await buy1155OnSecondary({
|
|
194
193
|
account: collectorAccount,
|
|
195
194
|
quantity: quantityToBuy,
|
|
196
195
|
contract: contractAddress,
|
|
197
196
|
tokenId: newTokenId,
|
|
197
|
+
publicClient,
|
|
198
198
|
});
|
|
199
199
|
|
|
200
200
|
expect(buyResult.error).toBeUndefined();
|
|
@@ -229,11 +229,12 @@ describe("secondary", () => {
|
|
|
229
229
|
// now sell 10_000n tokens
|
|
230
230
|
const quantityToSell = 100n;
|
|
231
231
|
|
|
232
|
-
const sellResult = await
|
|
232
|
+
const sellResult = await sell1155OnSecondary({
|
|
233
233
|
account: collectorAccount,
|
|
234
234
|
quantity: quantityToSell,
|
|
235
235
|
contract: contractAddress,
|
|
236
236
|
tokenId: newTokenId,
|
|
237
|
+
publicClient,
|
|
237
238
|
});
|
|
238
239
|
|
|
239
240
|
expect(sellResult.error).toBeUndefined();
|
|
@@ -300,27 +301,24 @@ describe("secondary", () => {
|
|
|
300
301
|
}),
|
|
301
302
|
});
|
|
302
303
|
|
|
303
|
-
const
|
|
304
|
-
chainId: chain.id,
|
|
305
|
-
publicClient,
|
|
306
|
-
mintGetter,
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
const secondaryInfo = await collectorClient.getSecondaryInfo({
|
|
304
|
+
const secondaryInfo = await getSecondaryInfo({
|
|
310
305
|
contract: contractAddress,
|
|
311
306
|
tokenId: newTokenId,
|
|
307
|
+
publicClient,
|
|
312
308
|
});
|
|
313
309
|
|
|
314
310
|
// mint enough to start the countdown
|
|
315
311
|
const quantityToMint =
|
|
316
312
|
secondaryInfo!.minimumMintsForCountdown! - secondaryInfo!.mintCount;
|
|
317
313
|
|
|
318
|
-
const { parameters: collectParameters } = await
|
|
314
|
+
const { parameters: collectParameters } = await mint({
|
|
319
315
|
minterAccount: collectorAccount,
|
|
320
316
|
mintType: "1155",
|
|
321
317
|
quantityToMint: quantityToMint,
|
|
322
318
|
tokenId: newTokenId,
|
|
323
319
|
tokenContract: contractAddress,
|
|
320
|
+
publicClient,
|
|
321
|
+
mintGetter,
|
|
324
322
|
});
|
|
325
323
|
|
|
326
324
|
await simulateAndWriteContractWithRetries({
|
|
@@ -335,17 +333,16 @@ describe("secondary", () => {
|
|
|
335
333
|
testClient,
|
|
336
334
|
publicClient,
|
|
337
335
|
walletClient,
|
|
338
|
-
collectorClient,
|
|
339
|
-
chainId: chain.id,
|
|
340
336
|
account: collectorAccount,
|
|
341
337
|
});
|
|
342
338
|
|
|
343
|
-
const buyResult = await
|
|
339
|
+
const buyResult = await buy1155OnSecondary({
|
|
344
340
|
account: collectorAccount,
|
|
345
341
|
quantity: 5n,
|
|
346
342
|
contract: contractAddress,
|
|
347
343
|
tokenId: newTokenId,
|
|
348
344
|
comment: "test comment",
|
|
345
|
+
publicClient,
|
|
349
346
|
});
|
|
350
347
|
|
|
351
348
|
const receipt = await simulateAndWriteContractWithRetries({
|
|
@@ -375,12 +372,13 @@ describe("secondary", () => {
|
|
|
375
372
|
expect(boughtAndCommentedEvent[0]!.args.swapDirection).toBe(0);
|
|
376
373
|
|
|
377
374
|
// PERMIT BUY TEST
|
|
378
|
-
const buyResultASecondTime = await
|
|
375
|
+
const buyResultASecondTime = await buy1155OnSecondary({
|
|
379
376
|
account: collectorAccount,
|
|
380
377
|
quantity: 5n,
|
|
381
378
|
contract: contractAddress,
|
|
382
379
|
tokenId: newTokenId,
|
|
383
380
|
comment: "test comment",
|
|
381
|
+
publicClient,
|
|
384
382
|
});
|
|
385
383
|
|
|
386
384
|
const valueToSend = (buyResultASecondTime.price!.wei.total * 105n) / 100n;
|
|
@@ -431,11 +429,12 @@ describe("secondary", () => {
|
|
|
431
429
|
// now PERMIT SELL ON SECONDARY TEST
|
|
432
430
|
const quantityToSell = 3n;
|
|
433
431
|
|
|
434
|
-
const sellResult = await
|
|
432
|
+
const sellResult = await sell1155OnSecondary({
|
|
435
433
|
account: collectorAccount,
|
|
436
434
|
quantity: quantityToSell,
|
|
437
435
|
contract: contractAddress,
|
|
438
436
|
tokenId: newTokenId,
|
|
437
|
+
publicClient,
|
|
439
438
|
});
|
|
440
439
|
|
|
441
440
|
expect(sellResult.error).toBeUndefined();
|