Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core Contract Improvements & Security Enhancements #62

Merged
merged 42 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3b8210c
[feat] added swap and improved execute transfer function
TomasDmArg Jan 6, 2025
dcbad3c
[feat] added modifiers, missing libs, and initial tests/mock contracts
TomasDmArg Jan 6, 2025
fb80d09
fix: factory interface and inheritance conflicts
TomasDmArg Jan 12, 2025
e3b4917
[chore] removed old tests
TomasDmArg Jan 12, 2025
25e1e96
[fix/WIP] resolve multiple contract compilation issues
TomasDmArg Jan 12, 2025
42bf011
[fix/WIP] resolve function mutability and unused parameter warnings
TomasDmArg Jan 12, 2025
f52510a
[test] added detailed logging for test setup debugging
TomasDmArg Jan 12, 2025
ae95695
[fix] update deployment scripts
TomasDmArg Jan 13, 2025
60766b5
[fix] resolve naming conflicts and config access in factory deployment
TomasDmArg Jan 13, 2025
a877378
[fix] initialization, added entrypoint context to tests
TomasDmArg Jan 13, 2025
d8aeeb7
[fix] improve swap router mock and tests passing
TomasDmArg Jan 13, 2025
c0d1e80
[feat] updated deploy script and deployed contracts successfully
TomasDmArg Jan 13, 2025
b7383b7
[docs] translate spanish docs
TomasDmArg Jan 13, 2025
2cd57e6
[chore] removed unnecesary contracts
TomasDmArg Jan 13, 2025
be4314a
test: add arbitrum integration test
TomasDmArg Jan 20, 2025
8114f1b
forge install: forge-std
TomasDmArg Jan 20, 2025
a2f79c1
[feat/WIP] Chatterpay integration test with chainlink price feed and …
TomasDmArg Jan 20, 2025
bbd2a29
[fix] decimal calculations. Integration test passing
TomasDmArg Jan 22, 2025
2aaef7f
[feat] test passing with custom pool and tokens with different decimals
TomasDmArg Jan 22, 2025
20a8539
[refactor] improved code quality, and improved documentation
TomasDmArg Jan 22, 2025
3cc9e2b
[refactor] improved code quality in integration test, and improved do…
TomasDmArg Jan 22, 2025
8b183d0
[refactor] unified test files
TomasDmArg Jan 22, 2025
55b2ba0
[refactor/WIP] increase test coverage, and addded missing contract fu…
TomasDmArg Jan 22, 2025
aabfd82
[test] entrypoint, admin and swap integration test modules working
TomasDmArg Jan 23, 2025
d28baa3
[fix] transfer integration test passing
TomasDmArg Jan 23, 2025
e32c7e6
[feat] improved reentrancy protection and security test passes now
TomasDmArg Jan 23, 2025
ad0c230
[fix] fee calculation issue
TomasDmArg Jan 23, 2025
cb2e16d
[test] simplified test approach with script
TomasDmArg Jan 23, 2025
4140727
[feat] added tolerance to test fee price
TomasDmArg Jan 23, 2025
da8f1c1
[fix] all tests passing
TomasDmArg Jan 23, 2025
fe6b82a
[docs] added test command in readme
TomasDmArg Jan 23, 2025
89e82f5
Merge branch 'develop' into feat/improved-transfer-swap
TomasDmArg Jan 23, 2025
e279d37
[refactor] removed unnecesary files, reorganized folders, updated docs
TomasDmArg Jan 23, 2025
0fe2533
[documentation] checked, updated, and added natspec documentation to …
TomasDmArg Jan 23, 2025
989d120
[feat] added script to generate ABIs
TomasDmArg Jan 23, 2025
0ece269
[ci] :hammer: update how to run tests in github actions
dappsar Jan 24, 2025
0290a2b
[chore] :see_no_evil: ignore forge-cache in gitignore
dappsar Jan 24, 2025
407b4bd
[test] :white_check_mark: update fee tolerante to 1% in swap tests
dappsar Jan 24, 2025
debcdce
merge fix/fix-build into feat/improved-transfer-swap (#64)
dappsar Jan 24, 2025
c02020d
[ci] :recycle: set up cache for fountry en gihub tests
dappsar Jan 24, 2025
502bc42
[ci] :recycle: set up cache for fountry en gihub tests (#65)
dappsar Jan 24, 2025
14e5354
[ci] :fire: remove .forge-cache folder
dappsar Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .doc/technical-overview/contracts-details.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ChatterPay Contracts Details

## 1. [**ChatterPay.sol**](../../src/L2/ChatterPay.sol)
## 1. [**ChatterPay.sol**](../../src/ChatterPay.sol)

### **High-Level Overview**:
The `ChatterPay` contract is the core implementation of an account abstraction-based wallet. It allows users to execute transactions, manage token transfers, and interact with a paymaster for fee management. It includes mechanisms for validating user operations, performing token transfers, and interacting with external price feeds.
Expand All @@ -24,7 +24,7 @@ The `ChatterPay` contract is the core implementation of an account abstraction-b

---

## 2. [**ChatterPayPaymaster.sol**](../../src/L2/ChatterPayPaymaster.sol)
## 2. [**ChatterPayPaymaster.sol**](../../src/ChatterPayPaymaster.sol)

### **High-Level Overview**:
The `ChatterPayPaymaster` contract is responsible for handling the payment of transaction fees on behalf of users. It validates and processes user operations by checking the signature and expiration of paymaster data, ensuring only authorized parties can execute the payment logic.
Expand All @@ -44,7 +44,7 @@ The `ChatterPayPaymaster` contract is responsible for handling the payment of tr

---

## 3. [**ChatterPayNFT.sol**](../../src/L2/ChatterPayNFT.sol)
## 3. [**ChatterPayNFT.sol**](../../src/ChatterPayNFT.sol)

### **High-Level Overview**:
The `ChatterPayNFT` contract allows for the creation and management of NFTs associated with the ChatterPay platform. Users can mint original NFTs and create copies of these NFTs, with the ability to set limits on how many copies can be minted.
Expand All @@ -65,7 +65,7 @@ The `ChatterPayNFT` contract allows for the creation and management of NFTs asso

---

## 4. [**ChatterPayVault.sol**](../../src/L2/ChatterPayNFT.sol)
## 4. [**ChatterPayVault.sol**](../../src/ChatterPayNFT.sol)

### High-Level Summary:
The `ChatterPayNFT` contract is an ERC721-based non-fungible token (NFT) contract that supports minting both original tokens and copies of those tokens. The contract uses upgradeable OpenZeppelin contracts and includes functionality to set a base URI for metadata, mint original tokens, mint copies, and set limits on the number of copies that can be minted. It also restricts certain actions, such as changing copy limits, to the original minter of a token.
Expand Down Expand Up @@ -101,7 +101,7 @@ The `ChatterPayNFT` contract is an ERC721-based non-fungible token (NFT) contrac

---

## 5. [**ChatterPayWalletFactory.sol**](../../src/L2/ChatterPayWalletFactory.sol)
## 5. [**ChatterPayWalletFactory.sol**](../../src/ChatterPayWalletFactory.sol)

### High-Level Summary:
The `ChatterPayWalletFactory` contract is responsible for creating and managing `ChatterPayWalletProxy` instances. It enables the deployment of proxy contracts that are initialized with specific wallet implementations. The contract allows for flexible wallet creation with different owners and manages the proxy contracts. It also supports the updating of wallet implementations and tracks the deployed proxies.
Expand Down Expand Up @@ -136,7 +136,7 @@ The `ChatterPayWalletFactory` contract is responsible for creating and managing

---

## 6. [**ChatterPayWalletProxy.sol**](../../src/L2/ChatterPayWalletProxy.sol)
## 6. [**ChatterPayWalletProxy.sol**](../../src/ChatterPayWalletProxy.sol)

### High-Level Summary:
The `ChatterPayWalletProxy` contract is an upgradeable proxy that delegates calls to a logic contract. It uses the [ERC-1967 proxy pattern](https://docs.openzeppelin.com/contracts/4.x/api/proxy#ERC1967Proxy), which is a widely used standard for creating upgradeable contracts. The proxy allows the logic of the contract to be upgraded without changing the address that users interact with. This contract includes the necessary functionality to receive Ether and to view the current implementation address.
Expand All @@ -162,7 +162,7 @@ The `ChatterPayWalletProxy` contract is an upgradeable proxy that delegates call

---

## 7. [**SimpleSwap.sol**](../../src/L2/SimpleSwap.sol)
## 7. [**SimpleSwap.sol**](../../src/SimpleSwap.sol)

### High-Level Summary:
The `SimpleSwap` contract allows users to swap between WETH (Wrapped Ether) and USDT (Tether USD). It supports liquidity provision where users can add WETH and USDT to the contract's liquidity pool and facilitate swaps between the two tokens. This contract uses the `SafeERC20` library for safe token transfers and includes a reentrancy guard to prevent reentrancy attacks.
Expand Down Expand Up @@ -197,7 +197,7 @@ The `SimpleSwap` contract allows users to swap between WETH (Wrapped Ether) and

---

## 8. [**USDT.sol**](../../src/L2/USDT.sol)
## 8. [**USDT.sol**](../../src/USDT.sol)

### High-Level Summary:
The `USDT` contract is an ERC20 token representing Tether USD (USDT). It allows for the creation of USDT tokens and provides a minting function for the contract owner to generate more tokens. The contract is based on the ERC20 standard, which is widely used for tokenizing assets in decentralized finance (DeFi) applications. The initial supply is set at 10 million USDT tokens.
Expand All @@ -223,7 +223,7 @@ The `USDT` contract is an ERC20 token representing Tether USD (USDT). It allows

---

## 9. [**WETH.sol**](../../src/L2/WETH.sol)
## 9. [**WETH.sol**](../../src/WETH.sol)

### High-Level Summary:
The `WETH` contract is an ERC20 token that represents Wrapped Ether (WETH). Its purpose is to allow users to mint and transfer WETH tokens, which are commonly used in DeFi applications to wrap Ether (ETH) into a token compatible with the ERC20 standard. The contract is based on the ERC20 standard and allows the owner to mint new tokens. The initial supply is fixed at 10 million tokens.
Expand All @@ -249,7 +249,7 @@ The `WETH` contract is an ERC20 token that represents Wrapped Ether (WETH). Its

---

## 10. [**PackedUserOperation.sol**](../../src/L2/utils/PackedUserOperation.sol)
## 10. [**PackedUserOperation.sol**](../../src/utils/PackedUserOperation.sol)

### High-Level Summary:
The `PackedUserOperation` struct is designed to bundle and pack various data points related to a user operation in a blockchain environment. This data is used in transactions or operations that involve smart contracts, particularly in systems such as account abstraction or meta-transactions. The struct captures necessary information such as the sender's address, the operation's nonce, gas limits, call data, and the user's fee preferences.
Expand Down
20 changes: 10 additions & 10 deletions .doc/technical-overview/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ These smart contracts collectively create a robust ecosystem for wallet manageme

## Contracts List:

1. [**ChatterPay.sol**](../../src/L2/ChatterPay.sol)
1. [**ChatterPay.sol**](../../src/ChatterPay.sol)
Core wallet contract for ChatterPay, handling user operations, token transfers, and transaction fee management.

2. [**ChatterPayPaymaster.sol**](../../src/L2/ChatterPayPaymaster.sol)
2. [**ChatterPayPaymaster.sol**](../../src/ChatterPayPaymaster.sol)
Fee manager contract that ensures transaction fees are paid on behalf of users, supporting the account abstraction model of ChatterPay.

3. [**ChatterPayNFT.sol**](../../src/L2/ChatterPayNFT.sol)
3. [**ChatterPayNFT.sol**](../../src/ChatterPayNFT.sol)
Manages the minting of original NFTs and their associated copies, with controls for copy limits and owner management.

4. [**ChatterPayVault.sol**](../../src/L2/ChatterPayNFT.sol)
4. [**ChatterPayVault.sol**](../../src/ChatterPayNFT.sol)
Handles secure storage and management of assets within the ChatterPay ecosystem, providing vault services for users.

5. [**ChatterPayWalletFactory.sol**](../../src/L2/ChatterPayWalletFactory.sol)
5. [**ChatterPayWalletFactory.sol**](../../src/ChatterPayWalletFactory.sol)
A wallet factory contract that creates proxy wallets for users, tracks proxies, and allows for updates to wallet implementations.

6. [**ChatterPayWalletProxy.sol**](../../src/L2/ChatterPayWalletProxy.sol)
6. [**ChatterPayWalletProxy.sol**](../../src/ChatterPayWalletProxy.sol)
A proxy contract for ChatterPay wallets, allowing for upgradeable wallet functionality using [ERC-1967 Proxy](https://docs.openzeppelin.com/contracts/4.x/api/proxy#ERC1967Proxy), and providing a method to retrieve the current wallet implementation.

7. [**SimpleSwap.sol**](../../src/L2/SimpleSwap.sol)
7. [**SimpleSwap.sol**](../../src/SimpleSwap.sol)
Implements a simple token swapping mechanism, allowing users to swap between supported tokens within the ChatterPay ecosystem.

8. [**USDT.sol**](../../src/L2/USDT.sol)
8. [**USDT.sol**](../../src/USDT.sol)
A contract representing the USDT (Tether) token on Layer 2, enabling stablecoin transactions within the ChatterPay platform.

9. [**WETH.sol**](../../src/L2/WETH.sol)
9. [**WETH.sol**](../../src/WETH.sol)
A contract for wrapping and unwrapping ETH as WETH (Wrapped Ether), allowing users to interact with ETH as an ERC-20 token in the ChatterPay ecosystem.

10. [**PackedUserOperation.sol**](../../src/L2/utils/PackedUserOperation.sol)
10. [**PackedUserOperation.sol**](../../src/utils/PackedUserOperation.sol)
Defines the structure for user operations, including details like gas limits, fees, and operation signatures, enabling flexible interaction with the wallet system.

11. [**L1Keystore.sol**](../../src/Ethereum/L1Keystore.sol)
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
BACKEND_EOA: ${{ secrets.BACKEND_EOA }}
BACKEND_PK: ${{ secrets.BACKEND_PK }}
NFT_BASE_URI: https://dev.back.chatterpay.net/nft/metadata/opensea/
FOUNDRY_DISABLE_NIGHTLY_WARNING: 1

jobs:
check:
Expand All @@ -29,6 +30,15 @@ jobs:
with:
submodules: recursive

- name: Set up cache for Foundry
uses: actions/cache@v3
with:
path: |
.forge-cache
lib
key: ${{ runner.os }}-forge-cache-${{ hashFiles('**/*.sol') }}
restore-keys: |

- name: Initialize and update submodules
run: |
git submodule update --init --recursive
Expand All @@ -46,5 +56,5 @@ jobs:

- name: Run Forge tests
run: |
forge test -vvv
yarn test:local
id: test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ node_modules

#lock
package-lock.json

#abis
abi

# cache
.forge-cache
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "lib/account-abstraction"]
path = lib/account-abstraction
url = https://github.com/eth-infinitism/account-abstraction.git
[submodule "lib/solidity-stringutils"]
path = lib/solidity-stringutils
url = https://github.com/Arachnid/solidity-stringutils
36 changes: 32 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
-include .env

deploy_verify_arbitrum_sepolia_all :; forge clean && forge build; forge script script/DeployAllContracts.s.sol --rpc-url $(ARBITRUM_SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --verify --etherscan-api-key $(ARBISCAN_API_KEY) --broadcast
deploy_arbitrum_sepolia_all :; forge clean && forge build; forge script script/DeployAllContracts.s.sol --rpc-url $(ARBITRUM_SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast
deploy_verify_arbitrum_sepolia_only_chatterpay :; forge clean && forge build; forge script script/DeployChatterPay.s.sol --rpc-url $(ARBITRUM_SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --verify --etherscan-api-key $(ARBISCAN_API_KEY) --broadcast
deploy_arbitrum_sepolia_only_chatterpay :; forge clean && forge build; forge script script/DeployChatterPay.s.sol --rpc-url $(ARBITRUM_SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast
# Common build command with local profile to ensure AST generation
BUILD = FOUNDRY_PROFILE=local forge clean && FOUNDRY_PROFILE=local forge build

# Deploy all contracts
deploy_verify_arbitrum_sepolia_all :; $(BUILD) && \
FOUNDRY_PROFILE=local forge script script/DeployAllContracts.s.sol \
--rpc-url $(ARBITRUM_SEPOLIA_RPC_URL) \
--private-key $(PRIVATE_KEY) \
--verify \
--etherscan-api-key $(ARBISCAN_API_KEY) \
--broadcast

deploy_arbitrum_sepolia_all :; $(BUILD) && \
FOUNDRY_PROFILE=local forge script script/DeployAllContracts.s.sol \
--rpc-url $(ARBITRUM_SEPOLIA_RPC_URL) \
--private-key $(PRIVATE_KEY) \
--broadcast

# Deploy only ChatterPay contract
deploy_verify_arbitrum_sepolia_only_chatterpay :; $(BUILD) && \
FOUNDRY_PROFILE=local forge script script/DeployChatterPay.s.sol \
--rpc-url $(ARBITRUM_SEPOLIA_RPC_URL) \
--private-key $(PRIVATE_KEY) \
--verify \
--etherscan-api-key $(ARBISCAN_API_KEY) \
--broadcast

deploy_arbitrum_sepolia_only_chatterpay :; $(BUILD) && \
FOUNDRY_PROFILE=local forge script script/DeployChatterPay.s.sol \
--rpc-url $(ARBITRUM_SEPOLIA_RPC_URL) \
--private-key $(PRIVATE_KEY) \
--broadcast
Loading
Loading