Skip to content

Commit c27d712

Browse files
Merge pull request #71 from OpenZeppelin/chore/update-openzeppelin-contracts-api
chore: updated api references and examples
2 parents 268e968 + 4b2c697 commit c27d712

27 files changed

Lines changed: 6516 additions & 3070 deletions

content/contracts/5.x/api/access.mdx

Lines changed: 22 additions & 22 deletions
Large diffs are not rendered by default.

content/contracts/5.x/api/account.mdx

Lines changed: 82 additions & 54 deletions
Large diffs are not rendered by default.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
title: "Crosschain"
3+
description: "Smart contract crosschain utilities and implementations"
4+
---
5+
6+
This directory contains contracts for sending and receiving cross chain messages that follows the ERC-7786 standard.
7+
8+
* [`ERC7786Recipient`](#ERC7786Recipient): generic ERC-7786 crosschain contract that receives messages from a trusted gateway
9+
10+
## Helpers
11+
12+
[`ERC7786Recipient`](#ERC7786Recipient)
13+
14+
<a id="ERC7786Recipient"></a>
15+
16+
<div style={{marginTop: "4em"}} className="w-full flex flex-row items-center justify-between">
17+
18+
## `ERC7786Recipient`
19+
20+
<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.5.0/contracts/crosschain/ERC7786Recipient.sol">
21+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github-icon lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>
22+
</a>
23+
24+
</div>
25+
26+
```solidity
27+
import "@openzeppelin/contracts/crosschain/ERC7786Recipient.sol";
28+
```
29+
30+
Base implementation of an ERC-7786 compliant cross-chain message receiver.
31+
32+
This abstract contract exposes the `receiveMessage` function that is used for communication with (one or multiple)
33+
destination gateways. This contract leaves two functions unimplemented:
34+
35+
* [`ERC7786Recipient._isAuthorizedGateway`](#ERC7786Recipient-_isAuthorizedGateway-address-bytes-), an internal getter used to verify whether an address is recognised by the contract as a
36+
valid ERC-7786 destination gateway. One or multiple gateway can be supported. Note that any malicious address for
37+
which this function returns true would be able to impersonate any account on any other chain sending any message.
38+
39+
* [`ERC7786Recipient._processMessage`](#ERC7786Recipient-_processMessage-address-bytes32-bytes-bytes-), the internal function that will be called with any message that has been validated.
40+
41+
This contract implements replay protection, meaning that if two messages are received from the same gateway with the
42+
same `receiveId`, then the second one will NOT be executed, regardless of the result of [`ERC7786Recipient._isAuthorizedGateway`](#ERC7786Recipient-_isAuthorizedGateway-address-bytes-).
43+
44+
<div className="bg-secondary p-4 rounded-md mb-6">
45+
<h3 style={{ marginTop: "0"}}>Functions</h3>
46+
<div className="font-mono">
47+
- [receiveMessage(receiveId, sender, payload)](#ERC7786Recipient-receiveMessage-bytes32-bytes-bytes-)
48+
- [_isAuthorizedGateway(gateway, sender)](#ERC7786Recipient-_isAuthorizedGateway-address-bytes-)
49+
- [_processMessage(gateway, receiveId, sender, payload)](#ERC7786Recipient-_processMessage-address-bytes32-bytes-bytes-)
50+
#### IERC7786Recipient [!toc]
51+
</div>
52+
</div>
53+
54+
<div className="bg-secondary p-4 rounded-md mb-6">
55+
<h3 style={{ marginTop: "0"}}>Errors</h3>
56+
<div className="font-mono">
57+
- [ERC7786RecipientUnauthorizedGateway(gateway, sender)](#ERC7786Recipient-ERC7786RecipientUnauthorizedGateway-address-bytes-)
58+
- [ERC7786RecipientMessageAlreadyProcessed(gateway, receiveId)](#ERC7786Recipient-ERC7786RecipientMessageAlreadyProcessed-address-bytes32-)
59+
#### IERC7786Recipient [!toc]
60+
</div>
61+
</div>
62+
63+
<a id="ERC7786Recipient-receiveMessage-bytes32-bytes-bytes-"></a>
64+
65+
<div className="border rounded-md mb-4">
66+
<div className="bg-secondary flex w-full justify-between px-4">
67+
<p className="font-bold text-sm font-mono">receiveMessage(bytes32 receiveId, bytes sender, bytes payload) → bytes4</p>
68+
<div className="flex flex-row items-center gap-2">
69+
<p className="font-light text-sm">external</p>
70+
<a className="peer" data-card href="ERC7786Recipient-receiveMessage-bytes32-bytes-bytes-">#</a>
71+
</div>
72+
</div>
73+
<div className="px-4">
74+
75+
Endpoint for receiving cross-chain message.
76+
77+
This function may be called directly by the gateway.
78+
79+
</div>
80+
</div>
81+
82+
<a id="ERC7786Recipient-_isAuthorizedGateway-address-bytes-"></a>
83+
84+
<div className="border rounded-md mb-4">
85+
<div className="bg-secondary flex w-full justify-between px-4">
86+
<p className="font-bold text-sm font-mono">_isAuthorizedGateway(address gateway, bytes sender) → bool</p>
87+
<div className="flex flex-row items-center gap-2">
88+
<p className="font-light text-sm">internal</p>
89+
<a className="peer" data-card href="ERC7786Recipient-_isAuthorizedGateway-address-bytes-">#</a>
90+
</div>
91+
</div>
92+
<div className="px-4">
93+
94+
Virtual getter that returns whether an address is a valid ERC-7786 gateway for a given sender.
95+
96+
The `sender` parameter is an interoperable address that include the source chain. The chain part can be
97+
extracted using the [`InteroperableAddress`](/contracts/5.x/api/utils#InteroperableAddress) library to selectively authorize gateways based on the origin chain
98+
of a message.
99+
100+
</div>
101+
</div>
102+
103+
<a id="ERC7786Recipient-_processMessage-address-bytes32-bytes-bytes-"></a>
104+
105+
<div className="border rounded-md mb-4">
106+
<div className="bg-secondary flex w-full justify-between px-4">
107+
<p className="font-bold text-sm font-mono">_processMessage(address gateway, bytes32 receiveId, bytes sender, bytes payload)</p>
108+
<div className="flex flex-row items-center gap-2">
109+
<p className="font-light text-sm">internal</p>
110+
<a className="peer" data-card href="ERC7786Recipient-_processMessage-address-bytes32-bytes-bytes-">#</a>
111+
</div>
112+
</div>
113+
<div className="px-4">
114+
115+
Virtual function that should contain the logic to execute when a cross-chain message is received.
116+
117+
</div>
118+
</div>
119+
120+
<a id="ERC7786Recipient-ERC7786RecipientUnauthorizedGateway-address-bytes-"></a>
121+
122+
<div className="border rounded-md mb-4">
123+
<div className="bg-secondary flex w-full justify-between px-4">
124+
<p className="font-bold text-sm font-mono">ERC7786RecipientUnauthorizedGateway(address gateway, bytes sender)</p>
125+
<div className="flex flex-row items-center gap-2">
126+
<p className="font-light text-sm">error</p>
127+
<a className="peer" data-card href="ERC7786Recipient-ERC7786RecipientUnauthorizedGateway-address-bytes-">#</a>
128+
</div>
129+
</div>
130+
<div className="px-4">
131+
132+
</div>
133+
</div>
134+
135+
<a id="ERC7786Recipient-ERC7786RecipientMessageAlreadyProcessed-address-bytes32-"></a>
136+
137+
<div className="border rounded-md mb-4">
138+
<div className="bg-secondary flex w-full justify-between px-4">
139+
<p className="font-bold text-sm font-mono">ERC7786RecipientMessageAlreadyProcessed(address gateway, bytes32 receiveId)</p>
140+
<div className="flex flex-row items-center gap-2">
141+
<p className="font-light text-sm">error</p>
142+
<a className="peer" data-card href="ERC7786Recipient-ERC7786RecipientMessageAlreadyProcessed-address-bytes32-">#</a>
143+
</div>
144+
</div>
145+
<div className="px-4">
146+
147+
</div>
148+
</div>

content/contracts/5.x/api/finance.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This directory includes primitives for financial systems:
1919

2020
## `VestingWallet`
2121

22-
<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.4.0/contracts/finance/VestingWallet.sol">
22+
<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.5.0/contracts/finance/VestingWallet.sol">
2323
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github-icon lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>
2424
</a>
2525

@@ -40,7 +40,7 @@ By setting the duration to 0, one can configure this contract to behave like an
4040
a beneficiary until a specified time.
4141

4242
<Callout>
43-
Since the wallet is [`Ownable`](./access#Ownable), and ownership can be transferred, it is possible to sell unvested tokens.
43+
Since the wallet is [`Ownable`](/contracts/5.x/api/access#Ownable), and ownership can be transferred, it is possible to sell unvested tokens.
4444
Preventing this in a smart contract is difficult, considering that: 1) a beneficiary address could be a
4545
counterfactually deployed contract, 2) there is likely to be a migration path for EOAs to become contracts in the
4646
near future.
@@ -253,7 +253,7 @@ Getter for the amount of releasable eth.
253253
<div className="px-4">
254254

255255
Getter for the amount of releasable `token` tokens. `token` should be the address of an
256-
[`IERC20`](./token/ERC20#IERC20) contract.
256+
[`IERC20`](/contracts/5.x/api/token/ERC20#IERC20) contract.
257257

258258
</div>
259259
</div>
@@ -270,7 +270,7 @@ Getter for the amount of releasable `token` tokens. `token` should be the addres
270270
</div>
271271
<div className="px-4">
272272

273-
Release the native token (ether) that have already vested.
273+
Release the native tokens (ether) that have already vested.
274274

275275
Emits a [`VestingWallet.EtherReleased`](#VestingWallet-EtherReleased-uint256-) event.
276276

@@ -385,7 +385,7 @@ an asset given its total historical allocation.
385385

386386
## `VestingWalletCliff`
387387

388-
<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.4.0/contracts/finance/VestingWalletCliff.sol">
388+
<a target="_blank" style={{marginTop: "1.5em"}} href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.5.0/contracts/finance/VestingWalletCliff.sol">
389389
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github-icon lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>
390390
</a>
391391

0 commit comments

Comments
 (0)