@agenticprimitives/contracts 1.0.0-alpha.5 → 1.0.0-alpha.50
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/AUDIT.md +119 -27
- package/README.md +47 -12
- package/deployments-base-sepolia.json +52 -1
- package/deployments-faithchain.json +103 -0
- package/deployments-hopechain.json +78 -0
- package/deployments-paymaster-anvil.json +1 -0
- package/deployments-registries-base-sepolia.json +1 -0
- package/deployments-registries-hopechain.json +1 -0
- package/dist/abi/AccountBootstrap.json +99 -0
- package/dist/abi/AgentAccount.json +461 -67
- package/dist/abi/AgentAccountFactory.json +309 -0
- package/dist/abi/AgentNameAttributeResolver.json +212 -0
- package/dist/abi/AgentNameRegistry.json +544 -0
- package/dist/abi/AgentNameUniversalResolver.json +222 -0
- package/dist/abi/AgentProfileResolver.json +236 -0
- package/dist/abi/AgentRegistryBase.json +1003 -0
- package/dist/abi/AgentRelationship.json +405 -0
- package/dist/abi/AgenticGovernance.json +155 -0
- package/dist/abi/AgreementRegistry.json +203 -5
- package/dist/abi/AllowedMethodsEnforcer.json +193 -0
- package/dist/abi/AllowedTargetsEnforcer.json +193 -0
- package/dist/abi/ApprovedHashRegistry.json +267 -2
- package/dist/abi/AttestationRegistry.json +242 -0
- package/dist/abi/AttributeStorage.json +24 -0
- package/dist/abi/CallDataHashEnforcer.json +193 -0
- package/dist/abi/CustodyPolicy.json +422 -55
- package/dist/abi/DelegationManager.json +292 -0
- package/dist/abi/DigestBindingEnforcer.json +541 -0
- package/dist/abi/Eip7702.json +13 -0
- package/dist/abi/EstateProjectionRegistry.json +599 -0
- package/dist/abi/Generation5Bridge.json +355 -0
- package/dist/abi/GeoFeatureRegistry.json +235 -0
- package/dist/abi/IAgentAccountFactoryView.json +26 -0
- package/dist/abi/IAgentAccountGovernanceTimelockView.json +15 -0
- package/dist/abi/IApprovedHashRegistryWrite.json +35 -0
- package/dist/abi/ICustodyEpochView.json +28 -0
- package/dist/abi/ICustodyPolicyAccountModuleView.json +31 -0
- package/dist/abi/ICustodyPolicyFactoryView.json +13 -0
- package/dist/abi/ICustodyPolicyPasskeyView.json +50 -0
- package/dist/abi/IDelegationManager.json +18 -0
- package/dist/abi/IGeneration4Reads.json +143 -0
- package/dist/abi/IGeneration5Account.json +33 -0
- package/dist/abi/IGeneration5Voucher.json +26 -0
- package/dist/abi/IMoveAccountView.json +57 -0
- package/dist/abi/IMoveCustodyView.json +169 -0
- package/dist/abi/IMoveFactoryView.json +41 -0
- package/dist/abi/IPaymentReceiptRegistry.json +50 -0
- package/dist/abi/IRedemptionContext.json +15 -0
- package/dist/abi/IRegistryMembershipPolicy.json +70 -0
- package/dist/abi/ITimelockVeto.json +93 -0
- package/dist/abi/ITreasurySpendPolicyAccountView.json +44 -0
- package/dist/abi/IUpgradeVoucherView.json +26 -0
- package/dist/abi/MockUSDC.json +621 -0
- package/dist/abi/OntologyTermRegistry.json +268 -0
- package/dist/abi/PayloadClassesEnforcer.json +310 -0
- package/dist/abi/PaymentEnforcer.json +639 -0
- package/dist/abi/PaymentEscrow.json +501 -0
- package/dist/abi/PaymentReceiptRegistry.json +388 -0
- package/dist/abi/PermissionlessSubregistry.json +353 -0
- package/dist/abi/PricedSubregistry.json +1141 -0
- package/dist/abi/QuorumEnforcer.json +209 -0
- package/dist/abi/ReceiptAnchorRegistry.json +346 -0
- package/dist/abi/RelationshipTypeRegistry.json +268 -0
- package/dist/abi/ShapeRegistry.json +268 -0
- package/dist/abi/SignatureVerifier.json +196 -0
- package/dist/abi/SkillDefinitionRegistry.json +235 -0
- package/dist/abi/SmartAgentPaymaster.json +445 -1
- package/dist/abi/StableProxyGoverned.json +190 -0
- package/dist/abi/StableProxyGovernedOneShot.json +172 -0
- package/dist/abi/TimestampEnforcer.json +193 -0
- package/dist/abi/TreasurySpendPolicy.json +667 -0
- package/dist/abi/UpgradeVoucher.json +328 -0
- package/dist/abi/ValueEnforcer.json +193 -0
- package/dist/abi/index.d.ts +35 -0
- package/dist/abi/index.js +35 -0
- package/dist/deployments/base-sepolia.d.ts +11 -0
- package/dist/deployments/base-sepolia.js +51 -28
- package/dist/deployments/faithchain.d.ts +77 -0
- package/dist/deployments/faithchain.js +107 -0
- package/dist/deployments/hopechain.d.ts +68 -0
- package/dist/deployments/hopechain.js +82 -0
- package/dist/deployments/index.d.ts +7 -2
- package/dist/deployments/index.js +15 -0
- package/dist/deployments/paymaster-anvil.d.ts +11 -0
- package/dist/deployments/paymaster-anvil.js +9 -0
- package/dist/deployments/registries-base-sepolia.d.ts +10 -0
- package/dist/deployments/registries-base-sepolia.js +8 -0
- package/dist/deployments/registries-hopechain.d.ts +10 -0
- package/dist/deployments/registries-hopechain.js +8 -0
- package/package.json +37 -7
- package/src/AccountBootstrap.sol +38 -0
- package/src/AgentAccount.sol +1091 -134
- package/src/AgentAccountFactory.sol +198 -21
- package/src/ApprovedHashRegistry.sol +134 -10
- package/src/IAgentAccount.sol +37 -0
- package/src/SmartAgentPaymaster.sol +275 -22
- package/src/UniversalSignatureValidator.sol +7 -0
- package/src/UpgradeVoucher.sol +87 -0
- package/src/agency/DelegationManager.sol +299 -76
- package/src/agency/ICaveatEnforcer.sol +10 -0
- package/src/agency/IDelegationManager.sol +37 -5
- package/src/agreement/AgreementRegistry.sol +105 -35
- package/src/attestation/AttestationRegistry.sol +220 -40
- package/src/custody/CustodyPolicy.sol +588 -70
- package/src/custody/TreasurySpendPolicy.sol +338 -0
- package/src/enforcers/AllowedMethodsEnforcer.sol +13 -2
- package/src/enforcers/AllowedTargetsEnforcer.sol +13 -2
- package/src/enforcers/CallDataHashEnforcer.sol +7 -1
- package/src/enforcers/DigestBindingEnforcer.sol +182 -0
- package/src/enforcers/PayloadClassesEnforcer.sol +36 -0
- package/src/enforcers/PaymentEnforcer.sol +291 -0
- package/src/enforcers/QuorumEnforcer.sol +24 -3
- package/src/enforcers/TimestampEnforcer.sol +7 -1
- package/src/enforcers/ValueEnforcer.sol +13 -2
- package/src/geo/GeoFeatureRegistry.sol +67 -22
- package/src/governance/AgenticGovernance.sol +187 -4
- package/src/governance/GovernanceManaged.sol +2 -0
- package/src/governance/StableProxyGoverned.sol +79 -0
- package/src/governance/StableProxyGovernedOneShot.sol +93 -0
- package/src/identity/AgentProfilePredicates.sol +23 -0
- package/src/identity/AgentProfileResolver.sol +22 -2
- package/src/libraries/Eip7702.sol +36 -0
- package/src/libraries/SignatureSlotRecovery.sol +28 -7
- package/src/libraries/SignatureVerifier.sol +52 -0
- package/src/libraries/WebAuthnLib.sol +16 -0
- package/src/migration/Generation5Bridge.sol +364 -0
- package/src/mocks/MockUSDC.sol +152 -0
- package/src/naming/AgentNameAttributeResolver.sol +29 -4
- package/src/naming/AgentNamePredicates.sol +89 -0
- package/src/naming/AgentNameRegistry.sol +324 -20
- package/src/naming/AgentNameUniversalResolver.sol +35 -2
- package/src/naming/PermissionlessSubregistry.sol +82 -25
- package/src/naming/PricedSubregistry.sol +293 -0
- package/src/ontology/AttributeStorage.sol +93 -80
- package/src/ontology/OntologyTermRegistry.sol +58 -2
- package/src/ontology/ShapeRegistry.sol +58 -2
- package/src/payments/PaymentEscrow.sol +187 -0
- package/src/payments/PaymentReceiptRegistry.sol +100 -0
- package/src/provenance/ReceiptAnchorRegistry.sol +67 -0
- package/src/registry/AgentRegistryBase.sol +372 -0
- package/src/registry/EstateProjectionRegistry.sol +177 -0
- package/src/registry/IRegistryMembershipPolicy.sol +30 -0
- package/src/relationships/AgentRelationship.sol +129 -8
- package/src/relationships/RelationshipTypeRegistry.sol +58 -2
- package/src/skills/SkillDefinitionRegistry.sol +61 -17
|
@@ -3,6 +3,7 @@ pragma solidity ^0.8.28;
|
|
|
3
3
|
|
|
4
4
|
import "./AgentNameRegistry.sol";
|
|
5
5
|
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
|
6
|
+
import "../governance/StableProxyGoverned.sol";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @title PermissionlessSubregistry
|
|
@@ -21,12 +22,21 @@ import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol
|
|
|
21
22
|
* is owned by `newOwner` (caller decides — typically themselves
|
|
22
23
|
* OR a PSA they control).
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
25
|
+
* Front-running (spec 445 / REG-5, ledger SUB-1): registration is COMMIT-REVEAL. A claimant first
|
|
26
|
+
* publishes `commit(keccak256(this, chainId, label, newOwner, secret))`, waits `MIN_COMMIT_AGE`, then
|
|
27
|
+
* reveals with `register(label, newOwner, secret)` before `MAX_COMMIT_AGE`. The label is not visible
|
|
28
|
+
* until the reveal, and a mempool observer who copies the reveal has no matured commitment of its own;
|
|
29
|
+
* copying the SAME reveal only registers the name to the owner the claimant chose (the commitment
|
|
30
|
+
* binds the owner, not the caller, so a relayer may reveal).
|
|
31
|
+
*
|
|
32
|
+
* The cap (ledger SUB-2) is one reveal per CALLER (`claimedBy[msg.sender]`). It is a courtesy rate
|
|
33
|
+
* limit and NOT a security control: a fresh address is free, so this contract does not ration names
|
|
34
|
+
* and nothing may rely on the cap. (A per-owner cap was considered and rejected: anyone could spend
|
|
35
|
+
* a victim's only slot by registering a junk name to them.) A root whose names are scarce or
|
|
36
|
+
* valuable MUST use `PricedSubregistry` (a coin and a gate's ticket); this contract is the testnet /
|
|
37
|
+
* demo posture and a production deploy does not put it in front of a typed root (spec 445 §2.1).
|
|
38
|
+
*
|
|
39
|
+
* Reserved labels and DNS-host injectivity are the registry's rule (`AgentNameRegistry.register`).
|
|
30
40
|
*
|
|
31
41
|
* Authority model:
|
|
32
42
|
* - The contract calls `REGISTRY.register(...)`; the registry sees
|
|
@@ -45,14 +55,23 @@ import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol
|
|
|
45
55
|
/// could re-enter `register()` and pass the check a second time.
|
|
46
56
|
/// The guard prevents any nested call into `register()`, closing
|
|
47
57
|
/// the window. Recon doc § 4.1 / `docs/audits/r6-contracts-recon-2026-05-31.md`.
|
|
48
|
-
contract PermissionlessSubregistry is ReentrancyGuard {
|
|
58
|
+
contract PermissionlessSubregistry is ReentrancyGuard, StableProxyGoverned {
|
|
49
59
|
AgentNameRegistry public immutable REGISTRY;
|
|
50
60
|
bytes32 public immutable PARENT_NODE;
|
|
51
61
|
address public immutable DEFAULT_RESOLVER;
|
|
52
62
|
|
|
53
63
|
uint256 public constant MIN_LABEL_LENGTH = 3;
|
|
54
64
|
|
|
55
|
-
/// @notice
|
|
65
|
+
/// @notice A commitment must be at least this old to be revealed — the reveal lands in a later block
|
|
66
|
+
/// than the commit, so an observer of the reveal cannot commit-and-reveal ahead of it.
|
|
67
|
+
uint256 public constant MIN_COMMIT_AGE = 10 seconds;
|
|
68
|
+
/// @notice …and at most this old. A stale commitment is void and may be re-committed.
|
|
69
|
+
uint256 public constant MAX_COMMIT_AGE = 1 days;
|
|
70
|
+
|
|
71
|
+
/// @notice commitment → when it was committed (0 = none / consumed).
|
|
72
|
+
mapping(bytes32 => uint256) public committedAt;
|
|
73
|
+
|
|
74
|
+
/// @notice msg.sender → the child node they've already claimed. Courtesy limit, not sybil resistance.
|
|
56
75
|
mapping(address => bytes32) public claimedBy;
|
|
57
76
|
/// @notice Total claims served by this subregistry instance.
|
|
58
77
|
uint256 public claimCount;
|
|
@@ -68,37 +87,72 @@ contract PermissionlessSubregistry is ReentrancyGuard {
|
|
|
68
87
|
error LabelTooShort();
|
|
69
88
|
error EmptyLabel();
|
|
70
89
|
error ZeroNewOwner();
|
|
90
|
+
error ZeroCommitment();
|
|
91
|
+
/// @notice A live (not yet expired) commitment with this hash already exists — re-committing would
|
|
92
|
+
/// reset its age, which a griefer could use to keep a claimant's reveal immature.
|
|
93
|
+
error CommitmentPending(bytes32 commitment);
|
|
94
|
+
error CommitmentNotFound(bytes32 commitment);
|
|
95
|
+
error CommitmentTooNew(bytes32 commitment, uint256 matureAt);
|
|
96
|
+
error CommitmentExpired(bytes32 commitment);
|
|
97
|
+
|
|
98
|
+
event Committed(bytes32 indexed commitment, address indexed by);
|
|
71
99
|
|
|
72
|
-
|
|
100
|
+
/// @notice A DIRECT deployment, with no upgrade governance (frozen code, as before). Spec 447 — behind a stable
|
|
101
|
+
/// proxy, `initialize(governance_)` instead. The immutables stay: `REGISTRY` and `DEFAULT_RESOLVER` are
|
|
102
|
+
/// stable proxy addresses and `PARENT_NODE` is a constant of this instance (one subregistry serves one
|
|
103
|
+
/// parent), so a fix is a new implementation built with the same three values.
|
|
104
|
+
/// `ReentrancyGuard` (OZ 5.0.2, non-upgradeable) keeps `_status` in slot 0; behind a proxy it starts at 0,
|
|
105
|
+
/// which `_nonReentrantBefore` treats as not-entered (it reverts only on `ENTERED == 2`), and the first
|
|
106
|
+
/// guarded call leaves it at `NOT_ENTERED == 1`.
|
|
107
|
+
constructor(AgentNameRegistry registry, bytes32 parentNode, address defaultResolver) initializer {
|
|
73
108
|
REGISTRY = registry;
|
|
74
109
|
PARENT_NODE = parentNode;
|
|
75
110
|
DEFAULT_RESOLVER = defaultResolver;
|
|
76
111
|
}
|
|
77
112
|
|
|
113
|
+
/// @notice The commitment for a claim: binds this subregistry, the chain, the label, the owner the
|
|
114
|
+
/// name will be registered to, and a secret only the claimant knows.
|
|
115
|
+
function makeCommitment(string calldata label, address newOwner, bytes32 secret) public view returns (bytes32) {
|
|
116
|
+
return keccak256(abi.encode(address(this), block.chainid, keccak256(bytes(label)), newOwner, secret));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// @notice Step 1 — publish a commitment. Anyone may; it reveals nothing about the label.
|
|
120
|
+
function commit(bytes32 commitment) external {
|
|
121
|
+
if (commitment == bytes32(0)) revert ZeroCommitment();
|
|
122
|
+
uint256 at = committedAt[commitment];
|
|
123
|
+
if (at != 0 && block.timestamp <= at + MAX_COMMIT_AGE) revert CommitmentPending(commitment);
|
|
124
|
+
committedAt[commitment] = block.timestamp;
|
|
125
|
+
emit Committed(commitment, msg.sender);
|
|
126
|
+
}
|
|
127
|
+
|
|
78
128
|
/**
|
|
79
|
-
* @notice
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* (e.g. label already taken).
|
|
129
|
+
* @notice Step 2 — reveal: claim `<label>.<parent>` for `newOwner`. Reverts when there is no matured,
|
|
130
|
+
* unexpired commitment for (label, newOwner, secret), when the caller already revealed a
|
|
131
|
+
* name here (courtesy limit), when the label fails the minimum-length guard, or when the registry
|
|
132
|
+
* refuses (label taken, reserved, or reading as a typed name).
|
|
84
133
|
*
|
|
85
|
-
* The caller pays gas. The contract does NOT collect a
|
|
86
|
-
*
|
|
87
|
-
* shape if needed.
|
|
134
|
+
* The caller pays gas. The contract does NOT collect a fee — fee gating is
|
|
135
|
+
* `PricedSubregistry`.
|
|
88
136
|
*/
|
|
89
|
-
function register(string calldata label, address newOwner) external nonReentrant returns (bytes32 childNode) {
|
|
137
|
+
function register(string calldata label, address newOwner, bytes32 secret) external nonReentrant returns (bytes32 childNode) {
|
|
90
138
|
if (bytes(label).length == 0) revert EmptyLabel();
|
|
91
139
|
if (bytes(label).length < MIN_LABEL_LENGTH) revert LabelTooShort();
|
|
92
140
|
if (newOwner == address(0)) revert ZeroNewOwner();
|
|
93
141
|
bytes32 prior = claimedBy[msg.sender];
|
|
94
142
|
if (prior != bytes32(0)) revert AlreadyClaimed(prior);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
143
|
+
|
|
144
|
+
bytes32 commitment = makeCommitment(label, newOwner, secret);
|
|
145
|
+
uint256 at = committedAt[commitment];
|
|
146
|
+
if (at == 0) revert CommitmentNotFound(commitment);
|
|
147
|
+
if (block.timestamp < at + MIN_COMMIT_AGE) revert CommitmentTooNew(commitment, at + MIN_COMMIT_AGE);
|
|
148
|
+
if (block.timestamp > at + MAX_COMMIT_AGE) revert CommitmentExpired(commitment);
|
|
149
|
+
delete committedAt[commitment];
|
|
150
|
+
claimedBy[msg.sender] = bytes32(uint256(1)); // provisional: written before the external call
|
|
151
|
+
|
|
152
|
+
// REGISTRY is an immutable contract we control that does not call back into this contract, and
|
|
153
|
+
// the function is `nonReentrant`; the claim slot and the consumed commitment are written BEFORE
|
|
154
|
+
// the call, and only the slot's final value (the node the registry returned) after it.
|
|
155
|
+
// R9 / docs/audits/r9-static-analysis-triage.md § Slither M-1: triaged false positive.
|
|
102
156
|
// slither-disable-next-line reentrancy-no-eth
|
|
103
157
|
childNode = REGISTRY.register(PARENT_NODE, label, newOwner, DEFAULT_RESOLVER, 0);
|
|
104
158
|
claimedBy[msg.sender] = childNode;
|
|
@@ -112,4 +166,7 @@ contract PermissionlessSubregistry is ReentrancyGuard {
|
|
|
112
166
|
function hasClaimed(address caller) external view returns (bool) {
|
|
113
167
|
return claimedBy[caller] != bytes32(0);
|
|
114
168
|
}
|
|
169
|
+
|
|
170
|
+
/// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
|
|
171
|
+
uint256[46] private __gap;
|
|
115
172
|
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.28;
|
|
3
|
+
|
|
4
|
+
import "./AgentNameRegistry.sol";
|
|
5
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
6
|
+
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
|
7
|
+
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
|
|
8
|
+
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
9
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
10
|
+
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
11
|
+
import "../governance/StableProxyGoverned.sol";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @title PricedSubregistry
|
|
15
|
+
* @notice A subregistry for one typed root where a claim COSTS a coin and needs a ticket (spec 431; the contract
|
|
16
|
+
* spec is 432). The successor of `PermissionlessSubregistry` for a root whose names are purchased.
|
|
17
|
+
*
|
|
18
|
+
* One signed operation, one receipt:
|
|
19
|
+
* - The PAYER calls `claim(ticket, gateSig)`. The payer is a treasury Smart Agent (assets live only in treasuries);
|
|
20
|
+
* it approved this contract for the price beforehand, in the same user operation.
|
|
21
|
+
* - The TICKET is signed (EIP-712) by an estate's naming GATE — the key a Home holds. A gate signs only after its
|
|
22
|
+
* own rules passed (the domain rule: a protected label needs a verified email at that domain). The contract
|
|
23
|
+
* checks the signature against the gates the governor named; it stores nothing about why the gate agreed
|
|
24
|
+
* beyond `domain` (a label, never an email).
|
|
25
|
+
* - The PRICE is a pure function of the label's length and this root's base, computed here and checked against
|
|
26
|
+
* the ticket, so the Home, the naming service and the chain agree on the number.
|
|
27
|
+
* - The fee moves from the payer to the fee treasury; the name is registered to `ticket.owner`; the owner is
|
|
28
|
+
* recorded as having claimed under this root (one name per owner per root, never released); the price and the
|
|
29
|
+
* time are stored so a reader never needs a log.
|
|
30
|
+
*
|
|
31
|
+
* What this is NOT (spec 431 D6): no expiry, no renewal, no resale, no refund. A paid name is an address card and
|
|
32
|
+
* grants nobody authority.
|
|
33
|
+
*
|
|
34
|
+
* Authority model: the registry sees `msg.sender == address(this)` AND `r.subregistry == this`; the child is owned
|
|
35
|
+
* by `ticket.owner`, never by this contract. Governance (gates, fee treasury, the price table) is the governor's —
|
|
36
|
+
* meant to be the root owner / the town's governor, and transferable.
|
|
37
|
+
*/
|
|
38
|
+
contract PricedSubregistry is ReentrancyGuard, EIP712, StableProxyGoverned {
|
|
39
|
+
using SafeERC20 for IERC20;
|
|
40
|
+
|
|
41
|
+
AgentNameRegistry public immutable REGISTRY;
|
|
42
|
+
bytes32 public immutable PARENT_NODE;
|
|
43
|
+
address public immutable DEFAULT_RESOLVER;
|
|
44
|
+
IERC20 public immutable COIN;
|
|
45
|
+
|
|
46
|
+
uint256 public constant MIN_LABEL_LENGTH = 3;
|
|
47
|
+
|
|
48
|
+
/// @dev keccak256("ClaimTicket(bytes32 parentNode,string label,address owner,address payer,uint256 price,bytes32 domain,uint256 expiry,bytes32 nonce)")
|
|
49
|
+
bytes32 public constant CLAIM_TICKET_TYPEHASH =
|
|
50
|
+
keccak256("ClaimTicket(bytes32 parentNode,string label,address owner,address payer,uint256 price,bytes32 domain,uint256 expiry,bytes32 nonce)");
|
|
51
|
+
|
|
52
|
+
struct ClaimTicket {
|
|
53
|
+
bytes32 parentNode;
|
|
54
|
+
string label;
|
|
55
|
+
address owner;
|
|
56
|
+
address payer;
|
|
57
|
+
uint256 price;
|
|
58
|
+
/// @dev keccak256 of the domain the gate vouched for (`ibm.com`), or zero for an unprotected label.
|
|
59
|
+
bytes32 domain;
|
|
60
|
+
uint256 expiry;
|
|
61
|
+
bytes32 nonce;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
address public governor;
|
|
65
|
+
address public feeTreasury;
|
|
66
|
+
/// @notice Estate naming gates whose tickets this root accepts.
|
|
67
|
+
mapping(address => bool) public gates;
|
|
68
|
+
|
|
69
|
+
/// @notice The price table: `base` in coin units for a label of 8+ characters; multipliers ×10 for lengths
|
|
70
|
+
/// 3, 4, 5, 6, 7 (an 8+ label is ×1); `cap` in coin units. Spec 431 §2.
|
|
71
|
+
uint256 public base;
|
|
72
|
+
uint16[5] public multipliersX10;
|
|
73
|
+
uint256 public cap;
|
|
74
|
+
|
|
75
|
+
/// @notice owner → the child node already claimed under this root (one per owner).
|
|
76
|
+
mapping(address => bytes32) public claimedBy;
|
|
77
|
+
/// @notice node → what was paid, and when. Readable without a log scan.
|
|
78
|
+
mapping(bytes32 => uint256) public paid;
|
|
79
|
+
mapping(bytes32 => uint64) public paidAt;
|
|
80
|
+
mapping(bytes32 => bool) public usedNonce;
|
|
81
|
+
uint256 public claimCount;
|
|
82
|
+
|
|
83
|
+
event NamePurchased(address indexed owner, address indexed payer, bytes32 indexed childNode, string label, uint256 price, bytes32 domain);
|
|
84
|
+
event GateSet(address indexed gate, bool allowed);
|
|
85
|
+
event FeeTreasurySet(address indexed feeTreasury);
|
|
86
|
+
event PriceTableSet(uint256 base, uint16[5] multipliersX10, uint256 cap);
|
|
87
|
+
event GovernorTransferred(address indexed oldGovernor, address indexed newGovernor);
|
|
88
|
+
|
|
89
|
+
error NotGovernor();
|
|
90
|
+
error ZeroAddress();
|
|
91
|
+
error WrongRoot();
|
|
92
|
+
error NotPayer();
|
|
93
|
+
error TicketExpired();
|
|
94
|
+
error NonceUsed();
|
|
95
|
+
error WrongPrice(uint256 expected);
|
|
96
|
+
error NotAGate(address signer);
|
|
97
|
+
error AlreadyClaimed(bytes32 existingNode);
|
|
98
|
+
error LabelTooShort();
|
|
99
|
+
error EmptyLabel();
|
|
100
|
+
/// @dev Spec 447 — `initialize(address)` alone would leave the governor, fee treasury and price table unset.
|
|
101
|
+
error GovernorRequired();
|
|
102
|
+
|
|
103
|
+
modifier onlyGovernor() {
|
|
104
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
105
|
+
if (msg.sender != governor) revert NotGovernor();
|
|
106
|
+
_;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
constructor(
|
|
110
|
+
AgentNameRegistry registry,
|
|
111
|
+
bytes32 parentNode,
|
|
112
|
+
address defaultResolver,
|
|
113
|
+
IERC20 coin,
|
|
114
|
+
address governor_,
|
|
115
|
+
address feeTreasury_,
|
|
116
|
+
uint256 base_,
|
|
117
|
+
uint16[5] memory multipliersX10_,
|
|
118
|
+
uint256 cap_
|
|
119
|
+
) EIP712("PricedSubregistry", "1") initializer {
|
|
120
|
+
if (address(coin) == address(0)) revert ZeroAddress();
|
|
121
|
+
REGISTRY = registry;
|
|
122
|
+
PARENT_NODE = parentNode;
|
|
123
|
+
DEFAULT_RESOLVER = defaultResolver;
|
|
124
|
+
COIN = coin;
|
|
125
|
+
_initPricing(governor_, feeTreasury_, base_, multipliersX10_, cap_);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ── spec 447: behind a stable proxy ─────────────────────────────────────────────────────────────────────
|
|
129
|
+
//
|
|
130
|
+
// A DIRECT deployment (above) has no upgrade governance: its code is frozen, as before. Behind a stable proxy
|
|
131
|
+
// the implementation is built with the same constructor arguments (its immutables are what the proxy runs
|
|
132
|
+
// with) and the proxy is initialized with `initialize(governance_, governor_, …)`, which sets the same storage
|
|
133
|
+
// the constructor sets. `governance` is the upgrade authority only; the `governor` runs the root as before.
|
|
134
|
+
//
|
|
135
|
+
// Immutables kept: `REGISTRY` and `DEFAULT_RESOLVER` are stable proxy addresses, `COIN` is a token address and
|
|
136
|
+
// `PARENT_NODE` a constant of this instance (one subregistry serves one root), so a fix is a new implementation
|
|
137
|
+
// built with the same four values.
|
|
138
|
+
//
|
|
139
|
+
// OZ `EIP712` (5.0.2) is proxy-safe: `_domainSeparatorV4()` returns the cached separator only when
|
|
140
|
+
// `address(this) == _cachedThis` (the implementation) and otherwise rebuilds it from `address(this)` — the
|
|
141
|
+
// proxy — so a gate signs tickets over the proxy's domain, and they stay valid across an upgrade that keeps
|
|
142
|
+
// the name and version. "PricedSubregistry" / "1" fit in a `ShortString`, so the name and version live in
|
|
143
|
+
// immutables, not in the `_nameFallback` / `_versionFallback` storage a proxy would see empty.
|
|
144
|
+
// `ReentrancyGuard` (5.0.2, non-upgradeable) starts at `_status == 0` behind a proxy, which it treats as
|
|
145
|
+
// not-entered (it reverts only on `ENTERED == 2`).
|
|
146
|
+
|
|
147
|
+
function initialize(
|
|
148
|
+
address governance_,
|
|
149
|
+
address governor_,
|
|
150
|
+
address feeTreasury_,
|
|
151
|
+
uint256 base_,
|
|
152
|
+
uint16[5] calldata multipliersX10_,
|
|
153
|
+
uint256 cap_
|
|
154
|
+
) external initializer {
|
|
155
|
+
_initializeGovernance(governance_);
|
|
156
|
+
_initPricing(governor_, feeTreasury_, base_, multipliersX10_, cap_);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// @dev The one-argument path would leave the governor, fee treasury and price table unset; refused.
|
|
160
|
+
function initialize(address) external pure override {
|
|
161
|
+
revert GovernorRequired();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function _initPricing(
|
|
165
|
+
address governor_,
|
|
166
|
+
address feeTreasury_,
|
|
167
|
+
uint256 base_,
|
|
168
|
+
uint16[5] memory multipliersX10_,
|
|
169
|
+
uint256 cap_
|
|
170
|
+
) private {
|
|
171
|
+
if (governor_ == address(0) || feeTreasury_ == address(0)) revert ZeroAddress();
|
|
172
|
+
governor = governor_;
|
|
173
|
+
feeTreasury = feeTreasury_;
|
|
174
|
+
base = base_;
|
|
175
|
+
multipliersX10 = multipliersX10_;
|
|
176
|
+
cap = cap_;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ── the price ───────────────────────────────────────────────────────────────────────────────────────────
|
|
180
|
+
|
|
181
|
+
/// @notice What `label` costs under this root: `min(cap, base × multiplier(length))`. Pure in the label.
|
|
182
|
+
function priceOf(string calldata label) public view returns (uint256) {
|
|
183
|
+
uint256 len = bytes(label).length;
|
|
184
|
+
if (len < MIN_LABEL_LENGTH) revert LabelTooShort();
|
|
185
|
+
uint256 x10 = len >= 8 ? 10 : multipliersX10[len - 3];
|
|
186
|
+
uint256 p = (base * x10) / 10;
|
|
187
|
+
return p > cap ? cap : p;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ── the claim ───────────────────────────────────────────────────────────────────────────────────────────
|
|
191
|
+
|
|
192
|
+
/// @notice The EIP-712 digest a gate signs for `t`.
|
|
193
|
+
function ticketDigest(ClaimTicket calldata t) public view returns (bytes32) {
|
|
194
|
+
return _hashTypedDataV4(keccak256(abi.encode(
|
|
195
|
+
CLAIM_TICKET_TYPEHASH, t.parentNode, keccak256(bytes(t.label)), t.owner, t.payer, t.price, t.domain, t.expiry, t.nonce
|
|
196
|
+
)));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @notice Buy `<label>.<root>` for `t.owner`, paid by `msg.sender` (= `t.payer`) with a ticket a gate signed.
|
|
201
|
+
* Reverts when the ticket is for another root, expired, re-used, carries the wrong price, is signed by
|
|
202
|
+
* nobody the governor named, when the owner already holds a name here, or when the registry refuses
|
|
203
|
+
* (the label is taken).
|
|
204
|
+
*/
|
|
205
|
+
function claim(ClaimTicket calldata t, bytes calldata gateSig) external nonReentrant returns (bytes32 childNode) {
|
|
206
|
+
if (bytes(t.label).length == 0) revert EmptyLabel();
|
|
207
|
+
if (t.parentNode != PARENT_NODE) revert WrongRoot();
|
|
208
|
+
if (t.payer != msg.sender) revert NotPayer();
|
|
209
|
+
if (t.owner == address(0)) revert ZeroAddress();
|
|
210
|
+
if (block.timestamp > t.expiry) revert TicketExpired();
|
|
211
|
+
if (usedNonce[t.nonce]) revert NonceUsed();
|
|
212
|
+
uint256 price = priceOf(t.label);
|
|
213
|
+
if (t.price != price) revert WrongPrice(price);
|
|
214
|
+
bytes32 prior = claimedBy[t.owner];
|
|
215
|
+
if (prior != bytes32(0)) revert AlreadyClaimed(prior);
|
|
216
|
+
address signer = ECDSA.recover(ticketDigest(t), gateSig);
|
|
217
|
+
if (!gates[signer]) revert NotAGate(signer);
|
|
218
|
+
|
|
219
|
+
usedNonce[t.nonce] = true;
|
|
220
|
+
if (price > 0) COIN.safeTransferFrom(msg.sender, feeTreasury, price);
|
|
221
|
+
// The registry is an immutable contract we control and does not call back here; the guard holds anyway.
|
|
222
|
+
// slither-disable-next-line reentrancy-no-eth
|
|
223
|
+
childNode = REGISTRY.register(PARENT_NODE, t.label, t.owner, DEFAULT_RESOLVER, 0);
|
|
224
|
+
claimedBy[t.owner] = childNode;
|
|
225
|
+
paid[childNode] = price;
|
|
226
|
+
paidAt[childNode] = uint64(block.timestamp);
|
|
227
|
+
unchecked { claimCount += 1; }
|
|
228
|
+
emit NamePurchased(t.owner, msg.sender, childNode, t.label, price, t.domain);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function hasClaimed(address owner) external view returns (bool) {
|
|
232
|
+
return claimedBy[owner] != bytes32(0);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ── governance ──────────────────────────────────────────────────────────────────────────────────────────
|
|
236
|
+
|
|
237
|
+
function setGate(address gate, bool allowed) external onlyGovernor {
|
|
238
|
+
if (gate == address(0)) revert ZeroAddress();
|
|
239
|
+
gates[gate] = allowed;
|
|
240
|
+
emit GateSet(gate, allowed);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function setFeeTreasury(address feeTreasury_) external onlyGovernor {
|
|
244
|
+
if (feeTreasury_ == address(0)) revert ZeroAddress();
|
|
245
|
+
feeTreasury = feeTreasury_;
|
|
246
|
+
emit FeeTreasurySet(feeTreasury_);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function setPriceTable(uint256 base_, uint16[5] calldata multipliersX10_, uint256 cap_) external onlyGovernor {
|
|
250
|
+
base = base_;
|
|
251
|
+
multipliersX10 = multipliersX10_;
|
|
252
|
+
cap = cap_;
|
|
253
|
+
emit PriceTableSet(base_, multipliersX10_, cap_);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function transferGovernor(address newGovernor) external onlyGovernor {
|
|
257
|
+
if (newGovernor == address(0)) revert ZeroAddress();
|
|
258
|
+
emit GovernorTransferred(governor, newGovernor);
|
|
259
|
+
governor = newGovernor;
|
|
260
|
+
pendingGovernor = address(0); // a proposal made by the previous governor does not survive it
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ─── Two-step governor hand-over (spec 445 / REG-11) ────────────
|
|
264
|
+
//
|
|
265
|
+
// `transferGovernor` is one step: a wrong address is permanent. It stays for the scripted bootstrap
|
|
266
|
+
// hand-over, where the deploy script asserts the end state in the same run (spec 445 §2.1). Every
|
|
267
|
+
// LATER rotation should use this pair — the successor proves it can act before the role moves.
|
|
268
|
+
|
|
269
|
+
/// @notice The successor named by `proposeGovernor`, until it accepts. Zero otherwise.
|
|
270
|
+
address public pendingGovernor;
|
|
271
|
+
|
|
272
|
+
event GovernorProposed(address indexed governor, address indexed pendingGovernor);
|
|
273
|
+
|
|
274
|
+
error NotPendingGovernor();
|
|
275
|
+
|
|
276
|
+
/// @notice Name a successor (zero cancels). The governor keeps the role until the successor accepts.
|
|
277
|
+
function proposeGovernor(address newGovernor) external onlyGovernor {
|
|
278
|
+
pendingGovernor = newGovernor;
|
|
279
|
+
emit GovernorProposed(governor, newGovernor);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/// @notice Take the governor role. Only the proposed successor.
|
|
283
|
+
function acceptGovernor() external {
|
|
284
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
285
|
+
if (msg.sender != pendingGovernor || msg.sender == address(0)) revert NotPendingGovernor();
|
|
286
|
+
emit GovernorTransferred(governor, msg.sender);
|
|
287
|
+
governor = msg.sender;
|
|
288
|
+
pendingGovernor = address(0);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/// @dev Spec 447 — storage gap: the root may sit behind a stable proxy; layout gated by `check:storage-layouts`.
|
|
292
|
+
uint256[35] private __gap;
|
|
293
|
+
}
|