Skip to content

Commit

Permalink
Make generator contract upgradable and add write functions for extern…
Browse files Browse the repository at this point in the history
…al contracts addresses. Use self deployed gunzip contract instead of ethfs.
  • Loading branch information
yoshiwarab committed Jan 18, 2024
1 parent a1143d6 commit 52e9ab2
Show file tree
Hide file tree
Showing 8 changed files with 375 additions and 431 deletions.
78 changes: 78 additions & 0 deletions packages/contracts/.openzeppelin/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"address": "0xEFA7Ef074A6E90a99fba8bAd4dCf337ef298387f",
"txHash": "0xee1ad6b97bf1819837293f000948d2802b325faa261f9d7d8dd277f999150658",
"kind": "transparent"
},
{
"address": "0xdC862938cA0a2D8dcabe5733C23e54ac7aAFFF27",
"txHash": "0x51a4238afeca59f44439f0303bb99bbc728d07993ad7bcfefb688585e4243770",
"kind": "transparent"
}
],
"impls": {
Expand Down Expand Up @@ -92,6 +97,79 @@
}
}
}
},
"1b6033ccc3bed545b5ceb14d868b4e11f3b6ec5a05a6b7628923f382bec23202": {
"address": "0x34a5F30D34EF69102DcAFeCb062605F3E3f57D93",
"txHash": "0x7bb2f060c373ed2af9f7733870de8fbf781e87bb97556e7277c0ce5d0369e18a",
"layout": {
"solcVersion": "0.8.19",
"storage": [
{
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "t_uint8",
"contract": "Initializable",
"src": "@openzeppelin-4.8/contracts-upgradeable/proxy/utils/Initializable.sol:62",
"retypedFrom": "bool"
},
{
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "t_bool",
"contract": "Initializable",
"src": "@openzeppelin-4.8/contracts-upgradeable/proxy/utils/Initializable.sol:67"
},
{
"label": "dependencyRegistry",
"offset": 2,
"slot": "0",
"type": "t_contract(DependencyRegistryV0)4223",
"contract": "GenArt721GeneratorV0",
"src": "contracts/generator/GenArt721GeneratorV0.sol:31"
},
{
"label": "scriptyBuilder",
"offset": 0,
"slot": "1",
"type": "t_contract(IScriptyBuilderV2)6462",
"contract": "GenArt721GeneratorV0",
"src": "contracts/generator/GenArt721GeneratorV0.sol:32"
},
{
"label": "gunzipScriptAddress",
"offset": 0,
"slot": "2",
"type": "t_address",
"contract": "GenArt721GeneratorV0",
"src": "contracts/generator/GenArt721GeneratorV0.sol:33"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_contract(DependencyRegistryV0)4223": {
"label": "contract DependencyRegistryV0",
"numberOfBytes": "20"
},
"t_contract(IScriptyBuilderV2)6462": {
"label": "contract IScriptyBuilderV2",
"numberOfBytes": "20"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
}
},
"namespaces": {}
}
}
}
}
29 changes: 29 additions & 0 deletions packages/contracts/contracts/BytecodeStorageV1Writer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.19;

// Created By: Art Blocks Inc.
import "./libs/v0.8.x/BytecodeStorageV1.sol";

/**
* @title Art Blocks Storage Writer
* @author Art Blocks Inc.
* @notice A simple contract that with a single function that uses
* the BytecodeStorageV1 library to write a string to bytecode storage.
*/
contract BytecodeStorageV1Writer {
using BytecodeStorageWriter for string;

event StorageContractCreated(address indexed storageContract);

/**
* @notice Write a string to bytecode storage.
* @param _string The string to write to bytecode storage.
* @dev This function emits an event with the address of the newly created
* storage contract.
*/
function writeStringToBytecodeStorage(string memory _string) public {
address storageContract = _string.writeToBytecode();

emit StorageContractCreated(storageContract);
}
}
76 changes: 65 additions & 11 deletions packages/contracts/contracts/generator/GenArt721GeneratorV0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {ABHelpers} from "../libs/v0.8.x/ABHelpers.sol";
import {AddressChunks} from "./AddressChunks.sol";

import "@openzeppelin-4.7/contracts/utils/Strings.sol";
import "@openzeppelin-4.8/contracts-upgradeable/proxy/utils/Initializable.sol";

import {IScriptyBuilderV2, HTMLRequest, HTMLTagType, HTMLTag} from "scripty.sol/contracts/scripty/interfaces/IScriptyBuilderV2.sol";

Expand All @@ -22,13 +23,14 @@ import {IScriptyBuilderV2, HTMLRequest, HTMLTagType, HTMLTag} from "scripty.sol/
* by combining the dependency script, project script, token data. It utilizes
* the ScriptyBuilder contract to generate the HTML.
*/
contract GenArt721GeneratorV0 {
contract GenArt721GeneratorV0 is Initializable {
using Bytes32Strings for bytes32;
using Bytes32Strings for string;
using BytecodeStorageWriter for string;

DependencyRegistryV0 public dependencyRegistry;
IScriptyBuilderV2 public scriptyBuilder;
address public ethFS;
address public gunzipScriptAddress;

function _onlySupportedCoreContract(
address coreContractAddress
Expand All @@ -39,24 +41,74 @@ contract GenArt721GeneratorV0 {
);
}

function _onlyDependencyRegistryAdminACL(bytes4 selector) internal {
require(
dependencyRegistry.adminACLAllowed(
msg.sender,
address(this),
selector
),
"Only DependencyRegistry AdminACL"
);
}

/**
* @notice Constructor for the GenArt721GeneratorV0 contract.
* @notice Initializer for the GenArt721GeneratorV0 contract.
* @param _dependencyRegistry The address of the DependencyRegistry
* contract to be used for retrieving dependency scripts.
* @param _scriptyBuilder The address of the ScriptyBuilderV2 contract
* to be used for generating the HTML for tokens.
* @param _ethFS The address of the EthFSFileStorage contract to retrieve
* the gunzipScripts-0.0.1.js script from used to gunzip the dependency
* scripts.
* @param _gunzipScriptAddress The address of the gunzip script bytecode
* storage contract used to gunzip the dependency scripts in the browser.
*/
constructor(
function initialize(
address _dependencyRegistry,
address _scriptyBuilder,
address _ethFS
) {
address _gunzipScriptAddress
) public initializer {
dependencyRegistry = DependencyRegistryV0(_dependencyRegistry);
scriptyBuilder = IScriptyBuilderV2(_scriptyBuilder);
ethFS = _ethFS;
gunzipScriptAddress = _gunzipScriptAddress;
}

/**
* @notice Set the DependencyRegistry contract address.
* @param _dependencyRegistry The address of the DependencyRegistry
* contract to be used for retrieving dependency scripts.
* @dev This function is gated to only the DependencyRegistry AdminACL.
* If an address is passed that does not implement the adminACLAllowed
* function, we will lose access to the write functions on this contract.
*/
function updateDependencyRegistry(address _dependencyRegistry) external {
_onlyDependencyRegistryAdminACL(this.updateDependencyRegistry.selector);

dependencyRegistry = DependencyRegistryV0(_dependencyRegistry);
}

/**
* @notice Set the ScriptyBuilder contract address.
* @param _scriptyBuilder The address of the ScriptyBuilderV2 contract
* to be used for generating the HTML for tokens.
* @dev This function is gated to only the DependencyRegistry AdminACL.
*/
function updateScriptyBuilder(address _scriptyBuilder) external {
_onlyDependencyRegistryAdminACL(this.updateScriptyBuilder.selector);

scriptyBuilder = IScriptyBuilderV2(_scriptyBuilder);
}

/**
* @notice Set the gunzip script address.
* @param _gunzipScriptAddress The address of the gunzip script bytecode
* storage contract used to gunzip the dependency scripts in the browser.
* @dev This function is gated to only the DependencyRegistry AdminACL.
*/
function updateGunzipScriptAddress(address _gunzipScriptAddress) external {
_onlyDependencyRegistryAdminACL(
this.updateGunzipScriptAddress.selector
);

gunzipScriptAddress = _gunzipScriptAddress;
}

/**
Expand Down Expand Up @@ -325,7 +377,9 @@ contract GenArt721GeneratorV0 {
// so we need to include this so we can gunzip them in the browser.
bodyTags[1].name = "gunzipScripts-0.0.1.js";
bodyTags[1].tagType = HTMLTagType.scriptBase64DataURI; // <script src="data:text/javascript;base64,[script]"></script>
bodyTags[1].contractAddress = ethFS;
bodyTags[1].tagContent = bytes(
BytecodeStorageReader.readFromBytecode(gunzipScriptAddress)
);

bytes memory projectScript = getProjectScriptBytes(
coreContractAddress,
Expand Down

This file was deleted.

Loading

0 comments on commit 52e9ab2

Please sign in to comment.