Skip to content

Commit

Permalink
Merge pull request #156 from G7DAO/feat/SUM-910-citizen-wallet
Browse files Browse the repository at this point in the history
Feat/sum 910 AA citizen wallet + Forwarder contract
  • Loading branch information
ogarciarevett authored Oct 7, 2024
2 parents e7a9b7b + c7abd6b commit 4ec77f2
Show file tree
Hide file tree
Showing 100 changed files with 1,682 additions and 1,078 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# TESTNET - MAINNET
#PRIVATE_KEY="0xYourKey"


# DEV - ZKSYNC - LOCAL
PRIVATE_KEY="0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"

POLYGON_PROVIDER_URL="https://endpoints.omniatech.io/v1/matic/mumbai/public"
POLYGONSCAN_API_KEY="YOUR_API_KEY"
ARBISCAN_API_KEY="YOUR_API_KEY"
Expand Down
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
browser: true,
es6: true,
node: true,
mocha: true,
},
extends: [
'plugin:import/errors',
Expand All @@ -39,7 +40,10 @@ module.exports = {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
'unused-imports/no-unused-imports-ts': 'warn',
'unused-imports/no-unused-vars-ts': ['error', { vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_' }],
'unused-imports/no-unused-vars-ts': [
'error',
{ vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_' },
],
'@typescript-eslint/no-use-before-define': ['error'],
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18.18.0

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 8
Expand All @@ -32,7 +32,7 @@ jobs:
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
44 changes: 12 additions & 32 deletions README.md
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.
13 changes: 12 additions & 1 deletion constants/constructor-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,18 @@ export const MiddlewareNativeTokenStakerArgs = {
admin: 'DEPLOYER_WALLET',
},
TESTNET: {
stakerContract: '0xa6B0461b7E54Fa342Be6320D4938295A81f82Cd3',
stakerContract: '0xE7e669769Bb409b31540ff5dB6F15af3307928b1',
admin: 'DEPLOYER_WALLET',
},
};

export const ForwarderArgs = {
MAINNET: {
parentWallet: 'DEPLOYER_WALLET',
admin: 'DEPLOYER_WALLET',
},
TESTNET: {
parentWallet: 'DEPLOYER_WALLET',
admin: 'DEPLOYER_WALLET',
},
};
Expand Down
3 changes: 3 additions & 0 deletions constants/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum CONTRACT_TYPE {
EnglishAuctionsExtension = 'EnglishAuctionsExtension',
OffersExtension = 'OffersExtension',
DirectListingsAddonExtension = 'DirectListingsAddonExtension',
Forwarder = 'Forwarder',
}

export enum PROXY_CONTRACT_TYPE {
Expand Down Expand Up @@ -60,6 +61,7 @@ export enum CONTRACT_FILE_NAME {
OffersExtension = 'OffersLogic',
DirectListingsAddonExtension = 'DirectListingsAddon',
Martins = 'Martins',
Forwarder = 'Forwarder',
}

export enum CONTRACT_UPGRADABLE_FILE_NAME {
Expand Down Expand Up @@ -106,6 +108,7 @@ export enum CONTRACT_NAME {
DirectListingsAddonExtension = 'DirectListingsAddonExtension',
Staker = 'Staker',
MiddlewareStaker = 'MiddlewareStakerG7',
Forwarder = 'Forwarder',
}

export enum CONTRACT_UPGRADABLE_NAME {
Expand Down
14 changes: 14 additions & 0 deletions constants/deployments/deployments-g7-testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AvatarBoundArgs,
AvatarBoundV1Args,
ERC20Args,
ForwarderArgs,
ItemBoundArgs,
LevelsBoundArgs,
LevelsBoundV1Args,
Expand Down Expand Up @@ -224,4 +225,17 @@ export const G7_TESTNET_CONTRACTS: DeploymentContract[] = [
functionCalls: [],
args: MiddlewareNativeTokenStakerArgs.TESTNET,
},
{
contractFileName: CONTRACT_FILE_NAME.Forwarder,
type: CONTRACT_TYPE.Forwarder,
name: CONTRACT_NAME.Forwarder,
chain,
networkType,
tenants: [TENANT.Game7],
verify: true,
upgradable: false,
dependencies: [],
functionCalls: [],
args: ForwarderArgs.TESTNET,
},
];
42 changes: 22 additions & 20 deletions contracts/Tokens/Martins.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
// SPDX-License-Identifier: UNLICENSED
///@notice This contract is for mock for WETH token.
pragma solidity ^0.8.17;

/**
* Author: Achievo Team - (https://achievo.xyz/)
*/

// MMMMNkc. .,oKWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
// MWXd,. .cONMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
// Wx' .cKMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
// x. ;KMMMMMMMMMMMMWKxlcclxKWMMMMMMMMWKxlc::::::::ckWMMXd:cOMMMMMMMMKo:oKMMWkccxWMWKdccccccccccccoKMM0l:l0MMMMMMMMMWkc:dXMMMXkoc::::::clxKW
// ' lNMMMMMMMMMMNd. .. .dNMMMMMMNd. ..........oWMM0' oWMMMMMMMk. .kMMN: :XMNl .''''''''';OMMX: ,0MMMMMMMWk. oNMWk' ........ .o
// . :XMMMMMMMMMWd. .o00l. .dWMMMMWx. .o0KKXKKXXXXNMMM0' oNWWWWWWWk. .kMMN: :NMNc .kNNNNNNNNNNWMMM0, :XMMMMMM0, cXMMO. c0KKKKXK0o.
// , .lkxo. ;dkx, oWMMMMMMMMWk. oNMMNo. .kWMMMWl ;KMMMMMMMMMMMMMM0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M
pragma solidity ^0.8.24;



// @author Summon.xyz Team - https://summon.xyz
// @contributors: [ @ogarciarevett, @vasinl124]
//....................................................................................................................................................
//....................&&&&&&..........................................................................................................................
//..................&&&&&&&&&&&.......................................................................................................................
//..............X.....&&&&&&&&&&&&....................................................................................................................
//............&&&&&&.....&&&&&&&&&&&..................................................................................................................
//............&&&&&&&&&.....&&&&&.....................................................................................................................
//............&&&&&&&&&&&&.........&.............&&&&&&&&&&&&..&&&&....&&&&.&&&&&&&&..&&&&&&&.&&&&&&&&..&&&&&&&&.&&&&&&&&&&&&.&&&&&....&&&&...........
//...............&&&&&&&&&&&&.....&&$............&&&&..........&&&&....&&&&.&&&&&&&&.&&&&&&&&..&&&&&&&&.&&&&&&&&.&&&&&&&&&&&&.&&&&&&&..&&&&...........
//............&.....&&&&&&&&&&&&..................&&&&&&&&&&&..&&&&....&&&&.&&&&..&&&&&&.&&&&..&&&&.&&&&&&..&&&&.&&&&....&&&&.&&&&.&&&&&&&&...........
//............&&.......&&&&&&&&&&&&......................&&&&..&&&&&&&&&&&&.&&&&..&&&&&..&&&&..&&&&..&&&&...&&&&.&&&&&&&&&&&&.&&&&...&&&&&&...........
//................&&&.....&&&&&&&&&&+............&&&&&&&&&&&&...&&&&&&&&&&..&&&&...&&&&..&&&&.&&&&&..&&&&...&&&&.&&&&&&&&&&&&.&&&&....&&&&&...........
//.............&&&&&&&&&.....&&&&&&&..................................................................................................................
//.............&&&&&&&&&&&&.....&&&...................................................................................................................
//.................&&&&&&&&&&&........................................................................................................................
//....................&&&&&&&.........................................................................................................................
//....................................................................................................................................................

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
Expand Down
140 changes: 140 additions & 0 deletions contracts/accounts/Forwarder.sol
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);
}
}
Loading

0 comments on commit 4ec77f2

Please sign in to comment.