Cross-chain atomic swaps: swap Ethereum/Cosmos assets via 1inch Fusion+, secure & decentralized.
A complete cross-chain atomic swap system implementing 1inch Fusion+ protocol between Ethereum and Cosmos ecosystems.
βββββββββββββββββββ IBC/Cross-Chain βββββββββββββββββββ
β ETHEREUM β βββββββββββββββββββΊ β COSMOS β
β β β β
β βββββββββββββββ β β βββββββββββββββ β
β β 1inch LOP β β β β Cosmos LOP β β
β βββββββββββββββ β β βββββββββββββββ β
β β β β β β
β βΌ β β βΌ β
β βββββββββββββββ β β βββββββββββββββ β
β βEscrowFactoryβ β β βEscrowFactoryβ β
β βββββββββββββββ β β βββββββββββββββ β
β β β β β β
β βΌ β β βΌ β
β βββββββββββββββ β β βββββββββββββββ β
β β Resolver β β β β Resolver β β
β βββββββββββββββ β β βββββββββββββββ β
βββββββββββββββββββ βββββββββββββββββββ
# Install Node.js dependencies
pnpm install
# Install Foundry (for Ethereum contracts)
curl -L https://foundry.paradigm.xyz | bash
# Install Rust (for Cosmos contracts)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
# Install contract dependencies
forge install
# Test the Cosmos CosmWasm contracts
cd cosmos-contracts
cargo test --package escrow-factory --test simple_test
# Expected output:
# β
test_escrow_factory_instantiation ... ok
# β
test_cross_chain_swap_simulation ... ok
# β
test_create_source_escrow ... ok
# β
test_withdraw_from_source ... ok
# test result: ok. 4 passed; 0 failed
cd cosmos-contracts
make build # Build all contracts
make test # Run all tests
make optimize # Optimize for deployment
cross-chain-resolver-example/
βββ cosmos-contracts/ # π Cosmos CosmWasm Contracts
β βββ contracts/
β β βββ escrow-factory/ # Cross-chain escrow management
β β βββ lop/ # 1inch LOP implementation
β β βββ resolver/ # Swap coordination
β βββ tests/ # Comprehensive test suite
β βββ Makefile # Build automation
βββ contracts/ # Ethereum Solidity contracts
β βββ src/
β βββ Resolver.sol # Main resolver contract
β βββ TestEscrowFactory.sol
βββ tests/ # Cross-chain integration tests
βββ 1inch-lop/ # 1inch protocol integration
// User creates order on Ethereum
const order = await createCrossChainOrder({
makerAsset: "ETH",
takerAsset: "ATOM",
makingAmount: "1000000000000000000", // 1 ETH
takingAmount: "100000000" // 100 ATOM
});
// Cosmos contract creates source escrow
execute_create_src_escrow(
immutables,
order_hash,
safety_deposit
) -> IBC message to Ethereum
// Ethereum contract receives IBC message
function deploySrc(immutables, order, signature, amount)
-> Creates destination escrow
// Secret revealed, swap completes atomically
execute_withdraw_from_src(order_hash, secret)
-> Transfers complete on both chains β
running 4 tests
test tests::test_escrow_factory_instantiation ... ok
test tests::test_cross_chain_swap_simulation ... ok
test tests::test_create_source_escrow ... ok
test tests::test_withdraw_from_source ... ok
test result: ok. 4 passed; 0 failed; 0 ignored
cd cosmos-contracts
# Development workflow
make dev # Format, lint, test
make build # Build contracts
make optimize # Optimize for deployment
make deploy-local # Deploy to local chain
# Compile contracts
forge build
# Run cross-chain tests
cargo test --package escrow-factory --test simple_test
# Deploy contracts
forge script script/Deploy.s.sol --broadcast
# Optimize contracts
cd cosmos-contracts && make optimize
# Deploy to testnet
wasmd tx wasm store artifacts/escrow_factory.wasm --from wallet --gas-adjustment 1.3 --gas auto -y
# Instantiate contracts
wasmd tx wasm instantiate $CODE_ID '{"lop_address":"cosmos1lop","ethereum_channel":"channel-0"}' --from wallet --label "escrow-factory" -y
# Deploy with Foundry
forge script script/Deploy.s.sol --rpc-url $ETH_RPC_URL --broadcast --verify
import { EthereumCosmosIntegration } from './cosmos-contracts/tests/ethereum-cosmos-integration';
const integration = new EthereumCosmosIntegration(
'http://localhost:26657', // Cosmos RPC
cosmosWallet,
'http://localhost:8545', // Ethereum RPC
ethereumPrivateKey,
contractAddresses
);
// Execute cross-chain swap
await integration.executeEthereumToCosmosSwap(
'cosmos1maker',
'0xTakerAddress',
'1000000000000000000', // 1 ETH
'100000000' // 100 ATOM
);
use escrow_factory::contract::{execute, EscrowImmutables};
// Create cross-chain escrow
let immutables = EscrowImmutables {
order_hash: "unique_order_id".to_string(),
maker: "cosmos1maker".to_string(),
taker: "cosmos1taker".to_string(),
amount: Uint128::new(1000000),
token: "uatom".to_string(),
// ... other fields
};
execute(deps, env, info, ExecuteMsg::CreateSrcEscrow { immutables, order_hash })?;
| Network | RPC URL | Chain ID | |-----------|--------------------------------------|----------| | Ethereum | https://eth.merkle.io | 1 | | Cosmos | https://rpc.cosmos.network | cosmoshub-4 |
| Role | Address | Private Key | |----------|----------------------------------------------|-------------| | Owner | 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 | 0xac0974... | | User | 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 | 0x59c6995... | | Resolver | 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC | 0x5de4111... |
WARNING: These contracts are in development and have not been audited. Do not use in production.
Built with β€οΈ for the cross-chain future π
βββββββββββββββββββ IBC/Cross-Chain βββββββββββββββββββ
β ETHEREUM β βββββββββββββββββββΊ β COSMOS β
β β β β
β βββββββββββββββ β β βββββββββββββββ β
β β 1inch LOP β β β β Cosmos LOP β β
β βββββββββββββββ β β βββββββββββββββ β
β β β β β β
β βΌ β β βΌ β
β βββββββββββββββ β β βββββββββββββββ β
β βEscrowFactoryβ β β βEscrowFactoryβ β
β βββββββββββββββ β β βββββββββββββββ β
β β β β β β
β βΌ β β βΌ β
β βββββββββββββββ β β βββββββββββββββ β
β β Resolver β β β β Resolver β β
β βββββββββββββββ β β βββββββββββββββ β
βββββββββββββββββββ βββββββββββββββββββ
# Install Node.js dependencies
pnpm install
# Install Foundry (for Ethereum contracts)
curl -L https://foundry.paradigm.xyz | bash
# Install Rust (for Cosmos contracts)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
# Install contract dependencies
forge install
# Test the Cosmos CosmWasm contracts
cd cosmos-contracts
cargo test --package escrow-factory --test simple_test
# Expected output:
# β
test_escrow_factory_instantiation ... ok
# β
test_cross_chain_swap_simulation ... ok
# β
test_create_source_escrow ... ok
# β
test_withdraw_from_source ... ok
# test result: ok. 4 passed; 0 failed
cd cosmos-contracts
make build # Build all contracts
make test # Run all tests
make optimize # Optimize for deployment