@1inch/aqua-sdk

中文文档
0.4.0发布于 2026/11/05LicenseRef-Degensoft-Aqua-Source-1.1TypeScriptESM + CJS构建来源已验证近 30 天下载 3881

1inch Aqua Protocol SDK

原始使用文档
文档目录22 节
  1. Overview
  2. Installation
  3. Quick Start
  4. Core Operations
  5. Ship
  6. Dock
  7. Event Parsing
  8. Pushed Event
  9. Pulled Event
  10. Shipped Event
  11. Docked Event
  12. Utility Functions
  13. Calculate Strategy Hash
  14. Encode Call Data
  15. Supported Networks
  16. API Reference
  17. Exports
  18. Real-Life Examples
  19. Example 1: Ship Liquidity to XYCSwap.sol aqua app
  20. Example 2: Execute a Swap through XYCSwap.sol aqua app
  21. Example 3: Dock Liquidity
  22. License

@1inch/aqua-sdk - TypeScript SDK for 1inch Aqua Protocol

A TypeScript SDK for encoding, decoding, and interacting with the 1inch Aqua Protocol smart contract. This SDK provides utilities for building transactions and parsing events for the Aqua Protocol's core operations.

Overview

The Aqua Protocol is a decentralized protocol for liquidity management. This SDK simplifies integration by providing:

  • Encoding/Decoding: Build typed call data for ship, dock operations
  • Event Parsing: Decode and parse Pushed, Pulled, Shipped, and Docked events
  • Multi-Chain Support: Pre-configured addresses for 10+ blockchain networks

For detailed protocol documentation, see the Aqua Protocol Documentation.

Installation

pnpm add @1inch/aqua-sdk

Quick Start

import {
  AquaProtocolContract,
  AQUA_CONTRACT_ADDRESSES,
  Address,
  HexString,
  NetworkEnum
} from '@1inch/aqua-sdk'

// Initialize the contract
const contractAddress = AQUA_CONTRACT_ADDRESSES[NetworkEnum.ETHEREUM]
const aqua = new AquaProtocolContract(contractAddress)

// Build a ship transaction
const shipTx = aqua.ship({
  app: new Address('0x...'),
  strategy: new HexString('0x...'),
  amountsAndTokens: [
    {
      token: new Address('0x...'),
      amount: 1000000000000000000n, // 1 token with 18 decimals
    },
  ],
})

// Use the transaction data
console.log(shipTx) // { to: '0x...', data: '0x...', value: 0n }

Core Operations

Ship

Initiates a liquidity strategy by setting virtual token balances for it.

const shipTx = aqua.ship({
  app: new Address('0x...'),
  strategy: new HexString('0x...'),
  amountsAndTokens: [
    {
      token: new Address('0x...'),
      amount: 1000000000000000000n,
    },
  ],
})

Parameters:

  • app - Address of the application contract
  • strategy - Strategy bytes containing execution logic
  • amountsAndTokens - Array of token addresses and amounts to ship

Returns: CallInfo object with encoded transaction data

Dock

Completes a liquidity strategy by removing virtual token balances from it.

const strategyHash = AquaProtocolContract.calculateStrategyHash(strategy)

const dockTx = aqua.dock({
  app: new Address('0x...'),
  strategyHash: strategyHash,
  tokens: [
    new Address('0x...'),
    new Address('0x...'),
  ],
})

Parameters:

  • app - Address of the application contract
  • strategyHash - Keccak256 hash of the strategy bytes
  • tokens - Array of all token addresses of the strategy, whose virtual balances are set to zero

Returns: CallInfo object with encoded transaction data

Event Parsing

Pushed Event

Emitted when funds are pushed to a strategy/wallet.

import { PushedEvent } from '@1inch/aqua-sdk'

const log = { data: '0x...', topics: ['0x...'] }
const event = PushedEvent.fromLog(log)

console.log(event.maker)        // Address
console.log(event.app)          // Address
console.log(event.strategyHash) // HexString
console.log(event.token)        // Address
console.log(event.amount)       // bigint

Pulled Event

Emitted when funds are pulled from a strategy/wallet.

import { PulledEvent } from '@1inch/aqua-sdk'

const event = PulledEvent.fromLog(log)

Shipped Event

Emitted when a liquidity strategy is initiated.

import { ShippedEvent } from '@1inch/aqua-sdk'

const event = ShippedEvent.fromLog(log)

Docked Event

Emitted when a liquidity strategy is closed.

import { DockedEvent } from '@1inch/aqua-sdk'

const event = DockedEvent.fromLog(log)

Utility Functions

Calculate Strategy Hash

Convert strategy bytes to their keccak256 hash.

import { AquaProtocolContract } from '@1inch/aqua-sdk'
import { HexString } from '@1inch/sdk-core'

const strategy = new HexString('0x...')
const hash = AquaProtocolContract.calculateStrategyHash(strategy)

Encode Call Data

Manually encode function call data if needed.

import { AquaProtocolContract } from '@1inch/aqua-sdk'

const encodedShip = AquaProtocolContract.encodeShipCallData({
  app: new Address('0x...'),
  strategy: new HexString('0x...'),
  amountsAndTokens: [ /* ... */ ],
})

const encodedDock = AquaProtocolContract.encodeDockCallData({
  app: new Address('0x...'),
  strategyHash: new HexString('0x...'),
  tokens: [ /* ... */ ],
})

Supported Networks

The SDK includes pre-configured contract addresses for the following networks:

NetworkChain IDAddress
Ethereum10x1111113ccf1426a8e30e2bff5e005d929bf6a90a
BNB Chain560x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Polygon1370x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Arbitrum421610x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Avalanche431140x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Gnosis1000x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Coinbase Base84530x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Optimism100x1111113ccf1426a8e30e2bff5e005d929bf6a90a
zkSync Era3240x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Linea591440x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Unichain1300x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Sonic1460x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Robinhood Chain46630x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Monad1430x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Cronos250x1111113ccf1426a8e30e2bff5e005d929bf6a90a
HyperEVM9990x1111113ccf1426a8e30e2bff5e005d929bf6a90a
Arc50420x1111113ccf1426a8e30e2bff5e005d929bf6a90a

Access addresses using:

import { AQUA_CONTRACT_ADDRESSES } from '@1inch/aqua-sdk'
import { NetworkEnum } from '@1inch/sdk-core'

const ethereumAddress = AQUA_CONTRACT_ADDRESSES[NetworkEnum.ETHEREUM]
const arbitrumAddress = AQUA_CONTRACT_ADDRESSES[NetworkEnum.ARBITRUM]

API Reference

Exports

The SDK exports:

Real-Life Examples

Example 1: Ship Liquidity to XYCSwap.sol aqua app

Initialize a liquidity strategy by setting its virtual balances in Aqua. ship does not transfer tokens: they stay in the maker's wallet and Aqua pulls them with transferFrom when swaps execute, so the maker must hold the tokens and approve the Aqua contract to spend each of them.

import { AquaProtocolContract, Address, HexString, AQUA_CONTRACT_ADDRESSES, NetworkEnum } from '@1inch/aqua-sdk'
import { encodeAbiParameters, parseUnits, http, createWalletClient, isHex, erc20Abi, maxUint256 } from 'viem'
import { privateKeyToAccount, privateKeyToAddress } from 'viem/accounts'
import { mainnet } from 'viem/chains'
import assert from 'assert'
import 'dotenv/config'

const makerPrivateKey = process.env.MAKER_PRIVATE_KEY

assert(isHex(makerPrivateKey))
const maker = privateKeyToAddress(makerPrivateKey)
const app = '0xTODO_REPLACE'
const WETH = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const USDC = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'

// Define strategy based on the smart contract app structure. Each Aqua app can have it's own strategy schema
const strategyData = {
  maker,
  token0: WETH,
  token1: USDC,
  feeBps: 0n,
  salt: '0x0000000000000000000000000000000000000000000000000000000000000001'
} as const

// Encode strategy as bytes
const strategy = encodeAbiParameters(
  [
    {
      name: 'strategy',
      type: 'tuple',
      components: [
        { name: 'maker', type: 'address' },
        { name: 'token0', type: 'address' },
        { name: 'token1', type: 'address' },
        { name: 'feeBps', type: 'uint256' },
        { name: 'salt', type: 'bytes32' }
      ]
    }
  ],
  [strategyData]
)

console.log('Encoded strategy:', strategy)

// Initialize Aqua contract
const aqua = new AquaProtocolContract(AQUA_CONTRACT_ADDRESSES[NetworkEnum.ETHEREUM])

// Create ship transaction
const shipTx = aqua.ship({
  app: new Address(app),
  strategy: new HexString(strategy),
  amountsAndTokens: [
    {
      token: new Address(USDC),
      amount: parseUnits('4000', 6)
    },
    {
      token: new Address(WETH),
      amount: parseUnits('1', 18)
    }
  ]
})

const wallet = createWalletClient({
  chain: mainnet,
  transport: http(),
  account: privateKeyToAccount(makerPrivateKey)
})

// Aqua pulls the tokens from the maker's wallet when swaps execute, so it needs an allowance
for (const token of [USDC, WETH] as const) {
  await wallet.writeContract({
    address: token,
    abi: erc20Abi,
    functionName: 'approve',
    args: [aqua.address.toString(), maxUint256]
  })
}

// Send transaction
await wallet.sendTransaction(shipTx)

Full test example: tests/aqua.spec.ts - should ship

Example 2: Execute a Swap through XYCSwap.sol aqua app

Execute a swap against liquidity provided through Aqua. TestTrader.sol helper contract is used as an approve holder and router.

import {
  parseUnits,
  http,
  createWalletClient,
  isHex,
  encodeFunctionData,
  decodeAbiParameters,
  publicActions
} from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet } from 'viem/chains'
import assert from 'assert'
import 'dotenv/config'

const takerPrivateKey = process.env.TAKER_PRIVATE_KEY

assert(isHex(takerPrivateKey))
const USDC = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
const app = '0xTODOReplace'
const routerAddress = '0xTestTraderAddress'

const strategy = '0x' // parsed from ship events or fetched from api

// Send transaction
const wallet = createWalletClient({
  chain: mainnet,
  transport: http(),
  account: privateKeyToAccount(takerPrivateKey)
}).extend(publicActions)

// decode data based on specified by app format
const [strategyData] = decodeAbiParameters(
  [
    {
      type: 'tuple',
      components: [
        { name: 'maker', type: 'address' },
        { name: 'token0', type: 'address' },
        { name: 'token1', type: 'address' },
        { name: 'feeBps', type: 'uint256' },
        { name: 'salt', type: 'bytes32' }
      ]
    }
  ],
  strategy
)

// Define swap parameters
const srcAmount = parseUnits('10', 6) // 10 USDC
const srcToken = USDC
const isZeroForOne = strategyData.token0 === srcToken

// Encode the swap call to helper Router contract
const swapData = encodeFunctionData({
  abi: [
    {
      type: 'function',
      name: 'swap',
      inputs: [
        {
          name: 'app',
          type: 'address'
        },
        {
          name: 'strategy',
          type: 'tuple',
          components: [
            { name: 'maker', type: 'address' },
            { name: 'token0', type: 'address' },
            { name: 'token1', type: 'address' },
            { name: 'feeBps', type: 'uint256' },
            { name: 'salt', type: 'bytes32' }
          ]
        },
        { name: 'zeroForOne', type: 'bool' },
        { name: 'amountIn', type: 'uint256' }
      ],
      outputs: [{ name: 'amountOut', type: 'uint256' }],
      stateMutability: 'nonpayable'
    }
  ],
  functionName: 'swap',
  args: [app, strategyData, isZeroForOne, srcAmount]
})

// give erc20 approve to routerAddress
await wallet.writeContract({
  abi: [
    {
      type: 'function',
      name: 'approve',
      inputs: [
        { name: 'spender', type: 'address', internalType: 'address' },
        { name: 'value', type: 'uint256', internalType: 'uint256' }
      ],
      outputs: [{ name: '', type: 'bool', internalType: 'bool' }],
      stateMutability: 'nonpayable'
    }
  ],
  address: srcToken,
  account: wallet.account,
  functionName: 'approve',
  chain: wallet.chain,
  args: [routerAddress, srcAmount]
})

// Execute swap
const swapTx = await wallet.sendTransaction({
  to: routerAddress,
  data: swapData
})

await wallet.waitForTransactionReceipt({ hash: swapTx })

Full test example: tests/aqua.spec.ts - should swap

Example 3: Dock Liquidity

Close a strategy by setting all of its virtual balances to zero. dock does not transfer tokens: they are already in the maker's wallet.

import { AquaProtocolContract, Address, HexString, AQUA_CONTRACT_ADDRESSES, NetworkEnum } from '@1inch/aqua-sdk'
import { http, createWalletClient, isHex } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet } from 'viem/chains'
import assert from 'assert'
import 'dotenv/config'

const makerPrivateKey = process.env.MAKER_PRIVATE_KEY

assert(isHex(makerPrivateKey))
const app = '0xTODO_REPLACE'
const WETH = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const USDC = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'

const strategy = '0x' // parsed from ship events or fetched from api

// Initialize Aqua contract
const aqua = new AquaProtocolContract(AQUA_CONTRACT_ADDRESSES[NetworkEnum.ETHEREUM])

// Create dock transaction
const dockTx = aqua.dock({
  app: new Address(app),
  strategyHash: AquaProtocolContract.calculateStrategyHash(new HexString(strategy)),
  tokens: [new Address(USDC), new Address(WETH)]
})

// Send transaction
const wallet = createWalletClient({
  chain: mainnet,
  transport: http(),
  account: privateKeyToAccount(makerPrivateKey)
})

await wallet.sendTransaction(dockTx)

// After the transaction is confirmed, the strategy's virtual balances are zero
// and the strategy is closed

Full test example: tests/aqua.spec.ts - should dock

License

This SDK is provided under the terms described in LICENSE and THIRD_PARTY_NOTICES.

For any licensing questions or requests, contact:

版本与发布记录

@1inch/aqua-sdk 共发布 16 个版本,首次发布于 2025/11/17;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.0latest2026/11/051 天前
0.3.42026/09/111 个月前
0.3.32026/09/111 个月前
0.3.22026/09/091 个月前
0.3.2-rc.0next2026/09/052 个月前
0.3.12026/08/182 个月前

关于 @1inch/aqua-sdk 的常见问题

@1inch/aqua-sdk 是什么?

1inch Aqua Protocol SDK

如何安装 @1inch/aqua-sdk?

在项目目录运行 npm install @1inch/aqua-sdk,或使用 pnpm add / yarn add / bun add。

@1inch/aqua-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@1inch/aqua-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@1inch/aqua-sdk 可以商用吗?

@1inch/aqua-sdk 使用 LicenseRef-Degensoft-Aqua-Source-1.1 许可。声明的许可为 LicenseRef-Degensoft-Aqua-Source-1.1,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@1inch/aqua-sdk 的下载量有多少?

根据 npm 官方下载统计,@1inch/aqua-sdk 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,881 次,日均约 129 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@1inch/aqua-sdk 还在维护吗?

最新版本 0.4.0 发布于 2026/11/05(1 天前);至今共发布 16 个版本,其中过去 12 个月发布了 16 个;首次发布于 2025/11/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。