Skip to content

Commit

Permalink
enforced tx + permalinks + excerpts
Browse files Browse the repository at this point in the history
  • Loading branch information
Turupawn committed Aug 5, 2023
1 parent 91f4032 commit ab8ff65
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ section: developers
date: Last Modified
title: "Bridge an ERC721 NFT through a Custom Gateway"
lang: "en"
permalink: "TODO"
excerpt: "TODO"
permalink: "developers/guides/bridge-an-erc721-nft-through-a-custom-gateway"
excerpt: "Whenever you want to bridge an ERC721 NFT, you may interact with the Gateway and NFT contracts on Sepolia and Scroll testnet. In this guide, we'll cover different ways of doing so."
---

Whenever you want to bridge an ERC721 NFT, you may interact with the Gateway and NFT contracts on Sepolia and Scroll testnet. In this guide, we'll cover different ways of doing so.
Expand All @@ -15,7 +15,7 @@ If you already have an existing token on Sepolia, feel free to skip this step. I

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
Expand All @@ -34,9 +34,9 @@ This step is needed only if you want to launch your own Gateway. Launching your

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity =0.8.16;
import "@scroll-tech/contracts@0.0.10/L1/gateways/L1ERC721Gateway.sol";
import "@scroll-tech/contracts@0.1.0/L1/gateways/L1ERC721Gateway.sol";
contract MyL1ERC721Gateway is L1ERC721Gateway {
function _depositERC721(
Expand All @@ -61,15 +61,15 @@ contract MyL1ERC721Gateway is L1ERC721Gateway {
}
```

## Step 3: Launch the Gateway on Scroll Alpha
## Step 3: Launch the Gateway on Scroll testnet

You can also skip this step if you use the Scroll ERC721 Gateway launched at `TODO: 0x8Fee20e0C0Ef16f2898a8073531a857D11b9C700`. This contract lets you bridge tokens from Scroll testnet back to Sepolia.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity =0.8.16;
import "@scroll-tech/contracts@0.0.10/L2/gateways/L2ERC721Gateway.sol";
import "@scroll-tech/contracts@0.1.0/L2/gateways/L2ERC721Gateway.sol";
contract MyL2ERC721Gateway is L2ERC721Gateway {
function _withdrawERC721(
Expand All @@ -94,16 +94,16 @@ contract MyL2ERC721Gateway is L2ERC721Gateway {
}
```

## Step 4: Launch the custom token on Scroll Alpha
## Step 4: Launch the custom token on Scroll testnet

This contract has to follow the IScrollERC721 standard interface. It has to allow the gateway to mint tokens on deposit and burn on withdrawal. The following example shows a sample implementation by passing as constructor parameters the L2 gateway (either the one you just launched or Scroll's at `TODO: 0x1C441Dfc5C2eD7A2AA8636748A664E59CB029157`) and your token address on Sepolia.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@scroll-tech/contracts@0.0.10/libraries/token/IScrollERC721.sol";
import "@scroll-tech/contracts@0.1.0/libraries/token/IScrollERC721.sol";
contract MockNFT is ERC721, IScrollERC721 {
address GATEWAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ section: developers
date: Last Modified
title: "Bridge ERC1155 through the Custom Gateway"
lang: "en"
permalink: "TODO"
excerpt: "TODO"
permalink: "developers/guides/bridge-erc1155-through-the-custom-gateway"
excerpt: "Whenever you want to bridge an ERC1155 NFT, you may interact with the Gateway and NFT contracts on Sepolia and Scroll testnet. In this guide, we'll cover different approaches to doing so."
---

Whenever you want to bridge an ERC1155 NFT, you may interact with the Gateway and NFT contracts on Sepolia and Scroll testnet. In this guide, we'll cover different approaches to doing so.
Expand All @@ -15,7 +15,7 @@ If you already have an existing token on Sepolia, feel free to skip this step. I

```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
Expand All @@ -32,45 +32,46 @@ contract MockNFT is ERC1155 {

This step is needed only if you want to launch your own Gateway. Launching your own gateway is fully permissionless and also allows you to have custom logic called every time a token is deposited. You can skip this step if you use the Scroll ERC1155 bridge launched at `TODO: TODO: 0xd1bE599aaCBC21448fD6373bbc7c1b4c7806f135`. More information is available [here](https://github.com/scroll-tech/token-list). This contract will allow you to send ERC1155 tokens from Sepolia to Scroll testnet.

<pre class="language-solidity"><code class="lang-solidity"><strong>// SPDX-License-Identifier: MIT
</strong>pragma solidity 0.8.19;
```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "@scroll-tech/contracts@0.0.10/L1/gateways/L1ERC1155Gateway.sol";
import "@scroll-tech/contracts@0.1.0/L1/gateways/L1ERC1155Gateway.sol";
contract MyL1ERC1155Gateway is L1ERC1155Gateway {
function _depositERC1155(
address _token,
address _to,
uint256 _tokenId,
uint256 _amount,
uint256 _gasLimit
) internal override nonReentrant {
super._depositERC1155(_token, _to, _tokenId, _amount, _gasLimit);
/*custom logic goes here*/
}

function _batchDepositERC1155(
address _token,
address _to,
uint256[] calldata _tokenIds,
uint256[] calldata _amounts,
<strong> uint256 _gasLimit
</strong> ) internal override nonReentrant {
super._batchDepositERC1155(_token, _to, _tokenIds, _amounts, _gasLimit);
/*custom logic goes here*/
}
function _depositERC1155(
address _token,
address _to,
uint256 _tokenId,
uint256 _amount,
uint256 _gasLimit
) internal override nonReentrant {
super._depositERC1155(_token, _to, _tokenId, _amount, _gasLimit);
/*custom logic goes here*/
}
function _batchDepositERC1155(
address _token,
address _to,
uint256[] calldata _tokenIds,
uint256[] calldata _amounts,
uint256 _gasLimit
) internal override nonReentrant {
super._batchDepositERC1155(_token, _to, _tokenIds, _amounts, _gasLimit);
/*custom logic goes here*/
}
}
</code></pre>
```

## Step 3: Launch the Gateway on Scroll

This step is needed only if you want to launch your own Gateway. Launching your own gateway is fully permissionless and also allows you to have custom logic called every time a token is deposited. You can skip this step if you use the Scroll ERC1155 bridge launched at `TODO: 0xfe5Fc32777646bD123564C41f711FF708Dd48360`. More information is available [here](https://github.com/scroll-tech/token-list). This contract will allow you to send ERC1155 tokens from Sepolia to Scroll testnet.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity =0.8.16;
import "@scroll-tech/contracts@0.0.10/L2/gateways/L2ERC1155Gateway.sol";
import "@scroll-tech/contracts@0.1.0/L2/gateways/L2ERC1155Gateway.sol";
contract MyL2ERC1155Gateway is L2ERC1155Gateway {
function _withdrawERC1155(
Expand Down Expand Up @@ -103,10 +104,10 @@ This contract has to follow the IScrollERC1155 standard interface. It has to all

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@scroll-tech/contracts@0.0.10/libraries/token/IScrollERC1155.sol";
import "@scroll-tech/contracts@0.1.0/libraries/token/IScrollERC1155.sol";
contract MockNFT is ERC1155, IScrollERC1155 {
address GATEWAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ section: developers
date: Last Modified
title: "Bridge ERC20 through the Custom Gateway"
lang: "en"
permalink: "TODO"
excerpt: "TODO"
permalink: "developers/guides/bridge-erc20-through-the-custom-gateway"
excerpt: "This guide will walk through how to use Scroll's bridge for ERC20s that need custom functionality using the Custom Gateway."
---

This guide will walk through how to use Scroll's bridge for ERC20s that need custom functionality using the Custom Gateway.
Expand All @@ -15,7 +15,7 @@ There is no need for a particular implementation for a token to be compatible wi

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand All @@ -39,10 +39,10 @@ The following is a complete example of a token compatible with the bridge. As th

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@scroll-tech/contracts@0.0.10/libraries/token/IScrollERC20Extension.sol";
import "@scroll-tech/contracts@0.1.0/libraries/token/IScrollERC20Extension.sol";
contract L2Token is ERC20, IScrollERC20Extension {
// We store the gateway and the L1 token address to provide the gateway() and counterpart() functions which are needed from the Scroll Standard ERC20 interface
Expand Down Expand Up @@ -109,9 +109,9 @@ Let’s start by launching the following contract on Sepolia.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity =0.8.16;
import "@scroll-tech/contracts@0.0.10/L1/gateways/L1CustomERC20Gateway.sol";
import "@scroll-tech/contracts@0.1.0/L1/gateways/L1CustomERC20Gateway.sol";
contract MyL1Gateway is L1CustomERC20Gateway {
function _deposit(
Expand All @@ -133,9 +133,9 @@ Now let’s launch the counterpart contract on Scroll testnet.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity =0.8.16;
import "@scroll-tech/contracts@0.0.10/L2/gateways/L2CustomERC20Gateway.sol";
import "@scroll-tech/contracts@0.1.0/L2/gateways/L2CustomERC20Gateway.sol";
contract MyL2Gateway is L2CustomERC20Gateway {
function _withdraw(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ section: developers
date: Last Modified
title: "Estimating Gas and Tx Fees"
lang: "en"
permalink: "TODO"
excerpt: "TODO"
permalink: "developers/guides/"
excerpt: "Since Scroll is an L2 rollup, part of the transaction lifecycle is committing some data to L1 for security. To pay for this, all transaction incurs an additional fee called the L1 fee"
---

import Aside from "../../../../../components/Aside.astro"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ section: developers
date: Last Modified
title: "Greeting Contract with Cross-chain Interaction"
lang: "en"
permalink: "TODO"
excerpt: "TODO"
permalink: "developers/guides/greeting-contract-with-cross-chain-interaction"
excerpt: "In this example, we will launch a dummy smart contract on either Sepolia or Scroll testnet and interact with it from the opposite chain."
---

In this example, we will launch a dummy smart contract on either Sepolia or Scroll testnet and interact with it from the opposite chain. We will be using the `ScrollMessenger` that is deployed on both Sepolia and Scroll testnet.
Expand All @@ -15,7 +15,7 @@ Let’s start by deploying the target smart contract. We will use the Greeter sm

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity ^0.8.16;
// This Greeter contract will be interacted with through the ScrollMessenger across the bridge
contract Greeter {
Expand All @@ -36,11 +36,11 @@ Now switch to the other chain and deploy the `GreeterOperator`. If you deployed

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma solidity ^0.8.16;
// The Scroll Messenger interface is the same on both L1 and L2, it allows sending cross-chain transactions
// Let's import it directly from the Scroll Contracts library
import "@scroll-tech/contracts@0.0.10/libraries/IScrollMessenger.sol";
import "@scroll-tech/contracts@0.1.0/libraries/IScrollMessenger.sol";
// The GreeterOperator is capable of executing the Greeter function through the bridge
contract GreeterOperator {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
section: developers
date: Last Modified
title: "Enforced transactions"
lang: "en"
permalink: "developers/l1-and-l2-bridging/enforced-trnsactions"
excerpt: "The Enforced Transaction contract enables sending transactions between L1 and L2 the sendTransaction function."
---

import Aside from "../../../../../components/Aside.astro"

The Enforced Transaction contract enables sending transactions between L1 and L2 the **`sendTransaction`** function. This contract shares similarities with the Scroll Messenger contract as it allows sending arbitrary data from one layer to the other. However, it distinguishes itself by enabling the relaying of signed transactions and the ability to set the sender (CALLER or msg.sender) on the receiving transaction on Scroll.

## Enforced Transactions API

Please visit the [npm library](https://www.npmjs.com/package/@scroll-tech/contracts?activeTab=code) for the complete Scroll contract API documentation.

### sendTransaction

```solidity
function sendTransaction(address _target, uint256 _value, uint256 _gasLimit, bytes calldata _data) public payable;
```

Add an enforced transaction to L2 from an EOA account sender.

| Parameter | Description |
| ---------- | ---------------------------------------------------------- |
| \_target | The address of target contract to call in L2. |
| \_value | The value passed. |
| \_gasLimit | The maximum gas should be used for this transaction in L2. |
| \_data | The calldata passed to target contract. |

### sendTransaction

```solidity
function sendTransaction(
address _sender,
address _target,
uint256 _value,
uint256 _gasLimit,
bytes calldata _data,
bytes memory _signature,
address _refundAddress
) public payable;
```

Add an enforced transaction to L2 by relaying a signature from the sender.

| Parameter | Description |
| --------------- | --------------------------------------------------------------- |
| \_sender | The address of sender who will initiate this transaction in L2. |
| \_target | The address of target contract to call in L2. |
| \_value | The value passed |
| \_gasLimit | The maximum gas should be used for this transaction in L2. |
| \_data | The calldata passed to target contract. |
| \_signature | The signature for the transaction. |
| \_refundAddress | The address to refund exceeded fee. |
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ section: developers
date: Last Modified
title: "ERC1155 token bridge"
lang: "en"
permalink: "TODO"
excerpt: "TODO"
permalink: "developers/l1-and-l2-bridging/erc1155-token-bridge"
excerpt: "ERC1155 bridging from L1 to L2 is done via the L1ERC1155Gateway."
---

import Aside from "../../../../../components/Aside.astro"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ section: developers
date: Last Modified
title: "ERC721 NFT Bridge"
lang: "en"
permalink: "TODO"
excerpt: "TODO"
permalink: "developers/l1-and-l2-bridging/erc721-nft-bridge"
excerpt: "NFT bridging from L1 to L2 is done via the L1ERC721Gateway contract instead of using a router."
---

import Aside from "../../../../../components/Aside.astro"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ section: developers
date: Last Modified
title: "ETH and ERC20 token bridge"
lang: "en"
permalink: "TODO"
excerpt: "TODO"
permalink: "developers/l1-and-l2-bridging/eth-and-erc20-token-bridge"
excerpt: "The Gateway Router allows ETH and ERC20 token bridging from L1 to L2 using the depositETH and depositERC20 functions respectively."
---

import Aside from "../../../../../components/Aside.astro"
Expand Down
Loading

0 comments on commit ab8ff65

Please sign in to comment.