This project implements an order-based token swap system using Solidity smart contracts. It allows users to deposit various ERC-20 tokens, create swap orders and fulfill orders created by other users.
- Deposit and withdraw various ERC-20 tokens
- Create swap orders specifying the token to sell and the token to buy
- Fulfill orders created by other users
- Cancel active orders
- Gas-efficient operations
- Comprehensive test suite including fuzz testing
- Solidity ^0.8.24
- Hardhat
- Ethers.js v6
- OpenZeppelin Contracts
- Chai (for testing)
.
├── contracts/
│ ├── OrderBasedSwap.sol
│ └── DoomEternalToken.sol
├── scripts/
│ ├── deploy.js
│ └── interact.js
├── test/
│ └── OrderBasedSwap.js
├── hardhat.config.js
└── README.md
-
Clone the repository:
git clone https://github.com/DonGuillotine/order_based_swap_contract.git cd order_based_swap_contract
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory and add your environment variables:ETHERSCAN_API_KEY=your_etherscan_api_key ALCHEMY_API_KEY=your_alchemy_api_key PRIVATE_KEY=your_wallet_private_key
npx hardhat compile
npx hardhat test
To deploy to a local Hardhat network:
npx hardhat run scripts/deploy.js
To deploy to a specific network (e.g., lisk-sepolia testnet):
npx hardhat run scripts/deploy.js --network lisk-sepolia
The smart contracts are deployed on the Lisk Sepolia Testnet. You can interact with the deployed contracts via a front-end or using Hardhat.
- ERC20 Token Address:
- OrderBasedSwap Contract Address: https://sepolia-blockscout.lisk.com/address/0x05dbB7372f939c3CFFa4EABD31662B031202b38C?tab=write_contract
npx hardhat run scripts/interact.js --network lisk-sepolia
After deploying to a public network, verify your contract on Etherscan:
npx hardhat verify --network lisk-sepolia DEPLOYED_CONTRACT_ADDRESS
For DoomEternalToken
contracts:
npx hardhat verify --network lisk-sepolia DUMMY_TOKEN_ADDRESS "Token Name" "TKN" "1000000000000000000000000"
This is the main contract that handles the order-based swap functionality. It allows users to:
- Deposit and withdraw ERC-20 tokens
- Create swap orders
- Fulfill existing orders
- Cancel their own orders
A simple ERC-20 token implementation used for testing purposes. It allows:
- Minting tokens (restricted to the contract owner)
- Standard ERC-20 functionalities (transfer, approve, etc.)
The project includes a comprehensive test suite that covers:
- Basic functionalities (deposit, withdraw, create order, fulfill order, cancel order)
- Edge cases and error conditions
- Gas usage reporting
Run the tests using:
npx hardhat test
- The contract uses OpenZeppelin's
SafeERC20
to handle token transfers safely. ReentrancyGuard
is implemented to prevent reentrancy attacks.- Access control is in place to ensure only authorized actions are performed.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
This project is for educational purposes only. It has not been audited and should not be used in production without a thorough security review.