-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from G7DAO/feat/SUM-910-citizen-wallet
Feat/sum 910 AA citizen wallet + Forwarder contract
- Loading branch information
Showing
100 changed files
with
1,682 additions
and
1,078 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,31 @@ | ||
<p align="center"> | ||
<br /> | ||
<a href="https://achievo.xyz"><img src="https://docs.achievo.xyz/assets/images/achievo_hero-c6f48974170f838b624d0b30ef52735f.png" width="200" alt=""/></a> | ||
<a href="https://achievo.xyz"><img src="https://summon.xyz/hero.png" width="200" alt=""/></a> | ||
<br /> | ||
</p> | ||
<h1 align="center">Achievo Contracts</h1> | ||
<h1 align="center">Summon Contracts</h1> | ||
<p align="center"> | ||
<a href="https://github.com/G7DAO/achievo-contracts/actions"><img alt="Build Status" src="https://github.com/G7DAO/achievo-contracts/actions/workflows/ci.yml/badge.svg"/></a> | ||
<a href="https://github.com/G7DAO/achievo-contracts/actions"><img alt="Build Status" src="https://github.com/G7DAO/summon-contracts/actions/workflows/ci.yml/badge.svg"/></a> | ||
|
||
</p> | ||
<br /> | ||
|
||
## Requirements | ||
|
||
1. NodeJs >= 18 (use nvm pls) | ||
1. NodeJs >= 21.13.1 (use nvm pls) | ||
2. Fill the .env file with the correct values(see .env.example) | ||
3. Install dependencies | ||
|
||
```shell | ||
pnpm install | ||
``` | ||
|
||
## Scripts | ||
|
||
```json | ||
{ | ||
"deploy:create2": "pnpm compile && hardhat --config hardhat.config.ts deploy-create2", | ||
"deploy:nonce": "pnpm compile && hardhat --config hardhat.config.ts deploy-nonce", | ||
"deploy:proxy": "pnpm compile && hardhat --config hardhat.config.ts deploy-proxy", | ||
"deploy:sepolia": "pnpm compile && hardhat --config hardhat.config.ts deploy --network sepolia", | ||
"deploy:arbitrum:one": "pnpm compile && hardhat --config arbitrum.config.ts deploy --network arbitrumOne", | ||
"deploy:arbitrum:sepolia": "pnpm compile && hardhat --config arbitrum.config.ts deploy --network arbitrumSepolia", | ||
"deploy:base:mainnet": "pnpm compile && hardhat --config base.config.ts deploy --network base", | ||
"deploy:base:sepolia": "pnpm compile && hardhat --config base.config.ts deploy --network baseSepolia", | ||
"deploy:mantle:mainnet": "pnpm compile && hardhat --config mantle.config.ts deploy --network mantle", | ||
"deploy:mantle:sepolia": "pnpm compile && hardhat --config mantle.config.ts deploy --network mantleSepolia", | ||
"deploy:polygon:mainnet": "pnpm compile && hardhat --config polygon.config.ts deploy --network polygon", | ||
"deploy:polygon:mumbai": "pnpm compile && hardhat --config polygon.config.ts deploy --network polygonMumbai", | ||
"deploy:g7:testnet": "pnpm compile && hardhat --config g7.config.ts deploy --network game7Testnet", | ||
"test:foundry": "forge test -vvv", | ||
"test": "REPORT_GAS=true hardhat --config hardhat.config.ts test test/hardhatTests/*.ts --network hardhat", | ||
"test:ci": "hardhat --config hardhat.config.ts test test/hardhatTests/*.ts --network hardhat", | ||
"lint": "eslint --config ./.eslintrc.js --ignore-path ./.eslintignore ./test/**/*.ts", | ||
"solhint": "solhint ./contracts/**/*.sol", | ||
"format": "yarn prettier -w ./deploy/**/*.ts ./tasks/**/*.ts ./tests/**/*.ts ./helpers/**/*.ts contracts/**/*.sol ", | ||
"format:check": "yarn prettier -c ./deploy/**/*.ts ./tasks/**/*.ts ./tests/**/*.ts ./helpers/**/*.ts ./contracts/**/*.sol ", | ||
"coverage": "TS_NODE_TRANSPILE_ONLY=true SOLIDITY_COVERAGE=true hardhat coverage --solcoverjs .solcover.ts", | ||
"coverage:foundry": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage", | ||
"generate:types": "pnpm dlx hardhat typechain" | ||
} | ||
## Deployments | ||
|
||
How to deploy a specific contract using the hardhat tasks of this repo: | ||
|
||
```shell | ||
pnpm deploy:g7:testnet --name Forwarder | ||
``` | ||
|
||
You need to provide the **name** argument with the contract name you want to deploy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol"; | ||
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; | ||
import { Pausable } from "@openzeppelin/contracts/utils/Pausable.sol"; | ||
|
||
// @author Summon.xyz Team - https://summon.xyz | ||
// @contributors: [@ogarciarevett] | ||
//.................................................................................................................................................... | ||
//....................&&&&&&.......................................................................................................................... | ||
//..................&&&&&&&&&&&....................................................................................................................... | ||
//..............X.....&&&&&&&&&&&&.................................................................................................................... | ||
//............&&&&&&.....&&&&&&&&&&&.................................................................................................................. | ||
//............&&&&&&&&&.....&&&&&..................................................................................................................... | ||
//............&&&&&&&&&&&&.........&.............&&&&&&&&&&&&..&&&&....&&&&.&&&&&&&&..&&&&&&&.&&&&&&&&..&&&&&&&&.&&&&&&&&&&&&.&&&&&....&&&&........... | ||
//...............&&&&&&&&&&&&.....&&$............&&&&..........&&&&....&&&&.&&&&&&&&.&&&&&&&&..&&&&&&&&.&&&&&&&&.&&&&&&&&&&&&.&&&&&&&..&&&&........... | ||
//............&.....&&&&&&&&&&&&..................&&&&&&&&&&&..&&&&....&&&&.&&&&..&&&&&&.&&&&..&&&&.&&&&&&..&&&&.&&&&....&&&&.&&&&.&&&&&&&&........... | ||
//............&&.......&&&&&&&&&&&&......................&&&&..&&&&&&&&&&&&.&&&&..&&&&&..&&&&..&&&&..&&&&...&&&&.&&&&&&&&&&&&.&&&&...&&&&&&........... | ||
//................&&&.....&&&&&&&&&&+............&&&&&&&&&&&&...&&&&&&&&&&..&&&&...&&&&..&&&&.&&&&&..&&&&...&&&&.&&&&&&&&&&&&.&&&&....&&&&&........... | ||
//.............&&&&&&&&&.....&&&&&&&.................................................................................................................. | ||
//.............&&&&&&&&&&&&.....&&&................................................................................................................... | ||
//.................&&&&&&&&&&&........................................................................................................................ | ||
//....................&&&&&&&......................................................................................................................... | ||
//.................................................................................................................................................... | ||
|
||
|
||
/// @title Forwarder | ||
/// @notice This contract handles deposits of native tokens, forwarding deposits to a parent address | ||
contract Forwarder is | ||
AccessControl, | ||
Pausable, | ||
ReentrancyGuard | ||
{ | ||
/*////////////////////////////////////////////////////////////// | ||
STATE-VARS | ||
//////////////////////////////////////////////////////////////*/ | ||
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); | ||
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); | ||
address public parentAddress; | ||
uint256 public minDeposit = 0.00001 ether; | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
EVENTS | ||
//////////////////////////////////////////////////////////////*/ | ||
event ForwarderDeposited(address indexed user, address indexed payer, uint256 value, address indexed parentAddress); | ||
event ParentAddressUpdated(address newParentAddress); | ||
event MinDepositUpdated(uint256 newMinDeposit); | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
MODIFIERS | ||
//////////////////////////////////////////////////////////////*/ | ||
modifier validDeposit() { | ||
if(msg.value < minDeposit) revert InvalidAmount(); | ||
_; | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
ERRORS | ||
//////////////////////////////////////////////////////////////*/ | ||
error ForwardFailed(); | ||
error InvalidParentAddress(); | ||
error InsufficientBalance(); | ||
error InvalidAmount(); | ||
error InvalidMinDeposit(); | ||
|
||
/// @notice Constructs the Forwarder contract | ||
/// @param _parentAddress The address to which deposits will be forwarded | ||
/// @param _admin The address that will be granted admin roles | ||
constructor(address _parentAddress, address _admin) { | ||
if (_parentAddress == address(0)) revert InvalidParentAddress(); | ||
parentAddress = _parentAddress; | ||
|
||
_grantRole(DEFAULT_ADMIN_ROLE, _admin); | ||
_grantRole(ADMIN_ROLE, _admin); | ||
_grantRole(PAUSER_ROLE, _admin); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
EXTERNAL FUNCTIONS | ||
//////////////////////////////////////////////////////////////*/ | ||
/// @notice Allows a user to withdraw their balance | ||
function deposit() external payable nonReentrant whenNotPaused validDeposit { | ||
_handleDeposit(msg.sender, msg.value); | ||
} | ||
|
||
/// @notice Allows a user to withdraw their balance | ||
/// @param user The address of the user that will receive the deposit | ||
function depositTo(address user) external payable nonReentrant whenNotPaused validDeposit { | ||
_handleDeposit(user, msg.value); | ||
} | ||
|
||
/// @notice Updates the parent address to which deposits are forwarded | ||
/// @param newParentAddress The new parent address | ||
function updateParentAddress(address newParentAddress) external onlyRole(ADMIN_ROLE) { | ||
if (newParentAddress == address(0)) revert InvalidParentAddress(); | ||
parentAddress = newParentAddress; | ||
emit ParentAddressUpdated(newParentAddress); | ||
} | ||
|
||
/// @notice Updates the minimum deposit amount | ||
/// @param newMinDeposit The new minimum deposit amount | ||
function updateMinDeposit(uint256 newMinDeposit) external onlyRole(ADMIN_ROLE) { | ||
if (newMinDeposit == 0) revert InvalidMinDeposit(); | ||
minDeposit = newMinDeposit; | ||
emit MinDepositUpdated(newMinDeposit); | ||
} | ||
|
||
/// @notice Pauses the contract | ||
function pause() external onlyRole(PAUSER_ROLE) { | ||
_pause(); | ||
} | ||
|
||
/// @notice Unpauses the contract | ||
function unpause() external onlyRole(PAUSER_ROLE) { | ||
_unpause(); | ||
} | ||
|
||
/// @notice Handles incoming native token transfers | ||
receive() external payable whenNotPaused validDeposit { | ||
_handleDeposit(msg.sender, msg.value); | ||
} | ||
|
||
/// @notice Allows deposits on behalf of a specified user | ||
fallback() external payable whenNotPaused validDeposit { | ||
_handleDeposit(msg.sender, msg.value); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
INTERNAL FUNCTIONS | ||
//////////////////////////////////////////////////////////////*/ | ||
/// @notice Handles deposits, updating balances and forwarding funds | ||
/// @param user that will receive the deposit | ||
/// @param amount The amount of native tokens being deposited | ||
function _handleDeposit(address user, uint256 amount) internal { | ||
(bool success, ) = parentAddress.call{value: amount}(""); | ||
if (!success) revert ForwardFailed(); | ||
emit ForwarderDeposited(user, msg.sender, amount, parentAddress); | ||
} | ||
} |
Oops, something went wrong.