A template project for building and deploying custom swap strategies using 1inch's SwapVM and Aqua protocol.
This project provides a complete implementation of:
- AquaAMM: A concentrated liquidity AMM strategy for SwapVM
- MockTaker: A test contract for simulating swap operations
- Deployment scripts: Automated deployment and verification
- Test suite: Comprehensive tests for swap functionality
- Node.js v18+ (Note: Node.js v23 may show warnings but works)
- Yarn
- Git
- Clone the repository:
git clone https://github.com/1inch/swap-vm-template.git
cd swap-vm-template- Install dependencies:
yarn- Copy environment variables:
cp .env.example .env- Configure your
.envfile:
PRIVATE_KEY=your_private_key_here
SEPOLIA_RPC_URL=your_sepolia_rpc_url
ETHERSCAN_API_KEY=your_etherscan_api_key
Compile the smart contracts:
npx hardhat compileRun the test suite:
npx hardhat testDeploy to local Hardhat network:
yarn deploy hardhatDeploy to Sepolia testnet:
yarn deploy sepoliaThe deployment script will:
- Deploy Aqua protocol
- Deploy AquaAMM strategy
- Deploy AquaSwapVMRouter
- Deploy MockTaker (optional, for testing)
- Verify all contracts on Etherscan (for non-local networks)
const order = await aquaAMM.buildProgram(
makerAddress, // Liquidity provider
token0Address, // First token address
token1Address, // Second token address
feeBpsIn, // Trading fee in basis points
delta0, // Concentration parameter for token0
delta1, // Concentration parameter for token1
decayPeriod, // Price decay period
protocolFeeBpsIn, // Protocol fee in basis points
feeReceiverAddress, // Fee receiver address
salt // Unique order identifier
);// Build taker traits
const takerData = TakerTraitsLib.build({
taker: takerAddress,
isExactIn: true,
threshold: minOutputAmount,
useTransferFromAndAquaPush: true
});
// Execute swap
await swapVM.swap(
order,
tokenIn,
tokenOut,
amountIn,
takerData
);swap-vm-template/
├── contracts/ # Smart contracts
│ ├── AquaAMM.sol # AMM strategy implementation
│ ├── MockTaker.sol # Test resolver contract
│ └── SwapVMImport.sol # SwapVM imports
├── deploy/ # Deployment scripts
├── test/ # Test suite
│ ├── AquaAMM.test.ts # Main test file
│ └── utils/ # Test utilities
├── typechain-types/ # Generated TypeScript types
└── hardhat.config.ts # Hardhat configuration
To create your own swap strategy:
- Create a new contract inheriting from SwapVM opcodes
- Implement your swap logic using the VM instruction set
- Build program bytecode using the ProgramBuilder
- Deploy and register with Aqua
- Write unit tests for your strategy logic
- Test with both resolver contracts and EOAs
- Verify gas consumption and optimization
- Test edge cases and error conditions
This software is provided "as is", without warranty of any kind. Use at your own risk.
This project is licensed under the LicenseRef-Degensoft-SwapVM-1.1
See the LICENSE file for details. See the THIRD_PARTY_NOTICES file for information about third-party software, libraries, and dependencies used in this project.
Contact for licensing inquiries: