@1inch/swap-vm-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +103 -0
- package/README.md +584 -0
- package/dist/abi/SwapVM.abi.d.mts +403 -0
- package/dist/abi/SwapVM.abi.d.ts +403 -0
- package/dist/abi/index.d.mts +1 -0
- package/dist/abi/index.d.ts +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3842 -0
- package/dist/index.mjs +3777 -0
- package/dist/swap-vm/index.d.mts +6 -0
- package/dist/swap-vm/index.d.ts +6 -0
- package/dist/swap-vm/instructions/balances/balances-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/balances/balances-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/balances/balances-args.d.mts +17 -0
- package/dist/swap-vm/instructions/balances/balances-args.d.ts +17 -0
- package/dist/swap-vm/instructions/balances/index.d.mts +3 -0
- package/dist/swap-vm/instructions/balances/index.d.ts +3 -0
- package/dist/swap-vm/instructions/balances/opcodes.d.mts +12 -0
- package/dist/swap-vm/instructions/balances/opcodes.d.ts +12 -0
- package/dist/swap-vm/instructions/balances/types.d.mts +5 -0
- package/dist/swap-vm/instructions/balances/types.d.ts +5 -0
- package/dist/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args.d.mts +40 -0
- package/dist/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args.d.ts +40 -0
- package/dist/swap-vm/instructions/base-fee-adjuster/index.d.mts +2 -0
- package/dist/swap-vm/instructions/base-fee-adjuster/index.d.ts +2 -0
- package/dist/swap-vm/instructions/base-fee-adjuster/opcodes.d.mts +5 -0
- package/dist/swap-vm/instructions/base-fee-adjuster/opcodes.d.ts +5 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.d.mts +21 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.d.ts +21 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.d.mts +17 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.d.ts +17 -0
- package/dist/swap-vm/instructions/concentrate/index.d.mts +5 -0
- package/dist/swap-vm/instructions/concentrate/index.d.ts +5 -0
- package/dist/swap-vm/instructions/concentrate/opcodes.d.mts +10 -0
- package/dist/swap-vm/instructions/concentrate/opcodes.d.ts +10 -0
- package/dist/swap-vm/instructions/concentrate/types.d.mts +5 -0
- package/dist/swap-vm/instructions/concentrate/types.d.ts +5 -0
- package/dist/swap-vm/instructions/concentrate/utils.d.mts +4 -0
- package/dist/swap-vm/instructions/concentrate/utils.d.ts +4 -0
- package/dist/swap-vm/instructions/controls/deadline-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/controls/deadline-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/controls/deadline-args.d.mts +9 -0
- package/dist/swap-vm/instructions/controls/deadline-args.d.ts +9 -0
- package/dist/swap-vm/instructions/controls/index.d.mts +8 -0
- package/dist/swap-vm/instructions/controls/index.d.ts +8 -0
- package/dist/swap-vm/instructions/controls/jump-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/controls/jump-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/controls/jump-args.d.mts +16 -0
- package/dist/swap-vm/instructions/controls/jump-args.d.ts +16 -0
- package/dist/swap-vm/instructions/controls/jump-if-token-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/controls/jump-if-token-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/controls/jump-if-token-args.d.mts +10 -0
- package/dist/swap-vm/instructions/controls/jump-if-token-args.d.ts +10 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-balance-gte-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-balance-gte-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-balance-gte-args.d.mts +17 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-balance-gte-args.d.ts +17 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args.d.mts +16 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args.d.ts +16 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.d.mts +18 -0
- package/dist/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.d.ts +18 -0
- package/dist/swap-vm/instructions/controls/opcodes.d.mts +36 -0
- package/dist/swap-vm/instructions/controls/opcodes.d.ts +36 -0
- package/dist/swap-vm/instructions/controls/salt-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/controls/salt-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/controls/salt-args.d.mts +16 -0
- package/dist/swap-vm/instructions/controls/salt-args.d.ts +16 -0
- package/dist/swap-vm/instructions/debug/debug-args.d.mts +8 -0
- package/dist/swap-vm/instructions/debug/debug-args.d.ts +8 -0
- package/dist/swap-vm/instructions/debug/debug-empty-args.d.mts +19 -0
- package/dist/swap-vm/instructions/debug/debug-empty-args.d.ts +19 -0
- package/dist/swap-vm/instructions/debug/opcodes.d.mts +18 -0
- package/dist/swap-vm/instructions/debug/opcodes.d.ts +18 -0
- package/dist/swap-vm/instructions/debug/print-amount-for-swap.d.mts +16 -0
- package/dist/swap-vm/instructions/debug/print-amount-for-swap.d.ts +16 -0
- package/dist/swap-vm/instructions/debug/print-context.d.mts +16 -0
- package/dist/swap-vm/instructions/debug/print-context.d.ts +16 -0
- package/dist/swap-vm/instructions/debug/print-free-memory-pointer.d.mts +16 -0
- package/dist/swap-vm/instructions/debug/print-free-memory-pointer.d.ts +16 -0
- package/dist/swap-vm/instructions/debug/print-gas-left.d.mts +16 -0
- package/dist/swap-vm/instructions/debug/print-gas-left.d.ts +16 -0
- package/dist/swap-vm/instructions/debug/print-swap-query.d.mts +16 -0
- package/dist/swap-vm/instructions/debug/print-swap-query.d.ts +16 -0
- package/dist/swap-vm/instructions/debug/print-swap-registers.d.mts +16 -0
- package/dist/swap-vm/instructions/debug/print-swap-registers.d.ts +16 -0
- package/dist/swap-vm/instructions/decay/decay-xd-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/decay/decay-xd-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/decay/decay-xd-args.d.mts +16 -0
- package/dist/swap-vm/instructions/decay/decay-xd-args.d.ts +16 -0
- package/dist/swap-vm/instructions/decay/index.d.mts +2 -0
- package/dist/swap-vm/instructions/decay/index.d.ts +2 -0
- package/dist/swap-vm/instructions/decay/opcodes.d.mts +5 -0
- package/dist/swap-vm/instructions/decay/opcodes.d.ts +5 -0
- package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args.d.mts +44 -0
- package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args.d.ts +44 -0
- package/dist/swap-vm/instructions/dutch-auction/index.d.mts +2 -0
- package/dist/swap-vm/instructions/dutch-auction/index.d.ts +2 -0
- package/dist/swap-vm/instructions/dutch-auction/opcodes.d.mts +10 -0
- package/dist/swap-vm/instructions/dutch-auction/opcodes.d.ts +10 -0
- package/dist/swap-vm/instructions/empty.d.mts +13 -0
- package/dist/swap-vm/instructions/empty.d.ts +13 -0
- package/dist/swap-vm/instructions/extruction/extruction-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/extruction/extruction-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/extruction/extruction-args.d.mts +21 -0
- package/dist/swap-vm/instructions/extruction/extruction-args.d.ts +21 -0
- package/dist/swap-vm/instructions/extruction/index.d.mts +2 -0
- package/dist/swap-vm/instructions/extruction/index.d.ts +2 -0
- package/dist/swap-vm/instructions/extruction/opcodes.d.mts +5 -0
- package/dist/swap-vm/instructions/extruction/opcodes.d.ts +5 -0
- package/dist/swap-vm/instructions/fee/flat-fee-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/fee/flat-fee-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/fee/flat-fee-args.d.mts +28 -0
- package/dist/swap-vm/instructions/fee/flat-fee-args.d.ts +28 -0
- package/dist/swap-vm/instructions/fee/index.d.mts +3 -0
- package/dist/swap-vm/instructions/fee/index.d.ts +3 -0
- package/dist/swap-vm/instructions/fee/opcodes.d.mts +30 -0
- package/dist/swap-vm/instructions/fee/opcodes.d.ts +30 -0
- package/dist/swap-vm/instructions/fee/protocol-fee-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/fee/protocol-fee-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/fee/protocol-fee-args.d.mts +35 -0
- package/dist/swap-vm/instructions/fee/protocol-fee-args.d.ts +35 -0
- package/dist/swap-vm/instructions/index.d.mts +29 -0
- package/dist/swap-vm/instructions/index.d.ts +29 -0
- package/dist/swap-vm/instructions/instruction.d.mts +7 -0
- package/dist/swap-vm/instructions/instruction.d.ts +7 -0
- package/dist/swap-vm/instructions/invalidators/index.d.mts +4 -0
- package/dist/swap-vm/instructions/invalidators/index.d.ts +4 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-bit-1d-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-bit-1d-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-bit-1d-args.d.mts +16 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-bit-1d-args.d.ts +16 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-token-in-1d-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-token-in-1d-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-token-in-1d-args.d.mts +8 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-token-in-1d-args.d.ts +8 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-token-out-1d-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-token-out-1d-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-token-out-1d-args.d.mts +8 -0
- package/dist/swap-vm/instructions/invalidators/invalidate-token-out-1d-args.d.ts +8 -0
- package/dist/swap-vm/instructions/invalidators/opcodes.d.mts +15 -0
- package/dist/swap-vm/instructions/invalidators/opcodes.d.ts +15 -0
- package/dist/swap-vm/instructions/limit-swap/index.d.mts +2 -0
- package/dist/swap-vm/instructions/limit-swap/index.d.ts +2 -0
- package/dist/swap-vm/instructions/limit-swap/limit-swap-direction-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/limit-swap/limit-swap-direction-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/limit-swap/limit-swap-direction-args.d.mts +24 -0
- package/dist/swap-vm/instructions/limit-swap/limit-swap-direction-args.d.ts +24 -0
- package/dist/swap-vm/instructions/limit-swap/opcodes.d.mts +10 -0
- package/dist/swap-vm/instructions/limit-swap/opcodes.d.ts +10 -0
- package/dist/swap-vm/instructions/min-rate/index.d.mts +2 -0
- package/dist/swap-vm/instructions/min-rate/index.d.ts +2 -0
- package/dist/swap-vm/instructions/min-rate/min-rate-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/min-rate/min-rate-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/min-rate/min-rate-args.d.mts +22 -0
- package/dist/swap-vm/instructions/min-rate/min-rate-args.d.ts +22 -0
- package/dist/swap-vm/instructions/min-rate/opcodes.d.mts +10 -0
- package/dist/swap-vm/instructions/min-rate/opcodes.d.ts +10 -0
- package/dist/swap-vm/instructions/opcode.d.mts +8 -0
- package/dist/swap-vm/instructions/opcode.d.ts +8 -0
- package/dist/swap-vm/instructions/oracle-price-adjuster/index.d.mts +2 -0
- package/dist/swap-vm/instructions/oracle-price-adjuster/index.d.ts +2 -0
- package/dist/swap-vm/instructions/oracle-price-adjuster/opcodes.d.mts +5 -0
- package/dist/swap-vm/instructions/oracle-price-adjuster/opcodes.d.ts +5 -0
- package/dist/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.d.mts +41 -0
- package/dist/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.d.ts +41 -0
- package/dist/swap-vm/instructions/stable-swap/index.d.mts +2 -0
- package/dist/swap-vm/instructions/stable-swap/index.d.ts +2 -0
- package/dist/swap-vm/instructions/stable-swap/opcodes.d.mts +4 -0
- package/dist/swap-vm/instructions/stable-swap/opcodes.d.ts +4 -0
- package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args.d.mts +25 -0
- package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args.d.ts +25 -0
- package/dist/swap-vm/instructions/twap-swap/index.d.mts +2 -0
- package/dist/swap-vm/instructions/twap-swap/index.d.ts +2 -0
- package/dist/swap-vm/instructions/twap-swap/opcodes.d.mts +5 -0
- package/dist/swap-vm/instructions/twap-swap/opcodes.d.ts +5 -0
- package/dist/swap-vm/instructions/twap-swap/twap-swap-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/twap-swap/twap-swap-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/twap-swap/twap-swap-args.d.mts +71 -0
- package/dist/swap-vm/instructions/twap-swap/twap-swap-args.d.ts +71 -0
- package/dist/swap-vm/instructions/types.d.mts +18 -0
- package/dist/swap-vm/instructions/types.d.ts +18 -0
- package/dist/swap-vm/instructions/xyc-swap/index.d.mts +2 -0
- package/dist/swap-vm/instructions/xyc-swap/index.d.ts +2 -0
- package/dist/swap-vm/instructions/xyc-swap/opcodes.d.mts +5 -0
- package/dist/swap-vm/instructions/xyc-swap/opcodes.d.ts +5 -0
- package/dist/swap-vm/instructions/xyc-swap/xyc-swap-xd-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/xyc-swap/xyc-swap-xd-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/xyc-swap/xyc-swap-xd-args.d.mts +15 -0
- package/dist/swap-vm/instructions/xyc-swap/xyc-swap-xd-args.d.ts +15 -0
- package/dist/swap-vm/maker-traits.d.mts +206 -0
- package/dist/swap-vm/maker-traits.d.ts +206 -0
- package/dist/swap-vm/order.d.mts +84 -0
- package/dist/swap-vm/order.d.ts +84 -0
- package/dist/swap-vm/programs/aqua-program-builder.d.mts +118 -0
- package/dist/swap-vm/programs/aqua-program-builder.d.ts +118 -0
- package/dist/swap-vm/programs/index.d.mts +4 -0
- package/dist/swap-vm/programs/index.d.ts +4 -0
- package/dist/swap-vm/programs/program-builder.d.mts +26 -0
- package/dist/swap-vm/programs/program-builder.d.ts +26 -0
- package/dist/swap-vm/programs/regular-program-builder.d.mts +187 -0
- package/dist/swap-vm/programs/regular-program-builder.d.ts +187 -0
- package/dist/swap-vm/programs/swap-vm-program.d.mts +6 -0
- package/dist/swap-vm/programs/swap-vm-program.d.ts +6 -0
- package/dist/swap-vm/strategies/aqua-amm-strategy.d.mts +32 -0
- package/dist/swap-vm/strategies/aqua-amm-strategy.d.ts +32 -0
- package/dist/swap-vm/strategies/index.d.mts +1 -0
- package/dist/swap-vm/strategies/index.d.ts +1 -0
- package/dist/swap-vm/taker-traits.d.mts +214 -0
- package/dist/swap-vm/taker-traits.d.ts +214 -0
- package/dist/swap-vm/types.d.mts +22 -0
- package/dist/swap-vm/types.d.ts +22 -0
- package/dist/swap-vm-contract/constants.d.mts +13 -0
- package/dist/swap-vm-contract/constants.d.ts +13 -0
- package/dist/swap-vm-contract/events/index.d.mts +1 -0
- package/dist/swap-vm-contract/events/index.d.ts +1 -0
- package/dist/swap-vm-contract/events/swapped-event.d.mts +19 -0
- package/dist/swap-vm-contract/events/swapped-event.d.ts +19 -0
- package/dist/swap-vm-contract/index.d.mts +4 -0
- package/dist/swap-vm-contract/index.d.ts +4 -0
- package/dist/swap-vm-contract/swap-vm-contract.d.mts +38 -0
- package/dist/swap-vm-contract/swap-vm-contract.d.ts +38 -0
- package/dist/swap-vm-contract/types.d.mts +22 -0
- package/dist/swap-vm-contract/types.d.ts +22 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
# @1inch/swap-vm-sdk - TypeScript SDK for 1inch Swap VM protocol
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for encoding, decoding, and interacting with the 1inch Swap VM Protocol smart contract. This SDK provides utilities for building transactions, parsing events, and managing virtual machine instructions for the Swap VM Protocol's core operations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Swap VM Protocol is a lightweight virtual machine designed for efficient and flexible token swapping on-chain. This SDK simplifies integration by providing:
|
|
8
|
+
|
|
9
|
+
- **Transaction Building**: Build typed call data for `quote`, `swap`, and `hash` operations
|
|
10
|
+
- **Instruction System**: Comprehensive instruction set including swaps, liquidity concentration, fees, and controls
|
|
11
|
+
- **Trait management**: Taker and maker traits builders with sensible defaults for standard swaps, plus fine-grained control whenever you need advanced order customization.
|
|
12
|
+
|
|
13
|
+
For detailed protocol documentation, see the [Swap VM Protocol Documentation](https://github.com/1inch/swap-vm#-table-of-contents).
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @1inch/swap-vm-sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### Provide liquidity
|
|
24
|
+
```typescript
|
|
25
|
+
import {
|
|
26
|
+
AQUA_SWAP_VM_CONTRACT_ADDRESSES,
|
|
27
|
+
Address,
|
|
28
|
+
NetworkEnum,
|
|
29
|
+
Order,
|
|
30
|
+
MakerTraits,
|
|
31
|
+
AquaAMMStrategy
|
|
32
|
+
} from '@1inch/swap-vm-sdk'
|
|
33
|
+
import { AquaProtocolContract, AQUA_CONTRACT_ADDRESSES } from '@1inch/aqua-sdk'
|
|
34
|
+
|
|
35
|
+
const chainId = NetworkEnum.ETHEREUM
|
|
36
|
+
const aqua = new AquaProtocolContract(AQUA_CONTRACT_ADDRESSES[chainId])
|
|
37
|
+
const swapVMAddress = AQUA_SWAP_VM_CONTRACT_ADDRESSES[chainId]
|
|
38
|
+
|
|
39
|
+
const maker = '0xmaker_address'
|
|
40
|
+
const USDC = new Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48')
|
|
41
|
+
const WETH = new Address('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2')
|
|
42
|
+
|
|
43
|
+
const program = AquaAMMStrategy.new({
|
|
44
|
+
tokenA: USDC,
|
|
45
|
+
tokenB: WETH
|
|
46
|
+
}).build()
|
|
47
|
+
|
|
48
|
+
const order = Order.new({
|
|
49
|
+
maker: new Address(maker),
|
|
50
|
+
program,
|
|
51
|
+
traits: MakerTraits.default()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const tx = aqua.ship({
|
|
55
|
+
app: new Address(swapVMAddress),
|
|
56
|
+
strategy: order.encode(),
|
|
57
|
+
amountsAndTokens: [
|
|
58
|
+
{
|
|
59
|
+
amount: 10000n * 10n ** 6n,
|
|
60
|
+
token: USDC
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
amount: 5n * 10n ** 18n,
|
|
64
|
+
token: WETH
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
await makerWallet.send(tx)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Swap
|
|
73
|
+
```typescript
|
|
74
|
+
import {
|
|
75
|
+
Order,
|
|
76
|
+
HexString,
|
|
77
|
+
TakerTraits,
|
|
78
|
+
Address,
|
|
79
|
+
AQUA_SWAP_VM_CONTRACT_ADDRESSES,
|
|
80
|
+
NetworkEnum,
|
|
81
|
+
SwapVMContract,
|
|
82
|
+
ABI
|
|
83
|
+
} from '@1inch/swap-vm-sdk'
|
|
84
|
+
import { decodeFunctionResult } from 'viem'
|
|
85
|
+
|
|
86
|
+
const chainId = NetworkEnum.ETHEREUM
|
|
87
|
+
const swapVM = new SwapVMContract(AQUA_SWAP_VM_CONTRACT_ADDRESSES[chainId])
|
|
88
|
+
|
|
89
|
+
const USDC = new Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48')
|
|
90
|
+
const WETH = new Address('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2')
|
|
91
|
+
|
|
92
|
+
const encodedOrder = '0x...' // fetched from ship event or from api
|
|
93
|
+
const order = Order.parse(new HexString(encodedOrder))
|
|
94
|
+
|
|
95
|
+
const srcAmount = 100n * 10n ** 6n
|
|
96
|
+
const swapParams = {
|
|
97
|
+
order,
|
|
98
|
+
amount: srcAmount,
|
|
99
|
+
takerTraits: TakerTraits.default(),
|
|
100
|
+
tokenIn: USDC,
|
|
101
|
+
tokenOut: WETH
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Simulate the call to get the dstAmount
|
|
105
|
+
const simulateResult = await taker.call(swapVM.quote(swapParams))
|
|
106
|
+
const [_, dstAmount] = decodeFunctionResult({
|
|
107
|
+
abi: ABI.SWAP_VM_ABI,
|
|
108
|
+
functionName: 'quote',
|
|
109
|
+
data: simulateResult.data!
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
console.log('dstAmount', dstAmount)
|
|
113
|
+
|
|
114
|
+
// Swap
|
|
115
|
+
const swapTx = swapVM.swap(swapParams)
|
|
116
|
+
await taker.send(swapTx)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Contract operations
|
|
120
|
+
|
|
121
|
+
### Quote
|
|
122
|
+
|
|
123
|
+
Get a quote for a swap.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const quoteTx = swapVm.quote({
|
|
127
|
+
order: Order.parse('0x...'),
|
|
128
|
+
tokenIn: new Address('0x...'),
|
|
129
|
+
tokenOut: new Address('0x...'),
|
|
130
|
+
amount: 1000000000000000000n,
|
|
131
|
+
takerTraits: TakerTraits.default(),
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Parameters:**
|
|
136
|
+
- `order` - The maker's order (fetched from ship event or from api)
|
|
137
|
+
- `tokenIn` - The input token address
|
|
138
|
+
- `tokenOut` - The output token address
|
|
139
|
+
- `amount` - The input amount to quote
|
|
140
|
+
- `takerTraits` - Taker-specific traits configuration
|
|
141
|
+
|
|
142
|
+
**Returns:** `CallInfo` object with encoded transaction data
|
|
143
|
+
|
|
144
|
+
### Swap
|
|
145
|
+
|
|
146
|
+
Execute a swap transaction.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const swapTx = swapVm.swap({
|
|
150
|
+
order: Order.parse('0x...'),
|
|
151
|
+
tokenIn: new Address('0x...'),
|
|
152
|
+
tokenOut: new Address('0x...'),
|
|
153
|
+
amount: 1000000000000000000n,
|
|
154
|
+
takerTraits: TakerTraits.default(),
|
|
155
|
+
})
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Parameters:**
|
|
159
|
+
- All parameters from `quote`
|
|
160
|
+
|
|
161
|
+
**Returns:** `CallInfo` object with encoded transaction data
|
|
162
|
+
|
|
163
|
+
### Hash Order
|
|
164
|
+
|
|
165
|
+
Calculate the hash of an order (view).
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
const order = new Order({
|
|
169
|
+
maker: new Address('0x...'),
|
|
170
|
+
traits: MakerTraits.default(),
|
|
171
|
+
program: new HexString('0x...'),
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
const hashOrderTx = swapVm.hashOrder(order)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Parameters:**
|
|
178
|
+
- `order` - The order to hash
|
|
179
|
+
|
|
180
|
+
**Returns:** `CallInfo` object with encoded transaction data for the `hash` order function
|
|
181
|
+
|
|
182
|
+
## Event Parsing
|
|
183
|
+
|
|
184
|
+
### Swapped Event
|
|
185
|
+
|
|
186
|
+
Emitted when a swap is executed.
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { SwappedEvent } from '@1inch/swap-vm-sdk'
|
|
190
|
+
|
|
191
|
+
const log = { data: '0x...', topics: ['0x...'] }
|
|
192
|
+
const event = SwappedEvent.fromLog(log)
|
|
193
|
+
|
|
194
|
+
console.log(event.orderHash) // HexString
|
|
195
|
+
console.log(event.maker) // Address
|
|
196
|
+
console.log(event.taker) // Address
|
|
197
|
+
console.log(event.tokenIn) // Address
|
|
198
|
+
console.log(event.tokenOut) // Address
|
|
199
|
+
console.log(event.amountIn) // bigint
|
|
200
|
+
console.log(event.amountOut) // bigint
|
|
201
|
+
```
|
|
202
|
+
## Instructions
|
|
203
|
+
|
|
204
|
+
The Swap VM uses a comprehensive instruction system for building swap programs.
|
|
205
|
+
|
|
206
|
+
🔎 **Instruction coverage vs. deployment**
|
|
207
|
+
|
|
208
|
+
- The **SDK** exposes the **full instruction set** (see `_allInstructions` in [`src/swap-vm/instructions/index.ts`](./src/swap-vm/instructions/index.ts)) and can safely **encode/decode every core opcode** defined by the protocol.
|
|
209
|
+
- The **currently deployed `AquaSwapVMRouter` contracts** support **only the Aqua subset** of these instructions (see `aquaInstructions` in the same file).
|
|
210
|
+
- Any program that uses instructions **outside `aquaInstructions`** will **not be executable on current Aqua deployments**, even though encoding/decoding will succeed.
|
|
211
|
+
- After the **`Fusaka` Ethereum hardfork**, a full `SwapVM` deployment is planned; at that point, programs using the complete `_allInstructions` set will be executable on-chain on Ethereum.
|
|
212
|
+
|
|
213
|
+
💡 **Gotcha**: When designing programs intended to run on today’s on-chain Aqua instances, treat `aquaInstructions` as the authoritative list of **runtime-available** opcodes, and the rest of the instruction set as **future / generic Swap VM** capabilities.
|
|
214
|
+
|
|
215
|
+
Available instruction categories in the full Swap VM instruction set include:
|
|
216
|
+
|
|
217
|
+
### Balances
|
|
218
|
+
- `STATIC_BALANCES_XD` - Initialize static token balances
|
|
219
|
+
- `DYNAMIC_BALANCES_XD` - Access and manipulate dynamic token balances
|
|
220
|
+
|
|
221
|
+
### Invalidators
|
|
222
|
+
- `INVALIDATE_BIT_1D` - Invalidate an order bit in the maker’s bitmap
|
|
223
|
+
- `INVALIDATE_TOKEN_IN_1D` - Invalidate orders by input token
|
|
224
|
+
- `INVALIDATE_TOKEN_OUT_1D` - Invalidate orders by output token
|
|
225
|
+
|
|
226
|
+
### Controls
|
|
227
|
+
- `JUMP` - Unconditional jump to another instruction
|
|
228
|
+
- `JUMP_IF_TOKEN_IN` - Conditional jump based on taker input token
|
|
229
|
+
- `JUMP_IF_TOKEN_OUT` - Conditional jump based on taker output token
|
|
230
|
+
- `DEADLINE` - Guard: only execute before a given timestamp
|
|
231
|
+
- `ONLY_TAKER_TOKEN_BALANCE_NON_ZERO` - Guard: only execute if taker token balance is non-zero
|
|
232
|
+
- `ONLY_TAKER_TOKEN_BALANCE_GTE` - Guard: only execute if balance >= threshold
|
|
233
|
+
- `ONLY_TAKER_TOKEN_SUPPLY_SHARE_GTE` - Guard: only execute if supply share >= threshold
|
|
234
|
+
- `SALT` - Add randomness to order hash
|
|
235
|
+
|
|
236
|
+
### Trading instructions
|
|
237
|
+
- `XYC_SWAP_XD` - XYC swap for multi-dimensional pools
|
|
238
|
+
- `CONCENTRATE_GROW_LIQUIDITY_XD` - Concentrate liquidity in multi-dimensional pools
|
|
239
|
+
- `CONCENTRATE_GROW_LIQUIDITY_2D` - Concentrate liquidity in 2D pools
|
|
240
|
+
- `DECAY_XD` - Apply decay calculation
|
|
241
|
+
- `LIMIT_SWAP_1D` - Execute limit order swap
|
|
242
|
+
- `LIMIT_SWAP_ONLY_FULL_1D` - Execute limit order only if fully fillable
|
|
243
|
+
- `REQUIRE_MIN_RATE_1D` - Enforce minimum rate requirement
|
|
244
|
+
- `ADJUST_MIN_RATE_1D` - Adjust minimum rate dynamically
|
|
245
|
+
- `DUTCH_AUCTION_BALANCE_IN_1D` - Dutch auction based on available input balance
|
|
246
|
+
- `DUTCH_AUCTION_BALANCE_OUT_1D` - Dutch auction based on desired output balance
|
|
247
|
+
- `ORACLE_PRICE_ADJUSTER_1D` - Adjust prices based on oracle data
|
|
248
|
+
- `BASE_FEE_ADJUSTER_1D` - Adjust for network base fees
|
|
249
|
+
- `TWAP` - Time-weighted average price swap
|
|
250
|
+
- `EXTRUCTION` - External contract instruction
|
|
251
|
+
|
|
252
|
+
### Fee instructions
|
|
253
|
+
- `FLAT_FEE_AMOUNT_IN_XD` - Flat fee based on input amount
|
|
254
|
+
- `FLAT_FEE_AMOUNT_OUT_XD` - Flat fee based on output amount
|
|
255
|
+
- `PROGRESSIVE_FEE_IN_XD` - Progressive fee applied on input
|
|
256
|
+
- `PROGRESSIVE_FEE_OUT_XD` - Progressive fee applied on output
|
|
257
|
+
- `PROTOCOL_FEE_AMOUNT_OUT_XD` - Protocol fee on output
|
|
258
|
+
- `AQUA_PROTOCOL_FEE_AMOUNT_OUT_XD` - Aqua protocol fee on output
|
|
259
|
+
|
|
260
|
+
### Custom instruction sets & `ProgramBuilder`
|
|
261
|
+
|
|
262
|
+
Anyone can deploy a **SwapVM-compatible contract with a custom instruction set** (e.g. different opcode layout, subset, or extension of the core set) and still use this SDK to build programs for it.
|
|
263
|
+
|
|
264
|
+
The generic [`ProgramBuilder`](./src/swap-vm/programs/program-builder.ts):
|
|
265
|
+
|
|
266
|
+
- Is **instruction-set agnostic** – you inject the opcode table via the constructor as `ixsSet: IOpcode[]`.
|
|
267
|
+
- Can **build and decode programs** for:
|
|
268
|
+
- The full `SwapVM` instruction set (`_allInstructions`)
|
|
269
|
+
- The Aqua subset (`aquaInstructions`)
|
|
270
|
+
- **Any custom opcode table** that matches your own contract deployment
|
|
271
|
+
|
|
272
|
+
**Take attention**:
|
|
273
|
+
- `ProgramBuilder.add(ix)` validates that the instruction’s opcode is present in the provided `ixsSet`.
|
|
274
|
+
- If you accidentally mix instructions from a different set, it throws with the list of supported opcode IDs.
|
|
275
|
+
- `ProgramBuilder.decode(program)` uses the same `ixsSet` to map opcode indices back to instruction definitions, so your **off-chain opcode table must match the on-chain contract layout**.
|
|
276
|
+
|
|
277
|
+
This makes it safe to:
|
|
278
|
+
|
|
279
|
+
- Deploy your own `SwapVM`-style contract with a custom opcode mapping.
|
|
280
|
+
- Use `ProgramBuilder` with your custom `ixsSet` to construct and parse programs for that deployment, without changing the rest of the SDK.
|
|
281
|
+
|
|
282
|
+
### Recommended builder for Aqua strategies
|
|
283
|
+
|
|
284
|
+
For strategies intended to run on **today’s deployed `AquaSwapVM` contracts**, it is **recommended** to use the specialized [`AquaProgramBuilder`](./src/swap-vm/programs/aqua-program-builder.ts) instead of the bare `ProgramBuilder`:
|
|
285
|
+
|
|
286
|
+
- It is pre-wired with `aquaInstructions`, so you **cannot accidentally use opcodes that are not supported by Aqua**.
|
|
287
|
+
- It exposes a rich set of **high-level, typed methods** for the Aqua instruction set
|
|
288
|
+
💡 **Practical guidance**:
|
|
289
|
+
|
|
290
|
+
- Use **`AquaProgramBuilder`** for real-world strategy building on current Aqua deployments – it gives you a safer, higher-level API over the Aqua opcode subset.
|
|
291
|
+
- Use **`ProgramBuilder`** when:
|
|
292
|
+
- Targeting future full `SwapVM` deployments (post-`Fusaka` on Ethereum), or
|
|
293
|
+
- Working with your own custom instruction sets and contracts.
|
|
294
|
+
|
|
295
|
+
## Strategies
|
|
296
|
+
|
|
297
|
+
A **strategy** is a reusable template that produces a `SwapVmProgram` – a sequence of instructions that defines **how** liquidity behaves and **how** swaps should be executed.
|
|
298
|
+
|
|
299
|
+
At a high level:
|
|
300
|
+
|
|
301
|
+
- You parameterize a strategy with **business-level inputs** (tokens, fees, decay periods, etc.).
|
|
302
|
+
- The strategy’s `.build()` method compiles these into a low-level `SwapVmProgram` using a program builder.
|
|
303
|
+
- That program is then embedded into an `Order` and shipped.
|
|
304
|
+
|
|
305
|
+
### How strategies are built
|
|
306
|
+
|
|
307
|
+
Strategies are thin wrappers around a program builder:
|
|
308
|
+
|
|
309
|
+
1. **Collect inputs** (e.g. tokens, fee bps, decay parameters, protocol fee receiver).
|
|
310
|
+
2. **Instantiate a builder**:
|
|
311
|
+
- `AquaProgramBuilder` for current `AquaSwapVM` deployments (recommended).
|
|
312
|
+
- `ProgramBuilder` with a custom opcode set for non-Aqua/custom deployments.
|
|
313
|
+
3. **Append instructions** in the desired execution order.
|
|
314
|
+
4. Call `.build()` to get a `SwapVmProgram`.
|
|
315
|
+
|
|
316
|
+
Because the strategy owns the builder, you can keep the strategy API stable even if the underlying instruction sequence evolves.
|
|
317
|
+
|
|
318
|
+
### Creating your own strategy
|
|
319
|
+
|
|
320
|
+
To define a custom strategy:
|
|
321
|
+
|
|
322
|
+
1. Create a small builder class that:
|
|
323
|
+
- Stores your **domain parameters** (tokens, price bands, risk limits, etc.).
|
|
324
|
+
- Offers fluent `withX(...)` methods to configure them.
|
|
325
|
+
2. In `.build()`:
|
|
326
|
+
- Create `ProgramBuilder`.
|
|
327
|
+
- Append instructions in the order you want them executed.
|
|
328
|
+
- Return `builder.build()`.
|
|
329
|
+
|
|
330
|
+
This pattern keeps your **business logic readable** at the strategy layer while leveraging the full flexibility of the underlying Swap VM instruction set.
|
|
331
|
+
|
|
332
|
+
For example:
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import type { SwapVmProgram } from '@1inch/swap-vm-sdk'
|
|
336
|
+
import { AquaProgramBuilder, instructions, Address, Order, MakerTraits } from '@1inch/swap-vm-sdk'
|
|
337
|
+
const { concentrate, fee } = instructions
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Minimal strategy:
|
|
341
|
+
* - concentrates liquidity for a 2-token pool
|
|
342
|
+
* - optionally charges a taker fee on input
|
|
343
|
+
* - always finishes with a simple XYC swap
|
|
344
|
+
*/
|
|
345
|
+
export class SimpleAmmStrategy {
|
|
346
|
+
private liquidityA?: bigint
|
|
347
|
+
|
|
348
|
+
private liquidityB?: bigint
|
|
349
|
+
|
|
350
|
+
private feeBpsIn?: number
|
|
351
|
+
|
|
352
|
+
constructor(
|
|
353
|
+
public readonly tokenA: Address,
|
|
354
|
+
public readonly tokenB: Address,
|
|
355
|
+
) {}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Sets initial virtual liquidity for the pair.
|
|
359
|
+
*/
|
|
360
|
+
public withLiquidity(a: bigint, b: bigint): this {
|
|
361
|
+
this.liquidityA = a
|
|
362
|
+
this.liquidityB = b
|
|
363
|
+
|
|
364
|
+
return this
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Sets taker fee (bps) applied to amountIn.
|
|
369
|
+
* If not called, no taker fee is applied.
|
|
370
|
+
*/
|
|
371
|
+
public withFeeTokenIn(bps: number): this {
|
|
372
|
+
this.feeBpsIn = bps
|
|
373
|
+
|
|
374
|
+
return this
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Builds a SwapVmProgram for AquaSwapVM using a small, fixed instruction pipeline:
|
|
379
|
+
* [concentrate liquidity] -> [optional fee on input] -> [XYC swap]
|
|
380
|
+
*/
|
|
381
|
+
public build(): SwapVmProgram {
|
|
382
|
+
const builder = new AquaProgramBuilder()
|
|
383
|
+
|
|
384
|
+
if (this.liquidityA !== undefined && this.liquidityB !== undefined) {
|
|
385
|
+
const data = concentrate.ConcentrateGrowLiquidity2DArgs.fromTokenDeltas(
|
|
386
|
+
this.tokenA,
|
|
387
|
+
this.tokenB,
|
|
388
|
+
this.liquidityA,
|
|
389
|
+
this.liquidityB,
|
|
390
|
+
)
|
|
391
|
+
builder.add(concentrate.concentrateGrowLiquidity2D.createIx(data))
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (this.feeBpsIn !== undefined) {
|
|
395
|
+
const feeArgs = fee.FlatFeeArgs.fromBps(this.feeBpsIn)
|
|
396
|
+
builder.add(fee.flatFeeAmountInXD.createIx(feeArgs))
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Core swap step
|
|
400
|
+
builder.xycSwapXD()
|
|
401
|
+
|
|
402
|
+
return builder.build()
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Example usage:
|
|
407
|
+
|
|
408
|
+
const strategy = new SimpleAmmStrategy(USDC, WETH)
|
|
409
|
+
.withLiquidity(
|
|
410
|
+
10_000n * 10n ** 6n, // 10k USDC
|
|
411
|
+
5n * 10n ** 18n, // 5 WETH
|
|
412
|
+
)
|
|
413
|
+
.withFeeTokenIn(5) // 5 bps taker fee on input (optional)
|
|
414
|
+
|
|
415
|
+
const program = strategy.build()
|
|
416
|
+
|
|
417
|
+
const order = Order.new({
|
|
418
|
+
maker: new Address(maker),
|
|
419
|
+
program,
|
|
420
|
+
traits: MakerTraits.default(),
|
|
421
|
+
})
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
## Creating your own instructions
|
|
425
|
+
|
|
426
|
+
You can define your own high-level instructions as long as they:
|
|
427
|
+
|
|
428
|
+
- Have an on-chain implementation at a specific opcode index.
|
|
429
|
+
- Provide a **TypeScript args type**, a **coder**, and an **`Opcode` definition** wired into an instruction set.
|
|
430
|
+
|
|
431
|
+
Here is an example of implementation `flatFeeXD` instruction. You can implement any custom instruction in the same way.
|
|
432
|
+
|
|
433
|
+
### 1. Define args class (`FlatFeeArgs`)
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
const FEE_100_PERCENT = 1e9 // 1e9 = 100%
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Arguments for flat fee instruction
|
|
440
|
+
*/
|
|
441
|
+
export class FlatFeeArgs implements IArgsData {
|
|
442
|
+
public static readonly CODER = new FlatFeeArgsCoder()
|
|
443
|
+
|
|
444
|
+
constructor(public readonly fee: bigint) {
|
|
445
|
+
assert(fee >= 0n && fee <= UINT_32_MAX, `Invalid fee: ${fee}. Must be a valid uint32`)
|
|
446
|
+
assert(
|
|
447
|
+
fee <= BigInt(FEE_100_PERCENT),
|
|
448
|
+
`Fee out of range: ${fee}. Must be <= ${FEE_100_PERCENT}`,
|
|
449
|
+
)
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Creates a FlatFeeArgs instance from basis points
|
|
454
|
+
* @param bps - Fee in basis points (10000 bps = 100%)
|
|
455
|
+
*/
|
|
456
|
+
public static fromBps(bps: number): FlatFeeArgs {
|
|
457
|
+
const fee = BigInt(bps * 100000)
|
|
458
|
+
|
|
459
|
+
return new FlatFeeArgs(fee)
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### 2. Implement an args coder (`FlatFeeArgsCoder`)
|
|
465
|
+
|
|
466
|
+
Coders:
|
|
467
|
+
- Implement `IArgsCoder<T>`.
|
|
468
|
+
- Are responsible for **binary layout** of arguments.
|
|
469
|
+
- Must be strictly symmetric: `decode(encode(args)) === args`.
|
|
470
|
+
|
|
471
|
+
```typescript
|
|
472
|
+
export class FlatFeeArgsCoder implements IArgsCoder<FlatFeeArgs> {
|
|
473
|
+
encode(args: FlatFeeArgs): HexString {
|
|
474
|
+
const builder = new BytesBuilder()
|
|
475
|
+
builder.addUint32(args.fee)
|
|
476
|
+
|
|
477
|
+
return new HexString(add0x(builder.asHex()))
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
decode(data: HexString): FlatFeeArgs {
|
|
481
|
+
const iter = BytesIter.BigInt(data.toString())
|
|
482
|
+
const fee = iter.nextUint32()
|
|
483
|
+
|
|
484
|
+
return new FlatFeeArgs(fee)
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### 3. Declare the opcode (`flatFeeXD`)
|
|
490
|
+
|
|
491
|
+
An `Opcode` ties together:
|
|
492
|
+
- A **unique identifier** (`Symbol`) for this instruction.
|
|
493
|
+
- The **args coder** to use for encoding/decoding.
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
/**
|
|
497
|
+
* Applies flat fee to computed swap amount (same rate for exactIn and exactOut)
|
|
498
|
+
*/
|
|
499
|
+
export const flatFeeXD = new Opcode(Symbol('Fee.flatFeeXD'), FlatFeeArgs.CODER)
|
|
500
|
+
```
|
|
501
|
+
Once you have an `Opcode`:
|
|
502
|
+
|
|
503
|
+
- `flatFeeXD.createIx(args)` produces a typed instruction.
|
|
504
|
+
- `ProgramBuilder` can add it to a program:
|
|
505
|
+
- `builder.add(flatFeeXD.createIx(FlatFeeArgs.fromBps(5)))`.
|
|
506
|
+
|
|
507
|
+
### 4. Wire the opcode into an instruction set
|
|
508
|
+
To make your instruction **usable at runtime**, you must place it at the correct index in an instruction set that matches your on-chain VM:
|
|
509
|
+
|
|
510
|
+
```typescript
|
|
511
|
+
export const myInstructionSet: Opcode<IArgsData>[] = [
|
|
512
|
+
/* ... previous opcodes ... */
|
|
513
|
+
fee.flatFeeXD,
|
|
514
|
+
/* ... */
|
|
515
|
+
]
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
⚠️ The **array index** in the instruction set (`ixsSet[index]`) must match the **opcode index used by your on-chain contract**. A mismatch will not fail at encoding time but will execute the **wrong instruction** at runtime.
|
|
519
|
+
|
|
520
|
+
## Supported Networks
|
|
521
|
+
|
|
522
|
+
The SDK includes pre-configured contract addresses of `AquaSwapVMRouter` for the following networks:
|
|
523
|
+
|
|
524
|
+
| Network | Chain ID | Address |
|
|
525
|
+
|---------|----------|---------|
|
|
526
|
+
| Ethereum | 1 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://etherscan.io/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
527
|
+
| BNB Chain | 56 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://bscscan.com/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
528
|
+
| Polygon | 137 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://polygonscan.com/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
529
|
+
| Arbitrum | 42161 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://arbiscan.io/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
530
|
+
| Avalanche | 43114 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](http://snowscan.xyz/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
531
|
+
| Gnosis | 100 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://gnosisscan.io/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
532
|
+
| Coinbase Base | 8453 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://basescan.org/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
533
|
+
| Optimism | 10 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://optimistic.etherscan.io/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
534
|
+
| zkSync Era | 324 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://era.zksync.network/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
535
|
+
| Linea | 59144 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://lineascan.build/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
536
|
+
| Unichain | 1301 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://uniscan.xyz/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
537
|
+
| Sonic | 146 | [0x8fdd04dbf6111437b44bbca99c28882434e0958f](https://sonicscan.org/address/0x8fdd04dbf6111437b44bbca99c28882434e0958f) |
|
|
538
|
+
|
|
539
|
+
Access addresses using:
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
import { AQUA_SWAP_VM_CONTRACT_ADDRESSES, NetworkEnum } from '@1inch/swap-vm-sdk'
|
|
543
|
+
|
|
544
|
+
const ethereumAddress = AQUA_SWAP_VM_CONTRACT_ADDRESSES[NetworkEnum.ETHEREUM]
|
|
545
|
+
const arbitrumAddress = AQUA_SWAP_VM_CONTRACT_ADDRESSES[NetworkEnum.ARBITRUM]
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
## API Reference
|
|
549
|
+
|
|
550
|
+
### Exports
|
|
551
|
+
|
|
552
|
+
The SDK exports:
|
|
553
|
+
|
|
554
|
+
- **[`SwapVMContract`](./src/swap-vm-contract/swap-vm-contract.ts)** - Main contract class for encoding, decoding, and building transactions
|
|
555
|
+
- **[`AQUA_SWAP_VM_CONTRACT_ADDRESSES`](./src/swap-vm-contract/constants.ts)** - Pre-configured contract addresses by network
|
|
556
|
+
- **[`SwappedEvent`](./src/swap-vm-contract/events/swapped-event.ts)** - Event class for parsing swapped events
|
|
557
|
+
- **[`Order`](./src/swap-vm/order.ts)** - Order data structure
|
|
558
|
+
- **[`MakerTraits`](./src/swap-vm/maker-traits.ts)** - Maker-side configuration and flags
|
|
559
|
+
- **[`TakerTraits`](./src/swap-vm/taker-traits.ts)** - Taker-side configuration and flags
|
|
560
|
+
- **[`ABI`](./src/abi/)** - Contract ABI exports
|
|
561
|
+
- **[Instructions](./src/swap-vm/instructions/)** - Comprehensive instruction system:
|
|
562
|
+
- `controls` - Flow control instructions
|
|
563
|
+
- `balances` - Balance manipulation instructions
|
|
564
|
+
- `invalidators` - Invalidation instructions
|
|
565
|
+
- `xycSwap` - XYC swap instructions
|
|
566
|
+
- `concentrate` - Liquidity concentration instructions
|
|
567
|
+
- `decay` - Decay calculation instructions
|
|
568
|
+
- `limitSwap` - Limit order instructions
|
|
569
|
+
- `minRate` - Minimum rate guard instructions
|
|
570
|
+
- `dutchAuction` - Dutch auction instructions
|
|
571
|
+
- `oraclePriceAdjuster` - Oracle-based price adjustment
|
|
572
|
+
- `baseFeeAdjuster` - Base fee adjustment
|
|
573
|
+
- `twapSwap` - Time-weighted average price instructions
|
|
574
|
+
- `extruction` - External instruction call
|
|
575
|
+
- `fee` - Fee calculation instructions
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
## License
|
|
579
|
+
|
|
580
|
+
This SDK is provided under the terms described in [LICENSE](./LICENSE) and [THIRD_PARTY_NOTICES](./THIRD_PARTY_NOTICES).
|
|
581
|
+
|
|
582
|
+
For any licensing questions or requests, contact:
|
|
583
|
+
- license@degensoft.com
|
|
584
|
+
- legal@degensoft.com
|