1inch 跨链交换
STDIO使用1inch跨链代币交换工具
使用1inch跨链代币交换工具
A tool for executing cross-chain token swaps using 1inch Fusion+ and Model Context Protocol (MCP).
This tool facilitates cross-chain token swaps between different blockchains (Arbitrum, Base, Polygon, etc.) using the 1inch Fusion+ API. It handles the entire swap process, from initiating orders to monitoring their execution status through a background worker system.
Dependencies must be installed using pnpm
or yarn
and not npm
:
pnpm install # or yarn install
The project must be setup as a CommonJS project. The design of the library does not work in its current form if you import it as ESM.
.env
file in the root directory and populate it with the following variables:DEV_PORTAL_KEY=replace_with_developer_portal_api_key
WALLET_ADDRESS=replace_with_wallet_address
WALLET_KEY=replace_with_wallet_private_key
RPC_URL_ETHEREUM=replace_with_ethereum_rpc_url
RPC_URL_BASE=replace_with_base_rpc_url
INCH_API_KEY=replace_with_1inch_api_key
npm start
This starts the Model Context Protocol server which exposes tools for cross-chain swapping and portfolio management.
The tool provides the following MCP functions that can be used with Claude or other MCP-compatible assistants:
Parameters:
- srcChainId: Source chain ID (default: 8453/Base)
- dstChainId: Destination chain ID (default: 42161/Arbitrum)
- srcTokenAddress: Source token address
- dstTokenAddress: Destination token address
- amount: Amount to swap (in base units or human-readable format)
- invert: Swap direction toggle (default: false)
Parameters:
- orderHash: (Optional) Specific order hash to check
portfolio-protocols-value: Gets the value of protocols in your portfolio
Parameters:
- chainId: Blockchain ID (default: 1/Ethereum)
portfolio-tokens-details: Gets detailed information about tokens in your portfolio
Parameters:
- chainId: Blockchain ID (default: 1/Ethereum)
- closed: Include closed positions (default: true)
- closedThreshold: Threshold for considering positions closed (default: 1)
portfolio-general-value: Gets the general value of your portfolio
Parameters:
- chainId: Blockchain ID (default: 1/Ethereum)
portfolio-value-chart: Gets chart data for portfolio value over time
Parameters:
- chainId: Blockchain ID (default: 1/Ethereum)
The application includes a background worker system that monitors and processes swap orders:
# Start the monitor daemon npm run monitor:start # Check status of all orders npm run status # Check status of monitor daemon npm run monitor:status # Stop the monitor daemon npm run monitor:stop
order-status.json