https://github.com/ubisoft/authenticated-relay
Solidity smart contract that verifies an authorization signature before forwarding the call to the destination contract. Can be used for backend-gated minting.
https://github.com/ubisoft/authenticated-relay
Last synced: 11 months ago
JSON representation
Solidity smart contract that verifies an authorization signature before forwarding the call to the destination contract. Can be used for backend-gated minting.
- Host: GitHub
- URL: https://github.com/ubisoft/authenticated-relay
- Owner: ubisoft
- Created: 2024-09-09T16:44:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-09T16:44:58.000Z (over 1 year ago)
- Last Synced: 2025-04-09T19:21:55.579Z (about 1 year ago)
- Language: Solidity
- Size: 13.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Authenticated relay
Solidity smart contract that verifies an authorisation signature before forwarding the call to the destination contract. Can be used for backend-gated minting.
## Overview
The relay is deployed on-chain and is configured with an `operator` role (`OPERATOR_ROLE`)
The backend signs an EIP-712 message of the following structure with an owner key:
```solidity
struct RelayData {
bytes32 nonce;
address to;
uint256 validityStart;
uint256 validityEnd;
uint256 chainId;
bytes callData;
}
```
Where `to` is the destination contract, `callData` is the ABI-encoded calldata. The relay verifies that the recovered signature matches an owner role and executes the call on the destination contract.
The `operator` address can be updated by the `admin` (`DEFAULT_ADMIN_ROLE`)
## Usage
This example uses a test agains [Sequence's ERC721 contract library](https://github.com/0xsequence/contracts-library/blob/master/src/tokens/ERC721/presets/items/ERC721Items.sol).
See `test/AuthenticatedRelay.t.sol` for details.
### Requirements
- Foundry: https://book.getfoundry.sh/
### Build
```shell
forge install
# build sequence contracts dependencies:
pushd lib/contracts-library
yarn && yarn build
popd
forge build
```
### Test
```shell
forge test
```
### Example: mint an ERC721
Set the environment variables:
- `RELAY_CONTRACT`: The authenticated relay address
- `OPERATOR_PRIVATE_KEY`: The operator private key
- `ERC721_CONTRACT`: The ERC721 contract address. It has a `mint(address,uint256)` function that can only be called by the authenticated relay
- `RECIPIENT`: The NFT recipient
- `SENDER_PRIVATE_KEY`: The key of the wallet that will broadcast the transaction
- `NONCE`: A nonce to prevent replays
Then run the script:
```bash
forge script script/MinterWithRelay.s.sol:MintWithRelay --broadcast --private-key $SENDER_PRIVATE_KEY
```