Skip to content

Commit

Permalink
ContractPublisher updates for polygon deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Jun 28, 2022
1 parent 2a207b5 commit 2abaa42
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 197 deletions.
22 changes: 5 additions & 17 deletions contracts/ContractPublisher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
Mappings
//////////////////////////////////////////////////////////////*/

/**
* @dev Mapping from publisher address => operator address => whether publisher has approved operator
* to publish / unpublish contracts on their behalf.
*/
mapping(address => mapping(address => bool)) public isApprovedByPublisher;

/// @dev Mapping from public Id => publicly published contract.
mapping(uint256 => PublicContract) private publicContracts;

Expand All @@ -43,9 +37,9 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
Constructor + modifiers
//////////////////////////////////////////////////////////////*/

/// @dev Checks whether caller is publisher or approved by publisher.
modifier onlyApprovedOrPublisher(address _publisher) {
require(_msgSender() == _publisher || isApprovedByPublisher[_publisher][_msgSender()], "unapproved caller");
/// @dev Checks whether caller is publisher TODO enable external approvals
modifier onlyPublisher(address _publisher) {
require(_msgSender() == _publisher, "unapproved caller");

_;
}
Expand Down Expand Up @@ -139,20 +133,14 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
Publish logic
//////////////////////////////////////////////////////////////*/

/// @notice Lets a publisher (caller) approve an operator to publish / unpublish contracts on their behalf.
function approveOperator(address _operator, bool _toApprove) external {
isApprovedByPublisher[_msgSender()][_operator] = _toApprove;
emit Approved(_msgSender(), _operator, _toApprove);
}

/// @notice Let's an account publish a contract. The account must be approved by the publisher, or be the publisher.
function publishContract(
address _publisher,
string memory _publishMetadataUri,
bytes32 _bytecodeHash,
address _implementation,
string memory _contractId
) external onlyApprovedOrPublisher(_publisher) onlyUnpausedOrAdmin {
) external onlyPublisher(_publisher) onlyUnpausedOrAdmin {
CustomContractInstance memory publishedContract = CustomContractInstance({
contractId: _contractId,
publishTimestamp: block.timestamp,
Expand All @@ -177,7 +165,7 @@ contract ContractPublisher is IContractPublisher, ERC2771Context, AccessControlE
/// @notice Lets an account unpublish a contract and all its versions. The account must be approved by the publisher, or be the publisher.
function unpublishContract(address _publisher, string memory _contractId)
external
onlyApprovedOrPublisher(_publisher)
onlyPublisher(_publisher)
onlyUnpausedOrAdmin
{
bytes32 contractIdInBytes = keccak256(bytes(_contractId));
Expand Down
21 changes: 0 additions & 21 deletions contracts/interfaces/IContractPublisher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ interface IContractPublisher {
/// @dev Emitted when the registry is paused.
event Paused(bool isPaused);

/// @dev Emitted when a publisher's approval of an operator is updated.
event Approved(address indexed publisher, address indexed operator, bool isApproved);

/// @dev Emitted when a contract is published.
event ContractPublished(
address indexed operator,
Expand All @@ -51,24 +48,6 @@ interface IContractPublisher {
/// @dev Emitted when a published contract is removed from the public list.
event RemovedContractToPublicList(address indexed publisher, string indexed contractId);

/**
* @notice Returns whether a publisher has approved an operator to publish / unpublish contracts on their behalf.
*
* @param publisher The address of the publisher.
* @param operator The address of the operator who publishes/unpublishes on behalf of the publisher.
*
* @return isApproved Whether the publisher has approved the operator to publish / unpublish contracts on their behalf.
*/
function isApprovedByPublisher(address publisher, address operator) external view returns (bool isApproved);

/**
* @notice Lets a publisher (caller) approve an operator to publish / unpublish contracts on their behalf.
*
* @param operator The address of the operator who publishes/unpublishes on behalf of the publisher.
* @param toApprove whether to an operator to publish / unpublish contracts on the publisher's behalf.
*/
function approveOperator(address operator, bool toApprove) external;

/**
* @notice Returns the latest version of all contracts published by a publisher.
*
Expand Down
58 changes: 0 additions & 58 deletions docs/ContractPublisher.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ Lets an account add a published contract (and all its versions). The account mus
| _publisher | address | undefined
| _contractId | string | undefined

### approveOperator

```solidity
function approveOperator(address _operator, bool _toApprove) external nonpayable
```

Lets a publisher (caller) approve an operator to publish / unpublish contracts on their behalf.



#### Parameters

| Name | Type | Description |
|---|---|---|
| _operator | address | undefined
| _toApprove | bool | undefined

### getAllPublicPublishedContracts

```solidity
Expand Down Expand Up @@ -276,29 +259,6 @@ function hasRole(bytes32 role, address account) external view returns (bool)
|---|---|---|
| _0 | bool | undefined

### isApprovedByPublisher

```solidity
function isApprovedByPublisher(address, address) external view returns (bool)
```



*Mapping from publisher address => operator address => whether publisher has approved operator to publish / unpublish contracts on their behalf.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined
| _1 | address | undefined

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | bool | undefined

### isPaused

```solidity
Expand Down Expand Up @@ -524,24 +484,6 @@ event AddedContractToPublicList(address indexed publisher, string indexed contra
| publisher `indexed` | address | undefined |
| contractId `indexed` | string | undefined |

### Approved

```solidity
event Approved(address indexed publisher, address indexed operator, bool isApproved)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| publisher `indexed` | address | undefined |
| operator `indexed` | address | undefined |
| isApproved | bool | undefined |

### ContractPublished

```solidity
Expand Down
58 changes: 0 additions & 58 deletions docs/IContractPublisher.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,6 @@ Lets an account add a published contract (and all its versions). The account mus
| publisher | address | The address of the publisher.
| contractId | string | The identifier for a published contract (that can have multiple verisons).

### approveOperator

```solidity
function approveOperator(address operator, bool toApprove) external nonpayable
```

Lets a publisher (caller) approve an operator to publish / unpublish contracts on their behalf.



#### Parameters

| Name | Type | Description |
|---|---|---|
| operator | address | The address of the operator who publishes/unpublishes on behalf of the publisher.
| toApprove | bool | whether to an operator to publish / unpublish contracts on the publisher's behalf.

### getAllPublicPublishedContracts

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

### isApprovedByPublisher

```solidity
function isApprovedByPublisher(address publisher, address operator) external view returns (bool isApproved)
```

Returns whether a publisher has approved an operator to publish / unpublish contracts on their behalf.



#### Parameters

| Name | Type | Description |
|---|---|---|
| publisher | address | The address of the publisher.
| operator | address | The address of the operator who publishes/unpublishes on behalf of the publisher.

#### Returns

| Name | Type | Description |
|---|---|---|
| isApproved | bool | Whether the publisher has approved the operator to publish / unpublish contracts on their behalf.

### publishContract

```solidity
Expand Down Expand Up @@ -250,24 +210,6 @@ event AddedContractToPublicList(address indexed publisher, string indexed contra
| publisher `indexed` | address | undefined |
| contractId `indexed` | string | undefined |

### Approved

```solidity
event Approved(address indexed publisher, address indexed operator, bool isApproved)
```



*Emitted when a publisher's approval of an operator is updated.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| publisher `indexed` | address | undefined |
| operator `indexed` | address | undefined |
| isApproved | bool | undefined |

### ContractPublished

```solidity
Expand Down
45 changes: 2 additions & 43 deletions scripts/deploy/byocSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ import hre, { ethers } from "hardhat";

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

import { TWRegistry, ContractMetadataRegistry, ContractDeployer, ContractPublisher } from "typechain";
import { ContractPublisher } from "typechain";

/**
*
* There is a mock `TWRegistry` deployed on testnets for the purposes of thirdweb deploy testing.
*
* This script does the following:
* (1) deploys `contracts/ContractMetadataRegistry` and `contracts/ContractDeployer`.
* (2) grants `OPERATOR_ROLE` in `TWRegistry` to the deployed `ContractDeployer`.
* (3) grants `OPERATOR_ROLE` in `ContractMetadataRegistry` to the deployed `ContractDeployer`.
* (4) verifies deployed contracts.
* Deploys the contract publisher and verifies the contract.
*/

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

const trustedForwarder: string = "0xc82BbE41f2cF04e3a8efA18F7032BDD7f6d98a81";

const registryAddress: string = ethers.constants.AddressZero; // REPLACE FOR CORRECT CHAIN
const registry: TWRegistry = await ethers.getContractAt("TWRegistry", registryAddress);

const contractMetadataRegistry: ContractMetadataRegistry = await ethers
.getContractFactory("ContractMetadataRegistry")
.then(f => f.deploy(trustedForwarder));
console.log(
"Deploying ContractMetadataRegistry at tx: ",
contractMetadataRegistry.deployTransaction.hash,
" address: ",
contractMetadataRegistry.address,
);
await contractMetadataRegistry.deployTransaction.wait();
console.log("Deployed ContractMetadataRegistry");

const contractPublisher: ContractPublisher = await ethers
.getContractFactory("ContractPublisher")
.then(f => f.deploy(trustedForwarder));
Expand All @@ -59,29 +38,9 @@ async function main() {
await contractPublisher.deployTransaction.wait();
console.log("Deployed ContractPublisher");

const contractDeployer: ContractDeployer = await ethers
.getContractFactory("ContractDeployer")
.then(f => f.deploy(registry.address, contractMetadataRegistry.address, trustedForwarder));
console.log(
"\nDeploying ContractDeployer \ntx: ",
contractDeployer.deployTransaction.hash,
"\naddress: ",
contractDeployer.address,
);
await contractDeployer.deployTransaction.wait();

const tx = await registry.grantRole(await registry.OPERATOR_ROLE(), contractDeployer.address);
console.log("\nGranting operator role to ContractDeployer for TWRegistry: ", tx.hash);
await tx.wait();
const tx2 = await contractMetadataRegistry.grantRole(await registry.OPERATOR_ROLE(), contractDeployer.address);
console.log("\nGranting operator role to ContractDeployer for ContractMetadataRegistry: ", tx.hash);
await tx2.wait();

console.log("\nDone. Now verifying contracts:");

await verify(contractPublisher.address, [trustedForwarder]);
await verify(contractMetadataRegistry.address, [trustedForwarder]);
await verify(contractDeployer.address, [registry.address, contractMetadataRegistry.address, trustedForwarder]);
}

main()
Expand Down

0 comments on commit 2abaa42

Please sign in to comment.