Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
.PHONY: release-artifacts
.PHONY: rust-bindings

NOOP =
SPACE = $(NOOP) $(NOOP)

PROJECT_NAME := cartesi-rollups-contracts

PROJECT_MAJOR_VERSION := 3
Expand Down Expand Up @@ -129,6 +132,33 @@ MAINNET_CHAIN_IDS += $(OPT_MAINNET_CHAIN_ID)

LIVENET_CHAIN_IDS := $(TESTNET_CHAIN_IDS) $(MAINNET_CHAIN_IDS)

FORGE_BIND_CONTRACTS += IApplication
FORGE_BIND_CONTRACTS += IApplicationFactory
FORGE_BIND_CONTRACTS += IAuthority
FORGE_BIND_CONTRACTS += IAuthorityFactory
FORGE_BIND_CONTRACTS += IConsensus
FORGE_BIND_CONTRACTS += IERC1155BatchPortal
FORGE_BIND_CONTRACTS += IERC1155SinglePortal
FORGE_BIND_CONTRACTS += IERC20Portal
FORGE_BIND_CONTRACTS += IERC721Portal
FORGE_BIND_CONTRACTS += IEtherPortal
FORGE_BIND_CONTRACTS += IInputBox
FORGE_BIND_CONTRACTS += Inputs
FORGE_BIND_CONTRACTS += IOutputsMerkleRootValidator
FORGE_BIND_CONTRACTS += IQuorum
FORGE_BIND_CONTRACTS += IQuorumFactory
FORGE_BIND_CONTRACTS += IRefundOutputBuilder
FORGE_BIND_CONTRACTS += ISafeERC20Transfer
FORGE_BIND_CONTRACTS += ISelfHostedApplicationFactory
FORGE_BIND_CONTRACTS += IUsdWithdrawalOutputBuilder
FORGE_BIND_CONTRACTS += IUsdWithdrawalOutputBuilderFactory
FORGE_BIND_CONTRACTS += IWithdrawalOutputBuilder
FORGE_BIND_CONTRACTS += Outputs
FORGE_BIND_CONTRACTS += TestFungibleToken
FORGE_BIND_CONTRACTS += TestMultiToken
FORGE_BIND_CONTRACTS += TestNonFungibleToken

FORGE_BIND_OPTS += --select "$(subst $(SPACE),|,$(FORGE_BIND_CONTRACTS))"
FORGE_BIND_OPTS += --crate-name "$(PROJECT_NAME)"
FORGE_BIND_OPTS += --crate-version "$(PROJECT_VERSION)"
FORGE_BIND_OPTS += --crate-license "Apache-2.0"
Expand Down
25 changes: 24 additions & 1 deletion script/CodeGeneration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ contract DeployersCodeGenerationScript is CodeGenerationScript {
_addImport("src/portals", "ERC20Portal");
_addImport("src/portals", "ERC721Portal");
_addImport("src/portals", "EtherPortal");
_addImport("src/portals", "IERC1155BatchPortal");
_addImport("src/portals", "IERC1155SinglePortal");
_addImport("src/portals", "IERC20Portal");
_addImport("src/portals", "IERC721Portal");
_addImport("src/portals", "IEtherPortal");
_addImport("src/refund", "IRefundOutputBuilder");
_addImport("src/refund", "RefundOutputBuilder");
_addImport("src/withdrawal", "IUsdWithdrawalOutputBuilder");
_addImport("src/withdrawal", "IUsdWithdrawalOutputBuilderFactory");
_addImport("src/withdrawal", "UsdWithdrawalOutputBuilderFactory");
Expand All @@ -112,7 +119,6 @@ contract DeployersCodeGenerationScript is CodeGenerationScript {

{
string[] memory paramTypes = new string[](0);
_addDeployer("ApplicationFactory", paramTypes);
_addDeployer("AuthorityFactory", paramTypes);
_addDeployer("InputBox", paramTypes);
_addDeployer("QuorumFactory", paramTypes);
Expand All @@ -132,6 +138,23 @@ contract DeployersCodeGenerationScript is CodeGenerationScript {
_addDeployer("EtherPortal", paramTypes);
}

{
string[] memory paramTypes = new string[](6);
paramTypes[0] = "IEtherPortal";
paramTypes[1] = "IERC20Portal";
paramTypes[2] = "IERC721Portal";
paramTypes[3] = "IERC1155SinglePortal";
paramTypes[4] = "IERC1155BatchPortal";
paramTypes[5] = "ISafeERC20Transfer";
_addDeployer("RefundOutputBuilder", paramTypes);
}

{
string[] memory paramTypes = new string[](1);
paramTypes[0] = "IRefundOutputBuilder";
_addDeployer("ApplicationFactory", paramTypes);
}

{
string[] memory paramTypes = new string[](1);
paramTypes[0] = "ISafeERC20Transfer";
Expand Down
66 changes: 50 additions & 16 deletions script/utils/ContractDeployers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ import {ERC1155SinglePortal} from "src/portals/ERC1155SinglePortal.sol";
import {ERC20Portal} from "src/portals/ERC20Portal.sol";
import {ERC721Portal} from "src/portals/ERC721Portal.sol";
import {EtherPortal} from "src/portals/EtherPortal.sol";
import {IERC1155BatchPortal} from "src/portals/IERC1155BatchPortal.sol";
import {IERC1155SinglePortal} from "src/portals/IERC1155SinglePortal.sol";
import {IERC20Portal} from "src/portals/IERC20Portal.sol";
import {IERC721Portal} from "src/portals/IERC721Portal.sol";
import {IEtherPortal} from "src/portals/IEtherPortal.sol";
import {IRefundOutputBuilder} from "src/refund/IRefundOutputBuilder.sol";
import {RefundOutputBuilder} from "src/refund/RefundOutputBuilder.sol";
import {IUsdWithdrawalOutputBuilder} from "src/withdrawal/IUsdWithdrawalOutputBuilder.sol";
import {IUsdWithdrawalOutputBuilderFactory} from "src/withdrawal/IUsdWithdrawalOutputBuilderFactory.sol";
import {UsdWithdrawalOutputBuilderFactory} from "src/withdrawal/UsdWithdrawalOutputBuilderFactory.sol";
Expand All @@ -44,22 +51,6 @@ function computeAddress(bytes32 salt, bytes32 initCodeHash) pure returns (addres
);
}

function deployApplicationFactory() returns (ApplicationFactory deployment) {
bytes32 salt;
bytes memory creationCode = type(ApplicationFactory).creationCode;
bytes memory encodedArgs = abi.encode();
bytes memory initCode = abi.encodePacked(creationCode, encodedArgs);
bytes32 initCodeHash = keccak256(initCode);
address precomputedAddress = computeAddress(salt, initCodeHash);
if (precomputedAddress.code.length == 0) {
deployment = new ApplicationFactory{salt: salt}();
assert(address(deployment) == precomputedAddress);
assert(address(deployment).code.length > 0);
} else {
deployment = ApplicationFactory(precomputedAddress);
}
}

function deployAuthorityFactory() returns (AuthorityFactory deployment) {
bytes32 salt;
bytes memory creationCode = type(AuthorityFactory).creationCode;
Expand Down Expand Up @@ -256,6 +247,49 @@ function deployEtherPortal(IInputBox param1) returns (EtherPortal deployment) {
}
}

function deployRefundOutputBuilder(
IEtherPortal param1,
IERC20Portal param2,
IERC721Portal param3,
IERC1155SinglePortal param4,
IERC1155BatchPortal param5,
ISafeERC20Transfer param6
) returns (RefundOutputBuilder deployment) {
bytes32 salt;
bytes memory creationCode = type(RefundOutputBuilder).creationCode;
bytes memory encodedArgs = abi.encode(param1, param2, param3, param4, param5, param6);
bytes memory initCode = abi.encodePacked(creationCode, encodedArgs);
bytes32 initCodeHash = keccak256(initCode);
address precomputedAddress = computeAddress(salt, initCodeHash);
if (precomputedAddress.code.length == 0) {
deployment = new RefundOutputBuilder{salt: salt}(
param1, param2, param3, param4, param5, param6
);
assert(address(deployment) == precomputedAddress);
assert(address(deployment).code.length > 0);
} else {
deployment = RefundOutputBuilder(precomputedAddress);
}
}

function deployApplicationFactory(IRefundOutputBuilder param1)
returns (ApplicationFactory deployment)
{
bytes32 salt;
bytes memory creationCode = type(ApplicationFactory).creationCode;
bytes memory encodedArgs = abi.encode(param1);
bytes memory initCode = abi.encodePacked(creationCode, encodedArgs);
bytes32 initCodeHash = keccak256(initCode);
address precomputedAddress = computeAddress(salt, initCodeHash);
if (precomputedAddress.code.length == 0) {
deployment = new ApplicationFactory{salt: salt}(param1);
assert(address(deployment) == precomputedAddress);
assert(address(deployment).code.length > 0);
} else {
deployment = ApplicationFactory(precomputedAddress);
}
}

function deployUsdWithdrawalOutputBuilderFactory(ISafeERC20Transfer param1)
returns (UsdWithdrawalOutputBuilderFactory deployment)
{
Expand Down
17 changes: 16 additions & 1 deletion script/utils/CoreContracts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {ERC1155SinglePortal} from "src/portals/ERC1155SinglePortal.sol";
import {ERC20Portal} from "src/portals/ERC20Portal.sol";
import {ERC721Portal} from "src/portals/ERC721Portal.sol";
import {EtherPortal} from "src/portals/EtherPortal.sol";
import {RefundOutputBuilder} from "src/refund/RefundOutputBuilder.sol";
import {UsdWithdrawalOutputBuilderFactory} from "src/withdrawal/UsdWithdrawalOutputBuilderFactory.sol";

import "./ContractDeployers.sol" as G;
Expand All @@ -31,6 +32,7 @@ struct Suite {
EtherPortal etherPortal;
InputBox inputBox;
QuorumFactory quorumFactory;
RefundOutputBuilder refundOutputBuilder;
SafeERC20Transfer safeErc20Transfer;
SelfHostedApplicationFactory selfHostedApplicationFactory;
UsdWithdrawalOutputBuilderFactory usdWithdrawalOutputBuilderFactory;
Expand All @@ -45,7 +47,16 @@ function deploy() returns (Suite memory) {
ERC1155BatchPortal erc1155BatchPortal = G.deployERC1155BatchPortal(inputBox);
SafeERC20Transfer safeErc20Transfer = G.deploySafeERC20Transfer();
AuthorityFactory authorityFactory = G.deployAuthorityFactory();
ApplicationFactory applicationFactory = G.deployApplicationFactory();
RefundOutputBuilder refundOutputBuilder = G.deployRefundOutputBuilder(
etherPortal,
erc20Portal,
erc721Portal,
erc1155SinglePortal,
erc1155BatchPortal,
safeErc20Transfer
);
ApplicationFactory applicationFactory =
G.deployApplicationFactory(refundOutputBuilder);
QuorumFactory quorumFactory = G.deployQuorumFactory();
UsdWithdrawalOutputBuilderFactory usdWithdrawalOutputBuilderFactory =
G.deployUsdWithdrawalOutputBuilderFactory(safeErc20Transfer);
Expand All @@ -62,6 +73,7 @@ function deploy() returns (Suite memory) {
etherPortal: etherPortal,
inputBox: inputBox,
quorumFactory: quorumFactory,
refundOutputBuilder: refundOutputBuilder,
safeErc20Transfer: safeErc20Transfer,
selfHostedApplicationFactory: selfHostedApplicationFactory,
usdWithdrawalOutputBuilderFactory: usdWithdrawalOutputBuilderFactory
Expand All @@ -81,6 +93,9 @@ function store(VmSafe vmSafe, Suite memory s) {
storeDeployment(vmSafe, type(EtherPortal).name, address(s.etherPortal));
storeDeployment(vmSafe, type(QuorumFactory).name, address(s.quorumFactory));
storeDeployment(vmSafe, type(SafeERC20Transfer).name, address(s.safeErc20Transfer));
storeDeployment(
vmSafe, type(RefundOutputBuilder).name, address(s.refundOutputBuilder)
);
storeDeployment(
vmSafe,
type(SelfHostedApplicationFactory).name,
Expand Down
32 changes: 0 additions & 32 deletions src/common/DataAvailability.sol

This file was deleted.

12 changes: 12 additions & 0 deletions src/common/DelegateCallVoucher.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

pragma solidity ^0.8.30;

/// @notice A delegate-call voucher
/// @param destination The destination address
/// @param payload The delegate-call payload
struct DelegateCallVoucher {
address destination;
bytes payload;
}
18 changes: 18 additions & 0 deletions src/common/Erc1155BatchDeposit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

pragma solidity ^0.8.30;

import {IERC1155} from "@openzeppelin-contracts-5.2.0/token/ERC1155/IERC1155.sol";

/// @notice An ERC-1155 single token deposit
/// @param token The token contract
/// @param sender The token sender
/// @param tokenIds The token identifiers
/// @param value The token amounts per token type
struct Erc1155BatchDeposit {
IERC1155 token;
address sender;
uint256[] tokenIds;
uint256[] values;
}
18 changes: 18 additions & 0 deletions src/common/Erc1155SingleDeposit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

pragma solidity ^0.8.30;

import {IERC1155} from "@openzeppelin-contracts-5.2.0/token/ERC1155/IERC1155.sol";

/// @notice An ERC-1155 single token deposit
/// @param token The token contract
/// @param sender The token sender
/// @param tokenId The token identifier
/// @param value The token amount
struct Erc1155SingleDeposit {
IERC1155 token;
address sender;
uint256 tokenId;
uint256 value;
}
16 changes: 16 additions & 0 deletions src/common/Erc20Deposit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

pragma solidity ^0.8.30;

import {IERC20} from "@openzeppelin-contracts-5.2.0/token/ERC20/IERC20.sol";

/// @notice An ERC-20 token deposit
/// @param token The token contract
/// @param sender The token sender
/// @param value The token amount
struct Erc20Deposit {
IERC20 token;
address sender;
uint256 value;
}
16 changes: 16 additions & 0 deletions src/common/Erc721Deposit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

pragma solidity ^0.8.30;

import {IERC721} from "@openzeppelin-contracts-5.2.0/token/ERC721/IERC721.sol";

/// @notice An ERC-721 token deposit
/// @param token The token contract
/// @param sender The token sender
/// @param tokenId The token identifier
struct Erc721Deposit {
IERC721 token;
address sender;
uint256 tokenId;
}
12 changes: 12 additions & 0 deletions src/common/EtherDeposit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

pragma solidity ^0.8.30;

/// @notice An Ether token deposit
/// @param sender The Ether sender
/// @param value The Ether amount (in Wei)
struct EtherDeposit {
address sender;
uint256 value;
}
Loading