Skip to content

Commit 2abaa42

Browse files
ContractPublisher updates for polygon deployment
1 parent 2a207b5 commit 2abaa42

File tree

5 files changed

+7
-197
lines changed

5 files changed

+7
-197
lines changed

contracts/ContractPublisher.sol

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
2727
Mappings
2828
//////////////////////////////////////////////////////////////*/
2929

30-
/**
31-
* @dev Mapping from publisher address => operator address => whether publisher has approved operator
32-
* to publish / unpublish contracts on their behalf.
33-
*/
34-
mapping(address => mapping(address => bool)) public isApprovedByPublisher;
35-
3630
/// @dev Mapping from public Id => publicly published contract.
3731
mapping(uint256 => PublicContract) private publicContracts;
3832

@@ -43,9 +37,9 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
4337
Constructor + modifiers
4438
//////////////////////////////////////////////////////////////*/
4539

46-
/// @dev Checks whether caller is publisher or approved by publisher.
47-
modifier onlyApprovedOrPublisher(address _publisher) {
48-
require(_msgSender() == _publisher || isApprovedByPublisher[_publisher][_msgSender()], "unapproved caller");
40+
/// @dev Checks whether caller is publisher TODO enable external approvals
41+
modifier onlyPublisher(address _publisher) {
42+
require(_msgSender() == _publisher, "unapproved caller");
4943

5044
_;
5145
}
@@ -139,20 +133,14 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
139133
Publish logic
140134
//////////////////////////////////////////////////////////////*/
141135

142-
/// @notice Lets a publisher (caller) approve an operator to publish / unpublish contracts on their behalf.
143-
function approveOperator(address _operator, bool _toApprove) external {
144-
isApprovedByPublisher[_msgSender()][_operator] = _toApprove;
145-
emit Approved(_msgSender(), _operator, _toApprove);
146-
}
147-
148136
/// @notice Let's an account publish a contract. The account must be approved by the publisher, or be the publisher.
149137
function publishContract(
150138
address _publisher,
151139
string memory _publishMetadataUri,
152140
bytes32 _bytecodeHash,
153141
address _implementation,
154142
string memory _contractId
155-
) external onlyApprovedOrPublisher(_publisher) onlyUnpausedOrAdmin {
143+
) external onlyPublisher(_publisher) onlyUnpausedOrAdmin {
156144
CustomContractInstance memory publishedContract = CustomContractInstance({
157145
contractId: _contractId,
158146
publishTimestamp: block.timestamp,
@@ -177,7 +165,7 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
177165
/// @notice Lets an account unpublish a contract and all its versions. The account must be approved by the publisher, or be the publisher.
178166
function unpublishContract(address _publisher, string memory _contractId)
179167
external
180-
onlyApprovedOrPublisher(_publisher)
168+
onlyPublisher(_publisher)
181169
onlyUnpausedOrAdmin
182170
{
183171
bytes32 contractIdInBytes = keccak256(bytes(_contractId));

contracts/interfaces/IContractPublisher.sol

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ interface IContractPublisher {
3232
/// @dev Emitted when the registry is paused.
3333
event Paused(bool isPaused);
3434

35-
/// @dev Emitted when a publisher's approval of an operator is updated.
36-
event Approved(address indexed publisher, address indexed operator, bool isApproved);
37-
3835
/// @dev Emitted when a contract is published.
3936
event ContractPublished(
4037
address indexed operator,
@@ -51,24 +48,6 @@ interface IContractPublisher {
5148
/// @dev Emitted when a published contract is removed from the public list.
5249
event RemovedContractToPublicList(address indexed publisher, string indexed contractId);
5350

54-
/**
55-
* @notice Returns whether a publisher has approved an operator to publish / unpublish contracts on their behalf.
56-
*
57-
* @param publisher The address of the publisher.
58-
* @param operator The address of the operator who publishes/unpublishes on behalf of the publisher.
59-
*
60-
* @return isApproved Whether the publisher has approved the operator to publish / unpublish contracts on their behalf.
61-
*/
62-
function isApprovedByPublisher(address publisher, address operator) external view returns (bool isApproved);
63-
64-
/**
65-
* @notice Lets a publisher (caller) approve an operator to publish / unpublish contracts on their behalf.
66-
*
67-
* @param operator The address of the operator who publishes/unpublishes on behalf of the publisher.
68-
* @param toApprove whether to an operator to publish / unpublish contracts on the publisher's behalf.
69-
*/
70-
function approveOperator(address operator, bool toApprove) external;
71-
7251
/**
7352
* @notice Returns the latest version of all contracts published by a publisher.
7453
*

docs/ContractPublisher.md

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,6 @@ Lets an account add a published contract (and all its versions). The account mus
4444
| _publisher | address | undefined
4545
| _contractId | string | undefined
4646

47-
### approveOperator
48-
49-
```solidity
50-
function approveOperator(address _operator, bool _toApprove) external nonpayable
51-
```
52-
53-
Lets a publisher (caller) approve an operator to publish / unpublish contracts on their behalf.
54-
55-
56-
57-
#### Parameters
58-
59-
| Name | Type | Description |
60-
|---|---|---|
61-
| _operator | address | undefined
62-
| _toApprove | bool | undefined
63-
6447
### getAllPublicPublishedContracts
6548

6649
```solidity
@@ -276,29 +259,6 @@ function hasRole(bytes32 role, address account) external view returns (bool)
276259
|---|---|---|
277260
| _0 | bool | undefined
278261

279-
### isApprovedByPublisher
280-
281-
```solidity
282-
function isApprovedByPublisher(address, address) external view returns (bool)
283-
```
284-
285-
286-
287-
*Mapping from publisher address => operator address => whether publisher has approved operator to publish / unpublish contracts on their behalf.*
288-
289-
#### Parameters
290-
291-
| Name | Type | Description |
292-
|---|---|---|
293-
| _0 | address | undefined
294-
| _1 | address | undefined
295-
296-
#### Returns
297-
298-
| Name | Type | Description |
299-
|---|---|---|
300-
| _0 | bool | undefined
301-
302262
### isPaused
303263

304264
```solidity
@@ -524,24 +484,6 @@ event AddedContractToPublicList(address indexed publisher, string indexed contra
524484
| publisher `indexed` | address | undefined |
525485
| contractId `indexed` | string | undefined |
526486

527-
### Approved
528-
529-
```solidity
530-
event Approved(address indexed publisher, address indexed operator, bool isApproved)
531-
```
532-
533-
534-
535-
536-
537-
#### Parameters
538-
539-
| Name | Type | Description |
540-
|---|---|---|
541-
| publisher `indexed` | address | undefined |
542-
| operator `indexed` | address | undefined |
543-
| isApproved | bool | undefined |
544-
545487
### ContractPublished
546488

547489
```solidity

docs/IContractPublisher.md

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,6 @@ Lets an account add a published contract (and all its versions). The account mus
2727
| publisher | address | The address of the publisher.
2828
| contractId | string | The identifier for a published contract (that can have multiple verisons).
2929

30-
### approveOperator
31-
32-
```solidity
33-
function approveOperator(address operator, bool toApprove) external nonpayable
34-
```
35-
36-
Lets a publisher (caller) approve an operator to publish / unpublish contracts on their behalf.
37-
38-
39-
40-
#### Parameters
41-
42-
| Name | Type | Description |
43-
|---|---|---|
44-
| operator | address | The address of the operator who publishes/unpublishes on behalf of the publisher.
45-
| toApprove | bool | whether to an operator to publish / unpublish contracts on the publisher's behalf.
46-
4730
### getAllPublicPublishedContracts
4831

4932
```solidity
@@ -152,29 +135,6 @@ Returns all versions of a published contract.
152135
|---|---|---|
153136
| published | IContractPublisher.CustomContractInstance[] | The desired contracts published by the publisher.
154137

155-
### isApprovedByPublisher
156-
157-
```solidity
158-
function isApprovedByPublisher(address publisher, address operator) external view returns (bool isApproved)
159-
```
160-
161-
Returns whether a publisher has approved an operator to publish / unpublish contracts on their behalf.
162-
163-
164-
165-
#### Parameters
166-
167-
| Name | Type | Description |
168-
|---|---|---|
169-
| publisher | address | The address of the publisher.
170-
| operator | address | The address of the operator who publishes/unpublishes on behalf of the publisher.
171-
172-
#### Returns
173-
174-
| Name | Type | Description |
175-
|---|---|---|
176-
| isApproved | bool | Whether the publisher has approved the operator to publish / unpublish contracts on their behalf.
177-
178138
### publishContract
179139

180140
```solidity
@@ -250,24 +210,6 @@ event AddedContractToPublicList(address indexed publisher, string indexed contra
250210
| publisher `indexed` | address | undefined |
251211
| contractId `indexed` | string | undefined |
252212

253-
### Approved
254-
255-
```solidity
256-
event Approved(address indexed publisher, address indexed operator, bool isApproved)
257-
```
258-
259-
260-
261-
*Emitted when a publisher's approval of an operator is updated.*
262-
263-
#### Parameters
264-
265-
| Name | Type | Description |
266-
|---|---|---|
267-
| publisher `indexed` | address | undefined |
268-
| operator `indexed` | address | undefined |
269-
| isApproved | bool | undefined |
270-
271213
### ContractPublished
272214

273215
```solidity

scripts/deploy/byocSetup.ts

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ import hre, { ethers } from "hardhat";
22

33
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
44

5-
import { TWRegistry, ContractMetadataRegistry, ContractDeployer, ContractPublisher } from "typechain";
5+
import { ContractPublisher } from "typechain";
66

77
/**
88
*
9-
* There is a mock `TWRegistry` deployed on testnets for the purposes of thirdweb deploy testing.
10-
*
11-
* This script does the following:
12-
* (1) deploys `contracts/ContractMetadataRegistry` and `contracts/ContractDeployer`.
13-
* (2) grants `OPERATOR_ROLE` in `TWRegistry` to the deployed `ContractDeployer`.
14-
* (3) grants `OPERATOR_ROLE` in `ContractMetadataRegistry` to the deployed `ContractDeployer`.
15-
* (4) verifies deployed contracts.
9+
* Deploys the contract publisher and verifies the contract.
1610
*/
1711

1812
async function verify(address: string, args: any[]) {
@@ -32,21 +26,6 @@ async function main() {
3226

3327
const trustedForwarder: string = "0xc82BbE41f2cF04e3a8efA18F7032BDD7f6d98a81";
3428

35-
const registryAddress: string = ethers.constants.AddressZero; // REPLACE FOR CORRECT CHAIN
36-
const registry: TWRegistry = await ethers.getContractAt("TWRegistry", registryAddress);
37-
38-
const contractMetadataRegistry: ContractMetadataRegistry = await ethers
39-
.getContractFactory("ContractMetadataRegistry")
40-
.then(f => f.deploy(trustedForwarder));
41-
console.log(
42-
"Deploying ContractMetadataRegistry at tx: ",
43-
contractMetadataRegistry.deployTransaction.hash,
44-
" address: ",
45-
contractMetadataRegistry.address,
46-
);
47-
await contractMetadataRegistry.deployTransaction.wait();
48-
console.log("Deployed ContractMetadataRegistry");
49-
5029
const contractPublisher: ContractPublisher = await ethers
5130
.getContractFactory("ContractPublisher")
5231
.then(f => f.deploy(trustedForwarder));
@@ -59,29 +38,9 @@ async function main() {
5938
await contractPublisher.deployTransaction.wait();
6039
console.log("Deployed ContractPublisher");
6140

62-
const contractDeployer: ContractDeployer = await ethers
63-
.getContractFactory("ContractDeployer")
64-
.then(f => f.deploy(registry.address, contractMetadataRegistry.address, trustedForwarder));
65-
console.log(
66-
"\nDeploying ContractDeployer \ntx: ",
67-
contractDeployer.deployTransaction.hash,
68-
"\naddress: ",
69-
contractDeployer.address,
70-
);
71-
await contractDeployer.deployTransaction.wait();
72-
73-
const tx = await registry.grantRole(await registry.OPERATOR_ROLE(), contractDeployer.address);
74-
console.log("\nGranting operator role to ContractDeployer for TWRegistry: ", tx.hash);
75-
await tx.wait();
76-
const tx2 = await contractMetadataRegistry.grantRole(await registry.OPERATOR_ROLE(), contractDeployer.address);
77-
console.log("\nGranting operator role to ContractDeployer for ContractMetadataRegistry: ", tx.hash);
78-
await tx2.wait();
79-
8041
console.log("\nDone. Now verifying contracts:");
8142

8243
await verify(contractPublisher.address, [trustedForwarder]);
83-
await verify(contractMetadataRegistry.address, [trustedForwarder]);
84-
await verify(contractDeployer.address, [registry.address, contractMetadataRegistry.address, trustedForwarder]);
8544
}
8645

8746
main()

0 commit comments

Comments
 (0)