@artblocks/contracts 1.4.0 → 1.6.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/README.md +1 -1
- package/artifacts/contracts/interfaces/v0.8.x/IFormPaletteBindingHooks.sol/IFormPaletteBindingHooks.json +723 -0
- package/artifacts/contracts/interfaces/v0.8.x/IMintTimeAndTransferCountHooks.sol/IMintTimeAndTransferCountHooks.json +356 -0
- package/artifacts/contracts/interfaces/v0.8.x/IPMPProjectViewsV0.sol/IPMPProjectViewsV0.json +126 -0
- package/artifacts/contracts/interfaces/v0.8.x/ISharedMinterRequiredPMPV0.sol/ISharedMinterRequiredPMPV0.json +36 -0
- package/artifacts/contracts/libs/v0.8.x/minter-libs/RequiredPMPLib.sol/RequiredPMPLib.json +10 -0
- package/artifacts/contracts/minter-suite/Minters/MinterSetPricePMPV0.sol/MinterSetPricePMPV0.json +613 -0
- package/artifacts/contracts/mock/MockPMPMinterReentrantConfigureHook.sol/IMinterPMPPurchase.json +91 -0
- package/artifacts/contracts/mock/MockPMPMinterReentrantConfigureHook.sol/MockPMPMinterReentrantConfigureHook.json +180 -0
- package/artifacts/contracts/mock/MockPMPReentrantConfigureHook.sol/MockPMPReentrantConfigureHook.json +158 -0
- package/artifacts/contracts/mock/ReentrancyPMPMockShared.sol/IMinterPurchaseWithPMPs.json +67 -0
- package/artifacts/contracts/mock/ReentrancyPMPMockShared.sol/ReentrancyPMPMockShared.json +154 -0
- package/artifacts/contracts/web3call/combined-hooks/FormPaletteBindingHooks.sol/FormPaletteBindingHooks.json +919 -0
- package/artifacts/contracts/web3call/combined-hooks/MintTimeAndTransferCountHooks.sol/MintTimeAndTransferCountHooks.json +435 -0
- package/contracts/interfaces/v0.8.x/IFormPaletteBindingHooks.sol +339 -0
- package/contracts/interfaces/v0.8.x/IMintTimeAndTransferCountHooks.sol +125 -0
- package/contracts/interfaces/v0.8.x/IPMPProjectViewsV0.sol +59 -0
- package/contracts/interfaces/v0.8.x/ISharedMinterRequiredPMPV0.sol +27 -0
- package/contracts/libs/v0.8.x/minter-libs/RequiredPMPLib.sol +336 -0
- package/contracts/minter-suite/Minters/MinterSetPricePMPV0.sol +664 -0
- package/contracts/mock/MockPMPMinterReentrantConfigureHook.sol +85 -0
- package/contracts/mock/MockPMPReentrantConfigureHook.sol +59 -0
- package/contracts/mock/ReentrancyPMPMockShared.sol +81 -0
- package/contracts/web3call/combined-hooks/FormPaletteBindingHooks.sol +1392 -0
- package/contracts/web3call/combined-hooks/MintTimeAndTransferCountHooks.sol +483 -0
- package/package.json +2 -1
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-only
|
|
2
|
+
// Created By: Art Blocks Inc.
|
|
3
|
+
|
|
4
|
+
// @dev fixed to specific solidity version for clarity and for more clear
|
|
5
|
+
// source code verification purposes.
|
|
6
|
+
pragma solidity 0.8.22;
|
|
7
|
+
|
|
8
|
+
import {AbstractTransferHook} from "../../engine/V3/transfer-hooks/AbstractTransferHook.sol";
|
|
9
|
+
import {AbstractPMPAugmentHook} from "../augment-hooks/AbstractPMPAugmentHook.sol";
|
|
10
|
+
|
|
11
|
+
import {IMintTimeAndTransferCountHooks} from "../../interfaces/v0.8.x/IMintTimeAndTransferCountHooks.sol";
|
|
12
|
+
import {ITransferHook} from "../../interfaces/v0.8.x/ITransferHook.sol";
|
|
13
|
+
import {IPMPAugmentHook} from "../../interfaces/v0.8.x/IPMPAugmentHook.sol";
|
|
14
|
+
import {IPMPV0} from "../../interfaces/v0.8.x/IPMPV0.sol";
|
|
15
|
+
import {IGenArt721CoreContractV3_Engine} from "../../interfaces/v0.8.x/IGenArt721CoreContractV3_Engine.sol";
|
|
16
|
+
import {IWeb3Call} from "../../interfaces/v0.8.x/IWeb3Call.sol";
|
|
17
|
+
|
|
18
|
+
import {ABHelpers} from "../../libs/v0.8.x/ABHelpers.sol";
|
|
19
|
+
|
|
20
|
+
import {Strings} from "@openzeppelin-5.0/contracts/utils/Strings.sol";
|
|
21
|
+
import {IERC165} from "@openzeppelin-5.0/contracts/interfaces/IERC165.sol";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @title Mint-time and transfer-count combined hook
|
|
25
|
+
* @author Art Blocks Inc.
|
|
26
|
+
* @notice Reference combined hook. Records each token's mint timestamp and
|
|
27
|
+
* subsequent transfer count on chain, and injects those values — plus live
|
|
28
|
+
* seconds since mint — into the token's PostParams when they are read.
|
|
29
|
+
* Optionally writes `transferCount` as a real PMP so transfers emit
|
|
30
|
+
* `TokenParamsConfigured` and can trigger off-chain re-renders.
|
|
31
|
+
* ----------------------------------------------------------------------------
|
|
32
|
+
* A single deployment serves every project on the bound PMP, on every v3.3+
|
|
33
|
+
* Engine core on the network, that configures this address as its transfer
|
|
34
|
+
* hook. There is no owner and no allowlist. Constructor takes the PMP
|
|
35
|
+
* contract this hook is authorized to write to (`address(0)` to skip PMP
|
|
36
|
+
* writes). An artist points their project at this address as follows:
|
|
37
|
+
*
|
|
38
|
+
* 1. Core transfer hook, via `configureProjectTransferHook` on a v3.3+ Engine
|
|
39
|
+
* or Engine Flex core. This is what records mint time (`from == address(0)`)
|
|
40
|
+
* and increments transfer count. May be made permanent with
|
|
41
|
+
* `lockProjectTransferHook`.
|
|
42
|
+
* 2. PMP project param (optional, required for a populated `transferCount`
|
|
43
|
+
* PMP from mint and for transfer-triggered re-renders), via
|
|
44
|
+
* `configureProject` on the bound PMP. Configure a param with:
|
|
45
|
+
* - key: `transferCount`
|
|
46
|
+
* - `authOption`: `Address`
|
|
47
|
+
* - `authAddress`: this hook
|
|
48
|
+
* - `paramType`: `Uint256Range`
|
|
49
|
+
* - `minRange`: 0
|
|
50
|
+
* - `maxRange`: `type(uint256).max` (do not set a small max — a transfer
|
|
51
|
+
* that would exceed it will skip the PMP write rather than revert)
|
|
52
|
+
* - `pmpLockedAfterTimestamp`: 0 (do not lock this param). On PMPV1 a
|
|
53
|
+
* passed lock timestamp also freezes token values and later writes are
|
|
54
|
+
* skipped; PMPV0 only locks further project-config changes.
|
|
55
|
+
* Do **not** set this contract as `tokenPMPPostConfigHook`. An existing
|
|
56
|
+
* post-config hook on the project still runs on every `transferCount`
|
|
57
|
+
* write; if it reverts, the PMP write is skipped and the mint or transfer
|
|
58
|
+
* still succeeds.
|
|
59
|
+
* 3. PMP read-augmentation hook, via `configureProjectHooks` on the same PMP,
|
|
60
|
+
* passing this address as `tokenPMPReadAugmentationHook`. This injects
|
|
61
|
+
* `mintTimestamp`, live `secondsSinceMint`, and `transferCount` on read.
|
|
62
|
+
*
|
|
63
|
+
* Transfer-hook-only still records state, which other contracts (including an
|
|
64
|
+
* artwork script through the on-chain generator) can read via the view
|
|
65
|
+
* functions. Augment-hook-only injects zeros, because nothing was recorded.
|
|
66
|
+
* PMP Address-auth without the transfer hook never writes, because only this
|
|
67
|
+
* contract is authorized.
|
|
68
|
+
* ----------------------------------------------------------------------------
|
|
69
|
+
* POSTPARAMS. On each read this hook copies the input params, drops any
|
|
70
|
+
* existing entries whose keys collide with the keys below (this hook is the
|
|
71
|
+
* source of truth for them), and appends:
|
|
72
|
+
*
|
|
73
|
+
* - `mintTimestamp`: unix seconds of the mint block, as a decimal string.
|
|
74
|
+
* `"0"` if this hook did not observe the mint.
|
|
75
|
+
* - `secondsSinceMint`: `block.timestamp - mintTimestamp` at the time of the
|
|
76
|
+
* read, as a decimal string. `"0"` if the mint was not observed.
|
|
77
|
+
* - `transferCount`: ownership-changing transfers after mint, as a decimal
|
|
78
|
+
* string. Does not include the mint itself. `"0"` until a post-mint transfer
|
|
79
|
+
* is recorded.
|
|
80
|
+
*
|
|
81
|
+
* `secondsSinceMint` is computed at read time, so two reads of the same token
|
|
82
|
+
* in different blocks return different values. It is not stored as a PMP.
|
|
83
|
+
*
|
|
84
|
+
* `transferCount` is additionally written to the bound PMP at mint (`0`) and
|
|
85
|
+
* on each counted transfer when the project has configured that key with
|
|
86
|
+
* Address auth as described above. That write emits `TokenParamsConfigured`
|
|
87
|
+
* from the PMP contract, so the param is populated from the first render and
|
|
88
|
+
* later transfers can trigger off-chain re-renders. Do not also configure
|
|
89
|
+
* `mintTimestamp` or `secondsSinceMint` as project PMPs — they are
|
|
90
|
+
* inject-only.
|
|
91
|
+
* ----------------------------------------------------------------------------
|
|
92
|
+
* COMPLETENESS. Mint timestamp is only recorded if this hook was the project's
|
|
93
|
+
* transfer hook at mint. A hook configured mid-life starts counting transfers
|
|
94
|
+
* from the first ownership change it sees; `isTrackedFromMint` is false and
|
|
95
|
+
* `mintTimestamp` / `secondsSinceMint` stay `0`. Historical transfers from
|
|
96
|
+
* before configuration are not backfilled. If the project's transfer hook is
|
|
97
|
+
* later cleared, recording stops — values already written stay readable and
|
|
98
|
+
* the augment hook will keep injecting them.
|
|
99
|
+
* ----------------------------------------------------------------------------
|
|
100
|
+
* TRANSFER COUNT. Incremented for each ownership-changing transfer after mint.
|
|
101
|
+
* Not incremented for:
|
|
102
|
+
* - the mint itself (`from == address(0)`)
|
|
103
|
+
* - ERC-721 self-transfers (`from == to`), which do not change ownership
|
|
104
|
+
*
|
|
105
|
+
* Cores do not currently burn; a burn (`to == address(0)`) would count.
|
|
106
|
+
* ----------------------------------------------------------------------------
|
|
107
|
+
* GAS. State is one packed storage slot per token (`uint64` mint timestamp +
|
|
108
|
+
* `uint64` transfer count). Both sets of figures below are deltas against an
|
|
109
|
+
* otherwise identical project with no hook, on the same `GenArt721CoreV3_Engine`
|
|
110
|
+
* core, so they may be compared directly. Without a PMP write:
|
|
111
|
+
*
|
|
112
|
+
* - a mint costs about 40,500 gas more. Most of it is the new storage slot
|
|
113
|
+
* plus the core's reentrancy flag, which any hook pays.
|
|
114
|
+
* - a transfer costs about 28,100 gas more — an SSTORE update of the packed
|
|
115
|
+
* count, plus the same reentrancy flag.
|
|
116
|
+
*
|
|
117
|
+
* A successful PMP `configureTokenParams` write on mint or transfer is extra
|
|
118
|
+
* on top of that. With Address-auth `transferCount` writes enabled:
|
|
119
|
+
*
|
|
120
|
+
* - a mint costs about 92,700 gas more (about 52,200 for the PMP write)
|
|
121
|
+
* - a transfer costs about 78,300 gas more (about 50,200 for the PMP write)
|
|
122
|
+
*
|
|
123
|
+
* See the gas tests in `mint-time-and-transfer-count-hooks.test.ts` for the
|
|
124
|
+
* bounds that keep these figures honest.
|
|
125
|
+
* ----------------------------------------------------------------------------
|
|
126
|
+
* SAFETY. A reverting hook aborts the transfer that invoked it, so a hook that
|
|
127
|
+
* can revert can make a token permanently non-transferable. Local recording
|
|
128
|
+
* cannot revert on a transfer of a project that has this hook configured: the
|
|
129
|
+
* only revert path is the configuration check below, which is true by
|
|
130
|
+
* construction whenever the core actually dispatches to this address.
|
|
131
|
+
* The PMP write is `try`/`catch`'d — a missing, locked, or out-of-range
|
|
132
|
+
* `transferCount` param emits `TransferCountPMPSyncFailed` and does **not**
|
|
133
|
+
* revert the transfer. The augment path is `view` and returns zeros rather
|
|
134
|
+
* than reverting when a token has not been recorded.
|
|
135
|
+
*/
|
|
136
|
+
contract MintTimeAndTransferCountHooks is
|
|
137
|
+
AbstractTransferHook,
|
|
138
|
+
AbstractPMPAugmentHook,
|
|
139
|
+
IMintTimeAndTransferCountHooks
|
|
140
|
+
{
|
|
141
|
+
using Strings for uint256;
|
|
142
|
+
|
|
143
|
+
/// @notice PostParam key for the unix seconds of the mint block.
|
|
144
|
+
string public constant PARAM_KEY_MINT_TIMESTAMP = "mintTimestamp";
|
|
145
|
+
/// @notice PostParam key for live seconds since the recorded mint.
|
|
146
|
+
string public constant PARAM_KEY_SECONDS_SINCE_MINT = "secondsSinceMint";
|
|
147
|
+
/// @notice PostParam key for post-mint ownership-changing transfer count.
|
|
148
|
+
string public constant PARAM_KEY_TRANSFER_COUNT = "transferCount";
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @notice PMP contract this hook writes `transferCount` to.
|
|
152
|
+
* @dev `address(0)` skips PMP writes. One deployment per PMP instance.
|
|
153
|
+
*/
|
|
154
|
+
IPMPV0 public immutable pmp;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param pmp_ PMP contract this hook is authorized to write `transferCount`
|
|
158
|
+
* on. Pass `address(0)` to disable PMP writes (transfer-hook-only).
|
|
159
|
+
*/
|
|
160
|
+
constructor(address pmp_) {
|
|
161
|
+
pmp = IPMPV0(pmp_);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @notice Per-token state, keyed by core contract.
|
|
166
|
+
* @dev Keying by `coreContract` is what makes a single shared deployment
|
|
167
|
+
* safe: `AbstractTransferHook` guarantees `coreContract == msg.sender`, so
|
|
168
|
+
* a contract impersonating a core can only ever write beneath its own
|
|
169
|
+
* address, where nothing reads. The configuration check in
|
|
170
|
+
* `_onTokenTransfer` is a second, independent guard.
|
|
171
|
+
*/
|
|
172
|
+
mapping(address coreContract => mapping(uint256 tokenId => TokenTransferState))
|
|
173
|
+
private _state;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @notice Record a mint timestamp or increment transfer count.
|
|
177
|
+
* @dev Called by the core after the ERC-721 ownership write, and on mint
|
|
178
|
+
* after the token hash seed is assigned.
|
|
179
|
+
* @param coreContract Core that performed the ownership update. Guaranteed
|
|
180
|
+
* by `AbstractTransferHook` to equal `msg.sender`.
|
|
181
|
+
* @param tokenId Token whose ownership changed.
|
|
182
|
+
* @param from Previous owner; `address(0)` on mint.
|
|
183
|
+
* @param to New owner.
|
|
184
|
+
*/
|
|
185
|
+
function _onTokenTransfer(
|
|
186
|
+
address coreContract,
|
|
187
|
+
uint256 tokenId,
|
|
188
|
+
address from,
|
|
189
|
+
address to,
|
|
190
|
+
address /* operator */
|
|
191
|
+
) internal override {
|
|
192
|
+
_onlyConfiguredForProject({
|
|
193
|
+
coreContract: coreContract,
|
|
194
|
+
projectId: ABHelpers.tokenIdToProjectId(tokenId)
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// @dev ERC-721 permits `transferFrom(a, a, id)`. Ownership did not
|
|
198
|
+
// change, so counting it would inflate `transferCount`.
|
|
199
|
+
if (from == to) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
TokenTransferState storage state = _state[coreContract][tokenId];
|
|
204
|
+
|
|
205
|
+
if (from == address(0)) {
|
|
206
|
+
// mint: record timestamp once, do not count as a transfer, and
|
|
207
|
+
// write transferCount=0 so the PMP is populated from first render
|
|
208
|
+
if (state.mintTimestamp == 0) {
|
|
209
|
+
// @dev uint64 seconds is not a practical bound; no cast check
|
|
210
|
+
uint64 timestamp = uint64(block.timestamp);
|
|
211
|
+
state.mintTimestamp = timestamp;
|
|
212
|
+
emit MintTimestampRecorded({
|
|
213
|
+
coreContract: coreContract,
|
|
214
|
+
tokenId: tokenId,
|
|
215
|
+
timestamp: timestamp
|
|
216
|
+
});
|
|
217
|
+
_syncTransferCountToPMP({
|
|
218
|
+
coreContract: coreContract,
|
|
219
|
+
tokenId: tokenId,
|
|
220
|
+
newCount: 0
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
uint64 newCount = state.transferCount + 1;
|
|
227
|
+
state.transferCount = newCount;
|
|
228
|
+
emit TransferCounted({
|
|
229
|
+
coreContract: coreContract,
|
|
230
|
+
tokenId: tokenId,
|
|
231
|
+
transferCount: newCount,
|
|
232
|
+
from: from,
|
|
233
|
+
to: to
|
|
234
|
+
});
|
|
235
|
+
_syncTransferCountToPMP({
|
|
236
|
+
coreContract: coreContract,
|
|
237
|
+
tokenId: tokenId,
|
|
238
|
+
newCount: newCount
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @notice Augment the token parameters for a given token.
|
|
244
|
+
* Copies the input params, drops any entries whose keys collide with this
|
|
245
|
+
* hook's reserved keys, and appends `mintTimestamp`, `secondsSinceMint`,
|
|
246
|
+
* and `transferCount` as decimal strings.
|
|
247
|
+
* @dev This hook is called when a token's PostParams are read.
|
|
248
|
+
* @dev This must return all desired tokenParams, not just additional data.
|
|
249
|
+
* @param coreContract The address of the core contract of the queried token.
|
|
250
|
+
* @param tokenId The tokenId of the queried token.
|
|
251
|
+
* @param tokenParams The token parameters for the queried token.
|
|
252
|
+
* @return augmentedTokenParams The augmented token parameters.
|
|
253
|
+
*/
|
|
254
|
+
function onTokenPMPReadAugmentation(
|
|
255
|
+
address coreContract,
|
|
256
|
+
uint256 tokenId,
|
|
257
|
+
IWeb3Call.TokenParam[] calldata tokenParams
|
|
258
|
+
)
|
|
259
|
+
external
|
|
260
|
+
view
|
|
261
|
+
override(AbstractPMPAugmentHook, IPMPAugmentHook)
|
|
262
|
+
returns (IWeb3Call.TokenParam[] memory augmentedTokenParams)
|
|
263
|
+
{
|
|
264
|
+
uint256 originalLength = tokenParams.length;
|
|
265
|
+
// at most originalLength kept entries + 3 injected keys
|
|
266
|
+
uint256 augmentedMaxLength = originalLength + 3;
|
|
267
|
+
augmentedTokenParams = new IWeb3Call.TokenParam[](augmentedMaxLength);
|
|
268
|
+
|
|
269
|
+
bytes32 hashedMintTimestamp = keccak256(
|
|
270
|
+
bytes(PARAM_KEY_MINT_TIMESTAMP)
|
|
271
|
+
);
|
|
272
|
+
bytes32 hashedSecondsSinceMint = keccak256(
|
|
273
|
+
bytes(PARAM_KEY_SECONDS_SINCE_MINT)
|
|
274
|
+
);
|
|
275
|
+
bytes32 hashedTransferCount = keccak256(
|
|
276
|
+
bytes(PARAM_KEY_TRANSFER_COUNT)
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
uint256 j;
|
|
280
|
+
for (uint256 i; i < originalLength; ) {
|
|
281
|
+
bytes32 hashedKey = keccak256(bytes(tokenParams[i].key));
|
|
282
|
+
if (
|
|
283
|
+
hashedKey != hashedMintTimestamp &&
|
|
284
|
+
hashedKey != hashedSecondsSinceMint &&
|
|
285
|
+
hashedKey != hashedTransferCount
|
|
286
|
+
) {
|
|
287
|
+
augmentedTokenParams[j] = tokenParams[i];
|
|
288
|
+
unchecked {
|
|
289
|
+
++j;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
unchecked {
|
|
293
|
+
++i;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
TokenTransferState memory state = _state[coreContract][tokenId];
|
|
298
|
+
uint256 recordedMintTimestamp = uint256(state.mintTimestamp);
|
|
299
|
+
uint256 elapsed = _secondsSinceMint({
|
|
300
|
+
recordedMintTimestamp: recordedMintTimestamp
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
augmentedTokenParams[j] = IWeb3Call.TokenParam({
|
|
304
|
+
key: PARAM_KEY_MINT_TIMESTAMP,
|
|
305
|
+
value: recordedMintTimestamp.toString()
|
|
306
|
+
});
|
|
307
|
+
unchecked {
|
|
308
|
+
++j;
|
|
309
|
+
}
|
|
310
|
+
augmentedTokenParams[j] = IWeb3Call.TokenParam({
|
|
311
|
+
key: PARAM_KEY_SECONDS_SINCE_MINT,
|
|
312
|
+
value: elapsed.toString()
|
|
313
|
+
});
|
|
314
|
+
unchecked {
|
|
315
|
+
++j;
|
|
316
|
+
}
|
|
317
|
+
augmentedTokenParams[j] = IWeb3Call.TokenParam({
|
|
318
|
+
key: PARAM_KEY_TRANSFER_COUNT,
|
|
319
|
+
value: uint256(state.transferCount).toString()
|
|
320
|
+
});
|
|
321
|
+
unchecked {
|
|
322
|
+
++j;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// shorten to the populated length (original minus stripped plus 3)
|
|
326
|
+
assembly {
|
|
327
|
+
mstore(augmentedTokenParams, j)
|
|
328
|
+
}
|
|
329
|
+
return augmentedTokenParams;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @inheritdoc IMintTimeAndTransferCountHooks
|
|
334
|
+
*/
|
|
335
|
+
function tokenTransferState(
|
|
336
|
+
address coreContract,
|
|
337
|
+
uint256 tokenId
|
|
338
|
+
) external view returns (TokenTransferState memory state) {
|
|
339
|
+
return _state[coreContract][tokenId];
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* @inheritdoc IMintTimeAndTransferCountHooks
|
|
344
|
+
*/
|
|
345
|
+
function mintTimestamp(
|
|
346
|
+
address coreContract,
|
|
347
|
+
uint256 tokenId
|
|
348
|
+
) external view returns (uint256) {
|
|
349
|
+
return uint256(_state[coreContract][tokenId].mintTimestamp);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* @inheritdoc IMintTimeAndTransferCountHooks
|
|
354
|
+
*/
|
|
355
|
+
function transferCount(
|
|
356
|
+
address coreContract,
|
|
357
|
+
uint256 tokenId
|
|
358
|
+
) external view returns (uint256) {
|
|
359
|
+
return uint256(_state[coreContract][tokenId].transferCount);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* @inheritdoc IMintTimeAndTransferCountHooks
|
|
364
|
+
*/
|
|
365
|
+
function secondsSinceMint(
|
|
366
|
+
address coreContract,
|
|
367
|
+
uint256 tokenId
|
|
368
|
+
) external view returns (uint256) {
|
|
369
|
+
return
|
|
370
|
+
_secondsSinceMint({
|
|
371
|
+
recordedMintTimestamp: uint256(
|
|
372
|
+
_state[coreContract][tokenId].mintTimestamp
|
|
373
|
+
)
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* @inheritdoc IMintTimeAndTransferCountHooks
|
|
379
|
+
*/
|
|
380
|
+
function isTrackedFromMint(
|
|
381
|
+
address coreContract,
|
|
382
|
+
uint256 tokenId
|
|
383
|
+
) external view returns (bool) {
|
|
384
|
+
return _state[coreContract][tokenId].mintTimestamp != 0;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* @notice Write `transferCount` to the bound PMP as the Address-auth
|
|
389
|
+
* caller, including `0` at mint so the param exists before any transfer.
|
|
390
|
+
* Failures are swallowed so a misconfigured PMP cannot brick mints or
|
|
391
|
+
* transfers.
|
|
392
|
+
*/
|
|
393
|
+
function _syncTransferCountToPMP(
|
|
394
|
+
address coreContract,
|
|
395
|
+
uint256 tokenId,
|
|
396
|
+
uint64 newCount
|
|
397
|
+
) private {
|
|
398
|
+
if (address(pmp) == address(0)) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
IPMPV0.PMPInput[] memory pmpInputs = new IPMPV0.PMPInput[](1);
|
|
402
|
+
pmpInputs[0] = IPMPV0.PMPInput({
|
|
403
|
+
key: PARAM_KEY_TRANSFER_COUNT,
|
|
404
|
+
configuredParamType: IPMPV0.ParamType.Uint256Range,
|
|
405
|
+
configuredValue: bytes32(uint256(newCount)),
|
|
406
|
+
configuringArtistString: false,
|
|
407
|
+
configuredValueString: ""
|
|
408
|
+
});
|
|
409
|
+
try
|
|
410
|
+
pmp.configureTokenParams(coreContract, tokenId, pmpInputs)
|
|
411
|
+
{} catch {
|
|
412
|
+
emit TransferCountPMPSyncFailed({
|
|
413
|
+
coreContract: coreContract,
|
|
414
|
+
tokenId: tokenId,
|
|
415
|
+
transferCount: newCount
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* @notice Live seconds since `recordedMintTimestamp`. `0` when the mint
|
|
422
|
+
* was not observed or `block.timestamp` is not after it.
|
|
423
|
+
*/
|
|
424
|
+
function _secondsSinceMint(
|
|
425
|
+
uint256 recordedMintTimestamp
|
|
426
|
+
) private view returns (uint256) {
|
|
427
|
+
if (
|
|
428
|
+
recordedMintTimestamp == 0 ||
|
|
429
|
+
block.timestamp < recordedMintTimestamp
|
|
430
|
+
) {
|
|
431
|
+
return 0;
|
|
432
|
+
}
|
|
433
|
+
return block.timestamp - recordedMintTimestamp;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* @notice Revert unless `coreContract` has this hook configured for
|
|
438
|
+
* `projectId`.
|
|
439
|
+
* @dev This is the `ITransferHook` requirement that an implementation
|
|
440
|
+
* verify which cores it serves, answered without any configuration of its
|
|
441
|
+
* own: the set of cores this hook serves is exactly the set that points at
|
|
442
|
+
* it. A contract impersonating a core could answer this call dishonestly,
|
|
443
|
+
* which is why it is a second guard rather than the only one — the storage
|
|
444
|
+
* keyed by `coreContract` already confines such a caller to its own
|
|
445
|
+
* namespace.
|
|
446
|
+
*/
|
|
447
|
+
function _onlyConfiguredForProject(
|
|
448
|
+
address coreContract,
|
|
449
|
+
uint256 projectId
|
|
450
|
+
) private view {
|
|
451
|
+
(address configuredHook, ) = IGenArt721CoreContractV3_Engine(
|
|
452
|
+
coreContract
|
|
453
|
+
).projectTransferHookConfig(projectId);
|
|
454
|
+
if (configuredHook != address(this)) {
|
|
455
|
+
revert HookNotConfiguredForProject({
|
|
456
|
+
coreContract: coreContract,
|
|
457
|
+
projectId: projectId,
|
|
458
|
+
configuredHook: configuredHook
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* @notice Indicates support for `ITransferHook` (required by v3.3 cores)
|
|
465
|
+
* and `IPMPAugmentHook` (required by PMP before a read-augmentation hook
|
|
466
|
+
* may be configured).
|
|
467
|
+
*/
|
|
468
|
+
function supportsInterface(
|
|
469
|
+
bytes4 interfaceId
|
|
470
|
+
)
|
|
471
|
+
public
|
|
472
|
+
view
|
|
473
|
+
virtual
|
|
474
|
+
override(AbstractTransferHook, AbstractPMPAugmentHook, IERC165)
|
|
475
|
+
returns (bool)
|
|
476
|
+
{
|
|
477
|
+
return
|
|
478
|
+
interfaceId == type(IMintTimeAndTransferCountHooks).interfaceId ||
|
|
479
|
+
interfaceId == type(ITransferHook).interfaceId ||
|
|
480
|
+
interfaceId == type(IPMPAugmentHook).interfaceId ||
|
|
481
|
+
super.supportsInterface(interfaceId);
|
|
482
|
+
}
|
|
483
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artblocks/contracts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Smart contracts used by Art Blocks",
|
|
5
5
|
"files": [
|
|
6
6
|
"/contracts/**/*.sol",
|
|
@@ -153,6 +153,7 @@
|
|
|
153
153
|
"graphql": "^16.8.2",
|
|
154
154
|
"scripty.sol": "2.1.1",
|
|
155
155
|
"solady": "^0.1.26",
|
|
156
|
+
"undici": "^5.29.0",
|
|
156
157
|
"urql": "^4.2.1"
|
|
157
158
|
},
|
|
158
159
|
"resolutions": {
|