Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions .env.empty

This file was deleted.

42 changes: 42 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Deployer (DO NOT COMMIT REAL KEYS)
DEPLOYER_PRIVATE_KEY=0x...

# CREATE2 Salt (32 bytes, mined for desired vanity address)
ETOMIC_SWAP_V1_CREATE2_SALT=0x...

# ============ RPC URLs ============
# Testnets
SEPOLIA_RPC_URL=
BSC_TESTNET_RPC_URL=
POLYGON_MUMBAI_RPC_URL=
AVALANCHE_TESTNET_RPC_URL=
FANTOM_TESTNET_RPC_URL=

# Mainnets
MAINNET_RPC_URL=
BSC_RPC_URL=
POLYGON_RPC_URL=
AVALANCHE_RPC_URL=
ARBITRUM_RPC_URL=
BASE_RPC_URL=
KCC_RPC_URL=
MOONRIVER_RPC_URL=
MOONBEAM_RPC_URL=
FANTOM_RPC_URL=
HARMONY_RPC_URL=
ETC_RPC_URL=
RSK_RPC_URL=
EWC_RPC_URL=
SMARTBCH_RPC_URL=
UBIQ_RPC_URL=
QTUM_RPC_URL=

# ============ BLOCK EXPLORER API KEYS ============
ETHERSCAN_API_KEY=
BSCSCAN_API_KEY=
POLYGONSCAN_API_KEY=
SNOWTRACE_API_KEY=
ARBISCAN_API_KEY=
BASESCAN_API_KEY=
MOONSCAN_API_KEY=
FTMSCAN_API_KEY=
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ typings/
.env

.idea
merge
merge

artifacts
cache

ignition/deployments/
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ services:
- docker

before_install:
- cp .env.empty .env
- docker-compose build
- docker-compose up -d

script:
- docker-compose exec workspace yarn
- docker-compose exec workspace truffle test
- docker-compose exec workspace npx hardhat test
- docker-compose down
94 changes: 94 additions & 0 deletions DEPLOYMENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# EtomicSwap V1 (SafeERC20) Deployments

## Deployed Address (all chains)

```
0x61EEC68Cf64d1b31e41EA713356De2563fB6D3F1
```

Same address on every EVM chain via deterministic CREATE2 deployment.

## Live Deployments

| Chain | Chain ID | TX Hash | Explorer |
|-------|----------|---------|----------|
| Ethereum | 1 | `0xd78d0b7138fb1657da3d61e4db664d08b85fbcbb92ebf457cc8e3fa1f4d45a5c` | [etherscan.io](https://etherscan.io/address/0x61EEC68Cf64d1b31e41EA713356De2563fB6D3F1#code) |
| Sepolia (testnet) | 11155111 | `0x0ce7879bdb6546e1a806bab1a8c09f990622bab69ae252cb79c5a04418a4150b` | [sepolia.etherscan.io](https://sepolia.etherscan.io/address/0x61EEC68Cf64d1b31e41EA713356De2563fB6D3F1#code) |

## Deployment Steps

The contract is deployed using [Hardhat Ignition](https://hardhat.org/ignition) with the CREATE2 strategy, which uses the [CreateX](https://github.com/pcaversaccio/createx) factory (`0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed`) to produce deterministic addresses across chains.

### Prerequisites

1. Copy `.env.example` to `.env` and fill in:
- `DEPLOYER_PRIVATE_KEY` — the deployer wallet (`0x936c269a7378Ac408EF6EAB5770d29EA8EC6ecDd`)
- `ETOMIC_SWAP_V1_CREATE2_SALT` — the mined salt (see below)
- `ETHERSCAN_API_KEY` — for contract verification
- The RPC URL env var for the target chain (e.g., `BSC_RPC_URL`)

2. Fund the deployer address with native gas on the target chain (~1.2M gas needed).

3. Install dependencies:
```bash
yarn install
```

### Deploy to a new chain

```bash
npx hardhat ignition deploy ignition/modules/EtomicSwapV1.js --network <network-name> --strategy create2
```

Where `<network-name>` matches a key in `hardhat.config.js` `networks` (e.g., `bsc`, `polygon`, `avalanche`).

### Verify contract source

```bash
npx hardhat verify --network <network-name> 0x61EEC68Cf64d1b31e41EA713356De2563fB6D3F1
```

For chains using Etherscan V2, the single `ETHERSCAN_API_KEY` works. For chains with custom explorers (KCC, EWC), see `customChains` in `hardhat.config.js`.

### Adding a new chain

1. Add the network to `hardhat.config.js`:
```js
newchain: networkConfig(<chainId>, "NEWCHAIN_RPC_URL"),
```
2. Add the RPC URL to `.env`
3. Verify that [CreateX is deployed](https://github.com/pcaversaccio/createx#deployments) on the target chain
4. Deploy and verify using the commands above
5. Update this file with the TX hash and explorer link

## Pending Deployments

| Chain | Chain ID | Network Name | RPC Env Var |
|-------|----------|--------------|-------------|
| BSC | 56 | `bsc` | `BSC_RPC_URL` |
| Polygon | 137 | `polygon` | `POLYGON_RPC_URL` |
| Avalanche | 43114 | `avalanche` | `AVALANCHE_RPC_URL` |
| Arbitrum One | 42161 | `arbitrumOne` | `ARBITRUM_RPC_URL` |
| Base | 8453 | `base` | `BASE_RPC_URL` |
| Fantom | 250 | `opera` | `FANTOM_RPC_URL` |
| Moonriver | 1285 | `moonriver` | `MOONRIVER_RPC_URL` |
| Moonbeam | 1284 | `moonbeam` | `MOONBEAM_RPC_URL` |
| KCC | 321 | `kcc` | `KCC_RPC_URL` |
| Harmony | 1666600000 | `harmony` | `HARMONY_RPC_URL` |
| ETC | 61 | `etc` | `ETC_RPC_URL` |
| RSK | 30 | `rsk` | `RSK_RPC_URL` |
| EWC | 246 | `ewc` | `EWC_RPC_URL` |
| SmartBCH | 10000 | `smartbch` | `SMARTBCH_RPC_URL` |
| Ubiq | 8 | `ubiq` | `UBIQ_RPC_URL` |
| Qtum | 3888 | `qtum` | `QTUM_RPC_URL` |

## Background

- **Contract**: `EtomicSwap.sol` with OpenZeppelin SafeERC20 (enables USDT and other non-standard ERC20 tokens)
- **Deployer**: `0x936c269a7378Ac408EF6EAB5770d29EA8EC6ecDd`
- **CreateX Factory**: [`0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed`](https://github.com/pcaversaccio/createx)
- **Salt**: `0x936c269a7378ac408ef6eab5770d29ea8ec6ecdd0050a3d70fd56cd902144e36`
- Bytes 0-19: deployer address (permissioned salt)
- Byte 20: `0x00` (cross-chain mode — same address on all chains)
- Bytes 21-31: mined entropy via [createXcrunch](https://github.com/pcaversaccio/createx-crunch)
- **Previous V1 Contract** (no SafeERC20): `0x24ABE4c71FC658C91313b6552cd40cD808b3Ea80`
41 changes: 31 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Etomic Swap Smart Contracts for BarterDex platform.
# Etomic Swap Smart Contracts for Komodo SDK.
[![Build Status](https://travis-ci.org/artemii235/etomic-swap.svg?branch=master)](https://travis-ci.org/artemii235/etomic-swap)
Etomic swap Smart Contract is implemented to support ETH and ERC20 atomic swaps on BarterDex platform.
Etomic swap Smart Contract is implemented to support ETH and ERC20 atomic swaps on Komodo SDK.
Please note that this project is not production ready yet!

## Swap workflow
Expand All @@ -21,19 +21,40 @@ Despite example shows swap of ETH/ERC20 this approach will work also for ETH/ERC

## How to setup dev environment?

**Note:**
This setup supports both Docker Compose V1 (using `docker-compose` commands) and Docker Compose V2 (using `docker compose` commands).
Docker Compose V2 is preferable, as [from July 2023 Compose V1 stopped receiving updates](https://docs.docker.com/compose/).

1. Install docker.
1. Run `docker-compose build`.
1. `cp .env.empty .env`.
1. Start containers `docker-compose up -d`.
1. Install project dependencies: `docker-compose exec workspace yarn`.
1. To run tests: `docker-compose exec workspace truffle test`.
1. Run `docker compose build`.
1. Start containers `docker compose up -d`.
1. Install project dependencies: `docker compose exec workspace yarn`.
1. To run tests: `docker compose exec workspace npx hardhat test`.
1. To clean artifacts and cache: `docker compose exec workspace npx hardhat clean`.
1. Stop containers `docker compose down`.

## Related links

1. Komodo platform - https://www.komodoplatform.com

## Useful links for smart contracts development

1. Truffle suite - https://github.com/trufflesuite/truffle
1. Ganache-cli (EthereumJS Testrpc) - https://github.com/trufflesuite/ganache-cli
1. Zeppelin Solidity - https://github.com/OpenZeppelin/zeppelin-solidity
1. **Hardhat:** An Ethereum development environment. It facilitates building, testing, and deploying smart contracts. - https://hardhat.org
1. **Ethers.js:** A complete Ethereum library and wallet implementation in JavaScript. - https://github.com/ethers-io/ethers.js
1. **OpenZeppelin Contracts:** A library for secure smart contract development. It provides reusable contracts which are secure and tested. - https://github.com/OpenZeppelin/openzeppelin-contracts

## Contribution Guide

- Run Docker tests to ensure that the project is set up successfully.
- Write tests for new contracts and functionalities.
- Run tests to confirm that new implementations work correctly.
- Format Solidity code before opening a pull request (PR). For formatting, you can use Remix Online IDE - https://remix.ethereum.org/

## Where Can I Write Solidity Code?

### Notes for Those Without an IDE:
Using Remix Online IDE is sufficient. There's no need to install anything locally.

### Notes for JetBrains or Visual Studio Code (VSCode) Users:
- These IDEs offer Solidity and HardHat plugins, which can simplify your workflow. However, Remix Online IDE is also a viable option.
- To index JavaScript code, execute the Docker commands as mentioned. Necessary dependencies will be downloaded, enabling the IDE to index the rest of the code.
12 changes: 12 additions & 0 deletions contracts/Erc1155Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.30;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

contract Erc1155Token is ERC1155 {
constructor(string memory tokenUri) ERC1155(tokenUri) {
uint256 tokenId = 1;
uint256 amount = 3;
_mint(msg.sender, tokenId, amount, "");
}
}
13 changes: 13 additions & 0 deletions contracts/Erc721Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.30;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract Erc721Token is ERC721 {
constructor(string memory tokenName, string memory tokenSymbol)
ERC721(tokenName, tokenSymbol)
{
uint256 tokenId = 1;
_mint(msg.sender, tokenId);
}
}
Loading